blob: 4b9e7bdd1c0d1d44e7f98360c90b1f9f5a13e2c0 (
plain)
1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Copyright 2022 The RE2 Authors. All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import {css, html, LitElement, render} from 'lit';
import {customElement} from 'lit/decorators.js';
import /*default*/ loadModule from './_re2';
import {Info, MainModule} from './_re2';
var _re2: MainModule;
loadModule().then((module: MainModule) => {
_re2 = module;
render(html`<title>re2-dev</title><re2-dev></re2-dev>`, document.body);
});
@customElement('re2-dev')
export class RE2Dev extends LitElement {
private _pattern: string = '';
private _info: Info|null = null;
constructor() {
super();
this._pattern = decodeURIComponent(window.location.hash.slice(1));
this._info = this._pattern ? _re2.getInfo(this._pattern) : null;
this.requestUpdate();
}
private _onChange = (e: Event) => {
this._pattern = (e.target as HTMLInputElement).value;
this._info = this._pattern ? _re2.getInfo(this._pattern) : null;
this.requestUpdate();
window.location.hash = '#' + encodeURIComponent(this._pattern);
};
static override styles = css`
.code {
font-family: monospace;
white-space: pre-line;
}
`;
override render() {
var fragments = [];
fragments.push(html`
<div>
<input type="text" size="48" @change=${this._onChange} .value=${this._pattern}>
</div>
`);
if (this._info === null) {
return html`${fragments}`;
}
if (this._info.error) {
fragments.push(html`
<br>
<div>
error:
<span class="code">${this._info.error}</span>
</div>
`);
return html`${fragments}`;
}
fragments.push(html`
<br>
<div>
pattern:
<span class="code">${this._info.pattern}</span>
<br>
prefix:
<span class="code">${this._info.prefix}</span>
·
_foldcase:
<span class="code">${this._info.prefix_foldcase}</span>
<br>
accel_prefix:
<span class="code">${this._info.accel_prefix}</span>
·
_foldcase:
<span class="code">${this._info.accel_prefix_foldcase}</span>
<br>
num_captures:
<span class="code">${this._info.num_captures}</span>
<br>
is_one_pass:
<span class="code">${this._info.is_one_pass}</span>
<br>
can_bit_state:
<span class="code">${this._info.can_bit_state}</span>
<br>
<br>
bytecode:
<br>
<span class="code">${this._info.bytecode}</span>
<br>
bytemap:
<br>
<span class="code">${this._info.bytemap}</span>
</div>
`);
return html`${fragments}`;
}
}
declare global {
interface HTMLElementTagNameMap {
're2-dev': RE2Dev;
}
}
|