streamlit-pdf-viewer 0.0.20.dev0__tar.gz → 0.0.21.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/.bumpversion.toml +1 -1
  2. {streamlit_pdf_viewer-0.0.20.dev0/streamlit_pdf_viewer.egg-info → streamlit_pdf_viewer-0.0.21.dev0}/PKG-INFO +19 -21
  3. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/README.md +18 -20
  4. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/__init__.py +9 -4
  5. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/index.html +1 -1
  6. streamlit_pdf_viewer-0.0.21.dev0/streamlit_pdf_viewer/frontend/dist/js/app.16af2f06.js +2 -0
  7. streamlit_pdf_viewer-0.0.21.dev0/streamlit_pdf_viewer/frontend/dist/js/app.16af2f06.js.map +1 -0
  8. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0/streamlit_pdf_viewer.egg-info}/PKG-INFO +19 -21
  9. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer.egg-info/SOURCES.txt +2 -2
  10. streamlit_pdf_viewer-0.0.20.dev0/streamlit_pdf_viewer/frontend/dist/js/app.ebc5e2f4.js +0 -2
  11. streamlit_pdf_viewer-0.0.20.dev0/streamlit_pdf_viewer/frontend/dist/js/app.ebc5e2f4.js.map +0 -1
  12. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/LICENSE +0 -0
  13. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/MANIFEST.in +0 -0
  14. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/setup.cfg +0 -0
  15. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/setup.py +0 -0
  16. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/css/app.1df382f3.css +0 -0
  17. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/css/chunk-vendors.8a2a8d65.css +0 -0
  18. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/img/altText_add.7748ee93.svg +0 -0
  19. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/img/altText_done.1026be11.svg +0 -0
  20. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/img/cursor-editorFreeHighlight.1fed7bb7.svg +0 -0
  21. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/img/cursor-editorFreeText.0b596377.svg +0 -0
  22. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/img/cursor-editorInk.f94c2f42.svg +0 -0
  23. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/img/cursor-editorTextHighlight.5636640c.svg +0 -0
  24. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/img/editor-toolbar-delete.6694a89f.svg +0 -0
  25. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/img/toolbarButton-editorHighlight.c3287eaa.svg +0 -0
  26. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/img/toolbarButton-menuArrow.37a6145d.svg +0 -0
  27. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/js/chunk-vendors.72a36d5a.js +0 -0
  28. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer/frontend/dist/js/chunk-vendors.72a36d5a.js.map +0 -0
  29. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer.egg-info/dependency_links.txt +0 -0
  30. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer.egg-info/requires.txt +0 -0
  31. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/streamlit_pdf_viewer.egg-info/top_level.txt +0 -0
  32. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/__init__.py +0 -0
  33. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/e2e_utils.py +0 -0
  34. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_embed_height.py +0 -0
  35. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_embed_no_args.py +0 -0
  36. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_embed_width.py +0 -0
  37. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_embed_width_height.py +0 -0
  38. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_iframe_height.py +0 -0
  39. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_iframe_no_args.py +0 -0
  40. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_iframe_width.py +0 -0
  41. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_iframe_width_height.py +0 -0
  42. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_invalid_params.py +0 -0
  43. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_rendering_text.py +0 -0
  44. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_resolution_boost.py +0 -0
  45. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_tabs.py +0 -0
  46. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_tabs_2.py +0 -0
  47. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_unwrap_height.py +0 -0
  48. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_unwrap_no_args.py +0 -0
  49. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_unwrap_width.py +0 -0
  50. {streamlit_pdf_viewer-0.0.20.dev0 → streamlit_pdf_viewer-0.0.21.dev0}/tests/test_unwrap_width_height.py +0 -0
@@ -1,5 +1,5 @@
1
1
  [tool.bumpversion]
2
- current_version = "0.0.20-dev0"
2
+ current_version = "0.0.21-dev0"
3
3
  commit = "true"
4
4
  tag = "true"
5
5
  tag_name = "v{new_version}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: streamlit-pdf-viewer
3
- Version: 0.0.20.dev0
3
+ Version: 0.0.21.dev0
4
4
  Summary: Streamlit component for PDF visualisation and manipulation
5
5
  Home-page: https://github.com/lfoppiano/streamlit-pdf-viewer
6
6
  Author: Luca Foppiano, Tomoya Mato
