instaui 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.whl
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.
- instaui/components/html/select.py +1 -1
- instaui/consts.py +4 -0
- instaui/fastapi_server/resource.py +6 -7
- instaui/fastapi_server/server.py +37 -9
- instaui/html_tools.py +8 -0
- instaui/runtime/resource.py +2 -2
- instaui/static/insta-ui.ico +0 -0
- instaui/static/templates/debug/sse.html +2 -2
- instaui/systems/file_system.py +3 -5
- instaui/template/web_template.py +1 -1
- instaui/template/zero_template.py +7 -12
- instaui/ui/__init__.py +2 -0
- instaui/zero/func.py +4 -0
- instaui/zero/test.html +44 -0
- {instaui-0.1.2.dist-info → instaui-0.1.3.dist-info}/METADATA +1 -1
- {instaui-0.1.2.dist-info → instaui-0.1.3.dist-info}/RECORD +18 -16
- {instaui-0.1.2.dist-info → instaui-0.1.3.dist-info}/LICENSE +0 -0
- {instaui-0.1.2.dist-info → instaui-0.1.3.dist-info}/WHEEL +0 -0
instaui/consts.py
CHANGED
@@ -8,11 +8,15 @@ _STATIC_DIR = _THIS_DIR.joinpath("static")
|
|
8
8
|
INDEX_TEMPLATE_PATH = _TEMPLATES_DIR.joinpath("index.html")
|
9
9
|
APP_IIFE_JS_PATH = _STATIC_DIR.joinpath("insta-ui.iife.js")
|
10
10
|
APP_ES_JS_PATH = _STATIC_DIR.joinpath("insta-ui.esm-browser.prod.js")
|
11
|
+
APP_ES_JS_MAP_PATH = _STATIC_DIR.joinpath("insta-ui.js.map")
|
11
12
|
APP_CSS_PATH = _STATIC_DIR.joinpath("insta-ui.css")
|
12
13
|
VUE_IIFE_JS_PATH = _STATIC_DIR.joinpath("vue.global.prod.js")
|
13
14
|
VUE_ES_JS_PATH = _STATIC_DIR.joinpath("vue.esm-browser.prod.js")
|
14
15
|
VUE_ES_RUNTIME_JS_PATH = _STATIC_DIR.joinpath("vue.runtime.esm-browser.prod.js")
|
15
16
|
TAILWIND_JS_PATH = _STATIC_DIR.joinpath("tailwindcss.min.js")
|
17
|
+
FAVICON_PATH = _STATIC_DIR.joinpath("insta-ui.ico")
|
18
|
+
|
19
|
+
PAGE_TITLE = "insta-ui"
|
16
20
|
|
17
21
|
_T_App_Mode = Literal["zero", "web", "webview"]
|
18
22
|
TModifier = Literal["trim", "number", "lazy"]
|
@@ -1,6 +1,5 @@
|
|
1
1
|
from pathlib import Path
|
2
2
|
from typing import Dict
|
3
|
-
from urllib.parse import quote as urllib_quote
|
4
3
|
from instaui.systems import file_system
|
5
4
|
from instaui.version import __version__ as _INSTA_VERSION
|
6
5
|
|
@@ -25,11 +24,11 @@ def record_resource(path: Path):
|
|
25
24
|
return url
|
26
25
|
|
27
26
|
|
28
|
-
def
|
29
|
-
|
27
|
+
def _generate_hash_part(path: Path):
|
28
|
+
path = Path(path).resolve()
|
29
|
+
is_file = path.is_file()
|
30
30
|
|
31
|
+
if is_file:
|
32
|
+
return f"{file_system.generate_hash_name_from_path(path.parent)}/{path.name}"
|
31
33
|
|
32
|
-
|
33
|
-
file_path = Path(file_path).resolve()
|
34
|
-
hash_name = file_system.generate_hash_name_from_path(file_path)
|
35
|
-
return f"{hash_name}/{file_path.name}"
|
34
|
+
return file_system.generate_hash_name_from_path(path)
|
instaui/fastapi_server/server.py
CHANGED
@@ -9,6 +9,8 @@ import __main__
|
|
9
9
|
|
10
10
|
from fastapi import FastAPI
|
11
11
|
from fastapi import Request
|
12
|
+
from fastapi.staticfiles import StaticFiles
|
13
|
+
|
12
14
|
from fastapi.responses import HTMLResponse
|
13
15
|
import uvicorn
|
14
16
|
from uvicorn.supervisors import ChangeReload
|
@@ -31,13 +33,18 @@ from . import debug_mode_router
|
|
31
33
|
from .middlewares import RequestContextMiddleware
|
32
34
|
from ._uvicorn import UvicornServer
|
33
35
|
from . import resource
|
36
|
+
from instaui.version import __version__ as _INSTA_VERSION
|
34
37
|
|
35
38
|
APP_IMPORT_STRING = "instaui.fastapi_server.server:Server._instance.app"
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
|
41
|
+
INSTAUI_STATIC_URL = f"/_instaui_{_INSTA_VERSION}/static"
|
42
|
+
|
43
|
+
VUE_JS_HASH_LINK = f"{INSTAUI_STATIC_URL}/{consts.VUE_ES_JS_PATH.name}"
|
44
|
+
INSTAUI_JS_HASH_LINK = f"{INSTAUI_STATIC_URL}/{consts.APP_ES_JS_PATH.name}"
|
45
|
+
APP_CSS_LINK = f"{INSTAUI_STATIC_URL}/{consts.APP_CSS_PATH.name}"
|
46
|
+
TAILWIND_JS_HASH_LINK = f"{INSTAUI_STATIC_URL}/{consts.TAILWIND_JS_PATH.name}"
|
47
|
+
FAVICON_LINK = f"{INSTAUI_STATIC_URL}/{consts.FAVICON_PATH.name}"
|
41
48
|
|
42
49
|
|
43
50
|
class Server:
|
@@ -57,6 +64,8 @@ class Server:
|
|
57
64
|
watch_router.create_router(self.app)
|
58
65
|
debug_mode_router.create_router(self.app)
|
59
66
|
|
67
|
+
self.add_instaui_static(self.app)
|
68
|
+
|
60
69
|
for page_info in get_launch_collector()._page_router.values():
|
61
70
|
self.register_page(page_info)
|
62
71
|
|
@@ -103,6 +112,18 @@ class Server:
|
|
103
112
|
):
|
104
113
|
config_data = to_config_data()
|
105
114
|
|
115
|
+
system_slot = get_app_slot()
|
116
|
+
default_app_slot = get_default_app_slot()
|
117
|
+
html_resource = system_slot._html_resource
|
118
|
+
default_html_resource = default_app_slot._html_resource
|
119
|
+
|
120
|
+
favicon_url = FAVICON_LINK
|
121
|
+
if html_resource.favicon:
|
122
|
+
favicon_url = resource.record_resource(html_resource.favicon)
|
123
|
+
else:
|
124
|
+
if default_html_resource.favicon:
|
125
|
+
favicon_url = resource.record_resource(default_html_resource.favicon)
|
126
|
+
|
106
127
|
model = web_template.WebTemplateModel(
|
107
128
|
vue_js_link=VUE_JS_HASH_LINK,
|
108
129
|
instaui_js_link=INSTAUI_JS_HASH_LINK,
|
@@ -110,13 +131,12 @@ class Server:
|
|
110
131
|
APP_CSS_LINK,
|
111
132
|
],
|
112
133
|
config_dict=config_data,
|
134
|
+
favicon_url=favicon_url,
|
135
|
+
title=html_resource.title
|
136
|
+
or default_html_resource.title
|
137
|
+
or consts.PAGE_TITLE,
|
113
138
|
)
|
114
139
|
|
115
|
-
system_slot = get_app_slot()
|
116
|
-
default_app_slot = get_default_app_slot()
|
117
|
-
html_resource = system_slot._html_resource
|
118
|
-
default_html_resource = default_app_slot._html_resource
|
119
|
-
|
120
140
|
if html_resource.use_tailwind is None:
|
121
141
|
if default_html_resource.use_tailwind:
|
122
142
|
model.js_links.append(JsLink(TAILWIND_JS_HASH_LINK))
|
@@ -250,6 +270,14 @@ class Server:
|
|
250
270
|
def run_with(self, app):
|
251
271
|
assert isinstance(app, FastAPI), "app must be a FastAPI instance"
|
252
272
|
|
273
|
+
@staticmethod
|
274
|
+
def add_instaui_static(app: FastAPI):
|
275
|
+
app.mount(
|
276
|
+
INSTAUI_STATIC_URL,
|
277
|
+
StaticFiles(directory=consts._STATIC_DIR),
|
278
|
+
name=INSTAUI_STATIC_URL,
|
279
|
+
)
|
280
|
+
|
253
281
|
|
254
282
|
def _split_args(args: str):
|
255
283
|
return [a.strip() for a in args.split(",")]
|
instaui/html_tools.py
CHANGED
@@ -29,6 +29,14 @@ def use_tailwind(value=True):
|
|
29
29
|
get_app_slot()._html_resource.use_tailwind = value
|
30
30
|
|
31
31
|
|
32
|
+
def use_page_title(title: str):
|
33
|
+
get_app_slot()._html_resource.title = title
|
34
|
+
|
35
|
+
|
36
|
+
def use_favicon(favicon: Path):
|
37
|
+
get_app_slot()._html_resource.favicon = favicon
|
38
|
+
|
39
|
+
|
32
40
|
def add_js_code(code: str, *, script_attrs: Optional[Dict[str, Any]] = None):
|
33
41
|
get_app_slot()._html_resource.add_script_tag(code, script_attrs=script_attrs)
|
34
42
|
|
instaui/runtime/resource.py
CHANGED
@@ -6,7 +6,8 @@ from .dataclass import JsLink, VueAppUse, VueAppComponent
|
|
6
6
|
|
7
7
|
class HtmlResource:
|
8
8
|
use_tailwind: Optional[bool] = None
|
9
|
-
|
9
|
+
title: Optional[str] = None
|
10
|
+
favicon: Optional[Path] = None
|
10
11
|
|
11
12
|
def __init__(self) -> None:
|
12
13
|
self._css_links: Dict[Union[str, Path], Any] = {}
|
@@ -16,7 +17,6 @@ class HtmlResource:
|
|
16
17
|
self._vue_app_use: Set[VueAppUse] = set()
|
17
18
|
self._vue_app_components: Set[VueAppComponent] = set()
|
18
19
|
self._import_maps: Dict[str, str] = {}
|
19
|
-
self.title: str = self._title
|
20
20
|
self._appConfig = "{}"
|
21
21
|
|
22
22
|
def add_css_link(self, link: Union[str, Path]):
|
Binary file
|
@@ -10,9 +10,9 @@
|
|
10
10
|
left: 50%;
|
11
11
|
transform: translateX(-50%);
|
12
12
|
height: 75px;
|
13
|
-
background-color: rgba(
|
13
|
+
background-color: rgba(104, 184, 93, 0.8);
|
14
14
|
border: 1px solid #dee2e6;
|
15
|
-
box-shadow: 0 4px 6px rgba(
|
15
|
+
box-shadow: 0 4px 6px rgba(104, 184, 93, 0.5);
|
16
16
|
border-radius: 4px;
|
17
17
|
color: #343a40;
|
18
18
|
font-size: 16px;
|
instaui/systems/file_system.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
import uuid
|
2
1
|
from pathlib import Path
|
2
|
+
import hashlib
|
3
3
|
|
4
4
|
|
5
|
-
def generate_hash_name_from_path(
|
6
|
-
|
7
|
-
unique_id = uuid.uuid5(uuid.NAMESPACE_URL, path_str)
|
8
|
-
return str(unique_id)
|
5
|
+
def generate_hash_name_from_path(path: Path):
|
6
|
+
return hashlib.sha256(path.as_posix().encode()).hexdigest()[:32]
|
instaui/template/web_template.py
CHANGED
@@ -23,7 +23,7 @@ class WebTemplateModel:
|
|
23
23
|
vue_app_use: typing.List[str] = field(default_factory=list)
|
24
24
|
vue_app_component: typing.List[VueAppComponent] = field(default_factory=list)
|
25
25
|
prefix: str = ""
|
26
|
-
title: str =
|
26
|
+
title: typing.Optional[str] = None
|
27
27
|
favicon_url: str = ""
|
28
28
|
|
29
29
|
def add_extra_import_map(self, name: str, url: str):
|
@@ -35,8 +35,8 @@ class ZeroTemplateModel:
|
|
35
35
|
vue_app_use: typing.List[str] = field(default_factory=list)
|
36
36
|
vue_app_component: typing.List[ZeroVueAppComponent] = field(default_factory=list)
|
37
37
|
prefix: str = ""
|
38
|
-
title: str =
|
39
|
-
|
38
|
+
title: typing.Optional[str] = None
|
39
|
+
favicon: typing.Optional[Path] = None
|
40
40
|
|
41
41
|
def add_extra_import_map(self, name: str, url: _TCodeOrPath):
|
42
42
|
self.extra_import_maps[name] = url
|
@@ -83,11 +83,7 @@ class ZeroTemplateModel:
|
|
83
83
|
for component in self.vue_app_component
|
84
84
|
]
|
85
85
|
|
86
|
-
self.
|
87
|
-
self._normalize_path_to_base64_url(self.favicon_url, _ICON_PREFIX)
|
88
|
-
if self.favicon_url is not None
|
89
|
-
else None
|
90
|
-
)
|
86
|
+
self.favicon = self._normalize_path_to_base64_url(self.favicon, _ICON_PREFIX)
|
91
87
|
|
92
88
|
@staticmethod
|
93
89
|
def _normalize_path_to_dataurl(path: typing.Union[str, Path], prefix: str):
|
@@ -97,11 +93,10 @@ class ZeroTemplateModel:
|
|
97
93
|
return f"{prefix},{quote(path)}"
|
98
94
|
|
99
95
|
@staticmethod
|
100
|
-
def _normalize_path_to_base64_url(path: typing.
|
101
|
-
if
|
102
|
-
|
103
|
-
|
104
|
-
return f"{prefix},{base64.b64encode(path.encode('utf-8')).decode('utf-8')}"
|
96
|
+
def _normalize_path_to_base64_url(path: typing.Optional[Path], prefix: str):
|
97
|
+
if path is None:
|
98
|
+
return None
|
99
|
+
return f"{prefix},{base64.b64encode(path.read_bytes()).decode('utf-8')}"
|
105
100
|
|
106
101
|
|
107
102
|
def render_zero_html(model: ZeroTemplateModel) -> str:
|
instaui/ui/__init__.py
CHANGED
@@ -19,6 +19,7 @@ from instaui.html_tools import (
|
|
19
19
|
add_vue_app_use,
|
20
20
|
to_config_data,
|
21
21
|
use_tailwind,
|
22
|
+
use_page_title,
|
22
23
|
)
|
23
24
|
|
24
25
|
from instaui.components.element import Element as element
|
@@ -91,6 +92,7 @@ __all__ = [
|
|
91
92
|
"add_js_link",
|
92
93
|
"add_vue_app_use",
|
93
94
|
"use_tailwind",
|
95
|
+
"use_page_title",
|
94
96
|
"directive",
|
95
97
|
"vif",
|
96
98
|
"page",
|
instaui/zero/func.py
CHANGED
@@ -42,6 +42,10 @@ def to_html_str():
|
|
42
42
|
consts.APP_CSS_PATH,
|
43
43
|
],
|
44
44
|
config_dict=config_data,
|
45
|
+
favicon=html_resource.favicon
|
46
|
+
or default_html_resource.favicon
|
47
|
+
or consts.FAVICON_PATH,
|
48
|
+
title=html_resource.title or default_html_resource.title or consts.PAGE_TITLE,
|
45
49
|
)
|
46
50
|
|
47
51
|
if html_resource.use_tailwind is None:
|