instaui 0.1.2__py3-none-any.whl → 0.1.4__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.
Files changed (62) hide show
  1. instaui/components/content.py +4 -4
  2. instaui/components/element.py +56 -12
  3. instaui/components/highlight_code/code.js +63 -0
  4. instaui/components/highlight_code/code.py +117 -0
  5. instaui/components/highlight_code/static/core.min.js +307 -0
  6. instaui/components/highlight_code/static/languages/css.min.js +31 -0
  7. instaui/components/highlight_code/static/languages/javascript.min.js +81 -0
  8. instaui/components/highlight_code/static/languages/json.min.js +8 -0
  9. instaui/components/highlight_code/static/languages/python-repl.min.js +5 -0
  10. instaui/components/highlight_code/static/languages/python.min.js +42 -0
  11. instaui/components/highlight_code/static/languages/shell.min.js +5 -0
  12. instaui/components/highlight_code/static/styles/default.min.css +9 -0
  13. instaui/components/highlight_code/static/styles/github-dark-dimmed.min.css +9 -0
  14. instaui/components/highlight_code/static/styles/github-dark.min.css +10 -0
  15. instaui/components/highlight_code/static/styles/github.min.css +10 -0
  16. instaui/components/html/__init__.py +2 -0
  17. instaui/components/html/select.py +7 -8
  18. instaui/components/html/textarea.py +28 -0
  19. instaui/components/markdown/markdown.js +33 -0
  20. instaui/components/markdown/markdown.py +41 -0
  21. instaui/components/markdown/static/github-markdown.css +12 -0
  22. instaui/components/markdown/static/marked.esm.js +2580 -0
  23. instaui/components/vfor.py +1 -1
  24. instaui/consts.py +4 -0
  25. instaui/daisyui/__init__.py +20 -0
  26. instaui/daisyui/_index.py +15 -0
  27. instaui/daisyui/button.py +38 -0
  28. instaui/daisyui/checkbox.py +17 -0
  29. instaui/daisyui/static/daisyui.css +1 -0
  30. instaui/daisyui/static/themes.css +1 -0
  31. instaui/dependencies/component_dependency.py +11 -5
  32. instaui/fastapi_server/dependency_router.py +4 -3
  33. instaui/fastapi_server/resource.py +12 -17
  34. instaui/fastapi_server/server.py +66 -20
  35. instaui/html_tools.py +12 -0
  36. instaui/inject.py +3 -3
  37. instaui/runtime/_app.py +6 -1
  38. instaui/runtime/resource.py +5 -2
  39. instaui/spa_router/_functions.py +1 -1
  40. instaui/spa_router/_route_model.py +1 -1
  41. instaui/static/insta-ui.css +1 -1
  42. instaui/static/insta-ui.esm-browser.prod.js +106 -111
  43. instaui/static/insta-ui.ico +0 -0
  44. instaui/static/insta-ui.js.map +1 -1
  45. instaui/static/templates/debug/sse.html +2 -2
  46. instaui/systems/file_system.py +3 -5
  47. instaui/systems/module_system.py +30 -0
  48. instaui/template/web_template.py +1 -1
  49. instaui/template/zero_template.py +19 -23
  50. instaui/ui/__build_init.py +73 -0
  51. instaui/ui/__init__.py +69 -57
  52. instaui/ui/__init__.pyi +129 -0
  53. instaui/ui/events.py +1 -1
  54. instaui/ui_functions/server.py +3 -1
  55. instaui/zero/func.py +16 -11
  56. instaui/zero/scope.py +89 -1
  57. {instaui-0.1.2.dist-info → instaui-0.1.4.dist-info}/METADATA +1 -1
  58. {instaui-0.1.2.dist-info → instaui-0.1.4.dist-info}/RECORD +60 -34
  59. instaui/static/insta-ui.iife.js +0 -29
  60. instaui/static/insta-ui.iife.js.map +0 -1
  61. {instaui-0.1.2.dist-info → instaui-0.1.4.dist-info}/LICENSE +0 -0
  62. {instaui-0.1.2.dist-info → instaui-0.1.4.dist-info}/WHEEL +0 -0
