about summary refs log tree commit diff stats
path: root/subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-03-23 09:15:03 -0700
committerKartik Agaram <vc@akkartik.com>2019-03-23 09:15:03 -0700
commitcc5f4816b5397bf25fe583e6f104a1ee7347132c (patch)
tree160c8a75a269374329a14cf3e39a6a69f10401fa /subx
parent1ae8ec9efa277f9127ac0d693f4700c63218b7ee (diff)
downloadmu-cc5f4816b5397bf25fe583e6f104a1ee7347132c.tar.gz
5019
Diffstat (limited to 'subx')
-rwxr-xr-xsubx/apps/packbin22467 -> 22707 bytes
-rw-r--r--subx/apps/pack.subx83
2 files changed, 80 insertions, 3 deletions
diff --git a/subx/apps/pack b/subx/apps/pack
index fda8cb03..2123672a 100755
--- a/subx/apps/pack
+++ b/subx/apps/pack
Binary files differdiff --git a/subx/apps/pack.subx b/subx/apps/pack.subx
index 28de82c0..44d4c5c8 100644
--- a/subx/apps/pack.subx
+++ b/subx/apps/pack.subx
@@ -23,7 +23,7 @@
 Entry:  # run tests if necessary, convert stdin if not
 
 #?     # for debugging: run a single test
-#?     e8/call test-is-valid-name-starts-with-digit/disp32
+#?     e8/call test-convert-data-passes-names-through/disp32
 #?     8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/EBX   Num-test-failures/disp32          # copy *Num-test-failures to EBX
 #?     eb/jump  $main:end/disp8
 
@@ -484,6 +484,12 @@ convert-data:  # line : (address stream byte), out : (address buffered-file) ->
     #       write-stream-buffered(out, line)
     #     else if slice-ends-with?(word-slice, ":")   # label
     #       write-stream-buffered(out, line)
+    #     else if has-metadata?(word-slice, "imm32")
+    #       emit(out, word-slice, 4)
+    #     else if has-metadata?(word-slice, "disp32")
+    #       emit(out, word-slice, 4)
+    #     else
+    #       emit(out, word-slice, 1)
     #     ...
     #
     # . prolog
@@ -656,6 +662,75 @@ test-convert-data-passes-labels-through:
     5d/pop-to-EBP
     c3/return
 
+test-convert-data-passes-names-through:
+    # If a word is a valid name, just emit it unchanged.
+    # Later phases will deal with it.
+    # . prolog
+    55/push-EBP
+    89/copy                         3/mod/direct    5/rm32/EBP    .           .             .           4/r32/ESP   .               .                 # copy ESP to EBP
+    # setup
+    # . clear-stream(_test-input-stream)
+    # . . push args
+    68/push  _test-input-stream/imm32
+    # . . call
+    e8/call  clear-stream/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # . clear-stream(_test-output-stream)
+    # . . push args
+    68/push  _test-output-stream/imm32
+    # . . call
+    e8/call  clear-stream/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # . clear-stream(_test-output-buffered-file+4)
+    # . . push args
+    b8/copy-to-EAX  _test-output-buffered-file/imm32
+    05/add-to-EAX  4/imm32
+    50/push-EAX
+    # . . call
+    e8/call  clear-stream/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # initialize input
+    # . write(_test-input-stream, "abcd/imm32")
+    # . . push args
+    68/push  "abcd/imm32"/imm32
+    68/push  _test-input-stream/imm32
+    # . . call
+    e8/call  write/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # convert-data(_test-input-stream, _test-output-buffered-file)
+    # . . push args
+    68/push  _test-output-buffered-file/imm32
+    68/push  _test-input-stream/imm32
+    # . . call
+    e8/call  convert-data/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               8/imm32           # add to ESP
+    # check that the write happened as expected
+    # . flush(_test-output-buffered-file)
+    # . . push args
+    68/push  _test-output-buffered-file/imm32
+    # . . call
+    e8/call  flush/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               4/imm32           # add to ESP
+    # . check-stream-equal(_test-output-stream, "abcd/imm32", msg)
+    # . . push args
+    68/push  "F - test-convert-data-passes-names-through"/imm32
+    68/push  "abcd/imm32"/imm32
+    68/push  _test-output-stream/imm32
+    # . . call
+    e8/call  check-stream-equal/disp32
+    # . . discard args
+    81          0/subop/add         3/mod/direct    4/rm32/ESP    .           .             .           .           .               0xc/imm32         # add to ESP
+    # . epilog
+    89/copy                         3/mod/direct    4/rm32/ESP    .           .             .           5/r32/EBP   .               .                 # copy EBP to ESP
+    5d/pop-to-EBP
+    c3/return
+
 # - To pack an instruction, following the C++ version:
 # read first word as opcode and write-slice
 # if 0f or f2 or f3 read second opcode and write-slice
