pyjs 0.0.1__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 (146) hide show
  1. pyjs/__init__.py +6 -0
  2. pyjs/__main__.py +6 -0
  3. pyjs/cli.py +816 -0
  4. pyjs/decorators.py +170 -0
  5. pyjs/docs/__init__.py +6 -0
  6. pyjs/docs/builder.py +351 -0
  7. pyjs/docs/cli.py +55 -0
  8. pyjs/docs/config.py +45 -0
  9. pyjs/docs/favicon.svg +18 -0
  10. pyjs/docs/markdown.py +61 -0
  11. pyjs/docs/models.py +38 -0
  12. pyjs/docs/navigation.py +61 -0
  13. pyjs/docs/style.css +901 -0
  14. pyjs/docs/ui.py +349 -0
  15. pyjs/nativescript/__init__.py +77 -0
  16. pyjs/scaffolding/__init__.py +418 -0
  17. pyjs/scaffolding/templates/app/README.md.template +33 -0
  18. pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__PYJS_PACKAGE__.py.template +81 -0
  19. pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__init__.py.template +0 -0
  20. pyjs/scaffolding/templates/app/__PYJS_SOURCE_ROOT__/__PYJS_PACKAGE__/__main__.py.template +5 -0
  21. pyjs/scaffolding/templates/app/tests/test_app.py.template +22 -0
  22. pyjs/scaffolding/templates/app/tests/test_browser_app.py.template +19 -0
  23. pyjs/scaffolding/templates/app_test.py.template +8 -0
  24. pyjs/server.py +468 -0
  25. pyjs/skills/pyjs/SKILL.md +161 -0
  26. pyjs/state.py +101 -0
  27. pyjs/testing/__init__.py +3 -0
  28. pyjs/testing/android.py +248 -0
  29. pyjs/testing/artifacts.py +37 -0
  30. pyjs/testing/assertion_rewriter.py +125 -0
  31. pyjs/testing/builder.py +191 -0
  32. pyjs/testing/capture.py +133 -0
  33. pyjs/testing/client/__init__.py +1 -0
  34. pyjs/testing/client/app.py +718 -0
  35. pyjs/testing/client/assertions.py +49 -0
  36. pyjs/testing/client/runtime.py +123 -0
  37. pyjs/testing/client/sidebar.py +377 -0
  38. pyjs/testing/client/state.py +107 -0
  39. pyjs/testing/client/viewer.py +361 -0
  40. pyjs/testing/daemon.py +641 -0
  41. pyjs/testing/helpers.py +155 -0
  42. pyjs/testing/protocol.py +56 -0
  43. pyjs/testing/pytest_plugin.py +797 -0
  44. pyjs/testing/web.py +97 -0
  45. pyjs/testing/webgpu.py +27 -0
  46. pyjs/tooling/__init__.py +4 -0
  47. pyjs/tooling/android.py +138 -0
  48. pyjs/tooling/browser.py +676 -0
  49. pyjs/tooling/command.py +75 -0
  50. pyjs/tooling/nativescript.py +156 -0
  51. pyjs/tooling/node.py +170 -0
  52. pyjs/tooling/perf.py +163 -0
  53. pyjs/transpiler/__init__.py +23 -0
  54. pyjs/transpiler/_builtins.py +485 -0
  55. pyjs/transpiler/analyzer.py +1495 -0
  56. pyjs/transpiler/objects.py +1015 -0
  57. pyjs/transpiler/source.py +189 -0
  58. pyjs/transpiler/transpiler.py +748 -0
  59. pyjs/transpiler/utils.py +150 -0
  60. pyjs/web/__init__.py +5 -0
  61. pyjs/web/console.py +16 -0
  62. pyjs/web/dom.py +1529 -0
  63. pyjs/web/domx.py +474 -0
  64. pyjs/web/dragdrop.py +102 -0
  65. pyjs/web/events.py +1306 -0
  66. pyjs/web/files.py +203 -0
  67. pyjs/web/geometry.py +475 -0
  68. pyjs/web/html.py +927 -0
  69. pyjs/web/indexeddb.py +410 -0
  70. pyjs/web/javascript.py +112 -0
  71. pyjs/web/network.py +193 -0
  72. pyjs/web/ssr.py +70 -0
  73. pyjs/web/streams.py +17 -0
  74. pyjs/web/svg.py +684 -0
  75. pyjs/web/timers.py +29 -0
  76. pyjs/web/ui/__init__.py +18 -0
  77. pyjs/web/ui/accordion.py +166 -0
  78. pyjs/web/ui/alert.py +52 -0
  79. pyjs/web/ui/alert_dialog.py +102 -0
  80. pyjs/web/ui/aspect_ratio.py +12 -0
  81. pyjs/web/ui/attachment.py +80 -0
  82. pyjs/web/ui/avatar.py +105 -0
  83. pyjs/web/ui/badge.py +48 -0
  84. pyjs/web/ui/breadcrumb.py +85 -0
  85. pyjs/web/ui/bubble.py +38 -0
  86. pyjs/web/ui/button.py +86 -0
  87. pyjs/web/ui/calendar.py +124 -0
  88. pyjs/web/ui/card.py +58 -0
  89. pyjs/web/ui/carousel.py +99 -0
  90. pyjs/web/ui/chart.py +56 -0
  91. pyjs/web/ui/checkbox.py +31 -0
  92. pyjs/web/ui/collapsible.py +71 -0
  93. pyjs/web/ui/combobox.py +36 -0
  94. pyjs/web/ui/command.py +118 -0
  95. pyjs/web/ui/context_menu.py +65 -0
  96. pyjs/web/ui/date_picker.py +24 -0
  97. pyjs/web/ui/dialog.py +289 -0
  98. pyjs/web/ui/direction.py +9 -0
  99. pyjs/web/ui/drawer.py +72 -0
  100. pyjs/web/ui/dropdown_menu.py +239 -0
  101. pyjs/web/ui/empty.py +69 -0
  102. pyjs/web/ui/field.py +96 -0
  103. pyjs/web/ui/floating.py +90 -0
  104. pyjs/web/ui/hover_card.py +128 -0
  105. pyjs/web/ui/input.py +48 -0
  106. pyjs/web/ui/input_group.py +77 -0
  107. pyjs/web/ui/input_otp.py +76 -0
  108. pyjs/web/ui/item.py +78 -0
  109. pyjs/web/ui/kbd.py +26 -0
  110. pyjs/web/ui/label.py +14 -0
  111. pyjs/web/ui/marker.py +29 -0
  112. pyjs/web/ui/menubar.py +52 -0
  113. pyjs/web/ui/message.py +57 -0
  114. pyjs/web/ui/message_scroller.py +45 -0
  115. pyjs/web/ui/native_select.py +47 -0
  116. pyjs/web/ui/navigation_menu.py +110 -0
  117. pyjs/web/ui/pagination.py +63 -0
  118. pyjs/web/ui/popover.py +217 -0
  119. pyjs/web/ui/progress.py +44 -0
  120. pyjs/web/ui/radio_group.py +129 -0
  121. pyjs/web/ui/resizable.py +194 -0
  122. pyjs/web/ui/scroll_area.py +29 -0
  123. pyjs/web/ui/select.py +83 -0
  124. pyjs/web/ui/separator.py +24 -0
  125. pyjs/web/ui/sheet.py +77 -0
  126. pyjs/web/ui/sidebar.py +162 -0
  127. pyjs/web/ui/skeleton.py +15 -0
  128. pyjs/web/ui/slider.py +46 -0
  129. pyjs/web/ui/sonner.py +70 -0
  130. pyjs/web/ui/spinner.py +14 -0
  131. pyjs/web/ui/switch.py +35 -0
  132. pyjs/web/ui/table.py +84 -0
  133. pyjs/web/ui/tabs.py +167 -0
  134. pyjs/web/ui/text.py +15 -0
  135. pyjs/web/ui/textarea.py +28 -0
  136. pyjs/web/ui/toggle.py +109 -0
  137. pyjs/web/ui/tooltip.py +164 -0
  138. pyjs/web/ui/typography.py +79 -0
  139. pyjs/web/url.py +76 -0
  140. pyjs/web/webgpu.py +496 -0
  141. pyjs-0.0.1.dist-info/METADATA +441 -0
  142. pyjs-0.0.1.dist-info/RECORD +146 -0
  143. pyjs-0.0.1.dist-info/WHEEL +5 -0
  144. pyjs-0.0.1.dist-info/entry_points.txt +5 -0
  145. pyjs-0.0.1.dist-info/licenses/LICENSE +28 -0
  146. pyjs-0.0.1.dist-info/top_level.txt +1 -0
