@pyscript/core 0.6.55 → 0.6.56

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 (77) hide show
  1. package/dist/codemirror-DtxT3fWl.js +2 -0
  2. package/dist/codemirror-DtxT3fWl.js.map +1 -0
  3. package/dist/codemirror_commands-DEH2ednO.js +2 -0
  4. package/dist/{codemirror_commands-BOf4K2ts.js.map → codemirror_commands-DEH2ednO.js.map} +1 -1
  5. package/dist/codemirror_lang-python-BmOE5ND1.js +2 -0
  6. package/dist/{codemirror_lang-python-DCbIUspM.js.map → codemirror_lang-python-BmOE5ND1.js.map} +1 -1
  7. package/dist/codemirror_language-Bq5O0hUR.js +2 -0
  8. package/dist/{codemirror_language-g0vQwyLF.js.map → codemirror_language-Bq5O0hUR.js.map} +1 -1
  9. package/dist/codemirror_state-BIAL8JKm.js +2 -0
  10. package/dist/{codemirror_state-1UkzIAPK.js.map → codemirror_state-BIAL8JKm.js.map} +1 -1
  11. package/dist/codemirror_view-DNx7dL5k.js +2 -0
  12. package/dist/codemirror_view-DNx7dL5k.js.map +1 -0
  13. package/dist/core-BDCblYQn.js +4 -0
  14. package/dist/core-BDCblYQn.js.map +1 -0
  15. package/dist/core.js +1 -1
  16. package/dist/{deprecations-manager-Rw32oYx-.js → deprecations-manager-CNW_JX9q.js} +2 -2
  17. package/dist/{deprecations-manager-Rw32oYx-.js.map → deprecations-manager-CNW_JX9q.js.map} +1 -1
  18. package/dist/{donkey-GLRef4JN.js → donkey-Cr9g1DDX.js} +2 -2
  19. package/dist/{donkey-GLRef4JN.js.map → donkey-Cr9g1DDX.js.map} +1 -1
  20. package/dist/error-B6G-5Pif.js +2 -0
  21. package/dist/{error-BSxhsz-z.js.map → error-B6G-5Pif.js.map} +1 -1
  22. package/dist/index-BtkFDJPe.js +2 -0
  23. package/dist/{index-Dhv1RkW_.js.map → index-BtkFDJPe.js.map} +1 -1
  24. package/dist/mpy-Dugbcp74.js +2 -0
  25. package/dist/{mpy-DS908FIP.js.map → mpy-Dugbcp74.js.map} +1 -1
  26. package/dist/py-FOsA_TSL.js +2 -0
  27. package/dist/{py-C1zn1oIN.js.map → py-FOsA_TSL.js.map} +1 -1
  28. package/dist/py-editor-HhWs46KO.js +2 -0
  29. package/dist/{py-editor-BeLSW3t2.js.map → py-editor-HhWs46KO.js.map} +1 -1
  30. package/dist/py-game-CQq-8UP0.js +2 -0
  31. package/dist/{py-game-c17lRx9G.js.map → py-game-CQq-8UP0.js.map} +1 -1
  32. package/dist/py-terminal-ApYpC8rm.js +2 -0
  33. package/dist/{py-terminal-CJcYGK_0.js.map → py-terminal-ApYpC8rm.js.map} +1 -1
  34. package/dist/service-worker.js +1 -1
  35. package/dist/storage.js +1 -1
  36. package/dist/storage.js.map +1 -1
  37. package/dist/toml-BK2RWy-G.js +3 -0
  38. package/dist/{toml-DiUM0_qs.js.map → toml-BK2RWy-G.js.map} +1 -1
  39. package/dist/toml-Blg7Izee.js +3 -0
  40. package/dist/toml-Blg7Izee.js.map +1 -0
  41. package/dist/xterm-DrSYbXEP.js +2 -0
  42. package/dist/{xterm-CVv2fC4I.js.map → xterm-DrSYbXEP.js.map} +1 -1
  43. package/dist/xterm-readline-CYfUpnbV.js +2 -0
  44. package/dist/xterm-readline-CYfUpnbV.js.map +1 -0
  45. package/dist/xterm_addon-fit--gyF3PcZ.js.map +1 -1
  46. package/dist/xterm_addon-web-links-D95xh2la.js +2 -0
  47. package/dist/{xterm_addon-web-links-Cnej-nJ6.js.map → xterm_addon-web-links-D95xh2la.js.map} +1 -1
  48. package/dist/zip-BKVoQflw.js +2 -0
  49. package/dist/{zip-D13-hp9W.js.map → zip-BKVoQflw.js.map} +1 -1
  50. package/package.json +10 -10
  51. package/src/stdlib/pyscript/web.py +10 -0
  52. package/src/stdlib/pyscript.js +1 -1
  53. package/dist/codemirror-8Ev_qLCE.js +0 -2
  54. package/dist/codemirror-8Ev_qLCE.js.map +0 -1
  55. package/dist/codemirror_commands-BOf4K2ts.js +0 -2
  56. package/dist/codemirror_lang-python-DCbIUspM.js +0 -2
  57. package/dist/codemirror_language-g0vQwyLF.js +0 -2
  58. package/dist/codemirror_state-1UkzIAPK.js +0 -2
  59. package/dist/codemirror_view-Gaaf0HCU.js +0 -2
  60. package/dist/codemirror_view-Gaaf0HCU.js.map +0 -1
  61. package/dist/core-CJABae_n.js +0 -4
  62. package/dist/core-CJABae_n.js.map +0 -1
  63. package/dist/error-BSxhsz-z.js +0 -2
  64. package/dist/index-Dhv1RkW_.js +0 -2
  65. package/dist/mpy-DS908FIP.js +0 -2
  66. package/dist/py-C1zn1oIN.js +0 -2
  67. package/dist/py-editor-BeLSW3t2.js +0 -2
  68. package/dist/py-game-c17lRx9G.js +0 -2
  69. package/dist/py-terminal-CJcYGK_0.js +0 -2
  70. package/dist/toml-BLBSZ43A.js +0 -3
  71. package/dist/toml-BLBSZ43A.js.map +0 -1
  72. package/dist/toml-DiUM0_qs.js +0 -3
  73. package/dist/xterm-CVv2fC4I.js +0 -2
  74. package/dist/xterm-readline-e8QPhSrm.js +0 -2
  75. package/dist/xterm-readline-e8QPhSrm.js.map +0 -1
  76. package/dist/xterm_addon-web-links-Cnej-nJ6.js +0 -2
  77. package/dist/zip-D13-hp9W.js +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyscript/core",
3
- "version": "0.6.55",
3
+ "version": "0.6.56",
4
4
  "type": "module",
5
5
  "description": "PyScript",
6
6
  "module": "./index.js",