@@ -2250,9 +2325,10 @@ _test-input-stream:
     # current read index
     0/imm32
     # length
-    8/imm32
+    0x10/imm32
     # data
     00 00 00 00 00 00 00 00  # 8 bytes
+    00 00 00 00 00 00 00 00  # 8 bytes
 
 # a test buffered file for _test-input-stream
 _test-input-buffered-file:
@@ -2273,9 +2349,10 @@ _test-output-stream:
     # current read index
     0/imm32
     # length
-    8/imm32
+    0x10/imm32
     # data
     00 00 00 00 00 00 00 00  # 8 bytes
+    00 00 00 00 00 00 00 00  # 8 bytes
 
 # a test buffered file for _test-output-stream
 _test-output-buffered-file:
/a> 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
<!DOCTYPE html>
<html lang="en">
<!--
MIT License

Copyright (c) m15o

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<head>
    <meta charset="utf-8">
    <title>yon</title>
</head>
<style>
    html, body, #app, .column, textarea, table, td {
        height: 100%;
    }

    body {
        padding: 0;
        margin: 0;
        background-color: darkgoldenrod;
    }

    header {
        display: flex;
        border-bottom: 1px solid;
        border-top: 1px solid;
    }

    header > * {
        border-right: 1px solid;
    }

    .column {
        display: flex;
        flex-direction: column;
        min-width: 10px;
    }

    section {
        display: flex;
        flex-direction: column;
    }

    .name {
        box-sizing: border-box;
        width: 100%;
        padding: 2px 5px;
        margin: 0;
        outline: none;
        border: 0;
        border-right: 1px solid;
        background-color: lavender;
    }

    #search {
        display: none;
    }

    #search.searching {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background-color: darkblue;
        color: white;
    }

    textarea {
        box-sizing: border-box;
        padding: 5px;
        margin: 0;
        border: 0;
        outline: none;
        resize: none;
        background-color: bisque;
    }

    .action {
        padding: 2px 5px;
        cursor: pointer;
    }

    .back, .forward {
        background-color: silver;
    }

    .hist {
        background-color: inherit;
    }

    .folded .content {
        display: none;
        flex-shrink: 1;
    }

    section:not(.folded) {
        flex-grow: 1;
    }

    table {
        width: 100%;
        border-collapse: collapse;
    }

    td {
        padding: 0;
        border: 1px solid;
    }

    .menu {
        background-color: azure;
    }

    .menu > * {
        background-color: azure;
        padding: 0 4px;
        cursor: pointer;
    }

    .menu > *:hover {
        background-color: silver;
    }

    .active-p .content {
        background-color: white;
    }

    .active {
        background-color: turquoise;
    }

    .col {
        position: relative;
    }

    .resize:hover {
        background-color: rebeccapurple;
    }

    .resize {
        width: 2px;
        background-color: tan;
        cursor: col-resize;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
    }

    #settings {
        display: none;
    }

    #settings.visible {
        display: table-row;
    }

    .dirty .save {
        background-color: aquamarine;
    }