@@ -28,12 +28,13 @@ You can see an [application](https://github.com/lfoppiano/structure-vision) in a
28
28
  ## Features
29
29
  - Show PDF files in a Streamlit application with a simple command
30
30
  - Based on the pdf.js library
31
- - Support showing the PDF with the native pdf.js browser's viewer: "legacy" (with limitations, no annotations, no scrolling, etc..)
32
31
  - Visualize annotations on top of the PDF documents
33
32
  - Render text on top of the PDF document, allowing copy-paste
34
33
  - Allow to render specific pages of the PDF document
35
34
  - Scroll to a specific page
36
35
  - Scroll to a specific annotation
36
+ - Allow custom callbacks when an annotation is clicked
37
+ - Additional support showing PDF documents using the native pdf.js browser's viewer: "legacy" (with limitations, no annotations, no scrolling, etc..)
37
38
 
38
39
  ## Limitations
39
40
  - Tested and developed to support Firefox and Chrome.
@@ -42,8 +43,7 @@ You can see an [application](https://github.com/lfoppiano/structure-vision) in a
42
43
  - The component is still in development, so expect some bugs and limitations
43
44
  - The streamlit reload at each action may render slowly for complex PDF documents
44
45
 
45
- ## Caveats
46
-
46
+ ## Caveats
47
47
  Here some caveats to be aware of:
48
48
  - It ss mandatory to specify a `width` to show PDF document on tabs and expanders, otherwise, the viewer will not be displayed on tabs not immediately visible.
49
49
  - From version 0.0.16, the behavior for managing width and height has changed:
@@ -73,20 +73,20 @@ pdf_viewer("str, path or bytes")
73
73
 
74
74
  In the following table the list of parameters that can be provided to the `pdf_viewer` function:
75
75
 
76
- | name | description |
77
- |-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
78
- | input | The source of the PDF file. Accepts a file path, URL, or binary data. |
79
- | width | Width of the PDF viewer in pixels. It defaults to 700 pixels. |
80
- | height | Height of the PDF viewer in pixels. If not provided, the viewer shows the whole content. |
81
- | annotations | A list of annotations to be overlaid on the PDF. Format is described [here](#annotation-format). |
82
- | pages_vertical_spacing | The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels. |
83
- | annotation_outline_size | Size of the outline around each annotation in pixels. Defaults to 1 pixel. |
84
- | rendering | Type of rendering: `unwrap` (default), `legacy_iframe`, or `legacy_embed`. The default value, `unwrap` shows the PDF document using pdf.js, and supports the visualisation of annotations. Other values are `legacy_iframe` and `legacy_embed` which use the legacy approach of injecting the document into an `<embed>` or `<iframe>`. They allow viewing the PDF using the viewer of the browser that contains additional features we are still working to implement in this component. **IMPORTANT**: :warning: The "legacy" methods **work only with Firefox**, and **do not support annotations**. :warning: |
85
- | pages_to_render | Filter the rendering to a specific set of pages. By default, all pages are rendered. |
86
- | render_text | Enable a layer of text on top of the PDF document. The text may be selected and copied. **NOTE** to avoid breaking existing deployments, we made this optional at first, also considering that having many annotations might interfere with the copy-paste.
87
- | scroll_to_page | Scroll to a specific page when the component is rendered. Default is None. Require ints and ignores the parameters below zero. |
88
- | scroll_to_annotation | Scroll to a specific annotation when the component is rendered. Default is None. Mutually exclusive with `scroll_to_page`. Raise an exception if used with `scroll_to_page` |
89
- | on_annotation_click | Callback function that is called when an annotation is clicked. The function receives the annotation as a parameter. |
76
+ | name | description |
77
+ |---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
78
+ | input | The source of the PDF file. Accepts a file path, URL, or binary data. |
79
+ | width | Width of the PDF viewer in pixels. It defaults to 700 pixels. Can set it to string percentage also. For example 90% which will make the pdf render to 90% of the container/window/screen width. If the pdf width is larger than the screen width, it will horizontally scroll. |
80
+ | height | Height of the PDF viewer in pixels. If not provided, the viewer shows the whole content. |
81
+ | annotations | A list of annotations to be overlaid on the PDF. Format is described [here](#annotation-format). |
82
+ | pages_vertical_spacing | The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels. |
83
+ | annotation_outline_size | Size of the outline around each annotation in pixels. Defaults to 1 pixel. |
84
+ | rendering | Type of rendering: `unwrap` (default), `legacy_iframe`, or `legacy_embed`. The default value, `unwrap` shows the PDF document using pdf.js, and supports the visualisation of annotations. Other values are `legacy_iframe` and `legacy_embed` which use the legacy approach of injecting the document into an `<embed>` or `<iframe>`. They allow viewing the PDF using the viewer of the browser that contains additional features we are still working to implement in this component. **IMPORTANT**: :warning: The "legacy" methods **work only with Firefox**, and **do not support annotations**. :warning: |
85
+ | pages_to_render | Filter the rendering to a specific set of pages. By default, all pages are rendered. |
86
+ | render_text | Enable a layer of text on top of the PDF document. The text may be selected and copied. **NOTE** to avoid breaking existing deployments, we made this optional at first, also considering that having many annotations might interfere with the copy-paste. |
87
+ | scroll_to_page | Scroll to a specific page when the component is rendered. Default is None. Require ints and ignores the parameters below zero. |
88
+ | scroll_to_annotation | Scroll to a specific annotation when the component is rendered. Default is None. Mutually exclusive with `scroll_to_page`. Raise an exception if used with `scroll_to_page` |
89
+ | on_annotation_click | Callback function that is called when an annotation is clicked. The function receives the annotation as a parameter. |
90
90
 
91
91
  ### Annotation format
92
92
  The annotations format has been derived from the [Grobid's coordinate formats](https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/), which are described as a list of "bounding boxes".
@@ -109,7 +109,7 @@ Here an example:
109
109
 
110
110
  The example shown in our screenshot can be found [here](resources/annotations.json).
111
111
 
112
- ### How to use on_annotation_click
112
+ ### Custom callback for clicking on annotations
113
113
 
114
114
  ```python
115
115
  from streamlit_pdf_viewer import pdf_viewer
@@ -145,8 +145,6 @@ pdf_viewer(
145
145
  ```
146
146
 
147
147
 
148
- ###
149
-
150
148
  ## Developers notes
151
149
 
152
150
  ### Environment
@@ -14,12 +14,13 @@ You can see an [application](https://github.com/lfoppiano/structure-vision) in a
14
14
  ## Features
15
15
  - Show PDF files in a Streamlit application with a simple command
16
16
  - Based on the pdf.js library
17
- - Support showing the PDF with the native pdf.js browser's viewer: "legacy" (with limitations, no annotations, no scrolling, etc..)
18
17
  - Visualize annotations on top of the PDF documents
19
18
  - Render text on top of the PDF document, allowing copy-paste
20
19
  - Allow to render specific pages of the PDF document
21
20
  - Scroll to a specific page
22
21
  - Scroll to a specific annotation
22
+ - Allow custom callbacks when an annotation is clicked
23
+ - Additional support showing PDF documents using the native pdf.js browser's viewer: "legacy" (with limitations, no annotations, no scrolling, etc..)
23
24
 
24
25
  ## Limitations
25
26
  - Tested and developed to support Firefox and Chrome.
@@ -28,8 +29,7 @@ You can see an [application](https://github.com/lfoppiano/structure-vision) in a
28
29
  - The component is still in development, so expect some bugs and limitations
29
30
  - The streamlit reload at each action may render slowly for complex PDF documents
30
31
 
31
- ## Caveats
32
-
32
+ ## Caveats
33
33
  Here some caveats to be aware of:
34
34
  - It ss mandatory to specify a `width` to show PDF document on tabs and expanders, otherwise, the viewer will not be displayed on tabs not immediately visible.
35
35
  - From version 0.0.16, the behavior for managing width and height has changed:
@@ -59,20 +59,20 @@ pdf_viewer("str, path or bytes")
59
59
 
60
60
  In the following table the list of parameters that can be provided to the `pdf_viewer` function:
61
61
 
62
- | name | description |
63
- |-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
64
- | input | The source of the PDF file. Accepts a file path, URL, or binary data. |
65
- | width | Width of the PDF viewer in pixels. It defaults to 700 pixels. |
66
- | height | Height of the PDF viewer in pixels. If not provided, the viewer shows the whole content. |
67
- | annotations | A list of annotations to be overlaid on the PDF. Format is described [here](#annotation-format). |
68
- | pages_vertical_spacing | The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels. |
69
- | annotation_outline_size | Size of the outline around each annotation in pixels. Defaults to 1 pixel. |
70
- | rendering | Type of rendering: `unwrap` (default), `legacy_iframe`, or `legacy_embed`. The default value, `unwrap` shows the PDF document using pdf.js, and supports the visualisation of annotations. Other values are `legacy_iframe` and `legacy_embed` which use the legacy approach of injecting the document into an `<embed>` or `<iframe>`. They allow viewing the PDF using the viewer of the browser that contains additional features we are still working to implement in this component. **IMPORTANT**: :warning: The "legacy" methods **work only with Firefox**, and **do not support annotations**. :warning: |
71
- | pages_to_render | Filter the rendering to a specific set of pages. By default, all pages are rendered. |
72
- | render_text | Enable a layer of text on top of the PDF document. The text may be selected and copied. **NOTE** to avoid breaking existing deployments, we made this optional at first, also considering that having many annotations might interfere with the copy-paste.
73
- | scroll_to_page | Scroll to a specific page when the component is rendered. Default is None. Require ints and ignores the parameters below zero. |
74
- | scroll_to_annotation | Scroll to a specific annotation when the component is rendered. Default is None. Mutually exclusive with `scroll_to_page`. Raise an exception if used with `scroll_to_page` |
75
- | on_annotation_click | Callback function that is called when an annotation is clicked. The function receives the annotation as a parameter. |
62
+ | name | description |
63
+ |---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
64
+ | input | The source of the PDF file. Accepts a file path, URL, or binary data. |
65
+ | width | Width of the PDF viewer in pixels. It defaults to 700 pixels. Can set it to string percentage also. For example 90% which will make the pdf render to 90% of the container/window/screen width. If the pdf width is larger than the screen width, it will horizontally scroll. |
66
+ | height | Height of the PDF viewer in pixels. If not provided, the viewer shows the whole content. |
67
+ | annotations | A list of annotations to be overlaid on the PDF. Format is described [here](#annotation-format). |
68
+ | pages_vertical_spacing | The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels. |
69
+ | annotation_outline_size | Size of the outline around each annotation in pixels. Defaults to 1 pixel. |
70
+ | rendering | Type of rendering: `unwrap` (default), `legacy_iframe`, or `legacy_embed`. The default value, `unwrap` shows the PDF document using pdf.js, and supports the visualisation of annotations. Other values are `legacy_iframe` and `legacy_embed` which use the legacy approach of injecting the document into an `<embed>` or `<iframe>`. They allow viewing the PDF using the viewer of the browser that contains additional features we are still working to implement in this component. **IMPORTANT**: :warning: The "legacy" methods **work only with Firefox**, and **do not support annotations**. :warning: |
71
+ | pages_to_render | Filter the rendering to a specific set of pages. By default, all pages are rendered. |
72
+ | render_text | Enable a layer of text on top of the PDF document. The text may be selected and copied. **NOTE** to avoid breaking existing deployments, we made this optional at first, also considering that having many annotations might interfere with the copy-paste. |
73
+ | scroll_to_page | Scroll to a specific page when the component is rendered. Default is None. Require ints and ignores the parameters below zero. |
74
+ | scroll_to_annotation | Scroll to a specific annotation when the component is rendered. Default is None. Mutually exclusive with `scroll_to_page`. Raise an exception if used with `scroll_to_page` |
75
+ | on_annotation_click | Callback function that is called when an annotation is clicked. The function receives the annotation as a parameter. |
76
76
 
77
77
  ### Annotation format
78
78
  The annotations format has been derived from the [Grobid's coordinate formats](https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/), which are described as a list of "bounding boxes".
@@ -95,7 +95,7 @@ Here an example:
95
95
 
96
96
  The example shown in our screenshot can be found [here](resources/annotations.json).
97
97
 
98
- ### How to use on_annotation_click
98
+ ### Custom callback for clicking on annotations
99
99
 
100
100
  ```python
101
101
  from streamlit_pdf_viewer import pdf_viewer
@@ -131,8 +131,6 @@ pdf_viewer(
131
131
  ```
132
132
 
133
133
 
134
- ###
135
-
136
134
  ## Developers notes
137
135
 
138
136
  ### Environment
@@ -27,7 +27,7 @@ else:
27
27
 
28
28
  def pdf_viewer(
29
29
  input: Union[str, Path, bytes],
30
- width: int = None,
30
+ width: Union[str,int] = None,
31
31
  height: int = None,
32
32
  key=None,
33
33
  annotations: list = (),
@@ -69,8 +69,13 @@ def pdf_viewer(
69
69
  """
70
70
 
71
71
  # Validate width and height parameters
72
- if width is not None and not isinstance(width, int):
73
- raise TypeError("Width must be an integer")
72
+ if width is not None:
73
+ if isinstance(width, str):
74
+ # Check if the string is a valid integer or ends with '%'
75
+ if not (width.isdigit() or width.endswith('%')):
76
+ raise ValueError("Width must be an integer or a percentage string (e.g., '50%')")
77
+ elif not isinstance(width, int):
78
+ raise TypeError("Width must be an integer or a string")
74
79
  if height is not None and not isinstance(height, int):
75
80
  raise TypeError("Height must be an integer or None")
76
81
  if not all(isinstance(page, int) for page in pages_to_render):
@@ -232,4 +237,4 @@ if not _RELEASE:
232
237
  # if id == 0:
233
238
  # pdf_viewer(path, width=500, render_text=True)
234
239
  # else:
235
- # pdf_viewer(path, width=1000, render_text=True)
240
+ # pdf_viewer(path, width=1000, render_text=True)
@@ -1 +1 @@
1
- <!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>streamlit_pdf_viewer</title><script defer="defer" src="js/chunk-vendors.72a36d5a.js"></script><script defer="defer" src="js/app.ebc5e2f4.js"></script><link href="css/chunk-vendors.8a2a8d65.css" rel="stylesheet"><link href="css/app.1df382f3.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but streamlit_pdf_viewer doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>streamlit_pdf_viewer</title><script defer="defer" src="js/chunk-vendors.72a36d5a.js"></script><script defer="defer" src="js/app.16af2f06.js"></script><link href="css/chunk-vendors.8a2a8d65.css" rel="stylesheet"><link href="css/app.1df382f3.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but streamlit_pdf_viewer doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
@@ -0,0 +1,2 @@
1
+ (()=>{"use strict";var e={914:(e,t,n)=>{var a=n(3751),r=n(641);const i={id:"app"};function o(e,t,n,a,o,s){const l=(0,r.g2)("PdfViewer"),d=(0,r.g2)("WithStreamlitConnection");return(0,r.uX)(),(0,r.CE)("div",i,[(0,r.bF)(d,null,{default:(0,r.k6)((({args:e})=>[(0,r.bF)(l,{args:e},null,8,["args"])])),_:1})])}var s=n(33);const l={key:0},d={key:0,id:"pdfAnnotations"},c=["onClick"],p=["id"],g={key:1},u=["src","width","height"],h={key:2},v=["src","width","height"],f={key:3};function w(e,t,n,a,i,o){return(0,r.uX)(),(0,r.CE)("div",{id:"pdfContainer",style:(0,s.Tr)(a.pdfContainerStyle)},["unwrap"===n.args.rendering?((0,r.uX)(),(0,r.CE)("div",l,[(0,r.Lk)("div",{id:"pdfViewer",style:(0,s.Tr)(a.pdfViewerStyle)},[n.args.annotations?((0,r.uX)(),(0,r.CE)("div",d,[((0,r.uX)(!0),(0,r.CE)(r.FK,null,(0,r.pI)(a.filteredAnnotations,((e,t)=>((0,r.uX)(),(0,r.CE)("div",{key:t,style:(0,s.Tr)(a.getPageStyle),onClick:n=>a.handleAnnotationClick(e,t)},[(0,r.Lk)("div",{style:(0,s.Tr)(a.getAnnotationStyle(e,t)),id:`annotation-${t}`},null,12,p)],12,c)))),128))])):(0,r.Q3)("",!0)],4)])):"legacy_embed"===n.args.rendering?((0,r.uX)(),(0,r.CE)("div",g,[(0,r.Lk)("embed",{src:`data:application/pdf;base64,${n.args.binary}`,width:`${n.args.width}`,height:`${n.args.height}`,type:"application/pdf"},null,8,u)])):"legacy_iframe"===n.args.rendering?((0,r.uX)(),(0,r.CE)("div",h,[(0,r.Lk)("embed",{src:`data:application/pdf;base64,${n.args.binary}`,width:`${n.args.width}`,height:`${n.args.height}`,type:"application/pdf"},null,8,v)])):((0,r.uX)(),(0,r.CE)("div",f," Error rendering option. "))],4)}n(4114),n(7642),n(8004),n(3853),n(5876),n(2475),n(5024),n(1698),n(8992),n(4520);var m=n(953),y=(n(951),n(9936)),_=n(7445);const E="pdfjs-dist/cmaps/",b=!0,C=!0,k={props:["args"],setup(e){const t=(0,m.KR)(0),n=(0,m.KR)(0),a=(0,m.KR)([]),i=(0,m.KR)([]),o=(0,m.KR)([]),s=(0,m.KR)([]),l=0===e.args.pages_to_render.length,d=(0,r.EW)((()=>l?e.args.annotations:e.args.annotations.filter((t=>e.args.pages_to_render.includes(Number(t.page)))))),c=(e,t)=>{const n=JSON.parse(JSON.stringify(e));_.wk.setComponentValue({clicked_annotation:{index:t,...n}})},p=!0===e.args.render_text,g=(0,r.EW)((()=>{const t=(e,t)=>"string"===typeof e&&e.endsWith("%")?e:"number"===typeof e||"string"===typeof e&&/^\d+$/.test(e)?`${e}px`:t;return{width:t(e.args.width,`${n.value}px`),height:e.args.height?`${e.args.height}px`:"auto",overflow:"auto"}})),u={position:"relative"},h={position:"relative"},v=t=>{let n=0;if(l)for(let r=0;r<t-1;r++)n+=i.value[r]*a.value[r]+e.args.pages_vertical_spacing;else for(let r=0;r<i.value.length;r++)e.args.pages_to_render.includes(r+1)&&r<t-1&&(n+=i.value[r]*a.value[r]+e.args.pages_vertical_spacing);return n},f=(t,n)=>{const r=a.value[t.page-1],i={position:"absolute",left:t.x*r+"px",top:`${v(t.page)+t.y*r}px`,width:t.width*r+"px",height:t.height*r+"px",outline:e.args.annotation_outline_size*r+"px solid",outlineColor:t.color,cursor:"pointer","z-index":1};return n&&s.value.push(`annotation-${n}`),i},w=e=>{const t=e?.getElementsByTagName("canvas");for(let n=t.length-1;n>=0;n--)e?.removeChild(t.item(n))},k=(t,n,a,r,i=1)=>{const o=t.getViewport({scale:n,rotation:a}),s=(window.devicePixelRatio||1)*i,l=document.createElement("canvas");return l.id=`canvas_page_${r}`,l.height=o.height*s+e.args.pages_vertical_spacing,l.width=o.width*s,l.style.width=o.width+"px",l.style.height=o.height+"px",l.style.display="block",l.style.marginBottom=`${e.args.pages_vertical_spacing}px`,l.getContext("2d").scale(s,s),l},x=async(e,t,n)=>{const a={canvasContext:t.getContext("2d"),viewport:n};try{const t=e.render(a);await t.promise.catch((function(e){}))}catch(r){}if(p){const a=await e.getTextContent(),r=document.createElement("div");r.className="textLayer",r.style="z-index: 2";const i=new y.D6({textContentSource:a,container:r,viewport:n,textDivs:[]});await i.render(),requestAnimationFrame((async()=>{const e=document.createElement("div");e.className="page";const n=document.createElement("div");n.className="canvasWrapper",n.appendChild(t),e.style="position: relative;";const a=document.getElementById("pdfViewer");e.appendChild(n),e.appendChild(r),a.appendChild(e)}))}else requestAnimationFrame((()=>{const e=document.createElement("div");e.className="page";const n=document.createElement("div");n.className="canvasWrapper",n.appendChild(t),e.style="position: relative;",e.appendChild(n),pdfViewer.appendChild(e)}))},$=async(r,s,l=null)=>{if(0===l.length){l=[];for(let e=0;e<r.numPages;e++)l.push(e+1)}let d=1;e.args.resolution_boost&&(d=e.args.resolution_boost);for(let c=1;c<=r.numPages;c++){const p=await r.getPage(c),g=p.rotate,u=p.getViewport({scale:1,rotation:g});if(e.args.height>0){const t=u.width/u.height,a=t*e.args.height;(0===n.value||a<n.value)&&(n.value=a)}const h=n.value/u.width;if(a.value.push(h),i.value.push(u.height),l.includes(c)){const e=k(p,h,g,c,d);s.style.setProperty("--scale-factor",h);const n=p.getViewport({scale:a.value[p._pageIndex],rotation:p.rotate,intent:"print"}),r=(window.devicePixelRatio||1)*d;t.value+=e.height/r,await x(p,e,n),void 0!==e.id&&o.value.push(e.id)}}l.length>0&&(t.value-=e.args.pages_vertical_spacing)},S=e=>{window.alert(e.message),console.error(e)},V=async t=>{y.EA.workerSrc="pdfjs-dist/build/pdf.worker.mjs";try{const n=await(0,y.YE)({url:t,cMapUrl:E,cMapPacked:b,enableXfa:C}),a=document.getElementById("pdfViewer");w(a);const r=await n.promise;await $(r,a,e.args.pages_to_render)}catch(n){S(n)}},N=()=>{if(e.args.scroll_to_page){const t=document.getElementById(`canvas_page_${e.args.scroll_to_page}`);t&&t.scrollIntoView({behavior:"smooth"})}else if(e.args.scroll_to_annotation){const t=document.getElementById("annotation-"+(e.args.scroll_to_annotation-1));t&&t.scrollIntoView({behavior:"smooth",block:"center"})}},R=()=>{const e=new Set,t=new Set;let n;for(n=0;n<s.value.length;n++)t.add(s.value[n]);for(n=0;n<o.value.length;n++)e.add(o.value[n])},A=()=>{_.wk.setFrameHeight(e.args.height||t.value)},O=()=>{const{width:t}=e.args,a=e=>{if("string"===typeof e&&e.endsWith("%")){const t=parseFloat(e)/100;return Math.floor(window.innerWidth*t)}return Number.isInteger(Number(e))?Number(e):window.innerWidth};if(null===t||void 0===t)n.value=window.innerWidth;else{const e=a(t);n.value=Math.min(e,window.innerWidth)}};return(0,r.sV)((()=>{const t=`data:application/pdf;base64,${e.args.binary}`;O(),"unwrap"===e.args.rendering?V(t).then(A).then(R):A()})),(0,r.$u)((()=>{A(),O(),"unwrap"===e.args.rendering&&N()})),{filteredAnnotations:d,handleAnnotationClick:c,getAnnotationStyle:f,pdfContainerStyle:g,pdfViewerStyle:u,getPageStyle:h}}};var x=n(6262);const $=(0,x.A)(k,[["render",w]]),S=$,V={key:0},N={class:"err__msg"};function R(e,t,n,a,i,o){return(0,r.uX)(),(0,r.CE)("div",null,[""!=e.componentError?((0,r.uX)(),(0,r.CE)("div",V,[t[0]||(t[0]=(0,r.Lk)("h1",{class:"err__title"},"Component Error",-1)),(0,r.Lk)("div",N,"Message: "+(0,s.v_)(e.componentError),1)])):null!=e.renderData?(0,r.RG)(e.$slots,"default",{key:1,args:e.renderData.args,disabled:e.renderData.disabled},void 0,!0):(0,r.Q3)("",!0)])}const A=(0,r.pM)({name:"WithStreamlitConnection",setup(){const e=(0,m.KR)(void 0),t=(0,m.KR)(""),n=n=>{const a=n;e.value=a.detail,t.value=""};return(0,r.sV)((()=>{_.wk.events.addEventListener(_.wk.RENDER_EVENT,n),_.wk.setComponentReady()})),(0,r.$u)((()=>{""!=t.value&&_.wk.setFrameHeight()})),(0,r.hi)((()=>{_.wk.events.removeEventListener(_.wk.RENDER_EVENT,n)})),(0,r.qG)((e=>{t.value=String(e)})),{renderData:e,componentError:t}}}),O=(0,x.A)(A,[["render",R],["__scopeId","data-v-bef81972"]]),P=O,W=(0,r.pM)({name:"App",components:{PdfViewer:S,WithStreamlitConnection:P}}),X=(0,x.A)(W,[["render",o]]),I=X;(0,a.Ef)(I).mount("#app")}},t={};function n(a){var r=t[a];if(void 0!==r)return r.exports;var i=t[a]={exports:{}};return e[a].call(i.exports,i,i.exports,n),i.exports}n.m=e,(()=>{var e=[];n.O=(t,a,r,i)=>{if(!a){var o=1/0;for(c=0;c<e.length;c++){for(var[a,r,i]=e[c],s=!0,l=0;l<a.length;l++)(!1&i||o>=i)&&Object.keys(n.O).every((e=>n.O[e](a[l])))?a.splice(l--,1):(s=!1,i<o&&(o=i));if(s){e.splice(c--,1);var d=r();void 0!==d&&(t=d)}}return t}i=i||0;for(var c=e.length;c>0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[a,r,i]}})(),(()=>{n.d=(e,t)=>{for(var a in t)n.o(t,a)&&!n.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})}})(),(()=>{n.g=function(){if("object"===typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"===typeof window)return window}}()})(),(()=>{n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{var e={524:0};n.O.j=t=>0===e[t];var t=(t,a)=>{var r,i,[o,s,l]=a,d=0;if(o.some((t=>0!==e[t]))){for(r in s)n.o(s,r)&&(n.m[r]=s[r]);if(l)var c=l(n)}for(t&&t(a);d<o.length;d++)i=o[d],n.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return n.O(c)},a=self["webpackChunkstreamlit_pdf_viewer"]=self["webpackChunkstreamlit_pdf_viewer"]||[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();var a=n.O(void 0,[504],(()=>n(914)));a=n.O(a)})();
2
+ //# sourceMappingURL=app.16af2f06.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js/app.16af2f06.js","mapp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2J,EAAS+B,MAAMlR,GAAgC,IAAxB2Q,EAAgB3Q,KAAa,CACtD,IAAIyO,KAAYuC,EACZxC,EAAoBwB,EAAEgB,EAAavC,KACrCD,EAAoBO,EAAEN,GAAYuC,EAAYvC,IAGhD,GAAGwC,EAAS,IAAI/B,EAAS+B,EAAQzC,EAClC,CAEA,IADGsC,GAA4BA,EAA2BC,GACrDvL,EAAI2J,EAASnL,OAAQwB,IACzBoL,EAAUzB,EAAS3J,GAChBgJ,EAAoBwB,EAAEW,EAAiBC,IAAYD,EAAgBC,IACrED,EAAgBC,GAAS,KAE1BD,EAAgBC,GAAW,EAE5B,OAAOpC,EAAoBS,EAAEC,EAAO,EAGjCiC,EAAqBC,KAAK,oCAAsCA,KAAK,qCAAuC,GAChHD,EAAmBE,QAAQR,EAAqBS,KAAK,KAAM,IAC3DH,EAAmB7K,KAAOuK,EAAqBS,KAAK,KAAMH,EAAmB7K,KAAKgL,KAAKH,G,KC7CvF,IAAII,EAAsB/C,EAAoBS,OAAE/E,EAAW,CAAC,MAAM,IAAOsE,EAAoB,OAC7F+C,EAAsB/C,EAAoBS,EAAEsC,E","sources":["webpack://streamlit_pdf_viewer/./src/App.vue?9ab1","webpack://streamlit_pdf_viewer/./src/App.vue","webpack://streamlit_pdf_viewer/./src/PdfViewer.vue","webpack://streamlit_pdf_viewer/./src/PdfViewer.vue?f557","webpack://streamlit_pdf_viewer/./src/streamlit/WithStreamlitConnection.vue?8d46","webpack://streamlit_pdf_viewer/./src/streamlit/WithStreamlitConnection.vue","webpack://streamlit_pdf_viewer/./src/streamlit/WithStreamlitConnection.vue?1dfc","webpack://streamlit_pdf_viewer/./src/App.vue?7ccd","webpack://streamlit_pdf_viewer/./src/main.ts","webpack://streamlit_pdf_viewer/webpack/bootstrap","webpack://streamlit_pdf_viewer/webpack/runtime/chunk loaded","webpack://streamlit_pdf_viewer/webpack/runtime/define property getters","webpack://streamlit_pdf_viewer/webpack/runtime/global","webpack://streamlit_pdf_viewer/webpack/runtime/hasOwnProperty shorthand","webpack://streamlit_pdf_viewer/webpack/runtime/jsonp chunk loading","webpack://streamlit_pdf_viewer/webpack/startup"],"sourcesContent":["import { resolveComponent as _resolveComponent, createVNode as _createVNode, withCtx as _withCtx, openBlock as _openBlock, createElementBlock as _createElementBlock } from \"vue\"\n\nconst _hoisted_1 = { id: \"app\" }\n\nexport function render(_ctx: any,_cache: any,$props: any,$setup: any,$data: any,$options: any) {\n const _component_PdfViewer = _resolveComponent(\"PdfViewer\")!\n const _component_WithStreamlitConnection = _resolveComponent(\"WithStreamlitConnection\")!\n\n return (_openBlock(), _createElementBlock(\"div\", _hoisted_1, [\n _createVNode(_component_WithStreamlitConnection, null, {\n default: _withCtx(({ args }) => [\n _createVNode(_component_PdfViewer, { args: args }, null, 8, [\"args\"])\n ]),\n _: 1\n })\n ]))\n}","<!-- \n We bootstrap our Component to Streamlit with our scoped slot in the top-level App.\n This is where scoped slot passes Streamlit `args` data from itself to children MyComponent.\n You should not have to edit this, but are free to do so :)\n-->\n<template>\n <div id=\"app\">\n <WithStreamlitConnection v-slot=\"{ args }\">\n <PdfViewer :args=\"args\" />\n </WithStreamlitConnection>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent } from \"vue\"\nimport PdfViewer from \"./PdfViewer.vue\"\n\n// \"withStreamlitConnection\" is a scoped slot. It bootstraps the\n// connection between your component and the Streamlit app, and handles\n// passing arguments from Python -> Component.\n//\n// You don't need to edit withStreamlitConnection (but you're welcome to!).\nimport WithStreamlitConnection from \"./streamlit/WithStreamlitConnection.vue\"\n\nexport default defineComponent({\n name: \"App\",\n components: {\n PdfViewer,\n WithStreamlitConnection,\n },\n})\n</script>\n\n<style>\nbody {\n margin: 0;\n}\n#app {\n font-family: Avenir, Helvetica, Arial, sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n color: #2c3e50;\n}\n</style>\n","<template>\n <div id=\"pdfContainer\" :style=\"pdfContainerStyle\">\n <div v-if=\"args.rendering==='unwrap'\">\n <div id=\"pdfViewer\" :style=\"pdfViewerStyle\">\n <div id=\"pdfAnnotations\" v-if=\"args.annotations\">\n <div\n v-for=\"(annotation, index) in filteredAnnotations\"\n :key=\"index\"\n :style=\"getPageStyle\"\n @click=\"handleAnnotationClick(annotation, index)\"\n >\n <div\n :style=\"getAnnotationStyle(annotation, index)\"\n :id=\"`annotation-${index}`\"\n ></div>\n </div>\n </div>\n </div>\n </div>\n <div v-else-if=\"args.rendering==='legacy_embed'\">\n <embed :src=\"`data:application/pdf;base64,${args.binary}`\" :width=\"`${args.width}`\" :height=\"`${args.height}`\" type=\"application/pdf\"/>\n </div>\n <div v-else-if=\"args.rendering==='legacy_iframe'\">\n <embed :src=\"`data:application/pdf;base64,${args.binary}`\" :width=\"`${args.width}`\" :height=\"`${args.height}`\" type=\"application/pdf\"/>\n </div>\n <div v-else>\n Error rendering option.\n </div>\n </div>\n</template>\n\n<script>\nimport { onMounted, onUpdated, computed, ref} from \"vue\";\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport \"pdfjs-dist/build/pdf.worker.mjs\";\nimport {getDocument} from \"pdfjs-dist/build/pdf\";\nimport {Streamlit} from \"streamlit-component-lib\";\nimport * as pdfjsLib from \"pdfjs-dist\";\n\nconst CMAP_URL = \"pdfjs-dist/cmaps/\";\nconst CMAP_PACKED = true;\nconst ENABLE_XFA = true;\n\nexport default {\n props: [\"args\"],\n\n setup(props) {\n const totalHeight = ref(0);\n const maxWidth = ref(0);\n const pageScales = ref([]);\n const pageHeights = ref([]);\n const loadedPages = ref([]);\n const loadedAnnotations = ref([]);\n\n const isRenderingAllPages = props.args.pages_to_render.length === 0;\n\n const filteredAnnotations = computed(() => {\n if (isRenderingAllPages) {\n return props.args.annotations;\n }\n return props.args.annotations.filter(anno => {\n return props.args.pages_to_render.includes(Number(anno.page))\n })\n });\n\n const handleAnnotationClick = (annotation, index) => {\n // Convert the Proxy object to a plain object\n const serializedAnnotation = JSON.parse(JSON.stringify(annotation));\n\n // Send data to Streamlit\n Streamlit.setComponentValue({\n clicked_annotation: { index, ...serializedAnnotation },\n });\n };\n\n const renderText = props.args.render_text === true\n\n const pdfContainerStyle = computed(() => {\n const getStyleValue = (value, defaultValue) => {\n if (typeof value === 'string' && value.endsWith('%')) {\n return value; // Use percentage as is\n } else if (typeof value === 'number' || (typeof value === 'string' && /^\\d+$/.test(value))) {\n return `${value}px`; // Append 'px' for numeric values\n }\n return defaultValue; // Use default if value is not valid\n };\n\n return {\n width: getStyleValue(props.args.width, `${maxWidth.value}px`),\n height: props.args.height ? `${props.args.height}px` : 'auto',\n overflow: 'auto',\n };\n });\n\n const pdfViewerStyle = {position: 'relative'};\n const getPageStyle = {position: 'relative'};\n\n const calculatePdfsHeight = (page) => {\n let height = 0;\n if (isRenderingAllPages) {\n for (let i = 0; i < page - 1; i++) {\n height += pageHeights.value[i] * pageScales.value[i] + props.args.pages_vertical_spacing; // Add margin for each page\n }\n } else {\n for (let i = 0; i < pageHeights.value.length; i++) {\n if (props.args.pages_to_render.includes(i + 1) && i < page - 1) {\n height += pageHeights.value[i] * pageScales.value[i] + props.args.pages_vertical_spacing;\n }\n }\n }\n return height;\n };\n\n const getAnnotationStyle = (annoObj, index) => {\n const scale = pageScales.value[annoObj.page - 1];\n const obj = {\n position: 'absolute',\n left: `${annoObj.x * scale}px`,\n top: `${calculatePdfsHeight(annoObj.page) + annoObj.y * scale}px`,\n width: `${annoObj.width * scale}px`,\n height: `${annoObj.height * scale}px`,\n outline: `${props.args.annotation_outline_size * scale}px solid`,\n outlineColor: annoObj.color,\n cursor: 'pointer',\n 'z-index': 1\n };\n if (index) {\n loadedAnnotations.value.push(`annotation-${index}`);\n }\n return obj\n };\n\n const clearExistingCanvases = (pdfViewer) => {\n const canvases = pdfViewer?.getElementsByTagName(\"canvas\");\n for (let j = canvases.length - 1; j >= 0; j--) {\n pdfViewer?.removeChild(canvases.item(j));\n }\n };\n\n const createCanvasForPage = (page, scale, rotation, pageNumber, resolutionRatioBoost=1) => {\n const viewport = page.getViewport({scale, rotation});\n\n const ratio = (window.devicePixelRatio || 1) * resolutionRatioBoost\n // console.log(ratio)\n\n const canvas = document.createElement(\"canvas\");\n canvas.id = `canvas_page_${pageNumber}`;\n canvas.height = viewport.height * ratio + props.args.pages_vertical_spacing;\n canvas.width = viewport.width * ratio;\n canvas.style.width = viewport.width + 'px';\n canvas.style.height = viewport.height + 'px';\n canvas.style.display = \"block\";\n canvas.style.marginBottom = `${props.args.pages_vertical_spacing}px`;\n canvas.getContext(\"2d\").scale(ratio, ratio);\n return canvas;\n };\n\n\n const renderPage = async (page, canvas, viewport) => {\n const renderContext = {\n canvasContext: canvas.getContext(\"2d\"),\n viewport: viewport\n };\n\n try {\n const renderTask = page.render(renderContext);\n await renderTask.promise.catch(function(error){\n // alertError(error);\n // do nothing\n });\n } catch (e) {\n // do nothing\n }\n\n\n if (renderText) {\n const textContent = await page.getTextContent();\n const textLayerDiv = document.createElement(\"div\");\n textLayerDiv.className = \"textLayer\"\n textLayerDiv.style = \"z-index: 2\"\n // textLayerDiv.style.position = \"absolute\";\n // textLayerDiv.style.height = `${viewport.height}px`;\n // textLayerDiv.style.width = `${viewport.width}px`;\n const textLayer = new pdfjsLib.TextLayer({\n textContentSource: textContent,\n container: textLayerDiv,\n viewport: viewport,\n textDivs: []\n })\n await textLayer.render()\n\n requestAnimationFrame(async () => {\n const pageDiv = document.createElement('div');\n pageDiv.className = 'page';\n\n const canvasWrapper = document.createElement('div');\n canvasWrapper.className = 'canvasWrapper';\n canvasWrapper.appendChild(canvas);\n\n pageDiv.style = \"position: relative;\";\n\n const pdfViewer = document.getElementById(\"pdfViewer\");\n pageDiv.appendChild(canvasWrapper);\n pageDiv.appendChild(textLayerDiv);\n\n pdfViewer.appendChild(pageDiv);\n });\n } else {\n requestAnimationFrame(() => {\n const pageDiv = document.createElement('div');\n pageDiv.className = 'page';\n\n const canvasWrapper = document.createElement('div');\n canvasWrapper.className = 'canvasWrapper';\n canvasWrapper.appendChild(canvas);\n\n pageDiv.style = \"position: relative;\";\n pageDiv.appendChild(canvasWrapper);\n pdfViewer.appendChild(pageDiv);\n });\n }\n };\n\n const renderPdfPages = async (pdf, pdfViewer, pagesToRender = null) => {\n if (pagesToRender.length === 0) {\n pagesToRender = []\n for (let i = 0; i < pdf.numPages; i++) {\n pagesToRender.push(i + 1);\n }\n }\n\n let resolutionBoost = 1\n if (props.args.resolution_boost) {\n resolutionBoost = props.args.resolution_boost\n }\n\n for (let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++) {\n const page = await pdf.getPage(pageNumber)\n const rotation = page.rotate\n // Initial viewport\n const unscaledViewport = page.getViewport({\n scale: 1.0,\n rotation: rotation,\n })\n\n if (props.args.height > 0) {\n const widthScale = unscaledViewport.width / unscaledViewport.height\n const possibleScaledWidth = widthScale * props.args.height\n if (maxWidth.value === 0) {\n maxWidth.value = possibleScaledWidth\n } else if (possibleScaledWidth < maxWidth.value) {\n maxWidth.value = possibleScaledWidth\n }\n }\n\n const scale = maxWidth.value / unscaledViewport.width\n\n pageScales.value.push(scale)\n pageHeights.value.push(unscaledViewport.height)\n if (pagesToRender.includes(pageNumber)) {\n const canvas = createCanvasForPage(page, scale, rotation, pageNumber, resolutionBoost)\n\n // pdfViewer?.append(canvas)\n pdfViewer.style.setProperty('--scale-factor', scale);\n\n const viewport = page.getViewport({\n scale: pageScales.value[page._pageIndex],\n rotation: page.rotate,\n intent: \"print\",\n });\n\n const ratio = (window.devicePixelRatio || 1) * resolutionBoost\n totalHeight.value += canvas.height / ratio\n await renderPage(page, canvas, viewport)\n if (canvas.id !== undefined) {\n loadedPages.value.push(canvas.id)\n }\n }\n }\n // Subtract the margin for the last page as it's not needed\n if (pagesToRender.length > 0) {\n totalHeight.value -= props.args.pages_vertical_spacing;\n }\n };\n\n const alertError = (error) => {\n window.alert(error.message);\n console.error(error);\n };\n\n const loadPdfs = async (url) => {\n pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/build/pdf.worker.mjs';\n try {\n const loadingTask = await getDocument({\n url: url,\n cMapUrl: CMAP_URL,\n cMapPacked: CMAP_PACKED,\n enableXfa: ENABLE_XFA,\n });\n const pdfViewer = document.getElementById(\"pdfViewer\");\n clearExistingCanvases(pdfViewer);\n\n const pdf = await loadingTask.promise;\n await renderPdfPages(pdf, pdfViewer, props.args.pages_to_render);\n } catch (error) {\n alertError(error);\n }\n };\n\n const scrollToItem = () => {\n if (props.args.scroll_to_page) {\n const page = document.getElementById(`canvas_page_${props.args.scroll_to_page}`);\n if (page) {\n page.scrollIntoView({behavior: \"smooth\"});\n }\n } else if (props.args.scroll_to_annotation) {\n const annotation = document.getElementById(`annotation-${props.args.scroll_to_annotation - 1}`);\n if (annotation) {\n annotation.scrollIntoView({behavior: \"smooth\", block: \"center\"});\n }\n }\n };\n\n const collectAndReturnIds = () => {\n const pages_ids = new Set()\n const annotations_ids = new Set()\n\n let j\n\n for (j = 0; j < loadedAnnotations.value.length; j++) {\n annotations_ids.add(loadedAnnotations.value[j]);\n }\n for (j = 0; j < loadedPages.value.length; j++) {\n pages_ids.add(loadedPages.value[j]);\n }\n\n // Streamlit.setComponentValue({\"pages\": Array.from(pages_ids), \"annotations\": Array.from(annotations_ids)})\n }\n\n\n const setFrameHeight = () => {\n Streamlit.setFrameHeight(props.args.height || totalHeight.value);\n };\n\n const setFrameWidth = () => {\n const { width } = props.args;\n \n const calculateWidth = (widthValue) => {\n if (typeof widthValue === 'string' && widthValue.endsWith('%')) {\n // Handle percentage string\n const percentage = parseFloat(widthValue) / 100;\n return Math.floor(window.innerWidth * percentage);\n } else if (Number.isInteger(Number(widthValue))) {\n // Handle integer value\n return Number(widthValue);\n }\n // Default to full window width if invalid input\n return window.innerWidth;\n };\n\n if (width === null || width === undefined) {\n maxWidth.value = window.innerWidth;\n } else {\n const calculatedWidth = calculateWidth(width);\n \n // Ensure the calculated width doesn't exceed the window's inner width\n maxWidth.value = Math.min(calculatedWidth, window.innerWidth);\n }\n };\n\n onMounted(() => {\n const binaryDataUrl = `data:application/pdf;base64,${props.args.binary}`;\n setFrameWidth();\n if (props.args.rendering === \"unwrap\") {\n loadPdfs(binaryDataUrl)\n .then(setFrameHeight)\n .then(collectAndReturnIds)\n // .then(scrollToItem)\n //LF calling setComponentReady seems to be done anyway by the WithStreamlitConnection.vue\n // .then(Streamlit.setComponentReady);\n } else {\n setFrameHeight();\n // Streamlit.setComponentReady();\n }\n });\n\n onUpdated(() => {\n setFrameHeight();\n setFrameWidth();\n if (props.args.rendering === \"unwrap\") {\n scrollToItem();\n }\n });\n\n\n return {\n filteredAnnotations,\n handleAnnotationClick,\n getAnnotationStyle,\n pdfContainerStyle,\n pdfViewerStyle,\n getPageStyle\n };\n },\n};\n</script>\n","import { render } from \"./PdfViewer.vue?vue&type=template&id=56c0b474\"\nimport script from \"./PdfViewer.vue?vue&type=script&lang=js\"\nexport * from \"./PdfViewer.vue?vue&type=script&lang=js\"\n\nimport exportComponent from \"../node_modules/vue-loader/dist/exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__","import { createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, renderSlot as _renderSlot } from \"vue\"\n\nconst _hoisted_1 = { key: 0 }\nconst _hoisted_2 = { class: \"err__msg\" }\n\nexport function render(_ctx: any,_cache: any,$props: any,$setup: any,$data: any,$options: any) {\n return (_openBlock(), _createElementBlock(\"div\", null, [\n (_ctx.componentError != '')\n ? (_openBlock(), _createElementBlock(\"div\", _hoisted_1, [\n _cache[0] || (_cache[0] = _createElementVNode(\"h1\", { class: \"err__title\" }, \"Component Error\", -1)),\n _createElementVNode(\"div\", _hoisted_2, \"Message: \" + _toDisplayString(_ctx.componentError), 1)\n ]))\n : (_ctx.renderData != null)\n ? _renderSlot(_ctx.$slots, \"default\", {\n key: 1,\n args: _ctx.renderData.args,\n disabled: _ctx.renderData.disabled\n }, undefined, true)\n : _createCommentVNode(\"\", true)\n ]))\n}","<template>\n <div>\n <!-- Error boundary. If our wrapped component threw an error, display it. -->\n <div v-if=\"componentError != ''\">\n <h1 class=\"err__title\">Component Error</h1>\n <div class=\"err__msg\">Message: {{ componentError }}</div>\n </div>\n <!-- \n Else render the component slot and pass Streamlit event data in `args` props to it.\n Don't render until we've gotten our first RENDER_EVENT from Streamlit.\n All components get disabled while the app is being re-run, and become re-enabled when the re-run has finished.\n -->\n <slot\n v-else-if=\"renderData != null\"\n :args=\"renderData.args\"\n :disabled=\"renderData.disabled\"\n ></slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport {\n ref,\n defineComponent,\n onMounted,\n onUpdated,\n onUnmounted,\n onErrorCaptured,\n} from \"vue\"\nimport { Streamlit, RenderData } from \"streamlit-component-lib\"\n\nexport default defineComponent({\n name: \"WithStreamlitConnection\",\n setup() {\n const renderData = ref<RenderData>((undefined as unknown) as RenderData)\n const componentError = ref(\"\")\n\n const onRenderEvent = (event: Event): void => {\n const renderEvent = event as CustomEvent<RenderData>\n renderData.value = renderEvent.detail\n componentError.value = \"\"\n }\n\n // Set up event listeners, and signal to Streamlit that we're ready.\n // We won't render the component until we receive the first RENDER_EVENT.\n onMounted(() => {\n Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, onRenderEvent)\n Streamlit.setComponentReady()\n })\n onUpdated(() => {\n // If our slot threw an error, we display it in render(). In this\n // case, the slot won't be mounted and therefore won't call\n // `setFrameHeight` on its own. We do it here so that the rendered\n // error will be visible.\n if (componentError.value != \"\") {\n Streamlit.setFrameHeight()\n }\n })\n onUnmounted(() => {\n Streamlit.events.removeEventListener(\n Streamlit.RENDER_EVENT,\n onRenderEvent\n )\n })\n onErrorCaptured(err => {\n componentError.value = String(err)\n })\n\n return {\n renderData,\n componentError,\n }\n },\n})\n</script>\n\n<style scoped>\n.err__title,\n.err__msg {\n margin: 0;\n}\n</style>\n","import { render } from \"./WithStreamlitConnection.vue?vue&type=template&id=bef81972&scoped=true&ts=true\"\nimport script from \"./WithStreamlitConnection.vue?vue&type=script&lang=ts\"\nexport * from \"./WithStreamlitConnection.vue?vue&type=script&lang=ts\"\n\nimport \"./WithStreamlitConnection.vue?vue&type=style&index=0&id=bef81972&scoped=true&lang=css\"\n\nimport exportComponent from \"../../node_modules/vue-loader/dist/exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render],['__scopeId',\"data-v-bef81972\"]])\n\nexport default __exports__","import { render } from \"./App.vue?vue&type=template&id=6ea7f320&ts=true\"\nimport script from \"./App.vue?vue&type=script&lang=ts\"\nexport * from \"./App.vue?vue&type=script&lang=ts\"\n\nimport \"./App.vue?vue&type=style&index=0&id=6ea7f320&lang=css\"\n\nimport exportComponent from \"../node_modules/vue-loader/dist/exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__","import { createApp } from 'vue'\nimport App from './App.vue'\n\ncreateApp(App).mount('#app')\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n// expose the modules object (__webpack_modules__)\n__webpack_require__.m = __webpack_modules__;\n\n","var deferred = [];\n__webpack_require__.O = (result, chunkIds, fn, priority) => {\n\tif(chunkIds) {\n\t\tpriority = priority || 0;\n\t\tfor(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];\n\t\tdeferred[i] = [chunkIds, fn, priority];\n\t\treturn;\n\t}\n\tvar notFulfilled = Infinity;\n\tfor (var i = 0; i < deferred.length; i++) {\n\t\tvar [chunkIds, fn, priority] = deferred[i];\n\t\tvar fulfilled = true;\n\t\tfor (var j = 0; j < chunkIds.length; j++) {\n\t\t\tif ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {\n\t\t\t\tchunkIds.splice(j--, 1);\n\t\t\t} else {\n\t\t\t\tfulfilled = false;\n\t\t\t\tif(priority < notFulfilled) notFulfilled = priority;\n\t\t\t}\n\t\t}\n\t\tif(fulfilled) {\n\t\t\tdeferred.splice(i--, 1)\n\t\t\tvar r = fn();\n\t\t\tif (r !== undefined) result = r;\n\t\t}\n\t}\n\treturn result;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// no baseURI\n\n// object to store loaded and loading chunks\n// undefined = chunk not loaded, null = chunk preloaded/prefetched\n// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded\nvar installedChunks = {\n\t524: 0\n};\n\n// no chunk on demand loading\n\n// no prefetching\n\n// no preloaded\n\n// no HMR\n\n// no HMR manifest\n\n__webpack_require__.O.j = (chunkId) => (installedChunks[chunkId] === 0);\n\n// install a JSONP callback for chunk loading\nvar webpackJsonpCallback = (parentChunkLoadingFunction, data) => {\n\tvar [chunkIds, moreModules, runtime] = data;\n\t// add \"moreModules\" to the modules object,\n\t// then flag all \"chunkIds\" as loaded and fire callback\n\tvar moduleId, chunkId, i = 0;\n\tif(chunkIds.some((id) => (installedChunks[id] !== 0))) {\n\t\tfor(moduleId in moreModules) {\n\t\t\tif(__webpack_require__.o(moreModules, moduleId)) {\n\t\t\t\t__webpack_require__.m[moduleId] = moreModules[moduleId];\n\t\t\t}\n\t\t}\n\t\tif(runtime) var result = runtime(__webpack_require__);\n\t}\n\tif(parentChunkLoadingFunction) parentChunkLoadingFunction(data);\n\tfor(;i < chunkIds.length; i++) {\n\t\tchunkId = chunkIds[i];\n\t\tif(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {\n\t\t\tinstalledChunks[chunkId][0]();\n\t\t}\n\t\tinstalledChunks[chunkId] = 0;\n\t}\n\treturn __webpack_require__.O(result);\n}\n\nvar chunkLoadingGlobal = self[\"webpackChunkstreamlit_pdf_viewer\"] = self[\"webpackChunkstreamlit_pdf_viewer\"] || [];\nchunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));\nchunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));","// startup\n// Load entry module and return exports\n// This entry module depends on other loaded chunks and execution need to be delayed\nvar __webpack_exports__ = __webpack_require__.O(undefined, [504], () => (__webpack_require__(914)))\n__webpack_exports__ = __webpack_require__.O(__webpack_exports__);\n"],"names":["_hoisted_1","id","render","_ctx","_cache","$props","$setup","$data","$options","_component_PdfViewer","_resolveComponent","_component_WithStreamlitConnection","_openBlock","_createElementBlock","_createVNode","default","_withCtx","args","_","key","style","_normalizeStyle","pdfContainerStyle","rendering","_createElementVNode","pdfViewerStyle","annotations","_hoisted_2","_Fragment","_renderList","filteredAnnotations","annotation","index","getPageStyle","onClick","$event","handleAnnotationClick","getAnnotationStyle","_hoisted_4","_hoisted_3","_createCommentVNode","_hoisted_5","src","binary","width","height","type","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","CMAP_URL","CMAP_PACKED","ENABLE_XFA","props","setup","totalHeight","ref","maxWidth","pageScales","pageHeights","loadedPages","loadedAnnotations","isRenderingAllPages","pages_to_render","length","computed","filter","anno","includes","Number","page","serializedAnnotation","JSON","parse","stringify","Streamlit","setComponentValue","clicked_annotation","renderText","render_text","getStyleValue","value","defaultValue","endsWith","test","overflow","position","calculatePdfsHeight","i","pages_vertical_spacing","annoObj","scale","obj","left","x","top","y","outline","annotation_outline_size","outlineColor","color","cursor","push","clearExistingCanvases","pdfViewer","canvases","getElementsByTagName","j","removeChild","item","createCanvasForPage","rotation","pageNumber","resolutionRatioBoost","viewport","getViewport","ratio","window","devicePixelRatio","canvas","document","createElement","display","marginBottom","getContext","renderPage","async","renderContext","canvasContext","renderTask","promise","catch","error","e","textContent","getTextContent","textLayerDiv","className","textLayer","pdfjsLib","textContentSource","container","textDivs","requestAnimationFrame","pageDiv","canvasWrapper","appendChild","getElementById","renderPdfPages","pdf","pagesToRender","numPages","resolutionBoost","resolution_boost","getPage","rotate","unscaledViewport","widthScale","possibleScaledWidth","setProperty","_pageIndex","intent","undefined","alertError","alert","message","console","loadPdfs","workerSrc","loadingTask","getDocument","url","cMapUrl","cMapPacked","enableXfa","scrollToItem","scroll_to_page","scrollIntoView","behavior","scroll_to_annotation","block","collectAndReturnIds","pages_ids","Set","annotations_ids","add","setFrameHeight","setFrameWidth","calculateWidth","widthValue","percentage","parseFloat","Math","floor","innerWidth","isInteger","calculatedWidth","min","onMounted","binaryDataUrl","then","onUpdated","__exports__","class","componentError","_toDisplayString","renderData","_renderSlot","$slots","disabled","defineComponent","name","onRenderEvent","event","renderEvent","detail","events","addEventListener","RENDER_EVENT","setComponentReady","onUnmounted","removeEventListener","onErrorCaptured","err","String","components","PdfViewer","WithStreamlitConnection","createApp","App","mount","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","exports","module","__webpack_modules__","call","m","deferred","O","result","chunkIds","fn","priority","notFulfilled","Infinity","fulfilled","Object","keys","every","splice","r","d","definition","o","defineProperty","enumerable","get","g","globalThis","this","Function","prop","prototype","hasOwnProperty","installedChunks","chunkId","webpackJsonpCallback","parentChunkLoadingFunction","data","moreModules","runtime","some","chunkLoadingGlobal","self","forEach","bind","__webpack_exports__"],"sourceRoot":""}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: streamlit-pdf-viewer
3
- Version: 0.0.20.dev0
3
+ Version: 0.0.21.dev0
4
4
  Summary: Streamlit component for PDF visualisation and manipulation
5
5
  Home-page: https://github.com/lfoppiano/streamlit-pdf-viewer
6
6
  Author: Luca Foppiano, Tomoya Mato
@@ -28,12 +28,13 @@ You can see an [application](https://github.com/lfoppiano/structure-vision) in a
28
28
  ## Features
29
29
  - Show PDF files in a Streamlit application with a simple command
30
30
  - Based on the pdf.js library
31
- - Support showing the PDF with the native pdf.js browser's viewer: "legacy" (with limitations, no annotations, no scrolling, etc..)
32
31
  - Visualize annotations on top of the PDF documents
33
32
  - Render text on top of the PDF document, allowing copy-paste
34
33
  - Allow to render specific pages of the PDF document
35
34
  - Scroll to a specific page
36
35
  - Scroll to a specific annotation
36
+ - Allow custom callbacks when an annotation is clicked
37
+ - Additional support showing PDF documents using the native pdf.js browser's viewer: "legacy" (with limitations, no annotations, no scrolling, etc..)
37
38
 
38
39
  ## Limitations
39
40
  - Tested and developed to support Firefox and Chrome.
@@ -42,8 +43,7 @@ You can see an [application](https://github.com/lfoppiano/structure-vision) in a
42
43
  - The component is still in development, so expect some bugs and limitations
43
44
  - The streamlit reload at each action may render slowly for complex PDF documents
44
45
 
45
- ## Caveats
46
-
46
+ ## Caveats
47
47
  Here some caveats to be aware of:
48
48
  - It ss mandatory to specify a `width` to show PDF document on tabs and expanders, otherwise, the viewer will not be displayed on tabs not immediately visible.
49
49
  - From version 0.0.16, the behavior for managing width and height has changed:
@@ -73,20 +73,20 @@ pdf_viewer("str, path or bytes")
73
73
 
74
74
  In the following table the list of parameters that can be provided to the `pdf_viewer` function:
75
75
 
76
- | name | description |
77
- |-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
78
- | input | The source of the PDF file. Accepts a file path, URL, or binary data. |
79
- | width | Width of the PDF viewer in pixels. It defaults to 700 pixels. |
80
- | height | Height of the PDF viewer in pixels. If not provided, the viewer shows the whole content. |
81
- | annotations | A list of annotations to be overlaid on the PDF. Format is described [here](#annotation-format). |
82
- | pages_vertical_spacing | The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels. |
83
- | annotation_outline_size | Size of the outline around each annotation in pixels. Defaults to 1 pixel. |
84
- | rendering | Type of rendering: `unwrap` (default), `legacy_iframe`, or `legacy_embed`. The default value, `unwrap` shows the PDF document using pdf.js, and supports the visualisation of annotations. Other values are `legacy_iframe` and `legacy_embed` which use the legacy approach of injecting the document into an `<embed>` or `<iframe>`. They allow viewing the PDF using the viewer of the browser that contains additional features we are still working to implement in this component. **IMPORTANT**: :warning: The "legacy" methods **work only with Firefox**, and **do not support annotations**. :warning: |
85
- | pages_to_render | Filter the rendering to a specific set of pages. By default, all pages are rendered. |
86
- | render_text | Enable a layer of text on top of the PDF document. The text may be selected and copied. **NOTE** to avoid breaking existing deployments, we made this optional at first, also considering that having many annotations might interfere with the copy-paste.
87
- | scroll_to_page | Scroll to a specific page when the component is rendered. Default is None. Require ints and ignores the parameters below zero. |
88
- | scroll_to_annotation | Scroll to a specific annotation when the component is rendered. Default is None. Mutually exclusive with `scroll_to_page`. Raise an exception if used with `scroll_to_page` |
89
- | on_annotation_click | Callback function that is called when an annotation is clicked. The function receives the annotation as a parameter. |
76
+ | name | description |
77
+ |---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
78
+ | input | The source of the PDF file. Accepts a file path, URL, or binary data. |
79
+ | width | Width of the PDF viewer in pixels. It defaults to 700 pixels. Can set it to string percentage also. For example 90% which will make the pdf render to 90% of the container/window/screen width. If the pdf width is larger than the screen width, it will horizontally scroll. |
80
+ | height | Height of the PDF viewer in pixels. If not provided, the viewer shows the whole content. |
81
+ | annotations | A list of annotations to be overlaid on the PDF. Format is described [here](#annotation-format). |
82
+ | pages_vertical_spacing | The vertical space (in pixels) between each page of the PDF. Defaults to 2 pixels. |
83
+ | annotation_outline_size | Size of the outline around each annotation in pixels. Defaults to 1 pixel. |
84
+ | rendering | Type of rendering: `unwrap` (default), `legacy_iframe`, or `legacy_embed`. The default value, `unwrap` shows the PDF document using pdf.js, and supports the visualisation of annotations. Other values are `legacy_iframe` and `legacy_embed` which use the legacy approach of injecting the document into an `<embed>` or `<iframe>`. They allow viewing the PDF using the viewer of the browser that contains additional features we are still working to implement in this component. **IMPORTANT**: :warning: The "legacy" methods **work only with Firefox**, and **do not support annotations**. :warning: |
85
+ | pages_to_render | Filter the rendering to a specific set of pages. By default, all pages are rendered. |
86
+ | render_text | Enable a layer of text on top of the PDF document. The text may be selected and copied. **NOTE** to avoid breaking existing deployments, we made this optional at first, also considering that having many annotations might interfere with the copy-paste. |
87
+ | scroll_to_page | Scroll to a specific page when the component is rendered. Default is None. Require ints and ignores the parameters below zero. |
88
+ | scroll_to_annotation | Scroll to a specific annotation when the component is rendered. Default is None. Mutually exclusive with `scroll_to_page`. Raise an exception if used with `scroll_to_page` |
89
+ | on_annotation_click | Callback function that is called when an annotation is clicked. The function receives the annotation as a parameter. |
90
90
 
91
91
  ### Annotation format
92
92
  The annotations format has been derived from the [Grobid's coordinate formats](https://grobid.readthedocs.io/en/latest/Coordinates-in-PDF/), which are described as a list of "bounding boxes".
@@ -109,7 +109,7 @@ Here an example:
109
109
 
110
110
  The example shown in our screenshot can be found [here](resources/annotations.json).
111
111
 
112
- ### How to use on_annotation_click
112
+ ### Custom callback for clicking on annotations
113
113
 
114
114
  ```python
115
115
  from streamlit_pdf_viewer import pdf_viewer
@@ -145,8 +145,6 @@ pdf_viewer(
145
145
  ```
146
146
 
147
147
 
148
- ###
149
-
150
148
  ## Developers notes
151
149
 
152
150
  ### Environment
@@ -21,8 +21,8 @@ streamlit_pdf_viewer/frontend/dist/img/cursor-editorTextHighlight.5636640c.svg
21
21
  streamlit_pdf_viewer/frontend/dist/img/editor-toolbar-delete.6694a89f.svg
22
22
  streamlit_pdf_viewer/frontend/dist/img/toolbarButton-editorHighlight.c3287eaa.svg
23
23
  streamlit_pdf_viewer/frontend/dist/img/toolbarButton-menuArrow.37a6145d.svg
24
- streamlit_pdf_viewer/frontend/dist/js/app.ebc5e2f4.js
25
- streamlit_pdf_viewer/frontend/dist/js/app.ebc5e2f4.js.map
24
+ streamlit_pdf_viewer/frontend/dist/js/app.16af2f06.js
25
+ streamlit_pdf_viewer/frontend/dist/js/app.16af2f06.js.map
26
26
  streamlit_pdf_viewer/frontend/dist/js/chunk-vendors.72a36d5a.js
27
27
  streamlit_pdf_viewer/frontend/dist/js/chunk-vendors.72a36d5a.js.map
28
28
  tests/__init__.py
@@ -1,2 +0,0 @@
1
- (()=>{"use strict";var e={5060:(e,t,n)=>{var a=n(3751),r=n(641);const i={id:"app"};function o(e,t,n,a,o,s){const l=(0,r.g2)("PdfViewer"),d=(0,r.g2)("WithStreamlitConnection");return(0,r.uX)(),(0,r.CE)("div",i,[(0,r.bF)(d,null,{default:(0,r.k6)((({args:e})=>[(0,r.bF)(l,{args:e},null,8,["args"])])),_:1})])}var s=n(33);const l={key:0},d={key:0,id:"pdfAnnotations"},c=["onClick"],p=["id"],g={key:1},u=["src","width","height"],h={key:2},v=["src","width","height"],w={key:3};function f(e,t,n,a,i,o){return(0,r.uX)(),(0,r.CE)("div",{id:"pdfContainer",style:(0,s.Tr)(a.pdfContainerStyle)},["unwrap"===n.args.rendering?((0,r.uX)(),(0,r.CE)("div",l,[(0,r.Lk)("div",{id:"pdfViewer",style:(0,s.Tr)(a.pdfViewerStyle)},[n.args.annotations?((0,r.uX)(),(0,r.CE)("div",d,[((0,r.uX)(!0),(0,r.CE)(r.FK,null,(0,r.pI)(a.filteredAnnotations,((e,t)=>((0,r.uX)(),(0,r.CE)("div",{key:t,style:(0,s.Tr)(a.getPageStyle),onClick:n=>a.handleAnnotationClick(e,t)},[(0,r.Lk)("div",{style:(0,s.Tr)(a.getAnnotationStyle(e,t)),id:`annotation-${t}`},null,12,p)],12,c)))),128))])):(0,r.Q3)("",!0)],4)])):"legacy_embed"===n.args.rendering?((0,r.uX)(),(0,r.CE)("div",g,[(0,r.Lk)("embed",{src:`data:application/pdf;base64,${n.args.binary}`,width:`${n.args.width}`,height:`${n.args.height}`,type:"application/pdf"},null,8,u)])):"legacy_iframe"===n.args.rendering?((0,r.uX)(),(0,r.CE)("div",h,[(0,r.Lk)("embed",{src:`data:application/pdf;base64,${n.args.binary}`,width:`${n.args.width}`,height:`${n.args.height}`,type:"application/pdf"},null,8,v)])):((0,r.uX)(),(0,r.CE)("div",w," Error rendering option. "))],4)}n(4114),n(7642),n(8004),n(3853),n(5876),n(2475),n(5024),n(1698),n(8992),n(4520);var m=n(953),y=(n(951),n(9936)),_=n(7445);const E="pdfjs-dist/cmaps/",C=!0,b=!0,k={props:["args"],setup(e){const t=(0,m.KR)(0),n=(0,m.KR)(0),a=(0,m.KR)([]),i=(0,m.KR)([]),o=(0,m.KR)([]),s=(0,m.KR)([]),l=0===e.args.pages_to_render.length,d=(0,r.EW)((()=>l?e.args.annotations:e.args.annotations.filter((t=>e.args.pages_to_render.includes(Number(t.page)))))),c=(e,t)=>{const n=JSON.parse(JSON.stringify(e));_.wk.setComponentValue({clicked_annotation:{index:t,...n}})},p=!0===e.args.render_text,g=(0,r.EW)((()=>({width:e.args.width?`${e.args.width}px`:`${n.value}px`,height:e.args.height?`${e.args.height}px`:"auto",overflow:"auto"}))),u={position:"relative"},h={position:"relative"},v=t=>{let n=0;if(l)for(let r=0;r<t-1;r++)n+=i.value[r]*a.value[r]+e.args.pages_vertical_spacing;else for(let r=0;r<i.value.length;r++)e.args.pages_to_render.includes(r+1)&&r<t-1&&(n+=i.value[r]*a.value[r]+e.args.pages_vertical_spacing);return n},w=(t,n)=>{const r=a.value[t.page-1],i={position:"absolute",left:t.x*r+"px",top:`${v(t.page)+t.y*r}px`,width:t.width*r+"px",height:t.height*r+"px",outline:e.args.annotation_outline_size*r+"px solid",outlineColor:t.color,cursor:"pointer","z-index":1};return n&&s.value.push(`annotation-${n}`),i},f=e=>{const t=e?.getElementsByTagName("canvas");for(let n=t.length-1;n>=0;n--)e?.removeChild(t.item(n))},k=(t,n,a,r,i=1)=>{const o=t.getViewport({scale:n,rotation:a}),s=(window.devicePixelRatio||1)*i,l=document.createElement("canvas");return l.id=`canvas_page_${r}`,l.height=o.height*s+e.args.pages_vertical_spacing,l.width=o.width*s,l.style.width=o.width+"px",l.style.height=o.height+"px",l.style.display="block",l.style.marginBottom=`${e.args.pages_vertical_spacing}px`,l.getContext("2d").scale(s,s),l},x=async(e,t,n)=>{const a={canvasContext:t.getContext("2d"),viewport:n};try{const t=e.render(a);await t.promise.catch((function(e){}))}catch(r){}if(p){const a=await e.getTextContent(),r=document.createElement("div");r.className="textLayer",r.style="z-index: 2";const i=new y.D6({textContentSource:a,container:r,viewport:n,textDivs:[]});await i.render(),requestAnimationFrame((async()=>{const e=document.createElement("div");e.className="page";const n=document.createElement("div");n.className="canvasWrapper",n.appendChild(t),e.style="position: relative;";const a=document.getElementById("pdfViewer");e.appendChild(n),e.appendChild(r),a.appendChild(e)}))}else requestAnimationFrame((()=>{const e=document.createElement("div");e.className="page";const n=document.createElement("div");n.className="canvasWrapper",n.appendChild(t),e.style="position: relative;",e.appendChild(n),pdfViewer.appendChild(e)}))},$=async(r,s,l=null)=>{if(0===l.length){l=[];for(let e=0;e<r.numPages;e++)l.push(e+1)}let d=1;e.args.resolution_boost&&(d=e.args.resolution_boost);for(let c=1;c<=r.numPages;c++){const p=await r.getPage(c),g=p.rotate,u=p.getViewport({scale:1,rotation:g});if(e.args.height>0){const t=u.width/u.height,a=t*e.args.height;(0===n.value||a<n.value)&&(n.value=a)}const h=n.value/u.width;if(a.value.push(h),i.value.push(u.height),l.includes(c)){const e=k(p,h,g,c,d);s.style.setProperty("--scale-factor",h);const n=p.getViewport({scale:a.value[p._pageIndex],rotation:p.rotate,intent:"print"}),r=(window.devicePixelRatio||1)*d;t.value+=e.height/r,await x(p,e,n),void 0!==e.id&&o.value.push(e.id)}}l.length>0&&(t.value-=e.args.pages_vertical_spacing)},S=e=>{window.alert(e.message),console.error(e)},V=async t=>{y.EA.workerSrc="pdfjs-dist/build/pdf.worker.mjs";try{const n=await(0,y.YE)({url:t,cMapUrl:E,cMapPacked:C,enableXfa:b}),a=document.getElementById("pdfViewer");f(a);const r=await n.promise;await $(r,a,e.args.pages_to_render)}catch(n){S(n)}},R=()=>{if(e.args.scroll_to_page){const t=document.getElementById(`canvas_page_${e.args.scroll_to_page}`);t&&t.scrollIntoView({behavior:"smooth"})}else if(e.args.scroll_to_annotation){const t=document.getElementById("annotation-"+(e.args.scroll_to_annotation-1));t&&t.scrollIntoView({behavior:"smooth",block:"center"})}},A=()=>{const e=new Set,t=new Set;let n;for(n=0;n<s.value.length;n++)t.add(s.value[n]);for(n=0;n<o.value.length;n++)e.add(o.value[n])},N=()=>{_.wk.setFrameHeight(e.args.height||t.value)},O=()=>{null===e.args.width||void 0===e.args.width?n.value=window.innerWidth:Number.isInteger(e.args.width)&&(n.value=e.args.width,window.innerWidth>0&&window.innerWidth<n.value&&(n.value=window.innerWidth))};return(0,r.sV)((()=>{const t=`data:application/pdf;base64,${e.args.binary}`;O(),"unwrap"===e.args.rendering?V(t).then(N).then(A):N()})),(0,r.$u)((()=>{N(),"unwrap"===e.args.rendering&&R()})),{filteredAnnotations:d,handleAnnotationClick:c,getAnnotationStyle:w,pdfContainerStyle:g,pdfViewerStyle:u,getPageStyle:h}}};var x=n(6262);const $=(0,x.A)(k,[["render",f]]),S=$,V={key:0},R={class:"err__msg"};function A(e,t,n,a,i,o){return(0,r.uX)(),(0,r.CE)("div",null,[""!=e.componentError?((0,r.uX)(),(0,r.CE)("div",V,[t[0]||(t[0]=(0,r.Lk)("h1",{class:"err__title"},"Component Error",-1)),(0,r.Lk)("div",R,"Message: "+(0,s.v_)(e.componentError),1)])):null!=e.renderData?(0,r.RG)(e.$slots,"default",{key:1,args:e.renderData.args,disabled:e.renderData.disabled},void 0,!0):(0,r.Q3)("",!0)])}const N=(0,r.pM)({name:"WithStreamlitConnection",setup(){const e=(0,m.KR)(void 0),t=(0,m.KR)(""),n=n=>{const a=n;e.value=a.detail,t.value=""};return(0,r.sV)((()=>{_.wk.events.addEventListener(_.wk.RENDER_EVENT,n),_.wk.setComponentReady()})),(0,r.$u)((()=>{""!=t.value&&_.wk.setFrameHeight()})),(0,r.hi)((()=>{_.wk.events.removeEventListener(_.wk.RENDER_EVENT,n)})),(0,r.qG)((e=>{t.value=String(e)})),{renderData:e,componentError:t}}}),O=(0,x.A)(N,[["render",A],["__scopeId","data-v-bef81972"]]),P=O,X=(0,r.pM)({name:"App",components:{PdfViewer:S,WithStreamlitConnection:P}}),W=(0,x.A)(X,[["render",o]]),I=W;(0,a.Ef)(I).mount("#app")}},t={};function n(a){var r=t[a];if(void 0!==r)return r.exports;var i=t[a]={exports:{}};return e[a].call(i.exports,i,i.exports,n),i.exports}n.m=e,(()=>{var e=[];n.O=(t,a,r,i)=>{if(!a){var o=1/0;for(c=0;c<e.length;c++){for(var[a,r,i]=e[c],s=!0,l=0;l<a.length;l++)(!1&i||o>=i)&&Object.keys(n.O).every((e=>n.O[e](a[l])))?a.splice(l--,1):(s=!1,i<o&&(o=i));if(s){e.splice(c--,1);var d=r();void 0!==d&&(t=d)}}return t}i=i||0;for(var c=e.length;c>0&&e[c-1][2]>i;c--)e[c]=e[c-1];e[c]=[a,r,i]}})(),(()=>{n.d=(e,t)=>{for(var a in t)n.o(t,a)&&!n.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})}})(),(()=>{n.g=function(){if("object"===typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"===typeof window)return window}}()})(),(()=>{n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{var e={524:0};n.O.j=t=>0===e[t];var t=(t,a)=>{var r,i,[o,s,l]=a,d=0;if(o.some((t=>0!==e[t]))){for(r in s)n.o(s,r)&&(n.m[r]=s[r]);if(l)var c=l(n)}for(t&&t(a);d<o.length;d++)i=o[d],n.o(e,i)&&e[i]&&e[i][0](),e[i]=0;return n.O(c)},a=self["webpackChunkstreamlit_pdf_viewer"]=self["webpackChunkstreamlit_pdf_viewer"]||[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();var a=n.O(void 0,[504],(()=>n(5060)));a=n.O(a)})();
2
- //# sourceMappingURL=app.ebc5e2f4.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"js/app.ebc5e2f4.js","mappings":"gEAEA,MAAMA,EAAa,CCIZC,GAAG,ODFJ,SAAUC,EAAOC,EAAUC,EAAYC,EAAYC,EAAYC,EAAWC,GAC9E,MAAMC,GAAuBC,EAAAA,EAAAA,IAAkB,aACzCC,GAAqCD,EAAAA,EAAAA,IAAkB,2BAE7D,OAAQE,EAAAA,EAAAA,OCFRC,EAAAA,EAAAA,IAIM,MAJNb,EAIM,EAHJc,EAAAA,EAAAA,IAE0BH,EAAA,MAT9BI,SAAAC,EAAAA,EAAAA,KAQM,EADiCC,UAAI,EACrCH,EAAAA,EAAAA,IAA0BL,EAAA,CAAdQ,KAAMA,GAAI,oBAR5BC,EAAA,KDgBA,C,qBEhBAC,IAAA,G,GAAAA,IAAA,EAIalB,GAAG,kB,EAJhB,Y,EAAA,O,GAAAkB,IAAA,G,EAAA,yB,GAAAA,IAAA,G,EAAA,yB,GAAAA,IAAA,G,0CACEN,EAAAA,EAAAA,IA2BM,OA3BDZ,GAAG,eAAgBmB,OAD1BC,EAAAA,EAAAA,IACiCf,EAAAgB,oB,CACJ,WAAdjB,EAAAY,KAAKM,YAAS,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AAKoK,E,WCKlF,IAAIG,EAAkB,CACrB,IAAK,GAaNnC,EAAoBS,EAAE9H,EAAKyJ,GAA0C,IAA7BD,EAAgBC,GAGxD,IAAIC,EAAuB,CAACC,EAA4BC,KACvD,IAGItC,EAAUmC,GAHTzB,EAAU6B,EAAaC,GAAWF,EAGhB/K,EAAI,EAC3B,GAAGmJ,EAAS+B,MAAMtQ,GAAgC,IAAxB+P,EAAgB/P,KAAa,CACtD,IAAI6N,KAAYuC,EACZxC,EAAoBwB,EAAEgB,EAAavC,KACrCD,EAAoBO,EAAEN,GAAYuC,EAAYvC,IAGhD,GAAGwC,EAAS,IAAI/B,EAAS+B,EAAQzC,EAClC,CAEA,IADGsC,GAA4BA,EAA2BC,GACrD/K,EAAImJ,EAASvK,OAAQoB,IACzB4K,EAAUzB,EAASnJ,GAChBwI,EAAoBwB,EAAEW,EAAiBC,IAAYD,EAAgBC,IACrED,EAAgBC,GAAS,KAE1BD,EAAgBC,GAAW,EAE5B,OAAOpC,EAAoBS,EAAEC,EAAO,EAGjCiC,EAAqBC,KAAK,oCAAsCA,KAAK,qCAAuC,GAChHD,EAAmBE,QAAQR,EAAqBS,KAAK,KAAM,IAC3DH,EAAmBrK,KAAO+J,EAAqBS,KAAK,KAAMH,EAAmBrK,KAAKwK,KAAKH,G,KC7CvF,IAAII,EAAsB/C,EAAoBS,OAAEvE,EAAW,CAAC,MAAM,IAAO8D,EAAoB,QAC7F+C,EAAsB/C,EAAoBS,EAAEsC,E","sources":["webpack://streamlit_pdf_viewer/./src/App.vue?9ab1","webpack://streamlit_pdf_viewer/./src/App.vue","webpack://streamlit_pdf_viewer/./src/PdfViewer.vue","webpack://streamlit_pdf_viewer/./src/PdfViewer.vue?f557","webpack://streamlit_pdf_viewer/./src/streamlit/WithStreamlitConnection.vue?8d46","webpack://streamlit_pdf_viewer/./src/streamlit/WithStreamlitConnection.vue","webpack://streamlit_pdf_viewer/./src/streamlit/WithStreamlitConnection.vue?1dfc","webpack://streamlit_pdf_viewer/./src/App.vue?7ccd","webpack://streamlit_pdf_viewer/./src/main.ts","webpack://streamlit_pdf_viewer/webpack/bootstrap","webpack://streamlit_pdf_viewer/webpack/runtime/chunk loaded","webpack://streamlit_pdf_viewer/webpack/runtime/define property getters","webpack://streamlit_pdf_viewer/webpack/runtime/global","webpack://streamlit_pdf_viewer/webpack/runtime/hasOwnProperty shorthand","webpack://streamlit_pdf_viewer/webpack/runtime/jsonp chunk loading","webpack://streamlit_pdf_viewer/webpack/startup"],"sourcesContent":["import { resolveComponent as _resolveComponent, createVNode as _createVNode, withCtx as _withCtx, openBlock as _openBlock, createElementBlock as _createElementBlock } from \"vue\"\n\nconst _hoisted_1 = { id: \"app\" }\n\nexport function render(_ctx: any,_cache: any,$props: any,$setup: any,$data: any,$options: any) {\n const _component_PdfViewer = _resolveComponent(\"PdfViewer\")!\n const _component_WithStreamlitConnection = _resolveComponent(\"WithStreamlitConnection\")!\n\n return (_openBlock(), _createElementBlock(\"div\", _hoisted_1, [\n _createVNode(_component_WithStreamlitConnection, null, {\n default: _withCtx(({ args }) => [\n _createVNode(_component_PdfViewer, { args: args }, null, 8, [\"args\"])\n ]),\n _: 1\n })\n ]))\n}","<!-- \n We bootstrap our Component to Streamlit with our scoped slot in the top-level App.\n This is where scoped slot passes Streamlit `args` data from itself to children MyComponent.\n You should not have to edit this, but are free to do so :)\n-->\n<template>\n <div id=\"app\">\n <WithStreamlitConnection v-slot=\"{ args }\">\n <PdfViewer :args=\"args\" />\n </WithStreamlitConnection>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport { defineComponent } from \"vue\"\nimport PdfViewer from \"./PdfViewer.vue\"\n\n// \"withStreamlitConnection\" is a scoped slot. It bootstraps the\n// connection between your component and the Streamlit app, and handles\n// passing arguments from Python -> Component.\n//\n// You don't need to edit withStreamlitConnection (but you're welcome to!).\nimport WithStreamlitConnection from \"./streamlit/WithStreamlitConnection.vue\"\n\nexport default defineComponent({\n name: \"App\",\n components: {\n PdfViewer,\n WithStreamlitConnection,\n },\n})\n</script>\n\n<style>\nbody {\n margin: 0;\n}\n#app {\n font-family: Avenir, Helvetica, Arial, sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n color: #2c3e50;\n}\n</style>\n","<template>\n <div id=\"pdfContainer\" :style=\"pdfContainerStyle\">\n <div v-if=\"args.rendering==='unwrap'\">\n <div id=\"pdfViewer\" :style=\"pdfViewerStyle\">\n <div id=\"pdfAnnotations\" v-if=\"args.annotations\">\n <div\n v-for=\"(annotation, index) in filteredAnnotations\"\n :key=\"index\"\n :style=\"getPageStyle\"\n @click=\"handleAnnotationClick(annotation, index)\"\n >\n <div\n :style=\"getAnnotationStyle(annotation, index)\"\n :id=\"`annotation-${index}`\"\n ></div>\n </div>\n </div>\n </div>\n </div>\n <div v-else-if=\"args.rendering==='legacy_embed'\">\n <embed :src=\"`data:application/pdf;base64,${args.binary}`\" :width=\"`${args.width}`\" :height=\"`${args.height}`\" type=\"application/pdf\"/>\n </div>\n <div v-else-if=\"args.rendering==='legacy_iframe'\">\n <embed :src=\"`data:application/pdf;base64,${args.binary}`\" :width=\"`${args.width}`\" :height=\"`${args.height}`\" type=\"application/pdf\"/>\n </div>\n <div v-else>\n Error rendering option.\n </div>\n </div>\n</template>\n\n<script>\nimport { onMounted, onUpdated, computed, ref} from \"vue\";\nimport \"pdfjs-dist/web/pdf_viewer.css\";\nimport \"pdfjs-dist/build/pdf.worker.mjs\";\nimport {getDocument} from \"pdfjs-dist/build/pdf\";\nimport {Streamlit} from \"streamlit-component-lib\";\nimport * as pdfjsLib from \"pdfjs-dist\";\n\nconst CMAP_URL = \"pdfjs-dist/cmaps/\";\nconst CMAP_PACKED = true;\nconst ENABLE_XFA = true;\n\nexport default {\n props: [\"args\"],\n\n setup(props) {\n const totalHeight = ref(0);\n const maxWidth = ref(0);\n const pageScales = ref([]);\n const pageHeights = ref([]);\n const loadedPages = ref([]);\n const loadedAnnotations = ref([]);\n\n const isRenderingAllPages = props.args.pages_to_render.length === 0;\n\n const filteredAnnotations = computed(() => {\n if (isRenderingAllPages) {\n return props.args.annotations;\n }\n return props.args.annotations.filter(anno => {\n return props.args.pages_to_render.includes(Number(anno.page))\n })\n });\n\n const handleAnnotationClick = (annotation, index) => {\n // Convert the Proxy object to a plain object\n const serializedAnnotation = JSON.parse(JSON.stringify(annotation));\n\n // Send data to Streamlit\n Streamlit.setComponentValue({\n clicked_annotation: { index, ...serializedAnnotation },\n });\n };\n\n const renderText = props.args.render_text === true\n\n const pdfContainerStyle = computed(() => ({\n width: props.args.width ? `${props.args.width}px` : `${maxWidth.value}px`,\n height: props.args.height ? `${props.args.height}px` : 'auto',\n overflow: 'auto',\n }));\n\n const pdfViewerStyle = {position: 'relative'};\n const getPageStyle = {position: 'relative'};\n\n const calculatePdfsHeight = (page) => {\n let height = 0;\n if (isRenderingAllPages) {\n for (let i = 0; i < page - 1; i++) {\n height += pageHeights.value[i] * pageScales.value[i] + props.args.pages_vertical_spacing; // Add margin for each page\n }\n } else {\n for (let i = 0; i < pageHeights.value.length; i++) {\n if (props.args.pages_to_render.includes(i + 1) && i < page - 1) {\n height += pageHeights.value[i] * pageScales.value[i] + props.args.pages_vertical_spacing;\n }\n }\n }\n return height;\n };\n\n const getAnnotationStyle = (annoObj, index) => {\n const scale = pageScales.value[annoObj.page - 1];\n const obj = {\n position: 'absolute',\n left: `${annoObj.x * scale}px`,\n top: `${calculatePdfsHeight(annoObj.page) + annoObj.y * scale}px`,\n width: `${annoObj.width * scale}px`,\n height: `${annoObj.height * scale}px`,\n outline: `${props.args.annotation_outline_size * scale}px solid`,\n outlineColor: annoObj.color,\n cursor: 'pointer',\n 'z-index': 1\n };\n if (index) {\n loadedAnnotations.value.push(`annotation-${index}`);\n }\n return obj\n };\n\n const clearExistingCanvases = (pdfViewer) => {\n const canvases = pdfViewer?.getElementsByTagName(\"canvas\");\n for (let j = canvases.length - 1; j >= 0; j--) {\n pdfViewer?.removeChild(canvases.item(j));\n }\n };\n\n const createCanvasForPage = (page, scale, rotation, pageNumber, resolutionRatioBoost=1) => {\n const viewport = page.getViewport({scale, rotation});\n\n const ratio = (window.devicePixelRatio || 1) * resolutionRatioBoost\n // console.log(ratio)\n\n const canvas = document.createElement(\"canvas\");\n canvas.id = `canvas_page_${pageNumber}`;\n canvas.height = viewport.height * ratio + props.args.pages_vertical_spacing;\n canvas.width = viewport.width * ratio;\n canvas.style.width = viewport.width + 'px';\n canvas.style.height = viewport.height + 'px';\n canvas.style.display = \"block\";\n canvas.style.marginBottom = `${props.args.pages_vertical_spacing}px`;\n canvas.getContext(\"2d\").scale(ratio, ratio);\n return canvas;\n };\n\n\n const renderPage = async (page, canvas, viewport) => {\n const renderContext = {\n canvasContext: canvas.getContext(\"2d\"),\n viewport: viewport\n };\n\n try {\n const renderTask = page.render(renderContext);\n await renderTask.promise.catch(function(error){\n // alertError(error);\n // do nothing\n });\n } catch (e) {\n // do nothing\n }\n\n\n if (renderText) {\n const textContent = await page.getTextContent();\n const textLayerDiv = document.createElement(\"div\");\n textLayerDiv.className = \"textLayer\"\n textLayerDiv.style = \"z-index: 2\"\n // textLayerDiv.style.position = \"absolute\";\n // textLayerDiv.style.height = `${viewport.height}px`;\n // textLayerDiv.style.width = `${viewport.width}px`;\n const textLayer = new pdfjsLib.TextLayer({\n textContentSource: textContent,\n container: textLayerDiv,\n viewport: viewport,\n textDivs: []\n })\n await textLayer.render()\n\n requestAnimationFrame(async () => {\n const pageDiv = document.createElement('div');\n pageDiv.className = 'page';\n\n const canvasWrapper = document.createElement('div');\n canvasWrapper.className = 'canvasWrapper';\n canvasWrapper.appendChild(canvas);\n\n pageDiv.style = \"position: relative;\";\n\n const pdfViewer = document.getElementById(\"pdfViewer\");\n pageDiv.appendChild(canvasWrapper);\n pageDiv.appendChild(textLayerDiv);\n\n pdfViewer.appendChild(pageDiv);\n });\n } else {\n requestAnimationFrame(() => {\n const pageDiv = document.createElement('div');\n pageDiv.className = 'page';\n\n const canvasWrapper = document.createElement('div');\n canvasWrapper.className = 'canvasWrapper';\n canvasWrapper.appendChild(canvas);\n\n pageDiv.style = \"position: relative;\";\n pageDiv.appendChild(canvasWrapper);\n pdfViewer.appendChild(pageDiv);\n });\n }\n };\n\n const renderPdfPages = async (pdf, pdfViewer, pagesToRender = null) => {\n if (pagesToRender.length === 0) {\n pagesToRender = []\n for (let i = 0; i < pdf.numPages; i++) {\n pagesToRender.push(i + 1);\n }\n }\n\n let resolutionBoost = 1\n if (props.args.resolution_boost) {\n resolutionBoost = props.args.resolution_boost\n }\n\n for (let pageNumber = 1; pageNumber <= pdf.numPages; pageNumber++) {\n const page = await pdf.getPage(pageNumber)\n const rotation = page.rotate\n // Initial viewport\n const unscaledViewport = page.getViewport({\n scale: 1.0,\n rotation: rotation,\n })\n\n if (props.args.height > 0) {\n const widthScale = unscaledViewport.width / unscaledViewport.height\n const possibleScaledWidth = widthScale * props.args.height\n if (maxWidth.value === 0) {\n maxWidth.value = possibleScaledWidth\n } else if (possibleScaledWidth < maxWidth.value) {\n maxWidth.value = possibleScaledWidth\n }\n }\n\n const scale = maxWidth.value / unscaledViewport.width\n\n pageScales.value.push(scale)\n pageHeights.value.push(unscaledViewport.height)\n if (pagesToRender.includes(pageNumber)) {\n const canvas = createCanvasForPage(page, scale, rotation, pageNumber, resolutionBoost)\n\n // pdfViewer?.append(canvas)\n pdfViewer.style.setProperty('--scale-factor', scale);\n\n const viewport = page.getViewport({\n scale: pageScales.value[page._pageIndex],\n rotation: page.rotate,\n intent: \"print\",\n });\n\n const ratio = (window.devicePixelRatio || 1) * resolutionBoost\n totalHeight.value += canvas.height / ratio\n await renderPage(page, canvas, viewport)\n if (canvas.id !== undefined) {\n loadedPages.value.push(canvas.id)\n }\n }\n }\n // Subtract the margin for the last page as it's not needed\n if (pagesToRender.length > 0) {\n totalHeight.value -= props.args.pages_vertical_spacing;\n }\n };\n\n const alertError = (error) => {\n window.alert(error.message);\n console.error(error);\n };\n\n const loadPdfs = async (url) => {\n pdfjsLib.GlobalWorkerOptions.workerSrc = 'pdfjs-dist/build/pdf.worker.mjs';\n try {\n const loadingTask = await getDocument({\n url: url,\n cMapUrl: CMAP_URL,\n cMapPacked: CMAP_PACKED,\n enableXfa: ENABLE_XFA,\n });\n const pdfViewer = document.getElementById(\"pdfViewer\");\n clearExistingCanvases(pdfViewer);\n\n const pdf = await loadingTask.promise;\n await renderPdfPages(pdf, pdfViewer, props.args.pages_to_render);\n } catch (error) {\n alertError(error);\n }\n };\n\n const scrollToItem = () => {\n if (props.args.scroll_to_page) {\n const page = document.getElementById(`canvas_page_${props.args.scroll_to_page}`);\n if (page) {\n page.scrollIntoView({behavior: \"smooth\"});\n }\n } else if (props.args.scroll_to_annotation) {\n const annotation = document.getElementById(`annotation-${props.args.scroll_to_annotation - 1}`);\n if (annotation) {\n annotation.scrollIntoView({behavior: \"smooth\", block: \"center\"});\n }\n }\n };\n\n const collectAndReturnIds = () => {\n const pages_ids = new Set()\n const annotations_ids = new Set()\n\n let j\n\n for (j = 0; j < loadedAnnotations.value.length; j++) {\n annotations_ids.add(loadedAnnotations.value[j]);\n }\n for (j = 0; j < loadedPages.value.length; j++) {\n pages_ids.add(loadedPages.value[j]);\n }\n\n // Streamlit.setComponentValue({\"pages\": Array.from(pages_ids), \"annotations\": Array.from(annotations_ids)})\n }\n\n\n const setFrameHeight = () => {\n Streamlit.setFrameHeight(props.args.height || totalHeight.value);\n };\n\n const setFrameWidth = () => {\n if (props.args.width === null || props.args.width === undefined) {\n maxWidth.value = window.innerWidth\n } else if (Number.isInteger(props.args.width)) {\n maxWidth.value = props.args.width\n\n // If the desired width is larger than the available inner width,\n // we should not exceed it. To be revised\n if (window.innerWidth > 0) {\n if (window.innerWidth < maxWidth.value) {\n maxWidth.value = window.innerWidth\n }\n }\n }\n }\n\n onMounted(() => {\n const binaryDataUrl = `data:application/pdf;base64,${props.args.binary}`;\n setFrameWidth();\n if (props.args.rendering === \"unwrap\") {\n loadPdfs(binaryDataUrl)\n .then(setFrameHeight)\n .then(collectAndReturnIds)\n // .then(scrollToItem)\n //LF calling setComponentReady seems to be done anyway by the WithStreamlitConnection.vue\n // .then(Streamlit.setComponentReady);\n } else {\n setFrameHeight();\n // Streamlit.setComponentReady();\n }\n });\n\n onUpdated(() => {\n setFrameHeight();\n if (props.args.rendering === \"unwrap\") {\n scrollToItem();\n }\n });\n\n\n return {\n filteredAnnotations,\n handleAnnotationClick,\n getAnnotationStyle,\n pdfContainerStyle,\n pdfViewerStyle,\n getPageStyle\n };\n },\n};\n</script>\n","import { render } from \"./PdfViewer.vue?vue&type=template&id=3c58901a\"\nimport script from \"./PdfViewer.vue?vue&type=script&lang=js\"\nexport * from \"./PdfViewer.vue?vue&type=script&lang=js\"\n\nimport exportComponent from \"../node_modules/vue-loader/dist/exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__","import { createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock, createCommentVNode as _createCommentVNode, renderSlot as _renderSlot } from \"vue\"\n\nconst _hoisted_1 = { key: 0 }\nconst _hoisted_2 = { class: \"err__msg\" }\n\nexport function render(_ctx: any,_cache: any,$props: any,$setup: any,$data: any,$options: any) {\n return (_openBlock(), _createElementBlock(\"div\", null, [\n (_ctx.componentError != '')\n ? (_openBlock(), _createElementBlock(\"div\", _hoisted_1, [\n _cache[0] || (_cache[0] = _createElementVNode(\"h1\", { class: \"err__title\" }, \"Component Error\", -1)),\n _createElementVNode(\"div\", _hoisted_2, \"Message: \" + _toDisplayString(_ctx.componentError), 1)\n ]))\n : (_ctx.renderData != null)\n ? _renderSlot(_ctx.$slots, \"default\", {\n key: 1,\n args: _ctx.renderData.args,\n disabled: _ctx.renderData.disabled\n }, undefined, true)\n : _createCommentVNode(\"\", true)\n ]))\n}","<template>\n <div>\n <!-- Error boundary. If our wrapped component threw an error, display it. -->\n <div v-if=\"componentError != ''\">\n <h1 class=\"err__title\">Component Error</h1>\n <div class=\"err__msg\">Message: {{ componentError }}</div>\n </div>\n <!-- \n Else render the component slot and pass Streamlit event data in `args` props to it.\n Don't render until we've gotten our first RENDER_EVENT from Streamlit.\n All components get disabled while the app is being re-run, and become re-enabled when the re-run has finished.\n -->\n <slot\n v-else-if=\"renderData != null\"\n :args=\"renderData.args\"\n :disabled=\"renderData.disabled\"\n ></slot>\n </div>\n</template>\n\n<script lang=\"ts\">\nimport {\n ref,\n defineComponent,\n onMounted,\n onUpdated,\n onUnmounted,\n onErrorCaptured,\n} from \"vue\"\nimport { Streamlit, RenderData } from \"streamlit-component-lib\"\n\nexport default defineComponent({\n name: \"WithStreamlitConnection\",\n setup() {\n const renderData = ref<RenderData>((undefined as unknown) as RenderData)\n const componentError = ref(\"\")\n\n const onRenderEvent = (event: Event): void => {\n const renderEvent = event as CustomEvent<RenderData>\n renderData.value = renderEvent.detail\n componentError.value = \"\"\n }\n\n // Set up event listeners, and signal to Streamlit that we're ready.\n // We won't render the component until we receive the first RENDER_EVENT.\n onMounted(() => {\n Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, onRenderEvent)\n Streamlit.setComponentReady()\n })\n onUpdated(() => {\n // If our slot threw an error, we display it in render(). In this\n // case, the slot won't be mounted and therefore won't call\n // `setFrameHeight` on its own. We do it here so that the rendered\n // error will be visible.\n if (componentError.value != \"\") {\n Streamlit.setFrameHeight()\n }\n })\n onUnmounted(() => {\n Streamlit.events.removeEventListener(\n Streamlit.RENDER_EVENT,\n onRenderEvent\n )\n })\n onErrorCaptured(err => {\n componentError.value = String(err)\n })\n\n return {\n renderData,\n componentError,\n }\n },\n})\n</script>\n\n<style scoped>\n.err__title,\n.err__msg {\n margin: 0;\n}\n</style>\n","import { render } from \"./WithStreamlitConnection.vue?vue&type=template&id=bef81972&scoped=true&ts=true\"\nimport script from \"./WithStreamlitConnection.vue?vue&type=script&lang=ts\"\nexport * from \"./WithStreamlitConnection.vue?vue&type=script&lang=ts\"\n\nimport \"./WithStreamlitConnection.vue?vue&type=style&index=0&id=bef81972&scoped=true&lang=css\"\n\nimport exportComponent from \"../../node_modules/vue-loader/dist/exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render],['__scopeId',\"data-v-bef81972\"]])\n\nexport default __exports__","import { render } from \"./App.vue?vue&type=template&id=6ea7f320&ts=true\"\nimport script from \"./App.vue?vue&type=script&lang=ts\"\nexport * from \"./App.vue?vue&type=script&lang=ts\"\n\nimport \"./App.vue?vue&type=style&index=0&id=6ea7f320&lang=css\"\n\nimport exportComponent from \"../node_modules/vue-loader/dist/exportHelper.js\"\nconst __exports__ = /*#__PURE__*/exportComponent(script, [['render',render]])\n\nexport default __exports__","import { createApp } from 'vue'\nimport App from './App.vue'\n\ncreateApp(App).mount('#app')\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n// expose the modules object (__webpack_modules__)\n__webpack_require__.m = __webpack_modules__;\n\n","var deferred = [];\n__webpack_require__.O = (result, chunkIds, fn, priority) => {\n\tif(chunkIds) {\n\t\tpriority = priority || 0;\n\t\tfor(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];\n\t\tdeferred[i] = [chunkIds, fn, priority];\n\t\treturn;\n\t}\n\tvar notFulfilled = Infinity;\n\tfor (var i = 0; i < deferred.length; i++) {\n\t\tvar [chunkIds, fn, priority] = deferred[i];\n\t\tvar fulfilled = true;\n\t\tfor (var j = 0; j < chunkIds.length; j++) {\n\t\t\tif ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {\n\t\t\t\tchunkIds.splice(j--, 1);\n\t\t\t} else {\n\t\t\t\tfulfilled = false;\n\t\t\t\tif(priority < notFulfilled) notFulfilled = priority;\n\t\t\t}\n\t\t}\n\t\tif(fulfilled) {\n\t\t\tdeferred.splice(i--, 1)\n\t\t\tvar r = fn();\n\t\t\tif (r !== undefined) result = r;\n\t\t}\n\t}\n\treturn result;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// no baseURI\n\n// object to store loaded and loading chunks\n// undefined = chunk not loaded, null = chunk preloaded/prefetched\n// [resolve, reject, Promise] = chunk loading, 0 = chunk loaded\nvar installedChunks = {\n\t524: 0\n};\n\n// no chunk on demand loading\n\n// no prefetching\n\n// no preloaded\n\n// no HMR\n\n// no HMR manifest\n\n__webpack_require__.O.j = (chunkId) => (installedChunks[chunkId] === 0);\n\n// install a JSONP callback for chunk loading\nvar webpackJsonpCallback = (parentChunkLoadingFunction, data) => {\n\tvar [chunkIds, moreModules, runtime] = data;\n\t// add \"moreModules\" to the modules object,\n\t// then flag all \"chunkIds\" as loaded and fire callback\n\tvar moduleId, chunkId, i = 0;\n\tif(chunkIds.some((id) => (installedChunks[id] !== 0))) {\n\t\tfor(moduleId in moreModules) {\n\t\t\tif(__webpack_require__.o(moreModules, moduleId)) {\n\t\t\t\t__webpack_require__.m[moduleId] = moreModules[moduleId];\n\t\t\t}\n\t\t}\n\t\tif(runtime) var result = runtime(__webpack_require__);\n\t}\n\tif(parentChunkLoadingFunction) parentChunkLoadingFunction(data);\n\tfor(;i < chunkIds.length; i++) {\n\t\tchunkId = chunkIds[i];\n\t\tif(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {\n\t\t\tinstalledChunks[chunkId][0]();\n\t\t}\n\t\tinstalledChunks[chunkId] = 0;\n\t}\n\treturn __webpack_require__.O(result);\n}\n\nvar chunkLoadingGlobal = self[\"webpackChunkstreamlit_pdf_viewer\"] = self[\"webpackChunkstreamlit_pdf_viewer\"] || [];\nchunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));\nchunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));","// startup\n// Load entry module and return exports\n// This entry module depends on other loaded chunks and execution need to be delayed\nvar __webpack_exports__ = __webpack_require__.O(undefined, [504], () => (__webpack_require__(5060)))\n__webpack_exports__ = __webpack_require__.O(__webpack_exports__);\n"],"names":["_hoisted_1","id","render","_ctx","_cache","$props","$setup","$data","$options","_component_PdfViewer","_resolveComponent","_component_WithStreamlitConnection","_openBlock","_createElementBlock","_createVNode","default","_withCtx","args","_","key","style","_normalizeStyle","pdfContainerStyle","rendering","_createElementVNode","pdfViewerStyle","annotations","_hoisted_2","_Fragment","_renderList","filteredAnnotations","annotation","index","getPageStyle","onClick","$event","handleAnnotationClick","getAnnotationStyle","_hoisted_4","_hoisted_3","_createCommentVNode","_hoisted_5","src","binary","width","height","type","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","CMAP_URL","CMAP_PACKED","ENABLE_XFA","props","setup","totalHeight","ref","maxWidth","pageScales","pageHeights","loadedPages","loadedAnnotations","isRenderingAllPages","pages_to_render","length","computed","filter","anno","includes","Number","page","serializedAnnotation","JSON","parse","stringify","Streamlit","setComponentValue","clicked_annotation","renderText","render_text","value","overflow","position","calculatePdfsHeight","i","pages_vertical_spacing","annoObj","scale","obj","left","x","top","y","outline","annotation_outline_size","outlineColor","color","cursor","push","clearExistingCanvases","pdfViewer","canvases","getElementsByTagName","j","removeChild","item","createCanvasForPage","rotation","pageNumber","resolutionRatioBoost","viewport","getViewport","ratio","window","devicePixelRatio","canvas","document","createElement","display","marginBottom","getContext","renderPage","async","renderContext","canvasContext","renderTask","promise","catch","error","e","textContent","getTextContent","textLayerDiv","className","textLayer","pdfjsLib","textContentSource","container","textDivs","requestAnimationFrame","pageDiv","canvasWrapper","appendChild","getElementById","renderPdfPages","pdf","pagesToRender","numPages","resolutionBoost","resolution_boost","getPage","rotate","unscaledViewport","widthScale","possibleScaledWidth","setProperty","_pageIndex","intent","undefined","alertError","alert","message","console","loadPdfs","workerSrc","loadingTask","getDocument","url","cMapUrl","cMapPacked","enableXfa","scrollToItem","scroll_to_page","scrollIntoView","behavior","scroll_to_annotation","block","collectAndReturnIds","pages_ids","Set","annotations_ids","add","setFrameHeight","setFrameWidth","innerWidth","isInteger","onMounted","binaryDataUrl","then","onUpdated","__exports__","class","componentError","_toDisplayString","renderData","_renderSlot","$slots","disabled","defineComponent","name","onRenderEvent","event","renderEvent","detail","events","addEventListener","RENDER_EVENT","setComponentReady","onUnmounted","removeEventListener","onErrorCaptured","err","String","components","PdfViewer","WithStreamlitConnection","createApp","App","mount","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","exports","module","__webpack_modules__","call","m","deferred","O","result","chunkIds","fn","priority","notFulfilled","Infinity","fulfilled","Object","keys","every","splice","r","d","definition","o","defineProperty","enumerable","get","g","globalThis","this","Function","prop","prototype","hasOwnProperty","installedChunks","chunkId","webpackJsonpCallback","parentChunkLoadingFunction","data","moreModules","runtime","some","chunkLoadingGlobal","self","forEach","bind","__webpack_exports__"],"sourceRoot":""}