@@ -10,9 +10,9 @@
10
10
  left: 50%;
11
11
  transform: translateX(-50%);
12
12
  height: 75px;
13
- background-color: rgba(186, 230, 253, 0.8);
13
+ background-color: rgba(104, 184, 93, 0.8);
14
14
  border: 1px solid #dee2e6;
15
- box-shadow: 0 4px 6px rgba(186, 230, 253, 0.5);
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;
@@ -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(file_path: Path):
6
- path_str = str(file_path)
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]
@@ -0,0 +1,30 @@
1
+ from importlib import import_module
2
+ from types import ModuleType
3
+ from typing import Any, List
4
+
5
+
6
+ class LazyModule(ModuleType):
7
+ def __init__(self, name: str, member: str):
8
+ super().__init__(name)
9
+ self._name = name
10
+ self._mod = None
11
+ self._member_obj = None
12
+ self._member = member
13
+
14
+ def __getattr__(self, attr: str) -> Any:
15
+ self.__try_import()
16
+ return getattr(self._member_obj, attr)
17
+
18
+ def __call__(self, *args: Any, **kwds: Any) -> Any:
19
+ self.__try_import()
20
+ return self._member_obj(*args, **kwds) # type: ignore
21
+
22
+ def __dir__(self) -> List[str]:
23
+ if self._mod is None:
24
+ self._mod = import_module(self._name)
25
+ return dir(self._mod)
26
+
27
+ def __try_import(self):
28
+ if self._mod is None:
29
+ self._mod = import_module(self._name)
30
+ self._member_obj = getattr(self._mod, self._member)
@@ -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
- favicon_url: typing.Optional[_TCodeOrPath] = None
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
@@ -52,56 +52,52 @@ class ZeroTemplateModel:
52
52
  return dumps(data)
53
53
 
54
54
  def normalize_path_with_self(self):