pyjs/docs/ui.py ADDED
@@ -0,0 +1,349 @@
1
+ from pyjs import js
2
+ from pyjs.web.dom import document, localStorage, navigator, window
3
+ from pyjs.web.domx import CustomElement, button, dialog, div, input, ref, tag
4
+ from pyjs.web.events import Event, EventTarget, KeyboardEvent
5
+ from pyjs.web.html import HTMLElement
6
+ from pyjs.web.javascript import JSON
7
+
8
+
9
+ @js
10
+ class DocsEventListener:
11
+ def __init__(self, callback: callable):
12
+ self.callback = callback
13
+
14
+ @js(include=True)
15
+ def handleEvent(self, event: Event):
16
+ self.callback(event)
17
+
18
+
19
+ @js
20
+ class CodeCopyListener:
21
+ def __init__(self, button_element: HTMLElement, code_element: HTMLElement):
22
+ self.button = button_element
23
+ self.code = code_element
24
+
25
+ @js(include=True)
26
+ async def handleEvent(self, event: Event):
27
+ text = self.code.textContent
28
+ if text is None:
29
+ return
30
+ await navigator.clipboard.writeText(text)
31
+ self.button.textContent = "Copied"
32
+
33
+
34
+ @js
35
+ def bind(element: EventTarget, event_name: str, callback: callable) -> DocsEventListener:
36
+ listener = DocsEventListener(callback)
37
+ element.addEventListener(event_name, listener)
38
+ return listener
39
+
40
+
41
+ @js
42
+ def search_icon():
43
+ return tag(
44
+ "svg",
45
+ {
46
+ "aria-hidden": "true",
47
+ "class": "search-icon",
48
+ "viewBox": "0 0 24 24",
49
+ },
50
+ tag("circle", {"cx": "11", "cy": "11", "r": "7"}),
51
+ tag("path", {"d": "m20 20-3.8-3.8"}),
52
+ )
53
+
54
+
55
+ @js
56
+ class DocsApp(CustomElement):
57
+ def __init__(
58
+ self,
59
+ site_name: str = "",
60
+ home_href: str = "./",
61
+ navigation="",
62
+ article="",
63
+ outline="",
64
+ search_data="[]",
65
+ site_home_href: str = "",
66
+ site_navigation="",
67
+ ):
68
+ super().__init__()
69
+ if not site_home_href:
70
+ site_home_href = home_href
71
+ self.menu_button = ref(
72
+ button(
73
+ {
74
+ "aria-controls": "docs-navigation",
75
+ "aria-expanded": "false",
76
+ "aria-label": "Open navigation",
77
+ "class": "icon-button mobile-menu-button",
78
+ "type": "button",
79
+ },
80
+ "Menu",
81
+ )
82
+ )
83
+ self.search_button = ref(
84
+ button(
85
+ {
86
+ "aria-label": "Search documentation",
87
+ "class": "search-button",
88
+ "type": "button",
89
+ },
90
+ search_icon(),
91
+ tag("span", {"class": "search-label"}, "Search docs"),
92
+ tag("kbd", "⌘ K"),
93
+ )
94
+ )
95
+ self.theme_button = ref(
96
+ button(
97
+ {
98
+ "aria-label": "Switch color theme",
99
+ "class": "icon-button theme-button",
100
+ "type": "button",
101
+ },
102
+ "Theme",
103
+ )
104
+ )
105
+ self.search_input = ref(
106
+ input(
107
+ {
108
+ "aria-label": "Search documentation",
109
+ "autocomplete": "off",
110
+ "class": "search-input",
111
+ "placeholder": "Search the documentation…",
112
+ "type": "search",
113
+ }
114
+ )
115
+ )
116
+ self.search_results = ref(
117
+ div(
118
+ {"aria-live": "polite", "class": "search-results"},
119
+ div({"class": "search-empty"}, "Start typing to search every page."),
120
+ )
121
+ )
122
+ self.search_dialog = ref(
123
+ dialog(
124
+ {"aria-label": "Search documentation", "class": "search-dialog"},
125
+ div(
126
+ {"class": "search-panel"},
127
+ div(
128
+ {"class": "search-field"},
129
+ search_icon(),
130
+ self.search_input,
131
+ button(
132
+ {
133
+ "aria-label": "Close search",
134
+ "class": "search-close",
135
+ "type": "button",
136
+ },
137
+ "Esc",
138
+ ),
139
+ ),
140
+ self.search_results,
141
+ ),
142
+ )
143
+ )
144
+ self.search_data = ref(
145
+ tag(
146
+ "script",
147
+ {"class": "docs-search-data", "type": "application/json"},
148
+ search_data,
149
+ )
150
+ )
151
+ tag(
152
+ self,
153
+ tag(
154
+ "a",
155
+ {"class": "skip-link", "href": "#main-content"},
156
+ "Skip to content",
157
+ ),
158
+ tag(
159
+ "header",
160
+ {"class": "site-header"},
161
+ div(
162
+ {"class": "header-inner"},
163
+ self.menu_button,
164
+ tag(
165
+ "a",
166
+ {"class": "brand", "href": site_home_href},
167
+ tag("span", {"class": "brand-mark", "aria-hidden": "true"}, "Py"),
168
+ tag("span", site_name),
169
+ ),
170
+ tag("a", {"class": "brand-section", "href": home_href}, "Docs"),
171
+ site_navigation,
172
+ div({"class": "header-spacer"}),
173
+ self.search_button,
174
+ tag(
175
+ "a",
176
+ {
177
+ "aria-label": "View PyJS on GitHub",
178
+ "class": "icon-button github-button",
179
+ "href": "https://github.com/pyjs/pyjs",
180
+ },
181
+ "GitHub",
182
+ ),
183
+ self.theme_button,
184
+ ),
185
+ ),
186
+ div(
187
+ {"class": "docs-layout"},
188
+ tag(
189
+ "aside",
190
+ {
191
+ "aria-label": "Documentation navigation",
192
+ "class": "docs-sidebar",
193
+ "id": "docs-navigation",
194
+ },
195
+ navigation,
196
+ ),
197
+ tag(
198
+ "main",
199
+ {"class": "docs-main", "id": "main-content"},
200
+ article,
201
+ ),
202
+ tag(
203
+ "aside",
204
+ {"aria-label": "On this page", "class": "docs-outline"},
205
+ outline,
206
+ ),
207
+ ),
208
+ self.search_dialog,
209
+ self.search_data,
210
+ )
211
+
212
+ def initialize(self):
213
+ bind(self.menu_button, "click", self.toggle_menu)
214
+ bind(self.search_button, "click", self.open_search)
215
+ bind(self.theme_button, "click", self.toggle_theme)
216
+ bind(self.search_input, "input", self.update_search)
217
+ bind(self.search_dialog.querySelector(".search-close"), "click", self.close_search)
218
+ bind(self.search_dialog, "click", self.handle_dialog_click)
219
+ bind(window, "keydown", self.handle_keyboard)
220
+ self.apply_theme(localStorage.getItem("pyjs-docs-theme"))
221
+ self.add_code_copy_buttons()
222
+
223
+ def apply_theme(self, theme: str | None):
224
+ root = document.documentElement
225
+ if root is None:
226
+ return
227
+ if theme == "light" or theme == "dark":
228
+ root.setAttribute("data-theme", theme)
229
+ else:
230
+ root.removeAttribute("data-theme")
231
+ dark = theme == "dark"
232
+ if theme is None:
233
+ dark = window.matchMedia("(prefers-color-scheme: dark)").matches
234
+ self.theme_button.textContent = "Light" if dark else "Dark"
235
+ self.theme_button.setAttribute(
236
+ "aria-label", "Use light theme" if dark else "Use dark theme"
237
+ )
238
+
239
+ def toggle_theme(self, event: Event | None = None):
240
+ root = document.documentElement
241
+ if root is None:
242
+ return
243
+ current = root.getAttribute("data-theme")
244
+ if current is None:
245
+ current = (
246
+ "dark" if window.matchMedia("(prefers-color-scheme: dark)").matches else "light"
247
+ )
248
+ theme = "light" if current == "dark" else "dark"
249
+ localStorage.setItem("pyjs-docs-theme", theme)
250
+ self.apply_theme(theme)
251
+
252
+ def toggle_menu(self, event: Event | None = None):
253
+ expanded = self.menu_button.getAttribute("aria-expanded") == "true"
254
+ self.menu_button.setAttribute("aria-expanded", "false" if expanded else "true")
255
+ if expanded:
256
+ self.removeAttribute("data-menu-open")
257
+ else:
258
+ self.setAttribute("data-menu-open", "")
259
+
260
+ def open_search(self, event: Event | None = None):
261
+ if not self.search_dialog.open:
262
+ self.search_dialog.showModal()
263
+ self.search_input.focus()
264
+
265
+ def close_search(self, event: Event | None = None):
266
+ if self.search_dialog.open:
267
+ self.search_dialog.close()
268
+
269
+ def handle_keyboard(self, event: KeyboardEvent):
270
+ if (event.metaKey or event.ctrlKey) and event.key.lower() == "k":
271
+ event.preventDefault()
272
+ self.open_search()
273
+ elif event.key == "Escape":
274
+ self.close_search()
275
+
276
+ def handle_dialog_click(self, event: Event):
277
+ if event.target is self.search_dialog:
278
+ self.close_search()
279
+
280
+ def update_search(self, event: Event | None = None):
281
+ query = self.search_input.value.strip().lower()
282
+ self.search_results.replaceChildren()
283
+ if not query:
284
+ self.search_results.append(
285
+ div({"class": "search-empty"}, "Start typing to search every page.")
286
+ )
287
+ return
288
+
289
+ search_data = self.search_data.textContent
290
+ if search_data is None:
291
+ return
292
+ records: list[dict[str, str]] = JSON.parse(search_data)
293
+ matches: list[dict[str, str]] = []
294
+ for record in records:
295
+ searchable = (
296
+ record["title"].lower()
297
+ + " "
298
+ + record["section"].lower()
299
+ + " "
300
+ + record["text"].lower()
301
+ )
302
+ if query in searchable:
303
+ matches.append(record)
304
+ if len(matches) == 12:
305
+ break
306
+ if not matches:
307
+ self.search_results.append(div({"class": "search-empty"}, f"No results for “{query}”."))
308
+ return
309
+ for record in matches:
310
+ self.search_results.append(
311
+ tag(
312
+ "a",
313
+ {"class": "search-result", "href": record["url"]},
314
+ tag("span", {"class": "search-result-title"}, record["title"]),
315
+ tag("span", {"class": "search-result-section"}, record["section"]),
316
+ tag("span", {"class": "search-result-text"}, record["text"]),
317
+ )
318
+ )
319
+
320
+ def add_code_copy_buttons(self):
321
+ for block in self.querySelectorAll(".highlight"):
322
+ code = block.querySelector("code")
323
+ if code is not None:
324
+ copy_button = button({"class": "copy-button", "type": "button"}, "Copy")
325
+ copy_button.addEventListener("click", CodeCopyListener(copy_button, code))
326
+ block.append(copy_button)
327
+
328
+
329
+ @js
330
+ def main(
331
+ site_name: str = "PyJS",
332
+ home_href: str = "./",
333
+ navigation="",
334
+ article="",
335
+ outline="",
336
+ search_data="[]",
337
+ site_home_href: str = "",
338
+ site_navigation="",
339
+ ):
340
+ return DocsApp(
341
+ site_name,
342
+ home_href,
343
+ navigation,
344
+ article,
345
+ outline,
346
+ search_data,
347
+ site_home_href,
348
+ site_navigation,
349
+ )
@@ -0,0 +1,77 @@
1
+ from pyjs import js, js_object
2
+
3
+
4
+ @js(builtin=True)
5
+ class EventData:
6
+ def __init__(self):
7
+ self.eventName = ""
8
+ self.object = View()
9
+
10
+
11
+ @js(builtin=True)
12
+ class View:
13
+ def __init__(self):
14
+ self.id = ""
15
+ self.testID = ""
16
+ self.className = ""
17
+ self.backgroundColor = ""
18
+ self.color = ""
19
+ self.height: int | str = "auto"
20
+ self.width: int | str = "auto"
21
+ self.horizontalAlignment = "stretch"
22
+ self.verticalAlignment = "stretch"
23
+ self.margin: int | str = 0
24
+ self.padding: int | str = 0
25
+
26
+ def on(self, event_name: str, callback: callable): ...
27
+
28
+
29
+ @js(builtin=True)
30
+ class StackLayout(View):
31
+ def __init__(self):
32
+ super().__init__()
33
+ self.orientation = "vertical"
34
+ self.children: list[View] = []
35
+
36
+ def addChild(self, child: View):
37
+ self.children.append(child)
38
+
39
+
40
+ @js(builtin=True)
41
+ class Page(View):
42
+ def __init__(self):
43
+ super().__init__()
44
+ self.actionBarHidden = False
45
+ self.content = View()
46
+
47
+
48
+ @js(builtin=True)
49
+ class Label(View):
50
+ def __init__(self):
51
+ super().__init__()
52
+ self.text = ""
53
+ self.fontSize = 14
54
+ self.fontWeight = "normal"
55
+ self.textAlignment = "left"
56
+
57
+
58
+ @js(builtin=True)
59
+ class Button(View):
60
+ tapEvent = "tap"
61
+
62
+ def __init__(self):
63
+ super().__init__()
64
+ self.text = ""
65
+ self.fontSize = 14
66
+
67
+
68
+ @js(builtin=True)
69
+ class _Application:
70
+ @js(inline="{self}.run({{ create: {create} }})")
71
+ def run(self, create: callable) -> None: ...
72
+
73
+
74
+ Application = _Application()
75
+ js_object(Application, builtin=True)
76
+
77
+ __all__ = ["Application", "Button", "EventData", "Label", "Page", "StackLayout", "View"]