@@ -67,10 +67,10 @@
67
67
  "dependencies": {
68
68
  "@ungap/with-resolvers": "^0.1.0",
69
69
  "@webreflection/idb-map": "^0.3.2",
70
- "@webreflection/utils": "^0.1.0",
70
+ "@webreflection/utils": "^0.1.1",
71
71
  "add-promise-listener": "^0.1.3",
72
72
  "basic-devtools": "^0.1.6",
73
- "polyscript": "^0.17.23",
73
+ "polyscript": "^0.17.25",
74
74
  "sticky-module": "^0.1.1",
75
75
  "to-json-callback": "^0.1.1",
76
76
  "type-checked-collections": "^0.1.7"
@@ -80,22 +80,22 @@
80
80
  "@codemirror/lang-python": "^6.2.1",
81
81
  "@codemirror/language": "^6.11.1",
82
82
  "@codemirror/state": "^6.5.2",
83
- "@codemirror/view": "^6.37.1",
84
- "@playwright/test": "^1.53.0",
85
- "@rollup/plugin-commonjs": "^28.0.3",
83
+ "@codemirror/view": "^6.37.2",
84
+ "@playwright/test": "^1.53.1",
85
+ "@rollup/plugin-commonjs": "^28.0.6",
86
86
  "@rollup/plugin-node-resolve": "^16.0.1",
87
87
  "@rollup/plugin-terser": "^0.4.4",
88
88
  "@webreflection/toml-j0.4": "^1.1.4",
89
89
  "@xterm/addon-fit": "^0.10.0",
90
90
  "@xterm/addon-web-links": "^0.11.0",
91
91
  "@xterm/xterm": "^5.5.0",
92
- "bun": "^1.2.15",
92
+ "bun": "^1.2.16",
93
93
  "chokidar": "^4.0.3",
94
94
  "codedent": "^0.1.2",
95
- "codemirror": "^6.0.1",
96
- "eslint": "^9.28.0",
95
+ "codemirror": "^6.0.2",
96
+ "eslint": "^9.29.0",
97
97
  "flatted": "^3.3.3",
98
- "rollup": "^4.43.0",
98
+ "rollup": "^4.44.0",
99
99
  "rollup-plugin-postcss": "^4.0.2",
100
100
  "rollup-plugin-string": "^3.0.0",
101
101
  "static-handler": "^0.5.3",
@@ -124,6 +124,11 @@ class Element:
124
124
  # Element instance via `for_`).
125
125
  if name.endswith("_"):
126
126
  name = name[:-1] # noqa: FURB188 No str.removesuffix() in MicroPython.
127
+ if name == "for":
128
+ # The `for` attribute is a special case as it is a keyword in both
129
+ # Python and JavaScript.
130
+ # We need to get it from the underlying DOM element as `htmlFor`.
131
+ name = "htmlFor"
127
132
  return getattr(self._dom_element, name)
128
133
 
129
134
  def __setattr__(self, name, value):
@@ -142,6 +147,11 @@ class Element:
142
147
  # Element instance via `for_`).
143
148
  if name.endswith("_"):
144
149
  name = name[:-1] # noqa: FURB188 No str.removesuffix() in MicroPython.
150
+ if name == "for":
151
+ # The `for` attribute is a special case as it is a keyword in both
152
+ # Python and JavaScript.
153
+ # We need to set it on the underlying DOM element as `htmlFor`.
154
+ name = "htmlFor"
145
155
 
146
156
  if name.startswith("on_"):
147
157
  # Ensure on-events are cached in the _on_events dict if the
@@ -12,7 +12,7 @@ export default {
12
12
  "media.py": "from pyscript import window\nfrom pyscript.ffi import to_js\nclass Device:\n\tdef __init__(A,device):A._dom_element=device\n\t@property\n\tdef id(self):return self._dom_element.deviceId\n\t@property\n\tdef group(self):return self._dom_element.groupId\n\t@property\n\tdef kind(self):return self._dom_element.kind\n\t@property\n\tdef label(self):return self._dom_element.label\n\tdef __getitem__(A,key):return getattr(A,key)\n\t@classmethod\n\tasync def load(E,audio=False,video=True):\n\t\tC='video';B=video;A={};A['audio']=audio\n\t\tif isinstance(B,bool):A[C]=B\n\t\telse:\n\t\t\tA[C]={}\n\t\t\tfor D in B:A[C][D]=B[D]\n\t\treturn await window.navigator.mediaDevices.getUserMedia(to_js(A))\n\tasync def get_stream(A):B=A.kind.replace('input','').replace('output','');C={B:{'deviceId':{'exact':A.id}}};return await A.load(**C)\nasync def list_devices():return[Device(A)for A in await window.navigator.mediaDevices.enumerateDevices()]",
13
13
  "storage.py": "_C='memoryview'\n_B='bytearray'\n_A='generic'\nfrom polyscript import storage as _storage\nfrom pyscript.flatted import parse as _parse\nfrom pyscript.flatted import stringify as _stringify\ndef _to_idb(value):\n\tA=value\n\tif A is None:return _stringify(['null',0])\n\tif isinstance(A,(bool,float,int,str,list,dict,tuple)):return _stringify([_A,A])\n\tif isinstance(A,bytearray):return _stringify([_B,list(A)])\n\tif isinstance(A,memoryview):return _stringify([_C,list(A)])\n\tB=f\"Unexpected value: {A}\";raise TypeError(B)\ndef _from_idb(value):\n\tC=value;A,B=_parse(C)\n\tif A=='null':return\n\tif A==_A:return B\n\tif A==_B:return bytearray(B)\n\tif A==_C:return memoryview(bytearray(B))\n\treturn C\nclass Storage(dict):\n\tdef __init__(B,store):A=store;super().__init__({A:_from_idb(B)for(A,B)in A.entries()});B.__store__=A\n\tdef __delitem__(A,attr):A.__store__.delete(attr);super().__delitem__(attr)\n\tdef __setitem__(B,attr,value):A=value;B.__store__.set(attr,_to_idb(A));super().__setitem__(attr,A)\n\tdef clear(A):A.__store__.clear();super().clear()\n\tasync def sync(A):await A.__store__.sync()\nasync def storage(name='',storage_class=Storage):\n\tif not name:A='The storage name must be defined';raise ValueError(A)\n\treturn storage_class(await _storage(f\"@pyscript/{name}\"))",
14
14
  "util.py": "import js,sys,inspect\ndef as_bytearray(buffer):\n\tA=js.Uint8Array.new(buffer);B=A.length;C=bytearray(B)\n\tfor D in range(B):C[D]=A[D]\n\treturn C\nclass NotSupported:\n\tdef __init__(A,name,error):object.__setattr__(A,'name',name);object.__setattr__(A,'error',error)\n\tdef __repr__(A):return f\"<NotSupported {A.name} [{A.error}]>\"\n\tdef __getattr__(A,attr):raise AttributeError(A.error)\n\tdef __setattr__(A,attr,value):raise AttributeError(A.error)\n\tdef __call__(A,*B):raise TypeError(A.error)\ndef is_awaitable(obj):\n\tA=obj;from pyscript import config as B\n\tif B['type']=='mpy':\n\t\tif'<closure <generator>'in repr(A):return True\n\t\treturn inspect.isgeneratorfunction(A)\n\treturn inspect.iscoroutinefunction(A)",
15
- "web.py": "_B='on_'\n_A=None\nfrom pyscript import document,when,Event\nfrom pyscript.ffi import create_proxy\ndef wrap_dom_element(dom_element):return Element.wrap_dom_element(dom_element)\nclass Element:\n\telement_classes_by_tag_name={}\n\t@classmethod\n\tdef get_tag_name(A):return A.__name__.replace('_','')\n\t@classmethod\n\tdef register_element_classes(B,element_classes):\n\t\tfor A in element_classes:C=A.get_tag_name();B.element_classes_by_tag_name[C]=A\n\t@classmethod\n\tdef unregister_element_classes(A,element_classes):\n\t\tfor B in element_classes:C=B.get_tag_name();A.element_classes_by_tag_name.pop(C,_A)\n\t@classmethod\n\tdef wrap_dom_element(A,dom_element):B=dom_element;C=A.element_classes_by_tag_name.get(B.tagName.lower(),A);return C(dom_element=B)\n\tdef __init__(A,dom_element=_A,classes=_A,style=_A,**E):\n\t\tA._dom_element=dom_element or document.createElement(type(A).get_tag_name());A._on_events={};C={}\n\t\tfor(B,D)in E.items():\n\t\t\tif B.startswith(_B):F=A.get_event(B);F.add_listener(D)\n\t\t\telse:C[B]=D\n\t\tA._classes=Classes(A);A._style=Style(A);A.update(classes=classes,style=style,**C)\n\tdef __eq__(A,obj):return isinstance(obj,Element)and obj._dom_element==A._dom_element\n\tdef __getitem__(B,key):\n\t\tA=key\n\t\tif isinstance(A,(int,slice)):return B.children[A]\n\t\treturn B.find(A)\n\tdef __getattr__(B,name):\n\t\tA=name\n\t\tif A.startswith(_B):return B.get_event(A)\n\t\tif A.endswith('_'):A=A[:-1]\n\t\treturn getattr(B._dom_element,A)\n\tdef __setattr__(C,name,value):\n\t\tB=value;A=name\n\t\tif A.startswith('_'):super().__setattr__(A,B)\n\t\telse:\n\t\t\tif A.endswith('_'):A=A[:-1]\n\t\t\tif A.startswith(_B):C._on_events[A]=B\n\t\t\tsetattr(C._dom_element,A,B)\n\tdef get_event(A,name):\n\t\tB=name\n\t\tif not B.startswith(_B):C=\"Event names must start with 'on_'.\";raise ValueError(C)\n\t\tD=B[3:]\n\t\tif not hasattr(A._dom_element,D):C=f\"Element has no '{D}' event.\";raise ValueError(C)\n\t\tif B in A._on_events:return A._on_events[B]\n\t\tE=Event();A._on_events[B]=E;A._dom_element.addEventListener(D,create_proxy(E.trigger));return E\n\t@property\n\tdef children(self):return ElementCollection.wrap_dom_elements(self._dom_element.children)\n\t@property\n\tdef classes(self):return self._classes\n\t@property\n\tdef parent(self):\n\t\tif self._dom_element.parentElement is _A:return\n\t\treturn Element.wrap_dom_element(self._dom_element.parentElement)\n\t@property\n\tdef style(self):return self._style\n\tdef append(B,*C):\n\t\tfor A in C:\n\t\t\tif isinstance(A,Element):B._dom_element.appendChild(A._dom_element)\n\t\t\telif isinstance(A,ElementCollection):\n\t\t\t\tfor D in A:B._dom_element.appendChild(D._dom_element)\n\t\t\telif isinstance(A,(list,tuple)):\n\t\t\t\tfor E in A:B.append(E)\n\t\t\telse:\n\t\t\t\ttry:A.tagName;B._dom_element.appendChild(A)\n\t\t\t\texcept AttributeError:\n\t\t\t\t\ttry:\n\t\t\t\t\t\tA.length\n\t\t\t\t\t\tfor F in A:B._dom_element.appendChild(F)\n\t\t\t\t\texcept AttributeError:G=f'Element \"{A}\" is a proxy object, \"but not a valid element or a NodeList.';raise TypeError(G)\n\tdef clone(B,clone_id=_A):A=Element.wrap_dom_element(B._dom_element.cloneNode(True));A.id=clone_id;return A\n\tdef find(A,selector):return ElementCollection.wrap_dom_elements(A._dom_element.querySelectorAll(selector))\n\tdef show_me(A):A._dom_element.scrollIntoView()\n\tdef update(A,classes=_A,style=_A,**D):\n\t\tC=style;B=classes\n\t\tif B:A.classes.add(B)\n\t\tif C:A.style.set(**C)\n\t\tfor(E,F)in D.items():setattr(A,E,F)\nclass Classes:\n\tdef __init__(A,element):A._element=element;A._class_list=A._element._dom_element.classList\n\tdef __contains__(A,item):return item in A._class_list\n\tdef __eq__(C,other):\n\t\tA=other\n\t\tif isinstance(A,Classes):B=list(A._class_list)\n\t\telse:\n\t\t\ttry:B=iter(A)\n\t\t\texcept TypeError:return False\n\t\treturn set(C._class_list)==set(B)\n\tdef __iter__(A):return iter(A._class_list)\n\tdef __len__(A):return A._class_list.length\n\tdef __repr__(A):return f\"Classes({\", \".join(A._class_list)})\"\n\tdef __str__(A):return' '.join(A._class_list)\n\tdef add(B,*C):\n\t\tfor A in C:\n\t\t\tif isinstance(A,list):\n\t\t\t\tfor D in A:B.add(D)\n\t\t\telse:B._class_list.add(A)\n\tdef contains(A,class_name):return class_name in A\n\tdef remove(B,*C):\n\t\tfor A in C:\n\t\t\tif isinstance(A,list):\n\t\t\t\tfor D in A:B.remove(D)\n\t\t\telse:B._class_list.remove(A)\n\tdef replace(A,old_class,new_class):A.remove(old_class);A.add(new_class)\n\tdef toggle(A,*C):\n\t\tfor B in C:\n\t\t\tif B in A:A.remove(B)\n\t\t\telse:A.add(B)\nclass HasOptions:\n\t@property\n\tdef options(self):\n\t\tA=self\n\t\tif not hasattr(A,'_options'):A._options=Options(A)\n\t\treturn A._options\nclass Options:\n\tdef __init__(A,element):A._element=element\n\tdef __getitem__(A,key):return A.options[key]\n\tdef __iter__(A):yield from A.options\n\tdef __len__(A):return len(A.options)\n\tdef __repr__(A):return f\"{A.__class__.__name__} (length: {len(A)}) {A.options}\"\n\t@property\n\tdef options(self):return[Element.wrap_dom_element(A)for A in self._element._dom_element.options]\n\t@property\n\tdef selected(self):return self.options[self._element._dom_element.selectedIndex]\n\tdef add(D,value=_A,html=_A,text=_A,before=_A,**B):\n\t\tC=value;A=before\n\t\tif C is not _A:B['value']=C\n\t\tif html is not _A:B['innerHTML']=html\n\t\tif text is not _A:B['text']=text\n\t\tE=option(**B)\n\t\tif A and isinstance(A,Element):A=A._dom_element\n\t\tD._element._dom_element.add(E._dom_element,A)\n\tdef clear(A):\n\t\twhile len(A)>0:A.remove(0)\n\tdef remove(A,index):A._element._dom_element.remove(index)\nclass Style:\n\tdef __init__(A,element):A._element=element;A._style=A._element._dom_element.style\n\tdef __getitem__(A,key):return A._style.getPropertyValue(key)\n\tdef __setitem__(A,key,value):A._style.setProperty(key,value)\n\tdef remove(A,key):A._style.removeProperty(key)\n\tdef set(A,**B):\n\t\tfor(C,D)in B.items():A._element._dom_element.style.setProperty(C,D)\n\t@property\n\tdef visible(self):return self._element._dom_element.style.visibility\n\t@visible.setter\n\tdef visible(self,value):self._element._dom_element.style.visibility=value\nclass ContainerElement(Element):\n\tdef __init__(B,*C,children=_A,dom_element=_A,style=_A,classes=_A,**D):\n\t\tsuper().__init__(dom_element=dom_element,style=style,classes=classes,**D)\n\t\tfor A in list(C)+(children or[]):\n\t\t\tif isinstance(A,(Element,ElementCollection)):B.append(A)\n\t\t\telse:B._dom_element.insertAdjacentHTML('beforeend',A)\n\tdef __iter__(A):yield from A.children\nclass ClassesCollection:\n\tdef __init__(A,collection):A._collection=collection\n\tdef __contains__(A,class_name):\n\t\tfor B in A._collection:\n\t\t\tif class_name in B.classes:return True\n\t\treturn False\n\tdef __eq__(B,other):A=other;return isinstance(A,ClassesCollection)and B._collection==A._collection\n\tdef __iter__(A):yield from A._all_class_names()\n\tdef __len__(A):return len(A._all_class_names())\n\tdef __repr__(A):return f\"ClassesCollection({A._collection!r})\"\n\tdef __str__(A):return' '.join(A._all_class_names())\n\tdef add(A,*B):\n\t\tfor C in A._collection:C.classes.add(*B)\n\tdef contains(A,class_name):return class_name in A\n\tdef remove(A,*B):\n\t\tfor C in A._collection:C.classes.remove(*B)\n\tdef replace(A,old_class,new_class):\n\t\tfor B in A._collection:B.classes.replace(old_class,new_class)\n\tdef toggle(A,*B):\n\t\tfor C in A._collection:C.classes.toggle(*B)\n\tdef _all_class_names(B):\n\t\tA=set()\n\t\tfor C in B._collection:\n\t\t\tfor D in C.classes:A.add(D)\n\t\treturn A\nclass StyleCollection:\n\tdef __init__(A,collection):A._collection=collection\n\tdef __getitem__(A,key):return[A.style[key]for A in A._collection._elements]\n\tdef __setitem__(A,key,value):\n\t\tfor B in A._collection._elements:B.style[key]=value\n\tdef __repr__(A):return f\"StyleCollection({A._collection!r})\"\n\tdef remove(A,key):\n\t\tfor B in A._collection._elements:B.style.remove(key)\nclass ElementCollection:\n\t@classmethod\n\tdef wrap_dom_elements(A,dom_elements):return A([Element.wrap_dom_element(A)for A in dom_elements])\n\tdef __init__(A,elements):A._elements=elements;A._classes=ClassesCollection(A);A._style=StyleCollection(A)\n\tdef __eq__(A,obj):return isinstance(obj,ElementCollection)and obj._elements==A._elements\n\tdef __getitem__(B,key):\n\t\tA=key\n\t\tif isinstance(A,int):return B._elements[A]\n\t\tif isinstance(A,slice):return ElementCollection(B._elements[A])\n\t\treturn B.find(A)\n\tdef __iter__(A):yield from A._elements\n\tdef __len__(A):return len(A._elements)\n\tdef __repr__(A):return f\"{A.__class__.__name__} (length: {len(A._elements)}) {A._elements}\"\n\tdef __getattr__(A,name):return[getattr(A,name)for A in A._elements]\n\tdef __setattr__(C,name,value):\n\t\tB=value;A=name\n\t\tif A.startswith('_'):super().__setattr__(A,B)\n\t\telse:\n\t\t\tfor D in C._elements:setattr(D,A,B)\n\t@property\n\tdef classes(self):return self._classes\n\t@property\n\tdef elements(self):return self._elements\n\t@property\n\tdef style(self):return self._style\n\tdef find(B,selector):\n\t\tA=[]\n\t\tfor C in B._elements:A.extend(C.find(selector))\n\t\treturn ElementCollection(A)\nclass a(ContainerElement):0\nclass abbr(ContainerElement):0\nclass address(ContainerElement):0\nclass area(Element):0\nclass article(ContainerElement):0\nclass aside(ContainerElement):0\nclass audio(ContainerElement):0\nclass b(ContainerElement):0\nclass base(Element):0\nclass blockquote(ContainerElement):0\nclass body(ContainerElement):0\nclass br(Element):0\nclass button(ContainerElement):0\nclass canvas(ContainerElement):\n\tdef download(A,filename='snapped.png'):B=a(download=filename,href=A._dom_element.toDataURL());A.append(B);B._dom_element.click()\n\tdef draw(E,what,width=_A,height=_A):\n\t\tC=height;B=width;A=what\n\t\tif isinstance(A,Element):A=A._dom_element\n\t\tD=E._dom_element.getContext('2d')\n\t\tif B or C:D.drawImage(A,0,0,B,C)\n\t\telse:D.drawImage(A,0,0)\nclass caption(ContainerElement):0\nclass cite(ContainerElement):0\nclass code(ContainerElement):0\nclass col(Element):0\nclass colgroup(ContainerElement):0\nclass data(ContainerElement):0\nclass datalist(ContainerElement,HasOptions):0\nclass dd(ContainerElement):0\nclass del_(ContainerElement):0\nclass details(ContainerElement):0\nclass dialog(ContainerElement):0\nclass div(ContainerElement):0\nclass dl(ContainerElement):0\nclass dt(ContainerElement):0\nclass em(ContainerElement):0\nclass embed(Element):0\nclass fieldset(ContainerElement):0\nclass figcaption(ContainerElement):0\nclass figure(ContainerElement):0\nclass footer(ContainerElement):0\nclass form(ContainerElement):0\nclass h1(ContainerElement):0\nclass h2(ContainerElement):0\nclass h3(ContainerElement):0\nclass h4(ContainerElement):0\nclass h5(ContainerElement):0\nclass h6(ContainerElement):0\nclass head(ContainerElement):0\nclass header(ContainerElement):0\nclass hgroup(ContainerElement):0\nclass hr(Element):0\nclass html(ContainerElement):0\nclass i(ContainerElement):0\nclass iframe(ContainerElement):0\nclass img(Element):0\nclass input_(Element):0\nclass ins(ContainerElement):0\nclass kbd(ContainerElement):0\nclass label(ContainerElement):0\nclass legend(ContainerElement):0\nclass li(ContainerElement):0\nclass link(Element):0\nclass main(ContainerElement):0\nclass map_(ContainerElement):0\nclass mark(ContainerElement):0\nclass menu(ContainerElement):0\nclass meta(ContainerElement):0\nclass meter(ContainerElement):0\nclass nav(ContainerElement):0\nclass object_(ContainerElement):0\nclass ol(ContainerElement):0\nclass optgroup(ContainerElement,HasOptions):0\nclass option(ContainerElement):0\nclass output(ContainerElement):0\nclass p(ContainerElement):0\nclass param(ContainerElement):0\nclass picture(ContainerElement):0\nclass pre(ContainerElement):0\nclass progress(ContainerElement):0\nclass q(ContainerElement):0\nclass s(ContainerElement):0\nclass script(ContainerElement):0\nclass section(ContainerElement):0\nclass select(ContainerElement,HasOptions):0\nclass small(ContainerElement):0\nclass source(Element):0\nclass span(ContainerElement):0\nclass strong(ContainerElement):0\nclass style(ContainerElement):0\nclass sub(ContainerElement):0\nclass summary(ContainerElement):0\nclass sup(ContainerElement):0\nclass table(ContainerElement):0\nclass tbody(ContainerElement):0\nclass td(ContainerElement):0\nclass template(ContainerElement):0\nclass textarea(ContainerElement):0\nclass tfoot(ContainerElement):0\nclass th(ContainerElement):0\nclass thead(ContainerElement):0\nclass time(ContainerElement):0\nclass title(ContainerElement):0\nclass tr(ContainerElement):0\nclass track(Element):0\nclass u(ContainerElement):0\nclass ul(ContainerElement):0\nclass var(ContainerElement):0\nclass video(ContainerElement):\n\tdef snap(E,to=_A,width=_A,height=_A):\n\t\tH='CANVAS';G='Element to snap to must be a canvas.';C=height;B=width;A=to;B=B if B is not _A else E.videoWidth;C=C if C is not _A else E.videoHeight\n\t\tif A is _A:A=canvas(width=B,height=C)\n\t\telif isinstance(A,Element):\n\t\t\tif A.tag!='canvas':D=G;raise TypeError(D)\n\t\telif getattr(A,'tagName','')==H:A=canvas(dom_element=A)\n\t\telif isinstance(A,str):\n\t\t\tF=document.querySelectorAll(A)\n\t\t\tif F.length==0:D='No element with selector {to} to snap to.';raise TypeError(D)\n\t\t\tif F[0].tagName!=H:D=G;raise TypeError(D)\n\t\t\tA=canvas(dom_element=F[0])\n\t\tA.draw(E,B,C);return A\nclass wbr(Element):0\nELEMENT_CLASSES=[a,abbr,address,area,article,aside,audio,b,base,blockquote,body,br,button,canvas,caption,cite,code,col,colgroup,data,datalist,dd,del_,details,dialog,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,img,input_,ins,kbd,label,legend,li,link,main,map_,mark,menu,meta,meter,nav,object_,ol,optgroup,option,output,p,param,picture,pre,progress,q,s,script,section,select,small,source,span,strong,style,sub,summary,sup,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,u,ul,var,video,wbr]\nElement.register_element_classes(ELEMENT_CLASSES)\nclass Page:\n\tdef __init__(A):A.html=Element.wrap_dom_element(document.documentElement);A.body=Element.wrap_dom_element(document.body);A.head=Element.wrap_dom_element(document.head)\n\tdef __getitem__(A,selector):return A.find(selector)\n\t@property\n\tdef title(self):return document.title\n\t@title.setter\n\tdef title(self,value):document.title=value\n\tdef append(A,*B):A.body.append(*B)\n\tdef find(A,selector):return ElementCollection.wrap_dom_elements(document.querySelectorAll(selector))\npage=Page()",
15
+ "web.py": "_C='htmlFor'\n_B='on_'\n_A=None\nfrom pyscript import document,when,Event\nfrom pyscript.ffi import create_proxy\ndef wrap_dom_element(dom_element):return Element.wrap_dom_element(dom_element)\nclass Element:\n\telement_classes_by_tag_name={}\n\t@classmethod\n\tdef get_tag_name(A):return A.__name__.replace('_','')\n\t@classmethod\n\tdef register_element_classes(B,element_classes):\n\t\tfor A in element_classes:C=A.get_tag_name();B.element_classes_by_tag_name[C]=A\n\t@classmethod\n\tdef unregister_element_classes(A,element_classes):\n\t\tfor B in element_classes:C=B.get_tag_name();A.element_classes_by_tag_name.pop(C,_A)\n\t@classmethod\n\tdef wrap_dom_element(A,dom_element):B=dom_element;C=A.element_classes_by_tag_name.get(B.tagName.lower(),A);return C(dom_element=B)\n\tdef __init__(A,dom_element=_A,classes=_A,style=_A,**E):\n\t\tA._dom_element=dom_element or document.createElement(type(A).get_tag_name());A._on_events={};C={}\n\t\tfor(B,D)in E.items():\n\t\t\tif B.startswith(_B):F=A.get_event(B);F.add_listener(D)\n\t\t\telse:C[B]=D\n\t\tA._classes=Classes(A);A._style=Style(A);A.update(classes=classes,style=style,**C)\n\tdef __eq__(A,obj):return isinstance(obj,Element)and obj._dom_element==A._dom_element\n\tdef __getitem__(B,key):\n\t\tA=key\n\t\tif isinstance(A,(int,slice)):return B.children[A]\n\t\treturn B.find(A)\n\tdef __getattr__(B,name):\n\t\tA=name\n\t\tif A.startswith(_B):return B.get_event(A)\n\t\tif A.endswith('_'):A=A[:-1]\n\t\tif A=='for':A=_C\n\t\treturn getattr(B._dom_element,A)\n\tdef __setattr__(C,name,value):\n\t\tB=value;A=name\n\t\tif A.startswith('_'):super().__setattr__(A,B)\n\t\telse:\n\t\t\tif A.endswith('_'):A=A[:-1]\n\t\t\tif A=='for':A=_C\n\t\t\tif A.startswith(_B):C._on_events[A]=B\n\t\t\tsetattr(C._dom_element,A,B)\n\tdef get_event(A,name):\n\t\tB=name\n\t\tif not B.startswith(_B):C=\"Event names must start with 'on_'.\";raise ValueError(C)\n\t\tD=B[3:]\n\t\tif not hasattr(A._dom_element,D):C=f\"Element has no '{D}' event.\";raise ValueError(C)\n\t\tif B in A._on_events:return A._on_events[B]\n\t\tE=Event();A._on_events[B]=E;A._dom_element.addEventListener(D,create_proxy(E.trigger));return E\n\t@property\n\tdef children(self):return ElementCollection.wrap_dom_elements(self._dom_element.children)\n\t@property\n\tdef classes(self):return self._classes\n\t@property\n\tdef parent(self):\n\t\tif self._dom_element.parentElement is _A:return\n\t\treturn Element.wrap_dom_element(self._dom_element.parentElement)\n\t@property\n\tdef style(self):return self._style\n\tdef append(B,*C):\n\t\tfor A in C:\n\t\t\tif isinstance(A,Element):B._dom_element.appendChild(A._dom_element)\n\t\t\telif isinstance(A,ElementCollection):\n\t\t\t\tfor D in A:B._dom_element.appendChild(D._dom_element)\n\t\t\telif isinstance(A,(list,tuple)):\n\t\t\t\tfor E in A:B.append(E)\n\t\t\telse:\n\t\t\t\ttry:A.tagName;B._dom_element.appendChild(A)\n\t\t\t\texcept AttributeError:\n\t\t\t\t\ttry:\n\t\t\t\t\t\tA.length\n\t\t\t\t\t\tfor F in A:B._dom_element.appendChild(F)\n\t\t\t\t\texcept AttributeError:G=f'Element \"{A}\" is a proxy object, \"but not a valid element or a NodeList.';raise TypeError(G)\n\tdef clone(B,clone_id=_A):A=Element.wrap_dom_element(B._dom_element.cloneNode(True));A.id=clone_id;return A\n\tdef find(A,selector):return ElementCollection.wrap_dom_elements(A._dom_element.querySelectorAll(selector))\n\tdef show_me(A):A._dom_element.scrollIntoView()\n\tdef update(A,classes=_A,style=_A,**D):\n\t\tC=style;B=classes\n\t\tif B:A.classes.add(B)\n\t\tif C:A.style.set(**C)\n\t\tfor(E,F)in D.items():setattr(A,E,F)\nclass Classes:\n\tdef __init__(A,element):A._element=element;A._class_list=A._element._dom_element.classList\n\tdef __contains__(A,item):return item in A._class_list\n\tdef __eq__(C,other):\n\t\tA=other\n\t\tif isinstance(A,Classes):B=list(A._class_list)\n\t\telse:\n\t\t\ttry:B=iter(A)\n\t\t\texcept TypeError:return False\n\t\treturn set(C._class_list)==set(B)\n\tdef __iter__(A):return iter(A._class_list)\n\tdef __len__(A):return A._class_list.length\n\tdef __repr__(A):return f\"Classes({\", \".join(A._class_list)})\"\n\tdef __str__(A):return' '.join(A._class_list)\n\tdef add(B,*C):\n\t\tfor A in C:\n\t\t\tif isinstance(A,list):\n\t\t\t\tfor D in A:B.add(D)\n\t\t\telse:B._class_list.add(A)\n\tdef contains(A,class_name):return class_name in A\n\tdef remove(B,*C):\n\t\tfor A in C:\n\t\t\tif isinstance(A,list):\n\t\t\t\tfor D in A:B.remove(D)\n\t\t\telse:B._class_list.remove(A)\n\tdef replace(A,old_class,new_class):A.remove(old_class);A.add(new_class)\n\tdef toggle(A,*C):\n\t\tfor B in C:\n\t\t\tif B in A:A.remove(B)\n\t\t\telse:A.add(B)\nclass HasOptions:\n\t@property\n\tdef options(self):\n\t\tA=self\n\t\tif not hasattr(A,'_options'):A._options=Options(A)\n\t\treturn A._options\nclass Options:\n\tdef __init__(A,element):A._element=element\n\tdef __getitem__(A,key):return A.options[key]\n\tdef __iter__(A):yield from A.options\n\tdef __len__(A):return len(A.options)\n\tdef __repr__(A):return f\"{A.__class__.__name__} (length: {len(A)}) {A.options}\"\n\t@property\n\tdef options(self):return[Element.wrap_dom_element(A)for A in self._element._dom_element.options]\n\t@property\n\tdef selected(self):return self.options[self._element._dom_element.selectedIndex]\n\tdef add(D,value=_A,html=_A,text=_A,before=_A,**B):\n\t\tC=value;A=before\n\t\tif C is not _A:B['value']=C\n\t\tif html is not _A:B['innerHTML']=html\n\t\tif text is not _A:B['text']=text\n\t\tE=option(**B)\n\t\tif A and isinstance(A,Element):A=A._dom_element\n\t\tD._element._dom_element.add(E._dom_element,A)\n\tdef clear(A):\n\t\twhile len(A)>0:A.remove(0)\n\tdef remove(A,index):A._element._dom_element.remove(index)\nclass Style:\n\tdef __init__(A,element):A._element=element;A._style=A._element._dom_element.style\n\tdef __getitem__(A,key):return A._style.getPropertyValue(key)\n\tdef __setitem__(A,key,value):A._style.setProperty(key,value)\n\tdef remove(A,key):A._style.removeProperty(key)\n\tdef set(A,**B):\n\t\tfor(C,D)in B.items():A._element._dom_element.style.setProperty(C,D)\n\t@property\n\tdef visible(self):return self._element._dom_element.style.visibility\n\t@visible.setter\n\tdef visible(self,value):self._element._dom_element.style.visibility=value\nclass ContainerElement(Element):\n\tdef __init__(B,*C,children=_A,dom_element=_A,style=_A,classes=_A,**D):\n\t\tsuper().__init__(dom_element=dom_element,style=style,classes=classes,**D)\n\t\tfor A in list(C)+(children or[]):\n\t\t\tif isinstance(A,(Element,ElementCollection)):B.append(A)\n\t\t\telse:B._dom_element.insertAdjacentHTML('beforeend',A)\n\tdef __iter__(A):yield from A.children\nclass ClassesCollection:\n\tdef __init__(A,collection):A._collection=collection\n\tdef __contains__(A,class_name):\n\t\tfor B in A._collection:\n\t\t\tif class_name in B.classes:return True\n\t\treturn False\n\tdef __eq__(B,other):A=other;return isinstance(A,ClassesCollection)and B._collection==A._collection\n\tdef __iter__(A):yield from A._all_class_names()\n\tdef __len__(A):return len(A._all_class_names())\n\tdef __repr__(A):return f\"ClassesCollection({A._collection!r})\"\n\tdef __str__(A):return' '.join(A._all_class_names())\n\tdef add(A,*B):\n\t\tfor C in A._collection:C.classes.add(*B)\n\tdef contains(A,class_name):return class_name in A\n\tdef remove(A,*B):\n\t\tfor C in A._collection:C.classes.remove(*B)\n\tdef replace(A,old_class,new_class):\n\t\tfor B in A._collection:B.classes.replace(old_class,new_class)\n\tdef toggle(A,*B):\n\t\tfor C in A._collection:C.classes.toggle(*B)\n\tdef _all_class_names(B):\n\t\tA=set()\n\t\tfor C in B._collection:\n\t\t\tfor D in C.classes:A.add(D)\n\t\treturn A\nclass StyleCollection:\n\tdef __init__(A,collection):A._collection=collection\n\tdef __getitem__(A,key):return[A.style[key]for A in A._collection._elements]\n\tdef __setitem__(A,key,value):\n\t\tfor B in A._collection._elements:B.style[key]=value\n\tdef __repr__(A):return f\"StyleCollection({A._collection!r})\"\n\tdef remove(A,key):\n\t\tfor B in A._collection._elements:B.style.remove(key)\nclass ElementCollection:\n\t@classmethod\n\tdef wrap_dom_elements(A,dom_elements):return A([Element.wrap_dom_element(A)for A in dom_elements])\n\tdef __init__(A,elements):A._elements=elements;A._classes=ClassesCollection(A);A._style=StyleCollection(A)\n\tdef __eq__(A,obj):return isinstance(obj,ElementCollection)and obj._elements==A._elements\n\tdef __getitem__(B,key):\n\t\tA=key\n\t\tif isinstance(A,int):return B._elements[A]\n\t\tif isinstance(A,slice):return ElementCollection(B._elements[A])\n\t\treturn B.find(A)\n\tdef __iter__(A):yield from A._elements\n\tdef __len__(A):return len(A._elements)\n\tdef __repr__(A):return f\"{A.__class__.__name__} (length: {len(A._elements)}) {A._elements}\"\n\tdef __getattr__(A,name):return[getattr(A,name)for A in A._elements]\n\tdef __setattr__(C,name,value):\n\t\tB=value;A=name\n\t\tif A.startswith('_'):super().__setattr__(A,B)\n\t\telse:\n\t\t\tfor D in C._elements:setattr(D,A,B)\n\t@property\n\tdef classes(self):return self._classes\n\t@property\n\tdef elements(self):return self._elements\n\t@property\n\tdef style(self):return self._style\n\tdef find(B,selector):\n\t\tA=[]\n\t\tfor C in B._elements:A.extend(C.find(selector))\n\t\treturn ElementCollection(A)\nclass a(ContainerElement):0\nclass abbr(ContainerElement):0\nclass address(ContainerElement):0\nclass area(Element):0\nclass article(ContainerElement):0\nclass aside(ContainerElement):0\nclass audio(ContainerElement):0\nclass b(ContainerElement):0\nclass base(Element):0\nclass blockquote(ContainerElement):0\nclass body(ContainerElement):0\nclass br(Element):0\nclass button(ContainerElement):0\nclass canvas(ContainerElement):\n\tdef download(A,filename='snapped.png'):B=a(download=filename,href=A._dom_element.toDataURL());A.append(B);B._dom_element.click()\n\tdef draw(E,what,width=_A,height=_A):\n\t\tC=height;B=width;A=what\n\t\tif isinstance(A,Element):A=A._dom_element\n\t\tD=E._dom_element.getContext('2d')\n\t\tif B or C:D.drawImage(A,0,0,B,C)\n\t\telse:D.drawImage(A,0,0)\nclass caption(ContainerElement):0\nclass cite(ContainerElement):0\nclass code(ContainerElement):0\nclass col(Element):0\nclass colgroup(ContainerElement):0\nclass data(ContainerElement):0\nclass datalist(ContainerElement,HasOptions):0\nclass dd(ContainerElement):0\nclass del_(ContainerElement):0\nclass details(ContainerElement):0\nclass dialog(ContainerElement):0\nclass div(ContainerElement):0\nclass dl(ContainerElement):0\nclass dt(ContainerElement):0\nclass em(ContainerElement):0\nclass embed(Element):0\nclass fieldset(ContainerElement):0\nclass figcaption(ContainerElement):0\nclass figure(ContainerElement):0\nclass footer(ContainerElement):0\nclass form(ContainerElement):0\nclass h1(ContainerElement):0\nclass h2(ContainerElement):0\nclass h3(ContainerElement):0\nclass h4(ContainerElement):0\nclass h5(ContainerElement):0\nclass h6(ContainerElement):0\nclass head(ContainerElement):0\nclass header(ContainerElement):0\nclass hgroup(ContainerElement):0\nclass hr(Element):0\nclass html(ContainerElement):0\nclass i(ContainerElement):0\nclass iframe(ContainerElement):0\nclass img(Element):0\nclass input_(Element):0\nclass ins(ContainerElement):0\nclass kbd(ContainerElement):0\nclass label(ContainerElement):0\nclass legend(ContainerElement):0\nclass li(ContainerElement):0\nclass link(Element):0\nclass main(ContainerElement):0\nclass map_(ContainerElement):0\nclass mark(ContainerElement):0\nclass menu(ContainerElement):0\nclass meta(ContainerElement):0\nclass meter(ContainerElement):0\nclass nav(ContainerElement):0\nclass object_(ContainerElement):0\nclass ol(ContainerElement):0\nclass optgroup(ContainerElement,HasOptions):0\nclass option(ContainerElement):0\nclass output(ContainerElement):0\nclass p(ContainerElement):0\nclass param(ContainerElement):0\nclass picture(ContainerElement):0\nclass pre(ContainerElement):0\nclass progress(ContainerElement):0\nclass q(ContainerElement):0\nclass s(ContainerElement):0\nclass script(ContainerElement):0\nclass section(ContainerElement):0\nclass select(ContainerElement,HasOptions):0\nclass small(ContainerElement):0\nclass source(Element):0\nclass span(ContainerElement):0\nclass strong(ContainerElement):0\nclass style(ContainerElement):0\nclass sub(ContainerElement):0\nclass summary(ContainerElement):0\nclass sup(ContainerElement):0\nclass table(ContainerElement):0\nclass tbody(ContainerElement):0\nclass td(ContainerElement):0\nclass template(ContainerElement):0\nclass textarea(ContainerElement):0\nclass tfoot(ContainerElement):0\nclass th(ContainerElement):0\nclass thead(ContainerElement):0\nclass time(ContainerElement):0\nclass title(ContainerElement):0\nclass tr(ContainerElement):0\nclass track(Element):0\nclass u(ContainerElement):0\nclass ul(ContainerElement):0\nclass var(ContainerElement):0\nclass video(ContainerElement):\n\tdef snap(E,to=_A,width=_A,height=_A):\n\t\tH='CANVAS';G='Element to snap to must be a canvas.';C=height;B=width;A=to;B=B if B is not _A else E.videoWidth;C=C if C is not _A else E.videoHeight\n\t\tif A is _A:A=canvas(width=B,height=C)\n\t\telif isinstance(A,Element):\n\t\t\tif A.tag!='canvas':D=G;raise TypeError(D)\n\t\telif getattr(A,'tagName','')==H:A=canvas(dom_element=A)\n\t\telif isinstance(A,str):\n\t\t\tF=document.querySelectorAll(A)\n\t\t\tif F.length==0:D='No element with selector {to} to snap to.';raise TypeError(D)\n\t\t\tif F[0].tagName!=H:D=G;raise TypeError(D)\n\t\t\tA=canvas(dom_element=F[0])\n\t\tA.draw(E,B,C);return A\nclass wbr(Element):0\nELEMENT_CLASSES=[a,abbr,address,area,article,aside,audio,b,base,blockquote,body,br,button,canvas,caption,cite,code,col,colgroup,data,datalist,dd,del_,details,dialog,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,img,input_,ins,kbd,label,legend,li,link,main,map_,mark,menu,meta,meter,nav,object_,ol,optgroup,option,output,p,param,picture,pre,progress,q,s,script,section,select,small,source,span,strong,style,sub,summary,sup,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,u,ul,var,video,wbr]\nElement.register_element_classes(ELEMENT_CLASSES)\nclass Page:\n\tdef __init__(A):A.html=Element.wrap_dom_element(document.documentElement);A.body=Element.wrap_dom_element(document.body);A.head=Element.wrap_dom_element(document.head)\n\tdef __getitem__(A,selector):return A.find(selector)\n\t@property\n\tdef title(self):return document.title\n\t@title.setter\n\tdef title(self,value):document.title=value\n\tdef append(A,*B):A.body.append(*B)\n\tdef find(A,selector):return ElementCollection.wrap_dom_elements(document.querySelectorAll(selector))\npage=Page()",
16
16
  "websocket.py": "import js\nfrom pyscript.ffi import create_proxy\nfrom pyscript.util import as_bytearray\ncode='code'\nprotocols='protocols'\nreason='reason'\nmethods=['onclose','onerror','onmessage','onopen']\nclass EventMessage:\n\tdef __init__(A,event):A._event=event\n\tdef __getattr__(B,attr):\n\t\tA=getattr(B._event,attr)\n\t\tif attr=='data'and not isinstance(A,str):\n\t\t\tif hasattr(A,'to_py'):return A.to_py()\n\t\t\treturn memoryview(as_bytearray(A))\n\t\treturn A\nclass WebSocket:\n\tCONNECTING=0;OPEN=1;CLOSING=2;CLOSED=3\n\tdef __init__(E,**A):\n\t\tD=A['url']\n\t\tif protocols in A:B=js.WebSocket.new(D,A[protocols])\n\t\telse:B=js.WebSocket.new(D)\n\t\tobject.__setattr__(E,'_ws',B)\n\t\tfor C in methods:\n\t\t\tif C in A:setattr(B,C,create_proxy(A[C]))\n\tdef __getattr__(A,attr):return getattr(A._ws,attr)\n\tdef __setattr__(B,attr,value):\n\t\tC=value;A=attr\n\t\tif A in methods:D=lambda e:C(EventMessage(e));setattr(B._ws,A,create_proxy(D))\n\t\telse:setattr(B._ws,A,C)\n\tdef close(B,**A):\n\t\tif code in A and reason in A:B._ws.close(A[code],A[reason])\n\t\telif code in A:B._ws.close(A[code])\n\t\telse:B._ws.close()\n\tdef send(B,data):\n\t\tA=data\n\t\tif isinstance(A,str):B._ws.send(A)\n\t\telse:\n\t\t\tC=js.Uint8Array.new(len(A))\n\t\t\tfor(D,E)in enumerate(A):C[D]=E\n\t\t\tB._ws.send(C)",
17
17
  "workers.py": "import js as _js\nfrom polyscript import workers as _workers\n_get=_js.Reflect.get\ndef _set(script,name,value=''):script.setAttribute(name,value)\nclass _ReadOnlyProxy:\n\tdef __getitem__(A,name):return _get(_workers,name)\n\tdef __getattr__(A,name):return _get(_workers,name)\nworkers=_ReadOnlyProxy()\nasync def create_named_worker(src='',name='',config=None,type='py'):\n\tC=name;B=config;from json import dumps\n\tif not src:D='Named workers require src';raise ValueError(D)\n\tif not C:D='Named workers require a name';raise ValueError(D)\n\tA=_js.document.createElement('script');A.type=type;A.src=src;_set(A,'worker');_set(A,'name',C)\n\tif B:_set(A,'config',isinstance(B,str)and B or dumps(B))\n\t_js.document.body.append(A);return await workers[C]"
18
18
  }
@@ -1,2 +0,0 @@
1
- import{E as e,V as t,b as i,a as s,c as n,d as o,r,h as l,W as a,e as c,f as h,i as d,j as u,m as f,n as m,o as p,p as g,k as v}from"./codemirror_view-Gaaf0HCU.js";import{StateField as x,StateEffect as b,Prec as w,EditorSelection as k,Facet as y,combineConfig as M,codePointAt as S,fromCodePoint as C,codePointSize as L,CharCategory as q,EditorState as A,RangeSetBuilder as R,findClusterBreak as D}from"./codemirror_state-1UkzIAPK.js";import{f as W,a as F,b as I,c as P,d as E,e as $}from"./codemirror_language-g0vQwyLF.js";import{history as O,defaultKeymap as z,historyKeymap as T}from"./codemirror_commands-BOf4K2ts.js";import{c as B,a as j,b as _,d as V}from"./index-Dhv1RkW_.js";const H="function"==typeof String.prototype.normalize?e=>e.normalize("NFKD"):e=>e;class N{constructor(e,t,i=0,s=e.length,n,o){this.test=o,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,s),this.bufferStart=i,this.normalize=n?e=>n(H(e)):H,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return S(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=C(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=L(e);let s=this.normalize(t);if(s.length)for(let e=0,n=i;;e++){let o=s.charCodeAt(e),r=this.match(o,n,this.bufferPos+this.bufferStart);if(e==s.length-1){if(r)return this.value=r,this;break}n==i&&e<t.length&&t.charCodeAt(e)==o&&n++}}}match(e,t,i){let s=null;for(let t=0;t<this.matches.length;t+=2){let n=this.matches[t],o=!1;this.query.charCodeAt(n)==e&&(n==this.query.length-1?s={from:this.matches[t+1],to:i}:(this.matches[t]++,o=!0)),o||(this.matches.splice(t,2),t-=2)}return this.query.charCodeAt(0)==e&&(1==this.query.length?s={from:t,to:i}:this.matches.push(1,t)),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}"undefined"!=typeof Symbol&&(N.prototype[Symbol.iterator]=function(){return this});const K={from:-1,to:-1,match:/.*/.exec("")},Q="gm"+(null==/x/.unicode?"":"u");class U{constructor(e,t,i,s=0,n=e.length){if(this.text=e,this.to=n,this.curLine="",this.done=!1,this.value=K,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Z(e,t,i,s,n);this.re=new RegExp(t,Q+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.iter=e.iter();let o=e.lineAt(s);this.curLineStart=o.from,this.matchPos=J(e,s),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,s=i+t[0].length;if(this.matchPos=J(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<s||i>this.value.to)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,match:t},this;e=this.matchPos-this.curLineStart}else{if(!(this.curLineStart+this.curLine.length<this.to))return this.done=!0,this;this.nextLine(),e=0}}}}const G=new WeakMap;class Y{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let s=G.get(e);if(!s||s.from>=i||s.to<=t){let s=new Y(t,e.sliceString(t,i));return G.set(e,s),s}if(s.from==t&&s.to==i)return s;let{text:n,from:o}=s;return o>t&&(n=e.sliceString(t,o)+n,o=t),s.to<i&&(n+=e.sliceString(s.to,i)),G.set(e,new Y(o,n)),new Y(t,n.slice(t-o,i-o))}}class Z{constructor(e,t,i,s,n){this.text=e,this.to=n,this.done=!1,this.value=K,this.matchPos=J(e,s),this.re=new RegExp(t,Q+((null==i?void 0:i.ignoreCase)?"i":"")),this.test=null==i?void 0:i.test,this.flat=Y.get(e,s,this.chunkEnd(s+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let e=this.flat.from+t.index,i=e+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(e,i,t)))return this.value={from:e,to:i,match:t},this.matchPos=J(this.text,i+(e==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Y.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function J(e,t){if(t>=e.length)return t;let i,s=e.lineAt(t);for(;t<s.to&&(i=s.text.charCodeAt(t-s.from))>=56320&&i<57344;)t++;return t}function X(t){let i=String(t.state.doc.lineAt(t.state.selection.main.head).number),s=o("input",{class:"cm-textfield",name:"line",value:i});function n(){let i=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(s.value);if(!i)return;let{state:n}=t,o=n.doc.lineAt(n.selection.main.head),[,r,l,a,c]=i,h=a?+a.slice(1):0,d=l?+l:o.number;if(l&&c){let e=d/100;r&&(e=e*("-"==r?-1:1)+o.number/n.doc.lines),d=Math.round(n.doc.lines*e)}else l&&r&&(d=d*("-"==r?-1:1)+o.number);let u=n.doc.line(Math.max(1,Math.min(n.doc.lines,d))),f=k.cursor(u.from+Math.max(0,Math.min(h,u.length)));t.dispatch({effects:[ee.of(!1),e.scrollIntoView(f.from,{y:"center"})],selection:f}),t.focus()}return{dom:o("form",{class:"cm-gotoLine",onkeydown:e=>{27==e.keyCode?(e.preventDefault(),t.dispatch({effects:ee.of(!1)}),t.focus()):13==e.keyCode&&(e.preventDefault(),n())},onsubmit:e=>{e.preventDefault(),n()}},o("label",t.state.phrase("Go to line"),": ",s)," ",o("button",{class:"cm-button",type:"submit"},t.state.phrase("go")),o("button",{name:"close",onclick:()=>{t.dispatch({effects:ee.of(!1)}),t.focus()},"aria-label":t.state.phrase("close"),type:"button"},["×"]))}}"undefined"!=typeof Symbol&&(U.prototype[Symbol.iterator]=Z.prototype[Symbol.iterator]=function(){return this});const ee=b.define(),te=x.define({create:()=>!0,update(e,t){for(let i of t.effects)i.is(ee)&&(e=i.value);return e},provide:e=>n.from(e,(e=>e?X:null))}),ie=e.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px",position:"relative","& label":{fontSize:"80%"},"& [name=close]":{position:"absolute",top:"0",bottom:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:"0"}}}),se={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},ne=y.define({combine:e=>M(e,se,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})});const oe=s.mark({class:"cm-selectionMatch"}),re=s.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function le(e,t,i,s){return!(0!=i&&e(t.sliceDoc(i-1,i))==q.Word||s!=t.doc.length&&e(t.sliceDoc(s,s+1))==q.Word)}const ae=t.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(ne),{state:i}=e,n=i.selection;if(n.ranges.length>1)return s.none;let o,r=n.main,l=null;if(r.empty){if(!t.highlightWordAroundCursor)return s.none;let e=i.wordAt(r.head);if(!e)return s.none;l=i.charCategorizer(r.head),o=i.sliceDoc(e.from,e.to)}else{let e=r.to-r.from;if(e<t.minSelectionLength||e>200)return s.none;if(t.wholeWords){if(o=i.sliceDoc(r.from,r.to),l=i.charCategorizer(r.head),!le(l,i,r.from,r.to)||!function(e,t,i,s){return e(t.sliceDoc(i,i+1))==q.Word&&e(t.sliceDoc(s-1,s))==q.Word}(l,i,r.from,r.to))return s.none}else if(o=i.sliceDoc(r.from,r.to),!o)return s.none}let a=[];for(let n of e.visibleRanges){let e=new N(i.doc,o,n.from,n.to);for(;!e.next().done;){let{from:n,to:o}=e.value;if((!l||le(l,i,n,o))&&(r.empty&&n<=r.from&&o>=r.to?a.push(re.range(n,o)):(n>=r.to||o<=r.from)&&a.push(oe.range(n,o)),a.length>t.maxMatches))return s.none}}return s.set(a)}},{decorations:e=>e.decorations}),ce=e.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const he=y.define({combine:t=>M(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Te(e),scrollToMatch:t=>e.scrollIntoView(t)})});class de{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||function(e){try{return new RegExp(e,Q),!0}catch(e){return!1}}(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,((e,t)=>"n"==t?"\n":"r"==t?"\r":"t"==t?"\t":"\\"))}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord}create(){return this.regexp?new xe(this):new me(this)}getCursor(e,t=0,i){let s=e.doc?e:A.create({doc:e});return null==i&&(i=s.doc.length),this.regexp?pe(this,s,t,i):fe(this,s,t,i)}}class ue{constructor(e){this.spec=e}}function fe(e,t,i,s){return new N(t.doc,e.unquoted,i,s,e.caseSensitive?void 0:e=>e.toLowerCase(),e.wholeWord?(n=t.doc,o=t.charCategorizer(t.selection.main.head),(e,t,i,s)=>((s>e||s+i.length<t)&&(s=Math.max(0,e-2),i=n.sliceString(s,Math.min(n.length,t+2))),!(o(ge(i,e-s))==q.Word&&o(ve(i,e-s))==q.Word||o(ve(i,t-s))==q.Word&&o(ge(i,t-s))==q.Word))):void 0);var n,o}class me extends ue{constructor(e){super(e)}nextMatch(e,t,i){let s=fe(this.spec,e,i,e.doc.length).nextOverlapping();if(s.done){let i=Math.min(e.doc.length,t+this.spec.unquoted.length);s=fe(this.spec,e,0,i).nextOverlapping()}return s.done||s.value.from==t&&s.value.to==i?null:s.value}prevMatchInRange(e,t,i){for(let s=i;;){let i=Math.max(t,s-1e4-this.spec.unquoted.length),n=fe(this.spec,e,i,s),o=null;for(;!n.nextOverlapping().done;)o=n.value;if(o)return o;if(i==t)return null;s-=1e4}}prevMatch(e,t,i){let s=this.prevMatchInRange(e,0,t);return s||(s=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),!s||s.from==t&&s.to==i?null:s}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=fe(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let n=fe(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!n.next().done;)s(n.value.from,n.value.to)}}function pe(e,t,i,s){return new U(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:e.wholeWord?(n=t.charCategorizer(t.selection.main.head),(e,t,i)=>!i[0].length||(n(ge(i.input,i.index))!=q.Word||n(ve(i.input,i.index))!=q.Word)&&(n(ve(i.input,i.index+i[0].length))!=q.Word||n(ge(i.input,i.index+i[0].length))!=q.Word)):void 0},i,s);var n}function ge(e,t){return e.slice(D(e,t,!1),t)}function ve(e,t){return e.slice(t,D(e,t))}class xe extends ue{nextMatch(e,t,i){let s=pe(this.spec,e,i,e.doc.length).next();return s.done&&(s=pe(this.spec,e,0,t).next()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=1;;s++){let n=Math.max(t,i-1e4*s),o=pe(this.spec,e,n,i),r=null;for(;!o.next().done;)r=o.value;if(r&&(n==t||r.from>n+10))return r;if(n==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,((t,i)=>{if("&"==i)return e.match[0];if("$"==i)return"$";for(let t=i.length;t>0;t--){let s=+i.slice(0,t);if(s>0&&s<e.match.length)return e.match[s]+i.slice(t)}return t}))}matchAll(e,t){let i=pe(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let n=pe(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!n.next().done;)s(n.value.from,n.value.to)}}const be=b.define(),we=b.define(),ke=x.define({create:e=>new ye(Ie(e).create(),null),update(e,t){for(let i of t.effects)i.is(be)?e=new ye(i.value.create(),e.panel):i.is(we)&&(e=new ye(e.query,i.value?Fe:null));return e},provide:e=>n.from(e,(e=>e.panel))});class ye{constructor(e,t){this.query=e,this.panel=t}}const Me=s.mark({class:"cm-searchMatch"}),Se=s.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Ce=t.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field(ke))}update(e){let t=e.state.field(ke);(t!=e.startState.field(ke)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return s.none;let{view:i}=this,n=new R;for(let t=0,s=i.visibleRanges,o=s.length;t<o;t++){let{from:r,to:l}=s[t];for(;t<o-1&&l>s[t+1].from-500;)l=s[++t].to;e.highlight(i.state,r,l,((e,t)=>{let s=i.state.selection.ranges.some((i=>i.from==e&&i.to==t));n.add(e,t,s?Se:Me)}))}return n.finish()}},{decorations:e=>e.decorations});function Le(e){return t=>{let i=t.state.field(ke,!1);return i&&i.query.spec.valid?e(t,i):$e(t)}}const qe=Le(((e,{query:t})=>{let{to:i}=e.state.selection.main,s=t.nextMatch(e.state,i,i);if(!s)return!1;let n=k.single(s.from,s.to),o=e.state.facet(he);return e.dispatch({selection:n,effects:[Ve(e,s),o.scrollToMatch(n.main,e)],userEvent:"select.search"}),Ee(e),!0})),Ae=Le(((e,{query:t})=>{let{state:i}=e,{from:s}=i.selection.main,n=t.prevMatch(i,s,s);if(!n)return!1;let o=k.single(n.from,n.to),r=e.state.facet(he);return e.dispatch({selection:o,effects:[Ve(e,n),r.scrollToMatch(o.main,e)],userEvent:"select.search"}),Ee(e),!0})),Re=Le(((e,{query:t})=>{let i=t.matchAll(e.state,1e3);return!(!i||!i.length)&&(e.dispatch({selection:k.create(i.map((e=>k.range(e.from,e.to)))),userEvent:"select.search.matches"}),!0)})),De=Le(((t,{query:i})=>{let{state:s}=t,{from:n,to:o}=s.selection.main;if(s.readOnly)return!1;let r=i.nextMatch(s,n,n);if(!r)return!1;let l,a,c=r,h=[],d=[];if(c.from==n&&c.to==o&&(a=s.toText(i.getReplacement(c)),h.push({from:c.from,to:c.to,insert:a}),c=i.nextMatch(s,c.from,c.to),d.push(e.announce.of(s.phrase("replaced match on line $",s.doc.lineAt(n).number)+"."))),c){let e=0==h.length||h[0].from>=r.to?0:r.to-r.from-a.length;l=k.single(c.from-e,c.to-e),d.push(Ve(t,c)),d.push(s.facet(he).scrollToMatch(l.main,t))}return t.dispatch({changes:h,selection:l,effects:d,userEvent:"input.replace"}),!0})),We=Le(((t,{query:i})=>{if(t.state.readOnly)return!1;let s=i.matchAll(t.state,1e9).map((e=>{let{from:t,to:s}=e;return{from:t,to:s,insert:i.getReplacement(e)}}));if(!s.length)return!1;let n=t.state.phrase("replaced $ matches",s.length)+".";return t.dispatch({changes:s,effects:e.announce.of(n),userEvent:"input.replace.all"}),!0}));function Fe(e){return e.state.facet(he).createPanel(e)}function Ie(e,t){var i,s,n,o,r;let l=e.selection.main,a=l.empty||l.to>l.from+100?"":e.sliceDoc(l.from,l.to);if(t&&!a)return t;let c=e.facet(he);return new de({search:(null!==(i=null==t?void 0:t.literal)&&void 0!==i?i:c.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:null!==(s=null==t?void 0:t.caseSensitive)&&void 0!==s?s:c.caseSensitive,literal:null!==(n=null==t?void 0:t.literal)&&void 0!==n?n:c.literal,regexp:null!==(o=null==t?void 0:t.regexp)&&void 0!==o?o:c.regexp,wholeWord:null!==(r=null==t?void 0:t.wholeWord)&&void 0!==r?r:c.wholeWord})}function Pe(e){let t=i(e,Fe);return t&&t.dom.querySelector("[main-field]")}function Ee(e){let t=Pe(e);t&&t==e.root.activeElement&&t.select()}const $e=e=>{let t=e.state.field(ke,!1);if(t&&t.panel){let i=Pe(e);if(i&&i!=e.root.activeElement){let s=Ie(e.state,t.query.spec);s.valid&&e.dispatch({effects:be.of(s)}),i.focus(),i.select()}}else e.dispatch({effects:[we.of(!0),t?be.of(Ie(e.state,t.query.spec)):b.appendConfig.of(Ne)]});return!0},Oe=e=>{let t=e.state.field(ke,!1);if(!t||!t.panel)return!1;let s=i(e,Fe);return s&&s.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:we.of(!1)}),!0},ze=[{key:"Mod-f",run:$e,scope:"editor search-panel"},{key:"F3",run:qe,shift:Ae,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:qe,shift:Ae,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Oe,scope:"editor search-panel"},{key:"Mod-Shift-l",run:({state:e,dispatch:t})=>{let i=e.selection;if(i.ranges.length>1||i.main.empty)return!1;let{from:s,to:n}=i.main,o=[],r=0;for(let t=new N(e.doc,e.sliceDoc(s,n));!t.next().done;){if(o.length>1e3)return!1;t.value.from==s&&(r=o.length),o.push(k.range(t.value.from,t.value.to))}return t(e.update({selection:k.create(o,r),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:e=>{let t=i(e,X);if(!t){let s=[ee.of(!0)];null==e.state.field(te,!1)&&s.push(b.appendConfig.of([te,ie])),e.dispatch({effects:s}),t=i(e,X)}return t&&t.dom.querySelector("input").select(),!0}},{key:"Mod-d",run:({state:t,dispatch:i})=>{let{ranges:s}=t.selection;if(s.some((e=>e.from===e.to)))return(({state:e,dispatch:t})=>{let{selection:i}=e,s=k.create(i.ranges.map((t=>e.wordAt(t.head)||k.cursor(t.head))),i.mainIndex);return!s.eq(i)&&(t(e.update({selection:s})),!0)})({state:t,dispatch:i});let n=t.sliceDoc(s[0].from,s[0].to);if(t.selection.ranges.some((e=>t.sliceDoc(e.from,e.to)!=n)))return!1;let o=function(e,t){let{main:i,ranges:s}=e.selection,n=e.wordAt(i.head),o=n&&n.from==i.from&&n.to==i.to;for(let i=!1,n=new N(e.doc,t,s[s.length-1].to);;){if(n.next(),!n.done){if(i&&s.some((e=>e.from==n.value.from)))continue;if(o){let t=e.wordAt(n.value.from);if(!t||t.from!=n.value.from||t.to!=n.value.to)continue}return n.value}if(i)return null;n=new N(e.doc,t,0,Math.max(0,s[s.length-1].from-1)),i=!0}}(t,n);return!!o&&(i(t.update({selection:t.selection.addRange(k.range(o.from,o.to),!1),effects:e.scrollIntoView(o.to)})),!0)},preventDefault:!0}];class Te{constructor(e){this.view=e;let t=this.query=e.state.field(ke).query.spec;function i(e,t,i){return o("button",{class:"cm-button",name:e,onclick:t,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=o("input",{value:t.search,placeholder:Be(e,"Find"),"aria-label":Be(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=o("input",{value:t.replace,placeholder:Be(e,"Replace"),"aria-label":Be(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=o("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=o("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=o("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit}),this.dom=o("div",{onkeydown:e=>this.keydown(e),class:"cm-search"},[this.searchField,i("next",(()=>qe(e)),[Be(e,"next")]),i("prev",(()=>Ae(e)),[Be(e,"previous")]),i("select",(()=>Re(e)),[Be(e,"all")]),o("label",null,[this.caseField,Be(e,"match case")]),o("label",null,[this.reField,Be(e,"regexp")]),o("label",null,[this.wordField,Be(e,"by word")]),...e.state.readOnly?[]:[o("br"),this.replaceField,i("replace",(()=>De(e)),[Be(e,"replace")]),i("replaceAll",(()=>We(e)),[Be(e,"replace all")])],o("button",{name:"close",onclick:()=>Oe(e),"aria-label":Be(e,"close"),type:"button"},["×"])])}commit(){let e=new de({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:be.of(e)}))}keydown(e){r(this.view,e,"search-panel")?e.preventDefault():13==e.keyCode&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Ae:qe)(this.view)):13==e.keyCode&&e.target==this.replaceField&&(e.preventDefault(),De(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(be)&&!e.value.eq(this.query)&&this.setQuery(e.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(he).top}}function Be(e,t){return e.state.phrase(t)}const je=30,_e=/[\s\.,:;?!]/;function Ve(t,{from:i,to:s}){let n=t.state.doc.lineAt(i),o=t.state.doc.lineAt(s).to,r=Math.max(n.from,i-je),l=Math.min(o,s+je),a=t.state.sliceDoc(r,l);if(r!=n.from)for(let e=0;e<je;e++)if(!_e.test(a[e+1])&&_e.test(a[e])){a=a.slice(e);break}if(l!=o)for(let e=a.length-1;e>a.length-je;e--)if(!_e.test(a[e-1])&&_e.test(a[e])){a=a.slice(0,e);break}return e.announce.of(`${t.state.phrase("current match")}. ${a} ${t.state.phrase("on line")} ${n.number}.`)}const He=e.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Ne=[ke,w.low(Ce),He];class Ke{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class Qe{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let n=i.facet(nt).markerFilter;n&&(e=n(e,i));let o=e.slice().sort(((e,t)=>e.from-t.from||e.to-t.to)),r=new R,l=[],a=0;for(let e=0;;){let t,n,c=e==o.length?null:o[e];if(!c&&!l.length)break;for(l.length?(t=a,n=l.reduce(((e,t)=>Math.min(e,t.to)),c&&c.from>t?c.from:1e8)):(t=c.from,n=c.to,l.push(c),e++);e<o.length;){let i=o[e];if(i.from!=t||!(i.to>i.from||i.to==t)){n=Math.min(i.from,n);break}l.push(i),e++,n=Math.min(i.to,n)}let h=ft(l);if(l.some((e=>e.from==e.to||e.from==e.to-1&&i.doc.lineAt(e.from).to==e.from)))r.add(t,t,s.widget({widget:new lt(h),diagnostics:l.slice()}));else{let e=l.reduce(((e,t)=>t.markClass?e+" "+t.markClass:e),"");r.add(t,n,s.mark({class:"cm-lintRange cm-lintRange-"+h+e,diagnostics:l.slice(),inclusiveEnd:l.some((e=>e.to>n))}))}a=n;for(let e=0;e<l.length;e++)l[e].to<=a&&l.splice(e--,1)}let c=r.finish();return new Qe(c,t,Ue(c))}}function Ue(e,t=null,i=0){let s=null;return e.between(i,1e9,((e,i,{spec:n})=>{if(!(t&&n.diagnostics.indexOf(t)<0))if(s){if(n.diagnostics.indexOf(s.diagnostic)<0)return!1;s=new Ke(s.from,i,s.diagnostic)}else s=new Ke(e,i,t||n.diagnostics[0])})),s}const Ge=b.define(),Ye=b.define(),Ze=b.define(),Je=x.define({create:()=>new Qe(s.none,null,null),update(e,t){if(t.docChanged&&e.diagnostics.size){let i=e.diagnostics.map(t.changes),s=null,n=e.panel;if(e.selected){let n=t.changes.mapPos(e.selected.from,1);s=Ue(i,e.selected.diagnostic,n)||Ue(i,null,n)}!i.size&&n&&t.state.facet(nt).autoPanel&&(n=null),e=new Qe(i,n,s)}for(let i of t.effects)if(i.is(Ge)){let s=t.state.facet(nt).autoPanel?i.value.length?ct.open:null:e.panel;e=Qe.init(i.value,s,t.state)}else i.is(Ye)?e=new Qe(e.diagnostics,i.value?ct.open:null,e.selected):i.is(Ze)&&(e=new Qe(e.diagnostics,e.panel,i.value));return e},provide:t=>[n.from(t,(e=>e.panel)),e.decorations.from(t,(e=>e.diagnostics))]}),Xe=s.mark({class:"cm-lintRange cm-lintRange-active"});function et(e,t,i){let s,{diagnostics:n}=e.state.field(Je),o=-1,r=-1;n.between(t-(i<0?1:0),t+(i>0?1:0),((e,n,{spec:l})=>{if(t>=e&&t<=n&&(e==n||(t>e||i>0)&&(t<n||i<0)))return s=l.diagnostics,o=e,r=n,!1}));let l=e.state.facet(nt).tooltipFilter;return s&&l&&(s=l(s,e.state)),s?{pos:o,end:r,above:e.state.doc.lineAt(o).to<r,create:()=>({dom:tt(e,s)})}:null}function tt(e,t){return o("ul",{class:"cm-tooltip-lint"},t.map((t=>rt(e,t,!1))))}const it=e=>{let t=e.state.field(Je,!1);return!(!t||!t.panel)&&(e.dispatch({effects:Ye.of(!1)}),!0)},st=[{key:"Mod-Shift-m",run:e=>{let t=e.state.field(Je,!1);var s,n;t&&t.panel||e.dispatch({effects:(s=e.state,n=[Ye.of(!0)],s.field(Je,!1)?n:n.concat(b.appendConfig.of(mt)))});let o=i(e,ct.open);return o&&o.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:e=>{let t=e.state.field(Je,!1);if(!t)return!1;let i=e.state.selection.main,s=t.diagnostics.iter(i.to+1);return!(!s.value&&(s=t.diagnostics.iter(0),!s.value||s.from==i.from&&s.to==i.to))&&(e.dispatch({selection:{anchor:s.from,head:s.to},scrollIntoView:!0}),!0)}}],nt=y.define({combine:e=>Object.assign({sources:e.map((e=>e.source)).filter((e=>null!=e))},M(e.map((e=>e.config)),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t}))});function ot(e){let t=[];if(e)e:for(let{name:i}of e){for(let e=0;e<i.length;e++){let s=i[e];if(/[a-zA-Z]/.test(s)&&!t.some((e=>e.toLowerCase()==s.toLowerCase()))){t.push(s);continue e}}t.push("")}return t}function rt(e,t,i){var s;let n=i?ot(t.actions):[];return o("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},o("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),null===(s=t.actions)||void 0===s?void 0:s.map(((i,s)=>{let r=!1,l=s=>{if(s.preventDefault(),r)return;r=!0;let n=Ue(e.state.field(Je).diagnostics,t);n&&i.apply(e,n.from,n.to)},{name:a}=i,c=n[s]?a.indexOf(n[s]):-1,h=c<0?a:[a.slice(0,c),o("u",a.slice(c,c+1)),a.slice(c+1)];return o("button",{type:"button",class:"cm-diagnosticAction",onclick:l,onmousedown:l,"aria-label":` Action: ${a}${c<0?"":` (access key "${n[s]})"`}.`},h)})),t.source&&o("div",{class:"cm-diagnosticSource"},t.source))}class lt extends a{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return o("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class at{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=rt(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class ct{constructor(e){this.view=e,this.items=[];this.list=o("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t=>{if(27==t.keyCode)it(this.view),this.view.focus();else if(38==t.keyCode||33==t.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==t.keyCode||34==t.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==t.keyCode)this.moveSelection(0);else if(35==t.keyCode)this.moveSelection(this.items.length-1);else if(13==t.keyCode)this.view.focus();else{if(!(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],s=ot(i.actions);for(let n=0;n<s.length;n++)if(s[n].toUpperCase().charCodeAt(0)==t.keyCode){let t=Ue(this.view.state.field(Je).diagnostics,i);t&&i.actions[n].apply(e,t.from,t.to)}}}t.preventDefault()},onclick:e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)}}),this.dom=o("div",{class:"cm-panel-lint"},this.list,o("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>it(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Je).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Je),i=0,s=!1,n=null,o=new Set;for(e.between(0,this.view.state.doc.length,((e,r,{spec:l})=>{for(let e of l.diagnostics){if(o.has(e))continue;o.add(e);let r,l=-1;for(let t=i;t<this.items.length;t++)if(this.items[t].diagnostic==e){l=t;break}l<0?(r=new at(this.view,e),this.items.splice(i,0,r),s=!0):(r=this.items[l],l>i&&(this.items.splice(i,l-i),s=!0)),t&&r.diagnostic==t.diagnostic?r.dom.hasAttribute("aria-selected")||(r.dom.setAttribute("aria-selected","true"),n=r):r.dom.hasAttribute("aria-selected")&&r.dom.removeAttribute("aria-selected"),i++}}));i<this.items.length&&!(1==this.items.length&&this.items[0].diagnostic.from<0);)s=!0,this.items.pop();0==this.items.length&&(this.items.push(new at(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),s=!0),n?(this.list.setAttribute("aria-activedescendant",n.id),this.view.requestMeasure({key:this,read:()=>({sel:n.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let i=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/i:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/i)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),s&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling,t.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=Ue(this.view.state.field(Je).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:Ze.of(t)})}static open(e){return new ct(e)}}function ht(e){return function(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const dt=e.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:ht("#d11")},".cm-lintRange-warning":{backgroundImage:ht("orange")},".cm-lintRange-info":{backgroundImage:ht("#999")},".cm-lintRange-hint":{backgroundImage:ht("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}}});function ut(e){return"error"==e?4:"warning"==e?3:"info"==e?2:1}function ft(e){let t="hint",i=1;for(let s of e){let e=ut(s.severity);e>i&&(i=e,t=s.severity)}return t}const mt=[Je,e.decorations.compute([Je],(e=>{let{selected:t,panel:i}=e.field(Je);return t&&i&&t.from!=t.to?s.set([Xe.range(t.from,t.to)]):s.none})),l(et,{hideOn:function(e,t){let i=t.pos,s=t.end||i,n=e.state.facet(nt).hideOn(e,i,s);if(null!=n)return n;let o=e.startState.doc.lineAt(t.pos);return!(!e.effects.some((e=>e.is(Ge)))&&!e.changes.touchesRange(o.from,Math.max(o.to,s)))}}),dt],pt=(()=>[c(),h(),d(),O(),W(),u(),f(),A.allowMultipleSelections.of(!0),F(),I(E,{fallback:!0}),P(),B(),j(),m(),p(),g(),[ce,ae],v.of([..._,...z,...ze,...T,...$,...V,...st])])(),gt=(()=>[d(),O(),u(),I(E,{fallback:!0}),v.of([...z,...T])])();export{e as EditorView,pt as basicSetup,gt as minimalSetup};
2
- //# sourceMappingURL=codemirror-8Ev_qLCE.js.map