55
- self.vue_js_code = self._normalize_path_to_dataurl(self.vue_js_code, _JS_PREFIX)
56
- self.instaui_js_code = self._normalize_path_to_dataurl(
55
+ self.vue_js_code = _normalize_path_to_dataurl(self.vue_js_code, _JS_PREFIX)
56
+ self.instaui_js_code = _normalize_path_to_dataurl(
57
57
  self.instaui_js_code, _JS_PREFIX
58
58
  )
59
59
 
60
60
  self.css_links = [
61
- self._normalize_path_to_dataurl(link, _CSS_PREFIX)
61
+ _normalize_path_to_dataurl(link, _CSS_PREFIX)
62
62
  for link in self.css_links
63
+ if isinstance(link, str) or (isinstance(link, Path) and link.is_file())
63
64
  ]
64
65
 
65
66
  self.js_links = [
66
67
  JsLink(
67
- link=self._normalize_path_to_dataurl(link.link, _JS_PREFIX),
68
+ link=_normalize_path_to_dataurl(link.link, _JS_PREFIX),
68
69
  attrs=link.attrs,
69
70
  )
70
71
  for link in self.js_links
71
72
  ]
72
73
 
73
74
  self.extra_import_maps = {
74
- k: self._normalize_path_to_dataurl(v, _JS_PREFIX)
75
+ k: _normalize_path_to_dataurl(v, _JS_PREFIX)
75
76
  for k, v in self.extra_import_maps.items()
76
77
  }
77
78
 
78
79
  self.vue_app_component = [
79
80
  ZeroVueAppComponent(
80
81
  name=component.name,
81
- url=self._normalize_path_to_dataurl(component.url, _JS_PREFIX),
82
+ url=_normalize_path_to_dataurl(component.url, _JS_PREFIX),
82
83
  )
83
84
  for component in self.vue_app_component
84
85
  ]
85
86
 
86
- self.favicon_url = (
87
- self._normalize_path_to_base64_url(self.favicon_url, _ICON_PREFIX)
88
- if self.favicon_url is not None
89
- else None
90
- )
87
+ self.favicon = _normalize_path_to_base64_url(self.favicon, _ICON_PREFIX) # type: ignore
88
+
91
89
 
92
- @staticmethod
93
- def _normalize_path_to_dataurl(path: typing.Union[str, Path], prefix: str):
94
- if isinstance(path, Path):
95
- path = path.read_text(encoding="utf-8")
90
+ def _normalize_path_to_dataurl(path: typing.Union[str, Path], prefix: str):
91
+ if isinstance(path, Path):
92
+ path = path.read_text(encoding="utf-8")
96
93
 
97
- return f"{prefix},{quote(path)}"
94
+ return f"{prefix},{quote(path)}"
98
95
 
99
- @staticmethod
100
- def _normalize_path_to_base64_url(path: typing.Union[str, Path], prefix: str):
101
- if isinstance(path, Path):
102
- path = path.read_text(encoding="utf-8")
103
96
 
104
- return f"{prefix},{base64.b64encode(path.encode('utf-8')).decode('utf-8')}"
97
+ def _normalize_path_to_base64_url(path: typing.Optional[Path], prefix: str):
98
+ if path is None:
99
+ return None
100
+ return f"{prefix},{base64.b64encode(path.read_bytes()).decode('utf-8')}"
105
101
 
106
102
 
107
103
  def render_zero_html(model: ZeroTemplateModel) -> str:
@@ -0,0 +1,73 @@
1
+ from pathlib import Path
2
+ from typing import List
3
+
4
+
5
+ PYI_FILE = Path(__file__).parent / "__init__.pyi"
6
+ INIT_FILE = Path(__file__).parent / "__init__.py"
7
+
8
+ MARK_ALL = "# -- __all__"
9
+ MARK_STATIC_IMPORTS = "# -- static imports"
10
+ MARK_DYNAMIC_IMPORTS = "# -- dynamic imports"
11
+
12
+ LAZY_MODULE_IMPORT = "from instaui.systems.module_system import LazyModule"
13
+
14
+
15
+ def create_init_file():
16
+ all_part_lines, static_lines, dynamic_lines = _split_by_marks(
17
+ PYI_FILE, [MARK_ALL, MARK_STATIC_IMPORTS, MARK_DYNAMIC_IMPORTS]
18
+ )
19
+
20
+ # first line is comment, skip it
21
+ dynamic_lines = [
22
+ _conver_dynamic(line) for line in dynamic_lines[1:] if line.strip()
23
+ ]
24
+
25
+ with open(INIT_FILE, "w", encoding="utf-8") as f:
26
+ f.writelines("\n".join(all_part_lines))
27
+ f.write("\n")
28
+ f.writelines("\n".join(static_lines))
29
+ f.write("\n")
30
+
31
+ f.writelines(
32
+ "\n".join([MARK_DYNAMIC_IMPORTS, LAZY_MODULE_IMPORT, *dynamic_lines])
33
+ )
34
+
35
+ print(f"Create {INIT_FILE} success.")
36
+
37
+
38
+ def _split_by_marks(file: Path, marks: List[str]):
39
+ with open(file, "r", encoding="utf-8") as f:
40
+ lines = f.read().splitlines()
41
+
42
+ marks_index = [lines.index(mark) for mark in marks]
43
+ marks_index.append(len(lines))
44
+
45
+ return [
46
+ lines[marks_index[i] : marks_index[i + 1]] for i in range(len(marks_index) - 1)
47
+ ]
48
+
49
+
50
+ def _conver_dynamic(dynamic_code: str):
51
+ # "from instaui.components.highlight_code.code import Code as code" convert to "code = LazyModule('instaui.components.highlight_code.code', 'Code')"
52
+
53
+ # instaui.components.highlight_code.code
54
+ from_part = dynamic_code.split("import")[0][5:].strip()
55
+
56
+ # Code as code
57
+ import_part = dynamic_code.split("import")[1].strip()
58
+ has_as = " as " in import_part
59
+
60
+ member_name = ""
61
+ alias_name = ""
62
+
63
+ if has_as:
64
+ member_name, alias_name = import_part.split(" as ")
65
+ else:
66
+ member_name = import_part
67
+ alias_name = member_name
68
+
69
+ return f"{alias_name} = LazyModule('{from_part}', '{member_name}')"
70
+
71
+
72
+ if __name__ == "__main__":
73
+ create_init_file()
instaui/ui/__init__.py CHANGED
@@ -1,60 +1,4 @@
1
- from instaui.version import __version__
2
- from instaui.vars import TMaybeRef
3
- from instaui.vars.ref import ref, TRef
4
-
5
- from instaui.vars.data import ConstData as data, TConstData
6
- from instaui.vars.js_computed import JsComputed as js_computed, TJsComputed
7
- from instaui.vars.vue_computed import VueComputed as vue_computed, TVueComputed
8
- from instaui.vars.web_computed import web_computed as computed, TComputed
9
- from instaui.vars.state import state, StateModel
10
- from instaui.inject import inject_state, provide_state, injection_key
11
- from instaui.vars.vfor_item import TVForItem, TVForIndex
12
- from instaui.vars.element_ref import ElementRef as element_ref, run_element_method
13
- from instaui.html_tools import (
14
- to_json,
15
- add_css_link,
16
- add_js_link,
17
- add_style,
18
- add_js_code,
19
- add_vue_app_use,
20
- to_config_data,
21
- use_tailwind,
22
- )
23
-
24
- from instaui.components.element import Element as element
25
- from instaui.components.row import Row as row
26
- from instaui.components.column import Column as column
27
- from instaui.components.grid import Grid as grid
28
- from instaui.components.directive import Directive as directive
29
- from instaui.components.vfor import VFor as vfor
30
- from instaui.components.vif import VIf as vif
31
- from instaui.components.match import Match as match
32
- from instaui.components.content import Content as content
33
-
34
- from instaui.event.web_event import ui_event as event, WebEvent as TEventFn
35
- from instaui.event.js_event import js_event
36
- from instaui.vars.event_context import EventContext as event_context
37
- from instaui.runtime.context import get_context as context
38
-
39
- import instaui.js as js
40
- from instaui.watch.web_watch import watch
41
- from instaui.watch.vue_watch import VueWatch as vue_watch
42
- from instaui.watch.js_watch import js_watch
43
- from instaui.handlers.watch_handler import WatchState as TWatchState
44
- from instaui.skip import skip_output
45
- from instaui.ui_functions.input_slient_data import InputSilentData as slient
46
- from instaui.js.js_output import JsOutput as js_output
47
- import instaui.experimental as experimental
48
-
49
-
50
- from instaui.ui_functions.server import create_server as server
51
- from instaui.ui_functions.ui_page import page
52
- from instaui.ui_functions.url_location import UrlLocation as url_location
53
- from instaui.ui_functions.str_format import str_format
54
- from instaui.ui_functions.ui_types import TBindable, is_bindable
55
-
56
- from .events import on_page_request_lifespan
57
-
1
+ # -- __all__
58
2
  __all__ = [
59
3
  "__version__",
60
4
  "TMaybeRef",
@@ -87,10 +31,12 @@ __all__ = [
87
31
  "content",
88
32
  "add_style",
89
33
  "add_css_link",
34
+ "remove_css_link",
90
35
  "add_js_code",
91
36
  "add_js_link",
92
37
  "add_vue_app_use",
93
38
  "use_tailwind",
39
+ "use_page_title",
94
40
  "directive",
95
41
  "vif",
96
42
  "page",
@@ -115,4 +61,70 @@ __all__ = [
115
61
  "str_format",
116
62
  "url_location",
117
63
  "on_page_request_lifespan",
64
+ "code",
65
+ "markdown",
118
66
  ]
67
+
68
+ # -- static imports
69
+ from instaui.version import __version__
70
+ from instaui.vars import TMaybeRef
71
+ from instaui.vars.ref import ref, TRef
72
+
73
+ from instaui.vars.data import ConstData as data, TConstData
74
+ from instaui.vars.js_computed import JsComputed as js_computed, TJsComputed
75
+ from instaui.vars.vue_computed import VueComputed as vue_computed, TVueComputed
76
+ from instaui.vars.web_computed import web_computed as computed, TComputed
77
+ from instaui.vars.state import state, StateModel
78
+ from instaui.inject import inject_state, provide_state, injection_key
79
+ from instaui.vars.vfor_item import TVForItem, TVForIndex
80
+ from instaui.vars.element_ref import ElementRef as element_ref, run_element_method
81
+ from instaui.html_tools import (
82
+ to_json,
83
+ add_css_link,
84
+ remove_css_link,
85
+ add_js_link,
86
+ add_style,
87
+ add_js_code,
88
+ add_vue_app_use,
89
+ to_config_data,
90
+ use_tailwind,
91
+ use_page_title,
92
+ )
93
+
94
+ from instaui.components.element import Element as element
95
+ from instaui.components.row import Row as row
96
+ from instaui.components.column import Column as column
97
+ from instaui.components.grid import Grid as grid
98
+ from instaui.components.directive import Directive as directive
99
+ from instaui.components.vfor import VFor as vfor
100
+ from instaui.components.vif import VIf as vif
101
+ from instaui.components.match import Match as match
102
+ from instaui.components.content import Content as content
103
+
104
+ from instaui.event.web_event import ui_event as event, WebEvent as TEventFn
105
+ from instaui.event.js_event import js_event
106
+ from instaui.vars.event_context import EventContext as event_context
107
+ from instaui.runtime.context import get_context as context
108
+
109
+ import instaui.js as js
110
+ from instaui.watch.web_watch import watch
111
+ from instaui.watch.vue_watch import VueWatch as vue_watch
112
+ from instaui.watch.js_watch import js_watch
113
+ from instaui.handlers.watch_handler import WatchState as TWatchState
114
+ from instaui.skip import skip_output
115
+ from instaui.ui_functions.input_slient_data import InputSilentData as slient
116
+ from instaui.js.js_output import JsOutput as js_output
117
+ import instaui.experimental as experimental
118
+
119
+ from instaui.ui_functions.server import create_server as server
120
+ from instaui.ui_functions.ui_page import page
121
+ from instaui.ui_functions.url_location import UrlLocation as url_location
122
+ from instaui.ui_functions.str_format import str_format
123
+ from instaui.ui_functions.ui_types import TBindable, is_bindable
124
+
125
+ from .events import on_page_request_lifespan
126
+
127
+ # -- dynamic imports
128
+ from instaui.systems.module_system import LazyModule
129
+ code = LazyModule('instaui.components.highlight_code.code', 'Code')
130
+ markdown = LazyModule('instaui.components.markdown.markdown', 'Markdown')
@@ -0,0 +1,129 @@
1
+ # -- __all__
2
+ __all__ = [
3
+ "__version__",
4
+ "TMaybeRef",
5
+ "TBindable",
6
+ "is_bindable",
7
+ "ref",
8
+ "slient",
9
+ "data",
10
+ "TConstData",
11
+ "TRef",
12
+ "vue_computed",
13
+ "TVueComputed",
14
+ "js_computed",
15
+ "TJsComputed",
16
+ "computed",
17
+ "TComputed",
18
+ "state",
19
+ "StateModel",
20
+ "inject_state",
21
+ "provide_state",
22
+ "injection_key",
23
+ "TVForItem",
24
+ "TVForIndex",
25
+ "element_ref",
26
+ "run_element_method",
27
+ "to_json",
28
+ "to_config_data",
29
+ "element",
30
+ "vfor",
31
+ "content",
32
+ "add_style",
33
+ "add_css_link",
34
+ "remove_css_link",
35
+ "add_js_code",
36
+ "add_js_link",
37
+ "add_vue_app_use",
38
+ "use_tailwind",
39
+ "use_page_title",
40
+ "directive",
41
+ "vif",
42
+ "page",
43
+ "event",
44
+ "js_event",
45
+ "event_context",
46
+ "TEventFn",
47
+ "server",
48
+ "context",
49
+ "row",
50
+ "grid",
51
+ "js",
52
+ "watch",
53
+ "vue_watch",
54
+ "js_watch",
55
+ "TWatchState",
56
+ "match",
57
+ "column",
58
+ "experimental",
59
+ "skip_output",
60
+ "js_output",
61
+ "str_format",
62
+ "url_location",
63
+ "on_page_request_lifespan",
64
+ "code",
65
+ "markdown",
66
+ ]
67
+
68
+ # -- static imports
69
+ from instaui.version import __version__
70
+ from instaui.vars import TMaybeRef
71
+ from instaui.vars.ref import ref, TRef
72
+
73
+ from instaui.vars.data import ConstData as data, TConstData
74
+ from instaui.vars.js_computed import JsComputed as js_computed, TJsComputed
75
+ from instaui.vars.vue_computed import VueComputed as vue_computed, TVueComputed
76
+ from instaui.vars.web_computed import web_computed as computed, TComputed
77
+ from instaui.vars.state import state, StateModel
78
+ from instaui.inject import inject_state, provide_state, injection_key
79
+ from instaui.vars.vfor_item import TVForItem, TVForIndex
80
+ from instaui.vars.element_ref import ElementRef as element_ref, run_element_method
81
+ from instaui.html_tools import (
82
+ to_json,
83
+ add_css_link,
84
+ remove_css_link,
85
+ add_js_link,
86
+ add_style,
87
+ add_js_code,
88
+ add_vue_app_use,
89
+ to_config_data,
90
+ use_tailwind,
91
+ use_page_title,
92
+ )
93
+
94
+ from instaui.components.element import Element as element
95
+ from instaui.components.row import Row as row
96
+ from instaui.components.column import Column as column
97
+ from instaui.components.grid import Grid as grid
98
+ from instaui.components.directive import Directive as directive
99
+ from instaui.components.vfor import VFor as vfor
100
+ from instaui.components.vif import VIf as vif
101
+ from instaui.components.match import Match as match
102
+ from instaui.components.content import Content as content
103
+
104
+ from instaui.event.web_event import ui_event as event, WebEvent as TEventFn
105
+ from instaui.event.js_event import js_event
106
+ from instaui.vars.event_context import EventContext as event_context
107
+ from instaui.runtime.context import get_context as context
108
+
109
+ import instaui.js as js
110
+ from instaui.watch.web_watch import watch
111
+ from instaui.watch.vue_watch import VueWatch as vue_watch
112
+ from instaui.watch.js_watch import js_watch
113
+ from instaui.handlers.watch_handler import WatchState as TWatchState
114
+ from instaui.skip import skip_output
115
+ from instaui.ui_functions.input_slient_data import InputSilentData as slient
116
+ from instaui.js.js_output import JsOutput as js_output
117
+ import instaui.experimental as experimental
118
+
119
+ from instaui.ui_functions.server import create_server as server
120
+ from instaui.ui_functions.ui_page import page
121
+ from instaui.ui_functions.url_location import UrlLocation as url_location
122
+ from instaui.ui_functions.str_format import str_format
123
+ from instaui.ui_functions.ui_types import TBindable, is_bindable
124
+
125
+ from .events import on_page_request_lifespan
126
+
127
+ # -- dynamic imports
128
+ from instaui.components.highlight_code.code import Code as code
129
+ from instaui.components.markdown.markdown import Markdown as markdown
instaui/ui/events.py CHANGED
@@ -8,7 +8,7 @@ def on_page_request_lifespan(fn: Callable):
8
8
  Args:
9
9
  fn (Callable): A function to be called on each page request.
10
10
 
11
- Example:
11
+ Examples:
12
12
  .. code-block:: python
13
13
  @ui.on_page_request_lifespan
14
14
  def _():
@@ -1,8 +1,10 @@
1
+ from typing import Union
1
2
  from instaui.runtime.context import get_context
2
3
 
3
4
 
4
5
  def create_server(
5
6
  debug: bool = True,
7
+ use_gzip: Union[int, bool] = True,
6
8
  ):
7
9
  from instaui.fastapi_server.server import Server
8
10
 
@@ -10,4 +12,4 @@ def create_server(
10
12
  context._app_mode = "web"
11
13
  context._debug_mode = debug
12
14
 
13
- return Server.get_instance()
15
+ return Server(use_gzip=use_gzip)
instaui/zero/func.py CHANGED
@@ -1,7 +1,6 @@
1
1
  from __future__ import annotations
2
2
  import itertools
3
3
  from pathlib import Path
4
- from typing import Union
5
4
  import instaui.consts as consts
6
5
  from instaui.runtime._app import get_app_slot, get_default_app_slot
7
6
  from instaui.template import render_zero_html
@@ -10,15 +9,7 @@ from instaui.html_tools import to_config_data
10
9
  from instaui.runtime.dataclass import JsLink
11
10
 
12
11
 
13
- def to_html(file: Union[str, Path]):
14
- if isinstance(file, str):
15
- import inspect
16
-
17
- frame = inspect.currentframe().f_back # type: ignore
18
- assert frame is not None
19
- script_file = inspect.getfile(frame)
20
- file = Path(script_file).parent.joinpath(file)
21
-
12
+ def to_html(file: Path):
22
13
  file = Path(file)
23
14
 
24
15
  raw = to_html_str()
@@ -27,7 +18,7 @@ def to_html(file: Union[str, Path]):
27
18
  return file.resolve().absolute()
28
19
 
29
20
 
30
- def to_html_str():
21
+ def get_template_model():
31
22
  system_slot = get_app_slot()
32
23
  default_app_slot = get_default_app_slot()
33
24
  html_resource = system_slot._html_resource
@@ -42,6 +33,10 @@ def to_html_str():
42
33
  consts.APP_CSS_PATH,
43
34
  ],
44
35
  config_dict=config_data,
36
+ favicon=html_resource.favicon
37
+ or default_html_resource.favicon
38
+ or consts.FAVICON_PATH,
39
+ title=html_resource.title or default_html_resource.title or consts.PAGE_TITLE,
45
40
  )
46
41
 
47
42
  if html_resource.use_tailwind is None:
@@ -67,6 +62,11 @@ def to_html_str():
67
62
  for css_link in component.css:
68
63
  model.css_links.append(css_link)
69
64
 
65
+ if component.externals:
66
+ for name, url in component.externals.items():
67
+ if url.is_file():
68
+ model.add_extra_import_map(name, url)
69
+
70
70
  # register custom plugins
71
71
  for plugin in set(
72
72
  itertools.chain(
@@ -108,4 +108,9 @@ def to_html_str():
108
108
  ):
109
109
  model.style_tags.append(sylte_code)
110
110
 
111
+ return model
112
+
113
+
114
+ def to_html_str():
115
+ model = get_template_model()
111
116
  return render_zero_html(model)