instaui 0.1.15__py2.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 (283) hide show
  1. instaui/__init__.py +9 -0
  2. instaui/_helper/observable_helper.py +45 -0
  3. instaui/arco/__init__.py +191 -0
  4. instaui/arco/_settings.py +25 -0
  5. instaui/arco/_use_tools/locale.py +50 -0
  6. instaui/arco/component_types.py +1019 -0
  7. instaui/arco/components/_utils.py +22 -0
  8. instaui/arco/components/affix.py +29 -0
  9. instaui/arco/components/alert.py +42 -0
  10. instaui/arco/components/anchor.py +42 -0
  11. instaui/arco/components/auto_complete.py +96 -0
  12. instaui/arco/components/avatar.py +55 -0
  13. instaui/arco/components/back_top.py +14 -0
  14. instaui/arco/components/badge.py +14 -0
  15. instaui/arco/components/breadcrumb.py +14 -0
  16. instaui/arco/components/button.py +43 -0
  17. instaui/arco/components/calendar.py +47 -0
  18. instaui/arco/components/card.py +14 -0
  19. instaui/arco/components/carousel.py +33 -0
  20. instaui/arco/components/cascader.py +111 -0
  21. instaui/arco/components/checkbox.py +32 -0
  22. instaui/arco/components/collapse.py +31 -0
  23. instaui/arco/components/color_picker.py +45 -0
  24. instaui/arco/components/comment.py +14 -0
  25. instaui/arco/components/config_provider.py +13 -0
  26. instaui/arco/components/date_picker.py +111 -0
  27. instaui/arco/components/descriptions.py +14 -0
  28. instaui/arco/components/divider.py +13 -0
  29. instaui/arco/components/drawer.py +98 -0
  30. instaui/arco/components/dropdown.py +45 -0
  31. instaui/arco/components/empty.py +14 -0
  32. instaui/arco/components/form.py +55 -0
  33. instaui/arco/components/icon.py +17 -0
  34. instaui/arco/components/image.py +33 -0
  35. instaui/arco/components/input.py +102 -0
  36. instaui/arco/components/input_number.py +97 -0
  37. instaui/arco/components/input_password.py +38 -0
  38. instaui/arco/components/input_search.py +37 -0
  39. instaui/arco/components/input_tag.py +110 -0
  40. instaui/arco/components/layout.py +13 -0
  41. instaui/arco/components/layout_content.py +6 -0
  42. instaui/arco/components/layout_footer.py +6 -0
  43. instaui/arco/components/layout_header.py +6 -0
  44. instaui/arco/components/layout_sider.py +53 -0
  45. instaui/arco/components/link.py +36 -0
  46. instaui/arco/components/list.py +68 -0
  47. instaui/arco/components/mention.py +97 -0
  48. instaui/arco/components/menu.py +88 -0
  49. instaui/arco/components/modal.py +97 -0
  50. instaui/arco/components/overflow_list.py +29 -0
  51. instaui/arco/components/page_header.py +29 -0
  52. instaui/arco/components/pagination.py +45 -0
  53. instaui/arco/components/pop_confirm.py +58 -0
  54. instaui/arco/components/popover.py +32 -0
  55. instaui/arco/components/progress.py +14 -0
  56. instaui/arco/components/radio.py +40 -0
  57. instaui/arco/components/radio_group.py +42 -0
  58. instaui/arco/components/rate.py +45 -0
  59. instaui/arco/components/resize_box.py +62 -0
  60. instaui/arco/components/result.py +14 -0
  61. instaui/arco/components/select.py +182 -0
  62. instaui/arco/components/skeleton.py +14 -0
  63. instaui/arco/components/slider.py +38 -0
  64. instaui/arco/components/space.py +14 -0
  65. instaui/arco/components/spin.py +14 -0
  66. instaui/arco/components/split.py +76 -0
  67. instaui/arco/components/statistic.py +14 -0
  68. instaui/arco/components/steps.py +32 -0
  69. instaui/arco/components/switch.py +57 -0
  70. instaui/arco/components/tab_pane.py +12 -0
  71. instaui/arco/components/table.py +276 -0
  72. instaui/arco/components/tabs.py +101 -0
  73. instaui/arco/components/tag.py +42 -0
  74. instaui/arco/components/textarea.py +84 -0
  75. instaui/arco/components/time_picker.py +76 -0
  76. instaui/arco/components/timeline.py +14 -0
  77. instaui/arco/components/tooltip.py +29 -0
  78. instaui/arco/components/transfer.py +58 -0
  79. instaui/arco/components/tree.py +120 -0
  80. instaui/arco/components/tree_select.py +86 -0
  81. instaui/arco/components/trigger.py +58 -0
  82. instaui/arco/components/typography.py +142 -0
  83. instaui/arco/components/upload.py +71 -0
  84. instaui/arco/components/verification_code.py +58 -0
  85. instaui/arco/components/watermark.py +14 -0
  86. instaui/arco/locales/__init__.py +4 -0
  87. instaui/arco/locales/_index.py +31 -0
  88. instaui/arco/locales/en_us.py +227 -0
  89. instaui/arco/locales/zh_cn.py +224 -0
  90. instaui/arco/setup.py +36 -0
  91. instaui/arco/static/instaui-arco.css +1 -0
  92. instaui/arco/static/instaui-arco.js +55771 -0
  93. instaui/arco/types.py +24 -0
  94. instaui/boot_info.py +43 -0
  95. instaui/common/jsonable.py +37 -0
  96. instaui/components/__init__.py +0 -0
  97. instaui/components/column.py +26 -0
  98. instaui/components/component.py +47 -0
  99. instaui/components/content.py +34 -0
  100. instaui/components/directive.py +55 -0
  101. instaui/components/element.py +573 -0
  102. instaui/components/grid.py +213 -0
  103. instaui/components/html/__init__.py +49 -0
  104. instaui/components/html/_mixins.py +34 -0
  105. instaui/components/html/_preset.py +4 -0
  106. instaui/components/html/button.py +38 -0
  107. instaui/components/html/checkbox.py +35 -0
  108. instaui/components/html/date.py +28 -0
  109. instaui/components/html/div.py +7 -0
  110. instaui/components/html/form.py +7 -0
  111. instaui/components/html/heading.py +51 -0
  112. instaui/components/html/input.py +28 -0
  113. instaui/components/html/label.py +21 -0
  114. instaui/components/html/li.py +17 -0
  115. instaui/components/html/link.py +31 -0
  116. instaui/components/html/number.py +34 -0
  117. instaui/components/html/paragraph.py +29 -0
  118. instaui/components/html/range.py +48 -0
  119. instaui/components/html/select.py +69 -0
  120. instaui/components/html/span.py +19 -0
  121. instaui/components/html/table.py +36 -0
  122. instaui/components/html/textarea.py +28 -0
  123. instaui/components/html/ul.py +20 -0
  124. instaui/components/label.py +5 -0
  125. instaui/components/markdown/markdown.js +33 -0
  126. instaui/components/markdown/markdown.py +41 -0
  127. instaui/components/markdown/static/github-markdown.css +12 -0
  128. instaui/components/markdown/static/marked.esm.js +2579 -0
  129. instaui/components/match.py +108 -0
  130. instaui/components/row.py +17 -0
  131. instaui/components/shiki_code/shiki_code.js +126 -0
  132. instaui/components/shiki_code/shiki_code.py +99 -0
  133. instaui/components/shiki_code/static/langs/css.mjs +5 -0
  134. instaui/components/shiki_code/static/langs/markdown.mjs +5 -0
  135. instaui/components/shiki_code/static/langs/python.mjs +5 -0
  136. instaui/components/shiki_code/static/langs/shell.mjs +2 -0
  137. instaui/components/shiki_code/static/langs/shellscript.mjs +5 -0
  138. instaui/components/shiki_code/static/shiki-core.js +5784 -0
  139. instaui/components/shiki_code/static/shiki-style.css +179 -0
  140. instaui/components/shiki_code/static/shiki-transformers.js +461 -0
  141. instaui/components/shiki_code/static/themes/vitesse-dark.mjs +2 -0
  142. instaui/components/shiki_code/static/themes/vitesse-light.mjs +2 -0
  143. instaui/components/slot.py +81 -0
  144. instaui/components/transition_group.py +9 -0
  145. instaui/components/value_element.py +52 -0
  146. instaui/components/vfor.py +142 -0
  147. instaui/components/vif.py +42 -0
  148. instaui/consts.py +23 -0
  149. instaui/dependencies/component_dependency.py +22 -0
  150. instaui/dependencies/plugin_dependency.py +28 -0
  151. instaui/event/event_mixin.py +12 -0
  152. instaui/event/js_event.py +82 -0
  153. instaui/event/vue_event.py +66 -0
  154. instaui/event/web_event.py +123 -0
  155. instaui/experimental/__init__.py +3 -0
  156. instaui/experimental/debug.py +48 -0
  157. instaui/extra_libs/_echarts.py +3 -0
  158. instaui/extra_libs/_import_error.py +9 -0
  159. instaui/extra_libs/_mermaid.py +3 -0
  160. instaui/extra_libs/_shiki_code.py +3 -0
  161. instaui/fastapi_server/_utils.py +42 -0
  162. instaui/fastapi_server/_uvicorn.py +37 -0
  163. instaui/fastapi_server/debug_mode_router.py +60 -0
  164. instaui/fastapi_server/dependency_router.py +28 -0
  165. instaui/fastapi_server/event_router.py +58 -0
  166. instaui/fastapi_server/middlewares.py +19 -0
  167. instaui/fastapi_server/request_context.py +19 -0
  168. instaui/fastapi_server/resource.py +30 -0
  169. instaui/fastapi_server/server.py +308 -0
  170. instaui/fastapi_server/watch_router.py +53 -0
  171. instaui/handlers/_utils.py +88 -0
  172. instaui/handlers/event_handler.py +60 -0
  173. instaui/handlers/watch_handler.py +61 -0
  174. instaui/html_tools.py +94 -0
  175. instaui/inject.py +33 -0
  176. instaui/js/__init__.py +4 -0
  177. instaui/js/js_output.py +15 -0
  178. instaui/js/lambda_func.py +35 -0
  179. instaui/launch_collector.py +52 -0
  180. instaui/page_info.py +13 -0
  181. instaui/runtime/__init__.py +29 -0
  182. instaui/runtime/_app.py +234 -0
  183. instaui/runtime/_inner_helper.py +9 -0
  184. instaui/runtime/_link_manager.py +89 -0
  185. instaui/runtime/context.py +47 -0
  186. instaui/runtime/dataclass.py +30 -0
  187. instaui/runtime/resource.py +65 -0
  188. instaui/runtime/scope.py +133 -0
  189. instaui/runtime/ui_state_scope.py +15 -0
  190. instaui/settings/__init__.py +4 -0
  191. instaui/settings/__settings.py +13 -0
  192. instaui/shadcn_classless/_index.py +42 -0
  193. instaui/shadcn_classless/static/shadcn-classless.css +403 -0
  194. instaui/skip.py +12 -0
  195. instaui/spa_router/__init__.py +26 -0
  196. instaui/spa_router/_components.py +35 -0
  197. instaui/spa_router/_file_base_utils.py +273 -0
  198. instaui/spa_router/_functions.py +122 -0
  199. instaui/spa_router/_install.py +11 -0
  200. instaui/spa_router/_route_model.py +117 -0
  201. instaui/spa_router/_router_box.py +40 -0
  202. instaui/spa_router/_router_output.py +22 -0
  203. instaui/spa_router/_router_param_var.py +51 -0
  204. instaui/spa_router/_types.py +4 -0
  205. instaui/spa_router/templates/page_routes +60 -0
  206. instaui/static/insta-ui.css +1 -0
  207. instaui/static/insta-ui.esm-browser.prod.js +3717 -0
  208. instaui/static/insta-ui.ico +0 -0
  209. instaui/static/insta-ui.js.map +1 -0
  210. instaui/static/instaui-tools-browser.js +511 -0
  211. instaui/static/templates/debug/sse.html +117 -0
  212. instaui/static/templates/web.html +74 -0
  213. instaui/static/templates/webview.html +78 -0
  214. instaui/static/templates/zero.html +71 -0
  215. instaui/static/vue.esm-browser.prod.js +9 -0
  216. instaui/static/vue.global.prod.js +9 -0
  217. instaui/static/vue.runtime.esm-browser.prod.js +5 -0
  218. instaui/systems/file_system.py +6 -0
  219. instaui/systems/func_system.py +119 -0
  220. instaui/systems/js_system.py +22 -0
  221. instaui/systems/module_system.py +46 -0
  222. instaui/systems/pydantic_system.py +27 -0
  223. instaui/systems/string_system.py +10 -0
  224. instaui/tailwind/__init__.py +6 -0
  225. instaui/tailwind/_index.py +24 -0
  226. instaui/tailwind/static/tailwindcss-v3.min.js +62 -0
  227. instaui/tailwind/static/tailwindcss-v4.min.js +8 -0
  228. instaui/template/__init__.py +4 -0
  229. instaui/template/_utils.py +23 -0
  230. instaui/template/env.py +7 -0
  231. instaui/template/web_template.py +49 -0
  232. instaui/template/webview_template.py +48 -0
  233. instaui/template/zero_template.py +105 -0
  234. instaui/ui/__init__.py +144 -0
  235. instaui/ui/__init__.pyi +149 -0
  236. instaui/ui/events.py +25 -0
  237. instaui/ui_functions/input_slient_data.py +16 -0
  238. instaui/ui_functions/server.py +15 -0
  239. instaui/ui_functions/str_format.py +36 -0
  240. instaui/ui_functions/ui_page.py +16 -0
  241. instaui/ui_functions/ui_types.py +13 -0
  242. instaui/ui_functions/url_location.py +33 -0
  243. instaui/vars/_types.py +8 -0
  244. instaui/vars/data.py +68 -0
  245. instaui/vars/element_ref.py +40 -0
  246. instaui/vars/event_context.py +49 -0
  247. instaui/vars/event_extend.py +0 -0
  248. instaui/vars/js_computed.py +117 -0
  249. instaui/vars/mixin_types/common_type.py +5 -0
  250. instaui/vars/mixin_types/element_binding.py +16 -0
  251. instaui/vars/mixin_types/observable.py +7 -0
  252. instaui/vars/mixin_types/pathable.py +14 -0
  253. instaui/vars/mixin_types/py_binding.py +13 -0
  254. instaui/vars/mixin_types/str_format_binding.py +8 -0
  255. instaui/vars/mixin_types/var_type.py +5 -0
  256. instaui/vars/path_var.py +90 -0
  257. instaui/vars/ref.py +103 -0
  258. instaui/vars/slot_prop.py +46 -0
  259. instaui/vars/state.py +97 -0
  260. instaui/vars/types.py +24 -0
  261. instaui/vars/vfor_item.py +204 -0
  262. instaui/vars/vue_computed.py +81 -0
  263. instaui/vars/web_computed.py +209 -0
  264. instaui/vars/web_view_computed.py +1 -0
  265. instaui/version.py +3 -0
  266. instaui/watch/_types.py +4 -0
  267. instaui/watch/_utils.py +3 -0
  268. instaui/watch/js_watch.py +110 -0
  269. instaui/watch/vue_watch.py +77 -0
  270. instaui/watch/web_watch.py +181 -0
  271. instaui/webview/__init__.py +2 -0
  272. instaui/webview/_utils.py +8 -0
  273. instaui/webview/api.py +72 -0
  274. instaui/webview/func.py +114 -0
  275. instaui/webview/index.py +161 -0
  276. instaui/webview/resource.py +172 -0
  277. instaui/zero/__init__.py +3 -0
  278. instaui/zero/func.py +123 -0
  279. instaui/zero/scope.py +109 -0
  280. instaui-0.1.15.dist-info/METADATA +152 -0
  281. instaui-0.1.15.dist-info/RECORD +283 -0
  282. instaui-0.1.15.dist-info/WHEEL +5 -0
  283. instaui-0.1.15.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,4 @@
