@pyscript/core 0.5.16 → 0.6.0
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.
- package/README.md +143 -58
- package/dist/{codemirror-BEtcgaoQ.js → codemirror-D-uvNAgN.js} +2 -2
- package/dist/codemirror-D-uvNAgN.js.map +1 -0
- package/dist/{codemirror_commands-DDxffOmd.js → codemirror_commands-DSm3EjIb.js} +2 -2
- package/dist/{codemirror_commands-DDxffOmd.js.map → codemirror_commands-DSm3EjIb.js.map} +1 -1
- package/dist/{codemirror_lang-python-CnWnFqxD.js → codemirror_lang-python-DqJ7lvdh.js} +2 -2
- package/dist/{codemirror_lang-python-CnWnFqxD.js.map → codemirror_lang-python-DqJ7lvdh.js.map} +1 -1
- package/dist/{codemirror_language-CjmvX4ix.js → codemirror_language-DYjIHGr8.js} +2 -2
- package/dist/{codemirror_language-CjmvX4ix.js.map → codemirror_language-DYjIHGr8.js.map} +1 -1
- package/dist/codemirror_state-1d1uncXx.js +2 -0
- package/dist/{codemirror_state-D1qTXrff.js.map → codemirror_state-1d1uncXx.js.map} +1 -1
- package/dist/{codemirror_view-DVb8uYMr.js → codemirror_view-aIuSN42d.js} +2 -2
- package/dist/{codemirror_view-DVb8uYMr.js.map → codemirror_view-aIuSN42d.js.map} +1 -1
- package/dist/core-C9HPjYCc.js +2 -0
- package/dist/core-C9HPjYCc.js.map +1 -0
- package/dist/core.js +1 -1
- package/dist/{deprecations-manager-pFtn19mE.js → deprecations-manager-BMfD0JHV.js} +2 -2
- package/dist/{deprecations-manager-pFtn19mE.js.map → deprecations-manager-BMfD0JHV.js.map} +1 -1
- package/dist/{error-tq-z48YI.js → error-Cb9qat2C.js} +2 -2
- package/dist/{error-tq-z48YI.js.map → error-Cb9qat2C.js.map} +1 -1
- package/dist/{index-S1Do43bx.js → index-Bvz7aU6f.js} +2 -2
- package/dist/index-Bvz7aU6f.js.map +1 -0
- package/dist/{mpy-DovD7Qjy.js → mpy-1advVAHg.js} +2 -2
- package/dist/{mpy-DovD7Qjy.js.map → mpy-1advVAHg.js.map} +1 -1
- package/dist/{py-BUsUWVJg.js → py-Dgth27RD.js} +2 -2
- package/dist/{py-BUsUWVJg.js.map → py-Dgth27RD.js.map} +1 -1
- package/dist/{py-editor-CeySmmer.js → py-editor-Bhd8rbQi.js} +2 -2
- package/dist/{py-editor-CeySmmer.js.map → py-editor-Bhd8rbQi.js.map} +1 -1
- package/dist/{py-terminal-CH_wV7wQ.js → py-terminal-a-_kHDqz.js} +2 -2
- package/dist/{py-terminal-CH_wV7wQ.js.map → py-terminal-a-_kHDqz.js.map} +1 -1
- package/dist/storage.js +1 -1
- package/dist/storage.js.map +1 -1
- package/dist/zip-Bf48tRr5.js +2 -0
- package/dist/{zip-DrwYHuF9.js.map → zip-Bf48tRr5.js.map} +1 -1
- package/package.json +6 -6
- package/src/plugins.js +17 -4
- package/src/stdlib/pyscript/media.py +91 -0
- package/src/stdlib/pyscript.js +1 -0
- package/types/stdlib/pyscript.d.ts +1 -0
- package/dist/codemirror-BEtcgaoQ.js.map +0 -1
- package/dist/codemirror_state-D1qTXrff.js +0 -2
- package/dist/core-CjO3FOKB.js +0 -2
- package/dist/core-CjO3FOKB.js.map +0 -1
- package/dist/index-S1Do43bx.js.map +0 -1
- package/dist/zip-DrwYHuF9.js +0 -2
package/README.md
CHANGED
@@ -1,83 +1,168 @@
|
|
1
1
|
# @pyscript/core
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
3
|
+
PyScript brings two Python interpreters to the browser:
|
4
|
+
|
5
|
+
- [MicroPython](https://micropython.org/) - a lean and efficient implementation
|
6
|
+
of the Python 3 programming language that includes a small subset of the
|
7
|
+
Python standard library and is optimised to run on microcontrollers and in
|
8
|
+
constrained environments (like the browser).
|
9
|
+
- [Pyodide](https://pyodide.org)) - a port of all CPython to WebAssembly.
|
10
|
+
|
11
|
+
These interpreters are compiled to [WebAssembly](https://webassembly.org/)
|
12
|
+
(shortened to WASM). The browser provides a secure WASM computing sandbox. Both
|
13
|
+
interpreters are compiled to web assembly with
|
14
|
+
[Emscripten](https://emscripten.org/). PyScript core maintainers work closely
|
15
|
+
with the core maintainers of both MicroPython and Pyodide (and CPython). We
|
16
|
+
work hard to ensure PyScript works efficiently in browsers on all platforms:
|
17
|
+
desktop, mobile, or elsewhere.
|
18
|
+
|
19
|
+
Our technical documentation for using this project can be
|
20
|
+
[found here](https://docs.pyscript.net/).
|
21
|
+
|
22
|
+
PyScript sits on two further projects (both written in JavaScript):
|
23
|
+
|
24
|
+
1. [polyscript](https://github.com/pyscript/polyscript/#readme) - used to
|
25
|
+
bootstrap WASM compiled interpreters in a browser.
|
26
|
+
2. [coincident](https://github.com/WebReflection/coincident) - used to simplify
|
27
|
+
worker based tasks.
|
28
|
+
|
29
|
+
PyScript itself is mostly written in JavaScript. The test suite for JavaScript
|
30
|
+
is in two parts: automated tests run in [playwright](https://playwright.dev/),
|
31
|
+
and manual tests you have to run in a browser and check yourself. PyScript also
|
32
|
+
has a plugin system so third parties can extend its capabilities with
|
33
|
+
JavaScript. Our built-in core plugins can be found in the `src/plugins`
|
34
|
+
directory. We describe how to write third party plugins in our
|
35
|
+
[developer documentation](https://docs.pyscript.net/latest/user-guide/plugins/).
|
36
|
+
|
37
|
+
We provide a `pyscript` namespace containing Python modules for common browser
|
38
|
+
based APIs and features (i.e. you can `import pyscript` in Python code running
|
39
|
+
inside PyScript, to access these features). The Python code for the `pyscript`
|
40
|
+
namespace is in `src/stdlib/pyscript` with the associated test suite in
|
41
|
+
`tests/python`. The tests use the browser friendly
|
42
|
+
[uPyTest](https://github.com/ntoll/upytest) test framework for checking Python
|
43
|
+
code running _within_ PyScript. All the Python tests are run in each each
|
44
|
+
available interpreter in both the main thread and a web worker (i.e. the
|
45
|
+
test suite is run four times, accounting for each combination of interpreter
|
46
|
+
and main/worker context).
|
47
|
+
|
48
|
+
When you create a local build all the automated tests (JavaScript and Python)
|
49
|
+
are run.
|
50
|
+
|
51
|
+
## Developer Guide
|
52
|
+
|
53
|
+
Full instructions for setting up a working development environment, how to
|
54
|
+
build PyScript and how to test it can be
|
55
|
+
[found in our official docs](https://docs.pyscript.net/latest/developers/).
|
56
|
+
|
57
|
+
The short version is:
|
58
|
+
|
59
|
+
- Ensure you have Python, node and npm installed.
|
60
|
+
- Create a Python virtual environment.
|
61
|
+
- In the root of this repository `make setup`.
|
62
|
+
- `make build` to build PyScript.
|
63
|
+
- As dependencies change over time, `make update` to keep in sync.
|
64
|
+
|
65
|
+
To start using the locally built version of PyScript, you'll need an HTML
|
66
|
+
page something like this (note the relative paths to assets in the `dist`
|
67
|
+
directory, in the `<head>` of the document):
|
68
|
+
|
69
|
+
```html
|
70
|
+
<!doctype html>
|
71
|
+
<html lang="en">
|
72
|
+
<head>
|
73
|
+
<meta charset="UTF-8" />
|
74
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
75
|
+
<title>Pure Python PyScript tests</title>
|
76
|
+
<link rel="stylesheet" href="../../dist/core.css" />
|
77
|
+
<script type="module" src="../../dist/core.js"></script>
|
78
|
+
</head>
|
79
|
+
<body>
|
80
|
+
<script type="mpy" src="./main.py" config="./conf.toml"></script>
|
81
|
+
</body>
|
82
|
+
</html>
|
28
83
|
```
|
29
84
|
|
30
|
-
|
31
|
-
|
32
|
-
Before running the tests, we need to create a tests environment first. To do so run the following command from the root folder of the project:
|
85
|
+
Once set up, you should be able to run the most common activities via the
|
86
|
+
`make` command:
|
33
87
|
|
34
88
|
```
|
35
|
-
make
|
89
|
+
$ make
|
90
|
+
|
91
|
+
There is no default Makefile target right now. Try:
|
92
|
+
|
93
|
+
make setup - check your environment and install the dependencies.
|
94
|
+
make update - update dependencies.
|
95
|
+
make clean - clean up auto-generated assets.
|
96
|
+
make build - build PyScript.
|
97
|
+
make precommit-check - run the precommit checks (run eslint).
|
98
|
+
make test - run all automated tests in playwright.
|
99
|
+
make fmt - format the code.
|
100
|
+
make fmt-check - check the code formatting.
|
36
101
|
```
|
37
102
|
|
38
|
-
|
103
|
+
## Artifacts
|
39
104
|
|
40
|
-
|
105
|
+
There are two main artifacts in this project:
|
41
106
|
|
42
|
-
|
107
|
+
- **stdlib** and its content: `src/stdlib/pyscript.js` exposes, as a
|
108
|
+
JavaScript object literal, all the _Python_ content within the folder
|
109
|
+
(recursively).
|
110
|
+
- **plugins** and its content: `src/plugins.js` exposes all available
|
111
|
+
_dynamic imports_, and is able to instrument the bundler to create files
|
112
|
+
apart from the `_dist/_` folder, so that by default _core_ remains as small
|
113
|
+
as possible.
|
43
114
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
```
|
115
|
+
Accordingly, whenever a file contains this warning at its first line, **please
|
116
|
+
do not change such file directly before submitting a merge request**, as that
|
117
|
+
file will be overwritten at the next `npm run build` command, either here or
|
118
|
+
in _CI_:
|
49
119
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
```
|
54
|
-
make test
|
120
|
+
```js
|
121
|
+
// ⚠️ This file is an artifact: DO NOT MODIFY
|
55
122
|
```
|
56
123
|
|
57
|
-
|
58
|
-
|
59
|
-
Tests are found in the `tests` directory. These are organised into three locations:
|
124
|
+
## Plugins
|
60
125
|
|
61
|
-
|
62
|
-
|
63
|
-
|
126
|
+
While community or third party plugins don't need to be part of this repository
|
127
|
+
and can be added just importing `@pyscript/core` as module, there are a few
|
128
|
+
plugins that we would like to make available by default and these are
|
129
|
+
considered _core plugins_.
|
64
130
|
|
65
|
-
|
131
|
+
To add a _core plugin_ to this project define the plugin entry-point and name
|
132
|
+
in the `src/plugins` folder (see the `error.js` example) and create, if
|
133
|
+
necessary, a folder with the same name where extra files or dependencies can be
|
134
|
+
added.
|
66
135
|
|
67
|
-
The
|
136
|
+
The _build_ command will include plugins by name as artifacts so that the
|
137
|
+
bundler can create ad-hoc files within the `dist/` folder.
|
68
138
|
|
69
|
-
##
|
139
|
+
## Python
|
70
140
|
|
71
|
-
The `pyscript` package available in _Python_ lives in the folder
|
141
|
+
The `pyscript` package available in _Python_ lives in the folder
|
142
|
+
`src/stdlib/pyscript/`.
|
72
143
|
|
73
|
-
All _Python_ files will be embedded automatically whenever `npm run build`
|
144
|
+
All _Python_ files will be embedded automatically whenever `npm run build`
|
145
|
+
happens and reflected into the `src/stdlib/pyscript.js` file.
|
74
146
|
|
75
|
-
|
147
|
+
Its _core_ responsibility is to ensure those files will be available through
|
148
|
+
the filesystem in either the _main_ thread, or any _worker_.
|
76
149
|
|
77
|
-
##
|
150
|
+
## Release
|
78
151
|
|
79
|
-
|
152
|
+
To cut a new release of PyScript simply
|
153
|
+
[add a new release](https://github.com/pyscript/pyscript/releases) while
|
154
|
+
remembering to write a comprehensive changelog. A
|
155
|
+
[GitHub action](https://github.com/pyscript/pyscript/blob/main/.github/workflows/publish-release.yml)
|
156
|
+
will kick in and ensure the release is described and deployed to a URL with the
|
157
|
+
pattern: https://pyscript.net/releases/YYYY.M.v/ (year/month/version - as per
|
158
|
+
our [CalVer](https://calver.org/) versioning scheme).
|
80
159
|
|
81
|
-
|
160
|
+
Then, the following three separate repositories need updating:
|
82
161
|
|
83
|
-
|
162
|
+
- [Documentation](https://github.com/pyscript/docs) - Change the `version.json`
|
163
|
+
file in the root of the directory and then `node version-update.js`.
|
164
|
+
- [Homepage](https://github.com/pyscript/pyscript.net) - Ensure the version
|
165
|
+
referenced in `index.html` is the latest version.
|
166
|
+
- [PSDC](https://pyscript.com) - Use discord or Anaconda Slack (if you work at
|
167
|
+
Anaconda) to let the PSDC team know there's a new version, so they can update
|
168
|
+
their project templates.
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{V as e,a as t,E as i,b as s,c as n,r as o,h as r,W as a,d as l,e as c,f as h,i as d,j as u,m as f,n as m,o as p,k as g}from"./codemirror_view-DVb8uYMr.js";import{codePointAt as v,fromCodePoint as x,codePointSize as b,StateEffect as w,Facet as y,combineConfig as k,CharCategory as S,EditorSelection as M,Prec as C,StateField as A,EditorState as L,findClusterBreak as q,RangeSetBuilder as R}from"./codemirror_state-D1qTXrff.js";import{k as D,l as W,m as F,n as I,o as P,p as E}from"./codemirror_language-CjmvX4ix.js";import{history as $,defaultKeymap as O,historyKeymap as T}from"./codemirror_commands-DDxffOmd.js";import{a as z,b as B,d as j,e as _}from"./index-S1Do43bx.js";function V(){var e=arguments[0];"string"==typeof e&&(e=document.createElement(e));var t=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var s in i)if(Object.prototype.hasOwnProperty.call(i,s)){var n=i[s];"string"==typeof n?e.setAttribute(s,n):null!=n&&(e[s]=n)}t++}for(;t<arguments.length;t++)H(e,arguments[t]);return e}function H(e,t){if("string"==typeof t)e.appendChild(document.createTextNode(t));else if(null==t);else if(null!=t.nodeType)e.appendChild(t);else{if(!Array.isArray(t))throw new RangeError("Unsupported child node: "+t);for(var i=0;i<t.length;i++)H(e,t[i])}}const N="function"==typeof String.prototype.normalize?e=>e.normalize("NFKD"):e=>e;class U{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(N(e)):N,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 v(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=x(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=b(e);let s=this.normalize(t);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&&(U.prototype[Symbol.iterator]=function(){return this});const K={from:-1,to:-1,match:/.*/.exec("")},Q="gm"+(null==/x/.unicode?"":"u");class G{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 J(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=X(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=X(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 Y=new WeakMap;class Z{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let s=Y.get(e);if(!s||s.from>=i||s.to<=t){let s=new Z(t,e.sliceString(t,i));return Y.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)),Y.set(e,new Z(o,n)),new Z(t,n.slice(t-o,i-o))}}class J{constructor(e,t,i,s,n){this.text=e,this.to=n,this.done=!1,this.value=K,this.matchPos=X(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=Z.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=X(this.text,i+(e==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Z.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function X(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 ee(e){let t=V("input",{class:"cm-textfield",name:"line",value:String(e.state.doc.lineAt(e.state.selection.main.head).number)});function s(){let s=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(t.value);if(!s)return;let{state:n}=e,o=n.doc.lineAt(n.selection.main.head),[,r,a,l,c]=s,h=l?+l.slice(1):0,d=a?+a:o.number;if(a&&c){let e=d/100;r&&(e=e*("-"==r?-1:1)+o.number/n.doc.lines),d=Math.round(n.doc.lines*e)}else a&&r&&(d=d*("-"==r?-1:1)+o.number);let u=n.doc.line(Math.max(1,Math.min(n.doc.lines,d))),f=M.cursor(u.from+Math.max(0,Math.min(h,u.length)));e.dispatch({effects:[te.of(!1),i.scrollIntoView(f.from,{y:"center"})],selection:f}),e.focus()}return{dom:V("form",{class:"cm-gotoLine",onkeydown:t=>{27==t.keyCode?(t.preventDefault(),e.dispatch({effects:te.of(!1)}),e.focus()):13==t.keyCode&&(t.preventDefault(),s())},onsubmit:e=>{e.preventDefault(),s()}},V("label",e.state.phrase("Go to line"),": ",t)," ",V("button",{class:"cm-button",type:"submit"},e.state.phrase("go")))}}"undefined"!=typeof Symbol&&(G.prototype[Symbol.iterator]=J.prototype[Symbol.iterator]=function(){return this});const te=w.define(),ie=A.define({create:()=>!0,update(e,t){for(let i of t.effects)i.is(te)&&(e=i.value);return e},provide:e=>n.from(e,(e=>e?ee:null))}),se=i.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),ne={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},oe=y.define({combine:e=>k(e,ne,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})});const re=t.mark({class:"cm-selectionMatch"}),ae=t.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function le(e,t,i,s){return!(0!=i&&e(t.sliceDoc(i-1,i))==S.Word||s!=t.doc.length&&e(t.sliceDoc(s,s+1))==S.Word)}const ce=e.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 i=e.state.facet(oe),{state:s}=e,n=s.selection;if(n.ranges.length>1)return t.none;let o,r=n.main,a=null;if(r.empty){if(!i.highlightWordAroundCursor)return t.none;let e=s.wordAt(r.head);if(!e)return t.none;a=s.charCategorizer(r.head),o=s.sliceDoc(e.from,e.to)}else{let e=r.to-r.from;if(e<i.minSelectionLength||e>200)return t.none;if(i.wholeWords){if(o=s.sliceDoc(r.from,r.to),a=s.charCategorizer(r.head),!le(a,s,r.from,r.to)||!function(e,t,i,s){return e(t.sliceDoc(i,i+1))==S.Word&&e(t.sliceDoc(s-1,s))==S.Word}(a,s,r.from,r.to))return t.none}else if(o=s.sliceDoc(r.from,r.to),!o)return t.none}let l=[];for(let n of e.visibleRanges){let e=new U(s.doc,o,n.from,n.to);for(;!e.next().done;){let{from:n,to:o}=e.value;if((!a||le(a,s,n,o))&&(r.empty&&n<=r.from&&o>=r.to?l.push(ae.range(n,o)):(n>=r.to||o<=r.from)&&l.push(re.range(n,o)),l.length>i.maxMatches))return t.none}}return t.set(l)}},{decorations:e=>e.decorations}),he=i.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const de=y.define({combine:e=>k(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Be(e),scrollToMatch:e=>i.scrollIntoView(e)})});class ue{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 be(this):new pe(this)}getCursor(e,t=0,i){let s=e.doc?e:L.create({doc:e});return null==i&&(i=s.doc.length),this.regexp?ge(this,s,t,i):me(this,s,t,i)}}class fe{constructor(e){this.spec=e}}function me(e,t,i,s){return new U(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(ve(i,e-s))==S.Word&&o(xe(i,e-s))==S.Word||o(xe(i,t-s))==S.Word&&o(ve(i,t-s))==S.Word))):void 0);var n,o}class pe extends fe{constructor(e){super(e)}nextMatch(e,t,i){let s=me(this.spec,e,i,e.doc.length).nextOverlapping();return s.done&&(s=me(this.spec,e,0,t).nextOverlapping()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=i;;){let i=Math.max(t,s-1e4-this.spec.unquoted.length),n=me(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){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=me(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=me(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 ge(e,t,i,s){return new G(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:e.wholeWord?(n=t.charCategorizer(t.selection.main.head),(e,t,i)=>!i[0].length||(n(ve(i.input,i.index))!=S.Word||n(xe(i.input,i.index))!=S.Word)&&(n(xe(i.input,i.index+i[0].length))!=S.Word||n(ve(i.input,i.index+i[0].length))!=S.Word)):void 0},i,s);var n}function ve(e,t){return e.slice(q(e,t,!1),t)}function xe(e,t){return e.slice(t,q(e,t))}class be extends fe{nextMatch(e,t,i){let s=ge(this.spec,e,i,e.doc.length).next();return s.done&&(s=ge(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=ge(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)=>"$"==i?"$":"&"==i?e.match[0]:"0"!=i&&+i<e.match.length?e.match[i]:t))}matchAll(e,t){let i=ge(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=ge(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 we=w.define(),ye=w.define(),ke=A.define({create:e=>new Se(Pe(e).create(),null),update(e,t){for(let i of t.effects)i.is(we)?e=new Se(i.value.create(),e.panel):i.is(ye)&&(e=new Se(e.query,i.value?Ie:null));return e},provide:e=>n.from(e,(e=>e.panel))});class Se{constructor(e,t){this.query=e,this.panel=t}}const Me=t.mark({class:"cm-searchMatch"}),Ce=t.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Ae=e.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:i}){if(!i||!e.spec.valid)return t.none;let{view:s}=this,n=new R;for(let t=0,i=s.visibleRanges,o=i.length;t<o;t++){let{from:r,to:a}=i[t];for(;t<o-1&&a>i[t+1].from-500;)a=i[++t].to;e.highlight(s.state,r,a,((e,t)=>{let i=s.state.selection.ranges.some((i=>i.from==e&&i.to==t));n.add(e,t,i?Ce: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):Oe(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=M.single(s.from,s.to),o=e.state.facet(de);return e.dispatch({selection:n,effects:[He(e,s),o.scrollToMatch(n.main,e)],userEvent:"select.search"}),$e(e),!0})),Re=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=M.single(n.from,n.to),r=e.state.facet(de);return e.dispatch({selection:o,effects:[He(e,n),r.scrollToMatch(o.main,e)],userEvent:"select.search"}),$e(e),!0})),De=Le(((e,{query:t})=>{let i=t.matchAll(e.state,1e3);return!(!i||!i.length)&&(e.dispatch({selection:M.create(i.map((e=>M.range(e.from,e.to)))),userEvent:"select.search.matches"}),!0)})),We=Le(((e,{query:t})=>{let{state:s}=e,{from:n,to:o}=s.selection.main;if(s.readOnly)return!1;let r=t.nextMatch(s,n,n);if(!r)return!1;let a,l,c=[],h=[];if(r.from==n&&r.to==o&&(l=s.toText(t.getReplacement(r)),c.push({from:r.from,to:r.to,insert:l}),r=t.nextMatch(s,r.from,r.to),h.push(i.announce.of(s.phrase("replaced match on line $",s.doc.lineAt(n).number)+"."))),r){let t=0==c.length||c[0].from>=r.to?0:r.to-r.from-l.length;a=M.single(r.from-t,r.to-t),h.push(He(e,r)),h.push(s.facet(de).scrollToMatch(a.main,e))}return e.dispatch({changes:c,selection:a,effects:h,userEvent:"input.replace"}),!0})),Fe=Le(((e,{query:t})=>{if(e.state.readOnly)return!1;let s=t.matchAll(e.state,1e9).map((e=>{let{from:i,to:s}=e;return{from:i,to:s,insert:t.getReplacement(e)}}));if(!s.length)return!1;let n=e.state.phrase("replaced $ matches",s.length)+".";return e.dispatch({changes:s,effects:i.announce.of(n),userEvent:"input.replace.all"}),!0}));function Ie(e){return e.state.facet(de).createPanel(e)}function Pe(e,t){var i,s,n,o,r;let a=e.selection.main,l=a.empty||a.to>a.from+100?"":e.sliceDoc(a.from,a.to);if(t&&!l)return t;let c=e.facet(de);return new ue({search:(null!==(i=null==t?void 0:t.literal)&&void 0!==i?i:c.literal)?l:l.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 Ee(e){let t=s(e,Ie);return t&&t.dom.querySelector("[main-field]")}function $e(e){let t=Ee(e);t&&t==e.root.activeElement&&t.select()}const Oe=e=>{let t=e.state.field(ke,!1);if(t&&t.panel){let i=Ee(e);if(i&&i!=e.root.activeElement){let s=Pe(e.state,t.query.spec);s.valid&&e.dispatch({effects:we.of(s)}),i.focus(),i.select()}}else e.dispatch({effects:[ye.of(!0),t?we.of(Pe(e.state,t.query.spec)):w.appendConfig.of(Ue)]});return!0},Te=e=>{let t=e.state.field(ke,!1);if(!t||!t.panel)return!1;let i=s(e,Ie);return i&&i.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:ye.of(!1)}),!0},ze=[{key:"Mod-f",run:Oe,scope:"editor search-panel"},{key:"F3",run:qe,shift:Re,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:qe,shift:Re,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Te,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 U(e.doc,e.sliceDoc(s,n));!t.next().done;){if(o.length>1e3)return!1;t.value.from==s&&(r=o.length),o.push(M.range(t.value.from,t.value.to))}return t(e.update({selection:M.create(o,r),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:e=>{let t=s(e,ee);if(!t){let i=[te.of(!0)];null==e.state.field(ie,!1)&&i.push(w.appendConfig.of([ie,se])),e.dispatch({effects:i}),t=s(e,ee)}return t&&t.dom.querySelector("input").select(),!0}},{key:"Mod-d",run:({state:e,dispatch:t})=>{let{ranges:s}=e.selection;if(s.some((e=>e.from===e.to)))return(({state:e,dispatch:t})=>{let{selection:i}=e,s=M.create(i.ranges.map((t=>e.wordAt(t.head)||M.cursor(t.head))),i.mainIndex);return!s.eq(i)&&(t(e.update({selection:s})),!0)})({state:e,dispatch:t});let n=e.sliceDoc(s[0].from,s[0].to);if(e.selection.ranges.some((t=>e.sliceDoc(t.from,t.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 U(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 U(e.doc,t,0,Math.max(0,s[s.length-1].from-1)),i=!0}}(e,n);return!!o&&(t(e.update({selection:e.selection.addRange(M.range(o.from,o.to),!1),effects:i.scrollIntoView(o.to)})),!0)},preventDefault:!0}];class Be{constructor(e){this.view=e;let t=this.query=e.state.field(ke).query.spec;function i(e,t,i){return V("button",{class:"cm-button",name:e,onclick:t,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=V("input",{value:t.search,placeholder:je(e,"Find"),"aria-label":je(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=V("input",{value:t.replace,placeholder:je(e,"Replace"),"aria-label":je(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=V("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=V("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=V("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit}),this.dom=V("div",{onkeydown:e=>this.keydown(e),class:"cm-search"},[this.searchField,i("next",(()=>qe(e)),[je(e,"next")]),i("prev",(()=>Re(e)),[je(e,"previous")]),i("select",(()=>De(e)),[je(e,"all")]),V("label",null,[this.caseField,je(e,"match case")]),V("label",null,[this.reField,je(e,"regexp")]),V("label",null,[this.wordField,je(e,"by word")]),...e.state.readOnly?[]:[V("br"),this.replaceField,i("replace",(()=>We(e)),[je(e,"replace")]),i("replaceAll",(()=>Fe(e)),[je(e,"replace all")])],V("button",{name:"close",onclick:()=>Te(e),"aria-label":je(e,"close"),type:"button"},["×"])])}commit(){let e=new ue({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:we.of(e)}))}keydown(e){o(this.view,e,"search-panel")?e.preventDefault():13==e.keyCode&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Re:qe)(this.view)):13==e.keyCode&&e.target==this.replaceField&&(e.preventDefault(),We(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(we)&&!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(de).top}}function je(e,t){return e.state.phrase(t)}const _e=30,Ve=/[\s\.,:;?!]/;function He(e,{from:t,to:s}){let n=e.state.doc.lineAt(t),o=e.state.doc.lineAt(s).to,r=Math.max(n.from,t-_e),a=Math.min(o,s+_e),l=e.state.sliceDoc(r,a);if(r!=n.from)for(let e=0;e<_e;e++)if(!Ve.test(l[e+1])&&Ve.test(l[e])){l=l.slice(e);break}if(a!=o)for(let e=l.length-1;e>l.length-_e;e--)if(!Ve.test(l[e-1])&&Ve.test(l[e])){l=l.slice(0,e);break}return i.announce.of(`${e.state.phrase("current match")}. ${l} ${e.state.phrase("on line")} ${n.number}.`)}const Ne=i.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"}}),Ue=[ke,C.low(Ae),Ne];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,i,s){let n=e,o=s.facet(ot).markerFilter;o&&(n=o(n,s));let r=t.set(n.map((e=>e.from==e.to||e.from==e.to-1&&s.doc.lineAt(e.from).to==e.from?t.widget({widget:new lt(e),diagnostic:e}).range(e.from):t.mark({attributes:{class:"cm-lintRange cm-lintRange-"+e.severity+(e.markClass?" "+e.markClass:"")},diagnostic:e}).range(e.from,e.to))),!0);return new Qe(r,i,Ge(r))}}function Ge(e,t=null,i=0){let s=null;return e.between(i,1e9,((e,i,{spec:n})=>{if(!t||n.diagnostic==t)return s=new Ke(e,i,n.diagnostic),!1})),s}const Ye=w.define(),Ze=w.define(),Je=w.define(),Xe=A.define({create:()=>new Qe(t.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=Ge(i,e.selected.diagnostic,n)||Ge(i,null,n)}!i.size&&n&&t.state.facet(ot).autoPanel&&(n=null),e=new Qe(i,n,s)}for(let i of t.effects)if(i.is(Ye)){let s=t.state.facet(ot).autoPanel?i.value.length?ht.open:null:e.panel;e=Qe.init(i.value,s,t.state)}else i.is(Ze)?e=new Qe(e.diagnostics,i.value?ht.open:null,e.selected):i.is(Je)&&(e=new Qe(e.diagnostics,e.panel,i.value));return e},provide:e=>[n.from(e,(e=>e.panel)),i.decorations.from(e,(e=>e.diagnostics))]}),et=t.mark({class:"cm-lintRange cm-lintRange-active"});function tt(e,t,i){let{diagnostics:s}=e.state.field(Xe),n=[],o=2e8,r=0;s.between(t-(i<0?1:0),t+(i>0?1:0),((e,s,{spec:a})=>{t>=e&&t<=s&&(e==s||(t>e||i>0)&&(t<s||i<0))&&(n.push(a.diagnostic),o=Math.min(e,o),r=Math.max(s,r))}));let a=e.state.facet(ot).tooltipFilter;return a&&(n=a(n,e.state)),n.length?{pos:o,end:r,above:e.state.doc.lineAt(o).to<r,create:()=>({dom:it(e,n)})}:null}function it(e,t){return V("ul",{class:"cm-tooltip-lint"},t.map((t=>at(e,t,!1))))}const st=e=>{let t=e.state.field(Xe,!1);return!(!t||!t.panel)&&(e.dispatch({effects:Ze.of(!1)}),!0)},nt=[{key:"Mod-Shift-m",run:e=>{let t=e.state.field(Xe,!1);var i,n;t&&t.panel||e.dispatch({effects:(i=e.state,n=[Ze.of(!0)],i.field(Xe,!1)?n:n.concat(w.appendConfig.of(ft)))});let o=s(e,ht.open);return o&&o.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:e=>{let t=e.state.field(Xe,!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)}}],ot=y.define({combine:e=>Object.assign({sources:e.map((e=>e.source)).filter((e=>null!=e))},k(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 rt(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 at(e,t,i){var s;let n=i?rt(t.actions):[];return V("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},V("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 o=!1,r=s=>{if(s.preventDefault(),o)return;o=!0;let n=Ge(e.state.field(Xe).diagnostics,t);n&&i.apply(e,n.from,n.to)},{name:a}=i,l=n[s]?a.indexOf(n[s]):-1,c=l<0?a:[a.slice(0,l),V("u",a.slice(l,l+1)),a.slice(l+1)];return V("button",{type:"button",class:"cm-diagnosticAction",onclick:r,onmousedown:r,"aria-label":` Action: ${a}${l<0?"":` (access key "${n[s]})"`}.`},c)})),t.source&&V("div",{class:"cm-diagnosticSource"},t.source))}class lt extends a{constructor(e){super(),this.diagnostic=e}eq(e){return e.diagnostic==this.diagnostic}toDOM(){return V("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class ct{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=at(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class ht{constructor(e){this.view=e,this.items=[];this.list=V("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t=>{if(27==t.keyCode)st(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=rt(i.actions);for(let n=0;n<s.length;n++)if(s[n].toUpperCase().charCodeAt(0)==t.keyCode){let t=Ge(this.view.state.field(Xe).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=V("div",{class:"cm-panel-lint"},this.list,V("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>st(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Xe).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(Xe),i=0,s=!1,n=null;for(e.between(0,this.view.state.doc.length,((e,o,{spec:r})=>{let a,l=-1;for(let e=i;e<this.items.length;e++)if(this.items[e].diagnostic==r.diagnostic){l=e;break}l<0?(a=new ct(this.view,r.diagnostic),this.items.splice(i,0,a),s=!0):(a=this.items[l],l>i&&(this.items.splice(i,l-i),s=!0)),t&&a.diagnostic==t.diagnostic?a.dom.hasAttribute("aria-selected")||(a.dom.setAttribute("aria-selected","true"),n=a):a.dom.hasAttribute("aria-selected")&&a.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 ct(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=Ge(this.view.state.field(Xe).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:Je.of(t)})}static open(e){return new ht(e)}}function dt(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 ut=i.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:dt("#d11")},".cm-lintRange-warning":{backgroundImage:dt("orange")},".cm-lintRange-info":{backgroundImage:dt("#999")},".cm-lintRange-hint":{backgroundImage:dt("#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}}}),ft=[Xe,i.decorations.compute([Xe],(e=>{let{selected:i,panel:s}=e.field(Xe);return i&&s&&i.from!=i.to?t.set([et.range(i.from,i.to)]):t.none})),r(tt,{hideOn:function(e,t){let i=t.pos,s=t.end||i,n=e.state.facet(ot).hideOn(e,i,s);if(null!=n)return n;let o=e.startState.doc.lineAt(t.pos);return!(!e.effects.some((e=>e.is(Ye)))&&!e.changes.touchesRange(o.from,Math.max(o.to,s)))}}),ut],mt=(()=>[l(),c(),h(),$(),D(),d(),u(),L.allowMultipleSelections.of(!0),W(),F(I,{fallback:!0}),P(),z(),B(),f(),m(),p(),[he,ce],g.of([...j,...O,...ze,...T,...E,..._,...nt])])(),pt=(()=>[h(),$(),d(),F(I,{fallback:!0}),g.of([...O,...T])])();export{i as EditorView,mt as basicSetup,pt as minimalSetup};
|
2
|
-
//# sourceMappingURL=codemirror-
|
1
|
+
import{V as e,a as t,E as i,b as s,c as n,r as o,h as r,W as a,d as l,e as c,f as h,i as d,j as u,m as f,n as m,o as p,k as g}from"./codemirror_view-aIuSN42d.js";import{codePointAt as v,fromCodePoint as x,codePointSize as b,StateEffect as w,Facet as y,combineConfig as k,CharCategory as S,EditorSelection as M,Prec as C,StateField as A,EditorState as L,findClusterBreak as q,RangeSetBuilder as R}from"./codemirror_state-1d1uncXx.js";import{k as D,l as W,m as F,n as I,o as P,p as E}from"./codemirror_language-DYjIHGr8.js";import{history as $,defaultKeymap as O,historyKeymap as T}from"./codemirror_commands-DSm3EjIb.js";import{a as z,b as B,d as j,e as _}from"./index-Bvz7aU6f.js";function V(){var e=arguments[0];"string"==typeof e&&(e=document.createElement(e));var t=1,i=arguments[1];if(i&&"object"==typeof i&&null==i.nodeType&&!Array.isArray(i)){for(var s in i)if(Object.prototype.hasOwnProperty.call(i,s)){var n=i[s];"string"==typeof n?e.setAttribute(s,n):null!=n&&(e[s]=n)}t++}for(;t<arguments.length;t++)H(e,arguments[t]);return e}function H(e,t){if("string"==typeof t)e.appendChild(document.createTextNode(t));else if(null==t);else if(null!=t.nodeType)e.appendChild(t);else{if(!Array.isArray(t))throw new RangeError("Unsupported child node: "+t);for(var i=0;i<t.length;i++)H(e,t[i])}}const N="function"==typeof String.prototype.normalize?e=>e.normalize("NFKD"):e=>e;class U{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(N(e)):N,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 v(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=x(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=b(e);let s=this.normalize(t);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&&(U.prototype[Symbol.iterator]=function(){return this});const K={from:-1,to:-1,match:/.*/.exec("")},Q="gm"+(null==/x/.unicode?"":"u");class G{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 J(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=X(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=X(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 Y=new WeakMap;class Z{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let s=Y.get(e);if(!s||s.from>=i||s.to<=t){let s=new Z(t,e.sliceString(t,i));return Y.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)),Y.set(e,new Z(o,n)),new Z(t,n.slice(t-o,i-o))}}class J{constructor(e,t,i,s,n){this.text=e,this.to=n,this.done=!1,this.value=K,this.matchPos=X(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=Z.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=X(this.text,i+(e==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Z.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+2*this.flat.text.length))}}}function X(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 ee(e){let t=V("input",{class:"cm-textfield",name:"line",value:String(e.state.doc.lineAt(e.state.selection.main.head).number)});function s(){let s=/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(t.value);if(!s)return;let{state:n}=e,o=n.doc.lineAt(n.selection.main.head),[,r,a,l,c]=s,h=l?+l.slice(1):0,d=a?+a:o.number;if(a&&c){let e=d/100;r&&(e=e*("-"==r?-1:1)+o.number/n.doc.lines),d=Math.round(n.doc.lines*e)}else a&&r&&(d=d*("-"==r?-1:1)+o.number);let u=n.doc.line(Math.max(1,Math.min(n.doc.lines,d))),f=M.cursor(u.from+Math.max(0,Math.min(h,u.length)));e.dispatch({effects:[te.of(!1),i.scrollIntoView(f.from,{y:"center"})],selection:f}),e.focus()}return{dom:V("form",{class:"cm-gotoLine",onkeydown:t=>{27==t.keyCode?(t.preventDefault(),e.dispatch({effects:te.of(!1)}),e.focus()):13==t.keyCode&&(t.preventDefault(),s())},onsubmit:e=>{e.preventDefault(),s()}},V("label",e.state.phrase("Go to line"),": ",t)," ",V("button",{class:"cm-button",type:"submit"},e.state.phrase("go")))}}"undefined"!=typeof Symbol&&(G.prototype[Symbol.iterator]=J.prototype[Symbol.iterator]=function(){return this});const te=w.define(),ie=A.define({create:()=>!0,update(e,t){for(let i of t.effects)i.is(te)&&(e=i.value);return e},provide:e=>n.from(e,(e=>e?ee:null))}),se=i.baseTheme({".cm-panel.cm-gotoLine":{padding:"2px 6px 4px","& label":{fontSize:"80%"}}}),ne={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},oe=y.define({combine:e=>k(e,ne,{highlightWordAroundCursor:(e,t)=>e||t,minSelectionLength:Math.min,maxMatches:Math.min})});const re=t.mark({class:"cm-selectionMatch"}),ae=t.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function le(e,t,i,s){return!(0!=i&&e(t.sliceDoc(i-1,i))==S.Word||s!=t.doc.length&&e(t.sliceDoc(s,s+1))==S.Word)}const ce=e.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 i=e.state.facet(oe),{state:s}=e,n=s.selection;if(n.ranges.length>1)return t.none;let o,r=n.main,a=null;if(r.empty){if(!i.highlightWordAroundCursor)return t.none;let e=s.wordAt(r.head);if(!e)return t.none;a=s.charCategorizer(r.head),o=s.sliceDoc(e.from,e.to)}else{let e=r.to-r.from;if(e<i.minSelectionLength||e>200)return t.none;if(i.wholeWords){if(o=s.sliceDoc(r.from,r.to),a=s.charCategorizer(r.head),!le(a,s,r.from,r.to)||!function(e,t,i,s){return e(t.sliceDoc(i,i+1))==S.Word&&e(t.sliceDoc(s-1,s))==S.Word}(a,s,r.from,r.to))return t.none}else if(o=s.sliceDoc(r.from,r.to),!o)return t.none}let l=[];for(let n of e.visibleRanges){let e=new U(s.doc,o,n.from,n.to);for(;!e.next().done;){let{from:n,to:o}=e.value;if((!a||le(a,s,n,o))&&(r.empty&&n<=r.from&&o>=r.to?l.push(ae.range(n,o)):(n>=r.to||o<=r.from)&&l.push(re.range(n,o)),l.length>i.maxMatches))return t.none}}return t.set(l)}},{decorations:e=>e.decorations}),he=i.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}});const de=y.define({combine:e=>k(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new Be(e),scrollToMatch:e=>i.scrollIntoView(e)})});class ue{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 be(this):new pe(this)}getCursor(e,t=0,i){let s=e.doc?e:L.create({doc:e});return null==i&&(i=s.doc.length),this.regexp?ge(this,s,t,i):me(this,s,t,i)}}class fe{constructor(e){this.spec=e}}function me(e,t,i,s){return new U(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(ve(i,e-s))==S.Word&&o(xe(i,e-s))==S.Word||o(xe(i,t-s))==S.Word&&o(ve(i,t-s))==S.Word))):void 0);var n,o}class pe extends fe{constructor(e){super(e)}nextMatch(e,t,i){let s=me(this.spec,e,i,e.doc.length).nextOverlapping();return s.done&&(s=me(this.spec,e,0,t).nextOverlapping()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=i;;){let i=Math.max(t,s-1e4-this.spec.unquoted.length),n=me(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){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=me(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=me(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 ge(e,t,i,s){return new G(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:e.wholeWord?(n=t.charCategorizer(t.selection.main.head),(e,t,i)=>!i[0].length||(n(ve(i.input,i.index))!=S.Word||n(xe(i.input,i.index))!=S.Word)&&(n(xe(i.input,i.index+i[0].length))!=S.Word||n(ve(i.input,i.index+i[0].length))!=S.Word)):void 0},i,s);var n}function ve(e,t){return e.slice(q(e,t,!1),t)}function xe(e,t){return e.slice(t,q(e,t))}class be extends fe{nextMatch(e,t,i){let s=ge(this.spec,e,i,e.doc.length).next();return s.done&&(s=ge(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=ge(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)=>"$"==i?"$":"&"==i?e.match[0]:"0"!=i&&+i<e.match.length?e.match[i]:t))}matchAll(e,t){let i=ge(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=ge(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 we=w.define(),ye=w.define(),ke=A.define({create:e=>new Se(Pe(e).create(),null),update(e,t){for(let i of t.effects)i.is(we)?e=new Se(i.value.create(),e.panel):i.is(ye)&&(e=new Se(e.query,i.value?Ie:null));return e},provide:e=>n.from(e,(e=>e.panel))});class Se{constructor(e,t){this.query=e,this.panel=t}}const Me=t.mark({class:"cm-searchMatch"}),Ce=t.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Ae=e.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:i}){if(!i||!e.spec.valid)return t.none;let{view:s}=this,n=new R;for(let t=0,i=s.visibleRanges,o=i.length;t<o;t++){let{from:r,to:a}=i[t];for(;t<o-1&&a>i[t+1].from-500;)a=i[++t].to;e.highlight(s.state,r,a,((e,t)=>{let i=s.state.selection.ranges.some((i=>i.from==e&&i.to==t));n.add(e,t,i?Ce: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):Oe(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=M.single(s.from,s.to),o=e.state.facet(de);return e.dispatch({selection:n,effects:[He(e,s),o.scrollToMatch(n.main,e)],userEvent:"select.search"}),$e(e),!0})),Re=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=M.single(n.from,n.to),r=e.state.facet(de);return e.dispatch({selection:o,effects:[He(e,n),r.scrollToMatch(o.main,e)],userEvent:"select.search"}),$e(e),!0})),De=Le(((e,{query:t})=>{let i=t.matchAll(e.state,1e3);return!(!i||!i.length)&&(e.dispatch({selection:M.create(i.map((e=>M.range(e.from,e.to)))),userEvent:"select.search.matches"}),!0)})),We=Le(((e,{query:t})=>{let{state:s}=e,{from:n,to:o}=s.selection.main;if(s.readOnly)return!1;let r=t.nextMatch(s,n,n);if(!r)return!1;let a,l,c=[],h=[];if(r.from==n&&r.to==o&&(l=s.toText(t.getReplacement(r)),c.push({from:r.from,to:r.to,insert:l}),r=t.nextMatch(s,r.from,r.to),h.push(i.announce.of(s.phrase("replaced match on line $",s.doc.lineAt(n).number)+"."))),r){let t=0==c.length||c[0].from>=r.to?0:r.to-r.from-l.length;a=M.single(r.from-t,r.to-t),h.push(He(e,r)),h.push(s.facet(de).scrollToMatch(a.main,e))}return e.dispatch({changes:c,selection:a,effects:h,userEvent:"input.replace"}),!0})),Fe=Le(((e,{query:t})=>{if(e.state.readOnly)return!1;let s=t.matchAll(e.state,1e9).map((e=>{let{from:i,to:s}=e;return{from:i,to:s,insert:t.getReplacement(e)}}));if(!s.length)return!1;let n=e.state.phrase("replaced $ matches",s.length)+".";return e.dispatch({changes:s,effects:i.announce.of(n),userEvent:"input.replace.all"}),!0}));function Ie(e){return e.state.facet(de).createPanel(e)}function Pe(e,t){var i,s,n,o,r;let a=e.selection.main,l=a.empty||a.to>a.from+100?"":e.sliceDoc(a.from,a.to);if(t&&!l)return t;let c=e.facet(de);return new ue({search:(null!==(i=null==t?void 0:t.literal)&&void 0!==i?i:c.literal)?l:l.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 Ee(e){let t=s(e,Ie);return t&&t.dom.querySelector("[main-field]")}function $e(e){let t=Ee(e);t&&t==e.root.activeElement&&t.select()}const Oe=e=>{let t=e.state.field(ke,!1);if(t&&t.panel){let i=Ee(e);if(i&&i!=e.root.activeElement){let s=Pe(e.state,t.query.spec);s.valid&&e.dispatch({effects:we.of(s)}),i.focus(),i.select()}}else e.dispatch({effects:[ye.of(!0),t?we.of(Pe(e.state,t.query.spec)):w.appendConfig.of(Ue)]});return!0},Te=e=>{let t=e.state.field(ke,!1);if(!t||!t.panel)return!1;let i=s(e,Ie);return i&&i.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:ye.of(!1)}),!0},ze=[{key:"Mod-f",run:Oe,scope:"editor search-panel"},{key:"F3",run:qe,shift:Re,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:qe,shift:Re,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:Te,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 U(e.doc,e.sliceDoc(s,n));!t.next().done;){if(o.length>1e3)return!1;t.value.from==s&&(r=o.length),o.push(M.range(t.value.from,t.value.to))}return t(e.update({selection:M.create(o,r),userEvent:"select.search.matches"})),!0}},{key:"Mod-Alt-g",run:e=>{let t=s(e,ee);if(!t){let i=[te.of(!0)];null==e.state.field(ie,!1)&&i.push(w.appendConfig.of([ie,se])),e.dispatch({effects:i}),t=s(e,ee)}return t&&t.dom.querySelector("input").select(),!0}},{key:"Mod-d",run:({state:e,dispatch:t})=>{let{ranges:s}=e.selection;if(s.some((e=>e.from===e.to)))return(({state:e,dispatch:t})=>{let{selection:i}=e,s=M.create(i.ranges.map((t=>e.wordAt(t.head)||M.cursor(t.head))),i.mainIndex);return!s.eq(i)&&(t(e.update({selection:s})),!0)})({state:e,dispatch:t});let n=e.sliceDoc(s[0].from,s[0].to);if(e.selection.ranges.some((t=>e.sliceDoc(t.from,t.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 U(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 U(e.doc,t,0,Math.max(0,s[s.length-1].from-1)),i=!0}}(e,n);return!!o&&(t(e.update({selection:e.selection.addRange(M.range(o.from,o.to),!1),effects:i.scrollIntoView(o.to)})),!0)},preventDefault:!0}];class Be{constructor(e){this.view=e;let t=this.query=e.state.field(ke).query.spec;function i(e,t,i){return V("button",{class:"cm-button",name:e,onclick:t,type:"button"},i)}this.commit=this.commit.bind(this),this.searchField=V("input",{value:t.search,placeholder:je(e,"Find"),"aria-label":je(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=V("input",{value:t.replace,placeholder:je(e,"Replace"),"aria-label":je(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=V("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=V("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=V("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit}),this.dom=V("div",{onkeydown:e=>this.keydown(e),class:"cm-search"},[this.searchField,i("next",(()=>qe(e)),[je(e,"next")]),i("prev",(()=>Re(e)),[je(e,"previous")]),i("select",(()=>De(e)),[je(e,"all")]),V("label",null,[this.caseField,je(e,"match case")]),V("label",null,[this.reField,je(e,"regexp")]),V("label",null,[this.wordField,je(e,"by word")]),...e.state.readOnly?[]:[V("br"),this.replaceField,i("replace",(()=>We(e)),[je(e,"replace")]),i("replaceAll",(()=>Fe(e)),[je(e,"replace all")])],V("button",{name:"close",onclick:()=>Te(e),"aria-label":je(e,"close"),type:"button"},["×"])])}commit(){let e=new ue({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:we.of(e)}))}keydown(e){o(this.view,e,"search-panel")?e.preventDefault():13==e.keyCode&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?Re:qe)(this.view)):13==e.keyCode&&e.target==this.replaceField&&(e.preventDefault(),We(this.view))}update(e){for(let t of e.transactions)for(let e of t.effects)e.is(we)&&!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(de).top}}function je(e,t){return e.state.phrase(t)}const _e=30,Ve=/[\s\.,:;?!]/;function He(e,{from:t,to:s}){let n=e.state.doc.lineAt(t),o=e.state.doc.lineAt(s).to,r=Math.max(n.from,t-_e),a=Math.min(o,s+_e),l=e.state.sliceDoc(r,a);if(r!=n.from)for(let e=0;e<_e;e++)if(!Ve.test(l[e+1])&&Ve.test(l[e])){l=l.slice(e);break}if(a!=o)for(let e=l.length-1;e>l.length-_e;e--)if(!Ve.test(l[e-1])&&Ve.test(l[e])){l=l.slice(0,e);break}return i.announce.of(`${e.state.phrase("current match")}. ${l} ${e.state.phrase("on line")} ${n.number}.`)}const Ne=i.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"}}),Ue=[ke,C.low(Ae),Ne];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,i,s){let n=e,o=s.facet(ot).markerFilter;o&&(n=o(n,s));let r=t.set(n.map((e=>e.from==e.to||e.from==e.to-1&&s.doc.lineAt(e.from).to==e.from?t.widget({widget:new lt(e),diagnostic:e}).range(e.from):t.mark({attributes:{class:"cm-lintRange cm-lintRange-"+e.severity+(e.markClass?" "+e.markClass:"")},diagnostic:e}).range(e.from,e.to))),!0);return new Qe(r,i,Ge(r))}}function Ge(e,t=null,i=0){let s=null;return e.between(i,1e9,((e,i,{spec:n})=>{if(!t||n.diagnostic==t)return s=new Ke(e,i,n.diagnostic),!1})),s}const Ye=w.define(),Ze=w.define(),Je=w.define(),Xe=A.define({create:()=>new Qe(t.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=Ge(i,e.selected.diagnostic,n)||Ge(i,null,n)}!i.size&&n&&t.state.facet(ot).autoPanel&&(n=null),e=new Qe(i,n,s)}for(let i of t.effects)if(i.is(Ye)){let s=t.state.facet(ot).autoPanel?i.value.length?ht.open:null:e.panel;e=Qe.init(i.value,s,t.state)}else i.is(Ze)?e=new Qe(e.diagnostics,i.value?ht.open:null,e.selected):i.is(Je)&&(e=new Qe(e.diagnostics,e.panel,i.value));return e},provide:e=>[n.from(e,(e=>e.panel)),i.decorations.from(e,(e=>e.diagnostics))]}),et=t.mark({class:"cm-lintRange cm-lintRange-active"});function tt(e,t,i){let{diagnostics:s}=e.state.field(Xe),n=[],o=2e8,r=0;s.between(t-(i<0?1:0),t+(i>0?1:0),((e,s,{spec:a})=>{t>=e&&t<=s&&(e==s||(t>e||i>0)&&(t<s||i<0))&&(n.push(a.diagnostic),o=Math.min(e,o),r=Math.max(s,r))}));let a=e.state.facet(ot).tooltipFilter;return a&&(n=a(n,e.state)),n.length?{pos:o,end:r,above:e.state.doc.lineAt(o).to<r,create:()=>({dom:it(e,n)})}:null}function it(e,t){return V("ul",{class:"cm-tooltip-lint"},t.map((t=>at(e,t,!1))))}const st=e=>{let t=e.state.field(Xe,!1);return!(!t||!t.panel)&&(e.dispatch({effects:Ze.of(!1)}),!0)},nt=[{key:"Mod-Shift-m",run:e=>{let t=e.state.field(Xe,!1);var i,n;t&&t.panel||e.dispatch({effects:(i=e.state,n=[Ze.of(!0)],i.field(Xe,!1)?n:n.concat(w.appendConfig.of(ft)))});let o=s(e,ht.open);return o&&o.dom.querySelector(".cm-panel-lint ul").focus(),!0},preventDefault:!0},{key:"F8",run:e=>{let t=e.state.field(Xe,!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)}}],ot=y.define({combine:e=>Object.assign({sources:e.map((e=>e.source)).filter((e=>null!=e))},k(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 rt(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 at(e,t,i){var s;let n=i?rt(t.actions):[];return V("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},V("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 o=!1,r=s=>{if(s.preventDefault(),o)return;o=!0;let n=Ge(e.state.field(Xe).diagnostics,t);n&&i.apply(e,n.from,n.to)},{name:a}=i,l=n[s]?a.indexOf(n[s]):-1,c=l<0?a:[a.slice(0,l),V("u",a.slice(l,l+1)),a.slice(l+1)];return V("button",{type:"button",class:"cm-diagnosticAction",onclick:r,onmousedown:r,"aria-label":` Action: ${a}${l<0?"":` (access key "${n[s]})"`}.`},c)})),t.source&&V("div",{class:"cm-diagnosticSource"},t.source))}class lt extends a{constructor(e){super(),this.diagnostic=e}eq(e){return e.diagnostic==this.diagnostic}toDOM(){return V("span",{class:"cm-lintPoint cm-lintPoint-"+this.diagnostic.severity})}}class ct{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=at(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class ht{constructor(e){this.view=e,this.items=[];this.list=V("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t=>{if(27==t.keyCode)st(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=rt(i.actions);for(let n=0;n<s.length;n++)if(s[n].toUpperCase().charCodeAt(0)==t.keyCode){let t=Ge(this.view.state.field(Xe).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=V("div",{class:"cm-panel-lint"},this.list,V("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>st(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Xe).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(Xe),i=0,s=!1,n=null;for(e.between(0,this.view.state.doc.length,((e,o,{spec:r})=>{let a,l=-1;for(let e=i;e<this.items.length;e++)if(this.items[e].diagnostic==r.diagnostic){l=e;break}l<0?(a=new ct(this.view,r.diagnostic),this.items.splice(i,0,a),s=!0):(a=this.items[l],l>i&&(this.items.splice(i,l-i),s=!0)),t&&a.diagnostic==t.diagnostic?a.dom.hasAttribute("aria-selected")||(a.dom.setAttribute("aria-selected","true"),n=a):a.dom.hasAttribute("aria-selected")&&a.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 ct(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=Ge(this.view.state.field(Xe).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:Je.of(t)})}static open(e){return new ht(e)}}function dt(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 ut=i.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:dt("#d11")},".cm-lintRange-warning":{backgroundImage:dt("orange")},".cm-lintRange-info":{backgroundImage:dt("#999")},".cm-lintRange-hint":{backgroundImage:dt("#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}}}),ft=[Xe,i.decorations.compute([Xe],(e=>{let{selected:i,panel:s}=e.field(Xe);return i&&s&&i.from!=i.to?t.set([et.range(i.from,i.to)]):t.none})),r(tt,{hideOn:function(e,t){let i=t.pos,s=t.end||i,n=e.state.facet(ot).hideOn(e,i,s);if(null!=n)return n;let o=e.startState.doc.lineAt(t.pos);return!(!e.effects.some((e=>e.is(Ye)))&&!e.changes.touchesRange(o.from,Math.max(o.to,s)))}}),ut],mt=(()=>[l(),c(),h(),$(),D(),d(),u(),L.allowMultipleSelections.of(!0),W(),F(I,{fallback:!0}),P(),z(),B(),f(),m(),p(),[he,ce],g.of([...j,...O,...ze,...T,...E,..._,...nt])])(),pt=(()=>[h(),$(),d(),F(I,{fallback:!0}),g.of([...O,...T])])();export{i as EditorView,mt as basicSetup,pt as minimalSetup};
|
2
|
+
//# sourceMappingURL=codemirror-D-uvNAgN.js.map
|