Skip to content

Commit

Permalink
Revert "Support width in percentage #30"
Browse files Browse the repository at this point in the history
This reverts commit 4d18d18.
  • Loading branch information
t29mato committed Mar 1, 2024
1 parent 4d18d18 commit 4b3ea5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
streamlit
bump-my-version
streamlit_js_eval
bump-my-version
24 changes: 4 additions & 20 deletions streamlit_pdf_viewer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Union, List, Optional

import streamlit.components.v1 as components
from streamlit_js_eval import streamlit_js_eval
import json

_RELEASE = True
Expand All @@ -22,19 +21,8 @@
path=build_dir
)

def get_screen_width():
async_js_code = """
new Promise(resolve => {
if (document.readyState === "complete") {
resolve(window.innerWidth);
} else {
window.addEventListener("load", () => resolve(window.innerWidth));
}
})
"""
return streamlit_js_eval(js_expressions=async_js_code)

def pdf_viewer(input: Union[str, Path, bytes], width: Union[str, int] = "40%", height: int = None, key=None,
def pdf_viewer(input: Union[str, Path, bytes], width: int = 700, height: int = None, key=None,
annotations: list = (),
pages_vertical_spacing: int = 2,
annotation_outline_size: int = 1,
Expand Down Expand Up @@ -63,13 +51,9 @@ def pdf_viewer(input: Union[str, Path, bytes], width: Union[str, int] = "40%", h
Returns the value of the selected component (if any).
"""

if isinstance(width, str) and width.endswith('%'):
screen_width = get_screen_width()
percentage = float(width[:-1]) / 100
width = int(screen_width * percentage)
elif not isinstance(width, int):
raise TypeError("Width must be an integer or a percentage string (e.g., '70%' or 700)")

# Validate width and height parameters
if not isinstance(width, int):
raise TypeError("Width must be an integer")
if height is not None and not isinstance(height, int):
raise TypeError("Height must be an integer or None")
if not all(isinstance(page, int) for page in pages_to_render):
Expand Down

0 comments on commit 4b3ea5d

Please sign in to comment.