</style>
<body>
<div id="app"></div>
<script>
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Helpers

    function $(elt) {
        return document.querySelector(elt);
    }

    function $$(elt) {
        return document.querySelectorAll(elt);
    }

    function $$active(elt) {
        return $panel => ($panel && $panel.querySelector(elt)) || $('.active-p ' + elt);
    }

    function $name($panel) {
        return $$active('.name')($panel);
    }

    function $content($panel) {
        return $$active('.content')($panel);
    }

    function t$(e) {
        return e.target;
    }

    function closest$(e, sel) {
        return t$(e).closest(sel);
    }

    function $search() {
        return $('#search');
    }

    function $panel() {
        return $('.active-p');
    }

    function hasCls($elt, cls) {
        return $elt.classList.contains(cls);
    }

    function date() {
        return (new Date()).toLocaleDateString('en-CA');
    }

    function makeElt(elt, cls, attrs, html, value) {
        let e = document.createElement(elt);
        cls.forEach(c => e.classList.add(c));
        Object.keys(attrs).forEach(k => e.setAttribute(k, attrs[k]));
        html && (e.innerHTML = html);
        value && (e.value = value);
        return e;
    }

    function togCls(cls, sel, $elt) {
        $$(sel).forEach((e) => e.classList.remove(cls));
        $elt.classList.add(cls);
    }

    function setActive($section) {
        togCls('active-p', 'section', $section);
    }

    function closeSearch() {
        $search().classList.remove('searching');
        $content().focus();
    }

    function refPane(name) {
        let p;
        $$('section').forEach(e => e.querySelector('.name').value.startsWith('+ref') && (p = e));
        if (!p) {
            p = createPane();
        }
        setActive(p);
        load(name);
        return p;
    }

    function isChordNav(e) {
        return e.metaKey || e.ctrlKey;
    }

    function isChordNavBlank(e) {
        return isChordNav(e) && e.altKey;
    }

    function navBlank(name) {
        createPane();
        load(name);
    }

    function debounce(fn, ms) {
        let timeout;
        return (...args) => {
            clearTimeout(timeout);
            timeout = setTimeout(() => fn(...args), ms);
        }
    }

    function basename(path) {
        const n = path.split('/').pop();
        return n.split('.').shift();
    }

    function download(data, name, mime) {
        const link = document.createElement('a');
        link.download = name;
        link.href = window.URL.createObjectURL(new Blob([data], {type: mime}));
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // storage

    let store = {};

    function storeSet(k, v) {
        if (v === storeGet(k, v)) return;
        $('#app').classList.add('dirty');
        store[k] = v;
    }

    function storeGet(k) {
        return store[k] || '';
    }

    function storeDel(k) {
        delete store[k];
    }

    function storeKeys() {
        return Object.keys(store);
    }

    function storeClear() {
        store = {};
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Core

    function save() {
        let name = $name().value;
        let content = $content().value;
        $panel().dataset['name'] = name;
        if (!name || name[0] === '+') return;
        storeSet(name, content);
        refresh();
    }

    const saveD = debounce(save, 200);

    function updateHistory(name) {
        let cname = $panel().dataset['name'];
        if (!name || name === cname) return;
        hpush(hist().back, cname);
        hist().forward = [];
    }

    function ls(prefix) {
        return storeKeys().filter(k => !prefix || k.startsWith(prefix)).map(k => '[[' + k + ']]').join('\n');
    }

    function load(name, noHist) {
        if (!name) {
            $name().value = '';
            $content().value = '';
            return;
        }
        !noHist && updateHistory(name)
        if (name.startsWith('+ls')) {
            $content().value = ls(name.split(':')[1]);
        } else if (name.startsWith('+ref')) {
            $content().value = ref(name.split(':')[1]);
        } else {
            $content().value = storeGet(name);
        }
        $name().value = name;
        $panel().dataset['name'] = name;
        $panel().querySelector('.back').classList.toggle('hist', !!hist().back.length);
        $panel().querySelector('.forward').classList.toggle('hist', !!hist().forward.length);
    }

    function refresh() {
        const $elt = $('#files');
        $elt.innerHTML = '';
        storeKeys().forEach(k => $elt.appendChild(makeElt('option', [], {}, null, k)));
    }

    let paneID = 0;

    function createHistory(paneID) {
        history[paneID] = {back: [], forward: []};
    }

    function removeHistory(paneID) {
        delete history[paneID];
    }

    function deletePane($pane) {
        removeHistory($pane.dataset['id']);
        $pane.remove();
    }

    function createPane() {
        const header = document.createElement('header');
        header.append(
            makeElt('span', ['back', 'action'], {}, '<'),
            makeElt('span', ['forward', 'action'], {}, '>'),
            makeElt('input', ['name'], {list: 'files', autocomplete: 'off'}),
            makeElt('span', ['fold', 'action'], {}, '-'),
            makeElt('span', ['max', 'action'], {}, '+'),
            makeElt('span', ['move', 'action'], {}, '~'),
            makeElt('span', ['close', 'action'], {}, 'x')
        );
        const id = paneID++;
        const section = document.createElement('section');
        section.setAttribute('data-id', '' + id);
        section.append(
            header,
            makeElt('textarea', ['content'], {spellcheck: false, onkeyup: 'saveD()'})
        )
        createHistory(id);
        $(".column.active").appendChild(section);
        setActive(section);
        $content().focus();
        return section;
    }

    function ref(str) {
        return storeKeys().map(k => {
            const v = storeGet(k);
            const m = v.split('\n').filter(l => l.includes('[[' + str + ']]'));
            if (!m.length) return null;
            return ['[[' + k + ']]', '----------', ...m, ''].join('\n');
        }).filter(Boolean).join('\n');
    }

    function mv(before, after) {
        return storeKeys().forEach(k => {
            const v = storeGet(k);
            storeSet(k, v.replaceAll('[[' + before + ']]', '[[' + after + ']]'))
        })
    }

    function link(textarea) {
        const text = textarea.value;
        const pos = textarea.selectionStart;
        let start, end;

        for (start = pos; start > -1 && text[start] !== '['; start--) {
            if (/\n/.test(text[start]) || text[start] === ']') return null;
        }
        if (start === -1) return null;

        for (end = pos; end < text.length && text[end] !== ']'; end++) {
            if (/\n/.test(text[end]) || text[end] === '[') return null;
        }
        if (end === text.length) return null;

        return text.substring(start + 1, end);
    }

    function insert(textarea, text) {
        const start = textarea.selectionStart;
        const end = textarea.selectionEnd;
        const before = textarea.value.substring(0, start);
        const after = textarea.value.substring(end, textarea.value.length);

        textarea.value = before + text + after;
        textarea.selectionStart = textarea.selectionEnd = start + text.length;
    }

    const history = {};

    function hist() {
        return history[$panel().dataset['id']];
    }

    function hpush(h, name) {
        if (h[h.length - 1] === name) return;
        h.push(name);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Menu

    function menuNew() {
        createPane();
    }

    function menuLog() {
        $name() || createPane();
        load(date());
    }

    function menuLs() {
        load('+ls');
    }

    function menuReset() {
        if (confirm('delete everything?')) {
            storeClear();
        }
    }

    function menuRef() {
        refPane('+ref:' + $name().value);
    }

    function menuMv() {
        let prev = $panel().dataset['name'];
        mv(prev, $name().value);
        save();
        storeDel(prev);
        $prevPanel = $panel();
        $$('section').forEach($pane => {
            setActive($pane);
            load($name().value, false);
        })
        setActive($prevPanel);
        refresh();
    }

    function quine() {
        const regex = /let store = (.*)/;
        return ['<!DOCTYPE html>',
            document.documentElement.outerHTML.replace(regex, "let store = " + JSON.stringify(store)
                .replaceAll('</' + 'script', "' + '</' + 'script' + '") + ';')].join('\n');
    }

    function menuSave() {
        $('#app').classList.remove('dirty');
        download(quine(), basename(window.location.href) + '.html', 'text/html');
    }

    function menuExport() {
        download(JSON.stringify(store), basename(window.location.href) + '.json', 'text/json');
    }

    function menuDel() {
        let name = $name().value;
        if (name && confirm('delete ' + name + '?')) {
            storeDel(name);
            refresh();
            deletePane($panel());
        }
    }

    function menuSettings() {
        $('#settings').classList.toggle('visible');
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Pane actions

    function paneFold(e) {
        closest$(e, 'section').classList.toggle('folded');
    }

    function paneMax(e) {
        closest$(e, '.column').querySelectorAll("section").forEach(e => e.classList.add("folded"));
        closest$(e, 'section').classList.remove("folded");
    }

    function paneMove(e) {
        let $c;
        $$('.column').forEach(c => {
            if (c !== closest$(e, '.column')) $c = c;
        });
        $c.appendChild(closest$(e, 'section'));
    }

    function paneClose(e) {
        deletePane(closest$(e, 'section'));
    }

    function paneHist(from, to) {
        return function (e) {
            if (!from.length) return;
            let name = from.pop();
            if (isChordNavBlank(e)) {
                from.push(name);
                createPane();
            } else if (isChordNav(e)) {
                setActive($prevPanel);
                load(name);
                $content().focus();
            } else {
                hpush(to, $panel().dataset['name']);
            }
            load(name, true);
        }
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // Listeners

    let $prevPanel;
    let $resize;

    function handleSearch(e) {
        e.preventDefault();
        e.stopPropagation();
        if (isChordNavBlank(e)) {
            navBlank(t$(e).value);
            closeSearch();
        } else if (isChordNav(e)) {
            if (!$content()) createPane();
            closeSearch();
            load(t$(e).value);
        } else {
            if (!$content()) return;
            closeSearch();
            insert($content(), "[[" + t$(e).value + "]]");
        }
    }

    document.getElementById('app').innerHTML = `
 <datalist id="files"></datalist>
<table>
    <tr>
        <td colspan="2" class="menu" style="height: 0;">
            <span class="new">new</span><span class="log">log</span><span class="ls">ls</span><span
                class="ref">ref</span><span class="mv">mv</span><span class="del">del</span><span class="save">save</span><span class="settings">import</span><span class="export">export</span><span class="reset">reset</span>
        </td>
    </tr>
    <tr id="settings">
        <td colspan="2" class="menu" style="height: 0;">
            <input type="file" id="import" value="">
        </td>
    </tr>
    <tr>
        <td class="col">
            <div class="active column"></div>
            <div class="resize"></div>
        </td>
        <td>
            <div class="column"></div>
        </td>
    </tr>
</table>
<input list="files" spellcheck="false" id="search" autocomplete="off"/>
    `;

    document.addEventListener('mousedown', function (e) {
        if (hasCls(t$(e), 'resize')) {
            $resize = closest$(e, 'td');
        } else {
            $prevPanel = $panel() || $prevPanel;
            let section = closest$(e, 'section');
            section && setActive(section);
            let column = closest$(e, '.column');
            if (column && (!e.altKey && !e.metaKey && !e.ctrlKey)) {
                togCls('active', '.column', column);
            }
        }
    });

    document.addEventListener('mousemove', function (e) {
        if (!$resize) return;
        $resize.width = e.clientX;
    })

    document.addEventListener('mouseup', () => $resize = null);

    document.addEventListener('click', function (e) {
        // @formatter:off
        switch (t$(e).classList[0]) {
            case 'new': menuNew(); return;
            case 'log': menuLog(); return;
            case 'ls': menuLs(); return;
            case 'reset': menuReset(); return;
            case 'save': menuSave(); return;
            case 'ref': menuRef(); return;
            case 'mv': menuMv(); return;
            case 'del': menuDel(); return;
            case 'settings': menuSettings(); return;
            case 'export': menuExport(); return;
            case 'close': paneClose(e); return;
            case 'fold': paneFold(e); return;
            case 'max': paneMax(e); return;
            case 'move': paneMove(e); return;
            case 'back': paneHist(hist().back, hist().forward)(e); return;
            case 'forward': paneHist(hist().forward, hist().back)(e); return;
        }
        // @formatter:on
        if (isChordNavBlank(e) && e.button === 0) {
            link($content()) && navBlank(link($content()));
        } else if (isChordNav(e) && e.button === 0) {
            let name = link($content());
            if (name) {
                setActive($prevPanel);
                load(name);
                $content().focus();
            }
        }
    });

    window.addEventListener('beforeunload', e => {
        if ($('.dirty')) {
            e.preventDefault();
            e.returnValue = true;
        }
    })

    document.addEventListener('keydown', function (e) {
        if (e.key === 'Enter') {
            if (t$(e).id === 'search') {
                handleSearch(e);
            } else if (isChordNav(e)) {
                $search().value = '';
                $search().classList.add('searching');
                $search().focus();
            } else if (hasCls(e.target, 'name')) {
                load($name().value);
            }
        } else if (e.key === 'Escape' && e.target.id === 'search') {
            $search().classList.remove('searching');
            $content().focus();
        }
    });

    document.getElementById('import').addEventListener('change', function (e) {
        const file = e.target.files[0];
        const r = new FileReader();
        r.onload = e => {
            let data = JSON.parse('' + e.target.result);
            Object.keys(data).forEach(k => storeSet(k, data[k]));
        }
        r.readAsText(file);
        refresh();
    });

    refresh();
    createPane();
    load(location.hash && location.hash.substring(1));
</script>
</body>
</html>