1
+ from .web_template import render_web_html
2
+ from .zero_template import render_zero_html
3
+
4
+ __all__ = ["render_web_html", "render_zero_html"]
@@ -0,0 +1,23 @@
1
+ from __future__ import annotations
2
+ import typing
3
+ from pathlib import Path
4
+ from urllib.parse import quote
5
+ import base64
6
+
7
+
8
+ _JS_PREFIX = "data:text/javascript;charset=utf-8"
9
+ _CSS_PREFIX = "data:text/css;charset=utf-8"
10
+ _ICON_PREFIX = "data:image/x-icon;base64"
11
+
12
+
13
+ def normalize_path_to_dataurl(path: typing.Union[str, Path], prefix: str):
14
+ if isinstance(path, Path):
15
+ path = path.read_text(encoding="utf-8")
16
+
17
+ return f"{prefix},{quote(path)}"
18
+
19
+
20
+ def normalize_path_to_base64_url(path: typing.Optional[Path], prefix: str):
21
+ if path is None:
22
+ return None
23
+ return f"{prefix},{base64.b64encode(path.read_bytes()).decode('utf-8')}"
@@ -0,0 +1,7 @@
1
+ from __future__ import annotations
2
+ import jinja2
3
+
4
+
5
+ env = jinja2.Environment(
6
+ loader=jinja2.PackageLoader("instaui.static", "templates"),
7
+ )
@@ -0,0 +1,49 @@
1
+ from __future__ import annotations
2
+ import typing
3
+ from dataclasses import dataclass, field
4
+ from .env import env
5
+ from instaui.common.jsonable import dumps
6
+ from instaui.runtime.context import get_context
7
+ from instaui.runtime.dataclass import JsLink, VueAppComponent
8
+
9
+
10
+ _html_template = env.get_template("web.html")
11
+
12
+
13
+ @dataclass
14
+ class WebTemplateModel:
15
+ vue_js_link: str
16
+ instaui_js_link: str
17
+ config_dict: typing.Dict[str, typing.Any] = field(default_factory=dict)
18
+ extra_import_maps: typing.Dict[str, str] = field(default_factory=dict)
19
+ css_links: typing.List[str] = field(default_factory=list)
20
+ style_tags: typing.List[str] = field(default_factory=list)
21
+ js_links: typing.List[JsLink] = field(default_factory=list)
22
+ script_tags: typing.List[str] = field(default_factory=list)
23
+ vue_app_use: typing.List[str] = field(default_factory=list)
24
+ vue_app_component: typing.List[VueAppComponent] = field(default_factory=list)
25
+ prefix: str = ""
26
+ title: typing.Optional[str] = None
27
+ favicon_url: str = ""
28
+
29
+ def add_extra_import_map(self, name: str, url: str):
30
+ self.extra_import_maps[name] = url
31
+
32
+ @property
33
+ def import_maps_string(self):
34
+ data = {
35
+ **self.extra_import_maps,
36
+ "vue": self.vue_js_link,
37
+ "instaui": self.instaui_js_link,
38
+ }
39
+
40
+ return dumps(data)
41
+
42
+ @property
43
+ def is_debug(self):
44
+ context = get_context()
45
+ return context.debug_mode
46
+
47
+
48
+ def render_web_html(model: WebTemplateModel):
49
+ return _html_template.render(model=model)
@@ -0,0 +1,48 @@
1
+ from __future__ import annotations
2
+ import typing
3
+ from dataclasses import dataclass, field
4
+ from instaui.common.jsonable import dumps
5
+ from .env import env
6
+
7
+
8
+ _html_template = env.get_template("webview.html")
9
+
10
+
11
+ @dataclass(frozen=True)
12
+ class WebViewVueAppComponent:
13
+ name: str
14
+ url: str
15
+
16
+
17
+ @dataclass
18
+ class WebViewTemplateModel:
19
+ vue_js_code: str
20
+ instaui_js_code: str
21
+ config_dict: typing.Dict[str, typing.Any] = field(default_factory=dict)
22
+ extra_import_maps: typing.Dict[str, str] = field(default_factory=dict)
23
+ css_links: typing.List[str] = field(default_factory=list)
24
+ style_tags: typing.List[str] = field(default_factory=list)
25
+ js_links: typing.List[str] = field(default_factory=list)
26
+ script_tags: typing.List[str] = field(default_factory=list)
27
+ vue_app_use: typing.List[str] = field(default_factory=list)
28
+ vue_app_component: typing.List[WebViewVueAppComponent] = field(default_factory=list)
29
+ title: typing.Optional[str] = None
30
+ favicon_url: typing.Optional[str] = None
31
+ on_app_mounted: typing.Optional[typing.Callable] = None
32
+
33
+ def add_extra_import_map(self, name: str, code: str):
34
+ self.extra_import_maps[name] = code
35
+
36
+ @property
37
+ def import_maps_string(self):
38
+ data = {
39
+ **self.extra_import_maps,
40
+ "vue": self.vue_js_code,
41
+ "instaui": self.instaui_js_code,
42
+ }
43
+
44
+ return dumps(data)
45
+
46
+
47
+ def render_wbeview_html(model: WebViewTemplateModel) -> str:
48
+ return _html_template.render(model=model)
@@ -0,0 +1,105 @@
1
+ from __future__ import annotations
2
+ import typing
3
+ from pathlib import Path
4
+ from urllib.parse import quote
5
+ import base64
6
+ from dataclasses import dataclass, field
7
+ from .env import env
8
+ from instaui.common.jsonable import dumps
9
+ from instaui.runtime.dataclass import JsLink
10
+
11
+ _TCodeOrPath = typing.Union[str, Path]
12
+ _JS_PREFIX = "data:text/javascript;charset=utf-8"
13
+ _CSS_PREFIX = "data:text/css;charset=utf-8"
14
+ _ICON_PREFIX = "data:image/x-icon;base64"
15
+
16
+ _html_template = env.get_template("zero.html")
17
+
18
+
19
+ @dataclass(frozen=True)
20
+ class ZeroVueAppComponent:
21
+ name: str
22
+ url: _TCodeOrPath
23
+
24
+
25
+ @dataclass
26
+ class ZeroTemplateModel:
27
+ vue_js_code: _TCodeOrPath
28
+ instaui_js_code: _TCodeOrPath
29
+ config_dict: typing.Dict[str, typing.Any] = field(default_factory=dict)
30
+ extra_import_maps: typing.Dict[str, _TCodeOrPath] = field(default_factory=dict)
31
+ css_links: typing.List[_TCodeOrPath] = field(default_factory=list)
32
+ style_tags: typing.List[str] = field(default_factory=list)
33
+ js_links: typing.List[JsLink] = field(default_factory=list)
34
+ script_tags: typing.List[str] = field(default_factory=list)
35
+ vue_app_use: typing.List[str] = field(default_factory=list)
36
+ vue_app_component: typing.List[ZeroVueAppComponent] = field(default_factory=list)
37
+ prefix: str = ""
38
+ title: typing.Optional[str] = None
39
+ favicon: typing.Optional[Path] = None
40
+
41
+ def add_extra_import_map(self, name: str, url: _TCodeOrPath):
42
+ self.extra_import_maps[name] = url
43
+
44
+ @property
45
+ def import_maps_string(self):
46
+ data = {
47
+ **self.extra_import_maps,
48
+ "vue": self.vue_js_code,
49
+ "instaui": self.instaui_js_code,
50
+ }
51
+
52
+ return dumps(data)
53
+
54
+ def normalize_path_with_self(self):
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
+ self.instaui_js_code, _JS_PREFIX
58
+ )
59
+
60
+ self.css_links = [
61
+ _normalize_path_to_dataurl(link, _CSS_PREFIX)
62
+ for link in self.css_links
63
+ if isinstance(link, str) or (isinstance(link, Path) and link.is_file())
64
+ ]
65
+
66
+ self.js_links = [
67
+ JsLink(
68
+ link=_normalize_path_to_dataurl(link.link, _JS_PREFIX),
69
+ attrs=link.attrs,
70
+ )
71
+ for link in self.js_links
72
+ ]
73
+
74
+ self.extra_import_maps = {
75
+ k: _normalize_path_to_dataurl(v, _JS_PREFIX)
76
+ for k, v in self.extra_import_maps.items()
77
+ }
78
+
79
+ self.vue_app_component = [
80
+ ZeroVueAppComponent(
81
+ name=component.name,
82
+ url=_normalize_path_to_dataurl(component.url, _JS_PREFIX),
83
+ )
84
+ for component in self.vue_app_component
85
+ ]
86
+
87
+ self.favicon = _normalize_path_to_base64_url(self.favicon, _ICON_PREFIX) # type: ignore
88
+
89
+
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")
93
+
94
+ return f"{prefix},{quote(path)}"
95
+
96
+
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')}"
101
+
102
+
103
+ def render_zero_html(model: ZeroTemplateModel) -> str:
104
+ model.normalize_path_with_self()
105
+ return _html_template.render(model=model)
instaui/ui/__init__.py ADDED
@@ -0,0 +1,144 @@
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
+ "label",
33
+ "add_style",
34
+ "add_css_link",
35
+ "remove_css_link",
36
+ "add_js_code",
37
+ "add_js_link",
38
+ "add_vue_app_use",
39
+ "use_tailwind",
40
+ "use_page_title",
41
+ "directive",
42
+ "vif",
43
+ "page",
44
+ "event",
45
+ "js_event",
46
+ "vue_event",
47
+ "event_context",
48
+ "TEventFn",
49
+ "server",
50
+ "context",
51
+ "row",
52
+ "grid",
53
+ "js",
54
+ "watch",
55
+ "vue_watch",
56
+ "js_watch",
57
+ "TWatchState",
58
+ "match",
59
+ "column",
60
+ "experimental",
61
+ "skip_output",
62
+ "js_output",
63
+ "str_format",
64
+ "url_location",
65
+ "on_page_request_lifespan",
66
+ "webview",
67
+ "code",
68
+ "markdown",
69
+ "echarts",
70
+ "use_shadcn_classless",
71
+ "mermaid",
72
+ ]
73
+
74
+ # -- static imports
75
+ from instaui.version import __version__
76
+ from instaui.vars.types import TMaybeRef
77
+ from instaui.vars.ref import ref, TRef
78
+
79
+ from instaui.vars.data import ConstData as data, TConstData
80
+ from instaui.vars.js_computed import JsComputed as js_computed, TJsComputed
81
+ from instaui.vars.vue_computed import VueComputed as vue_computed, TVueComputed
82
+ from instaui.vars.web_computed import web_computed as computed, TComputed
83
+ from instaui.vars.state import state, StateModel
84
+ from instaui.inject import inject_state, provide_state, injection_key
85
+ from instaui.vars.vfor_item import TVForItem, TVForIndex
86
+ from instaui.vars.element_ref import ElementRef as element_ref, run_element_method
87
+ from instaui.html_tools import (
88
+ to_json,
89
+ add_css_link,
90
+ remove_css_link,
91
+ add_js_link,
92
+ add_style,
93
+ add_js_code,
94
+ add_vue_app_use,
95
+ to_config_data,
96
+ use_tailwind,
97
+ use_page_title,
98
+ )
99
+
100
+ from instaui.components.element import Element as element
101
+ from instaui.components.row import Row as row
102
+ from instaui.components.column import Column as column
103
+ from instaui.components.grid import Grid as grid
104
+ from instaui.components.directive import Directive as directive
105
+ from instaui.components.vfor import VFor as vfor
106
+ from instaui.components.vif import VIf as vif
107
+ from instaui.components.match import Match as match
108
+ from instaui.components.content import Content as content
109
+ from instaui.components.label import label
110
+
111
+ from instaui.event.web_event import event, WebEvent as TEventFn
112
+ from instaui.event.js_event import js_event
113
+ from instaui.event.vue_event import vue_event
114
+ from instaui.vars.event_context import EventContext as event_context
115
+ from instaui.runtime.context import get_context as context
116
+
117
+ import instaui.js as js
118
+ from instaui.watch.web_watch import watch
119
+ from instaui.watch.vue_watch import VueWatch as vue_watch
120
+ from instaui.watch.js_watch import js_watch
121
+ from instaui.handlers.watch_handler import WatchState as TWatchState
122
+ from instaui.skip import skip_output
123
+ from instaui.ui_functions.input_slient_data import InputSilentData as slient
124
+ from instaui.js.js_output import JsOutput as js_output
125
+ import instaui.experimental as experimental
126
+
127
+ from instaui.ui_functions.server import create_server as server
128
+ from instaui.ui_functions.ui_page import page
129
+ from instaui.ui_functions.url_location import UrlLocation as url_location
130
+ from instaui.ui_functions.str_format import str_format
131
+ from instaui.ui_functions.ui_types import TBindable, is_bindable
132
+
133
+ from .events import on_page_request_lifespan
134
+ from instaui.extra_libs._import_error import show_error # noqa: E402, F401
135
+
136
+ # -- dynamic imports
137
+ from instaui.systems.module_system import LazyModule as _LazyModule
138
+ markdown = _LazyModule('instaui.components.markdown.markdown', 'Markdown')
139
+ webview = _LazyModule('instaui.webview', 'WebviewWrapper')
140
+ use_shadcn_classless = _LazyModule('instaui.shadcn_classless._index', 'use_shadcn_classless')
141
+ # -- extra libs
142
+ mermaid = _LazyModule('instaui.extra_libs._mermaid', 'mermaid', import_error_callback=show_error('Mermaid is not installed. Please run "pip install instaui-mermaid" to install it.'),)
143
+ code = _LazyModule('instaui.extra_libs._shiki_code', 'code', import_error_callback=show_error('Shiki is not installed. Please run "pip install instaui-shiki" to install it.'),)
144
+ echarts = _LazyModule('instaui.extra_libs._echarts', 'echarts', import_error_callback=show_error('Echarts is not installed. Please run "pip install instaui-echarts" to install it.'),)
@@ -0,0 +1,149 @@
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
+ "label",
33
+ "add_style",
34
+ "add_css_link",
35
+ "remove_css_link",
36
+ "add_js_code",
37
+ "add_js_link",
38
+ "add_vue_app_use",
39
+ "use_tailwind",
40
+ "use_page_title",
41
+ "directive",
42
+ "vif",
43
+ "page",
44
+ "event",
45
+ "js_event",
46
+ "vue_event",
47
+ "event_context",
48
+ "TEventFn",
49
+ "server",
50
+ "context",
51
+ "row",
52
+ "grid",
53
+ "js",
54
+ "watch",
55
+ "vue_watch",
56
+ "js_watch",
57
+ "TWatchState",
58
+ "match",
59
+ "column",
60
+ "experimental",
61
+ "skip_output",
62
+ "js_output",
63
+ "str_format",
64
+ "url_location",
65
+ "on_page_request_lifespan",
66
+ "webview",
67
+ "code",
68
+ "markdown",
69
+ "echarts",
70
+ "use_shadcn_classless",
71
+ "mermaid",
72
+ ]
73
+
74
+ # -- static imports
75
+ from instaui.version import __version__
76
+ from instaui.vars.types import TMaybeRef
77
+ from instaui.vars.ref import ref, TRef
78
+
79
+ from instaui.vars.data import ConstData as data, TConstData
80
+ from instaui.vars.js_computed import JsComputed as js_computed, TJsComputed
81
+ from instaui.vars.vue_computed import VueComputed as vue_computed, TVueComputed
82
+ from instaui.vars.web_computed import web_computed as computed, TComputed
83
+ from instaui.vars.state import state, StateModel
84
+ from instaui.inject import inject_state, provide_state, injection_key
85
+ from instaui.vars.vfor_item import TVForItem, TVForIndex
86
+ from instaui.vars.element_ref import ElementRef as element_ref, run_element_method
87
+ from instaui.html_tools import (
88
+ to_json,
89
+ add_css_link,
90
+ remove_css_link,
91
+ add_js_link,
92
+ add_style,
93
+ add_js_code,
94
+ add_vue_app_use,
95
+ to_config_data,
96
+ use_tailwind,
97
+ use_page_title,
98
+ )
99
+
100
+ from instaui.components.element import Element as element
101
+ from instaui.components.row import Row as row
102
+ from instaui.components.column import Column as column
103
+ from instaui.components.grid import Grid as grid
104
+ from instaui.components.directive import Directive as directive
105
+ from instaui.components.vfor import VFor as vfor
106
+ from instaui.components.vif import VIf as vif
107
+ from instaui.components.match import Match as match
108
+ from instaui.components.content import Content as content
109
+ from instaui.components.label import label
110
+
111
+ from instaui.event.web_event import event, WebEvent as TEventFn
112
+ from instaui.event.js_event import js_event
113
+ from instaui.event.vue_event import vue_event
114
+ from instaui.vars.event_context import EventContext as event_context
115
+ from instaui.runtime.context import get_context as context
116
+
117
+ import instaui.js as js
118
+ from instaui.watch.web_watch import watch
119
+ from instaui.watch.vue_watch import VueWatch as vue_watch
120
+ from instaui.watch.js_watch import js_watch
121
+ from instaui.handlers.watch_handler import WatchState as TWatchState
122
+ from instaui.skip import skip_output
123
+ from instaui.ui_functions.input_slient_data import InputSilentData as slient
124
+ from instaui.js.js_output import JsOutput as js_output
125
+ import instaui.experimental as experimental
126
+
127
+ from instaui.ui_functions.server import create_server as server
128
+ from instaui.ui_functions.ui_page import page
129
+ from instaui.ui_functions.url_location import UrlLocation as url_location
130
+ from instaui.ui_functions.str_format import str_format
131
+ from instaui.ui_functions.ui_types import TBindable, is_bindable
132
+
133
+ from .events import on_page_request_lifespan
134
+ from instaui.extra_libs._import_error import show_error # noqa: E402, F401
135
+
136
+ # -- dynamic imports
137
+ from instaui.components.markdown.markdown import Markdown as markdown
138
+ from instaui.webview import WebviewWrapper as webview
139
+ from instaui.shadcn_classless._index import use_shadcn_classless
140
+
141
+ # -- extra libs
142
+ # mermaid = _LazyModule('instaui.extra_libs._mermaid', 'mermaid', import_error_callback=show_error('Mermaid is not installed. Please run "pip install instaui-mermaid" to install it.'),)
143
+ from instaui_mermaid import Mermaid as mermaid # type: ignore
144
+
145
+ # code = _LazyModule('instaui.extra_libs._shiki_code', 'code', import_error_callback=show_error('Shiki is not installed. Please run "pip install instaui-shiki" to install it.'),)
146
+ from instaui_shiki import shiki as code # type: ignore
147
+
148
+ # echarts = _LazyModule('instaui.extra_libs._echarts', 'echarts', import_error_callback=show_error('Echarts is not installed. Please run "pip install instaui-echarts" to install it.'),)
149
+ from instaui_echarts import echarts # type: ignore
instaui/ui/events.py ADDED
@@ -0,0 +1,25 @@
1
+ from typing import Callable
2
+ from instaui.launch_collector import get_launch_collector
3
+
4
+
5
+ def on_page_request_lifespan(fn: Callable):
6
+ """Register a function to be called on each page request.
7
+
8
+ Args:
9
+ fn (Callable): A function to be called on each page request.
10
+
11
+ Examples:
12
+ .. code-block:: python
13
+ @ui.on_page_request_lifespan
14
+ def _():
15
+ print("page request start")
16
+ yield
17
+ print("page request end")
18
+
19
+ # can stop the lifespan by calling the returned function
20
+ stop_lifespan = ui.on_page_request_lifespan(lambda: None)
21
+ stop_lifespan()
22
+ """
23
+
24
+ remove_key = get_launch_collector().add_page_request_lifespan(fn)
25
+ return lambda: get_launch_collector().remove_page_request_lifespan(remove_key)
@@ -0,0 +1,16 @@
1
+ import typing
2
+ from instaui.vars.mixin_types.py_binding import CanInputMixin
3
+
4
+
5
+ class InputSilentData(CanInputMixin):
6
+ def __init__(self, value: typing.Union[CanInputMixin, typing.Any]) -> None:
7
+ self.value = value
8
+
9
+ def is_const_value(self) -> bool:
10
+ return not isinstance(self.value, CanInputMixin)
11
+
12
+ def _to_input_config(self):
13
+ if isinstance(self.value, CanInputMixin):
14
+ return self.value._to_input_config()
15
+ else:
16
+ return self.value
@@ -0,0 +1,15 @@
1
+ from typing import Union
2
+ from instaui.runtime.context import get_context
3
+
4
+
5
+ def create_server(
6
+ debug: bool = True,
7
+ use_gzip: Union[int, bool] = True,
8
+ ):
9
+ from instaui.fastapi_server.server import Server
10
+
11
+ context = get_context()
12
+ context._app_mode = "web"
13
+ context._debug_mode = debug
14
+
15
+ return Server(use_gzip=use_gzip)
@@ -0,0 +1,36 @@
1
+ from typing import cast
2
+ from instaui.vars.mixin_types.str_format_binding import StrFormatBindingMixin
3
+ from instaui.vars.vue_computed import VueComputed
4
+
5
+
6
+ def str_format(template: str, *args, **kwargs):
7
+ bindings = {}
8
+
9
+ tran_args = []
10
+
11
+ for idx, arg in enumerate(args):
12
+ is_mixin = isinstance(arg, StrFormatBindingMixin)
13
+ value = (
14
+ cast(StrFormatBindingMixin, arg)._to_str_format_binding(idx)
15
+ if is_mixin
16
+ else arg
17
+ )
18
+ tran_args.append(value[-1] if is_mixin else value)
19
+ if is_mixin:
20
+ bindings[value[0]] = arg
21
+
22
+ tran_kwargs = {}
23
+
24
+ for idx, (k, v) in enumerate(kwargs.items()):
25
+ is_mixin = isinstance(v, StrFormatBindingMixin)
26
+ value = (
27
+ cast(StrFormatBindingMixin, v)._to_str_format_binding(idx)
28
+ if is_mixin
29
+ else v
30
+ )
31
+ tran_kwargs[k] = value[-1] if is_mixin else value
32
+ if is_mixin:
33
+ bindings[value[0]] = v
34
+
35
+ code = "()=>`" + template.format(*tran_args, **tran_kwargs) + "`"
36
+ return VueComputed(code, bindings=bindings)
@@ -0,0 +1,16 @@
1
+ from typing import Callable
2
+ from instaui.launch_collector import get_launch_collector, PageInfo
3
+
4
+
5
+ def page(path: str = "/"):
6
+ """Register a page route.
7
+
8
+ Args:
9
+ path (str): The route path.
10
+ """
11
+
12
+ def wrapper(func: Callable):
13
+ get_launch_collector().register_page(PageInfo(path, func))
14
+ return func
15
+
16
+ return wrapper
@@ -0,0 +1,13 @@
1
+ from typing import Any, TypeVar, Union
2
+ from instaui.vars.mixin_types.observable import ObservableMixin
3
+ from instaui.vars.mixin_types.py_binding import CanInputMixin, CanOutputMixin
4
+ from instaui.vars.mixin_types.element_binding import ElementBindingMixin
5
+
6
+ _T = TypeVar("_T")
7
+
8
+
9
+ def is_bindable(obj: Any):
10
+ return isinstance(obj, (CanInputMixin, CanOutputMixin,ObservableMixin, ElementBindingMixin))
11
+
12
+
13
+ TBindable = Union[CanInputMixin, CanOutputMixin,ObservableMixin, ElementBindingMixin[_T]]