// 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`
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`
`);
if (this._info === null) {
return html`${fragments}`;
}
if (this._info.error) {
fragments.push(html`
error:
${this._info.error}
`);
return html`${fragments}`;
}
fragments.push(html`
pattern:
${this._info.pattern}
prefix:
${this._info.prefix}
·
_foldcase:
${this._info.prefix_foldcase}
accel_prefix:
${this._info.accel_prefix}
·
_foldcase:
${this._info.accel_prefix_foldcase}
num_captures:
${this._info.num_captures}
is_one_pass:
${this._info.is_one_pass}
can_bit_state:
${this._info.can_bit_state}
bytecode:
${this._info.bytecode}
bytemap:
${this._info.bytemap}
`);
return html`${fragments}`;
}
}
declare global {
interface HTMLElementTagNameMap {
're2-dev': RE2Dev;
}
}