(function(){
    "use strict";
    var ρσ_iterator_symbol = (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") ? Symbol.iterator : "iterator-Symbol-5d0927e5554349048cf0e3762a228256";
    var ρσ_kwargs_symbol = (typeof Symbol === "function") ? Symbol("kwargs-object") : "kwargs-object-Symbol-5d0927e5554349048cf0e3762a228256";
    var ρσ_cond_temp, ρσ_expr_temp, ρσ_last_exception;
    var ρσ_object_counter = 0;
var ρσ_len;
function ρσ_bool(val) {
    return !!val;
};
if (!ρσ_bool.__argnames__) Object.defineProperties(ρσ_bool, {
    __argnames__ : {value: ["val"]},
    __module__ : {value: "__main__"}
});

function ρσ_print() {
    var parts;
    if (typeof console === "object") {
        parts = [];
        for (var i = 0; i < arguments.length; i++) {
            parts.push(ρσ_str(arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i]));
        }
        console.log(parts.join(" "));
    }
};
if (!ρσ_print.__module__) Object.defineProperties(ρσ_print, {
    __module__ : {value: "__main__"}
});

function ρσ_int(val, base) {
    var ans;
    if (typeof val === "number") {
        ans = val | 0;
    } else {
        ans = parseInt(val, base || 10);
    }
    if (isNaN(ans)) {
        throw new ValueError("Invalid literal for int with base " + (base || 10) + ": " + val);
    }
    return ans;
};
if (!ρσ_int.__argnames__) Object.defineProperties(ρσ_int, {
    __argnames__ : {value: ["val", "base"]},
    __module__ : {value: "__main__"}
});

function ρσ_float(val) {
    var ans;
    if (typeof val === "number") {
        ans = val;
    } else {
        ans = parseFloat(val);
    }
    if (isNaN(ans)) {
        throw new ValueError("Could not convert string to float: " + arguments[0]);
    }
    return ans;
};
if (!ρσ_float.__argnames__) Object.defineProperties(ρσ_float, {
    __argnames__ : {value: ["val"]},
    __module__ : {value: "__main__"}
});

function ρσ_arraylike_creator() {
    var names;
    names = "Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" ");
    if (typeof HTMLCollection === "function") {
        names = names.concat("HTMLCollection NodeList NamedNodeMap TouchList".split(" "));
    }
    return (function() {
        var ρσ_anonfunc = function (x) {
            if (Array.isArray(x) || typeof x === "string" || names.indexOf(Object.prototype.toString.call(x).slice(8, -1)) > -1) {
                return true;
            }
            return false;
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["x"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
};
if (!ρσ_arraylike_creator.__module__) Object.defineProperties(ρσ_arraylike_creator, {
    __module__ : {value: "__main__"}
});

function options_object(f) {
    return (function() {
        var ρσ_anonfunc = function () {
            if (typeof arguments[arguments.length - 1] === "object") {
                arguments[ρσ_bound_index(arguments.length - 1, arguments)][ρσ_kwargs_symbol] = true;
            }
            return f.apply(this, arguments);
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
};
if (!options_object.__argnames__) Object.defineProperties(options_object, {
    __argnames__ : {value: ["f"]},
    __module__ : {value: "__main__"}
});

function ρσ_id(x) {
    return x.ρσ_object_id;
};
if (!ρσ_id.__argnames__) Object.defineProperties(ρσ_id, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

function ρσ_dir(item) {
    var arr;
    arr = ρσ_list_decorate([]);
    for (var i in item) {
        arr.push(i);
    }
    return arr;
};
if (!ρσ_dir.__argnames__) Object.defineProperties(ρσ_dir, {
    __argnames__ : {value: ["item"]},
    __module__ : {value: "__main__"}
});

function ρσ_ord(x) {
    var ans, second;
    ans = x.charCodeAt(0);
    if (55296 <= ans && ans <= 56319) {
        second = x.charCodeAt(1);
        if (56320 <= second && second <= 57343) {
            return (ans - 55296) * 1024 + second - 56320 + 65536;
        }
        throw new TypeError("string is missing the low surrogate char");
    }
    return ans;
};
if (!ρσ_ord.__argnames__) Object.defineProperties(ρσ_ord, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

function ρσ_chr(code) {
    if (code <= 65535) {
        return String.fromCharCode(code);
    }
    code -= 65536;
    return String.fromCharCode(55296 + (code >> 10), 56320 + (code & 1023));
};
if (!ρσ_chr.__argnames__) Object.defineProperties(ρσ_chr, {
    __argnames__ : {value: ["code"]},
    __module__ : {value: "__main__"}
});

function ρσ_callable(x) {
    return typeof x === "function";
};
if (!ρσ_callable.__argnames__) Object.defineProperties(ρσ_callable, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

function ρσ_bin(x) {
    var ans;
    if (typeof x !== "number" || x % 1 !== 0) {
        throw new TypeError("integer required");
    }
    ans = x.toString(2);
    if (ans[0] === "-") {
        ans = "-" + "0b" + ans.slice(1);
    } else {
        ans = "0b" + ans;
    }
    return ans;
};
if (!ρσ_bin.__argnames__) Object.defineProperties(ρσ_bin, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

function ρσ_hex(x) {
    var ans;
    if (typeof x !== "number" || x % 1 !== 0) {
        throw new TypeError("integer required");
    }
    ans = x.toString(16);
    if (ans[0] === "-") {
        ans = "-" + "0x" + ans.slice(1);
    } else {
        ans = "0x" + ans;
    }
    return ans;
};
if (!ρσ_hex.__argnames__) Object.defineProperties(ρσ_hex, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

function ρσ_enumerate(iterable) {
    var ans, iterator;
    ans = {"_i":-1};
    ans[ρσ_iterator_symbol] = (function() {
        var ρσ_anonfunc = function () {
            return this;
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    if (ρσ_arraylike(iterable)) {
        ans["next"] = (function() {
            var ρσ_anonfunc = function () {
                this._i += 1;
                if (this._i < iterable.length) {
                    return {'done':false, 'value':[this._i, iterable[this._i]]};
                }
                return {'done':true};
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ans;
    }
    if (typeof iterable[ρσ_iterator_symbol] === "function") {
        iterator = (typeof Map === "function" && iterable instanceof Map) ? iterable.keys() : iterable[ρσ_iterator_symbol]();
        ans["_iterator"] = iterator;
        ans["next"] = (function() {
            var ρσ_anonfunc = function () {
                var r;
                r = this._iterator.next();
                if (r.done) {
                    return {'done':true};
                }
                this._i += 1;
                return {'done':false, 'value':[this._i, r.value]};
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ans;
    }
    return ρσ_enumerate(Object.keys(iterable));
};
if (!ρσ_enumerate.__argnames__) Object.defineProperties(ρσ_enumerate, {
    __argnames__ : {value: ["iterable"]},
    __module__ : {value: "__main__"}
});

function ρσ_reversed(iterable) {
    var ans;
    if (ρσ_arraylike(iterable)) {
        ans = {"_i": iterable.length};
        ans["next"] = (function() {
            var ρσ_anonfunc = function () {
                this._i -= 1;
                if (this._i > -1) {
                    return {'done':false, 'value':iterable[this._i]};
                }
                return {'done':true};
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        ans[ρσ_iterator_symbol] = (function() {
            var ρσ_anonfunc = function () {
                return this;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ans;
    }
    throw new TypeError("reversed() can only be called on arrays or strings");
};
if (!ρσ_reversed.__argnames__) Object.defineProperties(ρσ_reversed, {
    __argnames__ : {value: ["iterable"]},
    __module__ : {value: "__main__"}
});

function ρσ_iter(iterable) {
    var ans;
    if (typeof iterable[ρσ_iterator_symbol] === "function") {
        return (typeof Map === "function" && iterable instanceof Map) ? iterable.keys() : iterable[ρσ_iterator_symbol]();
    }
    if (ρσ_arraylike(iterable)) {
        ans = {"_i":-1};
        ans[ρσ_iterator_symbol] = (function() {
            var ρσ_anonfunc = function () {
                return this;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        ans["next"] = (function() {
            var ρσ_anonfunc = function () {
                this._i += 1;
                if (this._i < iterable.length) {
                    return {'done':false, 'value':iterable[this._i]};
                }
                return {'done':true};
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ans;
    }
    return ρσ_iter(Object.keys(iterable));
};
if (!ρσ_iter.__argnames__) Object.defineProperties(ρσ_iter, {
    __argnames__ : {value: ["iterable"]},
    __module__ : {value: "__main__"}
});

function ρσ_range_next(step, length) {
    var ρσ_unpack;
    this._i += step;
    this._idx += 1;
    if (this._idx >= length) {
        ρσ_unpack = [this.__i, -1];
        this._i = ρσ_unpack[0];
        this._idx = ρσ_unpack[1];
        return {'done':true};
    }
    return {'done':false, 'value':this._i};
};
if (!ρσ_range_next.__argnames__) Object.defineProperties(ρσ_range_next, {
    __argnames__ : {value: ["step", "length"]},
    __module__ : {value: "__main__"}
});

function ρσ_range(start, stop, step) {
    var length, ans;
    if (arguments.length <= 1) {
        stop = start || 0;
        start = 0;
    }
    step = arguments[2] || 1;
    length = Math.max(Math.ceil((stop - start) / step), 0);
    ans = {start:start, step:step, stop:stop};
    ans[ρσ_iterator_symbol] = (function() {
        var ρσ_anonfunc = function () {
            var it;
            it = {"_i": start - step, "_idx": -1};
            it.next = ρσ_range_next.bind(it, step, length);
            it[ρσ_iterator_symbol] = (function() {
                var ρσ_anonfunc = function () {
                    return this;
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "__main__"}
                });
                return ρσ_anonfunc;
            })();
            return it;
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ans.count = (function() {
        var ρσ_anonfunc = function (val) {
            if (!this._cached) {
                this._cached = list(this);
            }
            return this._cached.count(val);
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ans.index = (function() {
        var ρσ_anonfunc = function (val) {
            if (!this._cached) {
                this._cached = list(this);
            }
            return this._cached.index(val);
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ans.__len__ = (function() {
        var ρσ_anonfunc = function () {
            return length;
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ans.__repr__ = (function() {
        var ρσ_anonfunc = function () {
            return "range(" + ρσ_str.format("{}", start) + ", " + ρσ_str.format("{}", stop) + ", " + ρσ_str.format("{}", step) + ")";
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ans.__str__ = ans.toString = ans.__repr__;
    if (typeof Proxy === "function") {
        ans = new Proxy(ans, (function(){
            var ρσ_d = {};
            ρσ_d["get"] = (function() {
                var ρσ_anonfunc = function (obj, prop) {
                    var iprop;
                    if (typeof prop === "string") {
                        iprop = parseInt(prop);
                        if (!isNaN(iprop)) {
                            prop = iprop;
                        }
                    }
                    if (typeof prop === "number") {
                        if (!obj._cached) {
                            obj._cached = list(obj);
                        }
                        return (ρσ_expr_temp = obj._cached)[(typeof prop === "number" && prop < 0) ? ρσ_expr_temp.length + prop : prop];
                    }
                    return obj[(typeof prop === "number" && prop < 0) ? obj.length + prop : prop];
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["obj", "prop"]},
                    __module__ : {value: "__main__"}
                });
                return ρσ_anonfunc;
            })();
            return ρσ_d;
        }).call(this));
    }
    return ans;
};
if (!ρσ_range.__argnames__) Object.defineProperties(ρσ_range, {
    __argnames__ : {value: ["start", "stop", "step"]},
    __module__ : {value: "__main__"}
});

function ρσ_getattr(obj, name, defval) {
    var ret;
    try {
        ret = obj[(typeof name === "number" && name < 0) ? obj.length + name : name];
    } catch (ρσ_Exception) {
        ρσ_last_exception = ρσ_Exception;
        if (ρσ_Exception instanceof TypeError) {
            if (defval === undefined) {
                throw new AttributeError("The attribute " + name + " is not present");
            }
            return defval;
        } else {
            throw ρσ_Exception;
        }
    }
    if (ret === undefined && !(name in obj)) {
        if (defval === undefined) {
            throw new AttributeError("The attribute " + name + " is not present");
        }
        ret = defval;
    }
    return ret;
};
if (!ρσ_getattr.__argnames__) Object.defineProperties(ρσ_getattr, {
    __argnames__ : {value: ["obj", "name", "defval"]},
    __module__ : {value: "__main__"}
});

function ρσ_setattr(obj, name, value) {
    obj[(typeof name === "number" && name < 0) ? obj.length + name : name] = value;
};
if (!ρσ_setattr.__argnames__) Object.defineProperties(ρσ_setattr, {
    __argnames__ : {value: ["obj", "name", "value"]},
    __module__ : {value: "__main__"}
});

function ρσ_hasattr(obj, name) {
    return name in obj;
};
if (!ρσ_hasattr.__argnames__) Object.defineProperties(ρσ_hasattr, {
    __argnames__ : {value: ["obj", "name"]},
    __module__ : {value: "__main__"}
});

ρσ_len = (function() {
    var ρσ_anonfunc = function () {
        function len(obj) {
            if (ρσ_arraylike(obj)) {
                return obj.length;
            }
            if (typeof obj.__len__ === "function") {
                return obj.__len__();
            }
            if (obj instanceof Set || obj instanceof Map) {
                return obj.size;
            }
            return Object.keys(obj).length;
        };
        if (!len.__argnames__) Object.defineProperties(len, {
            __argnames__ : {value: ["obj"]},
            __module__ : {value: "__main__"}
        });

        function len5(obj) {
            if (ρσ_arraylike(obj)) {
                return obj.length;
            }
            if (typeof obj.__len__ === "function") {
                return obj.__len__();
            }
            return Object.keys(obj).length;
        };
        if (!len5.__argnames__) Object.defineProperties(len5, {
            __argnames__ : {value: ["obj"]},
            __module__ : {value: "__main__"}
        });

        return (typeof Set === "function" && typeof Map === "function") ? len : len5;
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})()();
function ρσ_get_module(name) {
    return ρσ_modules[(typeof name === "number" && name < 0) ? ρσ_modules.length + name : name];
};
if (!ρσ_get_module.__argnames__) Object.defineProperties(ρσ_get_module, {
    __argnames__ : {value: ["name"]},
    __module__ : {value: "__main__"}
});

function ρσ_pow(x, y, z) {
    var ans;
    ans = Math.pow(x, y);
    if (z !== undefined) {
        ans %= z;
    }
    return ans;
};
if (!ρσ_pow.__argnames__) Object.defineProperties(ρσ_pow, {
    __argnames__ : {value: ["x", "y", "z"]},
    __module__ : {value: "__main__"}
});

function ρσ_type(x) {
    return x.constructor;
};
if (!ρσ_type.__argnames__) Object.defineProperties(ρσ_type, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

function ρσ_divmod(x, y) {
    var d;
    if (y === 0) {
        throw new ZeroDivisionError("integer division or modulo by zero");
    }
    d = Math.floor(x / y);
    return [d, x - d * y];
};
if (!ρσ_divmod.__argnames__) Object.defineProperties(ρσ_divmod, {
    __argnames__ : {value: ["x", "y"]},
    __module__ : {value: "__main__"}
});

function ρσ_max() {
    var kwargs = arguments[arguments.length-1];
    if (kwargs === null || typeof kwargs !== "object" || kwargs [ρσ_kwargs_symbol] !== true) kwargs = {};
    var args = Array.prototype.slice.call(arguments, 0);
    if (kwargs !== null && typeof kwargs === "object" && kwargs [ρσ_kwargs_symbol] === true) args.pop();
    var args, x;
    if (args.length === 0) {
        if (kwargs.defval !== undefined) {
            return kwargs.defval;
        }
        throw new TypeError("expected at least one argument");
    }
    if (args.length === 1) {
        args = args[0];
    }
    if (kwargs.key) {
        args = (function() {
            var ρσ_Iter = ρσ_Iterable(args), ρσ_Result = [], x;
            for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                x = ρσ_Iter[ρσ_Index];
                ρσ_Result.push(kwargs.key(x));
            }
            ρσ_Result = ρσ_list_constructor(ρσ_Result);
            return ρσ_Result;
        })();
    }
    if (!Array.isArray(args)) {
        args = list(args);
    }
    if (args.length) {
        return this.apply(null, args);
    }
    if (kwargs.defval !== undefined) {
        return kwargs.defval;
    }
    throw new TypeError("expected at least one argument");
};
if (!ρσ_max.__handles_kwarg_interpolation__) Object.defineProperties(ρσ_max, {
    __handles_kwarg_interpolation__ : {value: true},
    __module__ : {value: "__main__"}
});

var abs = Math.abs, max = ρσ_max.bind(Math.max), min = ρσ_max.bind(Math.min), bool = ρσ_bool, type = ρσ_type;
var float = ρσ_float, int = ρσ_int, arraylike = ρσ_arraylike_creator(), ρσ_arraylike = arraylike;
var print = ρσ_print, id = ρσ_id, get_module = ρσ_get_module, pow = ρσ_pow, divmod = ρσ_divmod;
var dir = ρσ_dir, ord = ρσ_ord, chr = ρσ_chr, bin = ρσ_bin, hex = ρσ_hex, callable = ρσ_callable;
var enumerate = ρσ_enumerate, iter = ρσ_iter, reversed = ρσ_reversed, len = ρσ_len;
var range = ρσ_range, getattr = ρσ_getattr, setattr = ρσ_setattr, hasattr = ρσ_hasattr;function ρσ_equals(a, b) {
    var ρσ_unpack, akeys, bkeys, key;
    if (a === b) {
        return true;
    }
    if (a && typeof a.__eq__ === "function") {
        return a.__eq__(b);
    }
    if (b && typeof b.__eq__ === "function") {
        return b.__eq__(a);
    }
    if (ρσ_arraylike(a) && ρσ_arraylike(b)) {
        if ((a.length !== b.length && (typeof a.length !== "object" || ρσ_not_equals(a.length, b.length)))) {
            return false;
        }
        for (var i=0; i < a.length; i++) {
            if (!(((a[(typeof i === "number" && i < 0) ? a.length + i : i] === b[(typeof i === "number" && i < 0) ? b.length + i : i] || typeof a[(typeof i === "number" && i < 0) ? a.length + i : i] === "object" && ρσ_equals(a[(typeof i === "number" && i < 0) ? a.length + i : i], b[(typeof i === "number" && i < 0) ? b.length + i : i]))))) {
                return false;
            }
        }
        return true;
    }
    if (typeof a === "object" && typeof b === "object" && a !== null && b !== null && (a.constructor === Object && b.constructor === Object || Object.getPrototypeOf(a) === null && Object.getPrototypeOf(b) === null)) {
        ρσ_unpack = [Object.keys(a), Object.keys(b)];
        akeys = ρσ_unpack[0];
        bkeys = ρσ_unpack[1];
        if (akeys.length !== bkeys.length) {
            return false;
        }
        for (var j=0; j < akeys.length; j++) {
            key = akeys[(typeof j === "number" && j < 0) ? akeys.length + j : j];
            if (!(((a[(typeof key === "number" && key < 0) ? a.length + key : key] === b[(typeof key === "number" && key < 0) ? b.length + key : key] || typeof a[(typeof key === "number" && key < 0) ? a.length + key : key] === "object" && ρσ_equals(a[(typeof key === "number" && key < 0) ? a.length + key : key], b[(typeof key === "number" && key < 0) ? b.length + key : key]))))) {
                return false;
            }
        }
        return true;
    }
    return false;
};
if (!ρσ_equals.__argnames__) Object.defineProperties(ρσ_equals, {
    __argnames__ : {value: ["a", "b"]},
    __module__ : {value: "__main__"}
});

function ρσ_not_equals(a, b) {
    if (a === b) {
        return false;
    }
    if (a && typeof a.__ne__ === "function") {
        return a.__ne__(b);
    }
    if (b && typeof b.__ne__ === "function") {
        return b.__ne__(a);
    }
    return !ρσ_equals(a, b);
};
if (!ρσ_not_equals.__argnames__) Object.defineProperties(ρσ_not_equals, {
    __argnames__ : {value: ["a", "b"]},
    __module__ : {value: "__main__"}
});

var equals = ρσ_equals;
function ρσ_list_extend(iterable) {
    var start, iterator, result;
    if (Array.isArray(iterable) || typeof iterable === "string") {
        start = this.length;
        this.length += iterable.length;
        for (var i = 0; i < iterable.length; i++) {
            (ρσ_expr_temp = this)[ρσ_bound_index(start + i, ρσ_expr_temp)] = iterable[(typeof i === "number" && i < 0) ? iterable.length + i : i];
        }
    } else {
        iterator = (typeof Map === "function" && iterable instanceof Map) ? iterable.keys() : iterable[ρσ_iterator_symbol]();
        result = iterator.next();
        while (!result.done) {
            this.push(result.value);
            result = iterator.next();
        }
    }
};
if (!ρσ_list_extend.__argnames__) Object.defineProperties(ρσ_list_extend, {
    __argnames__ : {value: ["iterable"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_index(val, start, stop) {
    start = start || 0;
    if (start < 0) {
        start = this.length + start;
    }
    if (start < 0) {
        throw new ValueError(val + " is not in list");
    }
    if (stop === undefined) {
        stop = this.length;
    }
    if (stop < 0) {
        stop = this.length + stop;
    }
    for (var i = start; i < stop; i++) {
        if (((ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] === val || typeof (ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] === "object" && ρσ_equals((ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i], val))) {
            return i;
        }
    }
    throw new ValueError(val + " is not in list");
};
if (!ρσ_list_index.__argnames__) Object.defineProperties(ρσ_list_index, {
    __argnames__ : {value: ["val", "start", "stop"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_pop(index) {
    var ans;
    if (this.length === 0) {
        throw new IndexError("list is empty");
    }
    if (index === undefined) {
        index = -1;
    }
    ans = this.splice(index, 1);
    if (!ans.length) {
        throw new IndexError("pop index out of range");
    }
    return ans[0];
};
if (!ρσ_list_pop.__argnames__) Object.defineProperties(ρσ_list_pop, {
    __argnames__ : {value: ["index"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_remove(value) {
    for (var i = 0; i < this.length; i++) {
        if (((ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] === value || typeof (ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] === "object" && ρσ_equals((ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i], value))) {
            this.splice(i, 1);
            return;
        }
    }
    throw new ValueError(value + " not in list");
};
if (!ρσ_list_remove.__argnames__) Object.defineProperties(ρσ_list_remove, {
    __argnames__ : {value: ["value"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_to_string() {
    return "[" + this.join(", ") + "]";
};
if (!ρσ_list_to_string.__module__) Object.defineProperties(ρσ_list_to_string, {
    __module__ : {value: "__main__"}
});

function ρσ_list_insert(index, val) {
    if (index < 0) {
        index += this.length;
    }
    index = min(this.length, max(index, 0));
    if (index === 0) {
        this.unshift(val);
        return;
    }
    for (var i = this.length; i > index; i--) {
        (ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] = (ρσ_expr_temp = this)[ρσ_bound_index(i - 1, ρσ_expr_temp)];
    }
    (ρσ_expr_temp = this)[(typeof index === "number" && index < 0) ? ρσ_expr_temp.length + index : index] = val;
};
if (!ρσ_list_insert.__argnames__) Object.defineProperties(ρσ_list_insert, {
    __argnames__ : {value: ["index", "val"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_copy() {
    return ρσ_list_constructor(this);
};
if (!ρσ_list_copy.__module__) Object.defineProperties(ρσ_list_copy, {
    __module__ : {value: "__main__"}
});

function ρσ_list_clear() {
    this.length = 0;
};
if (!ρσ_list_clear.__module__) Object.defineProperties(ρσ_list_clear, {
    __module__ : {value: "__main__"}
});

function ρσ_list_as_array() {
    return Array.prototype.slice.call(this);
};
if (!ρσ_list_as_array.__module__) Object.defineProperties(ρσ_list_as_array, {
    __module__ : {value: "__main__"}
});

function ρσ_list_count(value) {
    return this.reduce((function() {
        var ρσ_anonfunc = function (n, val) {
            return n + (val === value);
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["n", "val"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })(), 0);
};
if (!ρσ_list_count.__argnames__) Object.defineProperties(ρσ_list_count, {
    __argnames__ : {value: ["value"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_sort_key(value) {
    var t;
    t = typeof value;
    if (t === "string" || t === "number") {
        return value;
    }
    return value.toString();
};
if (!ρσ_list_sort_key.__argnames__) Object.defineProperties(ρσ_list_sort_key, {
    __argnames__ : {value: ["value"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_sort_cmp(a, b, ap, bp) {
    if (a < b) {
        return -1;
    }
    if (a > b) {
        return 1;
    }
    return ap - bp;
};
if (!ρσ_list_sort_cmp.__argnames__) Object.defineProperties(ρσ_list_sort_cmp, {
    __argnames__ : {value: ["a", "b", "ap", "bp"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_sort() {
    var key = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ρσ_list_sort.__defaults__.key : arguments[0];
    var reverse = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ρσ_list_sort.__defaults__.reverse : arguments[1];
    var ρσ_kwargs_obj = arguments[arguments.length-1];
    if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
    if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "key")){
        key = ρσ_kwargs_obj.key;
    }
    if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "reverse")){
        reverse = ρσ_kwargs_obj.reverse;
    }
    var mult, keymap, posmap, k;
    key = key || ρσ_list_sort_key;
    mult = (reverse) ? -1 : 1;
    keymap = dict();
    posmap = dict();
    for (var i=0; i < this.length; i++) {
        k = (ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
        keymap.set(k, key(k));
        posmap.set(k, i);
    }
    this.sort((function() {
        var ρσ_anonfunc = function (a, b) {
            return mult * ρσ_list_sort_cmp(keymap.get(a), keymap.get(b), posmap.get(a), posmap.get(b));
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["a", "b"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })());
};
if (!ρσ_list_sort.__defaults__) Object.defineProperties(ρσ_list_sort, {
    __defaults__ : {value: {key:null, reverse:false}},
    __handles_kwarg_interpolation__ : {value: true},
    __argnames__ : {value: ["key", "reverse"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_concat() {
    var ans;
    ans = Array.prototype.concat.apply(this, arguments);
    ρσ_list_decorate(ans);
    return ans;
};
if (!ρσ_list_concat.__module__) Object.defineProperties(ρσ_list_concat, {
    __module__ : {value: "__main__"}
});

function ρσ_list_slice() {
    var ans;
    ans = Array.prototype.slice.apply(this, arguments);
    ρσ_list_decorate(ans);
    return ans;
};
if (!ρσ_list_slice.__module__) Object.defineProperties(ρσ_list_slice, {
    __module__ : {value: "__main__"}
});

function ρσ_list_iterator(value) {
    var self;
    self = this;
    return (function(){
        var ρσ_d = {};
        ρσ_d["_i"] = -1;
        ρσ_d["_list"] = self;
        ρσ_d["next"] = (function() {
            var ρσ_anonfunc = function () {
                this._i += 1;
                if (this._i >= this._list.length) {
                    return (function(){
                        var ρσ_d = {};
                        ρσ_d["done"] = true;
                        return ρσ_d;
                    }).call(this);
                }
                return (function(){
                    var ρσ_d = {};
                    ρσ_d["done"] = false;
                    ρσ_d["value"] = (ρσ_expr_temp = this._list)[ρσ_bound_index(this._i, ρσ_expr_temp)];
                    return ρσ_d;
                }).call(this);
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ρσ_d;
    }).call(this);
};
if (!ρσ_list_iterator.__argnames__) Object.defineProperties(ρσ_list_iterator, {
    __argnames__ : {value: ["value"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_len() {
    return this.length;
};
if (!ρσ_list_len.__module__) Object.defineProperties(ρσ_list_len, {
    __module__ : {value: "__main__"}
});

function ρσ_list_contains(val) {
    for (var i = 0; i < this.length; i++) {
        if (((ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] === val || typeof (ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] === "object" && ρσ_equals((ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i], val))) {
            return true;
        }
    }
    return false;
};
if (!ρσ_list_contains.__argnames__) Object.defineProperties(ρσ_list_contains, {
    __argnames__ : {value: ["val"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_eq(other) {
    if (!ρσ_arraylike(other)) {
        return false;
    }
    if ((this.length !== other.length && (typeof this.length !== "object" || ρσ_not_equals(this.length, other.length)))) {
        return false;
    }
    for (var i = 0; i < this.length; i++) {
        if (!((((ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] === other[(typeof i === "number" && i < 0) ? other.length + i : i] || typeof (ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] === "object" && ρσ_equals((ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i], other[(typeof i === "number" && i < 0) ? other.length + i : i]))))) {
            return false;
        }
    }
    return true;
};
if (!ρσ_list_eq.__argnames__) Object.defineProperties(ρσ_list_eq, {
    __argnames__ : {value: ["other"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_decorate(ans) {
    ans.append = Array.prototype.push;
    ans.toString = ρσ_list_to_string;
    ans.inspect = ρσ_list_to_string;
    ans.extend = ρσ_list_extend;
    ans.index = ρσ_list_index;
    ans.pypop = ρσ_list_pop;
    ans.remove = ρσ_list_remove;
    ans.insert = ρσ_list_insert;
    ans.copy = ρσ_list_copy;
    ans.clear = ρσ_list_clear;
    ans.count = ρσ_list_count;
    ans.concat = ρσ_list_concat;
    ans.pysort = ρσ_list_sort;
    ans.slice = ρσ_list_slice;
    ans.as_array = ρσ_list_as_array;
    ans.__len__ = ρσ_list_len;
    ans.__contains__ = ρσ_list_contains;
    ans.__eq__ = ρσ_list_eq;
    ans.constructor = ρσ_list_constructor;
    if (typeof ans[ρσ_iterator_symbol] !== "function") {
        ans[ρσ_iterator_symbol] = ρσ_list_iterator;
    }
    return ans;
};
if (!ρσ_list_decorate.__argnames__) Object.defineProperties(ρσ_list_decorate, {
    __argnames__ : {value: ["ans"]},
    __module__ : {value: "__main__"}
});

function ρσ_list_constructor(iterable) {
    var ans, iterator, result;
    if (iterable === undefined) {
        ans = [];
    } else if (ρσ_arraylike(iterable)) {
        ans = new Array(iterable.length);
        for (var i = 0; i < iterable.length; i++) {
            ans[(typeof i === "number" && i < 0) ? ans.length + i : i] = iterable[(typeof i === "number" && i < 0) ? iterable.length + i : i];
        }
    } else if (typeof iterable[ρσ_iterator_symbol] === "function") {
        iterator = (typeof Map === "function" && iterable instanceof Map) ? iterable.keys() : iterable[ρσ_iterator_symbol]();
        ans = ρσ_list_decorate([]);
        result = iterator.next();
        while (!result.done) {
            ans.push(result.value);
            result = iterator.next();
        }
    } else if (typeof iterable === "number") {
        ans = new Array(iterable);
    } else {
        ans = Object.keys(iterable);
    }
    return ρσ_list_decorate(ans);
};
if (!ρσ_list_constructor.__argnames__) Object.defineProperties(ρσ_list_constructor, {
    __argnames__ : {value: ["iterable"]},
    __module__ : {value: "__main__"}
});

ρσ_list_constructor.__name__ = "list";
var list = ρσ_list_constructor, list_wrap = ρσ_list_decorate;
function sorted() {
    var iterable = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
    var key = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? sorted.__defaults__.key : arguments[1];
    var reverse = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? sorted.__defaults__.reverse : arguments[2];
    var ρσ_kwargs_obj = arguments[arguments.length-1];
    if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
    if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "key")){
        key = ρσ_kwargs_obj.key;
    }
    if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "reverse")){
        reverse = ρσ_kwargs_obj.reverse;
    }
    var ans;
    ans = ρσ_list_constructor(iterable);
    ans.pysort(key, reverse);
    return ans;
};
if (!sorted.__defaults__) Object.defineProperties(sorted, {
    __defaults__ : {value: {key:null, reverse:false}},
    __handles_kwarg_interpolation__ : {value: true},
    __argnames__ : {value: ["iterable", "key", "reverse"]},
    __module__ : {value: "__main__"}
});

var ρσ_global_object_id = 0, ρσ_set_implementation;
function ρσ_set_keyfor(x) {
    var t, ans;
    t = typeof x;
    if (t === "string" || t === "number" || t === "boolean") {
        return "_" + t[0] + x;
    }
    if (x === null) {
        return "__!@#$0";
    }
    ans = x.ρσ_hash_key_prop;
    if (ans === undefined) {
        ans = "_!@#$" + (++ρσ_global_object_id);
        Object.defineProperty(x, "ρσ_hash_key_prop", (function(){
            var ρσ_d = {};
            ρσ_d["value"] = ans;
            return ρσ_d;
        }).call(this));
    }
    return ans;
};
if (!ρσ_set_keyfor.__argnames__) Object.defineProperties(ρσ_set_keyfor, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

function ρσ_set_polyfill() {
    this._store = {};
    this.size = 0;
};
if (!ρσ_set_polyfill.__module__) Object.defineProperties(ρσ_set_polyfill, {
    __module__ : {value: "__main__"}
});

ρσ_set_polyfill.prototype.add = (function() {
    var ρσ_anonfunc = function (x) {
        var key;
        key = ρσ_set_keyfor(x);
        if (!Object.prototype.hasOwnProperty.call(this._store, key)) {
            this.size += 1;
            (ρσ_expr_temp = this._store)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = x;
        }
        return this;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set_polyfill.prototype.clear = (function() {
    var ρσ_anonfunc = function (x) {
        this._store = {};
        this.size = 0;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set_polyfill.prototype.delete = (function() {
    var ρσ_anonfunc = function (x) {
        var key;
        key = ρσ_set_keyfor(x);
        if (Object.prototype.hasOwnProperty.call(this._store, key)) {
            this.size -= 1;
            delete this._store[key];
            return true;
        }
        return false;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set_polyfill.prototype.has = (function() {
    var ρσ_anonfunc = function (x) {
        return Object.prototype.hasOwnProperty.call(this._store, ρσ_set_keyfor(x));
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set_polyfill.prototype.values = (function() {
    var ρσ_anonfunc = function (x) {
        var ans;
        ans = {'_keys': Object.keys(this._store), '_i':-1, '_s':this._store};
        ans[ρσ_iterator_symbol] = (function() {
            var ρσ_anonfunc = function () {
                return this;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        ans["next"] = (function() {
            var ρσ_anonfunc = function () {
                this._i += 1;
                if (this._i >= this._keys.length) {
                    return {'done': true};
                }
                return {'done':false, 'value':this._s[this._keys[this._i]]};
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
if (typeof Set !== "function" || typeof Set.prototype.delete !== "function") {
    ρσ_set_implementation = ρσ_set_polyfill;
} else {
    ρσ_set_implementation = Set;
}
function ρσ_set(iterable) {
    var ans, s, iterator, result, keys;
    if (this instanceof ρσ_set) {
        this.jsset = new ρσ_set_implementation;
        ans = this;
        if (iterable === undefined) {
            return ans;
        }
        s = ans.jsset;
        if (ρσ_arraylike(iterable)) {
            for (var i = 0; i < iterable.length; i++) {
                s.add(iterable[(typeof i === "number" && i < 0) ? iterable.length + i : i]);
            }
        } else if (typeof iterable[ρσ_iterator_symbol] === "function") {
            iterator = (typeof Map === "function" && iterable instanceof Map) ? iterable.keys() : iterable[ρσ_iterator_symbol]();
            result = iterator.next();
            while (!result.done) {
                s.add(result.value);
                result = iterator.next();
            }
        } else {
            keys = Object.keys(iterable);
            for (var j=0; j < keys.length; j++) {
                s.add(keys[(typeof j === "number" && j < 0) ? keys.length + j : j]);
            }
        }
        return ans;
    } else {
        return new ρσ_set(iterable);
    }
};
if (!ρσ_set.__argnames__) Object.defineProperties(ρσ_set, {
    __argnames__ : {value: ["iterable"]},
    __module__ : {value: "__main__"}
});

ρσ_set.prototype.__name__ = "set";
Object.defineProperties(ρσ_set.prototype, (function(){
    var ρσ_d = {};
    ρσ_d["length"] = (function(){
        var ρσ_d = {};
        ρσ_d["get"] = (function() {
            var ρσ_anonfunc = function () {
                return this.jsset.size;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ρσ_d;
    }).call(this);
    ρσ_d["size"] = (function(){
        var ρσ_d = {};
        ρσ_d["get"] = (function() {
            var ρσ_anonfunc = function () {
                return this.jsset.size;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ρσ_d;
    }).call(this);
    return ρσ_d;
}).call(this));
ρσ_set.prototype.__len__ = (function() {
    var ρσ_anonfunc = function () {
        return this.jsset.size;
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.has = ρσ_set.prototype.__contains__ = (function() {
    var ρσ_anonfunc = function (x) {
        return this.jsset.has(x);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.add = (function() {
    var ρσ_anonfunc = function (x) {
        this.jsset.add(x);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.clear = (function() {
    var ρσ_anonfunc = function () {
        this.jsset.clear();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.copy = (function() {
    var ρσ_anonfunc = function () {
        return ρσ_set(this);
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.discard = (function() {
    var ρσ_anonfunc = function (x) {
        this.jsset.delete(x);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype[ρσ_iterator_symbol] = (function() {
    var ρσ_anonfunc = function () {
        return this.jsset.values();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.difference = (function() {
    var ρσ_anonfunc = function () {
        var ans, s, iterator, r, x, has;
        ans = new ρσ_set;
        s = ans.jsset;
        iterator = this.jsset.values();
        r = iterator.next();
        while (!r.done) {
            x = r.value;
            has = false;
            for (var i = 0; i < arguments.length; i++) {
                if (arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i].has(x)) {
                    has = true;
                    break;
                }
            }
            if (!has) {
                s.add(x);
            }
            r = iterator.next();
        }
        return ans;
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.difference_update = (function() {
    var ρσ_anonfunc = function () {
        var s, remove, iterator, r, x;
        s = this.jsset;
        remove = [];
        iterator = s.values();
        r = iterator.next();
        while (!r.done) {
            x = r.value;
            for (var i = 0; i < arguments.length; i++) {
                if (arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i].has(x)) {
                    remove.push(x);
                    break;
                }
            }
            r = iterator.next();
        }
        for (var j = 0; j < remove.length; j++) {
            s.delete(remove[(typeof j === "number" && j < 0) ? remove.length + j : j]);
        }
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.intersection = (function() {
    var ρσ_anonfunc = function () {
        var ans, s, iterator, r, x, has;
        ans = new ρσ_set;
        s = ans.jsset;
        iterator = this.jsset.values();
        r = iterator.next();
        while (!r.done) {
            x = r.value;
            has = true;
            for (var i = 0; i < arguments.length; i++) {
                if (!arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i].has(x)) {
                    has = false;
                    break;
                }
            }
            if (has) {
                s.add(x);
            }
            r = iterator.next();
        }
        return ans;
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.intersection_update = (function() {
    var ρσ_anonfunc = function () {
        var s, remove, iterator, r, x;
        s = this.jsset;
        remove = [];
        iterator = s.values();
        r = iterator.next();
        while (!r.done) {
            x = r.value;
            for (var i = 0; i < arguments.length; i++) {
                if (!arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i].has(x)) {
                    remove.push(x);
                    break;
                }
            }
            r = iterator.next();
        }
        for (var j = 0; j < remove.length; j++) {
            s.delete(remove[(typeof j === "number" && j < 0) ? remove.length + j : j]);
        }
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.isdisjoint = (function() {
    var ρσ_anonfunc = function (other) {
        var iterator, r, x;
        iterator = this.jsset.values();
        r = iterator.next();
        while (!r.done) {
            x = r.value;
            if (other.has(x)) {
                return false;
            }
            r = iterator.next();
        }
        return true;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["other"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.issubset = (function() {
    var ρσ_anonfunc = function (other) {
        var iterator, r, x;
        iterator = this.jsset.values();
        r = iterator.next();
        while (!r.done) {
            x = r.value;
            if (!other.has(x)) {
                return false;
            }
            r = iterator.next();
        }
        return true;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["other"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.issuperset = (function() {
    var ρσ_anonfunc = function (other) {
        var s, iterator, r, x;
        s = this.jsset;
        iterator = other.jsset.values();
        r = iterator.next();
        while (!r.done) {
            x = r.value;
            if (!s.has(x)) {
                return false;
            }
            r = iterator.next();
        }
        return true;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["other"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.pop = (function() {
    var ρσ_anonfunc = function () {
        var iterator, r;
        iterator = this.jsset.values();
        r = iterator.next();
        if (r.done) {
            throw new KeyError("pop from an empty set");
        }
        this.jsset.delete(r.value);
        return r.value;
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.remove = (function() {
    var ρσ_anonfunc = function (x) {
        if (!this.jsset.delete(x)) {
            throw new KeyError(x.toString());
        }
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.symmetric_difference = (function() {
    var ρσ_anonfunc = function (other) {
        return this.union(other).difference(this.intersection(other));
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["other"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.symmetric_difference_update = (function() {
    var ρσ_anonfunc = function (other) {
        var common;
        common = this.intersection(other);
        this.update(other);
        this.difference_update(common);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["other"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.union = (function() {
    var ρσ_anonfunc = function () {
        var ans;
        ans = ρσ_set(this);
        ans.update.apply(ans, arguments);
        return ans;
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.update = (function() {
    var ρσ_anonfunc = function () {
        var s, iterator, r;
        s = this.jsset;
        for (var i=0; i < arguments.length; i++) {
            iterator = arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i][ρσ_iterator_symbol]();
            r = iterator.next();
            while (!r.done) {
                s.add(r.value);
                r = iterator.next();
            }
        }
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.toString = ρσ_set.prototype.__repr__ = ρσ_set.prototype.__str__ = ρσ_set.prototype.inspect = (function() {
    var ρσ_anonfunc = function () {
        return "{" + list(this).join(", ") + "}";
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_set.prototype.__eq__ = (function() {
    var ρσ_anonfunc = function (other) {
        var iterator, r;
        if (!other instanceof this.constructor) {
            return false;
        }
        if (other.size !== this.size) {
            return false;
        }
        if (other.size === 0) {
            return true;
        }
        iterator = other[ρσ_iterator_symbol]();
        r = iterator.next();
        while (!r.done) {
            if (!this.has(r.value)) {
                return false;
            }
            r = iterator.next();
        }
        return true;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["other"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
function ρσ_set_wrap(x) {
    var ans;
    ans = new ρσ_set;
    ans.jsset = x;
    return ans;
};
if (!ρσ_set_wrap.__argnames__) Object.defineProperties(ρσ_set_wrap, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

var set = ρσ_set, set_wrap = ρσ_set_wrap;
var ρσ_dict_implementation;
function ρσ_dict_polyfill() {
    this._store = {};
    this.size = 0;
};
if (!ρσ_dict_polyfill.__module__) Object.defineProperties(ρσ_dict_polyfill, {
    __module__ : {value: "__main__"}
});

ρσ_dict_polyfill.prototype.set = (function() {
    var ρσ_anonfunc = function (x, value) {
        var key;
        key = ρσ_set_keyfor(x);
        if (!Object.prototype.hasOwnProperty.call(this._store, key)) {
            this.size += 1;
        }
        (ρσ_expr_temp = this._store)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = [x, value];
        return this;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x", "value"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict_polyfill.prototype.clear = (function() {
    var ρσ_anonfunc = function (x) {
        this._store = {};
        this.size = 0;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict_polyfill.prototype.delete = (function() {
    var ρσ_anonfunc = function (x) {
        var key;
        key = ρσ_set_keyfor(x);
        if (Object.prototype.hasOwnProperty.call(this._store, key)) {
            this.size -= 1;
            delete this._store[key];
            return true;
        }
        return false;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict_polyfill.prototype.has = (function() {
    var ρσ_anonfunc = function (x) {
        return Object.prototype.hasOwnProperty.call(this._store, ρσ_set_keyfor(x));
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict_polyfill.prototype.get = (function() {
    var ρσ_anonfunc = function (x) {
        try {
            return (ρσ_expr_temp = this._store)[ρσ_bound_index(ρσ_set_keyfor(x), ρσ_expr_temp)][1];
        } catch (ρσ_Exception) {
            ρσ_last_exception = ρσ_Exception;
            if (ρσ_Exception instanceof TypeError) {
                return undefined;
            } else {
                throw ρσ_Exception;
            }
        }
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict_polyfill.prototype.values = (function() {
    var ρσ_anonfunc = function (x) {
        var ans;
        ans = {'_keys': Object.keys(this._store), '_i':-1, '_s':this._store};
        ans[ρσ_iterator_symbol] = (function() {
            var ρσ_anonfunc = function () {
                return this;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        ans["next"] = (function() {
            var ρσ_anonfunc = function () {
                this._i += 1;
                if (this._i >= this._keys.length) {
                    return {'done': true};
                }
                return {'done':false, 'value':this._s[this._keys[this._i]][1]};
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict_polyfill.prototype.keys = (function() {
    var ρσ_anonfunc = function (x) {
        var ans;
        ans = {'_keys': Object.keys(this._store), '_i':-1, '_s':this._store};
        ans[ρσ_iterator_symbol] = (function() {
            var ρσ_anonfunc = function () {
                return this;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        ans["next"] = (function() {
            var ρσ_anonfunc = function () {
                this._i += 1;
                if (this._i >= this._keys.length) {
                    return {'done': true};
                }
                return {'done':false, 'value':this._s[this._keys[this._i]][0]};
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict_polyfill.prototype.entries = (function() {
    var ρσ_anonfunc = function (x) {
        var ans;
        ans = {'_keys': Object.keys(this._store), '_i':-1, '_s':this._store};
        ans[ρσ_iterator_symbol] = (function() {
            var ρσ_anonfunc = function () {
                return this;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        ans["next"] = (function() {
            var ρσ_anonfunc = function () {
                this._i += 1;
                if (this._i >= this._keys.length) {
                    return {'done': true};
                }
                return {'done':false, 'value':this._s[this._keys[this._i]]};
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
if (typeof Map !== "function" || typeof Map.prototype.delete !== "function") {
    ρσ_dict_implementation = ρσ_dict_polyfill;
} else {
    ρσ_dict_implementation = Map;
}
function ρσ_dict() {
    var iterable = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
    var kw = arguments[arguments.length-1];
    if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
    if (this instanceof ρσ_dict) {
        this.jsmap = new ρσ_dict_implementation;
        if (iterable !== undefined) {
            this.update(iterable);
        }
        this.update(kw);
        return this;
    } else {
        return ρσ_interpolate_kwargs_constructor.call(Object.create(ρσ_dict.prototype), false, ρσ_dict, [iterable].concat([ρσ_desugar_kwargs(kw)]));
    }
};
if (!ρσ_dict.__handles_kwarg_interpolation__) Object.defineProperties(ρσ_dict, {
    __handles_kwarg_interpolation__ : {value: true},
    __argnames__ : {value: ["iterable"]},
    __module__ : {value: "__main__"}
});

ρσ_dict.prototype.__name__ = "dict";
Object.defineProperties(ρσ_dict.prototype, (function(){
    var ρσ_d = {};
    ρσ_d["length"] = (function(){
        var ρσ_d = {};
        ρσ_d["get"] = (function() {
            var ρσ_anonfunc = function () {
                return this.jsmap.size;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ρσ_d;
    }).call(this);
    ρσ_d["size"] = (function(){
        var ρσ_d = {};
        ρσ_d["get"] = (function() {
            var ρσ_anonfunc = function () {
                return this.jsmap.size;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
        return ρσ_d;
    }).call(this);
    return ρσ_d;
}).call(this));
ρσ_dict.prototype.__len__ = (function() {
    var ρσ_anonfunc = function () {
        return this.jsmap.size;
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.has = ρσ_dict.prototype.__contains__ = (function() {
    var ρσ_anonfunc = function (x) {
        return this.jsmap.has(x);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["x"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.set = ρσ_dict.prototype.__setitem__ = (function() {
    var ρσ_anonfunc = function (key, value) {
        this.jsmap.set(key, value);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["key", "value"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.__delitem__ = (function() {
    var ρσ_anonfunc = function (key) {
        this.jsmap.delete(key);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["key"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.clear = (function() {
    var ρσ_anonfunc = function () {
        this.jsmap.clear();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.copy = (function() {
    var ρσ_anonfunc = function () {
        return ρσ_dict(this);
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.keys = (function() {
    var ρσ_anonfunc = function () {
        return this.jsmap.keys();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.values = (function() {
    var ρσ_anonfunc = function () {
        return this.jsmap.values();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.items = ρσ_dict.prototype.entries = (function() {
    var ρσ_anonfunc = function () {
        return this.jsmap.entries();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype[ρσ_iterator_symbol] = (function() {
    var ρσ_anonfunc = function () {
        return this.jsmap.keys();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.__getitem__ = (function() {
    var ρσ_anonfunc = function (key) {
        var ans;
        ans = this.jsmap.get(key);
        if (ans === undefined && !this.jsmap.has(key)) {
            throw new KeyError(key + "");
        }
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["key"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.get = (function() {
    var ρσ_anonfunc = function (key, defval) {
        var ans;
        ans = this.jsmap.get(key);
        if (ans === undefined && !this.jsmap.has(key)) {
            return (defval === undefined) ? null : defval;
        }
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["key", "defval"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.set_default = ρσ_dict.prototype.setdefault = (function() {
    var ρσ_anonfunc = function (key, defval) {
        var j;
        j = this.jsmap;
        if (!j.has(key)) {
            j.set(key, defval);
            return defval;
        }
        return j.get(key);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["key", "defval"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.fromkeys = ρσ_dict.prototype.fromkeys = (function() {
    var ρσ_anonfunc = function () {
        var iterable = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
        var value = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ρσ_anonfunc.__defaults__.value : arguments[1];
        var ρσ_kwargs_obj = arguments[arguments.length-1];
        if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
        if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "value")){
            value = ρσ_kwargs_obj.value;
        }
        var ans, iterator, r;
        ans = ρσ_dict();
        iterator = iter(iterable);
        r = iterator.next();
        while (!r.done) {
            ans.set(r.value, value);
            r = iterator.next();
        }
        return ans;
    };
    if (!ρσ_anonfunc.__defaults__) Object.defineProperties(ρσ_anonfunc, {
        __defaults__ : {value: {value:null}},
        __handles_kwarg_interpolation__ : {value: true},
        __argnames__ : {value: ["iterable", "value"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.pop = (function() {
    var ρσ_anonfunc = function (key, defval) {
        var ans;
        ans = this.jsmap.get(key);
        if (ans === undefined && !this.jsmap.has(key)) {
            if (defval === undefined) {
                throw new KeyError(key);
            }
            return defval;
        }
        this.jsmap.delete(key);
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["key", "defval"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.popitem = (function() {
    var ρσ_anonfunc = function () {
        var last, e, r;
        last = null;
        e = this.jsmap.entries();
        while (true) {
            r = e.next();
            if (r.done) {
                if (last === null) {
                    throw new KeyError("dict is empty");
                }
                this.jsmap.delete(last.value[0]);
                return last.value;
            }
            last = r;
        }
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.update = (function() {
    var ρσ_anonfunc = function () {
        var m, iterable, iterator, result, keys;
        if (arguments.length === 0) {
            return;
        }
        m = this.jsmap;
        iterable = arguments[0];
        if (Array.isArray(iterable)) {
            for (var i = 0; i < iterable.length; i++) {
                m.set(iterable[(typeof i === "number" && i < 0) ? iterable.length + i : i][0], iterable[(typeof i === "number" && i < 0) ? iterable.length + i : i][1]);
            }
        } else if (iterable instanceof ρσ_dict) {
            iterator = iterable.items();
            result = iterator.next();
            while (!result.done) {
                m.set(result.value[0], result.value[1]);
                result = iterator.next();
            }
        } else if (typeof Map === "function" && iterable instanceof Map) {
            iterator = iterable.entries();
            result = iterator.next();
            while (!result.done) {
                m.set(result.value[0], result.value[1]);
                result = iterator.next();
            }
        } else if (typeof iterable[ρσ_iterator_symbol] === "function") {
            iterator = iterable[ρσ_iterator_symbol]();
            result = iterator.next();
            while (!result.done) {
                m.set(result.value[0], result.value[1]);
                result = iterator.next();
            }
        } else {
            keys = Object.keys(iterable);
            for (var j=0; j < keys.length; j++) {
                if (keys[(typeof j === "number" && j < 0) ? keys.length + j : j] !== ρσ_iterator_symbol) {
                    m.set(keys[(typeof j === "number" && j < 0) ? keys.length + j : j], iterable[ρσ_bound_index(keys[(typeof j === "number" && j < 0) ? keys.length + j : j], iterable)]);
                }
            }
        }
        if (arguments.length > 1) {
            ρσ_dict.prototype.update.call(this, arguments[1]);
        }
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.toString = ρσ_dict.prototype.inspect = ρσ_dict.prototype.__str__ = ρσ_dict.prototype.__repr__ = (function() {
    var ρσ_anonfunc = function () {
        var entries, iterator, r;
        entries = [];
        iterator = this.jsmap.entries();
        r = iterator.next();
        while (!r.done) {
            entries.push(ρσ_repr(r.value[0]) + ": " + ρσ_repr(r.value[1]));
            r = iterator.next();
        }
        return "{" + entries.join(", ") + "}";
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.__eq__ = (function() {
    var ρσ_anonfunc = function (other) {
        var iterator, r, x;
        if (!(other instanceof this.constructor)) {
            return false;
        }
        if (other.size !== this.size) {
            return false;
        }
        if (other.size === 0) {
            return true;
        }
        iterator = other.items();
        r = iterator.next();
        while (!r.done) {
            x = this.jsmap.get(r.value[0]);
            if (x === undefined && !this.jsmap.has(r.value[0]) || x !== r.value[1]) {
                return false;
            }
            r = iterator.next();
        }
        return true;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["other"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_dict.prototype.as_object = (function() {
    var ρσ_anonfunc = function (other) {
        var ans, iterator, r;
        ans = {};
        iterator = this.jsmap.entries();
        r = iterator.next();
        while (!r.done) {
            ans[ρσ_bound_index(r.value[0], ans)] = r.value[1];
            r = iterator.next();
        }
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["other"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
function ρσ_dict_wrap(x) {
    var ans;
    ans = new ρσ_dict;
    ans.jsmap = x;
    return ans;
};
if (!ρσ_dict_wrap.__argnames__) Object.defineProperties(ρσ_dict_wrap, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

var dict = ρσ_dict, dict_wrap = ρσ_dict_wrap;// }}}
var NameError;
NameError = ReferenceError;
function Exception() {
    if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
    Exception.prototype.__init__.apply(this, arguments);
}
ρσ_extends(Exception, Error);
Exception.prototype.__init__ = function __init__(message) {
    var self = this;
    self.message = message;
    self.stack = (new Error).stack;
    self.name = self.constructor.name;
};
if (!Exception.prototype.__init__.__argnames__) Object.defineProperties(Exception.prototype.__init__, {
    __argnames__ : {value: ["message"]},
    __module__ : {value: "__main__"}
});
Exception.__argnames__ = Exception.prototype.__init__.__argnames__;
Exception.__handles_kwarg_interpolation__ = Exception.prototype.__init__.__handles_kwarg_interpolation__;
Exception.prototype.__repr__ = function __repr__() {
    var self = this;
    return self.name + ": " + self.message;
};
if (!Exception.prototype.__repr__.__module__) Object.defineProperties(Exception.prototype.__repr__, {
    __module__ : {value: "__main__"}
});
Exception.prototype.__str__ = function __str__ () {
    if(Error.prototype.__str__) return Error.prototype.__str__.call(this);
return this.__repr__();
};
Object.defineProperty(Exception.prototype, "__bases__", {value: [Error]});

function AttributeError() {
    if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
    AttributeError.prototype.__init__.apply(this, arguments);
}
ρσ_extends(AttributeError, Exception);
AttributeError.prototype.__init__ = function __init__ () {
    Exception.prototype.__init__ && Exception.prototype.__init__.apply(this, arguments);
};
AttributeError.prototype.__repr__ = function __repr__ () {
    if(Exception.prototype.__repr__) return Exception.prototype.__repr__.call(this);
    return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
};
AttributeError.prototype.__str__ = function __str__ () {
    if(Exception.prototype.__str__) return Exception.prototype.__str__.call(this);
return this.__repr__();
};
Object.defineProperty(AttributeError.prototype, "__bases__", {value: [Exception]});


function IndexError() {
    if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
    IndexError.prototype.__init__.apply(this, arguments);
}
ρσ_extends(IndexError, Exception);
IndexError.prototype.__init__ = function __init__ () {
    Exception.prototype.__init__ && Exception.prototype.__init__.apply(this, arguments);
};
IndexError.prototype.__repr__ = function __repr__ () {
    if(Exception.prototype.__repr__) return Exception.prototype.__repr__.call(this);
    return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
};
IndexError.prototype.__str__ = function __str__ () {
    if(Exception.prototype.__str__) return Exception.prototype.__str__.call(this);
return this.__repr__();
};
Object.defineProperty(IndexError.prototype, "__bases__", {value: [Exception]});


function KeyError() {
    if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
    KeyError.prototype.__init__.apply(this, arguments);
}
ρσ_extends(KeyError, Exception);
KeyError.prototype.__init__ = function __init__ () {
    Exception.prototype.__init__ && Exception.prototype.__init__.apply(this, arguments);
};
KeyError.prototype.__repr__ = function __repr__ () {
    if(Exception.prototype.__repr__) return Exception.prototype.__repr__.call(this);
    return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
};
KeyError.prototype.__str__ = function __str__ () {
    if(Exception.prototype.__str__) return Exception.prototype.__str__.call(this);
return this.__repr__();
};
Object.defineProperty(KeyError.prototype, "__bases__", {value: [Exception]});


function ValueError() {
    if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
    ValueError.prototype.__init__.apply(this, arguments);
}
ρσ_extends(ValueError, Exception);
ValueError.prototype.__init__ = function __init__ () {
    Exception.prototype.__init__ && Exception.prototype.__init__.apply(this, arguments);
};
ValueError.prototype.__repr__ = function __repr__ () {
    if(Exception.prototype.__repr__) return Exception.prototype.__repr__.call(this);
    return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
};
ValueError.prototype.__str__ = function __str__ () {
    if(Exception.prototype.__str__) return Exception.prototype.__str__.call(this);
return this.__repr__();
};
Object.defineProperty(ValueError.prototype, "__bases__", {value: [Exception]});


function UnicodeDecodeError() {
    if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
    UnicodeDecodeError.prototype.__init__.apply(this, arguments);
}
ρσ_extends(UnicodeDecodeError, Exception);
UnicodeDecodeError.prototype.__init__ = function __init__ () {
    Exception.prototype.__init__ && Exception.prototype.__init__.apply(this, arguments);
};
UnicodeDecodeError.prototype.__repr__ = function __repr__ () {
    if(Exception.prototype.__repr__) return Exception.prototype.__repr__.call(this);
    return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
};
UnicodeDecodeError.prototype.__str__ = function __str__ () {
    if(Exception.prototype.__str__) return Exception.prototype.__str__.call(this);
return this.__repr__();
};
Object.defineProperty(UnicodeDecodeError.prototype, "__bases__", {value: [Exception]});


function AssertionError() {
    if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
    AssertionError.prototype.__init__.apply(this, arguments);
}
ρσ_extends(AssertionError, Exception);
AssertionError.prototype.__init__ = function __init__ () {
    Exception.prototype.__init__ && Exception.prototype.__init__.apply(this, arguments);
};
AssertionError.prototype.__repr__ = function __repr__ () {
    if(Exception.prototype.__repr__) return Exception.prototype.__repr__.call(this);
    return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
};
AssertionError.prototype.__str__ = function __str__ () {
    if(Exception.prototype.__str__) return Exception.prototype.__str__.call(this);
return this.__repr__();
};
Object.defineProperty(AssertionError.prototype, "__bases__", {value: [Exception]});


function ZeroDivisionError() {
    if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
    ZeroDivisionError.prototype.__init__.apply(this, arguments);
}
ρσ_extends(ZeroDivisionError, Exception);
ZeroDivisionError.prototype.__init__ = function __init__ () {
    Exception.prototype.__init__ && Exception.prototype.__init__.apply(this, arguments);
};
ZeroDivisionError.prototype.__repr__ = function __repr__ () {
    if(Exception.prototype.__repr__) return Exception.prototype.__repr__.call(this);
    return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
};
ZeroDivisionError.prototype.__str__ = function __str__ () {
    if(Exception.prototype.__str__) return Exception.prototype.__str__.call(this);
return this.__repr__();
};
Object.defineProperty(ZeroDivisionError.prototype, "__bases__", {value: [Exception]});

var ρσ_in, ρσ_desugar_kwargs, ρσ_exists;
function ρσ_eslice(arr, step, start, end) {
    var is_string;
    if (typeof arr === "string" || arr instanceof String) {
        is_string = true;
        arr = arr.split("");
    }
    if (step < 0) {
        step = -step;
        arr = arr.slice().reverse();
        if (typeof start !== "undefined") {
            start = arr.length - start - 1;
        }
        if (typeof end !== "undefined") {
            end = arr.length - end - 1;
        }
    }
    if (typeof start === "undefined") {
        start = 0;
    }
    if (typeof end === "undefined") {
        end = arr.length;
    }
    arr = arr.slice(start, end).filter((function() {
        var ρσ_anonfunc = function (e, i) {
            return i % step === 0;
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["e", "i"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })());
    if (is_string) {
        arr = arr.join("");
    }
    return arr;
};
if (!ρσ_eslice.__argnames__) Object.defineProperties(ρσ_eslice, {
    __argnames__ : {value: ["arr", "step", "start", "end"]},
    __module__ : {value: "__main__"}
});

function ρσ_delslice(arr, step, start, end) {
    var is_string, ρσ_unpack, indices;
    if (typeof arr === "string" || arr instanceof String) {
        is_string = true;
        arr = arr.split("");
    }
    if (step < 0) {
        if (typeof start === "undefined") {
            start = arr.length;
        }
        if (typeof end === "undefined") {
            end = 0;
        }
        ρσ_unpack = [end, start, -step];
        start = ρσ_unpack[0];
        end = ρσ_unpack[1];
        step = ρσ_unpack[2];
    }
    if (typeof start === "undefined") {
        start = 0;
    }
    if (typeof end === "undefined") {
        end = arr.length;
    }
    if (step === 1) {
        arr.splice(start, end - start);
    } else {
        if (end > start) {
            indices = [];
            for (var i = start; i < end; i += step) {
                indices.push(i);
            }
            for (var i = indices.length - 1; i >= 0; i--) {
                arr.splice(indices[(typeof i === "number" && i < 0) ? indices.length + i : i], 1);
            }
        }
    }
    if (is_string) {
        arr = arr.join("");
    }
    return arr;
};
if (!ρσ_delslice.__argnames__) Object.defineProperties(ρσ_delslice, {
    __argnames__ : {value: ["arr", "step", "start", "end"]},
    __module__ : {value: "__main__"}
});

function ρσ_flatten(arr) {
    var ans, value;
    ans = ρσ_list_decorate([]);
    for (var i=0; i < arr.length; i++) {
        value = arr[(typeof i === "number" && i < 0) ? arr.length + i : i];
        if (Array.isArray(value)) {
            ans = ans.concat(ρσ_flatten(value));
        } else {
            ans.push(value);
        }
    }
    return ans;
};
if (!ρσ_flatten.__argnames__) Object.defineProperties(ρσ_flatten, {
    __argnames__ : {value: ["arr"]},
    __module__ : {value: "__main__"}
});

function ρσ_unpack_asarray(num, iterable) {
    var ans, iterator, result;
    if (ρσ_arraylike(iterable)) {
        return iterable;
    }
    ans = [];
    if (typeof iterable[ρσ_iterator_symbol] === "function") {
        iterator = (typeof Map === "function" && iterable instanceof Map) ? iterable.keys() : iterable[ρσ_iterator_symbol]();
        result = iterator.next();
        while (!result.done && ans.length < num) {
            ans.push(result.value);
            result = iterator.next();
        }
    }
    return ans;
};
if (!ρσ_unpack_asarray.__argnames__) Object.defineProperties(ρσ_unpack_asarray, {
    __argnames__ : {value: ["num", "iterable"]},
    __module__ : {value: "__main__"}
});

function ρσ_extends(child, parent) {
    child.prototype = Object.create(parent.prototype);
    child.prototype.constructor = child;
};
if (!ρσ_extends.__argnames__) Object.defineProperties(ρσ_extends, {
    __argnames__ : {value: ["child", "parent"]},
    __module__ : {value: "__main__"}
});

ρσ_in = (function() {
    var ρσ_anonfunc = function () {
        if (typeof Map === "function" && typeof Set === "function") {
            return (function() {
                var ρσ_anonfunc = function (val, arr) {
                    if (typeof arr === "string") {
                        return arr.indexOf(val) !== -1;
                    }
                    if (typeof arr.__contains__ === "function") {
                        return arr.__contains__(val);
                    }
                    if (arr instanceof Map || arr instanceof Set) {
                        return arr.has(val);
                    }
                    if (ρσ_arraylike(arr)) {
                        return ρσ_list_contains.call(arr, val);
                    }
                    return Object.prototype.hasOwnProperty.call(arr, val);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["val", "arr"]},
                    __module__ : {value: "__main__"}
                });
                return ρσ_anonfunc;
            })();
        }
        return (function() {
            var ρσ_anonfunc = function (val, arr) {
                if (typeof arr === "string") {
                    return arr.indexOf(val) !== -1;
                }
                if (typeof arr.__contains__ === "function") {
                    return arr.__contains__(val);
                }
                if (ρσ_arraylike(arr)) {
                    return ρσ_list_contains.call(arr, val);
                }
                return Object.prototype.hasOwnProperty.call(arr, val);
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["val", "arr"]},
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})()();
function ρσ_Iterable(iterable) {
    var iterator, ans, result;
    if (ρσ_arraylike(iterable)) {
        return iterable;
    }
    if (typeof iterable[ρσ_iterator_symbol] === "function") {
        iterator = (typeof Map === "function" && iterable instanceof Map) ? iterable.keys() : iterable[ρσ_iterator_symbol]();
        ans = ρσ_list_decorate([]);
        result = iterator.next();
        while (!result.done) {
            ans.push(result.value);
            result = iterator.next();
        }
        return ans;
    }
    return Object.keys(iterable);
};
if (!ρσ_Iterable.__argnames__) Object.defineProperties(ρσ_Iterable, {
    __argnames__ : {value: ["iterable"]},
    __module__ : {value: "__main__"}
});

ρσ_desugar_kwargs = (function() {
    var ρσ_anonfunc = function () {
        if (typeof Object.assign === "function") {
            return (function() {
                var ρσ_anonfunc = function () {
                    var ans;
                    ans = Object.create(null);
                    ans[ρσ_kwargs_symbol] = true;
                    for (var i = 0; i < arguments.length; i++) {
                        Object.assign(ans, arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i]);
                    }
                    return ans;
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "__main__"}
                });
                return ρσ_anonfunc;
            })();
        }
        return (function() {
            var ρσ_anonfunc = function () {
                var ans, keys;
                ans = Object.create(null);
                ans[ρσ_kwargs_symbol] = true;
                for (var i = 0; i < arguments.length; i++) {
                    keys = Object.keys(arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i]);
                    for (var j = 0; j < keys.length; j++) {
                        ans[ρσ_bound_index(keys[(typeof j === "number" && j < 0) ? keys.length + j : j], ans)] = (ρσ_expr_temp = arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i])[ρσ_bound_index(keys[(typeof j === "number" && j < 0) ? keys.length + j : j], ρσ_expr_temp)];
                    }
                }
                return ans;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})()();
function ρσ_interpolate_kwargs(f, supplied_args) {
    var has_prop, kwobj, args, prop;
    if (!f.__argnames__) {
        return f.apply(this, supplied_args);
    }
    has_prop = Object.prototype.hasOwnProperty;
    kwobj = supplied_args.pop();
    if (f.__handles_kwarg_interpolation__) {
        args = new Array(Math.max(supplied_args.length, f.__argnames__.length) + 1);
        args[args.length-1] = kwobj;
        for (var i = 0; i < args.length - 1; i++) {
            if (i < f.__argnames__.length) {
                prop = (ρσ_expr_temp = f.__argnames__)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
                if (has_prop.call(kwobj, prop)) {
                    args[(typeof i === "number" && i < 0) ? args.length + i : i] = kwobj[(typeof prop === "number" && prop < 0) ? kwobj.length + prop : prop];
                    delete kwobj[prop];
                } else if (i < supplied_args.length) {
                    args[(typeof i === "number" && i < 0) ? args.length + i : i] = supplied_args[(typeof i === "number" && i < 0) ? supplied_args.length + i : i];
                }
            } else {
                args[(typeof i === "number" && i < 0) ? args.length + i : i] = supplied_args[(typeof i === "number" && i < 0) ? supplied_args.length + i : i];
            }
        }
        return f.apply(this, args);
    }
    for (var i = 0; i < f.__argnames__.length; i++) {
        prop = (ρσ_expr_temp = f.__argnames__)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
        if (has_prop.call(kwobj, prop)) {
            supplied_args[(typeof i === "number" && i < 0) ? supplied_args.length + i : i] = kwobj[(typeof prop === "number" && prop < 0) ? kwobj.length + prop : prop];
        }
    }
    return f.apply(this, supplied_args);
};
if (!ρσ_interpolate_kwargs.__argnames__) Object.defineProperties(ρσ_interpolate_kwargs, {
    __argnames__ : {value: ["f", "supplied_args"]},
    __module__ : {value: "__main__"}
});

function ρσ_interpolate_kwargs_constructor(apply, f, supplied_args) {
    if (apply) {
        f.apply(this, supplied_args);
    } else {
        ρσ_interpolate_kwargs.call(this, f, supplied_args);
    }
    return this;
};
if (!ρσ_interpolate_kwargs_constructor.__argnames__) Object.defineProperties(ρσ_interpolate_kwargs_constructor, {
    __argnames__ : {value: ["apply", "f", "supplied_args"]},
    __module__ : {value: "__main__"}
});

function ρσ_getitem(obj, key) {
    if (obj.__getitem__) {
        return obj.__getitem__(key);
    }
    if (typeof key === "number" && key < 0) {
        key += obj.length;
    }
    return obj[(typeof key === "number" && key < 0) ? obj.length + key : key];
};
if (!ρσ_getitem.__argnames__) Object.defineProperties(ρσ_getitem, {
    __argnames__ : {value: ["obj", "key"]},
    __module__ : {value: "__main__"}
});

function ρσ_setitem(obj, key, val) {
    if (obj.__setitem__) {
        obj.__setitem__(key, val);
    } else {
        if (typeof key === "number" && key < 0) {
            key += obj.length;
        }
        obj[(typeof key === "number" && key < 0) ? obj.length + key : key] = val;
    }
    return val;
};
if (!ρσ_setitem.__argnames__) Object.defineProperties(ρσ_setitem, {
    __argnames__ : {value: ["obj", "key", "val"]},
    __module__ : {value: "__main__"}
});

function ρσ_delitem(obj, key) {
    if (obj.__delitem__) {
        obj.__delitem__(key);
    } else if (typeof obj.splice === "function") {
        obj.splice(key, 1);
    } else {
        if (typeof key === "number" && key < 0) {
            key += obj.length;
        }
        delete obj[key];
    }
};
if (!ρσ_delitem.__argnames__) Object.defineProperties(ρσ_delitem, {
    __argnames__ : {value: ["obj", "key"]},
    __module__ : {value: "__main__"}
});

function ρσ_bound_index(idx, arr) {
    if (typeof idx === "number" && idx < 0) {
        idx += arr.length;
    }
    return idx;
};
if (!ρσ_bound_index.__argnames__) Object.defineProperties(ρσ_bound_index, {
    __argnames__ : {value: ["idx", "arr"]},
    __module__ : {value: "__main__"}
});

function ρσ_splice(arr, val, start, end) {
    start = start || 0;
    if (start < 0) {
        start += arr.length;
    }
    if (end === undefined) {
        end = arr.length;
    }
    if (end < 0) {
        end += arr.length;
    }
    Array.prototype.splice.apply(arr, [start, end - start].concat(val));
};
if (!ρσ_splice.__argnames__) Object.defineProperties(ρσ_splice, {
    __argnames__ : {value: ["arr", "val", "start", "end"]},
    __module__ : {value: "__main__"}
});

ρσ_exists = (function(){
    var ρσ_d = {};
    ρσ_d["n"] = (function() {
        var ρσ_anonfunc = function (expr) {
            return expr !== undefined && expr !== null;
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["expr"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ρσ_d["d"] = (function() {
        var ρσ_anonfunc = function (expr) {
            if (expr === undefined || expr === null) {
                return Object.create(null);
            }
            return expr;
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["expr"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ρσ_d["c"] = (function() {
        var ρσ_anonfunc = function (expr) {
            if (typeof expr === "function") {
                return expr;
            }
            return (function() {
                var ρσ_anonfunc = function () {
                    return undefined;
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "__main__"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["expr"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ρσ_d["g"] = (function() {
        var ρσ_anonfunc = function (expr) {
            if (expr === undefined || expr === null || typeof expr.__getitem__ !== "function") {
                return (function(){
                    var ρσ_d = {};
                    ρσ_d["__getitem__"] = (function() {
                        var ρσ_anonfunc = function () {
                            return undefined;
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "__main__"}
                        });
                        return ρσ_anonfunc;
                    })();
                    return ρσ_d;
                }).call(this);
            }
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["expr"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ρσ_d["e"] = (function() {
        var ρσ_anonfunc = function (expr, alt) {
            return (expr === undefined || expr === null) ? alt : expr;
        };
        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
            __argnames__ : {value: ["expr", "alt"]},
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    return ρσ_d;
}).call(this);
function ρσ_mixin() {
    var seen, resolved_props, p, target, props, name;
    seen = Object.create(null);
    seen.__argnames__ = seen.__handles_kwarg_interpolation__ = seen.__init__ = seen.__annotations__ = seen.__doc__ = seen.__bind_methods__ = seen.__bases__ = seen.constructor = seen.__class__ = true;
    resolved_props = {};
    p = target = arguments[0].prototype;
    while (p && p !== Object.prototype) {
        props = Object.getOwnPropertyNames(p);
        for (var i = 0; i < props.length; i++) {
            seen[ρσ_bound_index(props[(typeof i === "number" && i < 0) ? props.length + i : i], seen)] = true;
        }
        p = Object.getPrototypeOf(p);
    }
    for (var c = 1; c < arguments.length; c++) {
        p = arguments[(typeof c === "number" && c < 0) ? arguments.length + c : c].prototype;
        while (p && p !== Object.prototype) {
            props = Object.getOwnPropertyNames(p);
            for (var i = 0; i < props.length; i++) {
                name = props[(typeof i === "number" && i < 0) ? props.length + i : i];
                if (seen[(typeof name === "number" && name < 0) ? seen.length + name : name]) {
                    continue;
                }
                seen[(typeof name === "number" && name < 0) ? seen.length + name : name] = true;
                resolved_props[(typeof name === "number" && name < 0) ? resolved_props.length + name : name] = Object.getOwnPropertyDescriptor(p, name);
            }
            p = Object.getPrototypeOf(p);
        }
    }
    Object.defineProperties(target, resolved_props);
};
if (!ρσ_mixin.__module__) Object.defineProperties(ρσ_mixin, {
    __module__ : {value: "__main__"}
});

function ρσ_instanceof() {
    var obj, bases, q, cls, p;
    obj = arguments[0];
    bases = "";
    if (obj && obj.constructor && obj.constructor.prototype) {
        bases = obj.constructor.prototype.__bases__ || "";
    }
    for (var i = 1; i < arguments.length; i++) {
        q = arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i];
        if (obj instanceof q) {
            return true;
        }
        if ((q === Array || q === ρσ_list_constructor) && Array.isArray(obj)) {
            return true;
        }
        if (q === ρσ_str && (typeof obj === "string" || obj instanceof String)) {
            return true;
        }
        if (q === ρσ_int && typeof obj === "number" && Number.isInteger(obj)) {
            return true;
        }
        if (q === ρσ_float && typeof obj === "number" && !Number.isInteger(obj)) {
            return true;
        }
        if (bases.length > 1) {
            for (var c = 1; c < bases.length; c++) {
                cls = bases[(typeof c === "number" && c < 0) ? bases.length + c : c];
                while (cls) {
                    if (q === cls) {
                        return true;
                    }
                    p = Object.getPrototypeOf(cls.prototype);
                    if (!p) {
                        break;
                    }
                    cls = p.constructor;
                }
            }
        }
    }
    return false;
};
if (!ρσ_instanceof.__module__) Object.defineProperties(ρσ_instanceof, {
    __module__ : {value: "__main__"}
});
function sum(iterable, start) {
    var ans, iterator, r;
    if (Array.isArray(iterable)) {
        return iterable.reduce((function() {
            var ρσ_anonfunc = function (prev, cur) {
                return prev + cur;
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["prev", "cur"]},
                __module__ : {value: "__main__"}
            });
            return ρσ_anonfunc;
        })(), start || 0);
    }
    ans = start || 0;
    iterator = iter(iterable);
    r = iterator.next();
    while (!r.done) {
        ans += r.value;
        r = iterator.next();
    }
    return ans;
};
if (!sum.__argnames__) Object.defineProperties(sum, {
    __argnames__ : {value: ["iterable", "start"]},
    __module__ : {value: "__main__"}
});

function map() {
    var iterators, func, args, ans;
    iterators = new Array(arguments.length - 1);
    func = arguments[0];
    args = new Array(arguments.length - 1);
    for (var i = 1; i < arguments.length; i++) {
        iterators[ρσ_bound_index(i - 1, iterators)] = iter(arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i]);
    }
    ans = {'_func':func, '_iterators':iterators, '_args':args};
    ans[ρσ_iterator_symbol] = (function() {
        var ρσ_anonfunc = function () {
            return this;
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ans["next"] = (function() {
        var ρσ_anonfunc = function () {
            var r;
            for (var i = 0; i < this._iterators.length; i++) {
                r = (ρσ_expr_temp = this._iterators)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i].next();
                if (r.done) {
                    return {'done':true};
                }
                (ρσ_expr_temp = this._args)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] = r.value;
            }
            return {'done':false, 'value':this._func.apply(undefined, this._args)};
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    return ans;
};
if (!map.__module__) Object.defineProperties(map, {
    __module__ : {value: "__main__"}
});

function filter(func_or_none, iterable) {
    var func, ans;
    func = (func_or_none === null) ? ρσ_bool : func_or_none;
    ans = {'_func':func, '_iterator':ρσ_iter(iterable)};
    ans[ρσ_iterator_symbol] = (function() {
        var ρσ_anonfunc = function () {
            return this;
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ans["next"] = (function() {
        var ρσ_anonfunc = function () {
            var r;
            r = this._iterator.next();
            while (!r.done) {
                if (this._func(r.value)) {
                    return r;
                }
                r = this._iterator.next();
            }
            return {'done':true};
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    return ans;
};
if (!filter.__argnames__) Object.defineProperties(filter, {
    __argnames__ : {value: ["func_or_none", "iterable"]},
    __module__ : {value: "__main__"}
});

function zip() {
    var iterators, ans;
    iterators = new Array(arguments.length);
    for (var i = 0; i < arguments.length; i++) {
        iterators[(typeof i === "number" && i < 0) ? iterators.length + i : i] = iter(arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i]);
    }
    ans = {'_iterators':iterators};
    ans[ρσ_iterator_symbol] = (function() {
        var ρσ_anonfunc = function () {
            return this;
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    ans["next"] = (function() {
        var ρσ_anonfunc = function () {
            var args, r;
            args = new Array(this._iterators.length);
            for (var i = 0; i < this._iterators.length; i++) {
                r = (ρσ_expr_temp = this._iterators)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i].next();
                if (r.done) {
                    return {'done':true};
                }
                args[(typeof i === "number" && i < 0) ? args.length + i : i] = r.value;
            }
            return {'done':false, 'value':args};
        };
        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
            __module__ : {value: "__main__"}
        });
        return ρσ_anonfunc;
    })();
    return ans;
};
if (!zip.__module__) Object.defineProperties(zip, {
    __module__ : {value: "__main__"}
});

function any(iterable) {
    var i;
    var ρσ_Iter0 = ρσ_Iterable(iterable);
    for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
        i = ρσ_Iter0[ρσ_Index0];
        if (i) {
            return true;
        }
    }
    return false;
};
if (!any.__argnames__) Object.defineProperties(any, {
    __argnames__ : {value: ["iterable"]},
    __module__ : {value: "__main__"}
});

function all(iterable) {
    var i;
    var ρσ_Iter1 = ρσ_Iterable(iterable);
    for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
        i = ρσ_Iter1[ρσ_Index1];
        if (!i) {
            return false;
        }
    }
    return true;
};
if (!all.__argnames__) Object.defineProperties(all, {
    __argnames__ : {value: ["iterable"]},
    __module__ : {value: "__main__"}
});
var decimal_sep, define_str_func, ρσ_unpack, ρσ_orig_split, ρσ_orig_replace;
decimal_sep = 1.1.toLocaleString()[1];
function ρσ_repr_js_builtin(x, as_array) {
    var ans, b, keys, key;
    ans = [];
    b = "{}";
    if (as_array) {
        b = "[]";
        for (var i = 0; i < x.length; i++) {
            ans.push(ρσ_repr(x[(typeof i === "number" && i < 0) ? x.length + i : i]));
        }
    } else {
        keys = Object.keys(x);
        for (var k = 0; k < keys.length; k++) {
            key = keys[(typeof k === "number" && k < 0) ? keys.length + k : k];
            ans.push(JSON.stringify(key) + ":" + ρσ_repr(x[(typeof key === "number" && key < 0) ? x.length + key : key]));
        }
    }
    return b[0] + ans.join(", ") + b[1];
};
if (!ρσ_repr_js_builtin.__argnames__) Object.defineProperties(ρσ_repr_js_builtin, {
    __argnames__ : {value: ["x", "as_array"]},
    __module__ : {value: "__main__"}
});

function ρσ_html_element_to_string(elem) {
    var attrs, val, attr, ans;
    attrs = [];
    var ρσ_Iter0 = ρσ_Iterable(elem.attributes);
    for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
        attr = ρσ_Iter0[ρσ_Index0];
        if (attr.specified) {
            val = attr.value;
            if (val.length > 10) {
                val = val.slice(0, 15) + "...";
            }
            val = JSON.stringify(val);
            attrs.push("" + ρσ_str.format("{}", attr.name) + "=" + ρσ_str.format("{}", val) + "");
        }
    }
    attrs = (attrs.length) ? " " + attrs.join(" ") : "";
    ans = "<" + ρσ_str.format("{}", elem.tagName) + "" + ρσ_str.format("{}", attrs) + ">";
    return ans;
};
if (!ρσ_html_element_to_string.__argnames__) Object.defineProperties(ρσ_html_element_to_string, {
    __argnames__ : {value: ["elem"]},
    __module__ : {value: "__main__"}
});

function ρσ_repr(x) {
    var ans, name;
    if (x === null) {
        return "None";
    }
    if (x === undefined) {
        return "undefined";
    }
    ans = x;
    if (typeof x.__repr__ === "function") {
        ans = x.__repr__();
    } else if (x === true || x === false) {
        ans = (x) ? "True" : "False";
    } else if (Array.isArray(x)) {
        ans = ρσ_repr_js_builtin(x, true);
    } else if (typeof x === "function") {
        ans = x.toString();
    } else if (typeof x === "object" && !x.toString) {
        ans = ρσ_repr_js_builtin(x);
    } else {
        name = Object.prototype.toString.call(x).slice(8, -1);
        if (ρσ_not_equals("Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".indexOf(name), -1)) {
            return name + "([" + x.map((function() {
                var ρσ_anonfunc = function (i) {
                    return str.format("0x{:02x}", i);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["i"]},
                    __module__ : {value: "__main__"}
                });
                return ρσ_anonfunc;
            })()).join(", ") + "])";
        }
        if (typeof HTMLElement !== "undefined" && x instanceof HTMLElement) {
            ans = ρσ_html_element_to_string(x);
        } else {
            ans = (typeof x.toString === "function") ? x.toString() : x;
        }
        if (ans === "[object Object]") {
            return ρσ_repr_js_builtin(x);
        }
        try {
            ans = JSON.stringify(x);
        } catch (ρσ_Exception) {
            ρσ_last_exception = ρσ_Exception;
            {
            } 
        }
    }
    return ans + "";
};
if (!ρσ_repr.__argnames__) Object.defineProperties(ρσ_repr, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

function ρσ_str(x) {
    var ans, name;
    if (x === null) {
        return "None";
    }
    if (x === undefined) {
        return "undefined";
    }
    ans = x;
    if (typeof x.__str__ === "function") {
        ans = x.__str__();
    } else if (typeof x.__repr__ === "function") {
        ans = x.__repr__();
    } else if (x === true || x === false) {
        ans = (x) ? "True" : "False";
    } else if (Array.isArray(x)) {
        ans = ρσ_repr_js_builtin(x, true);
    } else if (typeof x.toString === "function") {
        name = Object.prototype.toString.call(x).slice(8, -1);
        if (ρσ_not_equals("Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".indexOf(name), -1)) {
            return name + "([" + x.map((function() {
                var ρσ_anonfunc = function (i) {
                    return str.format("0x{:02x}", i);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["i"]},
                    __module__ : {value: "__main__"}
                });
                return ρσ_anonfunc;
            })()).join(", ") + "])";
        }
        if (typeof HTMLElement !== "undefined" && x instanceof HTMLElement) {
            ans = ρσ_html_element_to_string(x);
        } else {
            ans = x.toString();
        }
        if (ans === "[object Object]") {
            ans = ρσ_repr_js_builtin(x);
        }
    } else if (typeof x === "object" && !x.toString) {
        ans = ρσ_repr_js_builtin(x);
    }
    return ans + "";
};
if (!ρσ_str.__argnames__) Object.defineProperties(ρσ_str, {
    __argnames__ : {value: ["x"]},
    __module__ : {value: "__main__"}
});

define_str_func = (function() {
    var ρσ_anonfunc = function (name, func) {
        var f;
        (ρσ_expr_temp = ρσ_str.prototype)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name] = func;
        ρσ_str[(typeof name === "number" && name < 0) ? ρσ_str.length + name : name] = f = func.call.bind(func);
        if (func.__argnames__) {
            Object.defineProperty(f, "__argnames__", (function(){
                var ρσ_d = {};
                ρσ_d["value"] = ['string'].concat(func.__argnames__);
                return ρσ_d;
            }).call(this));
        }
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["name", "func"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_unpack = [String.prototype.split.call.bind(String.prototype.split), String.prototype.replace.call.bind(String.prototype.replace)];
ρσ_orig_split = ρσ_unpack[0];
ρσ_orig_replace = ρσ_unpack[1];
define_str_func("format", (function() {
    var ρσ_anonfunc = function () {
        var template, args, kwargs, explicit, implicit, idx, split, ans, pos, in_brace, markup, ch;
        template = this;
        if (template === undefined) {
            throw new TypeError("Template is required");
        }
        args = Array.prototype.slice.call(arguments);
        kwargs = {};
        if (args[args.length-1] && args[args.length-1][ρσ_kwargs_symbol] !== undefined) {
            kwargs = args[args.length-1];
            args = args.slice(0, -1);
        }
        explicit = implicit = false;
        idx = 0;
        split = ρσ_orig_split;
        if (ρσ_str.format._template_resolve_pat === undefined) {
            ρσ_str.format._template_resolve_pat = /[.\[]/;
        }
        function resolve(arg, object) {
            var ρσ_unpack, first, key, rest, ans;
            if (!arg) {
                return object;
            }
            ρσ_unpack = [arg[0], arg.slice(1)];
            first = ρσ_unpack[0];
            arg = ρσ_unpack[1];
            key = split(arg, ρσ_str.format._template_resolve_pat, 1)[0];
            rest = arg.slice(key.length);
            ans = (first === "[") ? object[ρσ_bound_index(key.slice(0, -1), object)] : getattr(object, key);
            if (ans === undefined) {
                throw new KeyError((first === "[") ? key.slice(0, -1) : key);
            }
            return resolve(rest, ans);
        };
        if (!resolve.__argnames__) Object.defineProperties(resolve, {
            __argnames__ : {value: ["arg", "object"]},
            __module__ : {value: "__main__"}
        });

        function resolve_format_spec(format_spec) {
            if (ρσ_str.format._template_resolve_fs_pat === undefined) {
                ρσ_str.format._template_resolve_fs_pat = /[{]([a-zA-Z0-9_]+)[}]/g;
            }
            return format_spec.replace(ρσ_str.format._template_resolve_fs_pat, (function() {
                var ρσ_anonfunc = function (match, key) {
                    if (!Object.prototype.hasOwnProperty.call(kwargs, key)) {
                        return "";
                    }
                    return "" + kwargs[(typeof key === "number" && key < 0) ? kwargs.length + key : key];
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["match", "key"]},
                    __module__ : {value: "__main__"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!resolve_format_spec.__argnames__) Object.defineProperties(resolve_format_spec, {
            __argnames__ : {value: ["format_spec"]},
            __module__ : {value: "__main__"}
        });

        function set_comma(ans, comma) {
            var sep;
            if (comma !== ",") {
                sep = 1234;
                sep = sep.toLocaleString(undefined, {useGrouping: true})[1];
                ans = str.replace(ans, sep, comma);
            }
            return ans;
        };
        if (!set_comma.__argnames__) Object.defineProperties(set_comma, {
            __argnames__ : {value: ["ans", "comma"]},
            __module__ : {value: "__main__"}
        });

        function safe_comma(value, comma) {
            try {
                return set_comma(value.toLocaleString(undefined, {useGrouping: true}), comma);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    return value.toString(10);
                } 
            }
        };
        if (!safe_comma.__argnames__) Object.defineProperties(safe_comma, {
            __argnames__ : {value: ["value", "comma"]},
            __module__ : {value: "__main__"}
        });

        function safe_fixed(value, precision, comma) {
            if (!comma) {
                return value.toFixed(precision);
            }
            try {
                return set_comma(value.toLocaleString(undefined, {useGrouping: true, minimumFractionDigits: precision, maximumFractionDigits: precision}), comma);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    return value.toFixed(precision);
                } 
            }
        };
        if (!safe_fixed.__argnames__) Object.defineProperties(safe_fixed, {
            __argnames__ : {value: ["value", "precision", "comma"]},
            __module__ : {value: "__main__"}
        });

        function apply_formatting(value, format_spec) {
            var ρσ_unpack, fill, align, sign, fhash, zeropad, width, comma, precision, ftype, is_numeric, is_int, lftype, code, prec, exp, nval, is_positive, left, right;
            if (format_spec.indexOf("{") !== -1) {
                format_spec = resolve_format_spec(format_spec);
            }
            if (ρσ_str.format._template_format_pat === undefined) {
                ρσ_str.format._template_format_pat = /([^{}](?=[<>=^]))?([<>=^])?([-+\x20])?(\#)?(0)?(\d+)?([,_])?(?:\.(\d+))?([bcdeEfFgGnosxX%])?/;
            }
            try {
                ρσ_unpack = format_spec.match(ρσ_str.format._template_format_pat).slice(1);
ρσ_unpack = ρσ_unpack_asarray(9, ρσ_unpack);
                fill = ρσ_unpack[0];
                align = ρσ_unpack[1];
                sign = ρσ_unpack[2];
                fhash = ρσ_unpack[3];
                zeropad = ρσ_unpack[4];
                width = ρσ_unpack[5];
                comma = ρσ_unpack[6];
                precision = ρσ_unpack[7];
                ftype = ρσ_unpack[8];
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof TypeError) {
                    return value;
                } else {
                    throw ρσ_Exception;
                }
            }
            if (zeropad) {
                fill = fill || "0";
                align = align || "=";
            } else {
                fill = fill || " ";
                align = align || ">";
            }
            is_numeric = Number(value) === value;
            is_int = is_numeric && value % 1 === 0;
            precision = parseInt(precision, 10);
            lftype = (ftype || "").toLowerCase();
            if (ftype === "n") {
                is_numeric = true;
                if (is_int) {
                    if (comma) {
                        throw new ValueError("Cannot specify ',' with 'n'");
                    }
                    value = parseInt(value, 10).toLocaleString();
                } else {
                    value = parseFloat(value).toLocaleString();
                }
            } else if (['b', 'c', 'd', 'o', 'x'].indexOf(lftype) !== -1) {
                value = parseInt(value, 10);
                is_numeric = true;
                if (!isNaN(value)) {
                    if (ftype === "b") {
                        value = (value >>> 0).toString(2);
                        if (fhash) {
                            value = "0b" + value;
                        }
                    } else if (ftype === "c") {
                        if (value > 65535) {
                            code = value - 65536;
                            value = String.fromCharCode(55296 + (code >> 10), 56320 + (code & 1023));
                        } else {
                            value = String.fromCharCode(value);
                        }
                    } else if (ftype === "d") {
                        if (comma) {
                            value = safe_comma(value, comma);
                        } else {
                            value = value.toString(10);
                        }
                    } else if (ftype === "o") {
                        value = value.toString(8);
                        if (fhash) {
                            value = "0o" + value;
                        }
                    } else if (lftype === "x") {
                        value = value.toString(16);
                        value = (ftype === "x") ? value.toLowerCase() : value.toUpperCase();
                        if (fhash) {
                            value = "0x" + value;
                        }
                    }
                }
            } else if (['e','f','g','%'].indexOf(lftype) !== -1) {
                is_numeric = true;
                value = parseFloat(value);
                prec = (isNaN(precision)) ? 6 : precision;
                if (lftype === "e") {
                    value = value.toExponential(prec);
                    value = (ftype === "E") ? value.toUpperCase() : value.toLowerCase();
                } else if (lftype === "f") {
                    value = safe_fixed(value, prec, comma);
                    value = (ftype === "F") ? value.toUpperCase() : value.toLowerCase();
                } else if (lftype === "%") {
                    value *= 100;
                    value = safe_fixed(value, prec, comma) + "%";
                } else if (lftype === "g") {
                    prec = max(1, prec);
                    exp = parseInt(split(value.toExponential(prec - 1).toLowerCase(), "e")[1], 10);
                    if (-4 <= exp && exp < prec) {
                        value = safe_fixed(value, prec - 1 - exp, comma);
                    } else {
                        value = value.toExponential(prec - 1);
                    }
                    value = value.replace(/0+$/g, "");
                    if (value[value.length-1] === decimal_sep) {
                        value = value.slice(0, -1);
                    }
                    if (ftype === "G") {
                        value = value.toUpperCase();
                    }
                }
            } else {
                if (comma) {
                    value = parseInt(value, 10);
                    if (isNaN(value)) {
                        throw new ValueError("Must use numbers with , or _");
                    }
                    value = safe_comma(value, comma);
                }
                value += "";
                if (!isNaN(precision)) {
                    value = value.slice(0, precision);
                }
            }
            value += "";
            if (is_numeric && sign) {
                nval = Number(value);
                is_positive = !isNaN(nval) && nval >= 0;
                if (is_positive && (sign === " " || sign === "+")) {
                    value = sign + value;
                }
            }
            function repeat(char, num) {
                return (new Array(num+1)).join(char);
            };
            if (!repeat.__argnames__) Object.defineProperties(repeat, {
                __argnames__ : {value: ["char", "num"]},
                __module__ : {value: "__main__"}
            });

            if (is_numeric && width && width[0] === "0") {
                width = width.slice(1);
                ρσ_unpack = ["0", "="];
                fill = ρσ_unpack[0];
                align = ρσ_unpack[1];
            }
            width = parseInt(width || "-1", 10);
            if (isNaN(width)) {
                throw new ValueError("Invalid width specification: " + width);
            }
            if (fill && value.length < width) {
                if (align === "<") {
                    value = value + repeat(fill, width - value.length);
                } else if (align === ">") {
                    value = repeat(fill, width - value.length) + value;
                } else if (align === "^") {
                    left = Math.floor((width - value.length) / 2);
                    right = width - left - value.length;
                    value = repeat(fill, left) + value + repeat(fill, right);
                } else if (align === "=") {
                    if (ρσ_in(value[0], "+- ")) {
                        value = value[0] + repeat(fill, width - value.length) + value.slice(1);
                    } else {
                        value = repeat(fill, width - value.length) + value;
                    }
                } else {
                    throw new ValueError("Unrecognized alignment: " + align);
                }
            }
            return value;
        };
        if (!apply_formatting.__argnames__) Object.defineProperties(apply_formatting, {
            __argnames__ : {value: ["value", "format_spec"]},
            __module__ : {value: "__main__"}
        });

        function parse_markup(markup) {
            var key, transformer, format_spec, pos, state, ch;
            key = transformer = format_spec = "";
            pos = 0;
            state = 0;
            while (pos < markup.length) {
                ch = markup[(typeof pos === "number" && pos < 0) ? markup.length + pos : pos];
                if (state === 0) {
                    if (ch === "!") {
                        state = 1;
                    } else if (ch === ":") {
                        state = 2;
                    } else {
                        key += ch;
                    }
                } else if (state === 1) {
                    if (ch === ":") {
                        state = 2;
                    } else {
                        transformer += ch;
                    }
                } else {
                    format_spec += ch;
                }
                pos += 1;
            }
            return [key, transformer, format_spec];
        };
        if (!parse_markup.__argnames__) Object.defineProperties(parse_markup, {
            __argnames__ : {value: ["markup"]},
            __module__ : {value: "__main__"}
        });

        function render_markup(markup) {
            var ρσ_unpack, key, transformer, format_spec, ends_with_equal, lkey, nvalue, object, ans;
            ρσ_unpack = parse_markup(markup);
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
            key = ρσ_unpack[0];
            transformer = ρσ_unpack[1];
            format_spec = ρσ_unpack[2];
            if (transformer && ['a', 'r', 's'].indexOf(transformer) === -1) {
                throw new ValueError("Unknown conversion specifier: " + transformer);
            }
            ends_with_equal = key.endsWith("=");
            if (ends_with_equal) {
                key = key.slice(0, -1);
            }
            lkey = key.length && split(key, /[.\[]/, 1)[0];
            if (lkey) {
                explicit = true;
                if (implicit) {
                    throw new ValueError("cannot switch from automatic field numbering to manual field specification");
                }
                nvalue = parseInt(lkey);
                object = (isNaN(nvalue)) ? kwargs[(typeof lkey === "number" && lkey < 0) ? kwargs.length + lkey : lkey] : args[(typeof nvalue === "number" && nvalue < 0) ? args.length + nvalue : nvalue];
                if (object === undefined) {
                    if (isNaN(nvalue)) {
                        throw new KeyError(lkey);
                    }
                    throw new IndexError(lkey);
                }
                object = resolve(key.slice(lkey.length), object);
            } else {
                implicit = true;
                if (explicit) {
                    throw new ValueError("cannot switch from manual field specification to automatic field numbering");
                }
                if (idx >= args.length) {
                    throw new IndexError("Not enough arguments to match template: " + template);
                }
                object = args[(typeof idx === "number" && idx < 0) ? args.length + idx : idx];
                idx += 1;
            }
            if (typeof object === "function") {
                object = object();
            }
            ans = "" + object;
            if (format_spec) {
                ans = apply_formatting(ans, format_spec);
            }
            if (ends_with_equal) {
                ans = "" + ρσ_str.format("{}", key) + "=" + ρσ_str.format("{}", ans) + "";
            }
            return ans;
        };
        if (!render_markup.__argnames__) Object.defineProperties(render_markup, {
            __argnames__ : {value: ["markup"]},
            __module__ : {value: "__main__"}
        });

        ans = "";
        pos = 0;
        in_brace = 0;
        markup = "";
        while (pos < template.length) {
            ch = template[(typeof pos === "number" && pos < 0) ? template.length + pos : pos];
            if (in_brace) {
                if (ch === "{") {
                    in_brace += 1;
                    markup += "{";
                } else if (ch === "}") {
                    in_brace -= 1;
                    if (in_brace > 0) {
                        markup += "}";
                    } else {
                        ans += render_markup(markup);
                    }
                } else {
                    markup += ch;
                }
            } else {
                if (ch === "{") {
                    if (template[ρσ_bound_index(pos + 1, template)] === "{") {
                        pos += 1;
                        ans += "{";
                    } else {
                        in_brace = 1;
                        markup = "";
                    }
                } else {
                    ans += ch;
                    if (ch === "}" && template[ρσ_bound_index(pos + 1, template)] === "}") {
                        pos += 1;
                    }
                }
            }
            pos += 1;
        }
        if (in_brace) {
            throw new ValueError("expected '}' before end of string");
        }
        return ans;
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("capitalize", (function() {
    var ρσ_anonfunc = function () {
        var string;
        string = this;
        if (string) {
            string = string[0].toUpperCase() + string.slice(1).toLowerCase();
        }
        return string;
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("center", (function() {
    var ρσ_anonfunc = function (width, fill) {
        var left, right;
        left = Math.floor((width - this.length) / 2);
        right = width - left - this.length;
        fill = fill || " ";
        return new Array(left+1).join(fill) + this + new Array(right+1).join(fill);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["width", "fill"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("count", (function() {
    var ρσ_anonfunc = function (needle, start, end) {
        var string, ρσ_unpack, pos, step, ans;
        string = this;
        start = start || 0;
        end = end || string.length;
        if (start < 0 || end < 0) {
            string = string.slice(start, end);
            ρσ_unpack = [0, string.length];
            start = ρσ_unpack[0];
            end = ρσ_unpack[1];
        }
        pos = start;
        step = needle.length;
        if (!step) {
            return 0;
        }
        ans = 0;
        while (pos !== -1) {
            pos = string.indexOf(needle, pos);
            if (pos !== -1) {
                ans += 1;
                pos += step;
            }
        }
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["needle", "start", "end"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("endswith", (function() {
    var ρσ_anonfunc = function (suffixes, start, end) {
        var string, q;
        string = this;
        start = start || 0;
        if (typeof suffixes === "string") {
            suffixes = [suffixes];
        }
        if (end !== undefined) {
            string = string.slice(0, end);
        }
        for (var i = 0; i < suffixes.length; i++) {
            q = suffixes[(typeof i === "number" && i < 0) ? suffixes.length + i : i];
            if (string.indexOf(q, Math.max(start, string.length - q.length)) !== -1) {
                return true;
            }
        }
        return false;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["suffixes", "start", "end"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("startswith", (function() {
    var ρσ_anonfunc = function (prefixes, start, end) {
        var prefix;
        start = start || 0;
        if (typeof prefixes === "string") {
            prefixes = [prefixes];
        }
        for (var i = 0; i < prefixes.length; i++) {
            prefix = prefixes[(typeof i === "number" && i < 0) ? prefixes.length + i : i];
            end = (end === undefined) ? this.length : end;
            if (end - start >= prefix.length && prefix === this.slice(start, start + prefix.length)) {
                return true;
            }
        }
        return false;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["prefixes", "start", "end"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("find", (function() {
    var ρσ_anonfunc = function (needle, start, end) {
        var ans;
        while (start < 0) {
            start += this.length;
        }
        ans = this.indexOf(needle, start);
        if (end !== undefined && ans !== -1) {
            while (end < 0) {
                end += this.length;
            }
            if (ans >= end - needle.length) {
                return -1;
            }
        }
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["needle", "start", "end"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("rfind", (function() {
    var ρσ_anonfunc = function (needle, start, end) {
        var ans;
        while (end < 0) {
            end += this.length;
        }
        ans = this.lastIndexOf(needle, end - 1);
        if (start !== undefined && ans !== -1) {
            while (start < 0) {
                start += this.length;
            }
            if (ans < start) {
                return -1;
            }
        }
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["needle", "start", "end"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("index", (function() {
    var ρσ_anonfunc = function (needle, start, end) {
        var ans;
        ans = ρσ_str.prototype.find.apply(this, arguments);
        if (ans === -1) {
            throw new ValueError("substring not found");
        }
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["needle", "start", "end"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("rindex", (function() {
    var ρσ_anonfunc = function (needle, start, end) {
        var ans;
        ans = ρσ_str.prototype.rfind.apply(this, arguments);
        if (ans === -1) {
            throw new ValueError("substring not found");
        }
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["needle", "start", "end"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("islower", (function() {
    var ρσ_anonfunc = function () {
        return this.length > 0 && this.toLowerCase() === this.toString();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("isupper", (function() {
    var ρσ_anonfunc = function () {
        return this.length > 0 && this.toUpperCase() === this.toString();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("isspace", (function() {
    var ρσ_anonfunc = function () {
        return this.length > 0 && /^\s+$/.test(this);
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("join", (function() {
    var ρσ_anonfunc = function (iterable) {
        var ans, r;
        if (Array.isArray(iterable)) {
            return iterable.join(this);
        }
        ans = "";
        r = iterable.next();
        while (!r.done) {
            if (ans) {
                ans += this;
            }
            ans += r.value;
            r = iterable.next();
        }
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["iterable"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("ljust", (function() {
    var ρσ_anonfunc = function (width, fill) {
        var string;
        string = this;
        if (width > string.length) {
            fill = fill || " ";
            string += new Array(width - string.length + 1).join(fill);
        }
        return string;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["width", "fill"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("rjust", (function() {
    var ρσ_anonfunc = function (width, fill) {
        var string;
        string = this;
        if (width > string.length) {
            fill = fill || " ";
            string = new Array(width - string.length + 1).join(fill) + string;
        }
        return string;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["width", "fill"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("lower", (function() {
    var ρσ_anonfunc = function () {
        return this.toLowerCase();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("upper", (function() {
    var ρσ_anonfunc = function () {
        return this.toUpperCase();
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("lstrip", (function() {
    var ρσ_anonfunc = function (chars) {
        var string, pos;
        string = this;
        pos = 0;
        chars = chars || ρσ_str.whitespace;
        while (chars.indexOf(string[(typeof pos === "number" && pos < 0) ? string.length + pos : pos]) !== -1) {
            pos += 1;
        }
        if (pos) {
            string = string.slice(pos);
        }
        return string;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["chars"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("rstrip", (function() {
    var ρσ_anonfunc = function (chars) {
        var string, pos;
        string = this;
        pos = string.length - 1;
        chars = chars || ρσ_str.whitespace;
        while (chars.indexOf(string[(typeof pos === "number" && pos < 0) ? string.length + pos : pos]) !== -1) {
            pos -= 1;
        }
        if (pos < string.length - 1) {
            string = string.slice(0, pos + 1);
        }
        return string;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["chars"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("strip", (function() {
    var ρσ_anonfunc = function (chars) {
        return ρσ_str.prototype.lstrip.call(ρσ_str.prototype.rstrip.call(this, chars), chars);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["chars"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("partition", (function() {
    var ρσ_anonfunc = function (sep) {
        var idx;
        idx = this.indexOf(sep);
        if (idx === -1) {
            return [this, "", ""];
        }
        return [this.slice(0, idx), sep, this.slice(idx + sep.length)];
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["sep"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("rpartition", (function() {
    var ρσ_anonfunc = function (sep) {
        var idx;
        idx = this.lastIndexOf(sep);
        if (idx === -1) {
            return ["", "", this];
        }
        return [this.slice(0, idx), sep, this.slice(idx + sep.length)];
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["sep"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("replace", (function() {
    var ρσ_anonfunc = function (old, repl, count) {
        var string, pos, idx;
        string = this;
        if (count === 1) {
            return ρσ_orig_replace(string, old, repl);
        }
        if (count < 1) {
            return string;
        }
        count = count || Number.MAX_VALUE;
        pos = 0;
        while (count > 0) {
            count -= 1;
            idx = string.indexOf(old, pos);
            if (idx === -1) {
                break;
            }
            pos = idx + repl.length;
            string = string.slice(0, idx) + repl + string.slice(idx + old.length);
        }
        return string;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["old", "repl", "count"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("split", (function() {
    var ρσ_anonfunc = function (sep, maxsplit) {
        var split, ans, extra, parts;
        if (maxsplit === 0) {
            return ρσ_list_decorate([ this ]);
        }
        split = ρσ_orig_split;
        if (sep === undefined || sep === null) {
            if (maxsplit > 0) {
                ans = split(this, /(\s+)/);
                extra = "";
                parts = [];
                for (var i = 0; i < ans.length; i++) {
                    if (parts.length >= maxsplit + 1) {
                        extra += ans[(typeof i === "number" && i < 0) ? ans.length + i : i];
                    } else if (i % 2 === 0) {
                        parts.push(ans[(typeof i === "number" && i < 0) ? ans.length + i : i]);
                    }
                }
                parts[parts.length-1] += extra;
                ans = parts;
            } else {
                ans = split(this, /\s+/);
            }
        } else {
            if (sep === "") {
                throw new ValueError("empty separator");
            }
            ans = split(this, sep);
            if (maxsplit > 0 && ans.length > maxsplit) {
                extra = ans.slice(maxsplit).join(sep);
                ans = ans.slice(0, maxsplit);
                ans.push(extra);
            }
        }
        return ρσ_list_decorate(ans);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["sep", "maxsplit"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("rsplit", (function() {
    var ρσ_anonfunc = function (sep, maxsplit) {
        var split, ans, is_space, pos, current, spc, ch, end, idx;
        if (!maxsplit) {
            return ρσ_str.prototype.split.call(this, sep);
        }
        split = ρσ_orig_split;
        if (sep === undefined || sep === null) {
            if (maxsplit > 0) {
                ans = [];
                is_space = /\s/;
                pos = this.length - 1;
                current = "";
                while (pos > -1 && maxsplit > 0) {
                    spc = false;
                    ch = (ρσ_expr_temp = this)[(typeof pos === "number" && pos < 0) ? ρσ_expr_temp.length + pos : pos];
                    while (pos > -1 && is_space.test(ch)) {
                        spc = true;
                        ch = this[--pos];
                    }
                    if (spc) {
                        if (current) {
                            ans.push(current);
                            maxsplit -= 1;
                        }
                        current = ch;
                    } else {
                        current += ch;
                    }
                    pos -= 1;
                }
                ans.push(this.slice(0, pos + 1) + current);
                ans.reverse();
            } else {
                ans = split(this, /\s+/);
            }
        } else {
            if (sep === "") {
                throw new ValueError("empty separator");
            }
            ans = [];
            pos = end = this.length;
            while (pos > -1 && maxsplit > 0) {
                maxsplit -= 1;
                idx = this.lastIndexOf(sep, pos);
                if (idx === -1) {
                    break;
                }
                ans.push(this.slice(idx + sep.length, end));
                pos = idx - 1;
                end = idx;
            }
            ans.push(this.slice(0, end));
            ans.reverse();
        }
        return ρσ_list_decorate(ans);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["sep", "maxsplit"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("splitlines", (function() {
    var ρσ_anonfunc = function (keepends) {
        var split, parts, ans;
        split = ρσ_orig_split;
        if (keepends) {
            parts = split(this, /((?:\r?\n)|\r)/);
            ans = [];
            for (var i = 0; i < parts.length; i++) {
                if (i % 2 === 0) {
                    ans.push(parts[(typeof i === "number" && i < 0) ? parts.length + i : i]);
                } else {
                    ans[ans.length-1] += parts[(typeof i === "number" && i < 0) ? parts.length + i : i];
                }
            }
        } else {
            ans = split(this, /(?:\r?\n)|\r/);
        }
        return ρσ_list_decorate(ans);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["keepends"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("swapcase", (function() {
    var ρσ_anonfunc = function () {
        var ans, a, b;
        ans = new Array(this.length);
        for (var i = 0; i < ans.length; i++) {
            a = (ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
            b = a.toLowerCase();
            if (a === b) {
                b = a.toUpperCase();
            }
            ans[(typeof i === "number" && i < 0) ? ans.length + i : i] = b;
        }
        return ans.join("");
    };
    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
define_str_func("zfill", (function() {
    var ρσ_anonfunc = function (width) {
        var string;
        string = this;
        if (width > string.length) {
            string = new Array(width - string.length + 1).join("0") + string;
        }
        return string;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["width"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})());
ρσ_str.uchrs = (function() {
    var ρσ_anonfunc = function (string, with_positions) {
        return (function(){
            var ρσ_d = {};
            ρσ_d["_string"] = string;
            ρσ_d["_pos"] = 0;
            ρσ_d[ρσ_iterator_symbol] = (function() {
                var ρσ_anonfunc = function () {
                    return this;
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "__main__"}
                });
                return ρσ_anonfunc;
            })();
            ρσ_d["next"] = (function() {
                var ρσ_anonfunc = function () {
                    var length, pos, value, ans, extra;
                    length = this._string.length;
                    if (this._pos >= length) {
                        return (function(){
                            var ρσ_d = {};
                            ρσ_d["done"] = true;
                            return ρσ_d;
                        }).call(this);
                    }
                    pos = this._pos;
                    value = this._string.charCodeAt(this._pos++);
                    ans = "\ufffd";
                    if (55296 <= value && value <= 56319) {
                        if (this._pos < length) {
                            extra = this._string.charCodeAt(this._pos++);
                            if ((extra & 56320) === 56320) {
                                ans = String.fromCharCode(value, extra);
                            }
                        }
                    } else if ((value & 56320) !== 56320) {
                        ans = String.fromCharCode(value);
                    }
                    if (with_positions) {
                        return (function(){
                            var ρσ_d = {};
                            ρσ_d["done"] = false;
                            ρσ_d["value"] = ρσ_list_decorate([ pos, ans ]);
                            return ρσ_d;
                        }).call(this);
                    } else {
                        return (function(){
                            var ρσ_d = {};
                            ρσ_d["done"] = false;
                            ρσ_d["value"] = ans;
                            return ρσ_d;
                        }).call(this);
                    }
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "__main__"}
                });
                return ρσ_anonfunc;
            })();
            return ρσ_d;
        }).call(this);
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["string", "with_positions"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_str.uslice = (function() {
    var ρσ_anonfunc = function (string, start, end) {
        var items, iterator, r;
        items = [];
        iterator = ρσ_str.uchrs(string);
        r = iterator.next();
        while (!r.done) {
            items.push(r.value);
            r = iterator.next();
        }
        return items.slice(start || 0, (end === undefined) ? items.length : end).join("");
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["string", "start", "end"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_str.ulen = (function() {
    var ρσ_anonfunc = function (string) {
        var iterator, r, ans;
        iterator = ρσ_str.uchrs(string);
        r = iterator.next();
        ans = 0;
        while (!r.done) {
            r = iterator.next();
            ans += 1;
        }
        return ans;
    };
    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
        __argnames__ : {value: ["string"]},
        __module__ : {value: "__main__"}
    });
    return ρσ_anonfunc;
})();
ρσ_str.ascii_lowercase = "abcdefghijklmnopqrstuvwxyz";
ρσ_str.ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ρσ_str.ascii_letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
ρσ_str.digits = "0123456789";
ρσ_str.punctuation = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
ρσ_str.printable = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\u000b\f";
ρσ_str.whitespace = " \t\n\r\u000b\f";
define_str_func = undefined;
var str = ρσ_str, repr = ρσ_repr;;
    var ρσ_modules = {};
    ρσ_modules.elementmaker = {};
    ρσ_modules.pythonize = {};
    ρσ_modules.initialize = {};
    ρσ_modules.traceback = {};
    ρσ_modules.gettext = {};
    ρσ_modules.ajax = {};
    ρσ_modules.book_list = {};
    ρσ_modules["book_list.globals"] = {};
    ρσ_modules.lru_cache = {};
    ρσ_modules.encodings = {};
    ρσ_modules.uuid = {};
    ρσ_modules.session = {};
    ρσ_modules.dom = {};
    ρσ_modules["book_list.theme"] = {};
    ρσ_modules.utils = {};
    ρσ_modules["book_list.library_data"] = {};
    ρσ_modules.date = {};
    ρσ_modules.popups = {};
    ρσ_modules.widgets = {};
    ρσ_modules.modals = {};
    ρσ_modules.qt = {};
    ρσ_modules.read_book = {};
    ρσ_modules["book_list.constants"] = {};
    ρσ_modules.aes = {};
    ρσ_modules["read_book.globals"] = {};
    ρσ_modules["book_list.router"] = {};
    ρσ_modules["read_book.viewport"] = {};
    ρσ_modules["read_book.cfi"] = {};
    ρσ_modules["read_book.annotations"] = {};
    ρσ_modules["read_book.db"] = {};
    ρσ_modules.iframe_comm = {};
    ρσ_modules["read_book.settings"] = {};
    ρσ_modules["read_book.resources"] = {};
    ρσ_modules["read_book.footnotes"] = {};
    ρσ_modules.select = {};
    ρσ_modules.fs_images = {};
    ρσ_modules.range_utils = {};
    ρσ_modules["read_book.anchor_visibility"] = {};
    ρσ_modules["read_book.extract"] = {};
    ρσ_modules["read_book.find"] = {};
    ρσ_modules["read_book.flow_mode"] = {};
    ρσ_modules["read_book.touch"] = {};
    ρσ_modules["read_book.gestures"] = {};
    ρσ_modules.complete = {};
    ρσ_modules["read_book.highlights"] = {};
    ρσ_modules["read_book.shortcuts"] = {};
    ρσ_modules["read_book.hints"] = {};
    ρσ_modules["read_book.mathjax"] = {};
    ρσ_modules["read_book.paged_mode"] = {};
    ρσ_modules["read_book.referencing"] = {};
    ρσ_modules["read_book.smil"] = {};
    ρσ_modules["read_book.toc"] = {};
    ρσ_modules["read_book.iframe"] = {};
    ρσ_modules["book_list.item_list"] = {};
    ρσ_modules["read_book.open_book"] = {};
    ρσ_modules["read_book.prefs"] = {};
    ρσ_modules["read_book.prefs.utils"] = {};
    ρσ_modules.viewer = {};
    ρσ_modules["viewer.constants"] = {};
    ρσ_modules["read_book.prefs.head_foot"] = {};
    ρσ_modules["book_list.cover_grid"] = {};
    ρσ_modules["book_list.top_bar"] = {};
    ρσ_modules["book_list.ui"] = {};
    ρσ_modules["book_list.home"] = {};
    ρσ_modules["read_book.bookmarks"] = {};
    ρσ_modules["read_book.content_popup"] = {};
    ρσ_modules["read_book.goto"] = {};
    ρσ_modules.file_uploads = {};
    ρσ_modules["book_list.add"] = {};
    ρσ_modules["book_list.delete_book"] = {};
    ρσ_modules["book_list.details_list"] = {};
    ρσ_modules["book_list.custom_list"] = {};
    ρσ_modules["book_list.saved_virtual_libraries"] = {};
    ρσ_modules["book_list.saved_virtual_library_icon_picker"] = {};
    ρσ_modules["book_list.saved_virtual_library_dialog"] = {};
    ρσ_modules["book_list.prefs"] = {};
    ρσ_modules["book_list.search"] = {};
    ρσ_modules["book_list.views"] = {};
    ρσ_modules["book_list.book_details"] = {};
    ρσ_modules["read_book.chrome"] = {};
    ρσ_modules["read_book.main_overlay_style"] = {};
    ρσ_modules["read_book.profiles"] = {};
    ρσ_modules["read_book.prefs.font_size"] = {};
    ρσ_modules["read_book.prefs.colors"] = {};
    ρσ_modules["read_book.prefs.fonts"] = {};
    ρσ_modules["read_book.prefs.keyboard"] = {};
    ρσ_modules["read_book.prefs.layout"] = {};
    ρσ_modules["read_book.prefs.misc"] = {};
    ρσ_modules["read_book.prefs.scrolling"] = {};
    ρσ_modules["read_book.selection_bar"] = {};
    ρσ_modules["read_book.prefs.selection"] = {};
    ρσ_modules["read_book.prefs.touch"] = {};
    ρσ_modules["read_book.prefs.user_stylesheet"] = {};
    ρσ_modules["read_book.prefs.main"] = {};
    ρσ_modules["read_book.word_actions"] = {};
    ρσ_modules["read_book.overlay"] = {};
    ρσ_modules["read_book.read_aloud"] = {};
    ρσ_modules["read_book.read_audio_ebook"] = {};
    ρσ_modules["read_book.scrollbar"] = {};
    ρσ_modules["read_book.search_worker"] = {};
    ρσ_modules.worker = {};
    ρσ_modules["read_book.search"] = {};
    ρσ_modules["read_book.timers"] = {};
    ρσ_modules["read_book.view"] = {};

    (function(){
        var __name__ = "elementmaker";
        var html_elements, mathml_elements, svg_elements, html5_tags, E;
        html_elements = (function(){
            var s = ρσ_set();
            s.jsset.add("a");
            s.jsset.add("abbr");
            s.jsset.add("acronym");
            s.jsset.add("address");
            s.jsset.add("area");
            s.jsset.add("article");
            s.jsset.add("aside");
            s.jsset.add("audio");
            s.jsset.add("b");
            s.jsset.add("base");
            s.jsset.add("big");
            s.jsset.add("body");
            s.jsset.add("blockquote");
            s.jsset.add("br");
            s.jsset.add("button");
            s.jsset.add("canvas");
            s.jsset.add("caption");
            s.jsset.add("center");
            s.jsset.add("cite");
            s.jsset.add("code");
            s.jsset.add("col");
            s.jsset.add("colgroup");
            s.jsset.add("command");
            s.jsset.add("datagrid");
            s.jsset.add("datalist");
            s.jsset.add("dd");
            s.jsset.add("del");
            s.jsset.add("details");
            s.jsset.add("dfn");
            s.jsset.add("dialog");
            s.jsset.add("dir");
            s.jsset.add("div");
            s.jsset.add("dl");
            s.jsset.add("dt");
            s.jsset.add("em");
            s.jsset.add("event-source");
            s.jsset.add("fieldset");
            s.jsset.add("figcaption");
            s.jsset.add("figure");
            s.jsset.add("footer");
            s.jsset.add("font");
            s.jsset.add("form");
            s.jsset.add("header");
            s.jsset.add("h1");
            s.jsset.add("h2");
            s.jsset.add("h3");
            s.jsset.add("h4");
            s.jsset.add("h5");
            s.jsset.add("h6");
            s.jsset.add("hr");
            s.jsset.add("head");
            s.jsset.add("i");
            s.jsset.add("iframe");
            s.jsset.add("img");
            s.jsset.add("input");
            s.jsset.add("ins");
            s.jsset.add("keygen");
            s.jsset.add("kbd");
            s.jsset.add("label");
            s.jsset.add("legend");
            s.jsset.add("li");
            s.jsset.add("m");
            s.jsset.add("map");
            s.jsset.add("menu");
            s.jsset.add("meter");
            s.jsset.add("multicol");
            s.jsset.add("nav");
            s.jsset.add("nextid");
            s.jsset.add("ol");
            s.jsset.add("output");
            s.jsset.add("optgroup");
            s.jsset.add("option");
            s.jsset.add("p");
            s.jsset.add("pre");
            s.jsset.add("progress");
            s.jsset.add("q");
            s.jsset.add("s");
            s.jsset.add("samp");
            s.jsset.add("script");
            s.jsset.add("section");
            s.jsset.add("select");
            s.jsset.add("small");
            s.jsset.add("sound");
            s.jsset.add("source");
            s.jsset.add("spacer");
            s.jsset.add("span");
            s.jsset.add("strike");
            s.jsset.add("strong");
            s.jsset.add("style");
            s.jsset.add("sub");
            s.jsset.add("sup");
            s.jsset.add("table");
            s.jsset.add("tbody");
            s.jsset.add("td");
            s.jsset.add("textarea");
            s.jsset.add("time");
            s.jsset.add("tfoot");
            s.jsset.add("th");
            s.jsset.add("thead");
            s.jsset.add("tr");
            s.jsset.add("tt");
            s.jsset.add("u");
            s.jsset.add("ul");
            s.jsset.add("var");
            s.jsset.add("video");
            return s;
        })();
        mathml_elements = (function(){
            var s = ρσ_set();
            s.jsset.add("maction");
            s.jsset.add("math");
            s.jsset.add("merror");
            s.jsset.add("mfrac");
            s.jsset.add("mi");
            s.jsset.add("mmultiscripts");
            s.jsset.add("mn");
            s.jsset.add("mo");
            s.jsset.add("mover");
            s.jsset.add("mpadded");
            s.jsset.add("mphantom");
            s.jsset.add("mprescripts");
            s.jsset.add("mroot");
            s.jsset.add("mrow");
            s.jsset.add("mspace");
            s.jsset.add("msqrt");
            s.jsset.add("mstyle");
            s.jsset.add("msub");
            s.jsset.add("msubsup");
            s.jsset.add("msup");
            s.jsset.add("mtable");
            s.jsset.add("mtd");
            s.jsset.add("mtext");
            s.jsset.add("mtr");
            s.jsset.add("munder");
            s.jsset.add("munderover");
            s.jsset.add("none");
            return s;
        })();
        svg_elements = (function(){
            var s = ρσ_set();
            s.jsset.add("a");
            s.jsset.add("animate");
            s.jsset.add("animateColor");
            s.jsset.add("animateMotion");
            s.jsset.add("animateTransform");
            s.jsset.add("clipPath");
            s.jsset.add("circle");
            s.jsset.add("defs");
            s.jsset.add("desc");
            s.jsset.add("ellipse");
            s.jsset.add("font-face");
            s.jsset.add("font-face-name");
            s.jsset.add("font-face-src");
            s.jsset.add("g");
            s.jsset.add("glyph");
            s.jsset.add("hkern");
            s.jsset.add("linearGradient");
            s.jsset.add("line");
            s.jsset.add("marker");
            s.jsset.add("metadata");
            s.jsset.add("missing-glyph");
            s.jsset.add("mpath");
            s.jsset.add("path");
            s.jsset.add("polygon");
            s.jsset.add("polyline");
            s.jsset.add("radialGradient");
            s.jsset.add("rect");
            s.jsset.add("set");
            s.jsset.add("stop");
            s.jsset.add("svg");
            s.jsset.add("switch");
            s.jsset.add("text");
            s.jsset.add("title");
            s.jsset.add("tspan");
            s.jsset.add("use");
            return s;
        })();
        html5_tags = html_elements.union(mathml_elements).union(svg_elements);
        function _makeelement() {
            var tag = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var kwargs = arguments[arguments.length-1];
            if (kwargs === null || typeof kwargs !== "object" || kwargs [ρσ_kwargs_symbol] !== true) kwargs = {};
            var args = Array.prototype.slice.call(arguments, 1);
            if (kwargs !== null && typeof kwargs === "object" && kwargs [ρσ_kwargs_symbol] === true) args.pop();
            var ans, vattr, val, attr, arg;
            ans = this.createElement(tag);
            var ρσ_Iter0 = ρσ_Iterable(kwargs);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                attr = ρσ_Iter0[ρσ_Index0];
                vattr = str.replace(str.rstrip(attr, "_"), "_", "-");
                val = kwargs[(typeof attr === "number" && attr < 0) ? kwargs.length + attr : attr];
                if (callable(val)) {
                    if (str.startswith(attr, "on")) {
                        attr = attr.slice(2);
                    }
                    ans.addEventListener(attr, val);
                } else if (val === true) {
                    ans.setAttribute(vattr, vattr);
                } else if (typeof val === "string") {
                    ans.setAttribute(vattr, val);
                }
            }
            var ρσ_Iter1 = ρσ_Iterable(args);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                arg = ρσ_Iter1[ρσ_Index1];
                if (typeof arg === "string") {
                    arg = this.createTextNode(arg);
                }
                ans.appendChild(arg);
            }
            return ans;
        };
        if (!_makeelement.__handles_kwarg_interpolation__) Object.defineProperties(_makeelement, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["tag"]},
            __module__ : {value: "elementmaker"}
        });

        function maker_for_document(document) {
            var E;
            E = _makeelement.bind(document);
            Object.defineProperties(E, (function() {
                var ρσ_Iter = ρσ_Iterable(html5_tags), ρσ_Result = {}, tag;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    tag = ρσ_Iter[ρσ_Index];
                    ρσ_Result[tag] = ((function(){
                        var ρσ_d = {};
                        ρσ_d["value"] = _makeelement.bind(document, tag);
                        return ρσ_d;
                    }).call(this));
                }
                return ρσ_Result;
            })());
            return E;
        };
        if (!maker_for_document.__argnames__) Object.defineProperties(maker_for_document, {
            __argnames__ : {value: ["document"]},
            __module__ : {value: "elementmaker"}
        });

        if (typeof document === "undefined") {
            E = maker_for_document((function(){
                var ρσ_d = {};
                ρσ_d["createTextNode"] = (function() {
                    var ρσ_anonfunc = function (value) {
                        return value;
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["value"]},
                        __module__ : {value: "elementmaker"}
                    });
                    return ρσ_anonfunc;
                })();
                ρσ_d["createElement"] = (function() {
                    var ρσ_anonfunc = function (name) {
                        return (function(){
                            var ρσ_d = {};
                            ρσ_d["name"] = name;
                            ρσ_d["children"] = ρσ_list_decorate([]);
                            ρσ_d["attributes"] = {};
                            ρσ_d["setAttribute"] = (function() {
                                var ρσ_anonfunc = function (name, val) {
                                    (ρσ_expr_temp = this.attributes)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name] = val;
                                };
                                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                    __argnames__ : {value: ["name", "val"]},
                                    __module__ : {value: "elementmaker"}
                                });
                                return ρσ_anonfunc;
                            })();
                            ρσ_d["appendChild"] = (function() {
                                var ρσ_anonfunc = function (child) {
                                    this.children.push(child);
                                };
                                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                    __argnames__ : {value: ["child"]},
                                    __module__ : {value: "elementmaker"}
                                });
                                return ρσ_anonfunc;
                            })();
                            return ρσ_d;
                        }).call(this);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["name"]},
                        __module__ : {value: "elementmaker"}
                    });
                    return ρσ_anonfunc;
                })();
                return ρσ_d;
            }).call(this));
        } else {
            E = maker_for_document(document);
        }
        ρσ_modules.elementmaker.html_elements = html_elements;
        ρσ_modules.elementmaker.mathml_elements = mathml_elements;
        ρσ_modules.elementmaker.svg_elements = svg_elements;
        ρσ_modules.elementmaker.html5_tags = html5_tags;
        ρσ_modules.elementmaker.E = E;
        ρσ_modules.elementmaker._makeelement = _makeelement;
        ρσ_modules.elementmaker.maker_for_document = maker_for_document;
    })();

    (function(){
        var __name__ = "pythonize";
        function strings() {
            var string_funcs, exclude, name;
            string_funcs = set("capitalize strip lstrip rstrip islower isupper isspace lower upper swapcase center count endswith startswith find rfind index rindex format join ljust rjust partition rpartition replace split rsplit splitlines zfill".split(" "));
            if (!arguments.length) {
                exclude = (function(){
                    var s = ρσ_set();
                    s.jsset.add("split");
                    s.jsset.add("replace");
                    return s;
                })();
            } else if (arguments[0]) {
                exclude = Array.prototype.slice.call(arguments);
            } else {
                exclude = null;
            }
            if (exclude) {
                string_funcs = string_funcs.difference(set(exclude));
            }
            var ρσ_Iter0 = ρσ_Iterable(string_funcs);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                name = ρσ_Iter0[ρσ_Index0];
                (ρσ_expr_temp = String.prototype)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name] = (ρσ_expr_temp = ρσ_str.prototype)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name];
            }
        };
        if (!strings.__module__) Object.defineProperties(strings, {
            __module__ : {value: "pythonize"}
        });

        ρσ_modules.pythonize.strings = strings;
    })();

    (function(){
        var __name__ = "initialize";
        var strings = ρσ_modules.pythonize.strings;

        strings();
    })();

    (function(){
        var __name__ = "traceback";
        function _get_internal_traceback(err) {
            var lines, final_lines, found_sentinel, sline, ρσ_unpack, i, line;
            if (ρσ_instanceof(err, Exception) && err.stack) {
                lines = ρσ_str.splitlines(err.stack);
                final_lines = [];
                found_sentinel = false;
                var ρσ_Iter0 = ρσ_Iterable(enumerate(lines));
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    ρσ_unpack = ρσ_Iter0[ρσ_Index0];
                    i = ρσ_unpack[0];
                    line = ρσ_unpack[1];
                    sline = ρσ_str.strip(line);
                    if (i === 0) {
                        final_lines.push(line);
                        continue;
                    }
                    if (found_sentinel) {
                        final_lines.push(line);
                        continue;
                    }
                    if (sline.startsWith("at new " + err.name) || sline.startsWith(err.name + "@")) {
                        found_sentinel = true;
                    }
                }
                return final_lines.join("\n");
            }
            return err && err.stack;
        };
        if (!_get_internal_traceback.__argnames__) Object.defineProperties(_get_internal_traceback, {
            __argnames__ : {value: ["err"]},
            __module__ : {value: "traceback"}
        });

        function format_exception(exc, limit) {
            var tb, lines, e;
            if (typeof exc === "undefined") {
                exc = ρσ_last_exception;
            }
            if (!(ρσ_instanceof(exc, Error))) {
                if (exc && exc.toString) {
                    return ρσ_list_decorate([ exc.toString() ]);
                }
                return ρσ_list_decorate([]);
            }
            tb = _get_internal_traceback(exc);
            if (tb) {
                lines = ρσ_str.splitlines(tb);
                e = lines[0];
                lines = lines.slice(1);
                if (limit) {
                    lines = (limit > 0) ? lines.slice(0, limit + 1) : lines.slice(limit);
                }
                lines.reverse();
                lines.push(e);
                lines.insert(0, "Traceback (most recent call last):");
                return (function() {
                    var ρσ_Iter = ρσ_Iterable(lines), ρσ_Result = [], l;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        l = ρσ_Iter[ρσ_Index];
                        ρσ_Result.push(l + "\n");
                    }
                    ρσ_Result = ρσ_list_constructor(ρσ_Result);
                    return ρσ_Result;
                })();
            }
            return ρσ_list_decorate([ exc.toString() ]);
        };
        if (!format_exception.__argnames__) Object.defineProperties(format_exception, {
            __argnames__ : {value: ["exc", "limit"]},
            __module__ : {value: "traceback"}
        });

        function format_exc(limit) {
            return format_exception(ρσ_last_exception, limit).join("");
        };
        if (!format_exc.__argnames__) Object.defineProperties(format_exc, {
            __argnames__ : {value: ["limit"]},
            __module__ : {value: "traceback"}
        });

        function print_exc(limit) {
            print(format_exc(limit));
        };
        if (!print_exc.__argnames__) Object.defineProperties(print_exc, {
            __argnames__ : {value: ["limit"]},
            __module__ : {value: "traceback"}
        });

        function format_stack(limit) {
            var stack, lines;
            stack = (new Error).stack;
            if (!stack) {
                return ρσ_list_decorate([]);
            }
            lines = str.splitlines(stack).slice(2);
            lines.reverse();
            if (limit) {
                lines = (limit > 0) ? lines.slice(0, limit + 1) : lines.slice(limit);
            }
            return (function() {
                var ρσ_Iter = ρσ_Iterable(lines), ρσ_Result = [], l;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    l = ρσ_Iter[ρσ_Index];
                    ρσ_Result.push(l + "\n");
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
        };
        if (!format_stack.__argnames__) Object.defineProperties(format_stack, {
            __argnames__ : {value: ["limit"]},
            __module__ : {value: "traceback"}
        });

        function print_stack(limit) {
            print(format_stack(limit).join(""));
        };
        if (!print_stack.__argnames__) Object.defineProperties(print_stack, {
            __argnames__ : {value: ["limit"]},
            __module__ : {value: "traceback"}
        });

        ρσ_modules.traceback._get_internal_traceback = _get_internal_traceback;
        ρσ_modules.traceback.format_exception = format_exception;
        ρσ_modules.traceback.format_exc = format_exc;
        ρσ_modules.traceback.print_exc = print_exc;
        ρσ_modules.traceback.format_stack = format_stack;
        ρσ_modules.traceback.print_stack = print_stack;
    })();

    (function(){
        var __name__ = "gettext";
        var Jed, plural_forms_parser, _gettext, _ngettext, has_prop, empty_translation_data;
        Jed = {};
        
  Jed.PF = {};

  Jed.PF.parse = function ( p ) {
    var plural_str = Jed.PF.extractPluralExpr( p );
    return Jed.PF.parser.parse.call(Jed.PF.parser, plural_str);
  };

  Jed.PF.compile = function ( p ) {
    // Handle trues and falses as 0 and 1
    function imply( val ) {
      return (val === true ? 1 : val ? val : 0);
    }

    var ast = Jed.PF.parse( p );
    return function ( n ) {
      return imply( Jed.PF.interpreter( ast )( n ) );
    };
  };

  Jed.PF.interpreter = function ( ast ) {
    return function ( n ) {
      var res;
      switch ( ast.type ) {
        case 'GROUP':
          return Jed.PF.interpreter( ast.expr )( n );
        case 'TERNARY':
          if ( Jed.PF.interpreter( ast.expr )( n ) ) {
            return Jed.PF.interpreter( ast.truthy )( n );
          }
          return Jed.PF.interpreter( ast.falsey )( n );
        case 'OR':
          return Jed.PF.interpreter( ast.left )( n ) || Jed.PF.interpreter( ast.right )( n );
        case 'AND':
          return Jed.PF.interpreter( ast.left )( n ) && Jed.PF.interpreter( ast.right )( n );
        case 'LT':
          return Jed.PF.interpreter( ast.left )( n ) < Jed.PF.interpreter( ast.right )( n );
        case 'GT':
          return Jed.PF.interpreter( ast.left )( n ) > Jed.PF.interpreter( ast.right )( n );
        case 'LTE':
          return Jed.PF.interpreter( ast.left )( n ) <= Jed.PF.interpreter( ast.right )( n );
        case 'GTE':
          return Jed.PF.interpreter( ast.left )( n ) >= Jed.PF.interpreter( ast.right )( n );
        case 'EQ':
          return Jed.PF.interpreter( ast.left )( n ) == Jed.PF.interpreter( ast.right )( n );
        case 'NEQ':
          return Jed.PF.interpreter( ast.left )( n ) != Jed.PF.interpreter( ast.right )( n );
        case 'MOD':
          return Jed.PF.interpreter( ast.left )( n ) % Jed.PF.interpreter( ast.right )( n );
        case 'VAR':
          return n;
        case 'NUM':
          return ast.val;
        default:
          throw new Error("Invalid Token found.");
      }
    };
  };

  Jed.PF.extractPluralExpr = function ( p ) {
    // trim first
    p = p.replace(/^\s\s*/, '').replace(/\s\s*$/, '');

    if (! /;\s*$/.test(p)) {
      p = p.concat(';');
    }

    var nplurals_re = /nplurals\=(\d+);/,
        plural_re = /plural\=(.*);/,
        nplurals_matches = p.match( nplurals_re ),
        res = {},
        plural_matches;

    // Find the nplurals number
    if ( nplurals_matches.length > 1 ) {
      res.nplurals = nplurals_matches[1];
    }
    else {
      throw new Error('nplurals not found in plural_forms string: ' + p );
    }

    // remove that data to get to the formula
    p = p.replace( nplurals_re, "" );
    plural_matches = p.match( plural_re );

    if (!( plural_matches && plural_matches.length > 1 ) ) {
      throw new Error('`plural` expression not found: ' + p);
    }
    return plural_matches[ 1 ];
  };

  /* Jison generated parser */
  Jed.PF.parser = (function(){

var parser = {trace: function trace() { },
yy: {},
symbols_: {"error":2,"expressions":3,"e":4,"EOF":5,"?":6,":":7,"||":8,"&&":9,"<":10,"<=":11,">":12,">=":13,"!=":14,"==":15,"%":16,"(":17,")":18,"n":19,"NUMBER":20,"$accept":0,"$end":1},
terminals_: {2:"error",5:"EOF",6:"?",7:":",8:"||",9:"&&",10:"<",11:"<=",12:">",13:">=",14:"!=",15:"==",16:"%",17:"(",18:")",19:"n",20:"NUMBER"},
productions_: [0,[3,2],[4,5],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,1],[4,1]],
performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) {

var $0 = $$.length - 1;
switch (yystate) {
case 1: return { type : 'GROUP', expr: $$[$0-1] };
case 2:this.$ = { type: 'TERNARY', expr: $$[$0-4], truthy : $$[$0-2], falsey: $$[$0] };
break;
case 3:this.$ = { type: "OR", left: $$[$0-2], right: $$[$0] };
break;
case 4:this.$ = { type: "AND", left: $$[$0-2], right: $$[$0] };
break;
case 5:this.$ = { type: 'LT', left: $$[$0-2], right: $$[$0] };
break;
case 6:this.$ = { type: 'LTE', left: $$[$0-2], right: $$[$0] };
break;
case 7:this.$ = { type: 'GT', left: $$[$0-2], right: $$[$0] };
break;
case 8:this.$ = { type: 'GTE', left: $$[$0-2], right: $$[$0] };
break;
case 9:this.$ = { type: 'NEQ', left: $$[$0-2], right: $$[$0] };
break;
case 10:this.$ = { type: 'EQ', left: $$[$0-2], right: $$[$0] };
break;
case 11:this.$ = { type: 'MOD', left: $$[$0-2], right: $$[$0] };
break;
case 12:this.$ = { type: 'GROUP', expr: $$[$0-1] };
break;
case 13:this.$ = { type: 'VAR' };
break;
case 14:this.$ = { type: 'NUM', val: Number(yytext) };
break;
}
},
table: [{3:1,4:2,17:[1,3],19:[1,4],20:[1,5]},{1:[3]},{5:[1,6],6:[1,7],8:[1,8],9:[1,9],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16]},{4:17,17:[1,3],19:[1,4],20:[1,5]},{5:[2,13],6:[2,13],7:[2,13],8:[2,13],9:[2,13],10:[2,13],11:[2,13],12:[2,13],13:[2,13],14:[2,13],15:[2,13],16:[2,13],18:[2,13]},{5:[2,14],6:[2,14],7:[2,14],8:[2,14],9:[2,14],10:[2,14],11:[2,14],12:[2,14],13:[2,14],14:[2,14],15:[2,14],16:[2,14],18:[2,14]},{1:[2,1]},{4:18,17:[1,3],19:[1,4],20:[1,5]},{4:19,17:[1,3],19:[1,4],20:[1,5]},{4:20,17:[1,3],19:[1,4],20:[1,5]},{4:21,17:[1,3],19:[1,4],20:[1,5]},{4:22,17:[1,3],19:[1,4],20:[1,5]},{4:23,17:[1,3],19:[1,4],20:[1,5]},{4:24,17:[1,3],19:[1,4],20:[1,5]},{4:25,17:[1,3],19:[1,4],20:[1,5]},{4:26,17:[1,3],19:[1,4],20:[1,5]},{4:27,17:[1,3],19:[1,4],20:[1,5]},{6:[1,7],8:[1,8],9:[1,9],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16],18:[1,28]},{6:[1,7],7:[1,29],8:[1,8],9:[1,9],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16]},{5:[2,3],6:[2,3],7:[2,3],8:[2,3],9:[1,9],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16],18:[2,3]},{5:[2,4],6:[2,4],7:[2,4],8:[2,4],9:[2,4],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16],18:[2,4]},{5:[2,5],6:[2,5],7:[2,5],8:[2,5],9:[2,5],10:[2,5],11:[2,5],12:[2,5],13:[2,5],14:[2,5],15:[2,5],16:[1,16],18:[2,5]},{5:[2,6],6:[2,6],7:[2,6],8:[2,6],9:[2,6],10:[2,6],11:[2,6],12:[2,6],13:[2,6],14:[2,6],15:[2,6],16:[1,16],18:[2,6]},{5:[2,7],6:[2,7],7:[2,7],8:[2,7],9:[2,7],10:[2,7],11:[2,7],12:[2,7],13:[2,7],14:[2,7],15:[2,7],16:[1,16],18:[2,7]},{5:[2,8],6:[2,8],7:[2,8],8:[2,8],9:[2,8],10:[2,8],11:[2,8],12:[2,8],13:[2,8],14:[2,8],15:[2,8],16:[1,16],18:[2,8]},{5:[2,9],6:[2,9],7:[2,9],8:[2,9],9:[2,9],10:[2,9],11:[2,9],12:[2,9],13:[2,9],14:[2,9],15:[2,9],16:[1,16],18:[2,9]},{5:[2,10],6:[2,10],7:[2,10],8:[2,10],9:[2,10],10:[2,10],11:[2,10],12:[2,10],13:[2,10],14:[2,10],15:[2,10],16:[1,16],18:[2,10]},{5:[2,11],6:[2,11],7:[2,11],8:[2,11],9:[2,11],10:[2,11],11:[2,11],12:[2,11],13:[2,11],14:[2,11],15:[2,11],16:[2,11],18:[2,11]},{5:[2,12],6:[2,12],7:[2,12],8:[2,12],9:[2,12],10:[2,12],11:[2,12],12:[2,12],13:[2,12],14:[2,12],15:[2,12],16:[2,12],18:[2,12]},{4:30,17:[1,3],19:[1,4],20:[1,5]},{5:[2,2],6:[1,7],7:[2,2],8:[1,8],9:[1,9],10:[1,10],11:[1,11],12:[1,12],13:[1,13],14:[1,14],15:[1,15],16:[1,16],18:[2,2]}],
defaultActions: {6:[2,1]},
parseError: function parseError(str, hash) {
    throw new Error(str);
},
parse: function parse(input) {
    var self = this,
        stack = [0],
        vstack = [null], // semantic value stack
        lstack = [], // location stack
        table = this.table,
        yytext = '',
        yylineno = 0,
        yyleng = 0,
        recovering = 0,
        TERROR = 2,
        EOF = 1;

    //this.reductionCount = this.shiftCount = 0;

    this.lexer.setInput(input);
    this.lexer.yy = this.yy;
    this.yy.lexer = this.lexer;
    if (typeof this.lexer.yylloc == 'undefined')
        this.lexer.yylloc = {};
    var yyloc = this.lexer.yylloc;
    lstack.push(yyloc);

    if (typeof this.yy.parseError === 'function')
        this.parseError = this.yy.parseError;

    function popStack (n) {
        stack.length = stack.length - 2*n;
        vstack.length = vstack.length - n;
        lstack.length = lstack.length - n;
    }

    function lex() {
        var token;
        token = self.lexer.lex() || 1; // $end = 1
        // if token isn't its numeric value, convert
        if (typeof token !== 'number') {
            token = self.symbols_[token] || token;
        }
        return token;
    }

    var symbol, preErrorSymbol, state, action, a, r, yyval={},p,len,newState, expected, errStr;
    while (true) {
        // retreive state number from top of stack
        state = stack[stack.length-1];

        // use default actions if available
        if (this.defaultActions[state]) {
            action = this.defaultActions[state];
        } else {
            if (symbol === null || symbol === undefined)
                symbol = lex();
            // read action for current state and first input
            action = table[state] && table[state][symbol];
        }

        // handle parse error
        _handle_error:
        if (typeof action === 'undefined' || !action.length || !action[0]) {

            if (!recovering) {
                // Report error
                expected = [];
                for (p in table[state]) if (this.terminals_[p] && p > 2) {
                    expected.push("'"+this.terminals_[p]+"'");
                }
                errStr = '';
                if (this.lexer.showPosition) {
                    errStr = 'Parse error on line '+(yylineno+1)+":\n"+this.lexer.showPosition()+"\nExpecting "+expected.join(', ') + ", got '" + this.terminals_[symbol]+ "'";
                } else {
                    errStr = 'Parse error on line '+(yylineno+1)+": Unexpected " +
                                  (symbol == 1 /*EOF*/ ? "end of input" :
                                              ("'"+(this.terminals_[symbol] || symbol)+"'"));
                }
                this.parseError(errStr,
                    {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected});
            }

            // just recovered from another error
            if (recovering == 3) {
                if (symbol == EOF) {
                    throw new Error(errStr || 'Parsing halted.');
                }

                // discard current lookahead and grab another
                yyleng = this.lexer.yyleng;
                yytext = this.lexer.yytext;
                yylineno = this.lexer.yylineno;
                yyloc = this.lexer.yylloc;
                symbol = lex();
            }

            // try to recover from error
            while (1) {
                // check for error recovery rule in this state
                if ((TERROR.toString()) in table[state]) {
                    break;
                }
                if (state === 0) {
                    throw new Error(errStr || 'Parsing halted.');
                }
                popStack(1);
                state = stack[stack.length-1];
            }

            preErrorSymbol = symbol; // save the lookahead token
            symbol = TERROR;         // insert generic error symbol as new lookahead
            state = stack[stack.length-1];
            action = table[state] && table[state][TERROR];
            recovering = 3; // allow 3 real symbols to be shifted before reporting a new error
        }

        // this shouldn't happen, unless resolve defaults are off
        if (action[0] instanceof Array && action.length > 1) {
            throw new Error('Parse Error: multiple actions possible at state: '+state+', token: '+symbol);
        }

        switch (action[0]) {

            case 1: // shift
                //this.shiftCount++;

                stack.push(symbol);
                vstack.push(this.lexer.yytext);
                lstack.push(this.lexer.yylloc);
                stack.push(action[1]); // push state
                symbol = null;
                if (!preErrorSymbol) { // normal execution/no error
                    yyleng = this.lexer.yyleng;
                    yytext = this.lexer.yytext;
                    yylineno = this.lexer.yylineno;
                    yyloc = this.lexer.yylloc;
                    if (recovering > 0)
                        recovering--;
                } else { // error just occurred, resume old lookahead f/ before error
                    symbol = preErrorSymbol;
                    preErrorSymbol = null;
                }
                break;

            case 2: // reduce
                //this.reductionCount++;

                len = this.productions_[action[1]][1];

                // perform semantic action
                yyval.$ = vstack[vstack.length-len]; // default to $$ = $1
                // default location, uses first token for firsts, last for lasts
                yyval._$ = {
                    first_line: lstack[lstack.length-(len||1)].first_line,
                    last_line: lstack[lstack.length-1].last_line,
                    first_column: lstack[lstack.length-(len||1)].first_column,
                    last_column: lstack[lstack.length-1].last_column
                };
                r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack);

                if (typeof r !== 'undefined') {
                    return r;
                }

                // pop off stack
                if (len) {
                    stack = stack.slice(0,-1*len*2);
                    vstack = vstack.slice(0, -1*len);
                    lstack = lstack.slice(0, -1*len);
                }

                stack.push(this.productions_[action[1]][0]);    // push nonterminal (reduce)
                vstack.push(yyval.$);
                lstack.push(yyval._$);
                // goto new state = table[STATE][NONTERMINAL]
                newState = table[stack[stack.length-2]][stack[stack.length-1]];
                stack.push(newState);
                break;

            case 3: // accept
                return true;
        }

    }

    return true;
}};/* Jison generated lexer */
var lexer = (function(){

var lexer = ({EOF:1,
parseError:function parseError(str, hash) {
        if (this.yy.parseError) {
            this.yy.parseError(str, hash);
        } else {
            throw new Error(str);
        }
    },
setInput:function (input) {
        this._input = input;
        this._more = this._less = this.done = false;
        this.yylineno = this.yyleng = 0;
        this.yytext = this.matched = this.match = '';
        this.conditionStack = ['INITIAL'];
        this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0};
        return this;
    },
input:function () {
        var ch = this._input[0];
        this.yytext+=ch;
        this.yyleng++;
        this.match+=ch;
        this.matched+=ch;
        var lines = ch.match(/\n/);
        if (lines) this.yylineno++;
        this._input = this._input.slice(1);
        return ch;
    },
unput:function (ch) {
        this._input = ch + this._input;
        return this;
    },
more:function () {
        this._more = true;
        return this;
    },
pastInput:function () {
        var past = this.matched.substr(0, this.matched.length - this.match.length);
        return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, "");
    },
upcomingInput:function () {
        var next = this.match;
        if (next.length < 20) {
            next += this._input.substr(0, 20-next.length);
        }
        return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, "");
    },
showPosition:function () {
        var pre = this.pastInput();
        var c = new Array(pre.length + 1).join("-");
        return pre + this.upcomingInput() + "\n" + c+"^";
    },
next:function () {
        if (this.done) {
            return this.EOF;
        }
        if (!this._input) this.done = true;

        var token,
            match,
            col,
            lines;
        if (!this._more) {
            this.yytext = '';
            this.match = '';
        }
        var rules = this._currentRules();
        for (var i=0;i < rules.length; i++) {
            match = this._input.match(this.rules[rules[i]]);
            if (match) {
                lines = match[0].match(/\n.*/g);
                if (lines) this.yylineno += lines.length;
                this.yylloc = {first_line: this.yylloc.last_line,
                               last_line: this.yylineno+1,
                               first_column: this.yylloc.last_column,
                               last_column: lines ? lines[lines.length-1].length-1 : this.yylloc.last_column + match[0].length};
                this.yytext += match[0];
                this.match += match[0];
                this.matches = match;
                this.yyleng = this.yytext.length;
                this._more = false;
                this._input = this._input.slice(match[0].length);
                this.matched += match[0];
                token = this.performAction.call(this, this.yy, this, rules[i],this.conditionStack[this.conditionStack.length-1]);
                if (token) return token;
                else return;
            }
        }
        if (this._input === "") {
            return this.EOF;
        } else {
            this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(),
                    {text: "", token: null, line: this.yylineno});
        }
    },
lex:function lex() {
        var r = this.next();
        if (typeof r !== 'undefined') {
            return r;
        } else {
            return this.lex();
        }
    },
begin:function begin(condition) {
        this.conditionStack.push(condition);
    },
popState:function popState() {
        return this.conditionStack.pop();
    },
_currentRules:function _currentRules() {
        return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules;
    },
topState:function () {
        return this.conditionStack[this.conditionStack.length-2];
    },
pushState:function begin(condition) {
        this.begin(condition);
    }});
lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {

var YYSTATE=YY_START;
switch($avoiding_name_collisions) {
case 0:/* skip whitespace */
break;
case 1:return 20
break;
case 2:return 19
break;
case 3:return 8
break;
case 4:return 9
break;
case 5:return 6
break;
case 6:return 7
break;
case 7:return 11
break;
case 8:return 13
break;
case 9:return 10
break;
case 10:return 12
break;
case 11:return 14
break;
case 12:return 15
break;
case 13:return 16
break;
case 14:return 17
break;
case 15:return 18
break;
case 16:return 5
break;
case 17:return 'INVALID'
break;
}
};
lexer.rules = [/^\s+/,/^[0-9]+(\.[0-9]+)?\b/,/^n\b/,/^\|\|/,/^&&/,/^\?/,/^:/,/^<=/,/^>=/,/^</,/^>/,/^!=/,/^==/,/^%/,/^\(/,/^\)/,/^$/,/^./];
lexer.conditions = {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],"inclusive":true}};return lexer;})()
parser.lexer = lexer;
return parser;
})();
;
        plural_forms_parser = Jed.PF;
        function _get_plural_forms_function(plural_forms_string) {
            return plural_forms_parser.compile(plural_forms_string || "nplurals=2; plural=(n != 1);");
        };
        if (!_get_plural_forms_function.__argnames__) Object.defineProperties(_get_plural_forms_function, {
            __argnames__ : {value: ["plural_forms_string"]},
            __module__ : {value: "gettext"}
        });

        _gettext = (function() {
            var ρσ_anonfunc = function (text) {
                return text;
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["text"]},
                __module__ : {value: "gettext"}
            });
            return ρσ_anonfunc;
        })();
        _ngettext = (function() {
            var ρσ_anonfunc = function (text, plural, n) {
                return (n === 1) ? text : plural;
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["text", "plural", "n"]},
                __module__ : {value: "gettext"}
            });
            return ρσ_anonfunc;
        })();
        function gettext(text) {
            return _gettext(text);
        };
        if (!gettext.__argnames__) Object.defineProperties(gettext, {
            __argnames__ : {value: ["text"]},
            __module__ : {value: "gettext"}
        });

        function ngettext(text, plural, n) {
            return _ngettext(text, plural, n);
        };
        if (!ngettext.__argnames__) Object.defineProperties(ngettext, {
            __argnames__ : {value: ["text", "plural", "n"]},
            __module__ : {value: "gettext"}
        });

        function install(translation_data) {
            var t, func;
            t = new Translations(translation_data);
            t.install();
            var ρσ_Iter0 = ρσ_Iterable(register_callback.install_callbacks);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                func = ρσ_Iter0[ρσ_Index0];
                try {
                    func(t);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                    } 
                }
            }
            return t;
        };
        if (!install.__argnames__) Object.defineProperties(install, {
            __argnames__ : {value: ["translation_data"]},
            __module__ : {value: "gettext"}
        });

        has_prop = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
        function register_callback(func) {
            register_callback.install_callbacks.push(func);
        };
        if (!register_callback.__argnames__) Object.defineProperties(register_callback, {
            __argnames__ : {value: ["func"]},
            __module__ : {value: "gettext"}
        });

        register_callback.install_callbacks = [];
        empty_translation_data = (function(){
            var ρσ_d = {};
            ρσ_d["entries"] = {};
            return ρσ_d;
        }).call(this);
        function Translations() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            Translations.prototype.__init__.apply(this, arguments);
        }
        Translations.prototype.__init__ = function __init__(translation_data) {
            var self = this;
            var func;
            translation_data = translation_data || empty_translation_data;
            func = _get_plural_forms_function(translation_data.plural_forms);
            self.translations = ρσ_list_decorate([ ρσ_list_decorate([ translation_data, func ]) ]);
            self.language = translation_data["language"];
        };
        if (!Translations.prototype.__init__.__argnames__) Object.defineProperties(Translations.prototype.__init__, {
            __argnames__ : {value: ["translation_data"]},
            __module__ : {value: "gettext"}
        });
        Translations.__argnames__ = Translations.prototype.__init__.__argnames__;
        Translations.__handles_kwarg_interpolation__ = Translations.prototype.__init__.__handles_kwarg_interpolation__;
        Translations.prototype.add_fallback = function add_fallback(fallback) {
            var self = this;
            var func;
            fallback = fallback || empty_translation_data;
            func = _get_plural_forms_function(fallback.plural_forms);
            self.translations.push(ρσ_list_decorate([ fallback, func ]));
        };
        if (!Translations.prototype.add_fallback.__argnames__) Object.defineProperties(Translations.prototype.add_fallback, {
            __argnames__ : {value: ["fallback"]},
            __module__ : {value: "gettext"}
        });
        Translations.prototype.gettext = function gettext(text) {
            var self = this;
            var m, t;
            var ρσ_Iter1 = ρσ_Iterable(self.translations);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                t = ρσ_Iter1[ρσ_Index1];
                m = t[0].entries;
                if (has_prop(m, text)) {
                    return m[(typeof text === "number" && text < 0) ? m.length + text : text][0];
                }
            }
            return text;
        };
        if (!Translations.prototype.gettext.__argnames__) Object.defineProperties(Translations.prototype.gettext, {
            __argnames__ : {value: ["text"]},
            __module__ : {value: "gettext"}
        });
        Translations.prototype.ngettext = function ngettext(text, plural, n) {
            var self = this;
            var m, idx, t;
            var ρσ_Iter2 = ρσ_Iterable(self.translations);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                t = ρσ_Iter2[ρσ_Index2];
                m = t[0].entries;
                if (has_prop(m, text)) {
                    idx = t[1](n);
                    return (ρσ_expr_temp = m[(typeof text === "number" && text < 0) ? m.length + text : text])[(typeof idx === "number" && idx < 0) ? ρσ_expr_temp.length + idx : idx] || ((n === 1) ? text : plural);
                }
            }
            return (n === 1) ? text : plural;
        };
        if (!Translations.prototype.ngettext.__argnames__) Object.defineProperties(Translations.prototype.ngettext, {
            __argnames__ : {value: ["text", "plural", "n"]},
            __module__ : {value: "gettext"}
        });
        Translations.prototype.install = function install() {
            var self = this;
            _gettext = (function() {
                var ρσ_anonfunc = function () {
                    return self.gettext.apply(self, arguments);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "gettext"}
                });
                return ρσ_anonfunc;
            })();
            _ngettext = (function() {
                var ρσ_anonfunc = function () {
                    return self.ngettext.apply(self, arguments);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "gettext"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!Translations.prototype.install.__module__) Object.defineProperties(Translations.prototype.install, {
            __module__ : {value: "gettext"}
        });
        Translations.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        Translations.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(Translations.prototype, "__bases__", {value: []});

        ρσ_modules.gettext.Jed = Jed;
        ρσ_modules.gettext.plural_forms_parser = plural_forms_parser;
        ρσ_modules.gettext._gettext = _gettext;
        ρσ_modules.gettext._ngettext = _ngettext;
        ρσ_modules.gettext.has_prop = has_prop;
        ρσ_modules.gettext.empty_translation_data = empty_translation_data;
        ρσ_modules.gettext._get_plural_forms_function = _get_plural_forms_function;
        ρσ_modules.gettext.gettext = gettext;
        ρσ_modules.gettext.ngettext = ngettext;
        ρσ_modules.gettext.install = install;
        ρσ_modules.gettext.register_callback = register_callback;
        ρσ_modules.gettext.Translations = Translations;
    })();

    (function(){
        var __name__ = "ajax";
        var default_timeout;
        var _ = ρσ_modules.gettext.gettext;

        default_timeout = 300;
        function set_default_timeout(val) {
            default_timeout = val;
        };
        if (!set_default_timeout.__argnames__) Object.defineProperties(set_default_timeout, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "ajax"}
        });

        function encode_query_component(x) {
            var ans;
            ans = encodeURIComponent(x);
            ans = ans.replace(/%2[fF]/g, "/");
            ans = ans.replace(/%40/g, "@");
            ans = ans.replace(/%5[bB]/g, "[");
            ans = ans.replace(/%5[dD]/g, "]");
            ans = ans.replace(/%5[eE]/g, "^");
            ans = ans.replace(/%3[aA]/g, ":");
            return ans;
        };
        if (!encode_query_component.__argnames__) Object.defineProperties(encode_query_component, {
            __argnames__ : {value: ["x"]},
            __module__ : {value: "ajax"}
        });

        function encode_query(query, qchar) {
            var keys, ans, val, k;
            if (!query) {
                return "";
            }
            qchar = qchar || "?";
            keys = Object.keys(query).sort();
            ans = "";
            if (keys.length) {
                var ρσ_Iter0 = ρσ_Iterable(keys);
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    k = ρσ_Iter0[ρσ_Index0];
                    val = query[(typeof k === "number" && k < 0) ? query.length + k : k];
                    if (val === undefined || val === null || val === "") {
                        continue;
                    }
                    ans += qchar + encodeURIComponent(k) + "=" + encode_query_component(val.toString());
                    qchar = "&";
                }
            }
            return ans;
        };
        if (!encode_query.__argnames__) Object.defineProperties(encode_query, {
            __argnames__ : {value: ["query", "qchar"]},
            __module__ : {value: "ajax"}
        });

        function absolute_path(path) {
            var slash;
            if (path[0] !== "/") {
                slash = ((ρσ_expr_temp = window.location.pathname)[ρσ_expr_temp.length-1] === "/") ? "" : "/";
                path = window.location.pathname + slash + path;
            }
            return path;
        };
        if (!absolute_path.__argnames__) Object.defineProperties(absolute_path, {
            __argnames__ : {value: ["path"]},
            __module__ : {value: "ajax"}
        });

        function workaround_qt_bug() {
            var xhr = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var end_type = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var ok_code = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? workaround_qt_bug.__defaults__.ok_code : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ok_code")){
                ok_code = ρσ_kwargs_obj.ok_code;
            }
            if (end_type === "error" && xhr.status === ok_code && window.navigator.userAgent.indexOf("calibre-viewer") === 0) {
                end_type = "load";
            }
            return end_type;
        };
        if (!workaround_qt_bug.__defaults__) Object.defineProperties(workaround_qt_bug, {
            __defaults__ : {value: {ok_code:200}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["xhr", "end_type", "ok_code"]},
            __module__ : {value: "ajax"}
        });

        function ajax() {
            var path = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var on_complete = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var on_progress = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax.__defaults__.on_progress : arguments[2];
            var bypass_cache = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax.__defaults__.bypass_cache : arguments[3];
            var method = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax.__defaults__.method : arguments[4];
            var query = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax.__defaults__.query : arguments[5];
            var timeout = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax.__defaults__.timeout : arguments[6];
            var ok_code = (arguments[7] === undefined || ( 7 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax.__defaults__.ok_code : arguments[7];
            var progress_totals_needed = (arguments[8] === undefined || ( 8 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax.__defaults__.progress_totals_needed : arguments[8];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_progress")){
                on_progress = ρσ_kwargs_obj.on_progress;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "bypass_cache")){
                bypass_cache = ρσ_kwargs_obj.bypass_cache;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "method")){
                method = ρσ_kwargs_obj.method;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "query")){
                query = ρσ_kwargs_obj.query;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "timeout")){
                timeout = ρσ_kwargs_obj.timeout;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ok_code")){
                ok_code = ρσ_kwargs_obj.ok_code;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "progress_totals_needed")){
                progress_totals_needed = ρσ_kwargs_obj.progress_totals_needed;
            }
            var xhr, eq, has_query;
            if (timeout === null) {
                timeout = default_timeout;
            }
            query = query || Object.create(null);
            xhr = new XMLHttpRequest;
            eq = encode_query(query);
            has_query = eq.length > 0;
            path = absolute_path(path) + eq;
            if (bypass_cache) {
                path += ((has_query) ? "&" : "?") + (new Date).getTime();
            }
            xhr.request_path = path;
            xhr.error_html = "";
            function set_error(event, is_network_error) {
                var rtext;
                if (is_network_error) {
                    xhr.error_html = str.format(_("Failed to communicate with \"{}\", network error. Is the server running and accessible?"), xhr.request_path);
                } else if (event === "timeout") {
                    xhr.error_html = str.format(_("Failed to communicate with \"{}\", timed out after: {} seconds"), xhr.request_path, timeout);
                } else if (event === "abort") {
                    xhr.error_html = str.format(_("Failed to communicate with \"{}\", aborted"), xhr.request_path);
                } else {
                    try {
                        rtext = xhr.responseText || "";
                    } catch (ρσ_Exception) {
                        ρσ_last_exception = ρσ_Exception;
                        {
                            rtext = "";
                        } 
                    }
                    xhr.error_html = str.format(_("Failed to communicate with \"{}\", with status: [{} ({})] {}<br><br>{}"), xhr.request_path, xhr.status, event, xhr.statusText, rtext.slice(0, 200));
                }
            };
            if (!set_error.__argnames__) Object.defineProperties(set_error, {
                __argnames__ : {value: ["event", "is_network_error"]},
                __module__ : {value: "ajax"}
            });

            function progress_callback(ev) {
                var ul;
                if (ev.lengthComputable) {
                    on_progress(ev.loaded, ev.total, xhr);
                } else if (ev.loaded) {
                    if (!progress_totals_needed) {
                        on_progress(ev.loaded, undefined, xhr);
                        return;
                    }
                    ul = xhr.getResponseHeader("Calibre-Uncompressed-Length");
                    if (ul) {
                        try {
                            ul = int(ul);
                        } catch (ρσ_Exception) {
                            ρσ_last_exception = ρσ_Exception;
                            if (ρσ_Exception instanceof Error) {
                                return;
                            } else {
                                throw ρσ_Exception;
                            }
                        }
                        on_progress(ev.loaded, ul, xhr);
                    }
                }
            };
            if (!progress_callback.__argnames__) Object.defineProperties(progress_callback, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "ajax"}
            });

            function complete_callback(end_type, ev) {
                var is_network_error;
                is_network_error = (end_type === "error") ? ev : false;
                if (xhr.status !== ok_code && end_type === "load") {
                    end_type = "error";
                }
                end_type = workaround_qt_bug(xhr, end_type, ok_code);
                if (end_type !== "load") {
                    set_error(end_type, is_network_error);
                }
                on_complete(end_type, xhr, ev);
            };
            if (!complete_callback.__argnames__) Object.defineProperties(complete_callback, {
                __argnames__ : {value: ["end_type", "ev"]},
                __module__ : {value: "ajax"}
            });

            if (on_progress) {
                xhr.addEventListener("progress", progress_callback);
            }
            xhr.addEventListener("abort", (function() {
                var ρσ_anonfunc = function (ev) {
                    complete_callback("abort", ev);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "ajax"}
                });
                return ρσ_anonfunc;
            })());
            xhr.addEventListener("error", (function() {
                var ρσ_anonfunc = function (ev) {
                    complete_callback("error", ev);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "ajax"}
                });
                return ρσ_anonfunc;
            })());
            xhr.addEventListener("load", (function() {
                var ρσ_anonfunc = function (ev) {
                    complete_callback("load", ev);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "ajax"}
                });
                return ρσ_anonfunc;
            })());
            xhr.addEventListener("timeout", (function() {
                var ρσ_anonfunc = function (ev) {
                    complete_callback("timeout", ev);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "ajax"}
                });
                return ρσ_anonfunc;
            })());
            xhr.open(method, path);
            xhr.timeout = timeout * 1e3;
            return xhr;
        };
        if (!ajax.__defaults__) Object.defineProperties(ajax, {
            __defaults__ : {value: {on_progress:null, bypass_cache:true, method:"GET", query:null, timeout:null, ok_code:200, progress_totals_needed:true}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["path", "on_complete", "on_progress", "bypass_cache", "method", "query", "timeout", "ok_code", "progress_totals_needed"]},
            __module__ : {value: "ajax"}
        });

        function ajax_send() {
            var path = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var data = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var on_complete = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var on_progress = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax_send.__defaults__.on_progress : arguments[3];
            var query = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax_send.__defaults__.query : arguments[4];
            var timeout = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax_send.__defaults__.timeout : arguments[5];
            var ok_code = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax_send.__defaults__.ok_code : arguments[6];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_progress")){
                on_progress = ρσ_kwargs_obj.on_progress;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "query")){
                query = ρσ_kwargs_obj.query;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "timeout")){
                timeout = ρσ_kwargs_obj.timeout;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ok_code")){
                ok_code = ρσ_kwargs_obj.ok_code;
            }
            var xhr;
            xhr = ajax(path, on_complete, on_progress, false, "POST", query, timeout, ok_code);
            xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
            xhr.send(JSON.stringify(data));
            return xhr;
        };
        if (!ajax_send.__defaults__) Object.defineProperties(ajax_send, {
            __defaults__ : {value: {on_progress:null, query:null, timeout:null, ok_code:200}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["path", "data", "on_complete", "on_progress", "query", "timeout", "ok_code"]},
            __module__ : {value: "ajax"}
        });

        function ajax_send_file() {
            var path = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var file = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var on_complete = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var on_progress = ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[3];
            var timeout = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax_send_file.__defaults__.timeout : arguments[4];
            var ok_code = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax_send_file.__defaults__.ok_code : arguments[5];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "timeout")){
                timeout = ρσ_kwargs_obj.timeout;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ok_code")){
                ok_code = ρσ_kwargs_obj.ok_code;
            }
            var xhr;
            xhr = ajax(path, on_complete, on_progress, false, "POST", timeout, ok_code);
            if (file.type) {
                xhr.overrideMimeType(file.type);
            }
            xhr.send(file);
            return xhr;
        };
        if (!ajax_send_file.__defaults__) Object.defineProperties(ajax_send_file, {
            __defaults__ : {value: {timeout:null, ok_code:200}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["path", "file", "on_complete", "on_progress", "timeout", "ok_code"]},
            __module__ : {value: "ajax"}
        });

        function console_print() {
            var args = Array.prototype.slice.call(arguments, 0);
            if (arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) args.pop();
            var data, xhr;
            ρσ_print.apply(this, args);
            data = " ".join(map(str, args)) + "\n";
            xhr = ρσ_interpolate_kwargs.call(this, ajax, ["console-print", (function() {
                var ρσ_anonfunc = function () {
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "ajax"}
                });
                return ρσ_anonfunc;
            })()].concat([ρσ_desugar_kwargs({method: "POST", progress_totals_needed: false})]));
            xhr.send(data);
        };
        if (!console_print.__handles_kwarg_interpolation__) Object.defineProperties(console_print, {
            __handles_kwarg_interpolation__ : {value: true},
            __module__ : {value: "ajax"}
        });

        ρσ_modules.ajax.default_timeout = default_timeout;
        ρσ_modules.ajax.set_default_timeout = set_default_timeout;
        ρσ_modules.ajax.encode_query_component = encode_query_component;
        ρσ_modules.ajax.encode_query = encode_query;
        ρσ_modules.ajax.absolute_path = absolute_path;
        ρσ_modules.ajax.workaround_qt_bug = workaround_qt_bug;
        ρσ_modules.ajax.ajax = ajax;
        ρσ_modules.ajax.ajax_send = ajax_send;
        ρσ_modules.ajax.ajax_send_file = ajax_send_file;
        ρσ_modules.ajax.console_print = console_print;
    })();

    (function(){
        var __name__ = "book_list";

    })();

    (function(){
        var __name__ = "book_list.globals";
        var session_data;
        session_data = null;
        function set_session_data(sd) {
            session_data = sd;
            return session_data;
        };
        if (!set_session_data.__argnames__) Object.defineProperties(set_session_data, {
            __argnames__ : {value: ["sd"]},
            __module__ : {value: "book_list.globals"}
        });

        function get_session_data() {
            return session_data;
        };
        if (!get_session_data.__module__) Object.defineProperties(get_session_data, {
            __module__ : {value: "book_list.globals"}
        });

        function main_js(newval) {
            if (newval !== undefined) {
                main_js.ans = newval;
            }
            return main_js.ans;
        };
        if (!main_js.__argnames__) Object.defineProperties(main_js, {
            __argnames__ : {value: ["newval"]},
            __module__ : {value: "book_list.globals"}
        });

        function get_current_query(newval) {
            if (newval) {
                get_current_query.ans = newval;
            }
            return get_current_query.ans;
        };
        if (!get_current_query.__argnames__) Object.defineProperties(get_current_query, {
            __argnames__ : {value: ["newval"]},
            __module__ : {value: "book_list.globals"}
        });

        function get_db(db) {
            if (db) {
                get_db.db = db;
            }
            return get_db.db;
        };
        if (!get_db.__argnames__) Object.defineProperties(get_db, {
            __argnames__ : {value: ["db"]},
            __module__ : {value: "book_list.globals"}
        });

        function get_translations(val) {
            if (val) {
                get_translations.ans = val;
            }
            return get_translations.ans;
        };
        if (!get_translations.__argnames__) Object.defineProperties(get_translations, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "book_list.globals"}
        });

        function book_whose_metadata_is_being_edited() {
            var set_book_id = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? book_whose_metadata_is_being_edited.__defaults__.set_book_id : arguments[0];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "set_book_id")){
                set_book_id = ρσ_kwargs_obj.set_book_id;
            }
            if (typeof set_book_id === "number") {
                book_whose_metadata_is_being_edited.ans = set_book_id;
            } else if (set_book_id === null) {
                book_whose_metadata_is_being_edited.ans = null;
            }
            return book_whose_metadata_is_being_edited.ans;
        };
        if (!book_whose_metadata_is_being_edited.__defaults__) Object.defineProperties(book_whose_metadata_is_being_edited, {
            __defaults__ : {value: {set_book_id:""}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["set_book_id"]},
            __module__ : {value: "book_list.globals"}
        });

        ρσ_modules["book_list.globals"].session_data = session_data;
        ρσ_modules["book_list.globals"].set_session_data = set_session_data;
        ρσ_modules["book_list.globals"].get_session_data = get_session_data;
        ρσ_modules["book_list.globals"].main_js = main_js;
        ρσ_modules["book_list.globals"].get_current_query = get_current_query;
        ρσ_modules["book_list.globals"].get_db = get_db;
        ρσ_modules["book_list.globals"].get_translations = get_translations;
        ρσ_modules["book_list.globals"].book_whose_metadata_is_being_edited = book_whose_metadata_is_being_edited;
    })();

    (function(){
        var __name__ = "lru_cache";
        function lru_node(key, val) {
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["key"] = key;
                ρσ_d["val"] = val;
                ρσ_d["prev"] = null;
                ρσ_d["next"] = null;
                return ρσ_d;
            }).call(this);
        };
        if (!lru_node.__argnames__) Object.defineProperties(lru_node, {
            __argnames__ : {value: ["key", "val"]},
            __module__ : {value: "lru_cache"}
        });

        function LRUCache() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            LRUCache.prototype.__bind_methods__.call(this);
            LRUCache.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(LRUCache.prototype, "__bind_methods__", {value: function () {
            this.set_head = LRUCache.prototype.set_head.bind(this);
            this.pop = LRUCache.prototype.pop.bind(this);
            this.set = LRUCache.prototype.set.bind(this);
            this.get = LRUCache.prototype.get.bind(this);
            this.clear = LRUCache.prototype.clear.bind(this);
        }});
        LRUCache.prototype.__init__ = function __init__(size) {
            var self = this;
            self.limit = 200;
            self.clear(size);
        };
        if (!LRUCache.prototype.__init__.__argnames__) Object.defineProperties(LRUCache.prototype.__init__, {
            __argnames__ : {value: ["size"]},
            __module__ : {value: "lru_cache"}
        });
        LRUCache.__argnames__ = LRUCache.prototype.__init__.__argnames__;
        LRUCache.__handles_kwarg_interpolation__ = LRUCache.prototype.__init__.__handles_kwarg_interpolation__;
        LRUCache.prototype.set_head = function set_head(node) {
            var self = this;
            node.next = self.head;
            node.prev = null;
            if (self.head !== null) {
                self.head.prev = node;
            }
            self.head = node;
            if (self.tail === null) {
                self.tail = node;
            }
            self.size += 1;
            (ρσ_expr_temp = self.map)[ρσ_bound_index(node.key, ρσ_expr_temp)] = node;
        };
        if (!LRUCache.prototype.set_head.__argnames__) Object.defineProperties(LRUCache.prototype.set_head, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "lru_cache"}
        });
        LRUCache.prototype.pop = function pop(key) {
            var self = this;
            var node;
            node = (ρσ_expr_temp = self.map)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
            if (!node) {
                return;
            }
            if (node.prev !== null) {
                node.prev.next = node.next;
            } else {
                self.head = node.next;
            }
            if (node.next !== null) {
                node.next.prev = node.prev;
            } else {
                self.tail = node.prev;
            }
            delete self.map[key];
            self.size -= 1;
        };
        if (!LRUCache.prototype.pop.__argnames__) Object.defineProperties(LRUCache.prototype.pop, {
            __argnames__ : {value: ["key"]},
            __module__ : {value: "lru_cache"}
        });
        LRUCache.prototype.set = function set(key, val) {
            var self = this;
            var node, existing;
            node = lru_node(key, val);
            existing = (ρσ_expr_temp = self.map)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
            if (existing) {
                existing.value = node.value;
                self.pop(node.key);
            } else if (self.size > self.limit) {
                delete self.map[self.tail.key];
                self.size -= 1;
                self.tail = self.tail.prev;
                self.tail.next = null;
            }
            self.set_head(node);
        };
        if (!LRUCache.prototype.set.__argnames__) Object.defineProperties(LRUCache.prototype.set, {
            __argnames__ : {value: ["key", "val"]},
            __module__ : {value: "lru_cache"}
        });
        LRUCache.prototype.get = function get(key, defval) {
            var self = this;
            var existing, val, node;
            existing = (ρσ_expr_temp = self.map)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
            if (!existing) {
                return (defval === undefined) ? null : defval;
            }
            val = existing.value;
            node = lru_node(key, val);
            self.pop(key);
            self.set_head(node);
            return val;
        };
        if (!LRUCache.prototype.get.__argnames__) Object.defineProperties(LRUCache.prototype.get, {
            __argnames__ : {value: ["key", "defval"]},
            __module__ : {value: "lru_cache"}
        });
        LRUCache.prototype.clear = function clear(size) {
            var self = this;
            self.size = 0;
            self.map = Object.create(null);
            self.head = self.tail = null;
            if (typeof size === "number") {
                self.limit = size;
            }
        };
        if (!LRUCache.prototype.clear.__argnames__) Object.defineProperties(LRUCache.prototype.clear, {
            __argnames__ : {value: ["size"]},
            __module__ : {value: "lru_cache"}
        });
        LRUCache.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        LRUCache.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(LRUCache.prototype, "__bases__", {value: []});

        ρσ_modules.lru_cache.lru_node = lru_node;
        ρσ_modules.lru_cache.LRUCache = LRUCache;
    })();

    (function(){
        var __name__ = "encodings";
        var utf8_decoder_table, _u8enc, utf8_encode;
        function base64encode(bytes, altchars, pad_char) {
            var l, remainder, main_length, encodings, ans, chunk;
            l = bytes.length;
            remainder = l % 3;
            main_length = l - remainder;
            encodings = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + (altchars || "+/");
            pad_char = (pad_char === undefined) ? "=" : pad_char;
            ans = [];
            for (var i = 0; i < main_length; i += 3) {
                chunk = bytes[(typeof i === "number" && i < 0) ? bytes.length + i : i] << 16 | bytes[ρσ_bound_index(i + 1, bytes)] << 8 | bytes[ρσ_bound_index(i + 2, bytes)];
                ans.push(encodings[ρσ_bound_index((chunk & 16515072) >> 18, encodings)], encodings[ρσ_bound_index((chunk & 258048) >> 12, encodings)], encodings[ρσ_bound_index((chunk & 4032) >> 6, encodings)], encodings[ρσ_bound_index(chunk & 63, encodings)]);
            }
            if (remainder === 1) {
                chunk = bytes[(typeof main_length === "number" && main_length < 0) ? bytes.length + main_length : main_length];
                ans.push(encodings[ρσ_bound_index((chunk & 252) >> 2, encodings)], encodings[ρσ_bound_index((chunk & 3) << 4, encodings)], pad_char, pad_char);
            } else if (remainder === 2) {
                chunk = bytes[(typeof main_length === "number" && main_length < 0) ? bytes.length + main_length : main_length] << 8 | bytes[ρσ_bound_index(main_length + 1, bytes)];
                ans.push(encodings[ρσ_bound_index((chunk & 64512) >> 10, encodings)], encodings[ρσ_bound_index((chunk & 1008) >> 4, encodings)], encodings[ρσ_bound_index((chunk & 15) << 2, encodings)], pad_char);
            }
            return ans.join("");
        };
        if (!base64encode.__argnames__) Object.defineProperties(base64encode, {
            __argnames__ : {value: ["bytes", "altchars", "pad_char"]},
            __module__ : {value: "encodings"}
        });

        function base64decode(string) {
            var chars, ans, i;
            if (typeof window !== "undefined") {
                chars = window.atob(string);
            } else {
                chars = new Buffer(string, "base64").toString("binary");
            }
            ans = new Uint8Array(chars.length);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ans.length; ρσ_Index0++) {
                i = ρσ_Index0;
                ans[(typeof i === "number" && i < 0) ? ans.length + i : i] = chars.charCodeAt(i);
            }
            return ans;
        };
        if (!base64decode.__argnames__) Object.defineProperties(base64decode, {
            __argnames__ : {value: ["string"]},
            __module__ : {value: "encodings"}
        });

        function urlsafe_b64encode(bytes, pad_char) {
            return base64encode(bytes, "-_", pad_char);
        };
        if (!urlsafe_b64encode.__argnames__) Object.defineProperties(urlsafe_b64encode, {
            __argnames__ : {value: ["bytes", "pad_char"]},
            __module__ : {value: "encodings"}
        });

        function urlsafe_b64decode(string) {
            string = String.prototype.replace.call(string, /[_-]/g, (function() {
                var ρσ_anonfunc = function (m) {
                    return (m === "-") ? "+" : "/";
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["m"]},
                    __module__ : {value: "encodings"}
                });
                return ρσ_anonfunc;
            })());
            return base64decode(string);
        };
        if (!urlsafe_b64decode.__argnames__) Object.defineProperties(urlsafe_b64decode, {
            __argnames__ : {value: ["string"]},
            __module__ : {value: "encodings"}
        });

        function hexlify(bytes) {
            var ans, x;
            ans = [];
            for (var i = 0; i < bytes.length; i++) {
                x = bytes[(typeof i === "number" && i < 0) ? bytes.length + i : i].toString(16);
                if (x.length === 1) {
                    x = "0" + x;
                }
                ans.push(x);
            }
            return ans.join("");
        };
        if (!hexlify.__argnames__) Object.defineProperties(hexlify, {
            __argnames__ : {value: ["bytes"]},
            __module__ : {value: "encodings"}
        });

        function unhexlify(string) {
            var num, ans, x;
            num = Math.floor(string.length / 2);
            if (num * 2 !== string.length) {
                throw new ValueError("string length is not a multiple of two");
            }
            ans = new Uint8Array(num);
            for (var i = 0; i < num; i++) {
                x = parseInt(string.slice(i * 2, i * 2 + 2), 16);
                if (isNaN(x)) {
                    throw new ValueError("string is not hex-encoded");
                }
                ans[(typeof i === "number" && i < 0) ? ans.length + i : i] = x;
            }
            return ans;
        };
        if (!unhexlify.__argnames__) Object.defineProperties(unhexlify, {
            __argnames__ : {value: ["string"]},
            __module__ : {value: "encodings"}
        });

        utf8_decoder_table = [
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 00..1f
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 20..3f
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 40..5f
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 60..7f
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9, // 80..9f
  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, // a0..bf
  8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, // c0..df
  0xa,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x3,0x4,0x3,0x3, // e0..ef
  0xb,0x6,0x6,0x6,0x5,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8, // f0..ff
  0x0,0x1,0x2,0x3,0x5,0x8,0x7,0x1,0x1,0x1,0x4,0x6,0x1,0x1,0x1,0x1, // s0..s0
  1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,1, // s1..s2
  1,2,1,1,1,1,1,2,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1, // s3..s4
  1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,1,1,1, // s5..s6
  1,3,1,1,1,1,1,3,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // s7..s8
];
        function _from_code_point(x) {
            if (x <= 65535) {
                return String.fromCharCode(x);
            }
            x -= 65536;
            return String.fromCharCode((x >> 10) + 55296, x % 1024 + 56320);
        };
        if (!_from_code_point.__argnames__) Object.defineProperties(_from_code_point, {
            __argnames__ : {value: ["x"]},
            __module__ : {value: "encodings"}
        });

        function utf8_decode(bytes, errors, replacement) {
            var state, ans, byte, typ, codep;
            state = 0;
            ans = [];
            for (var i = 0, l = bytes.length; i < l; i++) {
                byte = bytes[(typeof i === "number" && i < 0) ? bytes.length + i : i];
                typ = utf8_decoder_table[(typeof byte === "number" && byte < 0) ? utf8_decoder_table.length + byte : byte];
                codep = (state !== 0) ? byte & 63 | codep << 6 : 255 >> typ & byte;
                state = utf8_decoder_table[ρσ_bound_index(256 + state * 16 + typ, utf8_decoder_table)];
                if (state === 0) {
                    ans.push(_from_code_point(codep));
                } else if (state === 1) {
                    if (!errors || errors === "strict") {
                        throw new UnicodeDecodeError(str.format("The byte 0x{:02x} at position {} is not valid UTF-8", byte, i));
                    } else if (errors === "replace") {
                        ans.push(replacement || "?");
                    }
                }
            }
            return ans.join("");
        };
        if (!utf8_decode.__argnames__) Object.defineProperties(utf8_decode, {
            __argnames__ : {value: ["bytes", "errors", "replacement"]},
            __module__ : {value: "encodings"}
        });

        function utf8_encode_js(string) {
            var escstr, ans, ch, i;
            escstr = encodeURIComponent(string);
            ans = [];
            for (var i = 0; i < escstr.length; i++) {
                ch = escstr[(typeof i === "number" && i < 0) ? escstr.length + i : i];
                if (ch === "%") {
                    ans.push(parseInt(escstr.slice(i + 1, i + 3), 16));
                    i += 2;
                } else {
                    ans.push(ch.charCodeAt(0));
                }
            }
            return new Uint8Array(ans);
        };
        if (!utf8_encode_js.__argnames__) Object.defineProperties(utf8_encode_js, {
            __argnames__ : {value: ["string"]},
            __module__ : {value: "encodings"}
        });

        if (typeof TextEncoder === "function") {
            _u8enc = new TextEncoder("utf-8");
            utf8_encode = _u8enc.encode.bind(_u8enc);
            _u8enc = undefined;
        } else {
            utf8_encode = utf8_encode_js;
        }
        function utf8_encode_native(string) {
            return _u8enc.encode(string);
        };
        if (!utf8_encode_native.__argnames__) Object.defineProperties(utf8_encode_native, {
            __argnames__ : {value: ["string"]},
            __module__ : {value: "encodings"}
        });

        ρσ_modules.encodings.utf8_decoder_table = utf8_decoder_table;
        ρσ_modules.encodings._u8enc = _u8enc;
        ρσ_modules.encodings.utf8_encode = utf8_encode;
        ρσ_modules.encodings.base64encode = base64encode;
        ρσ_modules.encodings.base64decode = base64decode;
        ρσ_modules.encodings.urlsafe_b64encode = urlsafe_b64encode;
        ρσ_modules.encodings.urlsafe_b64decode = urlsafe_b64decode;
        ρσ_modules.encodings.hexlify = hexlify;
        ρσ_modules.encodings.unhexlify = unhexlify;
        ρσ_modules.encodings._from_code_point = _from_code_point;
        ρσ_modules.encodings.utf8_decode = utf8_decode;
        ρσ_modules.encodings.utf8_encode_js = utf8_encode_js;
        ρσ_modules.encodings.utf8_encode_native = utf8_encode_native;
    })();

    (function(){
        var __name__ = "uuid";
        var RFC_4122, random_bytes;
        var hexlify = ρσ_modules.encodings.hexlify;
        var urlsafe_b64decode = ρσ_modules.encodings.urlsafe_b64decode;
        var urlsafe_b64encode = ρσ_modules.encodings.urlsafe_b64encode;

        RFC_4122 = 1;
        if (typeof crypto === "object" && crypto.getRandomValues) {
            random_bytes = (function() {
                var ρσ_anonfunc = function (num) {
                    var ans;
                    ans = new Uint8Array(num || 16);
                    crypto.getRandomValues(ans);
                    return ans;
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["num"]},
                    __module__ : {value: "uuid"}
                });
                return ρσ_anonfunc;
            })();
        } else {
            random_bytes = (function() {
                var ρσ_anonfunc = function (num) {
                    var ans, i;
                    ans = new Uint8Array(num || 16);
                    for (var ρσ_Index0 = 0; ρσ_Index0 < ans.length; ρσ_Index0++) {
                        i = ρσ_Index0;
                        ans[(typeof i === "number" && i < 0) ? ans.length + i : i] = Math.floor(Math.random() * 256);
                    }
                    return ans;
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["num"]},
                    __module__ : {value: "uuid"}
                });
                return ρσ_anonfunc;
            })();
        }
        function uuid4_bytes() {
            var data;
            data = random_bytes();
            data[6] = 64 | data[6] & 15;
            data[8] = (data[8] >> 4 & 3 | 8) << 4 | data[8] & 15;
            return data;
        };
        if (!uuid4_bytes.__module__) Object.defineProperties(uuid4_bytes, {
            __module__ : {value: "uuid"}
        });

        function as_str() {
            var h;
            h = this.hex;
            return h.slice(0, 8) + "-" + h.slice(8, 12) + "-" + h.slice(12, 16) + "-" + h.slice(16, 20) + "-" + h.slice(20);
        };
        if (!as_str.__module__) Object.defineProperties(as_str, {
            __module__ : {value: "uuid"}
        });

        function uuid4() {
            var b;
            b = uuid4_bytes();
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["hex"] = hexlify(b);
                ρσ_d["bytes"] = b;
                ρσ_d["variant"] = RFC_4122;
                ρσ_d["version"] = 4;
                ρσ_d["__str__"] = as_str;
                ρσ_d["toString"] = as_str;
                return ρσ_d;
            }).call(this);
        };
        if (!uuid4.__module__) Object.defineProperties(uuid4, {
            __module__ : {value: "uuid"}
        });

        function num_to_string(numbers, alphabet, pad_to_length) {
            var ans, alphabet_len, x, number;
            ans = [];
            alphabet_len = alphabet.length;
            numbers = Array.prototype.slice.call(numbers);
            for (var i = 0; i < numbers.length - 1; i++) {
                x = divmod(numbers[(typeof i === "number" && i < 0) ? numbers.length + i : i], alphabet_len);
                numbers[(typeof i === "number" && i < 0) ? numbers.length + i : i] = x[0];
                numbers[ρσ_bound_index(i + 1, numbers)] += x[1];
            }
            for (var i = 0; i < numbers.length; i++) {
                number = numbers[(typeof i === "number" && i < 0) ? numbers.length + i : i];
                while (number) {
                    x = divmod(number, alphabet_len);
                    number = x[0];
                    ans.push(alphabet[ρσ_bound_index(x[1], alphabet)]);
                }
            }
            if (pad_to_length && pad_to_length > ans.length) {
                ans.push(alphabet[0].repeat(pad_to_length - ans.length));
            }
            return ans.join("");
        };
        if (!num_to_string.__argnames__) Object.defineProperties(num_to_string, {
            __argnames__ : {value: ["numbers", "alphabet", "pad_to_length"]},
            __module__ : {value: "uuid"}
        });

        function short_uuid() {
            return urlsafe_b64encode(random_bytes(), "");
        };
        if (!short_uuid.__module__) Object.defineProperties(short_uuid, {
            __module__ : {value: "uuid"}
        });

        function short_uuid4() {
            return urlsafe_b64encode(uuid4_bytes(), "");
        };
        if (!short_uuid4.__module__) Object.defineProperties(short_uuid4, {
            __module__ : {value: "uuid"}
        });

        function decode_short_uuid(val) {
            return urlsafe_b64decode(val + "==");
        };
        if (!decode_short_uuid.__argnames__) Object.defineProperties(decode_short_uuid, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "uuid"}
        });

        ρσ_modules.uuid.RFC_4122 = RFC_4122;
        ρσ_modules.uuid.random_bytes = random_bytes;
        ρσ_modules.uuid.uuid4_bytes = uuid4_bytes;
        ρσ_modules.uuid.as_str = as_str;
        ρσ_modules.uuid.uuid4 = uuid4;
        ρσ_modules.uuid.num_to_string = num_to_string;
        ρσ_modules.uuid.short_uuid = short_uuid;
        ρσ_modules.uuid.short_uuid4 = short_uuid4;
        ρσ_modules.uuid.decode_short_uuid = decode_short_uuid;
    })();

    (function(){
        var __name__ = "session";
        var all_settings, defaults, x, standalone_reader_defaults, default_interface_data;
        var short_uuid = ρσ_modules.uuid.short_uuid;

        var ajax_send = ρσ_modules.ajax.ajax_send;

        all_settings = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["copy_to_library_dupes"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "add;overwrite";
                ρσ_d["category"] = "book_list";
                return ρσ_d;
            }).call(this);
            ρσ_d["last_sort_order"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = Object.create(null);
                ρσ_d["category"] = "book_list";
                return ρσ_d;
            }).call(this);
            ρσ_d["show_all_metadata"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = false;
                ρσ_d["category"] = "book_list";
                return ρσ_d;
            }).call(this);
            ρσ_d["show_nav_list_book_count"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = true;
                ρσ_d["category"] = "book_list";
                ρσ_d["is_local"] = false;
                return ρσ_d;
            }).call(this);
            ρσ_d["show_nav_list_avg_rating"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = true;
                ρσ_d["category"] = "book_list";
                ρσ_d["is_local"] = false;
                return ρσ_d;
            }).call(this);
            ρσ_d["show_sidebar_in_book_viewer"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = false;
                ρσ_d["category"] = "book_list";
                ρσ_d["is_local"] = false;
                return ρσ_d;
            }).call(this);
            ρσ_d["book_list_color_scheme"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "auto";
                ρσ_d["category"] = "book_list";
                ρσ_d["is_local"] = false;
                return ρσ_d;
            }).call(this);
            ρσ_d["ui_highlight_colors"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["light"] = "#437000";
                    ρσ_d["dark"] = "#6cb4ee";
                    return ρσ_d;
                }).call(this);
                ρσ_d["category"] = "book_list";
                ρσ_d["is_local"] = false;
                return ρσ_d;
            }).call(this);
            ρσ_d["series_nav_display_mode"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "stack";
                ρσ_d["category"] = "book_list";
                ρσ_d["is_local"] = false;
                return ρσ_d;
            }).call(this);
            ρσ_d["saved_virtual_libraries"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = [];
                ρσ_d["category"] = "book_list";
                ρσ_d["is_local"] = false;
                return ρσ_d;
            }).call(this);
            ρσ_d["browse_visible_fields"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = Object.create(null);
                ρσ_d["category"] = "book_list";
                ρσ_d["is_local"] = false;
                return ρσ_d;
            }).call(this);
            ρσ_d["sort"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "timestamp.desc";
                ρσ_d["category"] = "book_list";
                return ρσ_d;
            }).call(this);
            ρσ_d["view_mode"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "cover_grid";
                ρσ_d["category"] = "book_list";
                return ρσ_d;
            }).call(this);
            ρσ_d["cover_grid_tile_pct"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 17;
                ρσ_d["category"] = "book_list";
                return ρσ_d;
            }).call(this);
            ρσ_d["fts_related_words"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = true;
                ρσ_d["category"] = "book_list";
                return ρσ_d;
            }).call(this);
            ρσ_d["and_search_terms"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = false;
                ρσ_d["category"] = "tag_browser";
                return ρσ_d;
            }).call(this);
            ρσ_d["collapse_at"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 25;
                ρσ_d["category"] = "tag_browser";
                return ρσ_d;
            }).call(this);
            ρσ_d["dont_collapse"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "";
                ρσ_d["category"] = "tag_browser";
                return ρσ_d;
            }).call(this);
            ρσ_d["hide_empty_categories"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "no";
                ρσ_d["category"] = "tag_browser";
                return ρσ_d;
            }).call(this);
            ρσ_d["partition_method"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "first letter";
                ρσ_d["category"] = "tag_browser";
                return ρσ_d;
            }).call(this);
            ρσ_d["sort_tags_by"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "name";
                ρσ_d["category"] = "tag_browser";
                return ρσ_d;
            }).call(this);
            ρσ_d["background_image_fade"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 0;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["background_image_style"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "scaled";
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["background_image"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = null;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["base_font_size"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 16;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["book_scrollbar"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = false;
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["columns_per_screen"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["portrait"] = 0;
                    ρσ_d["landscape"] = 0;
                    return ρσ_d;
                }).call(this);
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["controls_help_shown_count"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 0;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                ρσ_d["disallowed_in_profile"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["controls_help_shown_count_rtl_page_progression"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 0;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                ρσ_d["disallowed_in_profile"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["cover_preserve_aspect_ratio"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = true;
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["current_color_scheme"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "system";
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["footer"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["left"] = "menu-icon-on-hover";
                    ρσ_d["right"] = "progress";
                    return ρσ_d;
                }).call(this);
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["header"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["right"] = "menu-icon-on-hover";
                    return ρσ_d;
                }).call(this);
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["controls_footer"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["right"] = "progress";
                    return ρσ_d;
                }).call(this);
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["left-margin"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = Object.create(null);
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["right-margin"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = Object.create(null);
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["hide_tooltips"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = false;
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["keyboard_shortcuts"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = Object.create(null);
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["lines_per_sec_auto"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 1;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["lines_per_sec_smooth"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 20;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["margin_bottom"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 20;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["margin_left"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 20;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["margin_right"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 20;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["margin_top"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 20;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["max_text_height"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 0;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["max_text_width"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 0;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["override_book_colors"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "never";
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["paged_margin_clicks_scroll_by_screen"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = true;
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["paged_wheel_scrolls_by_screen"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = false;
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["paged_wheel_section_jumps"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = true;
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["paged_pixel_scroll_threshold"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 60;
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["read_mode"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "paged";
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["scroll_auto_boundary_delay"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = 5;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["scroll_mouse_boundary_delay"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = .5;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["scroll_stop_boundaries"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = false;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["standalone_font_settings"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = Object.create(null);
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["standalone_misc_settings"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = Object.create(null);
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["standalone_recently_opened"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = [];
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                ρσ_d["disallowed_in_profile"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["user_color_schemes"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = Object.create(null);
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["user_stylesheet"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "";
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["word_actions"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = [];
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["highlight_style"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = null;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["highlights_export_format"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "text";
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["custom_highlight_styles"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = [];
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["show_selection_bar"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = true;
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["net_search_url"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "https://google.com/search?q={q}";
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["selection_bar_actions"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = ['copy', 'lookup', 'highlight', 'remove_highlight', 'search_net', 'clear'];
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["selection_bar_quick_highlights"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = [];
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["skipped_dialogs"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = {};
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                ρσ_d["disallowed_in_profile"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["tts"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = {};
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                ρσ_d["disallowed_in_profile"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["tts_backend"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = {};
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                ρσ_d["disallowed_in_profile"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["fullscreen_when_opening"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "auto";
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["book_search_mode"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "contains";
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["book_search_case_sensitive"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = false;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["reverse_page_turn_zones"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = false;
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = true;
                return ρσ_d;
            }).call(this);
            ρσ_d["gesture_overrides"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = Object.create(null);
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["cite_text_template"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "[{text}]({url})";
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["cite_hl_template"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "[{text}]({url})";
                ρσ_d["category"] = "read_book";
                return ρσ_d;
            }).call(this);
            ρσ_d["tts_bar_position"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["default"] = "float";
                ρσ_d["category"] = "read_book";
                ρσ_d["is_local"] = false;
                ρσ_d["disallowed_in_profile"] = false;
                return ρσ_d;
            }).call(this);
            return ρσ_d;
        }).call(this);
        defaults = Object.create(null);
        var ρσ_Iter0 = ρσ_Iterable(Object.entries(all_settings));
        for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
            x = ρσ_Iter0[ρσ_Index0];
            defaults[ρσ_bound_index(x[0], defaults)] = x[1].default;
        }
        function session_defaults() {
            return defaults;
        };
        if (!session_defaults.__module__) Object.defineProperties(session_defaults, {
            __module__ : {value: "session"}
        });

        function storage_available(which) {
            var storage, x;
            which = which || "localStorage";
            try {
                storage = window[(typeof which === "number" && which < 0) ? window.length + which : which];
                x = "__storage__test__";
                storage.setItem(x, x);
                storage.removeItem(x);
                return true;
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    return false;
                } 
            }
        };
        if (!storage_available.__argnames__) Object.defineProperties(storage_available, {
            __argnames__ : {value: ["which"]},
            __module__ : {value: "session"}
        });

        function FakeStorage() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            FakeStorage.prototype.__bind_methods__.call(this);
            FakeStorage.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(FakeStorage.prototype, "__bind_methods__", {value: function () {
            this.getItem = FakeStorage.prototype.getItem.bind(this);
            this.setItem = FakeStorage.prototype.setItem.bind(this);
            this.clear = FakeStorage.prototype.clear.bind(this);
        }});
        FakeStorage.prototype.__init__ = function __init__() {
            var self = this;
            self.data = Object.create(null);
        };
        if (!FakeStorage.prototype.__init__.__module__) Object.defineProperties(FakeStorage.prototype.__init__, {
            __module__ : {value: "session"}
        });
        FakeStorage.__argnames__ = FakeStorage.prototype.__init__.__argnames__;
        FakeStorage.__handles_kwarg_interpolation__ = FakeStorage.prototype.__init__.__handles_kwarg_interpolation__;
        FakeStorage.prototype.getItem = function getItem(key) {
            var self = this;
            return (ρσ_expr_temp = self.data)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
        };
        if (!FakeStorage.prototype.getItem.__argnames__) Object.defineProperties(FakeStorage.prototype.getItem, {
            __argnames__ : {value: ["key"]},
            __module__ : {value: "session"}
        });
        FakeStorage.prototype.setItem = function setItem(key, value) {
            var self = this;
            if (typeof value !== "string") {
                value = JSON.stringify(value);
            }
            (ρσ_expr_temp = self.data)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = value;
        };
        if (!FakeStorage.prototype.setItem.__argnames__) Object.defineProperties(FakeStorage.prototype.setItem, {
            __argnames__ : {value: ["key", "value"]},
            __module__ : {value: "session"}
        });
        FakeStorage.prototype.clear = function clear() {
            var self = this;
            self.data = Object.create(null);
        };
        if (!FakeStorage.prototype.clear.__module__) Object.defineProperties(FakeStorage.prototype.clear, {
            __module__ : {value: "session"}
        });
        FakeStorage.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        FakeStorage.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(FakeStorage.prototype, "__bases__", {value: []});

        function get_session_storage() {
            if (!get_session_storage.ans) {
                if (storage_available("localStorage")) {
                    get_session_storage.ans = window.localStorage;
                } else if (storage_available("sessionStorage")) {
                    get_session_storage.ans = window.sessionStorage;
                    console.error("localStorage not available using sessionStorage instead");
                } else {
                    get_session_storage.ans = new FakeStorage;
                    console.error("sessionStorage and localStorage not available using a temp cache instead");
                }
            }
            return get_session_storage.ans;
        };
        if (!get_session_storage.__module__) Object.defineProperties(get_session_storage, {
            __module__ : {value: "session"}
        });

        function SessionData() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            SessionData.prototype.__bind_methods__.call(this);
            SessionData.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(SessionData.prototype, "__bind_methods__", {value: function () {
            this.get = SessionData.prototype.get.bind(this);
            this.set = SessionData.prototype.set.bind(this);
            this.set_bulk = SessionData.prototype.set_bulk.bind(this);
            this.clear = SessionData.prototype.clear.bind(this);
        }});
        SessionData.prototype.__init__ = function __init__() {
            var self = this;
            var global_prefix = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.global_prefix : arguments[0];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "global_prefix")){
                global_prefix = ρσ_kwargs_obj.global_prefix;
            }
            self.global_prefix = global_prefix || "calibre-session-";
            self.storage = get_session_storage();
            self.overflow_storage = Object.create(null);
            self.has_overflow = false;
        };
        if (!SessionData.prototype.__init__.__defaults__) Object.defineProperties(SessionData.prototype.__init__, {
            __defaults__ : {value: {global_prefix:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["global_prefix"]},
            __module__ : {value: "session"}
        });
        SessionData.__argnames__ = SessionData.prototype.__init__.__argnames__;
        SessionData.__handles_kwarg_interpolation__ = SessionData.prototype.__init__.__handles_kwarg_interpolation__;
        SessionData.prototype.get = function get(key, defval) {
            var self = this;
            var ans;
            key = self.global_prefix + key;
            if (self.has_overflow) {
                ans = (ρσ_expr_temp = self.overflow_storage)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
                if (ans === undefined) {
                    ans = self.storage.getItem(key);
                }
            } else {
                ans = self.storage.getItem(key);
            }
            if (ans === undefined || ans === null) {
                if (defval === undefined) {
                    defval = null;
                }
                return defval;
            }
            try {
                return JSON.parse(ans);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    if (defval === undefined) {
                        defval = null;
                    }
                    return defval;
                } 
            }
        };
        if (!SessionData.prototype.get.__argnames__) Object.defineProperties(SessionData.prototype.get, {
            __argnames__ : {value: ["key", "defval"]},
            __module__ : {value: "session"}
        });
        SessionData.prototype.set = function set(key, value) {
            var self = this;
            key = self.global_prefix + key;
            if (value === null) {
                self.storage.removeItem(key);
                delete self.overflow_storage[key];
                return true;
            }
            value = JSON.stringify(value);
            try {
                self.storage.setItem(key, value);
                delete self.overflow_storage[key];
                return true;
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    (ρσ_expr_temp = self.overflow_storage)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = value;
                    self.has_overflow = true;
                    console.error("session storage has overflowed, using a temp cache instead");
                } 
            }
            return false;
        };
        if (!SessionData.prototype.set.__argnames__) Object.defineProperties(SessionData.prototype.set, {
            __argnames__ : {value: ["key", "value"]},
            __module__ : {value: "session"}
        });
        SessionData.prototype.set_bulk = function set_bulk(changes) {
            var self = this;
            var key;
            var ρσ_Iter1 = ρσ_Iterable(Object.keys(changes));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                key = ρσ_Iter1[ρσ_Index1];
                self.set(key, changes[(typeof key === "number" && key < 0) ? changes.length + key : key]);
            }
        };
        if (!SessionData.prototype.set_bulk.__argnames__) Object.defineProperties(SessionData.prototype.set_bulk, {
            __argnames__ : {value: ["changes"]},
            __module__ : {value: "session"}
        });
        SessionData.prototype.clear = function clear() {
            var self = this;
            self.storage.clear();
            self.overflow_storage = Object.create(null);
            self.has_overflow = false;
        };
        if (!SessionData.prototype.clear.__module__) Object.defineProperties(SessionData.prototype.clear, {
            __module__ : {value: "session"}
        });
        SessionData.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        SessionData.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(SessionData.prototype, "__bases__", {value: []});

        function local_storage() {
            if (!local_storage.storage) {
                local_storage.storage = new SessionData("calibre-local-");
            }
            return local_storage.storage;
        };
        if (!local_storage.__module__) Object.defineProperties(local_storage, {
            __module__ : {value: "session"}
        });

        function get_device_uuid() {
            var s, ans;
            if (!get_device_uuid.ans) {
                s = local_storage();
                ans = s.get("device_uuid");
                if (!ans) {
                    ans = short_uuid();
                    s.set("device_uuid", ans);
                }
                get_device_uuid.ans = ans;
            }
            return get_device_uuid.ans;
        };
        if (!get_device_uuid.__module__) Object.defineProperties(get_device_uuid, {
            __module__ : {value: "session"}
        });

        function deep_eq(a, b) {
            var i, ka, key;
            if (a === b) {
                return true;
            }
            if (Array.isArray(a) && Array.isArray(b)) {
                if (a.length !== b.length) {
                    return false;
                }
                for (var ρσ_Index2 = 0; ρσ_Index2 < a.length; ρσ_Index2++) {
                    i = ρσ_Index2;
                    if (!deep_eq(a[(typeof i === "number" && i < 0) ? a.length + i : i], b[(typeof i === "number" && i < 0) ? b.length + i : i])) {
                        return false;
                    }
                }
                return true;
            }
            if (a === null || b === null || a === undefined || b === undefined) {
                return false;
            }
            if (typeof a !== "object" || typeof b !== "object") {
                return false;
            }
            ka = Object.keys(a);
            if (ka.length !== Object.keys(b).length) {
                return false;
            }
            var ρσ_Iter3 = ρσ_Iterable(ka);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                key = ρσ_Iter3[ρσ_Index3];
                if (!deep_eq(a[(typeof key === "number" && key < 0) ? a.length + key : key], b[(typeof key === "number" && key < 0) ? b.length + key : key])) {
                    return false;
                }
            }
            return true;
        };
        if (!deep_eq.__argnames__) Object.defineProperties(deep_eq, {
            __argnames__ : {value: ["a", "b"]},
            __module__ : {value: "session"}
        });

        function setting_val_is_default(setting_name, curval) {
            var defval;
            defval = defaults[(typeof setting_name === "number" && setting_name < 0) ? defaults.length + setting_name : setting_name];
            return deep_eq(defval, curval);
        };
        if (!setting_val_is_default.__argnames__) Object.defineProperties(setting_val_is_default, {
            __argnames__ : {value: ["setting_name", "curval"]},
            __module__ : {value: "session"}
        });

        function get_subset_of_settings(sd, filter_func) {
            var ans, curval, metadata, is_set, setting_name;
            ans = Object.create(null);
            var ρσ_Iter4 = ρσ_Iterable(Object.keys(all_settings));
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                setting_name = ρσ_Iter4[ρσ_Index4];
                curval = sd.get(setting_name, ans);
                metadata = all_settings[(typeof setting_name === "number" && setting_name < 0) ? all_settings.length + setting_name : setting_name];
                is_set = curval !== ans;
                if (filter_func(setting_name, metadata, is_set, curval)) {
                    ans[(typeof setting_name === "number" && setting_name < 0) ? ans.length + setting_name : setting_name] = window.structuredClone((is_set) ? curval : metadata.default);
                }
            }
            return ans;
        };
        if (!get_subset_of_settings.__argnames__) Object.defineProperties(get_subset_of_settings, {
            __argnames__ : {value: ["sd", "filter_func"]},
            __module__ : {value: "session"}
        });

        function apply_profile(sd, profile, filter_func) {
            var changes, metadata, curval, is_set, newval, setting_name;
            changes = Object.create(null);
            var ρσ_Iter5 = ρσ_Iterable(Object.keys(all_settings));
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                setting_name = ρσ_Iter5[ρσ_Index5];
                metadata = all_settings[(typeof setting_name === "number" && setting_name < 0) ? all_settings.length + setting_name : setting_name];
                curval = sd.get(setting_name, changes);
                is_set = curval !== changes;
                if (filter_func(setting_name, metadata, is_set, curval)) {
                    newval = null;
                    if (Object.prototype.hasOwnProperty.call(profile, setting_name)) {
                        newval = profile[(typeof setting_name === "number" && setting_name < 0) ? profile.length + setting_name : setting_name];
                        if (deep_eq(newval, metadata.default)) {
                            newval = null;
                        }
                    }
                    changes[(typeof setting_name === "number" && setting_name < 0) ? changes.length + setting_name : setting_name] = window.structuredClone(newval);
                }
            }
            sd.set_bulk(changes);
            return changes;
        };
        if (!apply_profile.__argnames__) Object.defineProperties(apply_profile, {
            __argnames__ : {value: ["sd", "profile", "filter_func"]},
            __module__ : {value: "session"}
        });

        standalone_reader_defaults = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["remember_window_geometry"] = false;
            ρσ_d["remember_last_read"] = true;
            ρσ_d["show_actions_toolbar"] = false;
            ρσ_d["show_actions_toolbar_in_fullscreen"] = false;
            ρσ_d["save_annotations_in_ebook"] = true;
            ρσ_d["sync_annots_user"] = "";
            ρσ_d["singleinstance"] = false;
            ρσ_d["auto_hide_mouse"] = true;
            ρσ_d["restore_docks"] = true;
            return ρσ_d;
        }).call(this);
        function settings_for_reader_profile(sd) {
            var margin_text_settings;
            margin_text_settings = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["footer"] = true;
                ρσ_d["header"] = true;
                ρσ_d["controls_footer"] = true;
                ρσ_d["left-margin"] = true;
                ρσ_d["right-margin"] = true;
                return ρσ_d;
            }).call(this);
            function filter_func(setting_name, metadata, is_set, curval) {
                var x, key;
                if (margin_text_settings[(typeof setting_name === "number" && setting_name < 0) ? margin_text_settings.length + setting_name : setting_name]) {
                    curval = window.structuredClone(curval);
                    var ρσ_Iter6 = ρσ_Iterable(['left', 'right', 'middle']);
                    for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                        x = ρσ_Iter6[ρσ_Index6];
                        if (curval[(typeof x === "number" && x < 0) ? curval.length + x : x] === "empty") {
                            delete curval[x];
                        }
                    }
                } else if (setting_name === "standalone_misc_settings") {
                    curval = window.structuredClone(curval);
                    var ρσ_Iter7 = ρσ_Iterable(Object.keys(curval));
                    for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                        key = ρσ_Iter7[ρσ_Index7];
                        if (curval[(typeof key === "number" && key < 0) ? curval.length + key : key] === standalone_reader_defaults[(typeof key === "number" && key < 0) ? standalone_reader_defaults.length + key : key]) {
                            delete curval[key];
                        }
                    }
                }
                if (!is_set || metadata.category !== "read_book" || metadata.disallowed_in_profile || deep_eq(curval, metadata.default)) {
                    return false;
                }
                return true;
            };
            if (!filter_func.__argnames__) Object.defineProperties(filter_func, {
                __argnames__ : {value: ["setting_name", "metadata", "is_set", "curval"]},
                __module__ : {value: "session"}
            });

            return get_subset_of_settings(sd, filter_func);
        };
        if (!settings_for_reader_profile.__argnames__) Object.defineProperties(settings_for_reader_profile, {
            __argnames__ : {value: ["sd"]},
            __module__ : {value: "session"}
        });

        function apply_reader_profile(sd, profile) {
            function filter_func(setting_name, metadata, is_set, curval) {
                return metadata.category === "read_book" && !metadata.disallowed_in_profile;
            };
            if (!filter_func.__argnames__) Object.defineProperties(filter_func, {
                __argnames__ : {value: ["setting_name", "metadata", "is_set", "curval"]},
                __module__ : {value: "session"}
            });

            apply_profile(sd, profile, filter_func);
        };
        if (!apply_reader_profile.__argnames__) Object.defineProperties(apply_reader_profile, {
            __argnames__ : {value: ["sd", "profile"]},
            __module__ : {value: "session"}
        });

        default_interface_data = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["username"] = null;
            ρσ_d["output_format"] = "EPUB";
            ρσ_d["input_formats"] = (function(){
                var s = ρσ_set();
                s.jsset.add("EPUB");
                s.jsset.add("MOBI");
                s.jsset.add("AZW3");
                return s;
            })();
            ρσ_d["gui_pubdate_display_format"] = "MMM yyyy";
            ρσ_d["gui_timestamp_display_format"] = "dd MMM yyyy";
            ρσ_d["gui_last_modified_display_format"] = "dd MMM yyyy";
            ρσ_d["use_roman_numerals_for_series_number"] = true;
            ρσ_d["default_library_id"] = null;
            ρσ_d["default_book_list_mode"] = session_defaults().view_mode;
            ρσ_d["library_map"] = null;
            ρσ_d["search_the_net_urls"] = ρσ_list_decorate([]);
            ρσ_d["donate_link"] = "https://calibre-ebook.com/donate";
            ρσ_d["default_author_link"] = "";
            ρσ_d["icon_map"] = Object.create(null);
            ρσ_d["icon_path"] = "";
            ρσ_d["custom_list_template"] = null;
            ρσ_d["num_per_page"] = 50;
            ρσ_d["lang_code_for_user_manual"] = "";
            return ρσ_d;
        }).call(this);
        function get_interface_data() {
            var ans, k;
            if (!get_interface_data.storage) {
                get_interface_data.storage = new SessionData("calibre-interface-data-");
            }
            ans = get_interface_data.storage.get("current");
            if (ans) {
                ans.is_default = false;
            } else {
                ans = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["is_default"] = true;
                    return ρσ_d;
                }).call(this);
                var ρσ_Iter8 = ρσ_Iterable(default_interface_data);
                for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                    k = ρσ_Iter8[ρσ_Index8];
                    ans[(typeof k === "number" && k < 0) ? ans.length + k : k] = default_interface_data[(typeof k === "number" && k < 0) ? default_interface_data.length + k : k];
                }
            }
            return ans;
        };
        if (!get_interface_data.__module__) Object.defineProperties(get_interface_data, {
            __module__ : {value: "session"}
        });

        function update_interface_data(new_data) {
            var data, nval, k;
            data = get_interface_data();
            var ρσ_Iter9 = ρσ_Iterable(default_interface_data);
            for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                k = ρσ_Iter9[ρσ_Index9];
                nval = new_data[(typeof k === "number" && k < 0) ? new_data.length + k : k];
                if (k !== undefined) {
                    data[(typeof k === "number" && k < 0) ? data.length + k : k] = nval;
                }
            }
            if (!get_interface_data.storage) {
                get_interface_data.storage = new SessionData("calibre-interface-data-");
            }
            get_interface_data.storage.set("current", data);
        };
        if (!update_interface_data.__argnames__) Object.defineProperties(update_interface_data, {
            __argnames__ : {value: ["new_data"]},
            __module__ : {value: "session"}
        });

        function get_translations(newval) {
            if (!get_translations.storage) {
                get_translations.storage = new SessionData("calibre-translations-");
            }
            if ((typeof newval !== "undefined" && newval !== null)) {
                get_translations.storage.set("current", newval);
            } else {
                return get_translations.storage.get("current");
            }
        };
        if (!get_translations.__argnames__) Object.defineProperties(get_translations, {
            __argnames__ : {value: ["newval"]},
            __module__ : {value: "session"}
        });

        function is_setting_local(name) {
            var m;
            m = all_settings[(typeof name === "number" && name < 0) ? all_settings.length + name : name];
            return (m) ? m.is_local : true;
        };
        if (!is_setting_local.__argnames__) Object.defineProperties(is_setting_local, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "session"}
        });

        function UserSessionData() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            UserSessionData.prototype.__bind_methods__.call(this);
            UserSessionData.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(UserSessionData, SessionData);
        Object.defineProperty(UserSessionData.prototype, "__bind_methods__", {value: function () {
            SessionData.prototype.__bind_methods__ && SessionData.prototype.__bind_methods__.call(this);
            this.defval = UserSessionData.prototype.defval.bind(this);
            this.get = UserSessionData.prototype.get.bind(this);
            this.get_library_option = UserSessionData.prototype.get_library_option.bind(this);
            this.set = UserSessionData.prototype.set.bind(this);
            this.set_library_option = UserSessionData.prototype.set_library_option.bind(this);
            this.push_to_server = UserSessionData.prototype.push_to_server.bind(this);
        }});
        UserSessionData.prototype.__init__ = function __init__(username, saved_data) {
            var self = this;
            var key;
            self.prefix = (username || "") + "-";
            self.has_user = bool(username);
            self.username = username;
            SessionData.prototype.__init__.call(self);
            self.echo_changes = false;
            self.changes = Object.create(null);
            self.has_changes = false;
            self.push_timer_id = null;
            if (saved_data) {
                var ρσ_Iter10 = ρσ_Iterable(saved_data);
                for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                    key = ρσ_Iter10[ρσ_Index10];
                    if (!is_setting_local(key)) {
                        self.set(key, saved_data[(typeof key === "number" && key < 0) ? saved_data.length + key : key]);
                    }
                }
            }
            self.echo_changes = true;
        };
        if (!UserSessionData.prototype.__init__.__argnames__) Object.defineProperties(UserSessionData.prototype.__init__, {
            __argnames__ : {value: ["username", "saved_data"]},
            __module__ : {value: "session"}
        });
        UserSessionData.__argnames__ = UserSessionData.prototype.__init__.__argnames__;
        UserSessionData.__handles_kwarg_interpolation__ = UserSessionData.prototype.__init__.__handles_kwarg_interpolation__;
        UserSessionData.prototype.defval = function defval(key) {
            var self = this;
            var ans;
            ans = (ρσ_expr_temp = session_defaults())[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
            if (ans) {
                ans = window.structuredClone(ans);
            }
            return ans;
        };
        if (!UserSessionData.prototype.defval.__argnames__) Object.defineProperties(UserSessionData.prototype.defval, {
            __argnames__ : {value: ["key"]},
            __module__ : {value: "session"}
        });
        UserSessionData.prototype.get = function get(key, defval) {
            var self = this;
            if (defval === undefined) {
                defval = self.defval(key);
            }
            return SessionData.prototype.get.call(self, self.prefix + key, defval);
        };
        if (!UserSessionData.prototype.get.__argnames__) Object.defineProperties(UserSessionData.prototype.get, {
            __argnames__ : {value: ["key", "defval"]},
            __module__ : {value: "session"}
        });
        UserSessionData.prototype.get_library_option = function get_library_option(library_id, key, defval) {
            var self = this;
            var lkey;
            if (!library_id) {
                return self.get(key, defval);
            }
            lkey = key + "-||-" + library_id;
            if (defval === undefined) {
                defval = self.defval(key);
            }
            return self.get(lkey, defval);
        };
        if (!UserSessionData.prototype.get_library_option.__argnames__) Object.defineProperties(UserSessionData.prototype.get_library_option, {
            __argnames__ : {value: ["library_id", "key", "defval"]},
            __module__ : {value: "session"}
        });
        UserSessionData.prototype.set = function set(key, value) {
            var self = this;
            if (self.echo_changes && self.has_user && !is_setting_local(key)) {
                (ρσ_expr_temp = self.changes)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = value;
                self.has_changes = true;
                if (self.push_timer_id !== null) {
                    clearTimeout(self.push_timer_id);
                }
                self.push_timer_id = setTimeout(self.push_to_server.bind(self), 1e3);
            }
            return SessionData.prototype.set.call(self, self.prefix + key, value);
        };
        if (!UserSessionData.prototype.set.__argnames__) Object.defineProperties(UserSessionData.prototype.set, {
            __argnames__ : {value: ["key", "value"]},
            __module__ : {value: "session"}
        });
        UserSessionData.prototype.set_library_option = function set_library_option(library_id, key, value) {
            var self = this;
            if (library_id) {
                key = key + "-||-" + library_id;
            }
            return self.set(key, value);
        };
        if (!UserSessionData.prototype.set_library_option.__argnames__) Object.defineProperties(UserSessionData.prototype.set_library_option, {
            __argnames__ : {value: ["library_id", "key", "value"]},
            __module__ : {value: "session"}
        });
        UserSessionData.prototype.push_to_server = function push_to_server() {
            var self = this;
            if (self.has_changes) {
                ajax_send("interface-data/set-session-data", self.changes, (function() {
                    var ρσ_anonfunc = function (end_type, xhr, ev) {
                        if (end_type !== "load") {
                            console.error("Failed to send session data to server: " + xhr.error_html);
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["end_type", "xhr", "ev"]},
                        __module__ : {value: "session"}
                    });
                    return ρσ_anonfunc;
                })());
                self.changes = Object.create(null);
                self.has_changes = false;
            }
        };
        if (!UserSessionData.prototype.push_to_server.__module__) Object.defineProperties(UserSessionData.prototype.push_to_server, {
            __module__ : {value: "session"}
        });
        UserSessionData.prototype.__repr__ = function __repr__ () {
            if(SessionData.prototype.__repr__) return SessionData.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        UserSessionData.prototype.__str__ = function __str__ () {
            if(SessionData.prototype.__str__) return SessionData.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(UserSessionData.prototype, "__bases__", {value: [SessionData]});

        ρσ_modules.session.all_settings = all_settings;
        ρσ_modules.session.defaults = defaults;
        ρσ_modules.session.x = x;
        ρσ_modules.session.standalone_reader_defaults = standalone_reader_defaults;
        ρσ_modules.session.default_interface_data = default_interface_data;
        ρσ_modules.session.session_defaults = session_defaults;
        ρσ_modules.session.storage_available = storage_available;
        ρσ_modules.session.FakeStorage = FakeStorage;
        ρσ_modules.session.get_session_storage = get_session_storage;
        ρσ_modules.session.SessionData = SessionData;
        ρσ_modules.session.local_storage = local_storage;
        ρσ_modules.session.get_device_uuid = get_device_uuid;
        ρσ_modules.session.deep_eq = deep_eq;
        ρσ_modules.session.setting_val_is_default = setting_val_is_default;
        ρσ_modules.session.get_subset_of_settings = get_subset_of_settings;
        ρσ_modules.session.apply_profile = apply_profile;
        ρσ_modules.session.settings_for_reader_profile = settings_for_reader_profile;
        ρσ_modules.session.apply_reader_profile = apply_reader_profile;
        ρσ_modules.session.get_interface_data = get_interface_data;
        ρσ_modules.session.update_interface_data = update_interface_data;
        ρσ_modules.session.get_translations = get_translations;
        ρσ_modules.session.is_setting_local = is_setting_local;
        ρσ_modules.session.UserSessionData = UserSessionData;
    })();

    (function(){
        var __name__ = "dom";
        var simple_vendor_prefixes, extra_css, add_extra_css;
        simple_vendor_prefixes = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["animation"] = ['webkit', 'moz', 'o'];
            ρσ_d["animation-name"] = ['webkit', 'moz', 'o'];
            ρσ_d["animation-duration"] = ['webkit', 'moz', 'o'];
            ρσ_d["animation-timing-function"] = ['webkit', 'moz', 'o'];
            ρσ_d["animation-delay"] = ['webkit', 'moz', 'o'];
            ρσ_d["animation-iteration-count"] = ['webkit', 'moz', 'o'];
            ρσ_d["animation-direction"] = ['webkit', 'moz', 'o'];
            ρσ_d["animation-fill-mode"] = ['webkit', 'moz', 'o'];
            ρσ_d["animation-play-state"] = ['webkit', 'moz', 'o'];
            ρσ_d["hyphens"] = ['webkit', 'moz', 'ms'];
            ρσ_d["transform"] = ['webkit', 'ms', 'moz', 'o'];
            ρσ_d["transform-origin"] = ['webkit', 'ms', 'moz', 'o'];
            ρσ_d["transition"] = ['webkit', 'moz', 'o'];
            ρσ_d["filter"] = ['webkit'];
            ρσ_d["user-select"] = ['webkit', 'moz', 'ms'];
            ρσ_d["break-before"] = ['webkit-column'];
            ρσ_d["break-after"] = ['webkit-column'];
            ρσ_d["break-inside"] = ['webkit-column'];
            ρσ_d["column-gap"] = ['webkit', 'moz'];
            ρσ_d["column-width"] = ['webkit', 'moz'];
            ρσ_d["column-rule"] = ['webkit', 'moz'];
            ρσ_d["column-fill"] = ['moz'];
            return ρσ_d;
        }).call(this);
        function set_css() {
            var elem = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            var s, ρσ_unpack, name, val, prefixes, prefix, prop;
            if (typeof elem === "string") {
                elem = document.querySelector(elem);
            }
            s = elem.style;
            if (s) {
                var ρσ_Iter0 = ρσ_Iterable(kw);
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    prop = ρσ_Iter0[ρσ_Index0];
                    ρσ_unpack = [str.replace(str.rstrip(prop, "_"), "_", "-"), kw[(typeof prop === "number" && prop < 0) ? kw.length + prop : prop]];
                    name = ρσ_unpack[0];
                    val = ρσ_unpack[1];
                    if (val === null || val === undefined) {
                        s.removeProperty(name);
                    } else {
                        s.setProperty(name, val);
                    }
                    prefixes = simple_vendor_prefixes[(typeof name === "number" && name < 0) ? simple_vendor_prefixes.length + name : name];
                    if (prefixes) {
                        var ρσ_Iter1 = ρσ_Iterable(prefixes);
                        for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                            prefix = ρσ_Iter1[ρσ_Index1];
                            if (val === null || val === undefined) {
                                s.removeProperty("-" + prefix + "-" + name);
                            } else {
                                s.setProperty("-" + prefix + "-" + name, val);
                            }
                        }
                    }
                }
            }
            return elem;
        };
        if (!set_css.__handles_kwarg_interpolation__) Object.defineProperties(set_css, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "dom"}
        });

        function set_important_css() {
            var elem = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            var s, ρσ_unpack, name, val, prefixes, prefix, prop;
            if (typeof elem === "string") {
                elem = document.querySelector(elem);
            }
            s = elem.style;
            if (s) {
                var ρσ_Iter2 = ρσ_Iterable(kw);
                for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                    prop = ρσ_Iter2[ρσ_Index2];
                    ρσ_unpack = [str.replace(str.rstrip(prop, "_"), "_", "-"), kw[(typeof prop === "number" && prop < 0) ? kw.length + prop : prop]];
                    name = ρσ_unpack[0];
                    val = ρσ_unpack[1];
                    if (val === null || val === undefined) {
                        s.removeProperty(name);
                    } else {
                        s.setProperty(name, val, "important");
                    }
                    prefixes = simple_vendor_prefixes[(typeof name === "number" && name < 0) ? simple_vendor_prefixes.length + name : name];
                    if (prefixes) {
                        var ρσ_Iter3 = ρσ_Iterable(prefixes);
                        for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                            prefix = ρσ_Iter3[ρσ_Index3];
                            if (val === null || val === undefined) {
                                s.removeProperty("-" + prefix + "-" + name);
                            } else {
                                s.setProperty("-" + prefix + "-" + name, val, "important");
                            }
                        }
                    }
                }
            }
            return elem;
        };
        if (!set_important_css.__handles_kwarg_interpolation__) Object.defineProperties(set_important_css, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "dom"}
        });

        function build_rule() {
            var selector = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            var ans, ρσ_unpack, name, val, prefixes, prefix, prop;
            ans = [selector + " { "];
            var ρσ_Iter4 = ρσ_Iterable(kw);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                prop = ρσ_Iter4[ρσ_Index4];
                ρσ_unpack = [str.replace(str.rstrip(prop, "_"), "_", "-"), kw[(typeof prop === "number" && prop < 0) ? kw.length + prop : prop]];
                name = ρσ_unpack[0];
                val = ρσ_unpack[1];
                ans.push(name + ":" + val + ";");
                prefixes = simple_vendor_prefixes[(typeof name === "number" && name < 0) ? simple_vendor_prefixes.length + name : name];
                if (prefixes) {
                    var ρσ_Iter5 = ρσ_Iterable(prefixes);
                    for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                        prefix = ρσ_Iter5[ρσ_Index5];
                        ans.push("-" + prefix + "-" + name + ":" + val + ";");
                    }
                }
            }
            ans.push("}");
            return ans.join("\n") + "\n";
        };
        if (!build_rule.__handles_kwarg_interpolation__) Object.defineProperties(build_rule, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["selector"]},
            __module__ : {value: "dom"}
        });

        function clear() {
            var node;
            for (var i = 0; i < arguments.length; i++) {
                node = arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i];
                while (node.firstChild) {
                    node.removeChild(node.firstChild);
                }
            }
        };
        if (!clear.__module__) Object.defineProperties(clear, {
            __module__ : {value: "dom"}
        });

        function remove_all_attributes() {
            var node;
            for (var i = 0; i < arguments.length; i++) {
                node = arguments[(typeof i === "number" && i < 0) ? arguments.length + i : i];
                while (node.attributes.length > 0) {
                    node.removeAttributeNode(node.attributes[0]);
                }
            }
        };
        if (!remove_all_attributes.__module__) Object.defineProperties(remove_all_attributes, {
            __module__ : {value: "dom"}
        });

        function create_keyframes() {
            var animation_name = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var frames = Array.prototype.slice.call(arguments, 1);
            if (arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) frames.pop();
            var ans, frame, prefix;
            ans = [];
            var ρσ_Iter6 = ρσ_Iterable(ρσ_list_decorate([ "-webkit-", "-moz-", "-o-", "" ]));
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                prefix = ρσ_Iter6[ρσ_Index6];
                ans.push("@" + prefix + "keyframes " + animation_name + " {");
                var ρσ_Iter7 = ρσ_Iterable(frames);
                for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                    frame = ρσ_Iter7[ρσ_Index7];
                    ans.push(frame);
                }
                ans.push("}");
            }
            return ans.join("\n") + "\n";
        };
        if (!create_keyframes.__handles_kwarg_interpolation__) Object.defineProperties(create_keyframes, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["animation_name"]},
            __module__ : {value: "dom"}
        });

        function change_icon_image(icon_element, new_name, tooltip) {
            var x, tt;
            if (new_name) {
                icon_element.firstChild.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "#icon-" + new_name);
            } else {
                icon_element.firstChild.removeAttributeNS("http://www.w3.org/1999/xlink", "xlink:href");
            }
            if ((typeof tooltip !== "undefined" && tooltip !== null)) {
                x = icon_element.getElementsByTagNameNS("http://www.w3.org/2000/svg", "title");
                if (!x.length) {
                    tt = document.createElementNS("http://www.w3.org/2000/svg", "title");
                    icon_element.appendChild(tt);
                    x = [tt];
                }
                x[0].textContent = tooltip;
            }
        };
        if (!change_icon_image.__argnames__) Object.defineProperties(change_icon_image, {
            __argnames__ : {value: ["icon_element", "new_name", "tooltip"]},
            __module__ : {value: "dom"}
        });

        function svgicon(name, height, width, tooltip) {
            var ans, u, tt;
            ans = document.createElementNS("http://www.w3.org/2000/svg", "svg");
            ans.setAttribute("style", "fill: currentColor; height: {}; width: {}; vertical-align: text-top".format((typeof height !== "undefined" && height !== null ? height : "2ex"), (typeof width !== "undefined" && width !== null ? width : "2ex")));
            u = document.createElementNS("http://www.w3.org/2000/svg", "use");
            ans.appendChild(u);
            if (name) {
                ans.firstChild.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "#icon-" + name);
            }
            if (tooltip) {
                tt = document.createElementNS("http://www.w3.org/2000/svg", "title");
                tt.textContent = tooltip;
                ans.appendChild(tt);
            }
            return ans;
        };
        if (!svgicon.__argnames__) Object.defineProperties(svgicon, {
            __argnames__ : {value: ["name", "height", "width", "tooltip"]},
            __module__ : {value: "dom"}
        });

        function element(elem_id, child_selector) {
            var ans;
            ans = (elem_id) ? document.getElementById(elem_id) : document.body;
            if (child_selector) {
                ans = ans.querySelector(child_selector);
            }
            return ans;
        };
        if (!element.__argnames__) Object.defineProperties(element, {
            __argnames__ : {value: ["elem_id", "child_selector"]},
            __module__ : {value: "dom"}
        });

        function selector() {
            var id_selector = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var args = Array.prototype.slice.call(arguments, 1);
            if (arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) args.pop();
            var ans, x;
            ans = "#" + id_selector;
            var ρσ_Iter8 = ρσ_Iterable(args);
            for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                x = ρσ_Iter8[ρσ_Index8];
                ans += " " + x;
            }
            return ans;
        };
        if (!selector.__handles_kwarg_interpolation__) Object.defineProperties(selector, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["id_selector"]},
            __module__ : {value: "dom"}
        });

        function rule() {
            var id_selector = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            var args = Array.prototype.slice.call(arguments, 1);
            if (kw !== null && typeof kw === "object" && kw [ρσ_kwargs_symbol] === true) args.pop();
            return ρσ_interpolate_kwargs.call(this, build_rule, [selector.apply(this, [id_selector].concat(args))].concat([ρσ_desugar_kwargs(kw)]));
        };
        if (!rule.__handles_kwarg_interpolation__) Object.defineProperties(rule, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["id_selector"]},
            __module__ : {value: "dom"}
        });

        function unique_id(prefix) {
            var num;
            prefix = prefix || "auto-id";
            (ρσ_expr_temp = unique_id.counts)[(typeof prefix === "number" && prefix < 0) ? ρσ_expr_temp.length + prefix : prefix] = num = ((ρσ_expr_temp = unique_id.counts)[(typeof prefix === "number" && prefix < 0) ? ρσ_expr_temp.length + prefix : prefix] || 0) + 1;
            return prefix + "-" + num;
        };
        if (!unique_id.__argnames__) Object.defineProperties(unique_id, {
            __argnames__ : {value: ["prefix"]},
            __module__ : {value: "dom"}
        });

        unique_id.counts = Object.create(null);
        function ensure_id(w, prefix) {
            var ans;
            ans = w.getAttribute("id");
            if (!ans) {
                ans = unique_id(prefix);
                w.setAttribute("id", ans);
            }
            return ans;
        };
        if (!ensure_id.__argnames__) Object.defineProperties(ensure_id, {
            __argnames__ : {value: ["w", "prefix"]},
            __module__ : {value: "dom"}
        });

        extra_css = [];
        add_extra_css = extra_css.push.bind(extra_css);
        function get_widget_css() {
            var ans, func;
            ans = [];
            var ρσ_Iter9 = ρσ_Iterable(extra_css);
            for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                func = ρσ_Iter9[ρσ_Index9];
                ans.push(func());
            }
            return ans.join("\n");
        };
        if (!get_widget_css.__module__) Object.defineProperties(get_widget_css, {
            __module__ : {value: "dom"}
        });

        function set_radio_group_value(parent, name, val) {
            var changed, inp;
            changed = false;
            var ρσ_Iter10 = ρσ_Iterable(parent.querySelectorAll("input[name=" + ρσ_str.format("{}", name) + "]"));
            for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                inp = ρσ_Iter10[ρσ_Index10];
                inp.checked = inp.value === val;
                changed = true;
            }
            if (!changed) {
                throw new KeyError("No radio group with name=" + ρσ_str.format("{}", name) + " found");
            }
        };
        if (!set_radio_group_value.__argnames__) Object.defineProperties(set_radio_group_value, {
            __argnames__ : {value: ["parent", "name", "val"]},
            __module__ : {value: "dom"}
        });

        ρσ_modules.dom.simple_vendor_prefixes = simple_vendor_prefixes;
        ρσ_modules.dom.extra_css = extra_css;
        ρσ_modules.dom.add_extra_css = add_extra_css;
        ρσ_modules.dom.set_css = set_css;
        ρσ_modules.dom.set_important_css = set_important_css;
        ρσ_modules.dom.build_rule = build_rule;
        ρσ_modules.dom.clear = clear;
        ρσ_modules.dom.remove_all_attributes = remove_all_attributes;
        ρσ_modules.dom.create_keyframes = create_keyframes;
        ρσ_modules.dom.change_icon_image = change_icon_image;
        ρσ_modules.dom.svgicon = svgicon;
        ρσ_modules.dom.element = element;
        ρσ_modules.dom.selector = selector;
        ρσ_modules.dom.rule = rule;
        ρσ_modules.dom.unique_id = unique_id;
        ρσ_modules.dom.ensure_id = ensure_id;
        ρσ_modules.dom.get_widget_css = get_widget_css;
        ρσ_modules.dom.set_radio_group_value = set_radio_group_value;
    })();

    (function(){
        var __name__ = "book_list.theme";
        var DARK, LIGHT, LIGHT_DARKER, DT_DARK, DT_DARK_DARKER, DT_DARK_LIGHTER, DT_DARK_LIGTHER_CONTRAST, DT_LIGHT, DEFAULT_COLORS, DEFAULT_SIZES, DEFAULT_FONTS;
        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var set_css = ρσ_modules.dom.set_css;

        var all_settings = ρσ_modules.session.all_settings;

        DARK = "#39322B";
        LIGHT = "#F6F3E9";
        LIGHT_DARKER = "#b6b3a8";
        DT_DARK = "#2d2d2d";
        DT_DARK_DARKER = "black";
        DT_DARK_LIGHTER = "#777";
        DT_DARK_LIGTHER_CONTRAST = "#1d1d1d";
        DT_LIGHT = "#ddd";
        function c(light, dark) {
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["light"] = light;
                ρσ_d["dark"] = dark || light;
                return ρσ_d;
            }).call(this);
        };
        if (!c.__argnames__) Object.defineProperties(c, {
            __argnames__ : {value: ["light", "dark"]},
            __module__ : {value: "book_list.theme"}
        });

        function _byte(n) {
            if (n < 0) {
                return 0;
            }
            if (n > 255) {
                return 255;
            }
            return int(n);
        };
        if (!_byte.__argnames__) Object.defineProperties(_byte, {
            __argnames__ : {value: ["n"]},
            __module__ : {value: "book_list.theme"}
        });

        function parse_hex_color(s) {
            var v;
            if (!s) {
                return null;
            }
            v = (s + "").strip();
            if (v.startsWith("#")) {
                v = v.slice(1);
            }
            if (v.length === 3) {
                v = v[0] + v[0] + v[1] + v[1] + v[2] + v[2];
            }
            if (v.length !== 6) {
                return null;
            }
            try {
                return ρσ_list_decorate([ int(v.slice(0, 2), 16), int(v.slice(2, 4), 16), int(v.slice(4, 6), 16) ]);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    return null;
                } else {
                    throw ρσ_Exception;
                }
            }
        };
        if (!parse_hex_color.__argnames__) Object.defineProperties(parse_hex_color, {
            __argnames__ : {value: ["s"]},
            __module__ : {value: "book_list.theme"}
        });

        function hex_as_rgba() {
            var s = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var opacity = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? hex_as_rgba.__defaults__.opacity : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "opacity")){
                opacity = ρσ_kwargs_obj.opacity;
            }
            var v;
            v = parse_hex_color(s);
            return "rgba(" + ρσ_str.format("{}", v[0]) + "," + ρσ_str.format("{}", v[1]) + "," + ρσ_str.format("{}", v[2]) + "," + ρσ_str.format("{}", opacity) + ")";
        };
        if (!hex_as_rgba.__defaults__) Object.defineProperties(hex_as_rgba, {
            __defaults__ : {value: {opacity:"1"}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["s", "opacity"]},
            __module__ : {value: "book_list.theme"}
        });

        function mix_rgb_channel(a, b, t) {
            return _byte(Math.round(a * (1 - t) + b * t));
        };
        if (!mix_rgb_channel.__argnames__) Object.defineProperties(mix_rgb_channel, {
            __argnames__ : {value: ["a", "b", "t"]},
            __module__ : {value: "book_list.theme"}
        });

        function mix_rgb(a, b, t) {
            var r0, r1, r2;
            r0 = mix_rgb_channel(a[0], b[0], t);
            r1 = mix_rgb_channel(a[1], b[1], t);
            r2 = mix_rgb_channel(a[2], b[2], t);
            return ρσ_list_decorate([ r0, r1, r2 ]);
        };
        if (!mix_rgb.__argnames__) Object.defineProperties(mix_rgb, {
            __argnames__ : {value: ["a", "b", "t"]},
            __module__ : {value: "book_list.theme"}
        });

        function rgb_to_hex(rgb) {
            var r, g, b;
            r = rgb[0];
            g = rgb[1];
            b = rgb[2];
            function h(n) {
                var s;
                s = n.toString(16);
                if (s.length < 2) {
                    s = "0" + s;
                }
                return s;
            };
            if (!h.__argnames__) Object.defineProperties(h, {
                __argnames__ : {value: ["n"]},
                __module__ : {value: "book_list.theme"}
            });

            return "#" + h(r) + h(g) + h(b);
        };
        if (!rgb_to_hex.__argnames__) Object.defineProperties(rgb_to_hex, {
            __argnames__ : {value: ["rgb"]},
            __module__ : {value: "book_list.theme"}
        });

        function light_mode_primary_tints(primary_rgb) {
            var W, wb, wb2, tree, dlg, lh_bg, inp, bar_bg, btn_base, btn_base2, btn_s, btn_e;
            W = ρσ_list_decorate([ 255, 255, 255 ]);
            wb = rgb_to_hex(mix_rgb(W, primary_rgb, .055));
            wb2 = rgb_to_hex(mix_rgb(W, primary_rgb, .115));
            tree = rgb_to_hex(mix_rgb(W, primary_rgb, .095));
            dlg = wb;
            lh_bg = rgb_to_hex(mix_rgb(W, primary_rgb, .168));
            inp = rgb_to_hex(mix_rgb(W, primary_rgb, .068));
            bar_bg = rgb_to_hex(mix_rgb(W, primary_rgb, .052));
            btn_base = ρσ_list_decorate([ 36, 38, 40 ]);
            btn_base2 = ρσ_list_decorate([ 52, 54, 58 ]);
            btn_s = rgb_to_hex(mix_rgb(btn_base, primary_rgb, .4));
            btn_e = rgb_to_hex(mix_rgb(btn_base2, primary_rgb, .36));
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["--calibre-color-window-background"] = wb;
                ρσ_d["--calibre-color-window-background2"] = wb2;
                ρσ_d["--calibre-color-tree-highlight-item"] = tree;
                ρσ_d["--calibre-color-dialog-background"] = dlg;
                ρσ_d["--calibre-color-list-hover-background"] = lh_bg;
                ρσ_d["--calibre-color-list-hover-foreground"] = DARK;
                ρσ_d["--calibre-color-input-background"] = inp;
                ρσ_d["--calibre-color-bar-background"] = bar_bg;
                ρσ_d["--calibre-color-bar-foreground"] = DARK;
                ρσ_d["--calibre-color-button-start"] = btn_s;
                ρσ_d["--calibre-color-button-end"] = btn_e;
                return ρσ_d;
            }).call(this);
        };
        if (!light_mode_primary_tints.__argnames__) Object.defineProperties(light_mode_primary_tints, {
            __argnames__ : {value: ["primary_rgb"]},
            __module__ : {value: "book_list.theme"}
        });

        function apply_theme_variables(variables) {
            var s, k;
            s = document.documentElement.style;
            var ρσ_Iter0 = ρσ_Iterable(Object.keys(variables));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                k = ρσ_Iter0[ρσ_Index0];
                s.setProperty(k, variables[(typeof k === "number" && k < 0) ? variables.length + k : k]);
            }
            get_color_as_rgba.cache = Object.create(null);
            cached_color_to_rgba.cache = Object.create(null);
        };
        if (!apply_theme_variables.__argnames__) Object.defineProperties(apply_theme_variables, {
            __argnames__ : {value: ["variables"]},
            __module__ : {value: "book_list.theme"}
        });

        DEFAULT_COLORS = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["window-background"] = c(LIGHT, DT_DARK);
            ρσ_d["window-background2"] = c(LIGHT_DARKER, DT_DARK_LIGHTER);
            ρσ_d["window-foreground"] = c(DARK, DT_LIGHT);
            ρσ_d["window-error-foreground"] = c("red", "#C40233");
            ρσ_d["window-hover-foreground"] = c("red", "#C40233");
            ρσ_d["link-foreground"] = c("blue", "#6cb4ee");
            ρσ_d["faded-text"] = c("#666", "#7f7f7f");
            ρσ_d["border"] = c("rgba(0,0,0,0.12)", "rgba(255,255,255,0.12)");
            ρσ_d["border-subtle"] = c("rgba(0,0,0,0.08)", "rgba(255,255,255,0.08)");
            ρσ_d["scrollbar-thumb"] = c("rgba(0,0,0,0.26)", "rgba(255,255,255,0.34)");
            ρσ_d["scrollbar-thumb-hover"] = c("rgba(0,0,0,0.38)", "rgba(255,255,255,0.48)");
            ρσ_d["surface-1"] = c(hex_as_rgba(LIGHT, "0.08"), hex_as_rgba(DT_DARK, "0.08"));
            ρσ_d["surface-2"] = c(hex_as_rgba(LIGHT, "0.04"), hex_as_rgba(DT_DARK, "0.04"));
            ρσ_d["surface-3"] = c(hex_as_rgba(LIGHT, "0.02"), hex_as_rgba(DT_DARK, "0.02"));
            ρσ_d["bar-background"] = c(DARK, DT_DARK_LIGHTER);
            ρσ_d["bar-foreground"] = c(LIGHT, DT_DARK_LIGTHER_CONTRAST);
            ρσ_d["bar-highlight"] = c("yellow");
            ρσ_d["heart"] = c("#B92111");
            ρσ_d["list-hover-background"] = c(DARK, DT_DARK_LIGHTER);
            ρσ_d["list-hover-foreground"] = c(LIGHT, DT_DARK_LIGTHER_CONTRAST);
            ρσ_d["tree-highlight-item"] = c(LIGHT_DARKER, DT_DARK_LIGHTER);
            ρσ_d["button-start"] = c(DARK, DT_LIGHT);
            ρσ_d["button-end"] = c("#49423B", "#666");
            ρσ_d["button-text"] = c(LIGHT, DT_DARK);
            ρσ_d["dialog-background"] = c(LIGHT, DT_DARK);
            ρσ_d["dialog-background-image"] = c("none", "none");
            ρσ_d["dialog-foreground"] = c(DARK, DT_LIGHT);
            ρσ_d["input-background"] = c("field", DT_DARK_DARKER);
            ρσ_d["input-foreground"] = c("fieldtext", DT_LIGHT);
            ρσ_d["input-focus-outline-color"] = c("#4D90FE", DT_LIGHT);
            return ρσ_d;
        }).call(this);
        DEFAULT_SIZES = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["title"] = "1.4rem";
            ρσ_d["item-list-title"] = "1.1rem";
            ρσ_d["item-list-subtitle"] = "0.8rem";
            return ρσ_d;
        }).call(this);
        DEFAULT_FONTS = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["main"] = "sans-serif";
            return ρσ_d;
        }).call(this);
        function theme_variables(is_dark_theme, primary_color) {
            var attr, default_colors, rgb, ρσ_unpack, r, g, b, ans, k, tints;
            attr = (is_dark_theme) ? "dark" : "light";
            default_colors = all_settings.ui_highlight_colors.default;
            if (!primary_color) {
                primary_color = (is_dark_theme) ? default_colors.dark : default_colors.light;
            }
            if (!primary_color.startswith("#")) {
                primary_color = "#" + primary_color;
            }
            rgb = parse_hex_color(primary_color);
            if (!rgb) {
                primary_color = (is_dark_theme) ? default_colors.dark : default_colors.light;
                rgb = parse_hex_color(primary_color);
            }
            ρσ_unpack = rgb;
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
            r = ρσ_unpack[0];
            g = ρσ_unpack[1];
            b = ρσ_unpack[2];
            ans = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["--calibre-color-primary"] = primary_color;
                ρσ_d["--calibre-color-primary-light"] = "rgba(" + ρσ_str.format("{}", r) + "," + ρσ_str.format("{}", g) + "," + ρσ_str.format("{}", b) + ",0.18)";
                ρσ_d["--calibre-color-primary-light-2"] = "rgba(" + ρσ_str.format("{}", r) + "," + ρσ_str.format("{}", g) + "," + ρσ_str.format("{}", b) + ",0.28)";
                return ρσ_d;
            }).call(this);
            var ρσ_Iter1 = ρσ_Iterable(DEFAULT_COLORS);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                k = ρσ_Iter1[ρσ_Index1];
                ans[ρσ_bound_index("--calibre-color-" + k, ans)] = (ρσ_expr_temp = DEFAULT_COLORS[(typeof k === "number" && k < 0) ? DEFAULT_COLORS.length + k : k])[(typeof attr === "number" && attr < 0) ? ρσ_expr_temp.length + attr : attr];
            }
            if (!is_dark_theme) {
                tints = light_mode_primary_tints(rgb);
                var ρσ_Iter2 = ρσ_Iterable(Object.keys(tints));
                for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                    k = ρσ_Iter2[ρσ_Index2];
                    ans[(typeof k === "number" && k < 0) ? ans.length + k : k] = tints[(typeof k === "number" && k < 0) ? tints.length + k : k];
                }
            }
            return ans;
        };
        if (!theme_variables.__argnames__) Object.defineProperties(theme_variables, {
            __argnames__ : {value: ["is_dark_theme", "primary_color"]},
            __module__ : {value: "book_list.theme"}
        });

        function set_ui_colors(is_dark_theme, primary_color) {
            apply_theme_variables(theme_variables(is_dark_theme, primary_color));
            document.documentElement.style.colorScheme = (is_dark_theme) ? "dark" : "light";
        };
        if (!set_ui_colors.__argnames__) Object.defineProperties(set_ui_colors, {
            __argnames__ : {value: ["is_dark_theme", "primary_color"]},
            __module__ : {value: "book_list.theme"}
        });

        function browser_in_dark_mode() {
            return window.matchMedia("(prefers-color-scheme: dark)").matches;
        };
        if (!browser_in_dark_mode.__module__) Object.defineProperties(browser_in_dark_mode, {
            __module__ : {value: "book_list.theme"}
        });

        function effective_book_list_is_dark() {
            var sd, pref;
            try {
                sd = get_session_data();
                if (!sd) {
                    return browser_in_dark_mode();
                }
                pref = (sd.get("book_list_color_scheme", "auto") || "auto") + "";
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    return browser_in_dark_mode();
                } else {
                    throw ρσ_Exception;
                }
            }
            if (pref === "dark") {
                return true;
            }
            if (pref === "light") {
                return false;
            }
            return browser_in_dark_mode();
        };
        if (!effective_book_list_is_dark.__module__) Object.defineProperties(effective_book_list_is_dark, {
            __module__ : {value: "book_list.theme"}
        });

        function get_saved_color_settings() {
            var is_dark, sd, colors, primary_color, default_colors;
            is_dark = effective_book_list_is_dark();
            try {
                sd = get_session_data();
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    sd = null;
                } else {
                    throw ρσ_Exception;
                }
            }
            colors = (sd) ? sd.get("ui_highlight_colors") : all_settings.ui_highlight_colors.default;
            primary_color = (is_dark) ? (typeof colors !== "undefined" && colors !== null ? colors : Object.create(null)).dark : (typeof colors !== "undefined" && colors !== null ? colors : Object.create(null)).light;
            if (!primary_color) {
                default_colors = all_settings.ui_highlight_colors.default;
                primary_color = (is_dark) ? default_colors.dark : default_colors.light;
            }
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["primary_color"] = primary_color;
                ρσ_d["is_dark"] = is_dark;
                return ρσ_d;
            }).call(this);
        };
        if (!get_saved_color_settings.__module__) Object.defineProperties(get_saved_color_settings, {
            __module__ : {value: "book_list.theme"}
        });

        function apply_book_list_theme() {
            var s;
            s = get_saved_color_settings();
            set_ui_colors(s.is_dark, s.primary_color);
            try {
                ρσ_interpolate_kwargs.call(this, set_css, [document.body].concat([ρσ_desugar_kwargs({background_color: get_color("window-background"), color: get_color("window-foreground")})]));
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                } else {
                    throw ρσ_Exception;
                }
            }
        };
        if (!apply_book_list_theme.__module__) Object.defineProperties(apply_book_list_theme, {
            __module__ : {value: "book_list.theme"}
        });

        function bind_book_list_color_scheme_listener() {
            var mq;
            try {
                mq = window.matchMedia("(prefers-color-scheme: dark)");
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    return;
                } else {
                    throw ρσ_Exception;
                }
            }
            function on_pref_change(ev) {
                var sd;
                try {
                    sd = get_session_data();
                    if (!sd) {
                        return;
                    }
                    if ((sd.get("book_list_color_scheme", "auto") || "auto") + "" !== "auto") {
                        return;
                    }
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        return;
                    } else {
                        throw ρσ_Exception;
                    }
                }
                apply_book_list_theme();
            };
            if (!on_pref_change.__argnames__) Object.defineProperties(on_pref_change, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.theme"}
            });

            if (mq.addEventListener) {
                mq.addEventListener("change", on_pref_change);
            } else {
                mq.addListener(on_pref_change);
            }
        };
        if (!bind_book_list_color_scheme_listener.__module__) Object.defineProperties(bind_book_list_color_scheme_listener, {
            __module__ : {value: "book_list.theme"}
        });

        function color_scheme() {
            return (effective_book_list_is_dark()) ? "dark" : "light";
        };
        if (!color_scheme.__module__) Object.defineProperties(color_scheme, {
            __module__ : {value: "book_list.theme"}
        });

        function css_for_variables() {
            var s, attr, ans, variables, k;
            s = get_saved_color_settings();
            attr = (s.is_dark) ? "dark" : "light";
            ans = [];
            variables = theme_variables(s.is_dark, s.primary_color);
            var ρσ_Iter3 = ρσ_Iterable(Object.keys(variables));
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                k = ρσ_Iter3[ρσ_Index3];
                ans.push("" + ρσ_str.format("{}", k) + ": " + ρσ_str.format("{}", variables[(typeof k === "number" && k < 0) ? variables.length + k : k]) + ";");
            }
            return ":root { color-scheme: " + ρσ_str.format("{}", attr) + "; " + ans.join("\n") + "}\n\n";
        };
        if (!css_for_variables.__module__) Object.defineProperties(css_for_variables, {
            __module__ : {value: "book_list.theme"}
        });

        function get_color(name) {
            return "var(--calibre-color-" + ρσ_str.format("{}", name) + ")";
        };
        if (!get_color.__argnames__) Object.defineProperties(get_color, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "book_list.theme"}
        });

        function color_to_rgba(color) {
            var cvs, ctx;
            cvs = document.createElement("canvas");
            cvs.height = 1;
            cvs.width = 1;
            if (color.startsWith("var(")) {
                color = window.getComputedStyle(document.documentElement).getPropertyValue(color.slice(4, -1));
            }
            ctx = cvs.getContext("2d");
            ctx.fillStyle = color;
            ctx.fillRect(0, 0, 1, 1);
            return ctx.getImageData(0, 0, 1, 1).data;
        };
        if (!color_to_rgba.__argnames__) Object.defineProperties(color_to_rgba, {
            __argnames__ : {value: ["color"]},
            __module__ : {value: "book_list.theme"}
        });

        function cached_color_to_rgba(color) {
            var cache;
            cache = cached_color_to_rgba.cache;
            if (!cache[(typeof color === "number" && color < 0) ? cache.length + color : color]) {
                cache[(typeof color === "number" && color < 0) ? cache.length + color : color] = color_to_rgba(color);
            }
            return cache[(typeof color === "number" && color < 0) ? cache.length + color : color];
        };
        if (!cached_color_to_rgba.__argnames__) Object.defineProperties(cached_color_to_rgba, {
            __argnames__ : {value: ["color"]},
            __module__ : {value: "book_list.theme"}
        });

        cached_color_to_rgba.cache = Object.create(null);
        function get_color_as_rgba(name) {
            var cache;
            cache = get_color_as_rgba.cache;
            if (!cache[(typeof name === "number" && name < 0) ? cache.length + name : name]) {
                cache[(typeof name === "number" && name < 0) ? cache.length + name : name] = color_to_rgba(get_color(name));
            }
            return cache[(typeof name === "number" && name < 0) ? cache.length + name : name];
        };
        if (!get_color_as_rgba.__argnames__) Object.defineProperties(get_color_as_rgba, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "book_list.theme"}
        });

        get_color_as_rgba.cache = Object.create(null);
        function get_font_size(name) {
            return DEFAULT_SIZES[(typeof name === "number" && name < 0) ? DEFAULT_SIZES.length + name : name];
        };
        if (!get_font_size.__argnames__) Object.defineProperties(get_font_size, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "book_list.theme"}
        });

        function get_font_family(name) {
            name = name || "main";
            return DEFAULT_FONTS[(typeof name === "number" && name < 0) ? DEFAULT_FONTS.length + name : name];
        };
        if (!get_font_family.__argnames__) Object.defineProperties(get_font_family, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "book_list.theme"}
        });

        ρσ_modules["book_list.theme"].DARK = DARK;
        ρσ_modules["book_list.theme"].LIGHT = LIGHT;
        ρσ_modules["book_list.theme"].LIGHT_DARKER = LIGHT_DARKER;
        ρσ_modules["book_list.theme"].DT_DARK = DT_DARK;
        ρσ_modules["book_list.theme"].DT_DARK_DARKER = DT_DARK_DARKER;
        ρσ_modules["book_list.theme"].DT_DARK_LIGHTER = DT_DARK_LIGHTER;
        ρσ_modules["book_list.theme"].DT_DARK_LIGTHER_CONTRAST = DT_DARK_LIGTHER_CONTRAST;
        ρσ_modules["book_list.theme"].DT_LIGHT = DT_LIGHT;
        ρσ_modules["book_list.theme"].DEFAULT_COLORS = DEFAULT_COLORS;
        ρσ_modules["book_list.theme"].DEFAULT_SIZES = DEFAULT_SIZES;
        ρσ_modules["book_list.theme"].DEFAULT_FONTS = DEFAULT_FONTS;
        ρσ_modules["book_list.theme"].c = c;
        ρσ_modules["book_list.theme"]._byte = _byte;
        ρσ_modules["book_list.theme"].parse_hex_color = parse_hex_color;
        ρσ_modules["book_list.theme"].hex_as_rgba = hex_as_rgba;
        ρσ_modules["book_list.theme"].mix_rgb_channel = mix_rgb_channel;
        ρσ_modules["book_list.theme"].mix_rgb = mix_rgb;
        ρσ_modules["book_list.theme"].rgb_to_hex = rgb_to_hex;
        ρσ_modules["book_list.theme"].light_mode_primary_tints = light_mode_primary_tints;
        ρσ_modules["book_list.theme"].apply_theme_variables = apply_theme_variables;
        ρσ_modules["book_list.theme"].theme_variables = theme_variables;
        ρσ_modules["book_list.theme"].set_ui_colors = set_ui_colors;
        ρσ_modules["book_list.theme"].browser_in_dark_mode = browser_in_dark_mode;
        ρσ_modules["book_list.theme"].effective_book_list_is_dark = effective_book_list_is_dark;
        ρσ_modules["book_list.theme"].get_saved_color_settings = get_saved_color_settings;
        ρσ_modules["book_list.theme"].apply_book_list_theme = apply_book_list_theme;
        ρσ_modules["book_list.theme"].bind_book_list_color_scheme_listener = bind_book_list_color_scheme_listener;
        ρσ_modules["book_list.theme"].color_scheme = color_scheme;
        ρσ_modules["book_list.theme"].css_for_variables = css_for_variables;
        ρσ_modules["book_list.theme"].get_color = get_color;
        ρσ_modules["book_list.theme"].color_to_rgba = color_to_rgba;
        ρσ_modules["book_list.theme"].cached_color_to_rgba = cached_color_to_rgba;
        ρσ_modules["book_list.theme"].get_color_as_rgba = get_color_as_rgba;
        ρσ_modules["book_list.theme"].get_font_size = get_font_size;
        ρσ_modules["book_list.theme"].get_font_family = get_font_family;
    })();

    (function(){
        var __name__ = "utils";
        var is_ios, ios_major_version, v, copy_hash, _roman, _data_ns;
        var encode_query = ρσ_modules.ajax.encode_query;

        var hexlify = ρσ_modules.encodings.hexlify;

        var get_font_family = ρσ_modules["book_list.theme"].get_font_family;

        is_ios = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
        ios_major_version = 0;
        if (!is_ios && !!navigator.platform && (typeof window !== "undefined" && window !== null) && window.navigator.platform === "MacIntel" && window.navigator.maxTouchPoints > 1) {
            is_ios = true;
        }
        if (is_ios) {
            v = navigator.appVersion.match(/OS (\d+)/);
            if (v && v[1]) {
                ios_major_version = parseInt(v[1], 10) || 0;
            }
        }
        function default_context_menu_should_be_allowed(evt) {
            if (evt.target && evt.target.tagName && ρσ_in(evt.target.tagName.toLowerCase(), ["input", 
            "textarea"])) {
                return true;
            }
            return false;
        };
        if (!default_context_menu_should_be_allowed.__argnames__) Object.defineProperties(default_context_menu_should_be_allowed, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "utils"}
        });

        function debounce() {
            var func = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var wait = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var immediate = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? debounce.__defaults__.immediate : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "immediate")){
                immediate = ρσ_kwargs_obj.immediate;
            }
            var timeout;
            timeout = null;
            return (function() {
                var ρσ_anonfunc = function debounce_inner() {
                    var ρσ_unpack, context, args, call_now;
                    ρσ_unpack = [this, arguments];
                    context = ρσ_unpack[0];
                    args = ρσ_unpack[1];
                    function later() {
                        timeout = null;
                        if (!immediate) {
                            func.apply(context, args);
                        }
                    };
                    if (!later.__module__) Object.defineProperties(later, {
                        __module__ : {value: "utils"}
                    });

                    call_now = immediate && !timeout;
                    window.clearTimeout(timeout);
                    timeout = window.setTimeout(later, wait);
                    if (call_now) {
                        func.apply(context, args);
                    }
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "utils"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!debounce.__defaults__) Object.defineProperties(debounce, {
            __defaults__ : {value: {immediate:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["func", "wait", "immediate"]},
            __module__ : {value: "utils"}
        });

        if (Object.assign) {
            copy_hash = (function() {
                var ρσ_anonfunc = function (obj) {
                    return Object.assign(Object.create(null), obj);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["obj"]},
                    __module__ : {value: "utils"}
                });
                return ρσ_anonfunc;
            })();
        } else {
            copy_hash = (function() {
                var ρσ_anonfunc = function (obj) {
                    return (function() {
                        var ρσ_Iter = ρσ_Iterable(Object.keys(obj)), ρσ_Result = Object.create(null), k;
                        for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                            k = ρσ_Iter[ρσ_Index];
                            ρσ_Result[k] = (obj[(typeof k === "number" && k < 0) ? obj.length + k : k]);
                        }
                        return ρσ_Result;
                    })();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["obj"]},
                    __module__ : {value: "utils"}
                });
                return ρσ_anonfunc;
            })();
        }
        function parse_url_params() {
            var url = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? parse_url_params.__defaults__.url : arguments[0];
            var allow_multiple = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? parse_url_params.__defaults__.allow_multiple : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "url")){
                url = ρσ_kwargs_obj.url;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "allow_multiple")){
                allow_multiple = ρσ_kwargs_obj.allow_multiple;
            }
            var cache, qs, ans, q, pairs, ρσ_unpack, key, val, pair;
            cache = parse_url_params.cache;
            url = url || window.location.href;
            if (cache[(typeof url === "number" && url < 0) ? cache.length + url : url]) {
                return copy_hash((ρσ_expr_temp = parse_url_params.cache)[(typeof url === "number" && url < 0) ? ρσ_expr_temp.length + url : url]);
            }
            qs = url.indexOf("#");
            ans = Object.create(null);
            if (qs < 0) {
                cache[(typeof url === "number" && url < 0) ? cache.length + url : url] = ans;
                return copy_hash(ans);
            }
            q = url.slice(qs + 1, url.length + 1);
            if (!q) {
                cache[(typeof url === "number" && url < 0) ? cache.length + url : url] = ans;
                return copy_hash(ans);
            }
            pairs = q.replace(/\+/g, " ").split("&");
            var ρσ_Iter0 = ρσ_Iterable(pairs);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                pair = ρσ_Iter0[ρσ_Index0];
                ρσ_unpack = ρσ_eslice(pair.partition("="), 2);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                key = ρσ_unpack[0];
                val = ρσ_unpack[1];
                ρσ_unpack = [decodeURIComponent(key), decodeURIComponent(val)];
                key = ρσ_unpack[0];
                val = ρσ_unpack[1];
                if (allow_multiple) {
                    if (ans[(typeof key === "number" && key < 0) ? ans.length + key : key] === undefined) {
                        ans[(typeof key === "number" && key < 0) ? ans.length + key : key] = [];
                    }
                    ans[(typeof key === "number" && key < 0) ? ans.length + key : key].append(val);
                } else {
                    ans[(typeof key === "number" && key < 0) ? ans.length + key : key] = val;
                }
            }
            cache[(typeof url === "number" && url < 0) ? cache.length + url : url] = ans;
            return copy_hash(ans);
        };
        if (!parse_url_params.__defaults__) Object.defineProperties(parse_url_params, {
            __defaults__ : {value: {url:null, allow_multiple:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["url", "allow_multiple"]},
            __module__ : {value: "utils"}
        });

        parse_url_params.cache = Object.create(null);
        function encode_query_with_path(query, path) {
            path = path || window.location.pathname;
            return path + encode_query(query, "#");
        };
        if (!encode_query_with_path.__argnames__) Object.defineProperties(encode_query_with_path, {
            __argnames__ : {value: ["query", "path"]},
            __module__ : {value: "utils"}
        });

        function full_screen_supported(elem) {
            elem = elem || document.documentElement;
            if (elem.requestFullScreen || elem.webkitRequestFullScreen || elem.mozRequestFullScreen) {
                return true;
            }
            return false;
        };
        if (!full_screen_supported.__argnames__) Object.defineProperties(full_screen_supported, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "utils"}
        });

        function request_full_screen(elem) {
            var options;
            elem = elem || document.documentElement;
            options = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["navigationUI"] = "hide";
                return ρσ_d;
            }).call(this);
            if (elem.requestFullScreen) {
                elem.requestFullScreen(options);
            } else if (elem.webkitRequestFullScreen) {
                elem.webkitRequestFullScreen();
            } else if (elem.mozRequestFullScreen) {
                elem.mozRequestFullScreen();
            }
        };
        if (!request_full_screen.__argnames__) Object.defineProperties(request_full_screen, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "utils"}
        });

        function full_screen_element() {
            return document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement;
        };
        if (!full_screen_element.__module__) Object.defineProperties(full_screen_element, {
            __module__ : {value: "utils"}
        });

        _roman = list(zip(ρσ_list_decorate([ 1e3, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ]), ρσ_list_decorate([ "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" ])));
        function roman(num) {
            var result, ρσ_unpack, d, r;
            if (num <= 0 || num >= 4e3 || int(num) !== num) {
                return num + "";
            }
            result = ρσ_list_decorate([]);
            var ρσ_Iter1 = ρσ_Iterable(_roman);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                ρσ_unpack = ρσ_Iter1[ρσ_Index1];
                d = ρσ_unpack[0];
                r = ρσ_unpack[1];
                while (num >= d) {
                    result.append(r);
                    num -= d;
                }
            }
            return result.join("");
        };
        if (!roman.__argnames__) Object.defineProperties(roman, {
            __argnames__ : {value: ["num"]},
            __module__ : {value: "utils"}
        });

        function fmt_sidx() {
            var val = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var fmt = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? fmt_sidx.__defaults__.fmt : arguments[1];
            var use_roman = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? fmt_sidx.__defaults__.use_roman : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "fmt")){
                fmt = ρσ_kwargs_obj.fmt;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "use_roman")){
                use_roman = ρσ_kwargs_obj.use_roman;
            }
            if (val === undefined || val === null || val === "") {
                return "1";
            }
            if (int(val) === float(val)) {
                if (use_roman) {
                    return roman(val);
                }
                return int(val) + "";
            }
            return fmt.format(float(val));
        };
        if (!fmt_sidx.__defaults__) Object.defineProperties(fmt_sidx, {
            __defaults__ : {value: {fmt:"{:.2f}", use_roman:true}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["val", "fmt", "use_roman"]},
            __module__ : {value: "utils"}
        });

        function rating_to_stars() {
            var value = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var allow_half_stars = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? rating_to_stars.__defaults__.allow_half_stars : arguments[1];
            var star = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? rating_to_stars.__defaults__.star : arguments[2];
            var half = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? rating_to_stars.__defaults__.half : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "allow_half_stars")){
                allow_half_stars = ρσ_kwargs_obj.allow_half_stars;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "star")){
                star = ρσ_kwargs_obj.star;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "half")){
                half = ρσ_kwargs_obj.half;
            }
            var r, ans;
            r = max(0, min(int(value || 0), 10));
            if (allow_half_stars) {
                ans = star.repeat(Math.floor(r / 2));
                if (r % 2) {
                    ans += half;
                }
            } else {
                ans = star.repeat(int(r / 2));
            }
            return ans;
        };
        if (!rating_to_stars.__defaults__) Object.defineProperties(rating_to_stars, {
            __defaults__ : {value: {allow_half_stars:false, star:"★", half:"⯨"}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["value", "allow_half_stars", "star", "half"]},
            __module__ : {value: "utils"}
        });

        function human_readable() {
            var size = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var sep = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? human_readable.__defaults__.sep : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "sep")){
                sep = ρσ_kwargs_obj.sep;
            }
            var i, suffix;
            if (size <= 0) {
                return "0" + ρσ_str.format("{}", sep) + "B";
            }
            i = Math.floor(Math.log(size) / Math.log(1024));
            size = (size / Math.pow(1024, i)).toFixed(1);
            if (size.endswith(".0")) {
                size = size.slice(0, -2);
            }
            suffix = (ρσ_expr_temp = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB'])[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
            return size + sep + suffix;
        };
        if (!human_readable.__defaults__) Object.defineProperties(human_readable, {
            __defaults__ : {value: {sep:" "}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["size", "sep"]},
            __module__ : {value: "utils"}
        });

        function document_height() {
            var html;
            html = document.documentElement;
            return max(document.body.scrollHeight, document.body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
        };
        if (!document_height.__module__) Object.defineProperties(document_height, {
            __module__ : {value: "utils"}
        });

        function document_width() {
            var html;
            html = document.documentElement;
            return max(document.body.scrollWidth, document.body.offsetWidth, html.clientWidth, html.scrollWidth, html.offsetWidth);
        };
        if (!document_width.__module__) Object.defineProperties(document_width, {
            __module__ : {value: "utils"}
        });

        _data_ns = null;
        function data_ns(name) {
            var rand;
            if (_data_ns === null) {
                rand = new Uint8Array(12);
                window.crypto.getRandomValues(rand);
                _data_ns = "data-" + hexlify(rand) + "-";
            }
            return _data_ns + name;
        };
        if (!data_ns.__argnames__) Object.defineProperties(data_ns, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "utils"}
        });

        function get_elem_data(elem, name, defval) {
            var ans;
            ans = elem.getAttribute(data_ns(name));
            if (ans === null) {
                return (typeof defval !== "undefined" && defval !== null ? defval : null);
            }
            return JSON.parse(ans);
        };
        if (!get_elem_data.__argnames__) Object.defineProperties(get_elem_data, {
            __argnames__ : {value: ["elem", "name", "defval"]},
            __module__ : {value: "utils"}
        });

        function set_elem_data(elem, name, val) {
            elem.setAttribute(data_ns(name), JSON.stringify(val));
        };
        if (!set_elem_data.__argnames__) Object.defineProperties(set_elem_data, {
            __argnames__ : {value: ["elem", "name", "val"]},
            __module__ : {value: "utils"}
        });

        function username_key(username) {
            return ((username) ? "u" : "n") + username;
        };
        if (!username_key.__argnames__) Object.defineProperties(username_key, {
            __argnames__ : {value: ["username"]},
            __module__ : {value: "utils"}
        });

        function html_escape(text) {
            var repl;
            repl = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["&"] = "&amp;";
                ρσ_d["\""] = "&quot;";
                ρσ_d["<"] = "&lt;";
                ρσ_d[">"] = "&gt;";
                return ρσ_d;
            }).call(this);
            return String.prototype.replace.call(text, /[&"<>]/g, (function() {
                var ρσ_anonfunc = function (c) {
                    return repl[(typeof c === "number" && c < 0) ? repl.length + c : c];
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["c"]},
                    __module__ : {value: "utils"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!html_escape.__argnames__) Object.defineProperties(html_escape, {
            __argnames__ : {value: ["text"]},
            __module__ : {value: "utils"}
        });

        function uniq(vals) {
            var ans, seen, x;
            ans = [];
            seen = Object.create(null);
            var ρσ_Iter2 = ρσ_Iterable(vals);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                x = ρσ_Iter2[ρσ_Index2];
                if (!seen[(typeof x === "number" && x < 0) ? seen.length + x : x]) {
                    seen[(typeof x === "number" && x < 0) ? seen.length + x : x] = true;
                    ans.push(x);
                }
            }
            return ans;
        };
        if (!uniq.__argnames__) Object.defineProperties(uniq, {
            __argnames__ : {value: ["vals"]},
            __module__ : {value: "utils"}
        });

        function conditional_timeout(elem_id, timeout, func) {
            function ct_impl() {
                var elem;
                elem = document.getElementById(elem_id);
                if (elem) {
                    func.call(elem);
                }
            };
            if (!ct_impl.__module__) Object.defineProperties(ct_impl, {
                __module__ : {value: "utils"}
            });

            window.setTimeout(ct_impl, timeout);
        };
        if (!conditional_timeout.__argnames__) Object.defineProperties(conditional_timeout, {
            __argnames__ : {value: ["elem_id", "timeout", "func"]},
            __module__ : {value: "utils"}
        });

        function simple_markup(html) {
            var div;
            html = (html || "").replace(/\uffff/g, "").replace(/<\s*(\/?[a-zA-Z1-6]+)[^>]*>/g, (function() {
                var ρσ_anonfunc = function (match, tag) {
                    var is_closing;
                    tag = tag.toLowerCase();
                    is_closing = (tag[0] === "/") ? "/" : "";
                    if (is_closing) {
                        tag = tag.slice(1);
                    }
                    if (simple_markup.allowed_tags.indexOf(tag) < 0) {
                        tag = "span";
                    }
                    return "\uffff" + ρσ_str.format("{}", is_closing) + "" + ρσ_str.format("{}", tag) + "\uffff";
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["match", "tag"]},
                    __module__ : {value: "utils"}
                });
                return ρσ_anonfunc;
            })());
            div = document.createElement("b");
            div.textContent = html;
            html = div.innerHTML;
            return html.replace(/\uffff(\/?[a-z1-6]+)\uffff/g, "<$1>");
        };
        if (!simple_markup.__argnames__) Object.defineProperties(simple_markup, {
            __argnames__ : {value: ["html"]},
            __module__ : {value: "utils"}
        });

        simple_markup.allowed_tags = 'a|b|i|br|hr|h1|h2|h3|h4|h5|h6|div|em|strong|span'.split('|');
        function safe_set_inner_html(elem, html) {
            elem.innerHTML = simple_markup(html);
            return elem;
        };
        if (!safe_set_inner_html.__argnames__) Object.defineProperties(safe_set_inner_html, {
            __argnames__ : {value: ["elem", "html"]},
            __module__ : {value: "utils"}
        });

        function sandboxed_html(html, style, sandbox) {
            var ans, css, final_html;
            ans = document.createElement("iframe");
            ans.setAttribute("sandbox", sandbox || "");
            ans.setAttribute("seamless", "");
            ans.style.width = "100%";
            html = html || "";
            css = "html, body { margin: 0; padding: 0; font-family: __FONT__ } p:first-child { margin-top: 0; padding-top: 0; -webkit-margin-before: 0 }".replace("__FONT__", get_font_family());
            css += style || "";
            final_html = "<!DOCTYPE html><html><head><style>" + ρσ_str.format("{}", css) + "</style></head><body>" + ρσ_str.format("{}", html) + "</body></html>";
            ans.srcdoc = final_html;
            return ans;
        };
        if (!sandboxed_html.__argnames__) Object.defineProperties(sandboxed_html, {
            __argnames__ : {value: ["html", "style", "sandbox"]},
            __module__ : {value: "utils"}
        });

        ρσ_modules.utils.is_ios = is_ios;
        ρσ_modules.utils.ios_major_version = ios_major_version;
        ρσ_modules.utils.v = v;
        ρσ_modules.utils.copy_hash = copy_hash;
        ρσ_modules.utils._roman = _roman;
        ρσ_modules.utils._data_ns = _data_ns;
        ρσ_modules.utils.default_context_menu_should_be_allowed = default_context_menu_should_be_allowed;
        ρσ_modules.utils.debounce = debounce;
        ρσ_modules.utils.parse_url_params = parse_url_params;
        ρσ_modules.utils.encode_query_with_path = encode_query_with_path;
        ρσ_modules.utils.full_screen_supported = full_screen_supported;
        ρσ_modules.utils.request_full_screen = request_full_screen;
        ρσ_modules.utils.full_screen_element = full_screen_element;
        ρσ_modules.utils.roman = roman;
        ρσ_modules.utils.fmt_sidx = fmt_sidx;
        ρσ_modules.utils.rating_to_stars = rating_to_stars;
        ρσ_modules.utils.human_readable = human_readable;
        ρσ_modules.utils.document_height = document_height;
        ρσ_modules.utils.document_width = document_width;
        ρσ_modules.utils.data_ns = data_ns;
        ρσ_modules.utils.get_elem_data = get_elem_data;
        ρσ_modules.utils.set_elem_data = set_elem_data;
        ρσ_modules.utils.username_key = username_key;
        ρσ_modules.utils.html_escape = html_escape;
        ρσ_modules.utils.uniq = uniq;
        ρσ_modules.utils.conditional_timeout = conditional_timeout;
        ρσ_modules.utils.simple_markup = simple_markup;
        ρσ_modules.utils.safe_set_inner_html = safe_set_inner_html;
        ρσ_modules.utils.sandboxed_html = sandboxed_html;
    })();

    (function(){
        var __name__ = "book_list.library_data";
        var load_status, library_data, BROWSE_VISIBLE_FIELDS_SETTING, thumbnail_cache;
        var _ = ρσ_modules.gettext.gettext;

        var absolute_path = ρσ_modules.ajax.absolute_path;
        var ajax = ρσ_modules.ajax.ajax;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var LRUCache = ρσ_modules.lru_cache.LRUCache;

        var get_interface_data = ρσ_modules.session.get_interface_data;

        var parse_url_params = ρσ_modules.utils.parse_url_params;

        load_status = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["loading"] = true;
            ρσ_d["ok"] = false;
            ρσ_d["error_html"] = null;
            ρσ_d["current_fetch"] = null;
            ρσ_d["http_error_code"] = 0;
            return ρσ_d;
        }).call(this);
        library_data = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["metadata"] = Object.create(null);
            ρσ_d["previous_book_ids"] = [];
            ρσ_d["force_refresh"] = false;
            ρσ_d["bools_are_tristate"] = true;
            ρσ_d["field_names"] = Object.create(null);
            ρσ_d["available_browse_fields"] = [];
            ρσ_d["browse_fields"] = [];
            return ρσ_d;
        }).call(this);
        BROWSE_VISIBLE_FIELDS_SETTING = "browse_visible_fields";
        function current_library_id() {
            var q;
            q = parse_url_params();
            return q.library_id || get_interface_data().default_library_id;
        };
        if (!current_library_id.__module__) Object.defineProperties(current_library_id, {
            __module__ : {value: "book_list.library_data"}
        });

        function all_libraries() {
            var interface_data, lids;
            interface_data = get_interface_data();
            lids = ρσ_interpolate_kwargs.call(this, sorted, [interface_data.library_map].concat([ρσ_desugar_kwargs({key: (function() {
                var ρσ_anonfunc = function (x) {
                    return (ρσ_expr_temp = interface_data.library_map)[(typeof x === "number" && x < 0) ? ρσ_expr_temp.length + x : x];
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["x"]},
                    __module__ : {value: "book_list.library_data"}
                });
                return ρσ_anonfunc;
            })()})]));
            return (function() {
                var ρσ_Iter = ρσ_Iterable(lids), ρσ_Result = [], lid;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    lid = ρσ_Iter[ρσ_Index];
                    ρσ_Result.push([lid, (ρσ_expr_temp = interface_data.library_map)[(typeof lid === "number" && lid < 0) ? ρσ_expr_temp.length + lid : lid]]);
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
        };
        if (!all_libraries.__module__) Object.defineProperties(all_libraries, {
            __module__ : {value: "book_list.library_data"}
        });

        function current_virtual_library() {
            var q;
            q = parse_url_params();
            return q.vl || "";
        };
        if (!current_virtual_library.__module__) Object.defineProperties(current_virtual_library, {
            __module__ : {value: "book_list.library_data"}
        });

        function last_virtual_library_for(library_id) {
            if (last_virtual_library_for.library_id === library_id) {
                return last_virtual_library_for.vl || "";
            }
            return "";
        };
        if (!last_virtual_library_for.__argnames__) Object.defineProperties(last_virtual_library_for, {
            __argnames__ : {value: ["library_id"]},
            __module__ : {value: "book_list.library_data"}
        });

        function url_books_query(sd) {
            var q, lid;
            q = parse_url_params();
            sd = sd || get_session_data();
            lid = current_library_id();
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["library_id"] = lid;
                ρσ_d["sort"] = q.sort || sd.get_library_option(lid, "sort");
                ρσ_d["search"] = q.search;
                ρσ_d["vl"] = current_virtual_library();
                return ρσ_d;
            }).call(this);
        };
        if (!url_books_query.__argnames__) Object.defineProperties(url_books_query, {
            __argnames__ : {value: ["sd"]},
            __module__ : {value: "book_list.library_data"}
        });

        function loaded_books_query() {
            var sr, sort;
            sr = library_data.search_result;
            sort = null;
            if (sr) {
                sort = (function() {
                    var ρσ_Iter = ρσ_Iterable(zip(sr.sort.split(","), sr.sort_order.split(","))), ρσ_Result = [], s, o;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        ρσ_unpack = ρσ_Iter[ρσ_Index];
                        s = ρσ_unpack[0];
                        o = ρσ_unpack[1];
                        ρσ_Result.push(s + "." + o);
                    }
                    ρσ_Result = ρσ_list_constructor(ρσ_Result);
                    return ρσ_Result;
                })().join(",");
            }
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["library_id"] = (sr) ? sr.library_id : null;
                ρσ_d["sort"] = sort;
                ρσ_d["search"] = (typeof sr !== "undefined" && sr !== null ? sr : Object.create(null)).query;
                ρσ_d["vl"] = (typeof sr !== "undefined" && sr !== null ? sr : Object.create(null)).vl;
                return ρσ_d;
            }).call(this);
        };
        if (!loaded_books_query.__module__) Object.defineProperties(loaded_books_query, {
            __module__ : {value: "book_list.library_data"}
        });

        function current_sorted_field() {
            var sort, csf, csfo;
            if (library_data.search_result) {
                return [library_data.search_result.sort, library_data.search_result.sort_order];
            }
            sort = url_books_query().sort.partition(",")[0];
            csf = sort.partition(".")[0];
            csfo = sort.partition(".")[2] || "asc";
            return [csf, csfo];
        };
        if (!current_sorted_field.__module__) Object.defineProperties(current_sorted_field, {
            __module__ : {value: "book_list.library_data"}
        });

        function all_virtual_libraries() {
            return library_data.virtual_libraries || Object.create(null);
        };
        if (!all_virtual_libraries.__module__) Object.defineProperties(all_virtual_libraries, {
            __module__ : {value: "book_list.library_data"}
        });

        function update_library_data(data) {
            var key, sr;
            load_status.loading = false;
            load_status.ok = true;
            load_status.error_html = null;
            load_status.http_error_code = 0;
            library_data.previous_book_ids = [];
            if (library_data.for_library !== current_library_id()) {
                library_data.field_names = Object.create(null);
            }
            library_data.for_library = current_library_id();
            var ρσ_Iter0 = ρσ_Iterable("search_result sortable_fields field_metadata metadata virtual_libraries book_display_fields bools_are_tristate book_details_vertical_categories fts_enabled fields_that_support_notes categories_using_hierarchy".split(" "));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                key = ρσ_Iter0[ρσ_Index0];
                library_data[(typeof key === "number" && key < 0) ? library_data.length + key : key] = data[(typeof key === "number" && key < 0) ? data.length + key : key];
            }
            library_data.available_browse_fields = data.browse_fields || [];
            update_visible_browse_fields();
            sr = library_data.search_result;
            if (sr) {
                last_virtual_library_for.library_id = sr.library_id;
                last_virtual_library_for.vl = sr.vl;
            } else {
                last_virtual_library_for.library_id = null;
                last_virtual_library_for.vl = null;
            }
            refresh_sidebar_navigation();
            refresh_browse_field_settings();
        };
        if (!update_library_data.__argnames__) Object.defineProperties(update_library_data, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "book_list.library_data"}
        });

        function configured_browse_fields() {
            var by_library;
            by_library = get_session_data().get(BROWSE_VISIBLE_FIELDS_SETTING) || Object.create(null);
            return by_library[ρσ_bound_index(current_library_id(), by_library)];
        };
        if (!configured_browse_fields.__module__) Object.defineProperties(configured_browse_fields, {
            __module__ : {value: "book_list.library_data"}
        });

        function configured_browse_field_map() {
            var configured, ans, key;
            configured = configured_browse_fields();
            if (!Array.isArray(configured)) {
                return null;
            }
            ans = Object.create(null);
            var ρσ_Iter1 = ρσ_Iterable(configured);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                key = ρσ_Iter1[ρσ_Index1];
                ans[(typeof key === "number" && key < 0) ? ans.length + key : key] = true;
            }
            return ans;
        };
        if (!configured_browse_field_map.__module__) Object.defineProperties(configured_browse_field_map, {
            __module__ : {value: "book_list.library_data"}
        });

        function update_visible_browse_fields() {
            var fields, selected, field;
            fields = library_data.available_browse_fields || [];
            selected = configured_browse_field_map();
            if (selected === null) {
                library_data.browse_fields = (function() {
                    var ρσ_Iter = ρσ_Iterable(fields), ρσ_Result = [], field;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        field = ρσ_Iter[ρσ_Index];
                        if (field.default_visible !== false) {
                            ρσ_Result.push(field);
                        }
                    }
                    ρσ_Result = ρσ_list_constructor(ρσ_Result);
                    return ρσ_Result;
                })();
            } else {
                library_data.browse_fields = (function() {
                    var ρσ_Iter = ρσ_Iterable(fields), ρσ_Result = [], field;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        field = ρσ_Iter[ρσ_Index];
                        if (selected[ρσ_bound_index(field.key, selected)]) {
                            ρσ_Result.push(field);
                        }
                    }
                    ρσ_Result = ρσ_list_constructor(ρσ_Result);
                    return ρσ_Result;
                })();
            }
        };
        if (!update_visible_browse_fields.__module__) Object.defineProperties(update_visible_browse_fields, {
            __module__ : {value: "book_list.library_data"}
        });

        function set_browse_fields(field_keys) {
            var by_library;
            by_library = get_session_data().get(BROWSE_VISIBLE_FIELDS_SETTING) || Object.create(null);
            by_library[ρσ_bound_index(current_library_id(), by_library)] = field_keys;
            get_session_data().set(BROWSE_VISIBLE_FIELDS_SETTING, by_library);
            update_visible_browse_fields();
            refresh_sidebar_navigation();
        };
        if (!set_browse_fields.__argnames__) Object.defineProperties(set_browse_fields, {
            __argnames__ : {value: ["field_keys"]},
            __module__ : {value: "book_list.library_data"}
        });

        function refresh_sidebar_navigation() {
            var refresh;
            try {
                refresh = window.cs_refresh_sidebar_navigation;
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    refresh = null;
                } else {
                    throw ρσ_Exception;
                }
            }
            if (refresh) {
                refresh();
            }
        };
        if (!refresh_sidebar_navigation.__module__) Object.defineProperties(refresh_sidebar_navigation, {
            __module__ : {value: "book_list.library_data"}
        });

        function refresh_browse_field_settings() {
            var refresh;
            try {
                refresh = window.cs_refresh_browse_field_settings;
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    refresh = null;
                } else {
                    throw ρσ_Exception;
                }
            }
            if (refresh) {
                refresh();
            }
        };
        if (!refresh_browse_field_settings.__module__) Object.defineProperties(refresh_browse_field_settings, {
            __module__ : {value: "book_list.library_data"}
        });

        function browse_field_settings() {
            var ans, selected, f, field;
            ans = [];
            selected = configured_browse_field_map();
            var ρσ_Iter2 = ρσ_Iterable(library_data.available_browse_fields || []);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                field = ρσ_Iter2[ρσ_Index2];
                f = Object.assign(Object.create(null), field);
                f.enabled = (selected === null) ? field.default_visible !== false : bool(selected[ρσ_bound_index(f.key, selected)]);
                ans.push(f);
            }
            return ans;
        };
        if (!browse_field_settings.__module__) Object.defineProperties(browse_field_settings, {
            __module__ : {value: "book_list.library_data"}
        });

        function browse_fields() {
            return library_data.browse_fields || [];
        };
        if (!browse_fields.__module__) Object.defineProperties(browse_fields, {
            __module__ : {value: "book_list.library_data"}
        });

        function browse_field_for(field) {
            var f;
            var ρσ_Iter3 = ρσ_Iterable(browse_fields());
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                f = ρσ_Iter3[ρσ_Index3];
                if (f.key === field) {
                    return f;
                }
            }
        };
        if (!browse_field_for.__argnames__) Object.defineProperties(browse_field_for, {
            __argnames__ : {value: ["field"]},
            __module__ : {value: "book_list.library_data"}
        });

        function add_more_books(data) {
            var key, sr;
            var ρσ_Iter4 = ρσ_Iterable(data.metadata);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                key = ρσ_Iter4[ρσ_Index4];
                (ρσ_expr_temp = library_data.metadata)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = (ρσ_expr_temp = data.metadata)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
            }
            sr = library_data.search_result;
            if (sr && sr.book_ids && sr.book_ids.length > 0) {
                library_data.previous_book_ids = library_data.previous_book_ids.concat(sr.book_ids);
            }
            library_data.search_result = data.search_result;
        };
        if (!add_more_books.__argnames__) Object.defineProperties(add_more_books, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "book_list.library_data"}
        });

        function current_book_ids() {
            return library_data.previous_book_ids.concat(library_data.search_result.book_ids);
        };
        if (!current_book_ids.__module__) Object.defineProperties(current_book_ids, {
            __module__ : {value: "book_list.library_data"}
        });

        function remove_from_array(array, item) {
            var idx;
            while (true) {
                idx = array.indexOf(item);
                if (idx < 0) {
                    break;
                }
                array.splice(idx, 1);
            }
        };
        if (!remove_from_array.__argnames__) Object.defineProperties(remove_from_array, {
            __argnames__ : {value: ["array", "item"]},
            __module__ : {value: "book_list.library_data"}
        });

        function remove_book(book_id) {
            book_id = int(book_id);
            if (library_data.previous_book_ids) {
                remove_from_array(library_data.previous_book_ids, book_id);
            }
            if (ρσ_exists.d(library_data.search_result).book_ids) {
                remove_from_array(library_data.search_result.book_ids, book_id);
            }
        };
        if (!remove_book.__argnames__) Object.defineProperties(remove_book, {
            __argnames__ : {value: ["book_id"]},
            __module__ : {value: "book_list.library_data"}
        });

        function book_after(book_id, delta) {
            var ids, idx, new_idx;
            if (!delta) {
                delta = 1;
            }
            ids = current_book_ids();
            idx = ids.indexOf(int(book_id));
            if (idx > -1) {
                new_idx = (idx + ids.length + delta) % ids.length;
                return ids[(typeof new_idx === "number" && new_idx < 0) ? ids.length + new_idx : new_idx];
            }
        };
        if (!book_after.__argnames__) Object.defineProperties(book_after, {
            __argnames__ : {value: ["book_id", "delta"]},
            __module__ : {value: "book_list.library_data"}
        });

        function on_data_loaded(end_type, xhr, ev) {
            var data, sd, q;
            load_status.current_fetch = null;
            function bad_load(msg) {
                load_status.ok = false;
                load_status.loading = false;
                load_status.error_html = msg || xhr.error_html;
                load_status.http_error_code = xhr.status;
            };
            if (!bad_load.__argnames__) Object.defineProperties(bad_load, {
                __argnames__ : {value: ["msg"]},
                __module__ : {value: "book_list.library_data"}
            });

            if (end_type === "load") {
                data = JSON.parse(xhr.responseText);
                if (data.bad_restriction) {
                    bad_load(_("The library restriction for the current user is invalid: {}").format(data.bad_restriction));
                } else {
                    update_library_data(data);
                    sd = get_session_data();
                    q = loaded_books_query();
                    sd.set_library_option(q.library_id, "sort", q.sort);
                }
            } else if (end_type === "abort") {
            } else {
                bad_load();
            }
        };
        if (!on_data_loaded.__argnames__) Object.defineProperties(on_data_loaded, {
            __argnames__ : {value: ["end_type", "xhr", "ev"]},
            __module__ : {value: "book_list.library_data"}
        });

        function fetch_init_data() {
            var query;
            if (load_status.current_fetch) {
                load_status.current_fetch.abort();
            }
            query = url_books_query();
            load_status.loading = true;
            load_status.ok = false;
            load_status.error_html = null;
            load_status.http_error_code = 0;
            load_status.current_fetch = ρσ_interpolate_kwargs.call(this, ajax, ["interface-data/books-init", on_data_loaded].concat([ρσ_desugar_kwargs({query: query})]));
            load_status.current_fetch.send();
        };
        if (!fetch_init_data.__module__) Object.defineProperties(fetch_init_data, {
            __module__ : {value: "book_list.library_data"}
        });

        function field_names_received(library_id, field, proceed, end_type, xhr, event) {
            var names;
            if (library_id !== current_library_id()) {
                return;
            }
            if (end_type !== "load") {
                if (end_type !== "abort") {
                    proceed(false, field, xhr.error_html);
                }
                return;
            }
            try {
                names = JSON.parse(xhr.responseText);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    var traceback = ρσ_modules.traceback;

                    traceback.print_exc();
                    proceed(false, field, "Invalid JSON from server");
                    return;
                } else {
                    throw ρσ_Exception;
                }
            }
            (ρσ_expr_temp = library_data.field_names)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["loading"] = false;
                ρσ_d["loaded"] = true;
                ρσ_d["last_updated_at"] = Date.now();
                ρσ_d["names"] = names;
                return ρσ_d;
            }).call(this);
            proceed(true, field, names);
        };
        if (!field_names_received.__argnames__) Object.defineProperties(field_names_received, {
            __argnames__ : {value: ["library_id", "field", "proceed", "end_type", "xhr", "event"]},
            __module__ : {value: "book_list.library_data"}
        });

        function field_names_for(field, proceed) {
            if (!library_data.field_names) {
                library_data.field_names = Object.create(null);
            }
            if ((ρσ_expr_temp = library_data.field_names)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field] && (ρσ_expr_temp = library_data.field_names)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field].loaded) {
                proceed(true, field, (ρσ_expr_temp = library_data.field_names)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field].names);
            }
            if (!(ρσ_expr_temp = library_data.field_names)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field] || !(ρσ_expr_temp = library_data.field_names)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field].loading && Date.now() - (ρσ_expr_temp = library_data.field_names)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field].last_updated_at > 3600 * 1e3) {
                ρσ_interpolate_kwargs.call(this, ajax, ["interface-data/field-names/" + ρσ_str.format("{}", encodeURIComponent(field)) + "", field_names_received.bind(null, current_library_id(), field, proceed)].concat([ρσ_desugar_kwargs({query: (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["library_id"] = current_library_id();
                    return ρσ_d;
                }).call(this)})])).send();
                if (!(ρσ_expr_temp = library_data.field_names)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field]) {
                    (ρσ_expr_temp = library_data.field_names)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["last_updated_at"] = 0;
                        ρσ_d["loaded"] = false;
                        ρσ_d["names"] = [];
                        return ρσ_d;
                    }).call(this);
                }
                (ρσ_expr_temp = library_data.field_names)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field].loading = true;
            }
        };
        if (!field_names_for.__argnames__) Object.defineProperties(field_names_for, {
            __argnames__ : {value: ["field", "proceed"]},
            __module__ : {value: "book_list.library_data"}
        });

        function thumbnail_url(book_id, width, height) {
            var query, prefix, lid;
            query = "sz=" + ρσ_str.format("{}", Math.ceil(width * window.devicePixelRatio)) + "x" + ρσ_str.format("{}", Math.ceil(height * window.devicePixelRatio)) + "";
            prefix = "get/thumb/" + ρσ_str.format("{}", book_id) + "";
            lid = loaded_books_query().library_id || current_library_id();
            if (lid) {
                prefix += "/" + ρσ_str.format("{}", lid) + "";
            }
            return absolute_path("" + ρσ_str.format("{}", prefix) + "?" + ρσ_str.format("{}", query) + "");
        };
        if (!thumbnail_url.__argnames__) Object.defineProperties(thumbnail_url, {
            __argnames__ : {value: ["book_id", "width", "height"]},
            __module__ : {value: "book_list.library_data"}
        });

        function cover_url(book_id) {
            var lid;
            lid = current_library_id();
            return absolute_path("get/cover/" + ρσ_str.format("{}", book_id) + "/" + ρσ_str.format("{}", lid) + "");
        };
        if (!cover_url.__argnames__) Object.defineProperties(cover_url, {
            __argnames__ : {value: ["book_id"]},
            __module__ : {value: "book_list.library_data"}
        });

        function download_url(book_id, fmt, content_disposition) {
            var lid, ans;
            lid = current_library_id();
            ans = absolute_path("get/" + ρσ_str.format("{}", fmt) + "/" + ρσ_str.format("{}", book_id) + "/" + ρσ_str.format("{}", lid) + "");
            if (content_disposition) {
                ans += "?content_disposition=" + ρσ_str.format("{}", content_disposition) + "";
            }
            return ans;
        };
        if (!download_url.__argnames__) Object.defineProperties(download_url, {
            __argnames__ : {value: ["book_id", "fmt", "content_disposition"]},
            __module__ : {value: "book_list.library_data"}
        });

        function download_data_file_url(book_id, relpath, content_disposition) {
            var lid, rpath, ans;
            lid = current_library_id();
            rpath = encodeURIComponent(relpath);
            ans = absolute_path("data-files/get/" + ρσ_str.format("{}", book_id) + "/" + ρσ_str.format("{}", rpath) + "/" + ρσ_str.format("{}", lid) + "");
            if (content_disposition) {
                ans += "?content_disposition=" + ρσ_str.format("{}", content_disposition) + "";
            }
            return ans;
        };
        if (!download_data_file_url.__argnames__) Object.defineProperties(download_data_file_url, {
            __argnames__ : {value: ["book_id", "relpath", "content_disposition"]},
            __module__ : {value: "book_list.library_data"}
        });

        function web_search_url(book_id, field, item_val) {
            return absolute_path("web-search/" + ρσ_str.format("{}", book_id) + "/" + ρσ_str.format("{}", encodeURIComponent(field)) + "/" + ρσ_str.format("{}", encodeURIComponent(item_val)) + "?library_id=" + ρσ_str.format("{}", encodeURIComponent(current_library_id())) + "");
        };
        if (!web_search_url.__argnames__) Object.defineProperties(web_search_url, {
            __argnames__ : {value: ["book_id", "field", "item_val"]},
            __module__ : {value: "book_list.library_data"}
        });

        function book_metadata(book_id) {
            return (ρσ_expr_temp = library_data.metadata)[(typeof book_id === "number" && book_id < 0) ? ρσ_expr_temp.length + book_id : book_id];
        };
        if (!book_metadata.__argnames__) Object.defineProperties(book_metadata, {
            __argnames__ : {value: ["book_id"]},
            __module__ : {value: "book_list.library_data"}
        });

        function set_book_metadata(book_id, value) {
            (ρσ_expr_temp = library_data.metadata)[(typeof book_id === "number" && book_id < 0) ? ρσ_expr_temp.length + book_id : book_id] = value;
        };
        if (!set_book_metadata.__argnames__) Object.defineProperties(set_book_metadata, {
            __argnames__ : {value: ["book_id", "value"]},
            __module__ : {value: "book_list.library_data"}
        });

        function loaded_book_ids() {
            return Object.keys(library_data.metadata);
        };
        if (!loaded_book_ids.__module__) Object.defineProperties(loaded_book_ids, {
            __module__ : {value: "book_list.library_data"}
        });

        function force_refresh_on_next_load() {
            library_data.force_refresh = true;
        };
        if (!force_refresh_on_next_load.__module__) Object.defineProperties(force_refresh_on_next_load, {
            __module__ : {value: "book_list.library_data"}
        });

        function ensure_current_library_data() {
            var fr, matches, q, loaded, key;
            fr = library_data.force_refresh;
            library_data.force_refresh = false;
            function is_same(a, b) {
                if (!a && !b) {
                    return true;
                }
                return a === b;
            };
            if (!is_same.__argnames__) Object.defineProperties(is_same, {
                __argnames__ : {value: ["a", "b"]},
                __module__ : {value: "book_list.library_data"}
            });

            if (fr) {
                matches = false;
            } else {
                q = url_books_query();
                loaded = loaded_books_query();
                matches = true;
                var ρσ_Iter5 = ρσ_Iterable(q);
                for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                    key = ρσ_Iter5[ρσ_Index5];
                    if (!is_same(q[(typeof key === "number" && key < 0) ? q.length + key : key], loaded[(typeof key === "number" && key < 0) ? loaded.length + key : key])) {
                        matches = false;
                        break;
                    }
                }
            }
            if (!matches) {
                fetch_init_data();
            }
        };
        if (!ensure_current_library_data.__module__) Object.defineProperties(ensure_current_library_data, {
            __module__ : {value: "book_list.library_data"}
        });

        function ThumbnailCache() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ThumbnailCache.prototype.__bind_methods__.call(this);
            ThumbnailCache.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ThumbnailCache.prototype, "__bind_methods__", {value: function () {
            this.get = ThumbnailCache.prototype.get.bind(this);
            this.load_finished = ThumbnailCache.prototype.load_finished.bind(this);
        }});
        ThumbnailCache.prototype.__init__ = function __init__() {
            var self = this;
            var size = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.size : arguments[0];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "size")){
                size = ρσ_kwargs_obj.size;
            }
            self.cache = new LRUCache(size);
        };
        if (!ThumbnailCache.prototype.__init__.__defaults__) Object.defineProperties(ThumbnailCache.prototype.__init__, {
            __defaults__ : {value: {size:256}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["size"]},
            __module__ : {value: "book_list.library_data"}
        });
        ThumbnailCache.__argnames__ = ThumbnailCache.prototype.__init__.__argnames__;
        ThumbnailCache.__handles_kwarg_interpolation__ = ThumbnailCache.prototype.__init__.__handles_kwarg_interpolation__;
        ThumbnailCache.prototype.get = function get(book_id, width, height, callback) {
            var self = this;
            var url, item, img;
            url = thumbnail_url(book_id, width, height);
            item = self.cache.get(url);
            if (!item) {
                img = new Image;
                item = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["img"] = img;
                    ρσ_d["load_type"] = null;
                    ρσ_d["callbacks"] = [callback];
                    return ρσ_d;
                }).call(this);
                img.onerror = self.load_finished.bind(null, item, "error");
                img.onload = self.load_finished.bind(null, item, "load");
                img.onabort = self.load_finished.bind(null, item, "abort");
                img.dataset.bookId = book_id + "";
                img.src = url;
                self.cache.set(url, item);
                return img;
            }
            if (item.load_type === null) {
                if (item.callbacks.indexOf(callback) < 0) {
                    item.callbacks.push(callback);
                }
            } else {
                callback(item.img, item.load_type);
            }
            return item.img;
        };
        if (!ThumbnailCache.prototype.get.__argnames__) Object.defineProperties(ThumbnailCache.prototype.get, {
            __argnames__ : {value: ["book_id", "width", "height", "callback"]},
            __module__ : {value: "book_list.library_data"}
        });
        ThumbnailCache.prototype.load_finished = function load_finished(item, load_type) {
            var self = this;
            var img, callback;
            item.load_type = load_type;
            img = item.img;
            img.onload = img.onerror = img.onabort = null;
            var ρσ_Iter6 = ρσ_Iterable(item.callbacks);
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                callback = ρσ_Iter6[ρσ_Index6];
                callback(img, load_type);
            }
        };
        if (!ThumbnailCache.prototype.load_finished.__argnames__) Object.defineProperties(ThumbnailCache.prototype.load_finished, {
            __argnames__ : {value: ["item", "load_type"]},
            __module__ : {value: "book_list.library_data"}
        });
        ThumbnailCache.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ThumbnailCache.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ThumbnailCache.prototype, "__bases__", {value: []});

        thumbnail_cache = new ThumbnailCache;
        function sync_library_books(library_id, to_sync, callback) {
            var url, which, lrmap, ρσ_unpack, book_id, fmt, key, last_read;
            url = "book-get-annotations/" + ρσ_str.format("{}", library_id) + "/";
            which = [];
            lrmap = Object.create(null);
            var ρσ_Iter7 = ρσ_Iterable(to_sync);
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                ρσ_unpack = ρσ_Iter7[ρσ_Index7];
                key = ρσ_unpack[0];
                last_read = ρσ_unpack[1];
                ρσ_unpack = key;
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
                library_id = ρσ_unpack[0];
                book_id = ρσ_unpack[1];
                fmt = ρσ_unpack[2];
                fmt = fmt.upper();
                which.push("" + ρσ_str.format("{}", book_id) + "-" + ρσ_str.format("{}", fmt) + "");
                lrmap[ρσ_bound_index("" + ρσ_str.format("{}", book_id) + ":" + ρσ_str.format("{}", fmt) + "", lrmap)] = last_read;
            }
            url += which.join("_");
            ajax(url, callback.bind(null, library_id, lrmap)).send();
        };
        if (!sync_library_books.__argnames__) Object.defineProperties(sync_library_books, {
            __argnames__ : {value: ["library_id", "to_sync", "callback"]},
            __module__ : {value: "book_list.library_data"}
        });

        ρσ_modules["book_list.library_data"].load_status = load_status;
        ρσ_modules["book_list.library_data"].library_data = library_data;
        ρσ_modules["book_list.library_data"].BROWSE_VISIBLE_FIELDS_SETTING = BROWSE_VISIBLE_FIELDS_SETTING;
        ρσ_modules["book_list.library_data"].thumbnail_cache = thumbnail_cache;
        ρσ_modules["book_list.library_data"].current_library_id = current_library_id;
        ρσ_modules["book_list.library_data"].all_libraries = all_libraries;
        ρσ_modules["book_list.library_data"].current_virtual_library = current_virtual_library;
        ρσ_modules["book_list.library_data"].last_virtual_library_for = last_virtual_library_for;
        ρσ_modules["book_list.library_data"].url_books_query = url_books_query;
        ρσ_modules["book_list.library_data"].loaded_books_query = loaded_books_query;
        ρσ_modules["book_list.library_data"].current_sorted_field = current_sorted_field;
        ρσ_modules["book_list.library_data"].all_virtual_libraries = all_virtual_libraries;
        ρσ_modules["book_list.library_data"].update_library_data = update_library_data;
        ρσ_modules["book_list.library_data"].configured_browse_fields = configured_browse_fields;
        ρσ_modules["book_list.library_data"].configured_browse_field_map = configured_browse_field_map;
        ρσ_modules["book_list.library_data"].update_visible_browse_fields = update_visible_browse_fields;
        ρσ_modules["book_list.library_data"].set_browse_fields = set_browse_fields;
        ρσ_modules["book_list.library_data"].refresh_sidebar_navigation = refresh_sidebar_navigation;
        ρσ_modules["book_list.library_data"].refresh_browse_field_settings = refresh_browse_field_settings;
        ρσ_modules["book_list.library_data"].browse_field_settings = browse_field_settings;
        ρσ_modules["book_list.library_data"].browse_fields = browse_fields;
        ρσ_modules["book_list.library_data"].browse_field_for = browse_field_for;
        ρσ_modules["book_list.library_data"].add_more_books = add_more_books;
        ρσ_modules["book_list.library_data"].current_book_ids = current_book_ids;
        ρσ_modules["book_list.library_data"].remove_from_array = remove_from_array;
        ρσ_modules["book_list.library_data"].remove_book = remove_book;
        ρσ_modules["book_list.library_data"].book_after = book_after;
        ρσ_modules["book_list.library_data"].on_data_loaded = on_data_loaded;
        ρσ_modules["book_list.library_data"].fetch_init_data = fetch_init_data;
        ρσ_modules["book_list.library_data"].field_names_received = field_names_received;
        ρσ_modules["book_list.library_data"].field_names_for = field_names_for;
        ρσ_modules["book_list.library_data"].thumbnail_url = thumbnail_url;
        ρσ_modules["book_list.library_data"].cover_url = cover_url;
        ρσ_modules["book_list.library_data"].download_url = download_url;
        ρσ_modules["book_list.library_data"].download_data_file_url = download_data_file_url;
        ρσ_modules["book_list.library_data"].web_search_url = web_search_url;
        ρσ_modules["book_list.library_data"].book_metadata = book_metadata;
        ρσ_modules["book_list.library_data"].set_book_metadata = set_book_metadata;
        ρσ_modules["book_list.library_data"].loaded_book_ids = loaded_book_ids;
        ρσ_modules["book_list.library_data"].force_refresh_on_next_load = force_refresh_on_next_load;
        ρσ_modules["book_list.library_data"].ensure_current_library_data = ensure_current_library_data;
        ρσ_modules["book_list.library_data"].ThumbnailCache = ThumbnailCache;
        ρσ_modules["book_list.library_data"].sync_library_books = sync_library_books;
    })();

    (function(){
        var __name__ = "date";
        var UNDEFINED_DATE_ISO, UNDEFINED_DATE, lcdata, supports_locales, fd_function_index;
        UNDEFINED_DATE_ISO = "0101-01-01T00:00:00+00:00";
        UNDEFINED_DATE = new Date(UNDEFINED_DATE_ISO);
        function is_date_undefined(date) {
            var ρσ_unpack, dy, uy;
            ρσ_unpack = [date.getUTCFullYear(), UNDEFINED_DATE.getUTCFullYear()];
            dy = ρσ_unpack[0];
            uy = ρσ_unpack[1];
            return dy < uy || dy === uy && date.getUTCMonth() === UNDEFINED_DATE.getUTCMonth() && date.getUTCDate() <= UNDEFINED_DATE.getUTCDate() + 1;
        };
        if (!is_date_undefined.__argnames__) Object.defineProperties(is_date_undefined, {
            __argnames__ : {value: ["date"]},
            __module__ : {value: "date"}
        });

        lcdata = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["abday"] = ρσ_list_decorate([ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ]);
            ρσ_d["abmon"] = ρσ_list_decorate([ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]);
            ρσ_d["day"] = ρσ_list_decorate([ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]);
            ρσ_d["mon"] = ρσ_list_decorate([ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]);
            return ρσ_d;
        }).call(this);
        supports_locales = false;
        try {
            (new Date).toLocaleString("dfkjghdfkgj");
        } catch (ρσ_Exception) {
            ρσ_last_exception = ρσ_Exception;
            if (ρσ_Exception instanceof RangeError) {
                supports_locales = true;
            } else {
            } 
        }
        function fmt_date_pat() {
            var ans;
            ans = fmt_date_pat.ans;
            if (!(typeof ans !== "undefined" && ans !== null)) {
                ans = fmt_date_pat.ans = /(s{1,2})|(m{1,2})|(h{1,2})|(H{1,2})|(zzz)|(z)|(ap)|(AP)|(Ap)|(aP)|(a)|(A)|(t)|(d{1,4}|M{1,4}|(?:yyyy|yy))/g;
            }
            return ans;
        };
        if (!fmt_date_pat.__module__) Object.defineProperties(fmt_date_pat, {
            __module__ : {value: "date"}
        });

        function fd_format_hour(dt, ampm, hr, as_utc) {
            var h;
            h = (as_utc) ? dt.getUTCHours() : dt.getHours();
            if (ampm) {
                h %= 12;
                if (h === 0) {
                    h = 12;
                }
            }
            return (hr.length === 1) ? h.toString() : str.format("{:02d}", h);
        };
        if (!fd_format_hour.__argnames__) Object.defineProperties(fd_format_hour, {
            __argnames__ : {value: ["dt", "ampm", "hr", "as_utc"]},
            __module__ : {value: "date"}
        });

        function fd_format_hour24(dt, ampm, hr, as_utc) {
            return fd_format_hour(dt, false, hr, as_utc);
        };
        if (!fd_format_hour24.__argnames__) Object.defineProperties(fd_format_hour24, {
            __argnames__ : {value: ["dt", "ampm", "hr", "as_utc"]},
            __module__ : {value: "date"}
        });

        function fd_format_minute(dt, ampm, min, as_utc) {
            var m;
            m = (as_utc) ? dt.getUTCMinutes() : dt.getMinutes();
            return (min.length === 1) ? m.toString() : str.format("{:02d}", m);
        };
        if (!fd_format_minute.__argnames__) Object.defineProperties(fd_format_minute, {
            __argnames__ : {value: ["dt", "ampm", "min", "as_utc"]},
            __module__ : {value: "date"}
        });

        function fd_format_second(dt, ampm, min, as_utc) {
            var s;
            s = (as_utc) ? dt.getUTCSeconds() : dt.getSeconds();
            return (min.length === 1) ? s.toString() : str.format("{:02d}", s);
        };
        if (!fd_format_second.__argnames__) Object.defineProperties(fd_format_second, {
            __argnames__ : {value: ["dt", "ampm", "min", "as_utc"]},
            __module__ : {value: "date"}
        });

        function fd_format_ms(dt, ampm, min, as_utc) {
            var s;
            s = (as_utc) ? dt.getUTCMilliseconds() : dt.getSeconds();
            return (min.length === 1) ? s.toString() : str.format("{:03d}", s);
        };
        if (!fd_format_ms.__argnames__) Object.defineProperties(fd_format_ms, {
            __argnames__ : {value: ["dt", "ampm", "min", "as_utc"]},
            __module__ : {value: "date"}
        });

        function fd_format_timezone(dt, ampm, t, as_utc) {
            var short, full, idx;
            short = dt.toLocaleTimeString();
            full = dt.toLocaleTimeString([], (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["timeZoneName"] = "long";
                return ρσ_d;
            }).call(this));
            idx = full.indexOf(short);
            if (idx > -1) {
                return full.slice(idx + short.length).strip();
            }
            return window.Intl.DateTimeFormat().resolvedOptions().timeZone;
        };
        if (!fd_format_timezone.__argnames__) Object.defineProperties(fd_format_timezone, {
            __argnames__ : {value: ["dt", "ampm", "t", "as_utc"]},
            __module__ : {value: "date"}
        });

        function get_ampm_text(which) {
            var ans, d, x;
            ans = get_ampm_text[(typeof which === "number" && which < 0) ? get_ampm_text.length + which : which];
            if (!ans) {
                try {
                    d = new Date;
                    if (which === "am") {
                        d.setHours(1, 0, 0, 0);
                    } else {
                        d.setHours(13, 0, 0, 0);
                    }
                    x = window.Intl.DateTimeFormat("default", (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["hour"] = "numeric";
                        ρσ_d["hour12"] = true;
                        return ρσ_d;
                    }).call(this)).format(d);
                    ans = x.replace(/\d+/g, "").trim() || which.toUpperCase();
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        ans = which.toUpperCase();
                    } 
                }
                get_ampm_text[(typeof which === "number" && which < 0) ? get_ampm_text.length + which : which] = ans;
            }
            return ans;
        };
        if (!get_ampm_text.__argnames__) Object.defineProperties(get_ampm_text, {
            __argnames__ : {value: ["which"]},
            __module__ : {value: "date"}
        });

        function fd_format_ampm(dt, ampm, ap, as_utc) {
            var h, ans;
            h = (as_utc) ? dt.getUTCHours() : dt.getHours();
            ans = (h < 12) ? "am" : "pm";
            ans = get_ampm_text(ans);
            if (ans === "Ap" || ans === "aP") {
                return ans;
            }
            return (ap === "ap" || ap === "a") ? ans.toLowerCase() : ans.toUpperCase();
        };
        if (!fd_format_ampm.__argnames__) Object.defineProperties(fd_format_ampm, {
            __argnames__ : {value: ["dt", "ampm", "ap", "as_utc"]},
            __module__ : {value: "date"}
        });

        function fd_format_day(dt, ampm, dy, as_utc) {
            var d, options, w;
            d = (as_utc) ? dt.getUTCDate() : dt.getDate();
            if (dy.length === 1) {
                return d.toString();
            }
            if (dy.length === 2) {
                return str.format("{:02d}", d);
            }
            if (supports_locales) {
                options = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["weekday"] = (dy.length === 3) ? "short" : "long";
                    return ρσ_d;
                }).call(this);
                if (as_utc) {
                    options["timeZone"] = "UTC";
                }
                return dt.toLocaleString(window.navigator.language, options);
            }
            w = (as_utc) ? dt.getUTCDay() : dt.getDay();
            return (ρσ_expr_temp = lcdata[ρσ_bound_index((dy.length === 3) ? "abday" : "day", lcdata)])[ρσ_bound_index((w + 1) % 7, ρσ_expr_temp)];
        };
        if (!fd_format_day.__argnames__) Object.defineProperties(fd_format_day, {
            __argnames__ : {value: ["dt", "ampm", "dy", "as_utc"]},
            __module__ : {value: "date"}
        });

        function fd_format_month(dt, ampm, mo, as_utc) {
            var m, options;
            m = (as_utc) ? dt.getUTCMonth() : dt.getMonth();
            if (mo.length === 1) {
                return (m + 1).toString();
            }
            if (mo.length === 2) {
                return str.format("{:02d}", m + 1);
            }
            if (supports_locales) {
                options = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["month"] = (ρσ_expr_temp = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d[1] = "numeric";
                        ρσ_d[2] = "2-digit";
                        ρσ_d[3] = "short";
                        ρσ_d[4] = "long";
                        return ρσ_d;
                    }).call(this))[ρσ_bound_index(mo.length, ρσ_expr_temp)] || "long";
                    return ρσ_d;
                }).call(this);
                if (as_utc) {
                    options["timeZone"] = "UTC";
                }
                return dt.toLocaleString(window.navigator.language, options);
            }
            return (ρσ_expr_temp = lcdata[ρσ_bound_index((mo.length === 3) ? "abmon" : "mon", lcdata)])[(typeof m === "number" && m < 0) ? ρσ_expr_temp.length + m : m];
        };
        if (!fd_format_month.__argnames__) Object.defineProperties(fd_format_month, {
            __argnames__ : {value: ["dt", "ampm", "mo", "as_utc"]},
            __module__ : {value: "date"}
        });

        function fd_format_year(dt, ampm, yr, as_utc) {
            var y;
            y = (as_utc) ? dt.getUTCFullYear() : dt.getFullYear();
            if (yr.length === 2) {
                return str.format("{:02d}", y % 100);
            }
            return str.format("{:04d}", y);
        };
        if (!fd_format_year.__argnames__) Object.defineProperties(fd_format_year, {
            __argnames__ : {value: ["dt", "ampm", "yr", "as_utc"]},
            __module__ : {value: "date"}
        });

        fd_function_index = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["d"] = fd_format_day;
            ρσ_d["M"] = fd_format_month;
            ρσ_d["y"] = fd_format_year;
            ρσ_d["h"] = fd_format_hour;
            ρσ_d["H"] = fd_format_hour24;
            ρσ_d["m"] = fd_format_minute;
            ρσ_d["s"] = fd_format_second;
            ρσ_d["a"] = fd_format_ampm;
            ρσ_d["A"] = fd_format_ampm;
            ρσ_d["ap"] = fd_format_ampm;
            ρσ_d["AP"] = fd_format_ampm;
            ρσ_d["Ap"] = fd_format_ampm;
            ρσ_d["aP"] = fd_format_ampm;
            ρσ_d["z"] = fd_format_ms;
            ρσ_d["t"] = fd_format_timezone;
            return ρσ_d;
        }).call(this);
        function am_pm_pat() {
            var ans;
            ans = am_pm_pat.ans;
            if (!(typeof ans !== "undefined" && ans !== null)) {
                ans = am_pm_pat.ans = /(ap)|(AP)|(Ap)|(aP)|(a)|(A)/;
            }
            return ans;
        };
        if (!am_pm_pat.__module__) Object.defineProperties(am_pm_pat, {
            __module__ : {value: "date"}
        });

        function as_iso(date) {
            var tzo, dif;
            tzo = -date.getTimezoneOffset();
            dif = (tzo >= 0) ? "+" : "-";
            function pad(num) {
                return ((num < 10) ? "0" : "") + num;
            };
            if (!pad.__argnames__) Object.defineProperties(pad, {
                __argnames__ : {value: ["num"]},
                __module__ : {value: "date"}
            });

            return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + " " + pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds()) + dif + pad(Math.floor(Math.abs(tzo) / 60)) + ":" + pad(Math.abs(tzo) % 60);
        };
        if (!as_iso.__argnames__) Object.defineProperties(as_iso, {
            __argnames__ : {value: ["date"]},
            __module__ : {value: "date"}
        });

        function format_date() {
            var date = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? format_date.__defaults__.date : arguments[0];
            var fmt = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? format_date.__defaults__.fmt : arguments[1];
            var as_utc = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? format_date.__defaults__.as_utc : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "date")){
                date = ρσ_kwargs_obj.date;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "fmt")){
                fmt = ρσ_kwargs_obj.fmt;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "as_utc")){
                as_utc = ρσ_kwargs_obj.as_utc;
            }
            var ampm;
            fmt = fmt || "dd MMM yyyy";
            ampm = am_pm_pat().test(fmt);
            if (typeof date === "string") {
                date = new Date(date);
            }
            date = date || new Date;
            if (is_date_undefined(date)) {
                return "";
            }
            if (fmt === "iso") {
                return as_iso(date);
            }
            return fmt.replace(fmt_date_pat(), (function() {
                var ρσ_anonfunc = function (match) {
                    if (!match) {
                        return "";
                    }
                    try {
                        return fd_function_index[ρσ_bound_index(match[0], fd_function_index)](date, ampm, match, as_utc);
                    } catch (ρσ_Exception) {
                        ρσ_last_exception = ρσ_Exception;
                        if (ρσ_Exception instanceof Error) {
                            print(str.format("Failed to format date with format: {} and match: {}", fmt, match));
                            return "";
                        } else {
                            throw ρσ_Exception;
                        }
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["match"]},
                    __module__ : {value: "date"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!format_date.__defaults__) Object.defineProperties(format_date, {
            __defaults__ : {value: {date:null, fmt:"dd MMM yyyy", as_utc:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["date", "fmt", "as_utc"]},
            __module__ : {value: "date"}
        });

        ρσ_modules.date.UNDEFINED_DATE_ISO = UNDEFINED_DATE_ISO;
        ρσ_modules.date.UNDEFINED_DATE = UNDEFINED_DATE;
        ρσ_modules.date.lcdata = lcdata;
        ρσ_modules.date.supports_locales = supports_locales;
        ρσ_modules.date.fd_function_index = fd_function_index;
        ρσ_modules.date.is_date_undefined = is_date_undefined;
        ρσ_modules.date.fmt_date_pat = fmt_date_pat;
        ρσ_modules.date.fd_format_hour = fd_format_hour;
        ρσ_modules.date.fd_format_hour24 = fd_format_hour24;
        ρσ_modules.date.fd_format_minute = fd_format_minute;
        ρσ_modules.date.fd_format_second = fd_format_second;
        ρσ_modules.date.fd_format_ms = fd_format_ms;
        ρσ_modules.date.fd_format_timezone = fd_format_timezone;
        ρσ_modules.date.get_ampm_text = get_ampm_text;
        ρσ_modules.date.fd_format_ampm = fd_format_ampm;
        ρσ_modules.date.fd_format_day = fd_format_day;
        ρσ_modules.date.fd_format_month = fd_format_month;
        ρσ_modules.date.fd_format_year = fd_format_year;
        ρσ_modules.date.am_pm_pat = am_pm_pat;
        ρσ_modules.date.as_iso = as_iso;
        ρσ_modules.date.format_date = format_date;
    })();

    (function(){
        var __name__ = "popups";
        var MODAL_Z_INDEX, POPUP_Z_INDEX, popup_count, shown_popups, associated_widgets;
        var get_color = ρσ_modules["book_list.theme"].get_color;

        var set_css = ρσ_modules.dom.set_css;
        var ensure_id = ρσ_modules.dom.ensure_id;
        var clear = ρσ_modules.dom.clear;
        var build_rule = ρσ_modules.dom.build_rule;
        var add_extra_css = ρσ_modules.dom.add_extra_css;

        var E = ρσ_modules.elementmaker.E;

        MODAL_Z_INDEX = 1e3;
        POPUP_Z_INDEX = MODAL_Z_INDEX + 1;
        popup_count = 0;
        shown_popups = set();
        associated_widgets = Object.create(null);
        function element_contains_click_event(element, event) {
            var r;
            r = element.getBoundingClientRect();
            return r.left <= (ρσ_cond_temp = event.clientX) && ρσ_cond_temp <= r.right && r.top <= (ρσ_cond_temp = event.clientY) && ρσ_cond_temp <= r.bottom;
        };
        if (!element_contains_click_event.__argnames__) Object.defineProperties(element_contains_click_event, {
            __argnames__ : {value: ["element", "event"]},
            __module__ : {value: "popups"}
        });

        function click_in_popup(event) {
            var popup, w, widget, wid, popup_id;
            var ρσ_Iter0 = ρσ_Iterable(shown_popups);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                popup_id = ρσ_Iter0[ρσ_Index0];
                popup = document.getElementById(popup_id);
                if (popup && element_contains_click_event(popup, event)) {
                    return true;
                }
                w = associated_widgets[(typeof popup_id === "number" && popup_id < 0) ? associated_widgets.length + popup_id : popup_id];
                if (w && w.length) {
                    var ρσ_Iter1 = ρσ_Iterable(w);
                    for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                        wid = ρσ_Iter1[ρσ_Index1];
                        widget = document.getElementById(wid);
                        if (widget && element_contains_click_event(widget, event)) {
                            return true;
                        }
                    }
                }
            }
            return false;
        };
        if (!click_in_popup.__argnames__) Object.defineProperties(click_in_popup, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "popups"}
        });

        function filter_clicks(event) {
            var popup_id;
            if (shown_popups.length) {
                if (!click_in_popup(event)) {
                    var ρσ_Iter2 = ρσ_Iterable(shown_popups);
                    for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                        popup_id = ρσ_Iter2[ρσ_Index2];
                        hide_popup(popup_id);
                    }
                    shown_popups.clear();
                    [event.stopPropagation(), event.preventDefault()];
                }
            }
        };
        if (!filter_clicks.__argnames__) Object.defineProperties(filter_clicks, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "popups"}
        });

        function install_event_filters() {
            window.addEventListener("click", filter_clicks, true);
        };
        if (!install_event_filters.__module__) Object.defineProperties(install_event_filters, {
            __module__ : {value: "popups"}
        });

        function create_popup(parent, idprefix) {
            var pid, div;
            popup_count += 1;
            pid = (idprefix || "popup") + "-" + popup_count;
            div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: pid, style: "display: none; position: fixed; z-index: {}".format(POPUP_Z_INDEX)})]);
            parent = parent || document.body;
            parent.appendChild(div);
            return div;
        };
        if (!create_popup.__argnames__) Object.defineProperties(create_popup, {
            __argnames__ : {value: ["parent", "idprefix"]},
            __module__ : {value: "popups"}
        });

        function show_popup() {
            var popup_id = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var associated_widget_ids = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_popup.__defaults__.associated_widget_ids : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "associated_widget_ids")){
                associated_widget_ids = ρσ_kwargs_obj.associated_widget_ids;
            }
            var elem;
            elem = document.getElementById(popup_id);
            elem.style.display = "block";
            shown_popups.add(popup_id);
            associated_widgets[(typeof popup_id === "number" && popup_id < 0) ? associated_widgets.length + popup_id : popup_id] = associated_widget_ids;
        };
        if (!show_popup.__defaults__) Object.defineProperties(show_popup, {
            __defaults__ : {value: {associated_widget_ids:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["popup_id", "associated_widget_ids"]},
            __module__ : {value: "popups"}
        });

        function hide_popup(popup_id) {
            var elem;
            elem = document.getElementById(popup_id);
            if (elem) {
                elem.style.display = "none";
            }
            delete associated_widgets[popup_id];
        };
        if (!hide_popup.__argnames__) Object.defineProperties(hide_popup, {
            __argnames__ : {value: ["popup_id"]},
            __module__ : {value: "popups"}
        });

        function CompletionPopup() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            CompletionPopup.prototype.__bind_methods__.call(this);
            CompletionPopup.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(CompletionPopup.prototype, "__bind_methods__", {value: function () {
            this.set_all_items = CompletionPopup.prototype.set_all_items.bind(this);
            this.add_associated_widget = CompletionPopup.prototype.add_associated_widget.bind(this);
            this.popup = CompletionPopup.prototype.popup.bind(this);
            this.show_at_widget = CompletionPopup.prototype.show_at_widget.bind(this);
            this.set_query = CompletionPopup.prototype.set_query.bind(this);
            this.hide = CompletionPopup.prototype.hide.bind(this);
            this.handle_keydown = CompletionPopup.prototype.handle_keydown.bind(this);
            this.move_highlight = CompletionPopup.prototype.move_highlight.bind(this);
            this._show_at = CompletionPopup.prototype._show_at.bind(this);
            this._apply_query = CompletionPopup.prototype._apply_query.bind(this);
            this._render_matches = CompletionPopup.prototype._render_matches.bind(this);
            this.onmouseenter = CompletionPopup.prototype.onmouseenter.bind(this);
            this.onclick = CompletionPopup.prototype.onclick.bind(this);
        }});
        Object.defineProperties(CompletionPopup.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById(self.container_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "is_visible": {
                "enumerable": true, 
                "get": function is_visible() {
                    var self = this;
                    return self.container.style.display !== "none";
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "current_item": {
                "enumerable": true, 
                "get": function current_item() {
                    var self = this;
                    var c;
                    c = self.container;
                    return c.querySelector("div.{} > div.{}".format(self.CLASS, self.CURRENT_ITEM_CLASS));
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "current_text": {
                "enumerable": true, 
                "get": function current_text() {
                    var self = this;
                    return ρσ_exists.d(self.current_item).textContent;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        CompletionPopup.prototype.__init__ = function __init__() {
            var self = this;
            var parent = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.parent : arguments[0];
            var max_items = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.max_items : arguments[1];
            var onselect = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.onselect : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "parent")){
                parent = ρσ_kwargs_obj.parent;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "max_items")){
                max_items = ρσ_kwargs_obj.max_items;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "onselect")){
                onselect = ρσ_kwargs_obj.onselect;
            }
            var c, ρσ_unpack;
            self.max_items = max_items;
            c = create_popup(parent);
            ρσ_interpolate_kwargs.call(this, set_css, [c].concat([ρσ_desugar_kwargs({user_select: "none"})]));
            self.container_id = c.getAttribute("id");
            self.onselect = onselect;
            self.items = ρσ_list_decorate([]);
            self.matches = ρσ_list_decorate([]);
            c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: self.CLASS})]));
            self.associated_widget_ids = set();
            ρσ_unpack = ["", false];
            self.current_query = ρσ_unpack[0];
            self.is_upwards = ρσ_unpack[1];
            self.applied_query = self.current_query;
        };
        if (!CompletionPopup.prototype.__init__.__defaults__) Object.defineProperties(CompletionPopup.prototype.__init__, {
            __defaults__ : {value: {parent:null, max_items:25, onselect:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["parent", "max_items", "onselect"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.__argnames__ = CompletionPopup.prototype.__init__.__argnames__;
        CompletionPopup.__handles_kwarg_interpolation__ = CompletionPopup.prototype.__init__.__handles_kwarg_interpolation__;
        CompletionPopup.prototype.set_all_items = function set_all_items(items) {
            var self = this;
            self.items = list(items);
            self.matches = ρσ_list_decorate([]);
            self.applied_query = null;
        };
        if (!CompletionPopup.prototype.set_all_items.__argnames__) Object.defineProperties(CompletionPopup.prototype.set_all_items, {
            __argnames__ : {value: ["items"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype.add_associated_widget = function add_associated_widget(widget_or_id) {
            var self = this;
            if (typeof widget_or_id !== "string") {
                widget_or_id = ensure_id(widget_or_id);
            }
            self.associated_widget_ids.add(widget_or_id);
        };
        if (!CompletionPopup.prototype.add_associated_widget.__argnames__) Object.defineProperties(CompletionPopup.prototype.add_associated_widget, {
            __argnames__ : {value: ["widget_or_id"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype.popup = function popup(widget) {
            var self = this;
            if (!self.is_visible) {
                if (self.applied_query !== self.current_query) {
                    self._apply_query();
                }
                if (self.matches.length) {
                    self.show_at_widget(widget);
                }
            }
        };
        if (!CompletionPopup.prototype.popup.__argnames__) Object.defineProperties(CompletionPopup.prototype.popup, {
            __argnames__ : {value: ["widget"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype.show_at_widget = function show_at_widget(w) {
            var self = this;
            var br, ρσ_unpack, y, upwards;
            br = w.getBoundingClientRect();
            if (br.top > window.innerHeight - br.bottom) {
                ρσ_unpack = [br.top, true];
                y = ρσ_unpack[0];
                upwards = ρσ_unpack[1];
            } else {
                ρσ_unpack = [br.bottom, false];
                y = ρσ_unpack[0];
                upwards = ρσ_unpack[1];
            }
            self._show_at(br.left, y, br.width, upwards);
        };
        if (!CompletionPopup.prototype.show_at_widget.__argnames__) Object.defineProperties(CompletionPopup.prototype.show_at_widget, {
            __argnames__ : {value: ["w"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype.set_query = function set_query(query) {
            var self = this;
            self.current_query = query;
            if (self.is_visible && self.applied_query !== self.current_query) {
                self._apply_query();
                if (!self.matches.length) {
                    self.hide();
                }
            }
        };
        if (!CompletionPopup.prototype.set_query.__argnames__) Object.defineProperties(CompletionPopup.prototype.set_query, {
            __argnames__ : {value: ["query"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype.hide = function hide() {
            var self = this;
            var c;
            self.container.style.display = "none";
            c = self.current_item;
            if (c) {
                c.classList.remove(self.CURRENT_ITEM_CLASS);
            }
        };
        if (!CompletionPopup.prototype.hide.__module__) Object.defineProperties(CompletionPopup.prototype.hide, {
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype.handle_keydown = function handle_keydown(event) {
            var self = this;
            var key;
            key = event.key;
            if (key === "Escape" || key === "Esc") {
                self.hide();
                return true;
            }
            if (key === "ArrowUp") {
                self.move_highlight(true);
                return true;
            }
            if (key === "ArrowDown") {
                self.move_highlight(false);
                return true;
            }
            return false;
        };
        if (!CompletionPopup.prototype.handle_keydown.__argnames__) Object.defineProperties(CompletionPopup.prototype.handle_keydown, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype.move_highlight = function move_highlight() {
            var self = this;
            var up = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? move_highlight.__defaults__.up : arguments[0];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "up")){
                up = ρσ_kwargs_obj.up;
            }
            var ans, div, c;
            if (up === null) {
                up = self.is_upwards;
            }
            ans = null;
            div = self.current_item;
            if (div) {
                div.classList.remove(self.CURRENT_ITEM_CLASS);
                ans = (up) ? div.previousSibling : div.nextSibling;
            }
            if (!ans) {
                c = self.container.firstChild;
                ans = (up) ? c.lastChild : c.firstChild;
            }
            if (ans) {
                ans.classList.add(self.CURRENT_ITEM_CLASS);
            }
        };
        if (!CompletionPopup.prototype.move_highlight.__defaults__) Object.defineProperties(CompletionPopup.prototype.move_highlight, {
            __defaults__ : {value: {up:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["up"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype._show_at = function _show_at(x, y, width, upwards) {
            var self = this;
            var c, cs;
            self.is_upwards = upwards;
            c = self.container;
            cs = c.style;
            cs.left = x + "px";
            cs.top = (upwards) ? "auto" : y + "px";
            cs.bottom = (upwards) ? window.innerHeight - y + "px" : "auto";
            cs.width = width + "px";
            cs.maxHeight = ((upwards) ? y : window.innerHeight - y) - 10 + "px";
            show_popup(self.container_id, self.associated_widget_ids);
        };
        if (!CompletionPopup.prototype._show_at.__argnames__) Object.defineProperties(CompletionPopup.prototype._show_at, {
            __argnames__ : {value: ["x", "y", "width", "upwards"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype._apply_query = function _apply_query() {
            var self = this;
            var q, i;
            q = self.current_query.toLowerCase();
            self.matches.clear();
            self.applied_query = self.current_query;
            if (!q) {
                self.matches = list(self.items.slice(0, self.max_items + 1));
            } else {
                i = 0;
                while (self.matches.length < self.max_items && i < self.items.length) {
                    if ((ρσ_expr_temp = self.items)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i].toLowerCase().startswith(q)) {
                        self.matches.push((ρσ_expr_temp = self.items)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i]);
                    }
                    i += 1;
                }
            }
            self._render_matches();
        };
        if (!CompletionPopup.prototype._apply_query.__module__) Object.defineProperties(CompletionPopup.prototype._apply_query, {
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype._render_matches = function _render_matches() {
            var self = this;
            var c, items, m;
            c = self.container;
            clear(c.firstChild);
            items = self.matches;
            if (self.is_upwards) {
                items = reversed(items);
            }
            var ρσ_Iter3 = ρσ_Iterable(items);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                m = ρσ_Iter3[ρσ_Index3];
                c.firstChild.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [m].concat([ρσ_desugar_kwargs({onmouseenter: self.onmouseenter, onclick: self.onclick})])));
            }
        };
        if (!CompletionPopup.prototype._render_matches.__module__) Object.defineProperties(CompletionPopup.prototype._render_matches, {
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype.onmouseenter = function onmouseenter(event) {
            var self = this;
            var div;
            div = self.current_item;
            if (div) {
                div.classList.remove(self.CURRENT_ITEM_CLASS);
            }
            event.currentTarget.classList.add(self.CURRENT_ITEM_CLASS);
        };
        if (!CompletionPopup.prototype.onmouseenter.__argnames__) Object.defineProperties(CompletionPopup.prototype.onmouseenter, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype.onclick = function onclick(event) {
            var self = this;
            self.onmouseenter(event);
            try {
                if (self.onselect) {
                    self.onselect(self.current_text);
                }
            } finally {
                self.hide();
            }
        };
        if (!CompletionPopup.prototype.onclick.__argnames__) Object.defineProperties(CompletionPopup.prototype.onclick, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "popups"}
        });
        CompletionPopup.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        CompletionPopup.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(CompletionPopup.prototype, "__bases__", {value: []});
        CompletionPopup.prototype.CLASS = "popup-completion-items";
        CompletionPopup.prototype.CURRENT_ITEM_CLASS = "popup-completion-current-item";
        
        
        
        

        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, style;
                sel = "div." + CompletionPopup.prototype.CLASS;
                style = ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({overflow: "hidden", text_align: "left", background_color: get_color("window-background"), border: "solid 1px " + get_color("window-foreground")})]));
                sel += " > div";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({cursor: "pointer", padding: "1ex 1rem", white_space: "nowrap", text_overflow: "ellipsis", overflow: "hidden"})]));
                sel += "." + CompletionPopup.prototype.CURRENT_ITEM_CLASS;
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({color: get_color("list-hover-foreground"), background_color: get_color("list-hover-background")})]));
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "popups"}
            });
            return ρσ_anonfunc;
        })());
        ρσ_modules.popups.MODAL_Z_INDEX = MODAL_Z_INDEX;
        ρσ_modules.popups.POPUP_Z_INDEX = POPUP_Z_INDEX;
        ρσ_modules.popups.popup_count = popup_count;
        ρσ_modules.popups.shown_popups = shown_popups;
        ρσ_modules.popups.associated_widgets = associated_widgets;
        ρσ_modules.popups.element_contains_click_event = element_contains_click_event;
        ρσ_modules.popups.click_in_popup = click_in_popup;
        ρσ_modules.popups.filter_clicks = filter_clicks;
        ρσ_modules.popups.install_event_filters = install_event_filters;
        ρσ_modules.popups.create_popup = create_popup;
        ρσ_modules.popups.show_popup = show_popup;
        ρσ_modules.popups.hide_popup = hide_popup;
        ρσ_modules.popups.CompletionPopup = CompletionPopup;
    })();

    (function(){
        var __name__ = "widgets";
        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var svgicon = ρσ_modules.dom.svgicon;
        var create_keyframes = ρσ_modules.dom.create_keyframes;
        var set_css = ρσ_modules.dom.set_css;
        var change_icon_image = ρσ_modules.dom.change_icon_image;
        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var ensure_id = ρσ_modules.dom.ensure_id;

        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        function create_button() {
            var text = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var icon = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_button.__defaults__.icon : arguments[1];
            var action = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_button.__defaults__.action : arguments[2];
            var tooltip = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_button.__defaults__.tooltip : arguments[3];
            var highlight = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_button.__defaults__.highlight : arguments[4];
            var download_filename = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_button.__defaults__.download_filename : arguments[5];
            var class_ = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_button.__defaults__.class_ : arguments[6];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "icon")){
                icon = ρσ_kwargs_obj.icon;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "action")){
                action = ρσ_kwargs_obj.action;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "tooltip")){
                tooltip = ρσ_kwargs_obj.tooltip;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "highlight")){
                highlight = ρσ_kwargs_obj.highlight;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "download_filename")){
                download_filename = ρσ_kwargs_obj.download_filename;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "class_")){
                class_ = ρσ_kwargs_obj.class_;
            }
            var ic, cls, ans;
            ic = "";
            if (icon) {
                ic = svgicon(icon);
                if (text) {
                    text = " " + text;
                }
            }
            cls = ("calibre-push-button " + (class_ || "")).strip();
            if (highlight) {
                cls = (cls + " calibre-primary-button").strip();
            }
            ans = ρσ_interpolate_kwargs.call(E, E.a, [ic, E.span(text)].concat([ρσ_desugar_kwargs({class_: cls, href: "javascript: void(0)", role: "button", title: tooltip || ""})]));
            if (download_filename && "download" in ans) {
                ans.setAttribute("download", download_filename);
            }
            if (action !== null) {
                if (typeof action === "string") {
                    ans.setAttribute("href", action);
                } else {
                    ans.addEventListener("click", (function() {
                        var ρσ_anonfunc = function (event) {
                            [event.preventDefault(), action(event)];
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["event"]},
                            __module__ : {value: "widgets"}
                        });
                        return ρσ_anonfunc;
                    })());
                }
            }
            return ans;
        };
        if (!create_button.__defaults__) Object.defineProperties(create_button, {
            __defaults__ : {value: {icon:null, action:null, tooltip:null, highlight:false, download_filename:null, class_:""}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["text", "icon", "action", "tooltip", "highlight", "download_filename", "class_"]},
            __module__ : {value: "widgets"}
        });

        create_button.style += "\n@media (max-width: 420px) {\n  #modal-container .button-box { flex-direction: column; align-items: stretch; }\n  #modal-container .button-box > a.calibre-push-button { width: 100%; flex: 1 1 auto; justify-content: center; }\n  #modal-container .button-box > a.calibre-push-button:only-of-type { margin-left: 0; }\n}\n";
        function create_pager_widget(on_prev, on_next) {
            var prev_btn, next_btn, buttons_container, top_row, middle_row, container;
            function create_pager_button(is_prev, label, icon, onclick) {
                var a;
                a = ρσ_interpolate_kwargs.call(E, E.a, [svgicon(icon), E.span(label)].concat([ρσ_desugar_kwargs({href: "javascript:void(0)", class_: "calibre-push-button"})]));
                if (!is_prev) {
                    a.insertBefore(a.firstChild.nextSibling, a.firstChild);
                }
                a.addEventListener("click", (function() {
                    var ρσ_anonfunc = function (evt) {
                        evt.preventDefault();
                        onclick();
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["evt"]},
                        __module__ : {value: "widgets"}
                    });
                    return ρσ_anonfunc;
                })());
                return a;
            };
            if (!create_pager_button.__argnames__) Object.defineProperties(create_pager_button, {
                __argnames__ : {value: ["is_prev", "label", "icon", "onclick"]},
                __module__ : {value: "widgets"}
            });

            prev_btn = create_pager_button(true, _("Prev"), "chevron-left", on_prev);
            next_btn = create_pager_button(false, _("Next"), "chevron-right", on_next);
            buttons_container = ρσ_interpolate_kwargs.call(E, E.div, [prev_btn, E.div(), next_btn].concat([ρσ_desugar_kwargs({class_: "bottom-row"})]));
            top_row = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "top-row hidden"})]);
            middle_row = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "middle-row hidden"})]);
            container = ρσ_interpolate_kwargs.call(E, E.div, [top_row, E.hr(), middle_row, E.hr(), buttons_container].concat([ρσ_desugar_kwargs({class_: "calibre-pager-widget calibre-group-box"})]));
            function update_container_visibility() {
                container.style.display = (buttons_container.classList.contains("hidden") && top_row.classList.contains("hidden") && middle_row.classList.contains("hidden")) ? "none" : "";
            };
            if (!update_container_visibility.__module__) Object.defineProperties(update_container_visibility, {
                __module__ : {value: "widgets"}
            });

            function set_enabled(has_prev, has_next) {
                prev_btn.setAttribute("aria-disabled", (has_prev) ? "false" : "true");
                next_btn.setAttribute("aria-disabled", (has_next) ? "false" : "true");
                if (has_prev || has_next) {
                    buttons_container.classList.remove("hidden");
                } else {
                    buttons_container.classList.add("hidden");
                }
                update_container_visibility();
            };
            if (!set_enabled.__argnames__) Object.defineProperties(set_enabled, {
                __argnames__ : {value: ["has_prev", "has_next"]},
                __module__ : {value: "widgets"}
            });

            function set_visible(which, visible) {
                if (visible) {
                    which.classList.remove("hidden");
                } else {
                    which.classList.add("hidden");
                }
                update_container_visibility();
            };
            if (!set_visible.__argnames__) Object.defineProperties(set_visible, {
                __argnames__ : {value: ["which", "visible"]},
                __module__ : {value: "widgets"}
            });

            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["container"] = container;
                ρσ_d["count_msg"] = buttons_container.firstChild.nextSibling;
                ρσ_d["prev_btn"] = prev_btn;
                ρσ_d["next_btn"] = next_btn;
                ρσ_d["set_enabled"] = set_enabled;
                ρσ_d["top_row"] = top_row;
                ρσ_d["middle_row"] = middle_row;
                ρσ_d["set_top_row_visibility"] = (function() {
                    var ρσ_anonfunc = function (visible) {
                        set_visible(top_row, visible);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["visible"]},
                        __module__ : {value: "widgets"}
                    });
                    return ρσ_anonfunc;
                })();
                ρσ_d["set_middle_row_visibility"] = (function() {
                    var ρσ_anonfunc = function (visible) {
                        set_visible(middle_row, visible);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["visible"]},
                        __module__ : {value: "widgets"}
                    });
                    return ρσ_anonfunc;
                })();
                return ρσ_d;
            }).call(this);
        };
        if (!create_pager_widget.__argnames__) Object.defineProperties(create_pager_widget, {
            __argnames__ : {value: ["on_prev", "on_next"]},
            __module__ : {value: "widgets"}
        });

        create_pager_widget.style = "\ndiv.calibre-pager-widget {\n    display: flex;\n    flex-direction: column;\n\n    & > hr {\n        margin-top: 0.9ex; margin-bottom: 0.9ex;\n    }\n\n    & > .top-row {\n        display: flex;\n        overflow: hidden;\n        gap: 0.75rem;\n    }\n\n    & > .middle-row {\n        display: flex;\n        overflow: hidden;\n        flex-wrap: wrap;\n        gap: 0.75rem;\n    }\n\n    & > .bottom-row {\n        display: flex;\n        align-items: center;\n        justify-content: space-between;\n        gap: 0.75rem;\n        flex-wrap: wrap;\n        min-width: 0;\n        width: 100%;\n        box-sizing: border-box;\n\n        & > :first-child, & > :last-child {\n            display: flex;\n            align-items: center;\n            gap: 0.5rem;\n            flex: 1 1 auto;\n            min-width: 0;\n            max-width: 100%;\n        }\n\n        & > :first-child { justify-content: flex-start; }\n        & > :last-child { justify-content: flex-end; }\n        & > :nth-child(2) {\n            text-align: center;\n            display: block;\n            text-overflow: ellipsis;\n        }\n    }\n\n    & > .hidden {\n        display: none;\n        & + hr { display: none; }\n    }\n    & > hr:has(+ .hidden) { display: none; }\n\n}\n";
        function create_search_widget() {
            var onsearch = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var value = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_search_widget.__defaults__.value : arguments[1];
            var placeholder = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_search_widget.__defaults__.placeholder : arguments[2];
            var tooltip = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_search_widget.__defaults__.tooltip : arguments[3];
            var live_searching = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_search_widget.__defaults__.live_searching : arguments[4];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "value")){
                value = ρσ_kwargs_obj.value;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "placeholder")){
                placeholder = ρσ_kwargs_obj.placeholder;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "tooltip")){
                tooltip = ρσ_kwargs_obj.tooltip;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "live_searching")){
                live_searching = ρσ_kwargs_obj.live_searching;
            }
            var box, search, sb;
            box = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({data_component: "search_box", style: "width: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 0.65rem"})]);
            search = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "search", value: value, placeholder: placeholder, title: tooltip || placeholder, autocomplete: "off", style: "width: 0; flex-grow: 1; min-width: 6em"})]);
            search.addEventListener((live_searching) ? "input" : "search", (function() {
                var ρσ_anonfunc = function () {
                    onsearch(this.value);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "widgets"}
                });
                return ρσ_anonfunc;
            })());
            box.appendChild(search);
            sb = ρσ_interpolate_kwargs.call(E, E.a, [svgicon("search")].concat([ρσ_desugar_kwargs({class_: "calibre-icon-button", style: "margin-left: auto", href: "javascript:void(0)", title: _("Search"), onmousedown: (function() {
                var ρσ_anonfunc = function (evt) {
                    evt.preventDefault();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["evt"]},
                    __module__ : {value: "widgets"}
                });
                return ρσ_anonfunc;
            })(), onclick: (function() {
                var ρσ_anonfunc = function (evt) {
                    evt.preventDefault();
                    onsearch(this.previousSibling.value);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["evt"]},
                    __module__ : {value: "widgets"}
                });
                return ρσ_anonfunc;
            })()})]));
            box.appendChild(sb);
            return box;
        };
        if (!create_search_widget.__defaults__) Object.defineProperties(create_search_widget, {
            __defaults__ : {value: {value:"", placeholder:"", tooltip:"", live_searching:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["onsearch", "value", "placeholder", "tooltip", "live_searching"]},
            __module__ : {value: "widgets"}
        });

        function create_select() {
            var title = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var current_value = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var options = arguments[arguments.length-1];
            if (options === null || typeof options !== "object" || options [ρσ_kwargs_symbol] !== true) options = {};
            var sel, ρσ_unpack, value, text, container;
            sel = ρσ_interpolate_kwargs.call(E, E.select, [ρσ_desugar_kwargs({title: title})]);
            var ρσ_Iter0 = ρσ_Iterable(Object.entries(options));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                ρσ_unpack = ρσ_Iter0[ρσ_Index0];
                value = ρσ_unpack[0];
                text = ρσ_unpack[1];
                sel.appendChild(ρσ_interpolate_kwargs.call(E, E.option, [text].concat([ρσ_desugar_kwargs({value: value})])));
            }
            sel.value = current_value;
            container = ρσ_interpolate_kwargs.call(E, E.div, [sel, E.span(svgicon("angle-down"))].concat([ρσ_desugar_kwargs({data_component: "select"})]));
            return [container, sel];
        };
        if (!create_select.__handles_kwarg_interpolation__) Object.defineProperties(create_select, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title", "current_value"]},
            __module__ : {value: "widgets"}
        });

        create_select.style = "\ndiv[data-component=select] {\n    display: inline-flex;\n    position: relative;\n    align-items: center;\n    flex-shrink: 0;\n\n    & > select {\n        appearance: none;\n        margin: 0;\n        padding: 0.35rem 2.0em 0.35rem 0.65rem;\n        border-radius: 999px;\n        border: var(--calibre-border-style-subtle);\n        background-color: var(--calibre-color-window-background);\n        color: var(--calibre-color-window-foreground);\n        align-self: center;\n        box-sizing: border-box;\n\n        &:hover {\n            background-color: var(--calibre-color-primary-light);\n            border: var(--calibre-border-style);\n        }\n        &:focus {\n            outline: none;\n            border: var(--calibre-border-style-subtle);\n        }\n\n        & > option {\n            background-color: var(--calibre-color-window-background);\n            color: var(--calibre-color-input-foreground);\n            &:checked { outline-color: var(--calibre-color-primary); }\n            &:hover {\n                background-color: var(--calibre-color-window-background);\n                color: var(--calibre-color-primary);\n            }\n        }\n    }\n    & > span {\n        position: absolute;\n        right: 0.65em;\n        top: 50%;\n        transform: translateY(-50%);\n        pointer-events: none;\n        opacity: 0.75;\n        color: currentColor;\n        display: inline-flex;\n        align-items: center;\n        justify-content: center;\n\n        & > svg {\n            width: 1em;\n            height: 1em;\n            flex-shrink: 0;\n        }\n    }\n}\n";
        function create_spinner(height, width) {
            var ans;
            ans = svgicon("cog", height, width);
            ans.classList.add("spin");
            return ans;
        };
        if (!create_spinner.__argnames__) Object.defineProperties(create_spinner, {
            __argnames__ : {value: ["height", "width"]},
            __module__ : {value: "widgets"}
        });

        create_spinner.style = ρσ_interpolate_kwargs.call(this, build_rule, [".spin"].concat([ρσ_desugar_kwargs({animation: "spin 2s infinite linear"})]));
        create_spinner.style += create_keyframes("spin", "from { transform: rotate(0deg); } to { transform: rotate(359deg);}");
        function Breadcrumbs() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            Breadcrumbs.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperties(Breadcrumbs.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById(self.container_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        Breadcrumbs.prototype.__init__ = function __init__(container) {
            var self = this;
            self.container_id = ensure_id(container, "calibre-breadcrumbs-");
            container.classList.add("calibre-breadcrumbs");
            clear(container);
        };
        if (!Breadcrumbs.prototype.__init__.__argnames__) Object.defineProperties(Breadcrumbs.prototype.__init__, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "widgets"}
        });
        Breadcrumbs.__argnames__ = Breadcrumbs.prototype.__init__.__argnames__;
        Breadcrumbs.__handles_kwarg_interpolation__ = Breadcrumbs.prototype.__init__.__handles_kwarg_interpolation__;
        Breadcrumbs.prototype.reset = function reset() {
            var self = this;
            clear(self.container);
        };
        if (!Breadcrumbs.prototype.reset.__module__) Object.defineProperties(Breadcrumbs.prototype.reset, {
            __module__ : {value: "widgets"}
        });
        Breadcrumbs.prototype.add_crumb = function add_crumb(callback) {
            var self = this;
            var li;
            li = E.li();
            if (callback) {
                li.addEventListener("click", callback);
            }
            self.container.appendChild(li);
            return li;
        };
        if (!Breadcrumbs.prototype.add_crumb.__argnames__) Object.defineProperties(Breadcrumbs.prototype.add_crumb, {
            __argnames__ : {value: ["callback"]},
            __module__ : {value: "widgets"}
        });
        Breadcrumbs.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        Breadcrumbs.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(Breadcrumbs.prototype, "__bases__", {value: []});
        Breadcrumbs.prototype.STYLE_RULES = ρσ_interpolate_kwargs.call(this, build_rule, [".calibre-breadcrumbs"].concat([ρσ_desugar_kwargs({user_select: "none", white_space: "nowrap", background_color: get_color("window-background2"), z_index: "-1", border_radius: "10px", margin: "1ex 1em", margin_bottom: "0"})]));
        Breadcrumbs.prototype.STYLE_RULES += ρσ_interpolate_kwargs.call(this, build_rule, [".calibre-breadcrumbs > li"].concat([ρσ_desugar_kwargs({cursor: "pointer", display: "inline-block", line_height: "26px", margin: "0 9px 0 -10px", padding: "0.5ex 1rem", position: "relative"})]));
        Breadcrumbs.prototype.STYLE_RULES += ρσ_interpolate_kwargs.call(this, build_rule, [".calibre-breadcrumbs > li:hover"].concat([ρσ_desugar_kwargs({color: get_color("window-hover-foreground")})]));
        Breadcrumbs.prototype.STYLE_RULES += ρσ_interpolate_kwargs.call(this, build_rule, [".calibre-breadcrumbs > li:active"].concat([ρσ_desugar_kwargs({color: get_color("window-hover-foreground"), transform: "scale(1.5)"})]));
        Breadcrumbs.prototype.STYLE_RULES += ρσ_interpolate_kwargs.call(this, build_rule, [".calibre-breadcrumbs > li:before, .calibre-breadcrumbs > li:after"].concat([ρσ_desugar_kwargs({border_right: "2px solid currentColor", content: "\"\"", display: "block", height: "50%", position: "absolute", left: "0", top: "0", right: "0", transform: "skewX(45deg)"})]));
        Breadcrumbs.prototype.STYLE_RULES += ρσ_interpolate_kwargs.call(this, build_rule, [".calibre-breadcrumbs > li:after"].concat([ρσ_desugar_kwargs({bottom: "0", top: "auto", transform: "skewX(-45deg)"})]));
        Breadcrumbs.prototype.STYLE_RULES += ρσ_interpolate_kwargs.call(this, build_rule, [".calibre-breadcrumbs > li:last-of-type:before, .calibre-breadcrumbs > li:last-of-type:after"].concat([ρσ_desugar_kwargs({display: "none"})]));
        

        function create_tree(root, populate_data, onclick) {
            var container;
            container = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "simple-tree"})]);
            ρσ_interpolate_kwargs.call(this, set_css, [container].concat([ρσ_desugar_kwargs({overflow: "auto"})]));
            function toggle_node(li) {
                if (li.dataset.treeState === "closed") {
                    li.dataset.treeState = "open";
                    li.lastChild.style.display = "block";
                    change_icon_image(li.firstChild.firstChild, "caret-down");
                } else {
                    li.dataset.treeState = "closed";
                    li.lastChild.style.display = "none";
                    change_icon_image(li.firstChild.firstChild, "caret-right");
                }
            };
            if (!toggle_node.__argnames__) Object.defineProperties(toggle_node, {
                __argnames__ : {value: ["li"]},
                __module__ : {value: "widgets"}
            });

            function bullet(icon) {
                var ans;
                ans = svgicon(icon, "2ex", "2ex");
                ans.style.minWidth = "2ex";
                ans.style.minHeight = "2ex";
                return ans;
            };
            if (!bullet.__argnames__) Object.defineProperties(bullet, {
                __argnames__ : {value: ["icon"]},
                __module__ : {value: "widgets"}
            });

            function process_node(node, parent_container, level) {
                var ul, icon, li, child;
                if (ρσ_exists.d(node.children).length) {
                    ul = E.div();
                    parent_container.appendChild(ul);
                    var ρσ_Iter1 = ρσ_Iterable(node.children);
                    for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                        child = ρσ_Iter1[ρσ_Index1];
                        icon = (ρσ_exists.d(child.children).length) ? "caret-right" : null;
                        li = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [bullet(icon), E.span(" "), ρσ_interpolate_kwargs.call(E, E.a, [ρσ_desugar_kwargs({href: "javascript: void(0)", class_: "tree-item-title", onclick: (function() {
                            var ρσ_anonfunc = function (event) {
                                if (onclick) {
                                    if (event.button === 0) {
                                        [event.preventDefault(), event.stopPropagation()];
                                    }
                                    onclick(event, event.currentTarget.parentNode.parentNode);
                                }
                            };
                            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                __argnames__ : {value: ["event"]},
                                __module__ : {value: "widgets"}
                            });
                            return ρσ_anonfunc;
                        })()})])].concat([ρσ_desugar_kwargs({style: "display:flex; align-items: center"})])), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display:none", data_tree_subtree_container: "1"})])].concat([ρσ_desugar_kwargs({style: "display:flex; flex-direction:column; margin: 1ex 1em; margin-left: {}em".format(level + 1), data_tree_state: "closed"})]));
                        ul.appendChild(li);
                        populate_data(child, li, li.firstChild.lastChild);
                        if (icon) {
                            ρσ_interpolate_kwargs.call(this, set_css, [li.firstChild.firstChild].concat([ρσ_desugar_kwargs({cursor: "pointer"})]));
                            li.firstChild.firstChild.addEventListener("click", (function() {
                                var ρσ_anonfunc = function (event) {
                                    toggle_node(event.currentTarget.parentNode.parentNode);
                                };
                                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                    __argnames__ : {value: ["event"]},
                                    __module__ : {value: "widgets"}
                                });
                                return ρσ_anonfunc;
                            })());
                            process_node(child, li.lastChild, level + 1);
                        }
                    }
                }
            };
            if (!process_node.__argnames__) Object.defineProperties(process_node, {
                __argnames__ : {value: ["node", "parent_container", "level"]},
                __module__ : {value: "widgets"}
            });

            if (root) {
                process_node(root, container, 0);
            }
            return container;
        };
        if (!create_tree.__argnames__) Object.defineProperties(create_tree, {
            __argnames__ : {value: ["root", "populate_data", "onclick"]},
            __module__ : {value: "widgets"}
        });

        function find_text_in_tree(container, q) {
            var last_match, lm, before, seen, ans, a;
            q = q.lower();
            last_match = container.querySelector("a[data-tree-last-match]");
            if (last_match) {
                last_match.parentNode.style.backgroundColor = "transparent";
                last_match.parentNode.style.borderRadius = "0";
                lm = last_match.getAttribute("data-tree-last-match");
                last_match.removeAttribute("data-tree-last-match");
                if (lm !== q) {
                    last_match = null;
                }
            }
            if (!q) {
                return;
            }
            before = ρσ_list_decorate([]);
            seen = false;
            ans = null;
            var ρσ_Iter2 = ρσ_Iterable(container.querySelectorAll("a.tree-item-title"));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                a = ρσ_Iter2[ρσ_Index2];
                if (a === last_match) {
                    seen = true;
                } else {
                    if (ρσ_not_equals(a.textContent.lower().indexOf(q), -1)) {
                        if (seen) {
                            ans = a;
                            break;
                        }
                        if (last_match === null) {
                            ans = a;
                            break;
                        }
                        before.push(a);
                    }
                }
            }
            if (!ans && before.length) {
                ans = before[0];
            }
            ans = ans || last_match;
            if (ans) {
                ans.dataset.treeLastMatch = q;
            }
            if (ans) {
                ans.parentNode.style.backgroundColor = get_color("tree-highlight-item");
                ans.parentNode.style.borderRadius = "5px";
                ans = ans.parentNode.parentNode;
            }
            return ans;
        };
        if (!find_text_in_tree.__argnames__) Object.defineProperties(find_text_in_tree, {
            __argnames__ : {value: ["container", "q"]},
            __module__ : {value: "widgets"}
        });

        function scroll_tree_item_into_view(item) {
            var p;
            p = ρσ_exists.d(item.parentNode).parentNode;
            while (p && p.getAttribute("data-tree-subtree-container")) {
                p.style.display = "block";
                p = ρσ_exists.d(ρσ_exists.d(p.parentNode).parentNode).parentNode;
            }
            item.scrollIntoView();
        };
        if (!scroll_tree_item_into_view.__argnames__) Object.defineProperties(scroll_tree_item_into_view, {
            __argnames__ : {value: ["item"]},
            __module__ : {value: "widgets"}
        });

        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var ans;
                ans = "a, button:focus { outline: none }; a, button::-moz-focus-inner { border: 0 }\n";
                ans += ".simple-link { cursor: pointer } .simple-link:hover { color: HC } .simple-link:active { transform: scale(1.5) }\n".replace("HC", get_color("window-hover-foreground"));
                ans += "\n        a.tree-item-title {\n            color: currentColor;\n            cursor: pointer;\n            text-decoration: none;\n            &:hover, &:active {\n                color: var(--calibre-color-primary);\n                text-decoration: none;\n            }\n        }\n    ";
                ans += ".blue-link { cursor: pointer; color: var(--calibre-color-primary) } .blue-link:visited { color: var(--calibre-color-primary)} .blue-link:hover { color: var(--calibre-color-primary) } .blue-link:active { transform: scale(1.5) }\n";
                ans += create_button.style + "\n";
                ans += create_pager_widget.style + "\n";
                ans += create_spinner.style + "\n";
                ans += Breadcrumbs.prototype.STYLE_RULES + "\n";
                ans += create_select.style + "\n";
                ans += "\n        select, textarea, input[type=\"text\"], input[type=\"password\"],\n        input[type=\"datetime\"], input[type=\"datetime-local\"],\n        input[type=\"date\"], input[type=\"month\"], input[type=\"time\"],\n        input[type=\"week\"], input[type=\"number\"], input[type=\"email\"],\n        input[type=\"url\"], input[type=\"search\"] { font-size: 1em }\n    ";
                return ans;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "widgets"}
            });
            return ρσ_anonfunc;
        })());
        function enable_escape_key(container, action) {
            container.setAttribute("tabindex", "0");
            container.addEventListener("keydown", (function() {
                var ρσ_anonfunc = function (ev) {
                    if (ev.key === "Escape") {
                        [ev.stopPropagation(), ev.preventDefault()];
                        action();
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "widgets"}
                });
                return ρσ_anonfunc;
            })(), (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.focus();
        };
        if (!enable_escape_key.__argnames__) Object.defineProperties(enable_escape_key, {
            __argnames__ : {value: ["container", "action"]},
            __module__ : {value: "widgets"}
        });

        ρσ_modules.widgets.create_button = create_button;
        ρσ_modules.widgets.create_pager_widget = create_pager_widget;
        ρσ_modules.widgets.create_search_widget = create_search_widget;
        ρσ_modules.widgets.create_select = create_select;
        ρσ_modules.widgets.create_spinner = create_spinner;
        ρσ_modules.widgets.Breadcrumbs = Breadcrumbs;
        ρσ_modules.widgets.create_tree = create_tree;
        ρσ_modules.widgets.find_text_in_tree = find_text_in_tree;
        ρσ_modules.widgets.scroll_tree_item_into_view = scroll_tree_item_into_view;
        ρσ_modules.widgets.enable_escape_key = enable_escape_key;
    })();

    (function(){
        var __name__ = "modals";
        var modal_container, modal_count;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var ajax = ρσ_modules.ajax.ajax;
        var ajax_send = ρσ_modules.ajax.ajax_send;

        var get_color = ρσ_modules["book_list.theme"].get_color;
        var get_font_size = ρσ_modules["book_list.theme"].get_font_size;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var set_css = ρσ_modules.dom.set_css;
        var svgicon = ρσ_modules.dom.svgicon;
        var unique_id = ρσ_modules.dom.unique_id;

        var MODAL_Z_INDEX = ρσ_modules.popups.MODAL_Z_INDEX;

        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;

        var create_button = ρσ_modules.widgets.create_button;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        modal_container = null;
        modal_count = 0;
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var modal_max, style;
                modal_max = "min(48rem, calc(100vw - 2rem))";
                style = ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container > div > a:hover"].concat([ρσ_desugar_kwargs({color: get_color("dialog-foreground") + " !important", background_color: get_color("dialog-background") + " !important"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container"].concat([ρσ_desugar_kwargs({overflow_x: "auto", overflow_y: "auto", overscroll_behavior_x: "none", overscroll_behavior_y: "contain", touch_action: "pan-x pan-y", padding: "max(1rem, env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px)) max(1rem, env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px))", box_sizing: "border-box"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container > div"].concat([ρσ_desugar_kwargs({overflow_x: "visible", overflow_y: "visible", width: "max-content", min_width: "0", max_width: modal_max, box_sizing: "border-box"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [".modal_height_container"].concat([ρσ_desugar_kwargs({min_width: "0", max_width: "100%", overflow_wrap: "anywhere", word_break: "break-word", overflow_x: "auto", overflow_y: "auto", overscroll_behavior_x: "none", touch_action: "pan-x pan-y"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container .modal_height_container pre, #modal-container .modal_height_container code"].concat([ρσ_desugar_kwargs({white_space: "pre-wrap", overflow_wrap: "anywhere", word_break: "break-word"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container .modal_height_container img, #modal-container .modal_height_container iframe"].concat([ρσ_desugar_kwargs({max_width: "100%", height: "auto"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container .modal_height_container table"].concat([ρσ_desugar_kwargs({max_width: "100%", box_sizing: "border-box"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container .modal_height_container th, #modal-container .modal_height_container td"].concat([ρσ_desugar_kwargs({overflow_wrap: "anywhere", word_break: "break-word"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container .modal_height_container input:not([type=\"checkbox\"]):not([type=\"radio\"]):not([type=\"color\"]):not([type=\"file\"])," + "#modal-container .modal_height_container textarea, #modal-container .modal_height_container select"].concat([ρσ_desugar_kwargs({max_width: "100%", box_sizing: "border-box"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container .button-box"].concat([ρσ_desugar_kwargs({display: "flex", justify_content: "space-between", align_items: "stretch", flex_wrap: "wrap", gap: "0.5rem", padding: "1rem 0rem", min_width: "0"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container .button-box > a.calibre-push-button"].concat([ρσ_desugar_kwargs({flex: "1 1 0", min_width: "0", justify_content: "center"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container .button-box > a.calibre-push-button:only-of-type"].concat([ρσ_desugar_kwargs({flex: "0 1 auto", margin_left: "auto"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container .button-box.button-box--wrap-chips"].concat([ρσ_desugar_kwargs({justify_content: "flex-start"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container .button-box.button-box--wrap-chips > a.calibre-push-button"].concat([ρσ_desugar_kwargs({flex: "0 1 auto"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container > div > a:last-child"].concat([ρσ_desugar_kwargs({z_index: "2"})]));
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "modals"}
            });
            return ρσ_anonfunc;
        })());
        function Modal() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            Modal.prototype.__init__.apply(this, arguments);
        }
        Modal.prototype.__init__ = function __init__(create_func, on_close, show_close, onkeydown) {
            var self = this;
            var ρσ_unpack;
            ρσ_unpack = [create_func, on_close, show_close];
            self.create_func = ρσ_unpack[0];
            self.on_close = ρσ_unpack[1];
            self.show_close = ρσ_unpack[2];
            self.onkeydown = onkeydown;
            modal_count += 1;
            self.id = modal_count;
        };
        if (!Modal.prototype.__init__.__argnames__) Object.defineProperties(Modal.prototype.__init__, {
            __argnames__ : {value: ["create_func", "on_close", "show_close", "onkeydown"]},
            __module__ : {value: "modals"}
        });
        Modal.__argnames__ = Modal.prototype.__init__.__argnames__;
        Modal.__handles_kwarg_interpolation__ = Modal.prototype.__init__.__handles_kwarg_interpolation__;
        Modal.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        Modal.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(Modal.prototype, "__bases__", {value: []});

        function ModalContainer() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ModalContainer.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperties(ModalContainer.prototype,  {
            "modal_container": {
                "enumerable": true, 
                "get": function modal_container() {
                    var self = this;
                    return document.getElementById("modal-container");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        ModalContainer.prototype.__init__ = function __init__() {
            var self = this;
            var div, popup_max;
            div = ρσ_interpolate_kwargs.call(E, E.div, [E.div(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "modal_height_container"})]), ρσ_interpolate_kwargs.call(E, E.a, [svgicon("close")].concat([ρσ_desugar_kwargs({title: _("Close"), onclick: self.close_current_modal.bind(self)})])))].concat([ρσ_desugar_kwargs({id: "modal-container", tabindex: "0"})]));
            div.addEventListener("keydown", self.onkeydown.bind(self), (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            document.body.appendChild(div);
            ρσ_interpolate_kwargs.call(this, set_css, [div].concat([ρσ_desugar_kwargs({position: "fixed", top: "0", right: "0", bottom: "0", left: "0", background_color: "rgba(0,0,0,0.5)", backdrop_filter: "blur(2px)", webkit_backdrop_filter: "blur(2px)", z_index: MODAL_Z_INDEX + "", display: "none", user_select: "none", justify_content: "center", align_items: "center", overscroll_behavior_x: "none", overscroll_behavior_y: "contain"})]));
            popup_max = "min(48rem, calc(100vw - 2rem))";
            ρσ_interpolate_kwargs.call(this, set_css, [div.firstChild].concat([ρσ_desugar_kwargs({position: "relative", display: "inline-block", min_width: "min(16rem, calc(100vw - 2rem))", max_width: popup_max, overflow_x: "visible", overflow_y: "visible", box_sizing: "border-box", border_radius: "1em", padding: "1em 2em", margin_right: "1em", margin_left: "1em", background_color: get_color("dialog-background"), color: get_color("dialog-foreground"), background_image: get_color("dialog-background-image"), box_shadow: "0 12px 40px rgba(0,0,0,0.2)", border: "var(--calibre-border-style)"})]));
            ρσ_interpolate_kwargs.call(this, set_css, [div.firstChild.lastChild].concat([ρσ_desugar_kwargs({font_size: "1.5em", line_height: "100%", cursor: "pointer", position: "absolute", right: "-0.5em", top: "-0.5em", width: "1em", height: "1em", background_color: get_color("window-foreground"), color: get_color("window-background"), display: "inline-box", border_radius: "50%", padding: "4px", text_align: "center", box_shadow: "1px 1px 3px black", z_index: "2"})]));
            ρσ_interpolate_kwargs.call(this, set_css, [div.firstChild.firstChild].concat([ρσ_desugar_kwargs({user_select: "text", max_height: "min(60vh, calc(100vh - 6rem))", overflow_x: "auto", overflow_y: "auto", overscroll_behavior_x: "none", padding: "1px", min_width: "0", max_width: "100%"})]));
            self.modals = [];
            self.current_modal = null;
            self.hide = self.close_current_modal.bind(self);
        };
        if (!ModalContainer.prototype.__init__.__module__) Object.defineProperties(ModalContainer.prototype.__init__, {
            __module__ : {value: "modals"}
        });
        ModalContainer.__argnames__ = ModalContainer.prototype.__init__.__argnames__;
        ModalContainer.__handles_kwarg_interpolation__ = ModalContainer.prototype.__init__.__handles_kwarg_interpolation__;
        ModalContainer.prototype.show_modal = function show_modal() {
            var self = this;
            var create_func = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var on_close = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_modal.__defaults__.on_close : arguments[1];
            var show_close = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_modal.__defaults__.show_close : arguments[2];
            var onkeydown = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_modal.__defaults__.onkeydown : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_close")){
                on_close = ρσ_kwargs_obj.on_close;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "show_close")){
                show_close = ρσ_kwargs_obj.show_close;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "onkeydown")){
                onkeydown = ρσ_kwargs_obj.onkeydown;
            }
            var modal_id;
            self.modals.push(new Modal(create_func, on_close, show_close, onkeydown));
            modal_id = (ρσ_expr_temp = self.modals)[ρσ_expr_temp.length-1].id;
            self.update();
            window.setTimeout((function() {
                var ρσ_anonfunc = function () {
                    self.modal_container.focus();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "modals"}
                });
                return ρσ_anonfunc;
            })(), 0);
            return modal_id;
        };
        if (!ModalContainer.prototype.show_modal.__defaults__) Object.defineProperties(ModalContainer.prototype.show_modal, {
            __defaults__ : {value: {on_close:null, show_close:true, onkeydown:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["create_func", "on_close", "show_close", "onkeydown"]},
            __module__ : {value: "modals"}
        });
        ModalContainer.prototype.hide_modal = function hide_modal(modal_id) {
            var self = this;
            var doomed_modal, ρσ_unpack, i, modal;
            if (self.current_modal !== null && self.current_modal.id === modal_id) {
                self.clear_current_modal();
            } else {
                doomed_modal = null;
                var ρσ_Iter0 = ρσ_Iterable(enumerate(self.modals));
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    ρσ_unpack = ρσ_Iter0[ρσ_Index0];
                    i = ρσ_unpack[0];
                    modal = ρσ_unpack[1];
                    if (modal.id === modal_id) {
                        doomed_modal = i;
                        break;
                    }
                }
                if (doomed_modal !== null) {
                    self.modals.splice(doomed_modal, 1);
                }
            }
        };
        if (!ModalContainer.prototype.hide_modal.__argnames__) Object.defineProperties(ModalContainer.prototype.hide_modal, {
            __argnames__ : {value: ["modal_id"]},
            __module__ : {value: "modals"}
        });
        ModalContainer.prototype.update = function update() {
            var self = this;
            var c;
            if (self.current_modal === null && self.modals) {
                self.current_modal = self.modals.shift();
                c = self.modal_container;
                try {
                    self.current_modal.create_func(c.firstChild.firstChild, self.hide);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        self.current_modal = null;
                        throw ρσ_Exception;
                    } 
                }
                if (c.style.display === "none") {
                    c.style.display = "flex";
                }
                c.firstChild.lastChild.style.visibility = (self.current_modal.show_close) ? "visible" : "hidden";
            }
        };
        if (!ModalContainer.prototype.update.__module__) Object.defineProperties(ModalContainer.prototype.update, {
            __module__ : {value: "modals"}
        });
        ModalContainer.prototype.clear_current_modal = function clear_current_modal() {
            var self = this;
            var c;
            self.current_modal = null;
            c = self.modal_container;
            clear(c.firstChild.firstChild);
            if (self.modals.length === 0) {
                ρσ_interpolate_kwargs.call(this, set_css, [c].concat([ρσ_desugar_kwargs({display: "none"})]));
            } else {
                self.update();
            }
        };
        if (!ModalContainer.prototype.clear_current_modal.__module__) Object.defineProperties(ModalContainer.prototype.clear_current_modal, {
            __module__ : {value: "modals"}
        });
        ModalContainer.prototype.close_current_modal = function close_current_modal(event) {
            var self = this;
            if (self.current_modal !== null) {
                if (self.current_modal.on_close !== null && self.current_modal.on_close(event) === true) {
                    return;
                }
                self.clear_current_modal();
            }
        };
        if (!ModalContainer.prototype.close_current_modal.__argnames__) Object.defineProperties(ModalContainer.prototype.close_current_modal, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "modals"}
        });
        ModalContainer.prototype.close_all_modals = function close_all_modals() {
            var self = this;
            while (self.current_modal !== null) {
                self.close_current_modal();
            }
        };
        if (!ModalContainer.prototype.close_all_modals.__module__) Object.defineProperties(ModalContainer.prototype.close_all_modals, {
            __module__ : {value: "modals"}
        });
        ModalContainer.prototype.onkeydown = function onkeydown(event) {
            var self = this;
            if (self.current_modal !== null && self.current_modal.onkeydown) {
                return self.current_modal.onkeydown(event, self.clear_current_modal.bind(self));
            }
            if ((event.key === "Escape" || event.key === "Esc") && !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) {
                [event.preventDefault(), event.stopPropagation()];
                self.close_current_modal(event);
            }
        };
        if (!ModalContainer.prototype.onkeydown.__argnames__) Object.defineProperties(ModalContainer.prototype.onkeydown, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "modals"}
        });
        ModalContainer.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ModalContainer.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ModalContainer.prototype, "__bases__", {value: []});
        

        function create_simple_dialog_markup(title, msg, details, icon, prefix, icon_color, parent) {
            var show_details, is_html_msg, html_container, details_container;
            details = details || "";
            show_details = ρσ_interpolate_kwargs.call(E, E.a, [_("Show details")].concat([ρσ_desugar_kwargs({class_: "blue-link", style: "padding-top:1em; display:inline-block; margin-left: auto"})]));
            show_details.addEventListener("click", (function() {
                var ρσ_anonfunc = function () {
                    show_details.style.display = "none";
                    show_details.nextSibling.style.display = "block";
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "modals"}
                });
                return ρσ_anonfunc;
            })());
            is_html_msg = /<[a-zA-Z]/.test(msg);
            html_container = E.div();
            if (is_html_msg) {
                safe_set_inner_html(html_container, msg);
            }
            details_container = E.span();
            if (/<[a-zA-Z]/.test(details)) {
                safe_set_inner_html(details_container, details);
            } else {
                details_container.textContent = details;
            }
            if (prefix) {
                prefix = ρσ_interpolate_kwargs.call(E, E.span, [" " + prefix + " "].concat([ρσ_desugar_kwargs({style: "white-space:pre; font-variant: small-caps"})]));
            } else {
                prefix = " ";
            }
            parent.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.h2, [ρσ_interpolate_kwargs.call(E, E.span, [svgicon(icon)].concat([ρσ_desugar_kwargs({style: "color:" + ρσ_str.format("{}", icon_color) + ""})])), prefix, title].concat([ρσ_desugar_kwargs({style: "font-weight: bold; font-size: " + get_font_size("title") + "; overflow-wrap:anywhere; word-break:break-word"})])), ρσ_interpolate_kwargs.call(E, E.div, [(is_html_msg) ? html_container : msg].concat([ρσ_desugar_kwargs({style: "padding-top: 1em; margin-top: 1em; border-top: 1px solid currentColor; min-width:0; overflow-wrap:anywhere; word-break:break-word"})])), ρσ_interpolate_kwargs.call(E, E.div, [show_details, ρσ_interpolate_kwargs.call(E, E.div, [details_container].concat([ρσ_desugar_kwargs({style: "display:none; white-space:pre-wrap; font-size: smaller; margin-top: 1em; border-top: solid 1px currentColor; padding-top: 1em"})]))].concat([ρσ_desugar_kwargs({style: "display: " + ((details) ? "block" : "none")})]))].concat([ρσ_desugar_kwargs({style: "max-width:100%; min-width:0; box-sizing:border-box; text-align:left; overflow-wrap:anywhere; word-break:break-word"})])));
        };
        if (!create_simple_dialog_markup.__argnames__) Object.defineProperties(create_simple_dialog_markup, {
            __argnames__ : {value: ["title", "msg", "details", "icon", "prefix", "icon_color", "parent"]},
            __module__ : {value: "modals"}
        });

        function create_simple_dialog() {
            var title = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var msg = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var details = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var icon = ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[3];
            var prefix = ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[4];
            var on_close = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_simple_dialog.__defaults__.on_close : arguments[5];
            var icon_color = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_simple_dialog.__defaults__.icon_color : arguments[6];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_close")){
                on_close = ρσ_kwargs_obj.on_close;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "icon_color")){
                icon_color = ρσ_kwargs_obj.icon_color;
            }
            ρσ_interpolate_kwargs.call(this, show_modal, [create_simple_dialog_markup.bind(null, title, msg, details, icon, prefix, icon_color)].concat([ρσ_desugar_kwargs({on_close: on_close})]));
        };
        if (!create_simple_dialog.__defaults__) Object.defineProperties(create_simple_dialog, {
            __defaults__ : {value: {on_close:null, icon_color:"red"}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title", "msg", "details", "icon", "prefix", "on_close", "icon_color"]},
            __module__ : {value: "modals"}
        });

        function create_custom_dialog() {
            var title = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var content_generator_func = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var on_close = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_custom_dialog.__defaults__.on_close : arguments[2];
            var onkeydown = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_custom_dialog.__defaults__.onkeydown : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_close")){
                on_close = ρσ_kwargs_obj.on_close;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "onkeydown")){
                onkeydown = ρσ_kwargs_obj.onkeydown;
            }
            function create_func(parent, close_modal) {
                var content_div;
                content_div = E.div();
                parent.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.h2, [title].concat([ρσ_desugar_kwargs({style: "font-weight: bold; font-size: " + get_font_size("title") + "; overflow-wrap:anywhere; word-break:break-word"})])), ρσ_interpolate_kwargs.call(E, E.div, [content_div].concat([ρσ_desugar_kwargs({style: "padding-top: 1em; margin-top: 1em; border-top: 1px solid currentColor; min-width:0"})]))].concat([ρσ_desugar_kwargs({style: "max-width:100%; min-width:0; box-sizing:border-box; text-align:left; overflow-wrap:anywhere; word-break:break-word"})])));
                content_generator_func(content_div, close_modal);
            };
            if (!create_func.__argnames__) Object.defineProperties(create_func, {
                __argnames__ : {value: ["parent", "close_modal"]},
                __module__ : {value: "modals"}
            });

            ρσ_interpolate_kwargs.call(this, show_modal, [create_func].concat([ρσ_desugar_kwargs({on_close: on_close, onkeydown: onkeydown})]));
        };
        if (!create_custom_dialog.__defaults__) Object.defineProperties(create_custom_dialog, {
            __defaults__ : {value: {on_close:null, onkeydown:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title", "content_generator_func", "on_close", "onkeydown"]},
            __module__ : {value: "modals"}
        });

        function get_text_dialog() {
            var title = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var callback = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var initial_text = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? get_text_dialog.__defaults__.initial_text : arguments[2];
            var msg = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? get_text_dialog.__defaults__.msg : arguments[3];
            var rows = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? get_text_dialog.__defaults__.rows : arguments[4];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "initial_text")){
                initial_text = ρσ_kwargs_obj.initial_text;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "msg")){
                msg = ρσ_kwargs_obj.msg;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "rows")){
                rows = ρσ_kwargs_obj.rows;
            }
            var called, cid;
            called = Object.create(null);
            cid = unique_id();
            function keyaction(ok, close_modal) {
                var text;
                if (called.done) {
                    return;
                }
                called.done = true;
                text = document.getElementById(cid).value || "";
                if (close_modal) {
                    close_modal();
                }
                callback(ok, text);
            };
            if (!keyaction.__argnames__) Object.defineProperties(keyaction, {
                __argnames__ : {value: ["ok", "close_modal"]},
                __module__ : {value: "modals"}
            });

            function on_keydown(event, close_modal) {
                if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
                    return;
                }
                if (event.key === "Escape" || event.key === "Esc") {
                    [event.preventDefault(), event.stopPropagation()];
                    keyaction(false, close_modal);
                }
            };
            if (!on_keydown.__argnames__) Object.defineProperties(on_keydown, {
                __argnames__ : {value: ["event", "close_modal"]},
                __module__ : {value: "modals"}
            });

            ρσ_interpolate_kwargs.call(this, create_custom_dialog, [title, (function() {
                var ρσ_anonfunc = function (parent, close_modal) {
                    parent.appendChild(E.div(ρσ_interpolate_kwargs.call(E, E.textarea, [initial_text || ""].concat([ρσ_desugar_kwargs({placeholder: msg || "", id: cid, rows: rows + "", style: "width:100%; max-width:100%; min-width:0; box-sizing:border-box; resize:vertical"})])), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Cancel"), "close", keyaction.bind(null, false, close_modal)), ρσ_interpolate_kwargs.call(this, create_button, [_("OK"), "check", keyaction.bind(null, true, close_modal)].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: "button-box"})]))));
                    window.setTimeout((function() {
                        var ρσ_anonfunc = function () {
                            parent.querySelector("textarea").focus();
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "modals"}
                        });
                        return ρσ_anonfunc;
                    })(), 10);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["parent", "close_modal"]},
                    __module__ : {value: "modals"}
                });
                return ρσ_anonfunc;
            })()].concat([ρσ_desugar_kwargs({on_close: keyaction.bind(null, false, null), onkeydown: on_keydown})]));
        };
        if (!get_text_dialog.__defaults__) Object.defineProperties(get_text_dialog, {
            __defaults__ : {value: {initial_text:null, msg:null, rows:12}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title", "callback", "initial_text", "msg", "rows"]},
            __module__ : {value: "modals"}
        });

        function question_dialog() {
            var title = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var msg = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var callback = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var yes_text = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? question_dialog.__defaults__.yes_text : arguments[3];
            var no_text = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? question_dialog.__defaults__.no_text : arguments[4];
            var skip_dialog_name = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? question_dialog.__defaults__.skip_dialog_name : arguments[5];
            var skip_dialog_msg = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? question_dialog.__defaults__.skip_dialog_msg : arguments[6];
            var skip_dialog_skipped_value = (arguments[7] === undefined || ( 7 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? question_dialog.__defaults__.skip_dialog_skipped_value : arguments[7];
            var skip_dialog_skip_precheck = (arguments[8] === undefined || ( 8 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? question_dialog.__defaults__.skip_dialog_skip_precheck : arguments[8];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "yes_text")){
                yes_text = ρσ_kwargs_obj.yes_text;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "no_text")){
                no_text = ρσ_kwargs_obj.no_text;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "skip_dialog_name")){
                skip_dialog_name = ρσ_kwargs_obj.skip_dialog_name;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "skip_dialog_msg")){
                skip_dialog_msg = ρσ_kwargs_obj.skip_dialog_msg;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "skip_dialog_skipped_value")){
                skip_dialog_skipped_value = ρσ_kwargs_obj.skip_dialog_skipped_value;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "skip_dialog_skip_precheck")){
                skip_dialog_skip_precheck = ρσ_kwargs_obj.skip_dialog_skip_precheck;
            }
            var called, skip_box, sd, skipped_dialogs;
            yes_text = yes_text || _("Yes");
            no_text = no_text || _("No");
            called = Object.create(null);
            function keyaction(yes, close_modal) {
                var sd, skipped_dialogs;
                if (called.done) {
                    return;
                }
                called.done = true;
                if (skip_dialog_name) {
                    if (!skip_box.querySelector("input").checked) {
                        sd = get_session_data();
                        skipped_dialogs = Object.assign({}, sd.get("skipped_dialogs", {}));
                        skipped_dialogs[(typeof skip_dialog_name === "number" && skip_dialog_name < 0) ? skipped_dialogs.length + skip_dialog_name : skip_dialog_name] = (new Date).toISOString();
                        sd.set("skipped_dialogs", skipped_dialogs);
                    }
                }
                if (close_modal) {
                    close_modal();
                }
                callback(yes);
            };
            if (!keyaction.__argnames__) Object.defineProperties(keyaction, {
                __argnames__ : {value: ["yes", "close_modal"]},
                __module__ : {value: "modals"}
            });

            function on_keydown(event, close_modal) {
                if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) {
                    return;
                }
                if (event.key === "Escape" || event.key === "Esc") {
                    [event.preventDefault(), event.stopPropagation()];
                    keyaction(false, close_modal);
                }
                if (event.key === "Enter" || event.key === "Return" || event.key === "Space") {
                    [event.preventDefault(), event.stopPropagation()];
                    keyaction(true, close_modal);
                }
            };
            if (!on_keydown.__argnames__) Object.defineProperties(on_keydown, {
                __argnames__ : {value: ["event", "close_modal"]},
                __module__ : {value: "modals"}
            });

            skip_box = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-top: 2ex;"})]);
            if (skip_dialog_name) {
                sd = get_session_data();
                skipped_dialogs = sd.get("skipped_dialogs", {});
                if (skipped_dialogs[(typeof skip_dialog_name === "number" && skip_dialog_name < 0) ? skipped_dialogs.length + skip_dialog_name : skip_dialog_name]) {
                    return callback(skip_dialog_skipped_value);
                }
                skip_dialog_msg = skip_dialog_msg || _("Show this confirmation again");
                skip_box.appendChild(E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox", name: "skip_dialog"})]), " ", skip_dialog_msg));
                if (skip_dialog_skip_precheck) {
                    skip_box.querySelector("input").checked = true;
                }
            } else {
                skip_box.style.display = "none";
            }
            ρσ_interpolate_kwargs.call(this, create_custom_dialog, [title, (function() {
                var ρσ_anonfunc = function (parent, close_modal) {
                    parent.appendChild(E.div(E.div(msg), skip_box, ρσ_interpolate_kwargs.call(E, E.div, [create_button(no_text, "close", keyaction.bind(null, false, close_modal)), ρσ_interpolate_kwargs.call(this, create_button, [yes_text, "check", keyaction.bind(null, true, close_modal)].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: "button-box"})]))));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["parent", "close_modal"]},
                    __module__ : {value: "modals"}
                });
                return ρσ_anonfunc;
            })()].concat([ρσ_desugar_kwargs({on_close: keyaction.bind(null, false, null), onkeydown: on_keydown})]));
        };
        if (!question_dialog.__defaults__) Object.defineProperties(question_dialog, {
            __defaults__ : {value: {yes_text:null, no_text:null, skip_dialog_name:null, skip_dialog_msg:null, skip_dialog_skipped_value:true, skip_dialog_skip_precheck:true}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title", "msg", "callback", "yes_text", "no_text", "skip_dialog_name", "skip_dialog_msg", "skip_dialog_skipped_value", "skip_dialog_skip_precheck"]},
            __module__ : {value: "modals"}
        });

        function create_progress_dialog(msg, on_close) {
            var ρσ_unpack, pbar, msg_div, show_close, modal_id;
            msg = msg || _("Loading, please wait...");
            ρσ_unpack = [ρσ_interpolate_kwargs.call(E, E.progress, [ρσ_desugar_kwargs({style: "display:inline-block"})]), 
            ρσ_interpolate_kwargs.call(E, E.div, [msg].concat([ρσ_desugar_kwargs({style: "text-align:center; padding-top:1ex"})]))];
            pbar = ρσ_unpack[0];
            msg_div = ρσ_unpack[1];
            function create_func(parent) {
                parent.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [pbar, msg_div].concat([ρσ_desugar_kwargs({style: "text-align: center; max-width:100%; min-width:0; box-sizing:border-box"})])));
            };
            if (!create_func.__argnames__) Object.defineProperties(create_func, {
                __argnames__ : {value: ["parent"]},
                __module__ : {value: "modals"}
            });

            show_close = on_close !== null;
            modal_id = show_modal(create_func, on_close, show_close);
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["close"] = (function() {
                    var ρσ_anonfunc = function () {
                        modal_container.hide_modal(modal_id);
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "modals"}
                    });
                    return ρσ_anonfunc;
                })();
                ρσ_d["update_progress"] = (function() {
                    var ρσ_anonfunc = function (amount, total) {
                        var ρσ_unpack;
                        ρσ_unpack = [total, amount];
                        pbar.max = ρσ_unpack[0];
                        pbar.value = ρσ_unpack[1];
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["amount", "total"]},
                        __module__ : {value: "modals"}
                    });
                    return ρσ_anonfunc;
                })();
                ρσ_d["set_msg"] = (function() {
                    var ρσ_anonfunc = function (new_msg) {
                        safe_set_inner_html(msg_div, new_msg);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["new_msg"]},
                        __module__ : {value: "modals"}
                    });
                    return ρσ_anonfunc;
                })();
                return ρσ_d;
            }).call(this);
        };
        if (!create_progress_dialog.__argnames__) Object.defineProperties(create_progress_dialog, {
            __argnames__ : {value: ["msg", "on_close"]},
            __module__ : {value: "modals"}
        });

        function create_modal_container() {
            if (modal_container === null) {
                modal_container = new ModalContainer;
            }
            return modal_container;
        };
        if (!create_modal_container.__module__) Object.defineProperties(create_modal_container, {
            __module__ : {value: "modals"}
        });

        function show_modal() {
            var create_func = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var on_close = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_modal.__defaults__.on_close : arguments[1];
            var show_close = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_modal.__defaults__.show_close : arguments[2];
            var onkeydown = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_modal.__defaults__.onkeydown : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_close")){
                on_close = ρσ_kwargs_obj.on_close;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "show_close")){
                show_close = ρσ_kwargs_obj.show_close;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "onkeydown")){
                onkeydown = ρσ_kwargs_obj.onkeydown;
            }
            return modal_container.show_modal(create_func, on_close, show_close, onkeydown);
        };
        if (!show_modal.__defaults__) Object.defineProperties(show_modal, {
            __defaults__ : {value: {on_close:null, show_close:true, onkeydown:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["create_func", "on_close", "show_close", "onkeydown"]},
            __module__ : {value: "modals"}
        });

        function close_all_modals() {
            return modal_container.close_all_modals();
        };
        if (!close_all_modals.__module__) Object.defineProperties(close_all_modals, {
            __module__ : {value: "modals"}
        });

        function error_dialog() {
            var title = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var msg = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var details = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? error_dialog.__defaults__.details : arguments[2];
            var on_close = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? error_dialog.__defaults__.on_close : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "details")){
                details = ρσ_kwargs_obj.details;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_close")){
                on_close = ρσ_kwargs_obj.on_close;
            }
            create_simple_dialog(title, msg, details, "bug", _("Error:"), on_close);
        };
        if (!error_dialog.__defaults__) Object.defineProperties(error_dialog, {
            __defaults__ : {value: {details:null, on_close:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title", "msg", "details", "on_close"]},
            __module__ : {value: "modals"}
        });

        function warning_dialog() {
            var title = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var msg = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var details = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? warning_dialog.__defaults__.details : arguments[2];
            var on_close = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? warning_dialog.__defaults__.on_close : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "details")){
                details = ρσ_kwargs_obj.details;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_close")){
                on_close = ρσ_kwargs_obj.on_close;
            }
            create_simple_dialog(title, msg, details, "warning", _("Warning:"), on_close);
        };
        if (!warning_dialog.__defaults__) Object.defineProperties(warning_dialog, {
            __defaults__ : {value: {details:null, on_close:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title", "msg", "details", "on_close"]},
            __module__ : {value: "modals"}
        });

        function info_dialog() {
            var title = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var msg = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var details = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? info_dialog.__defaults__.details : arguments[2];
            var on_close = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? info_dialog.__defaults__.on_close : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "details")){
                details = ρσ_kwargs_obj.details;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_close")){
                on_close = ρσ_kwargs_obj.on_close;
            }
            ρσ_interpolate_kwargs.call(this, create_simple_dialog, [title, msg, details, "check", "", on_close].concat([ρσ_desugar_kwargs({icon_color: "green"})]));
        };
        if (!info_dialog.__defaults__) Object.defineProperties(info_dialog, {
            __defaults__ : {value: {details:null, on_close:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title", "msg", "details", "on_close"]},
            __module__ : {value: "modals"}
        });

        function progress_dialog() {
            var msg = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var on_close = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? progress_dialog.__defaults__.on_close : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_close")){
                on_close = ρσ_kwargs_obj.on_close;
            }
            return create_progress_dialog(msg, on_close);
        };
        if (!progress_dialog.__defaults__) Object.defineProperties(progress_dialog, {
            __defaults__ : {value: {on_close:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["msg", "on_close"]},
            __module__ : {value: "modals"}
        });

        function ajax_progress_dialog() {
            var path = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var on_complete = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var msg = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var extra_data_for_callback = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ajax_progress_dialog.__defaults__.extra_data_for_callback : arguments[3];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            if (Object.prototype.hasOwnProperty.call(kw, "extra_data_for_callback")){
                extra_data_for_callback = kw.extra_data_for_callback;
                delete kw.extra_data_for_callback;
            }
            var pd, xhr;
            pd = null;
            function on_complete_callback(event_type, xhr, ev) {
                pd.close();
                pd = undefined;
                return on_complete(event_type, xhr, ev);
            };
            if (!on_complete_callback.__argnames__) Object.defineProperties(on_complete_callback, {
                __argnames__ : {value: ["event_type", "xhr", "ev"]},
                __module__ : {value: "modals"}
            });

            function on_progress_callback(loaded, total, xhr) {
                pd.update_progress(loaded, total);
            };
            if (!on_progress_callback.__argnames__) Object.defineProperties(on_progress_callback, {
                __argnames__ : {value: ["loaded", "total", "xhr"]},
                __module__ : {value: "modals"}
            });

            xhr = ρσ_interpolate_kwargs.call(this, ajax, [path, on_complete_callback].concat([ρσ_desugar_kwargs(kw, {on_progress: on_progress_callback})]));
            xhr.extra_data_for_callback = extra_data_for_callback;
            pd = progress_dialog(msg, xhr.abort.bind(xhr));
            xhr.send();
            return [xhr, pd];
        };
        if (!ajax_progress_dialog.__defaults__) Object.defineProperties(ajax_progress_dialog, {
            __defaults__ : {value: {extra_data_for_callback:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["path", "on_complete", "msg", "extra_data_for_callback"]},
            __module__ : {value: "modals"}
        });

        function ajax_send_progress_dialog() {
            var path = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var data = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var on_complete = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var msg = ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[3];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            var pd, xhr;
            pd = null;
            function on_complete_callback(event_type, xhr, ev) {
                pd.close();
                pd = undefined;
                return on_complete(event_type, xhr, ev);
            };
            if (!on_complete_callback.__argnames__) Object.defineProperties(on_complete_callback, {
                __argnames__ : {value: ["event_type", "xhr", "ev"]},
                __module__ : {value: "modals"}
            });

            function on_progress_callback(loaded, total, xhr) {
                pd.update_progress(loaded, total);
            };
            if (!on_progress_callback.__argnames__) Object.defineProperties(on_progress_callback, {
                __argnames__ : {value: ["loaded", "total", "xhr"]},
                __module__ : {value: "modals"}
            });

            xhr = ρσ_interpolate_kwargs.call(this, ajax_send, [path, data, on_complete_callback].concat([ρσ_desugar_kwargs(kw, {on_progress: on_progress_callback})]));
            pd = progress_dialog(msg, xhr.abort.bind(xhr));
            return [xhr, pd];
        };
        if (!ajax_send_progress_dialog.__handles_kwarg_interpolation__) Object.defineProperties(ajax_send_progress_dialog, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["path", "data", "on_complete", "msg"]},
            __module__ : {value: "modals"}
        });

        ρσ_modules.modals.modal_container = modal_container;
        ρσ_modules.modals.modal_count = modal_count;
        ρσ_modules.modals.Modal = Modal;
        ρσ_modules.modals.ModalContainer = ModalContainer;
        ρσ_modules.modals.create_simple_dialog_markup = create_simple_dialog_markup;
        ρσ_modules.modals.create_simple_dialog = create_simple_dialog;
        ρσ_modules.modals.create_custom_dialog = create_custom_dialog;
        ρσ_modules.modals.get_text_dialog = get_text_dialog;
        ρσ_modules.modals.question_dialog = question_dialog;
        ρσ_modules.modals.create_progress_dialog = create_progress_dialog;
        ρσ_modules.modals.create_modal_container = create_modal_container;
        ρσ_modules.modals.show_modal = show_modal;
        ρσ_modules.modals.close_all_modals = close_all_modals;
        ρσ_modules.modals.error_dialog = error_dialog;
        ρσ_modules.modals.warning_dialog = warning_dialog;
        ρσ_modules.modals.info_dialog = info_dialog;
        ρσ_modules.modals.progress_dialog = progress_dialog;
        ρσ_modules.modals.ajax_progress_dialog = ajax_progress_dialog;
        ρσ_modules.modals.ajax_send_progress_dialog = ajax_send_progress_dialog;
    })();

    (function(){
        var __name__ = "qt";
        var special_title, slots, to_python;
        special_title = "__webengine_messages_pending__";
        slots = Object.create(null);
        function ping(suffix) {
            document.title = special_title + suffix;
        };
        if (!ping.__argnames__) Object.defineProperties(ping, {
            __argnames__ : {value: ["suffix"]},
            __module__ : {value: "qt"}
        });

        function signal() {
            var args;
            args = Array.from(arguments);
            to_python._queue_message((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "signal";
                ρσ_d["name"] = this;
                ρσ_d["args"] = args;
                return ρσ_d;
            }).call(this));
        };
        if (!signal.__module__) Object.defineProperties(signal, {
            __module__ : {value: "qt"}
        });

        function ToPython() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ToPython.prototype.__bind_methods__.call(this);
            ToPython.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ToPython.prototype, "__bind_methods__", {value: function () {
            this._ping = ToPython.prototype._ping.bind(this);
            this._queue_message = ToPython.prototype._queue_message.bind(this);
            this._register_signals = ToPython.prototype._register_signals.bind(this);
            this._poll = ToPython.prototype._poll.bind(this);
            this._from_python = ToPython.prototype._from_python.bind(this);
        }});
        ToPython.prototype.__init__ = function __init__() {
            var self = this;
            self._messages = [];
            self._last_ping_value = 0;
            self._ping_timer_id = -1;
            self._queue_message((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "qt-ready";
                return ρσ_d;
            }).call(this));
        };
        if (!ToPython.prototype.__init__.__module__) Object.defineProperties(ToPython.prototype.__init__, {
            __module__ : {value: "qt"}
        });
        ToPython.__argnames__ = ToPython.prototype.__init__.__argnames__;
        ToPython.__handles_kwarg_interpolation__ = ToPython.prototype.__init__.__handles_kwarg_interpolation__;
        ToPython.prototype._ping = function _ping() {
            var self = this;
            if (self._ping_timer_id < 0) {
                self._last_ping_value = (self._last_ping_value) ? 0 : 1;
                self._ping_timer_id = setTimeout((function() {
                    var ρσ_anonfunc = function () {
                        ping(self._last_ping_value);
                        self._ping_timer_id = -1;
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "qt"}
                    });
                    return ρσ_anonfunc;
                })(), 0);
            }
        };
        if (!ToPython.prototype._ping.__module__) Object.defineProperties(ToPython.prototype._ping, {
            __module__ : {value: "qt"}
        });
        ToPython.prototype._queue_message = function _queue_message(msg) {
            var self = this;
            self._messages.push(msg);
            self._ping();
        };
        if (!ToPython.prototype._queue_message.__argnames__) Object.defineProperties(ToPython.prototype._queue_message, {
            __argnames__ : {value: ["msg"]},
            __module__ : {value: "qt"}
        });
        ToPython.prototype._register_signals = function _register_signals(signals) {
            var self = this;
            var signal_name;
            var ρσ_Iter0 = ρσ_Iterable(signals);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                signal_name = ρσ_Iter0[ρσ_Index0];
                self[(typeof signal_name === "number" && signal_name < 0) ? self.length + signal_name : signal_name] = signal.bind(signal_name);
            }
        };
        if (!ToPython.prototype._register_signals.__argnames__) Object.defineProperties(ToPython.prototype._register_signals, {
            __argnames__ : {value: ["signals"]},
            __module__ : {value: "qt"}
        });
        ToPython.prototype._poll = function _poll() {
            var self = this;
            var ans;
            ans = self._messages;
            self._messages = [];
            return ans;
        };
        if (!ToPython.prototype._poll.__module__) Object.defineProperties(ToPython.prototype._poll, {
            __module__ : {value: "qt"}
        });
        ToPython.prototype._from_python = function _from_python(name, args) {
            var self = this;
            var callback;
            callback = slots[(typeof name === "number" && name < 0) ? slots.length + name : name];
            if (callback) {
                callback.apply(null, args);
            } else {
                console.warn("Attempt to call non-existent python-to-js slot named: " + ρσ_str.format("{}", name) + "");
            }
        };
        if (!ToPython.prototype._from_python.__argnames__) Object.defineProperties(ToPython.prototype._from_python, {
            __argnames__ : {value: ["name", "args"]},
            __module__ : {value: "qt"}
        });
        ToPython.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ToPython.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ToPython.prototype, "__bases__", {value: []});

        to_python = null;
        if (window === window.top) {
            window.python_comm = to_python = new ToPython;
        }
        function from_python(func) {
            slots[ρσ_bound_index(func.name, slots)] = func;
        };
        if (!from_python.__argnames__) Object.defineProperties(from_python, {
            __argnames__ : {value: ["func"]},
            __module__ : {value: "qt"}
        });

        ρσ_modules.qt.special_title = special_title;
        ρσ_modules.qt.slots = slots;
        ρσ_modules.qt.to_python = to_python;
        ρσ_modules.qt.ping = ping;
        ρσ_modules.qt.signal = signal;
        ρσ_modules.qt.ToPython = ToPython;
        ρσ_modules.qt.from_python = from_python;
    })();

    (function(){
        var __name__ = "read_book";

    })();

    (function(){
        var __name__ = "book_list.constants";
        var book_list_container_id, read_book_container_id, cs_top_bar_host_id, INIT_ENDPOINT;
        book_list_container_id = "book-list-container";
        read_book_container_id = "read-book-container";
        cs_top_bar_host_id = "cs-top-bar-host";
        INIT_ENDPOINT = "interface-data/init";
        ρσ_modules["book_list.constants"].book_list_container_id = book_list_container_id;
        ρσ_modules["book_list.constants"].read_book_container_id = read_book_container_id;
        ρσ_modules["book_list.constants"].cs_top_bar_host_id = cs_top_bar_host_id;
        ρσ_modules["book_list.constants"].INIT_ENDPOINT = INIT_ENDPOINT;
    })();

    (function(){
        var __name__ = "aes";
        var string_to_bytes, bytes_to_string, number_of_rounds, rcon, S, Si, T1, T2, T3, T4, T5, T6, T7, T8, U1, U2, U3, U4, random_bytes, noderandom;
        function string_to_bytes_encoder(string) {
            return new TextEncoder("utf-8").encode(string + "");
        };
        if (!string_to_bytes_encoder.__argnames__) Object.defineProperties(string_to_bytes_encoder, {
            __argnames__ : {value: ["string"]},
            __module__ : {value: "aes"}
        });

        function string_to_bytes_slow(string) {
            var escstr, binstr, ua, ρσ_unpack, i, ch;
            escstr = encodeURIComponent(string);
            binstr = escstr.replace(/%([0-9A-F]{2})/g, (function() {
                var ρσ_anonfunc = function (match, p1) {
                    return String.fromCharCode("0x" + p1);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["match", "p1"]},
                    __module__ : {value: "aes"}
                });
                return ρσ_anonfunc;
            })());
            ua = new Uint8Array(binstr.length);
            var ρσ_Iter0 = ρσ_Iterable(enumerate(binstr));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                ρσ_unpack = ρσ_Iter0[ρσ_Index0];
                i = ρσ_unpack[0];
                ch = ρσ_unpack[1];
                ua[(typeof i === "number" && i < 0) ? ua.length + i : i] = ch.charCodeAt(0);
            }
            return ua;
        };
        if (!string_to_bytes_slow.__argnames__) Object.defineProperties(string_to_bytes_slow, {
            __argnames__ : {value: ["string"]},
            __module__ : {value: "aes"}
        });

        function as_hex() {
            var array = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var sep = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? as_hex.__defaults__.sep : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "sep")){
                sep = ρσ_kwargs_obj.sep;
            }
            var num, fmt;
            num = array.BYTES_PER_ELEMENT || 1;
            fmt = "{:0" + num * 2 + "x}";
            return (function() {
                var ρσ_Iter = ρσ_Iterable(array), ρσ_Result = [], x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    ρσ_Result.push(str.format(fmt, x));
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })().join(sep);
        };
        if (!as_hex.__defaults__) Object.defineProperties(as_hex, {
            __defaults__ : {value: {sep:""}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["array", "sep"]},
            __module__ : {value: "aes"}
        });

        function bytes_to_string_decoder(bytes, offset) {
            offset = offset || 0;
            if (offset) {
                bytes = bytes.subarray(offset);
            }
            return new TextDecoder("utf-8").decode(bytes);
        };
        if (!bytes_to_string_decoder.__argnames__) Object.defineProperties(bytes_to_string_decoder, {
            __argnames__ : {value: ["bytes", "offset"]},
            __module__ : {value: "aes"}
        });

        function bytes_to_string_slow(bytes, offset) {
            var ans, i, c;
            ans = [];
            i = offset || 0;
            while (i < bytes.length) {
                c = bytes[(typeof i === "number" && i < 0) ? bytes.length + i : i];
                if (c < 128) {
                    ans.push(String.fromCharCode(c));
                    i += 1;
                } else if (191 < c && c < 224) {
                    ans.push(String.fromCharCode((c & 31) << 6 | bytes[ρσ_bound_index(i + 1, bytes)] & 63));
                    i += 2;
                } else {
                    ans.push(String.fromCharCode((c & 15) << 12 | (bytes[ρσ_bound_index(i + 1, bytes)] & 63) << 6 | bytes[ρσ_bound_index(i + 2, bytes)] & 63));
                    i += 3;
                }
            }
            return ans.join("");
        };
        if (!bytes_to_string_slow.__argnames__) Object.defineProperties(bytes_to_string_slow, {
            __argnames__ : {value: ["bytes", "offset"]},
            __module__ : {value: "aes"}
        });

        string_to_bytes = (typeof TextEncoder === "function") ? string_to_bytes_encoder : string_to_bytes_slow;
        bytes_to_string = (typeof TextDecoder === "function") ? bytes_to_string_decoder : bytes_to_string_slow;
        function increment_counter(c) {
            for (var i = 15; i >= 12; i--) {
                if (c[(typeof i === "number" && i < 0) ? c.length + i : i] === 255) {
                    c[(typeof i === "number" && i < 0) ? c.length + i : i] = 0;
                } else {
                    c[(typeof i === "number" && i < 0) ? c.length + i : i] += 1;
                    break;
                }
            }
        };
        if (!increment_counter.__argnames__) Object.defineProperties(increment_counter, {
            __argnames__ : {value: ["c"]},
            __module__ : {value: "aes"}
        });

        function convert_to_int32(bytes, output, offset, length) {
            offset = offset || 0;
            length = length || bytes.length;
            for (var i = offset, j = 0; i < offset + length; i += 4, j++) {
                output[(typeof j === "number" && j < 0) ? output.length + j : j] = bytes[(typeof i === "number" && i < 0) ? bytes.length + i : i] << 24 | bytes[ρσ_bound_index(i + 1, bytes)] << 16 | bytes[ρσ_bound_index(i + 2, bytes)] << 8 | bytes[ρσ_bound_index(i + 3, bytes)];
            }
        };
        if (!convert_to_int32.__argnames__) Object.defineProperties(convert_to_int32, {
            __argnames__ : {value: ["bytes", "output", "offset", "length"]},
            __module__ : {value: "aes"}
        });

        function convert_to_int32_pad(bytes) {
            var extra, t, ans;
            extra = bytes.length % 4;
            if (extra) {
                t = new Uint8Array(bytes.length + 4 - extra);
                t.set(bytes);
                bytes = t;
            }
            ans = new Uint32Array(bytes.length / 4);
            convert_to_int32(bytes, ans);
            return ans;
        };
        if (!convert_to_int32_pad.__argnames__) Object.defineProperties(convert_to_int32_pad, {
            __argnames__ : {value: ["bytes"]},
            __module__ : {value: "aes"}
        });

        if (!Uint8Array.prototype.fill) {
            Uint8Array.prototype.fill = Uint32Array.prototype.fill = (function() {
                var ρσ_anonfunc = function (val, start, end) {
                    start = start || 0;
                    if (end === undefined) {
                        end = this.length;
                    }
                    if (start < 0) {
                        start += this.length;
                    }
                    if (end < 0) {
                        end += this.length;
                    }
                    for (var i = start; i < end; i++) {
                        (ρσ_expr_temp = this)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] = val;
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["val", "start", "end"]},
                    __module__ : {value: "aes"}
                });
                return ρσ_anonfunc;
            })();
        }
        function from_64_to_32(num) {
            var ans;
            ans = new Uint32Array(2);
            ans[0] = num / 4294967296 | 0;
            ans[1] = num & 4294967295;
            return ans;
        };
        if (!from_64_to_32.__argnames__) Object.defineProperties(from_64_to_32, {
            __argnames__ : {value: ["num"]},
            __module__ : {value: "aes"}
        });

        number_of_rounds = (function(){
            var ρσ_d = {};
            ρσ_d[16] = 10;
            ρσ_d[24] = 12;
            ρσ_d[32] = 14;
            return ρσ_d;
        }).call(this);
        rcon = new Uint32Array([0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91]);
        S = new Uint32Array([0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16]);
        Si = new Uint32Array([0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d]);
        T1 = new Uint32Array([0xc66363a5, 0xf87c7c84, 0xee777799, 0xf67b7b8d, 0xfff2f20d, 0xd66b6bbd, 0xde6f6fb1, 0x91c5c554, 0x60303050, 0x02010103, 0xce6767a9, 0x562b2b7d, 0xe7fefe19, 0xb5d7d762, 0x4dababe6, 0xec76769a, 0x8fcaca45, 0x1f82829d, 0x89c9c940, 0xfa7d7d87, 0xeffafa15, 0xb25959eb, 0x8e4747c9, 0xfbf0f00b, 0x41adadec, 0xb3d4d467, 0x5fa2a2fd, 0x45afafea, 0x239c9cbf, 0x53a4a4f7, 0xe4727296, 0x9bc0c05b, 0x75b7b7c2, 0xe1fdfd1c, 0x3d9393ae, 0x4c26266a, 0x6c36365a, 0x7e3f3f41, 0xf5f7f702, 0x83cccc4f, 0x6834345c, 0x51a5a5f4, 0xd1e5e534, 0xf9f1f108, 0xe2717193, 0xabd8d873, 0x62313153, 0x2a15153f, 0x0804040c, 0x95c7c752, 0x46232365, 0x9dc3c35e, 0x30181828, 0x379696a1, 0x0a05050f, 0x2f9a9ab5, 0x0e070709, 0x24121236, 0x1b80809b, 0xdfe2e23d, 0xcdebeb26, 0x4e272769, 0x7fb2b2cd, 0xea75759f, 0x1209091b, 0x1d83839e, 0x582c2c74, 0x341a1a2e, 0x361b1b2d, 0xdc6e6eb2, 0xb45a5aee, 0x5ba0a0fb, 0xa45252f6, 0x763b3b4d, 0xb7d6d661, 0x7db3b3ce, 0x5229297b, 0xdde3e33e, 0x5e2f2f71, 0x13848497, 0xa65353f5, 0xb9d1d168, 0x00000000, 0xc1eded2c, 0x40202060, 0xe3fcfc1f, 0x79b1b1c8, 0xb65b5bed, 0xd46a6abe, 0x8dcbcb46, 0x67bebed9, 0x7239394b, 0x944a4ade, 0x984c4cd4, 0xb05858e8, 0x85cfcf4a, 0xbbd0d06b, 0xc5efef2a, 0x4faaaae5, 0xedfbfb16, 0x864343c5, 0x9a4d4dd7, 0x66333355, 0x11858594, 0x8a4545cf, 0xe9f9f910, 0x04020206, 0xfe7f7f81, 0xa05050f0, 0x783c3c44, 0x259f9fba, 0x4ba8a8e3, 0xa25151f3, 0x5da3a3fe, 0x804040c0, 0x058f8f8a, 0x3f9292ad, 0x219d9dbc, 0x70383848, 0xf1f5f504, 0x63bcbcdf, 0x77b6b6c1, 0xafdada75, 0x42212163, 0x20101030, 0xe5ffff1a, 0xfdf3f30e, 0xbfd2d26d, 0x81cdcd4c, 0x180c0c14, 0x26131335, 0xc3ecec2f, 0xbe5f5fe1, 0x359797a2, 0x884444cc, 0x2e171739, 0x93c4c457, 0x55a7a7f2, 0xfc7e7e82, 0x7a3d3d47, 0xc86464ac, 0xba5d5de7, 0x3219192b, 0xe6737395, 0xc06060a0, 0x19818198, 0x9e4f4fd1, 0xa3dcdc7f, 0x44222266, 0x542a2a7e, 0x3b9090ab, 0x0b888883, 0x8c4646ca, 0xc7eeee29, 0x6bb8b8d3, 0x2814143c, 0xa7dede79, 0xbc5e5ee2, 0x160b0b1d, 0xaddbdb76, 0xdbe0e03b, 0x64323256, 0x743a3a4e, 0x140a0a1e, 0x924949db, 0x0c06060a, 0x4824246c, 0xb85c5ce4, 0x9fc2c25d, 0xbdd3d36e, 0x43acacef, 0xc46262a6, 0x399191a8, 0x319595a4, 0xd3e4e437, 0xf279798b, 0xd5e7e732, 0x8bc8c843, 0x6e373759, 0xda6d6db7, 0x018d8d8c, 0xb1d5d564, 0x9c4e4ed2, 0x49a9a9e0, 0xd86c6cb4, 0xac5656fa, 0xf3f4f407, 0xcfeaea25, 0xca6565af, 0xf47a7a8e, 0x47aeaee9, 0x10080818, 0x6fbabad5, 0xf0787888, 0x4a25256f, 0x5c2e2e72, 0x381c1c24, 0x57a6a6f1, 0x73b4b4c7, 0x97c6c651, 0xcbe8e823, 0xa1dddd7c, 0xe874749c, 0x3e1f1f21, 0x964b4bdd, 0x61bdbddc, 0x0d8b8b86, 0x0f8a8a85, 0xe0707090, 0x7c3e3e42, 0x71b5b5c4, 0xcc6666aa, 0x904848d8, 0x06030305, 0xf7f6f601, 0x1c0e0e12, 0xc26161a3, 0x6a35355f, 0xae5757f9, 0x69b9b9d0, 0x17868691, 0x99c1c158, 0x3a1d1d27, 0x279e9eb9, 0xd9e1e138, 0xebf8f813, 0x2b9898b3, 0x22111133, 0xd26969bb, 0xa9d9d970, 0x078e8e89, 0x339494a7, 0x2d9b9bb6, 0x3c1e1e22, 0x15878792, 0xc9e9e920, 0x87cece49, 0xaa5555ff, 0x50282878, 0xa5dfdf7a, 0x038c8c8f, 0x59a1a1f8, 0x09898980, 0x1a0d0d17, 0x65bfbfda, 0xd7e6e631, 0x844242c6, 0xd06868b8, 0x824141c3, 0x299999b0, 0x5a2d2d77, 0x1e0f0f11, 0x7bb0b0cb, 0xa85454fc, 0x6dbbbbd6, 0x2c16163a]);
        T2 = new Uint32Array([0xa5c66363, 0x84f87c7c, 0x99ee7777, 0x8df67b7b, 0x0dfff2f2, 0xbdd66b6b, 0xb1de6f6f, 0x5491c5c5, 0x50603030, 0x03020101, 0xa9ce6767, 0x7d562b2b, 0x19e7fefe, 0x62b5d7d7, 0xe64dabab, 0x9aec7676, 0x458fcaca, 0x9d1f8282, 0x4089c9c9, 0x87fa7d7d, 0x15effafa, 0xebb25959, 0xc98e4747, 0x0bfbf0f0, 0xec41adad, 0x67b3d4d4, 0xfd5fa2a2, 0xea45afaf, 0xbf239c9c, 0xf753a4a4, 0x96e47272, 0x5b9bc0c0, 0xc275b7b7, 0x1ce1fdfd, 0xae3d9393, 0x6a4c2626, 0x5a6c3636, 0x417e3f3f, 0x02f5f7f7, 0x4f83cccc, 0x5c683434, 0xf451a5a5, 0x34d1e5e5, 0x08f9f1f1, 0x93e27171, 0x73abd8d8, 0x53623131, 0x3f2a1515, 0x0c080404, 0x5295c7c7, 0x65462323, 0x5e9dc3c3, 0x28301818, 0xa1379696, 0x0f0a0505, 0xb52f9a9a, 0x090e0707, 0x36241212, 0x9b1b8080, 0x3ddfe2e2, 0x26cdebeb, 0x694e2727, 0xcd7fb2b2, 0x9fea7575, 0x1b120909, 0x9e1d8383, 0x74582c2c, 0x2e341a1a, 0x2d361b1b, 0xb2dc6e6e, 0xeeb45a5a, 0xfb5ba0a0, 0xf6a45252, 0x4d763b3b, 0x61b7d6d6, 0xce7db3b3, 0x7b522929, 0x3edde3e3, 0x715e2f2f, 0x97138484, 0xf5a65353, 0x68b9d1d1, 0x00000000, 0x2cc1eded, 0x60402020, 0x1fe3fcfc, 0xc879b1b1, 0xedb65b5b, 0xbed46a6a, 0x468dcbcb, 0xd967bebe, 0x4b723939, 0xde944a4a, 0xd4984c4c, 0xe8b05858, 0x4a85cfcf, 0x6bbbd0d0, 0x2ac5efef, 0xe54faaaa, 0x16edfbfb, 0xc5864343, 0xd79a4d4d, 0x55663333, 0x94118585, 0xcf8a4545, 0x10e9f9f9, 0x06040202, 0x81fe7f7f, 0xf0a05050, 0x44783c3c, 0xba259f9f, 0xe34ba8a8, 0xf3a25151, 0xfe5da3a3, 0xc0804040, 0x8a058f8f, 0xad3f9292, 0xbc219d9d, 0x48703838, 0x04f1f5f5, 0xdf63bcbc, 0xc177b6b6, 0x75afdada, 0x63422121, 0x30201010, 0x1ae5ffff, 0x0efdf3f3, 0x6dbfd2d2, 0x4c81cdcd, 0x14180c0c, 0x35261313, 0x2fc3ecec, 0xe1be5f5f, 0xa2359797, 0xcc884444, 0x392e1717, 0x5793c4c4, 0xf255a7a7, 0x82fc7e7e, 0x477a3d3d, 0xacc86464, 0xe7ba5d5d, 0x2b321919, 0x95e67373, 0xa0c06060, 0x98198181, 0xd19e4f4f, 0x7fa3dcdc, 0x66442222, 0x7e542a2a, 0xab3b9090, 0x830b8888, 0xca8c4646, 0x29c7eeee, 0xd36bb8b8, 0x3c281414, 0x79a7dede, 0xe2bc5e5e, 0x1d160b0b, 0x76addbdb, 0x3bdbe0e0, 0x56643232, 0x4e743a3a, 0x1e140a0a, 0xdb924949, 0x0a0c0606, 0x6c482424, 0xe4b85c5c, 0x5d9fc2c2, 0x6ebdd3d3, 0xef43acac, 0xa6c46262, 0xa8399191, 0xa4319595, 0x37d3e4e4, 0x8bf27979, 0x32d5e7e7, 0x438bc8c8, 0x596e3737, 0xb7da6d6d, 0x8c018d8d, 0x64b1d5d5, 0xd29c4e4e, 0xe049a9a9, 0xb4d86c6c, 0xfaac5656, 0x07f3f4f4, 0x25cfeaea, 0xafca6565, 0x8ef47a7a, 0xe947aeae, 0x18100808, 0xd56fbaba, 0x88f07878, 0x6f4a2525, 0x725c2e2e, 0x24381c1c, 0xf157a6a6, 0xc773b4b4, 0x5197c6c6, 0x23cbe8e8, 0x7ca1dddd, 0x9ce87474, 0x213e1f1f, 0xdd964b4b, 0xdc61bdbd, 0x860d8b8b, 0x850f8a8a, 0x90e07070, 0x427c3e3e, 0xc471b5b5, 0xaacc6666, 0xd8904848, 0x05060303, 0x01f7f6f6, 0x121c0e0e, 0xa3c26161, 0x5f6a3535, 0xf9ae5757, 0xd069b9b9, 0x91178686, 0x5899c1c1, 0x273a1d1d, 0xb9279e9e, 0x38d9e1e1, 0x13ebf8f8, 0xb32b9898, 0x33221111, 0xbbd26969, 0x70a9d9d9, 0x89078e8e, 0xa7339494, 0xb62d9b9b, 0x223c1e1e, 0x92158787, 0x20c9e9e9, 0x4987cece, 0xffaa5555, 0x78502828, 0x7aa5dfdf, 0x8f038c8c, 0xf859a1a1, 0x80098989, 0x171a0d0d, 0xda65bfbf, 0x31d7e6e6, 0xc6844242, 0xb8d06868, 0xc3824141, 0xb0299999, 0x775a2d2d, 0x111e0f0f, 0xcb7bb0b0, 0xfca85454, 0xd66dbbbb, 0x3a2c1616]);
        T3 = new Uint32Array([0x63a5c663, 0x7c84f87c, 0x7799ee77, 0x7b8df67b, 0xf20dfff2, 0x6bbdd66b, 0x6fb1de6f, 0xc55491c5, 0x30506030, 0x01030201, 0x67a9ce67, 0x2b7d562b, 0xfe19e7fe, 0xd762b5d7, 0xabe64dab, 0x769aec76, 0xca458fca, 0x829d1f82, 0xc94089c9, 0x7d87fa7d, 0xfa15effa, 0x59ebb259, 0x47c98e47, 0xf00bfbf0, 0xadec41ad, 0xd467b3d4, 0xa2fd5fa2, 0xafea45af, 0x9cbf239c, 0xa4f753a4, 0x7296e472, 0xc05b9bc0, 0xb7c275b7, 0xfd1ce1fd, 0x93ae3d93, 0x266a4c26, 0x365a6c36, 0x3f417e3f, 0xf702f5f7, 0xcc4f83cc, 0x345c6834, 0xa5f451a5, 0xe534d1e5, 0xf108f9f1, 0x7193e271, 0xd873abd8, 0x31536231, 0x153f2a15, 0x040c0804, 0xc75295c7, 0x23654623, 0xc35e9dc3, 0x18283018, 0x96a13796, 0x050f0a05, 0x9ab52f9a, 0x07090e07, 0x12362412, 0x809b1b80, 0xe23ddfe2, 0xeb26cdeb, 0x27694e27, 0xb2cd7fb2, 0x759fea75, 0x091b1209, 0x839e1d83, 0x2c74582c, 0x1a2e341a, 0x1b2d361b, 0x6eb2dc6e, 0x5aeeb45a, 0xa0fb5ba0, 0x52f6a452, 0x3b4d763b, 0xd661b7d6, 0xb3ce7db3, 0x297b5229, 0xe33edde3, 0x2f715e2f, 0x84971384, 0x53f5a653, 0xd168b9d1, 0x00000000, 0xed2cc1ed, 0x20604020, 0xfc1fe3fc, 0xb1c879b1, 0x5bedb65b, 0x6abed46a, 0xcb468dcb, 0xbed967be, 0x394b7239, 0x4ade944a, 0x4cd4984c, 0x58e8b058, 0xcf4a85cf, 0xd06bbbd0, 0xef2ac5ef, 0xaae54faa, 0xfb16edfb, 0x43c58643, 0x4dd79a4d, 0x33556633, 0x85941185, 0x45cf8a45, 0xf910e9f9, 0x02060402, 0x7f81fe7f, 0x50f0a050, 0x3c44783c, 0x9fba259f, 0xa8e34ba8, 0x51f3a251, 0xa3fe5da3, 0x40c08040, 0x8f8a058f, 0x92ad3f92, 0x9dbc219d, 0x38487038, 0xf504f1f5, 0xbcdf63bc, 0xb6c177b6, 0xda75afda, 0x21634221, 0x10302010, 0xff1ae5ff, 0xf30efdf3, 0xd26dbfd2, 0xcd4c81cd, 0x0c14180c, 0x13352613, 0xec2fc3ec, 0x5fe1be5f, 0x97a23597, 0x44cc8844, 0x17392e17, 0xc45793c4, 0xa7f255a7, 0x7e82fc7e, 0x3d477a3d, 0x64acc864, 0x5de7ba5d, 0x192b3219, 0x7395e673, 0x60a0c060, 0x81981981, 0x4fd19e4f, 0xdc7fa3dc, 0x22664422, 0x2a7e542a, 0x90ab3b90, 0x88830b88, 0x46ca8c46, 0xee29c7ee, 0xb8d36bb8, 0x143c2814, 0xde79a7de, 0x5ee2bc5e, 0x0b1d160b, 0xdb76addb, 0xe03bdbe0, 0x32566432, 0x3a4e743a, 0x0a1e140a, 0x49db9249, 0x060a0c06, 0x246c4824, 0x5ce4b85c, 0xc25d9fc2, 0xd36ebdd3, 0xacef43ac, 0x62a6c462, 0x91a83991, 0x95a43195, 0xe437d3e4, 0x798bf279, 0xe732d5e7, 0xc8438bc8, 0x37596e37, 0x6db7da6d, 0x8d8c018d, 0xd564b1d5, 0x4ed29c4e, 0xa9e049a9, 0x6cb4d86c, 0x56faac56, 0xf407f3f4, 0xea25cfea, 0x65afca65, 0x7a8ef47a, 0xaee947ae, 0x08181008, 0xbad56fba, 0x7888f078, 0x256f4a25, 0x2e725c2e, 0x1c24381c, 0xa6f157a6, 0xb4c773b4, 0xc65197c6, 0xe823cbe8, 0xdd7ca1dd, 0x749ce874, 0x1f213e1f, 0x4bdd964b, 0xbddc61bd, 0x8b860d8b, 0x8a850f8a, 0x7090e070, 0x3e427c3e, 0xb5c471b5, 0x66aacc66, 0x48d89048, 0x03050603, 0xf601f7f6, 0x0e121c0e, 0x61a3c261, 0x355f6a35, 0x57f9ae57, 0xb9d069b9, 0x86911786, 0xc15899c1, 0x1d273a1d, 0x9eb9279e, 0xe138d9e1, 0xf813ebf8, 0x98b32b98, 0x11332211, 0x69bbd269, 0xd970a9d9, 0x8e89078e, 0x94a73394, 0x9bb62d9b, 0x1e223c1e, 0x87921587, 0xe920c9e9, 0xce4987ce, 0x55ffaa55, 0x28785028, 0xdf7aa5df, 0x8c8f038c, 0xa1f859a1, 0x89800989, 0x0d171a0d, 0xbfda65bf, 0xe631d7e6, 0x42c68442, 0x68b8d068, 0x41c38241, 0x99b02999, 0x2d775a2d, 0x0f111e0f, 0xb0cb7bb0, 0x54fca854, 0xbbd66dbb, 0x163a2c16]);
        T4 = new Uint32Array([0x6363a5c6, 0x7c7c84f8, 0x777799ee, 0x7b7b8df6, 0xf2f20dff, 0x6b6bbdd6, 0x6f6fb1de, 0xc5c55491, 0x30305060, 0x01010302, 0x6767a9ce, 0x2b2b7d56, 0xfefe19e7, 0xd7d762b5, 0xababe64d, 0x76769aec, 0xcaca458f, 0x82829d1f, 0xc9c94089, 0x7d7d87fa, 0xfafa15ef, 0x5959ebb2, 0x4747c98e, 0xf0f00bfb, 0xadadec41, 0xd4d467b3, 0xa2a2fd5f, 0xafafea45, 0x9c9cbf23, 0xa4a4f753, 0x727296e4, 0xc0c05b9b, 0xb7b7c275, 0xfdfd1ce1, 0x9393ae3d, 0x26266a4c, 0x36365a6c, 0x3f3f417e, 0xf7f702f5, 0xcccc4f83, 0x34345c68, 0xa5a5f451, 0xe5e534d1, 0xf1f108f9, 0x717193e2, 0xd8d873ab, 0x31315362, 0x15153f2a, 0x04040c08, 0xc7c75295, 0x23236546, 0xc3c35e9d, 0x18182830, 0x9696a137, 0x05050f0a, 0x9a9ab52f, 0x0707090e, 0x12123624, 0x80809b1b, 0xe2e23ddf, 0xebeb26cd, 0x2727694e, 0xb2b2cd7f, 0x75759fea, 0x09091b12, 0x83839e1d, 0x2c2c7458, 0x1a1a2e34, 0x1b1b2d36, 0x6e6eb2dc, 0x5a5aeeb4, 0xa0a0fb5b, 0x5252f6a4, 0x3b3b4d76, 0xd6d661b7, 0xb3b3ce7d, 0x29297b52, 0xe3e33edd, 0x2f2f715e, 0x84849713, 0x5353f5a6, 0xd1d168b9, 0x00000000, 0xeded2cc1, 0x20206040, 0xfcfc1fe3, 0xb1b1c879, 0x5b5bedb6, 0x6a6abed4, 0xcbcb468d, 0xbebed967, 0x39394b72, 0x4a4ade94, 0x4c4cd498, 0x5858e8b0, 0xcfcf4a85, 0xd0d06bbb, 0xefef2ac5, 0xaaaae54f, 0xfbfb16ed, 0x4343c586, 0x4d4dd79a, 0x33335566, 0x85859411, 0x4545cf8a, 0xf9f910e9, 0x02020604, 0x7f7f81fe, 0x5050f0a0, 0x3c3c4478, 0x9f9fba25, 0xa8a8e34b, 0x5151f3a2, 0xa3a3fe5d, 0x4040c080, 0x8f8f8a05, 0x9292ad3f, 0x9d9dbc21, 0x38384870, 0xf5f504f1, 0xbcbcdf63, 0xb6b6c177, 0xdada75af, 0x21216342, 0x10103020, 0xffff1ae5, 0xf3f30efd, 0xd2d26dbf, 0xcdcd4c81, 0x0c0c1418, 0x13133526, 0xecec2fc3, 0x5f5fe1be, 0x9797a235, 0x4444cc88, 0x1717392e, 0xc4c45793, 0xa7a7f255, 0x7e7e82fc, 0x3d3d477a, 0x6464acc8, 0x5d5de7ba, 0x19192b32, 0x737395e6, 0x6060a0c0, 0x81819819, 0x4f4fd19e, 0xdcdc7fa3, 0x22226644, 0x2a2a7e54, 0x9090ab3b, 0x8888830b, 0x4646ca8c, 0xeeee29c7, 0xb8b8d36b, 0x14143c28, 0xdede79a7, 0x5e5ee2bc, 0x0b0b1d16, 0xdbdb76ad, 0xe0e03bdb, 0x32325664, 0x3a3a4e74, 0x0a0a1e14, 0x4949db92, 0x06060a0c, 0x24246c48, 0x5c5ce4b8, 0xc2c25d9f, 0xd3d36ebd, 0xacacef43, 0x6262a6c4, 0x9191a839, 0x9595a431, 0xe4e437d3, 0x79798bf2, 0xe7e732d5, 0xc8c8438b, 0x3737596e, 0x6d6db7da, 0x8d8d8c01, 0xd5d564b1, 0x4e4ed29c, 0xa9a9e049, 0x6c6cb4d8, 0x5656faac, 0xf4f407f3, 0xeaea25cf, 0x6565afca, 0x7a7a8ef4, 0xaeaee947, 0x08081810, 0xbabad56f, 0x787888f0, 0x25256f4a, 0x2e2e725c, 0x1c1c2438, 0xa6a6f157, 0xb4b4c773, 0xc6c65197, 0xe8e823cb, 0xdddd7ca1, 0x74749ce8, 0x1f1f213e, 0x4b4bdd96, 0xbdbddc61, 0x8b8b860d, 0x8a8a850f, 0x707090e0, 0x3e3e427c, 0xb5b5c471, 0x6666aacc, 0x4848d890, 0x03030506, 0xf6f601f7, 0x0e0e121c, 0x6161a3c2, 0x35355f6a, 0x5757f9ae, 0xb9b9d069, 0x86869117, 0xc1c15899, 0x1d1d273a, 0x9e9eb927, 0xe1e138d9, 0xf8f813eb, 0x9898b32b, 0x11113322, 0x6969bbd2, 0xd9d970a9, 0x8e8e8907, 0x9494a733, 0x9b9bb62d, 0x1e1e223c, 0x87879215, 0xe9e920c9, 0xcece4987, 0x5555ffaa, 0x28287850, 0xdfdf7aa5, 0x8c8c8f03, 0xa1a1f859, 0x89898009, 0x0d0d171a, 0xbfbfda65, 0xe6e631d7, 0x4242c684, 0x6868b8d0, 0x4141c382, 0x9999b029, 0x2d2d775a, 0x0f0f111e, 0xb0b0cb7b, 0x5454fca8, 0xbbbbd66d, 0x16163a2c]);
        T5 = new Uint32Array([0x51f4a750, 0x7e416553, 0x1a17a4c3, 0x3a275e96, 0x3bab6bcb, 0x1f9d45f1, 0xacfa58ab, 0x4be30393, 0x2030fa55, 0xad766df6, 0x88cc7691, 0xf5024c25, 0x4fe5d7fc, 0xc52acbd7, 0x26354480, 0xb562a38f, 0xdeb15a49, 0x25ba1b67, 0x45ea0e98, 0x5dfec0e1, 0xc32f7502, 0x814cf012, 0x8d4697a3, 0x6bd3f9c6, 0x038f5fe7, 0x15929c95, 0xbf6d7aeb, 0x955259da, 0xd4be832d, 0x587421d3, 0x49e06929, 0x8ec9c844, 0x75c2896a, 0xf48e7978, 0x99583e6b, 0x27b971dd, 0xbee14fb6, 0xf088ad17, 0xc920ac66, 0x7dce3ab4, 0x63df4a18, 0xe51a3182, 0x97513360, 0x62537f45, 0xb16477e0, 0xbb6bae84, 0xfe81a01c, 0xf9082b94, 0x70486858, 0x8f45fd19, 0x94de6c87, 0x527bf8b7, 0xab73d323, 0x724b02e2, 0xe31f8f57, 0x6655ab2a, 0xb2eb2807, 0x2fb5c203, 0x86c57b9a, 0xd33708a5, 0x302887f2, 0x23bfa5b2, 0x02036aba, 0xed16825c, 0x8acf1c2b, 0xa779b492, 0xf307f2f0, 0x4e69e2a1, 0x65daf4cd, 0x0605bed5, 0xd134621f, 0xc4a6fe8a, 0x342e539d, 0xa2f355a0, 0x058ae132, 0xa4f6eb75, 0x0b83ec39, 0x4060efaa, 0x5e719f06, 0xbd6e1051, 0x3e218af9, 0x96dd063d, 0xdd3e05ae, 0x4de6bd46, 0x91548db5, 0x71c45d05, 0x0406d46f, 0x605015ff, 0x1998fb24, 0xd6bde997, 0x894043cc, 0x67d99e77, 0xb0e842bd, 0x07898b88, 0xe7195b38, 0x79c8eedb, 0xa17c0a47, 0x7c420fe9, 0xf8841ec9, 0x00000000, 0x09808683, 0x322bed48, 0x1e1170ac, 0x6c5a724e, 0xfd0efffb, 0x0f853856, 0x3daed51e, 0x362d3927, 0x0a0fd964, 0x685ca621, 0x9b5b54d1, 0x24362e3a, 0x0c0a67b1, 0x9357e70f, 0xb4ee96d2, 0x1b9b919e, 0x80c0c54f, 0x61dc20a2, 0x5a774b69, 0x1c121a16, 0xe293ba0a, 0xc0a02ae5, 0x3c22e043, 0x121b171d, 0x0e090d0b, 0xf28bc7ad, 0x2db6a8b9, 0x141ea9c8, 0x57f11985, 0xaf75074c, 0xee99ddbb, 0xa37f60fd, 0xf701269f, 0x5c72f5bc, 0x44663bc5, 0x5bfb7e34, 0x8b432976, 0xcb23c6dc, 0xb6edfc68, 0xb8e4f163, 0xd731dcca, 0x42638510, 0x13972240, 0x84c61120, 0x854a247d, 0xd2bb3df8, 0xaef93211, 0xc729a16d, 0x1d9e2f4b, 0xdcb230f3, 0x0d8652ec, 0x77c1e3d0, 0x2bb3166c, 0xa970b999, 0x119448fa, 0x47e96422, 0xa8fc8cc4, 0xa0f03f1a, 0x567d2cd8, 0x223390ef, 0x87494ec7, 0xd938d1c1, 0x8ccaa2fe, 0x98d40b36, 0xa6f581cf, 0xa57ade28, 0xdab78e26, 0x3fadbfa4, 0x2c3a9de4, 0x5078920d, 0x6a5fcc9b, 0x547e4662, 0xf68d13c2, 0x90d8b8e8, 0x2e39f75e, 0x82c3aff5, 0x9f5d80be, 0x69d0937c, 0x6fd52da9, 0xcf2512b3, 0xc8ac993b, 0x10187da7, 0xe89c636e, 0xdb3bbb7b, 0xcd267809, 0x6e5918f4, 0xec9ab701, 0x834f9aa8, 0xe6956e65, 0xaaffe67e, 0x21bccf08, 0xef15e8e6, 0xbae79bd9, 0x4a6f36ce, 0xea9f09d4, 0x29b07cd6, 0x31a4b2af, 0x2a3f2331, 0xc6a59430, 0x35a266c0, 0x744ebc37, 0xfc82caa6, 0xe090d0b0, 0x33a7d815, 0xf104984a, 0x41ecdaf7, 0x7fcd500e, 0x1791f62f, 0x764dd68d, 0x43efb04d, 0xccaa4d54, 0xe49604df, 0x9ed1b5e3, 0x4c6a881b, 0xc12c1fb8, 0x4665517f, 0x9d5eea04, 0x018c355d, 0xfa877473, 0xfb0b412e, 0xb3671d5a, 0x92dbd252, 0xe9105633, 0x6dd64713, 0x9ad7618c, 0x37a10c7a, 0x59f8148e, 0xeb133c89, 0xcea927ee, 0xb761c935, 0xe11ce5ed, 0x7a47b13c, 0x9cd2df59, 0x55f2733f, 0x1814ce79, 0x73c737bf, 0x53f7cdea, 0x5ffdaa5b, 0xdf3d6f14, 0x7844db86, 0xcaaff381, 0xb968c43e, 0x3824342c, 0xc2a3405f, 0x161dc372, 0xbce2250c, 0x283c498b, 0xff0d9541, 0x39a80171, 0x080cb3de, 0xd8b4e49c, 0x6456c190, 0x7bcb8461, 0xd532b670, 0x486c5c74, 0xd0b85742]);
        T6 = new Uint32Array([0x5051f4a7, 0x537e4165, 0xc31a17a4, 0x963a275e, 0xcb3bab6b, 0xf11f9d45, 0xabacfa58, 0x934be303, 0x552030fa, 0xf6ad766d, 0x9188cc76, 0x25f5024c, 0xfc4fe5d7, 0xd7c52acb, 0x80263544, 0x8fb562a3, 0x49deb15a, 0x6725ba1b, 0x9845ea0e, 0xe15dfec0, 0x02c32f75, 0x12814cf0, 0xa38d4697, 0xc66bd3f9, 0xe7038f5f, 0x9515929c, 0xebbf6d7a, 0xda955259, 0x2dd4be83, 0xd3587421, 0x2949e069, 0x448ec9c8, 0x6a75c289, 0x78f48e79, 0x6b99583e, 0xdd27b971, 0xb6bee14f, 0x17f088ad, 0x66c920ac, 0xb47dce3a, 0x1863df4a, 0x82e51a31, 0x60975133, 0x4562537f, 0xe0b16477, 0x84bb6bae, 0x1cfe81a0, 0x94f9082b, 0x58704868, 0x198f45fd, 0x8794de6c, 0xb7527bf8, 0x23ab73d3, 0xe2724b02, 0x57e31f8f, 0x2a6655ab, 0x07b2eb28, 0x032fb5c2, 0x9a86c57b, 0xa5d33708, 0xf2302887, 0xb223bfa5, 0xba02036a, 0x5ced1682, 0x2b8acf1c, 0x92a779b4, 0xf0f307f2, 0xa14e69e2, 0xcd65daf4, 0xd50605be, 0x1fd13462, 0x8ac4a6fe, 0x9d342e53, 0xa0a2f355, 0x32058ae1, 0x75a4f6eb, 0x390b83ec, 0xaa4060ef, 0x065e719f, 0x51bd6e10, 0xf93e218a, 0x3d96dd06, 0xaedd3e05, 0x464de6bd, 0xb591548d, 0x0571c45d, 0x6f0406d4, 0xff605015, 0x241998fb, 0x97d6bde9, 0xcc894043, 0x7767d99e, 0xbdb0e842, 0x8807898b, 0x38e7195b, 0xdb79c8ee, 0x47a17c0a, 0xe97c420f, 0xc9f8841e, 0x00000000, 0x83098086, 0x48322bed, 0xac1e1170, 0x4e6c5a72, 0xfbfd0eff, 0x560f8538, 0x1e3daed5, 0x27362d39, 0x640a0fd9, 0x21685ca6, 0xd19b5b54, 0x3a24362e, 0xb10c0a67, 0x0f9357e7, 0xd2b4ee96, 0x9e1b9b91, 0x4f80c0c5, 0xa261dc20, 0x695a774b, 0x161c121a, 0x0ae293ba, 0xe5c0a02a, 0x433c22e0, 0x1d121b17, 0x0b0e090d, 0xadf28bc7, 0xb92db6a8, 0xc8141ea9, 0x8557f119, 0x4caf7507, 0xbbee99dd, 0xfda37f60, 0x9ff70126, 0xbc5c72f5, 0xc544663b, 0x345bfb7e, 0x768b4329, 0xdccb23c6, 0x68b6edfc, 0x63b8e4f1, 0xcad731dc, 0x10426385, 0x40139722, 0x2084c611, 0x7d854a24, 0xf8d2bb3d, 0x11aef932, 0x6dc729a1, 0x4b1d9e2f, 0xf3dcb230, 0xec0d8652, 0xd077c1e3, 0x6c2bb316, 0x99a970b9, 0xfa119448, 0x2247e964, 0xc4a8fc8c, 0x1aa0f03f, 0xd8567d2c, 0xef223390, 0xc787494e, 0xc1d938d1, 0xfe8ccaa2, 0x3698d40b, 0xcfa6f581, 0x28a57ade, 0x26dab78e, 0xa43fadbf, 0xe42c3a9d, 0x0d507892, 0x9b6a5fcc, 0x62547e46, 0xc2f68d13, 0xe890d8b8, 0x5e2e39f7, 0xf582c3af, 0xbe9f5d80, 0x7c69d093, 0xa96fd52d, 0xb3cf2512, 0x3bc8ac99, 0xa710187d, 0x6ee89c63, 0x7bdb3bbb, 0x09cd2678, 0xf46e5918, 0x01ec9ab7, 0xa8834f9a, 0x65e6956e, 0x7eaaffe6, 0x0821bccf, 0xe6ef15e8, 0xd9bae79b, 0xce4a6f36, 0xd4ea9f09, 0xd629b07c, 0xaf31a4b2, 0x312a3f23, 0x30c6a594, 0xc035a266, 0x37744ebc, 0xa6fc82ca, 0xb0e090d0, 0x1533a7d8, 0x4af10498, 0xf741ecda, 0x0e7fcd50, 0x2f1791f6, 0x8d764dd6, 0x4d43efb0, 0x54ccaa4d, 0xdfe49604, 0xe39ed1b5, 0x1b4c6a88, 0xb8c12c1f, 0x7f466551, 0x049d5eea, 0x5d018c35, 0x73fa8774, 0x2efb0b41, 0x5ab3671d, 0x5292dbd2, 0x33e91056, 0x136dd647, 0x8c9ad761, 0x7a37a10c, 0x8e59f814, 0x89eb133c, 0xeecea927, 0x35b761c9, 0xede11ce5, 0x3c7a47b1, 0x599cd2df, 0x3f55f273, 0x791814ce, 0xbf73c737, 0xea53f7cd, 0x5b5ffdaa, 0x14df3d6f, 0x867844db, 0x81caaff3, 0x3eb968c4, 0x2c382434, 0x5fc2a340, 0x72161dc3, 0x0cbce225, 0x8b283c49, 0x41ff0d95, 0x7139a801, 0xde080cb3, 0x9cd8b4e4, 0x906456c1, 0x617bcb84, 0x70d532b6, 0x74486c5c, 0x42d0b857]);
        T7 = new Uint32Array([0xa75051f4, 0x65537e41, 0xa4c31a17, 0x5e963a27, 0x6bcb3bab, 0x45f11f9d, 0x58abacfa, 0x03934be3, 0xfa552030, 0x6df6ad76, 0x769188cc, 0x4c25f502, 0xd7fc4fe5, 0xcbd7c52a, 0x44802635, 0xa38fb562, 0x5a49deb1, 0x1b6725ba, 0x0e9845ea, 0xc0e15dfe, 0x7502c32f, 0xf012814c, 0x97a38d46, 0xf9c66bd3, 0x5fe7038f, 0x9c951592, 0x7aebbf6d, 0x59da9552, 0x832dd4be, 0x21d35874, 0x692949e0, 0xc8448ec9, 0x896a75c2, 0x7978f48e, 0x3e6b9958, 0x71dd27b9, 0x4fb6bee1, 0xad17f088, 0xac66c920, 0x3ab47dce, 0x4a1863df, 0x3182e51a, 0x33609751, 0x7f456253, 0x77e0b164, 0xae84bb6b, 0xa01cfe81, 0x2b94f908, 0x68587048, 0xfd198f45, 0x6c8794de, 0xf8b7527b, 0xd323ab73, 0x02e2724b, 0x8f57e31f, 0xab2a6655, 0x2807b2eb, 0xc2032fb5, 0x7b9a86c5, 0x08a5d337, 0x87f23028, 0xa5b223bf, 0x6aba0203, 0x825ced16, 0x1c2b8acf, 0xb492a779, 0xf2f0f307, 0xe2a14e69, 0xf4cd65da, 0xbed50605, 0x621fd134, 0xfe8ac4a6, 0x539d342e, 0x55a0a2f3, 0xe132058a, 0xeb75a4f6, 0xec390b83, 0xefaa4060, 0x9f065e71, 0x1051bd6e, 0x8af93e21, 0x063d96dd, 0x05aedd3e, 0xbd464de6, 0x8db59154, 0x5d0571c4, 0xd46f0406, 0x15ff6050, 0xfb241998, 0xe997d6bd, 0x43cc8940, 0x9e7767d9, 0x42bdb0e8, 0x8b880789, 0x5b38e719, 0xeedb79c8, 0x0a47a17c, 0x0fe97c42, 0x1ec9f884, 0x00000000, 0x86830980, 0xed48322b, 0x70ac1e11, 0x724e6c5a, 0xfffbfd0e, 0x38560f85, 0xd51e3dae, 0x3927362d, 0xd9640a0f, 0xa621685c, 0x54d19b5b, 0x2e3a2436, 0x67b10c0a, 0xe70f9357, 0x96d2b4ee, 0x919e1b9b, 0xc54f80c0, 0x20a261dc, 0x4b695a77, 0x1a161c12, 0xba0ae293, 0x2ae5c0a0, 0xe0433c22, 0x171d121b, 0x0d0b0e09, 0xc7adf28b, 0xa8b92db6, 0xa9c8141e, 0x198557f1, 0x074caf75, 0xddbbee99, 0x60fda37f, 0x269ff701, 0xf5bc5c72, 0x3bc54466, 0x7e345bfb, 0x29768b43, 0xc6dccb23, 0xfc68b6ed, 0xf163b8e4, 0xdccad731, 0x85104263, 0x22401397, 0x112084c6, 0x247d854a, 0x3df8d2bb, 0x3211aef9, 0xa16dc729, 0x2f4b1d9e, 0x30f3dcb2, 0x52ec0d86, 0xe3d077c1, 0x166c2bb3, 0xb999a970, 0x48fa1194, 0x642247e9, 0x8cc4a8fc, 0x3f1aa0f0, 0x2cd8567d, 0x90ef2233, 0x4ec78749, 0xd1c1d938, 0xa2fe8cca, 0x0b3698d4, 0x81cfa6f5, 0xde28a57a, 0x8e26dab7, 0xbfa43fad, 0x9de42c3a, 0x920d5078, 0xcc9b6a5f, 0x4662547e, 0x13c2f68d, 0xb8e890d8, 0xf75e2e39, 0xaff582c3, 0x80be9f5d, 0x937c69d0, 0x2da96fd5, 0x12b3cf25, 0x993bc8ac, 0x7da71018, 0x636ee89c, 0xbb7bdb3b, 0x7809cd26, 0x18f46e59, 0xb701ec9a, 0x9aa8834f, 0x6e65e695, 0xe67eaaff, 0xcf0821bc, 0xe8e6ef15, 0x9bd9bae7, 0x36ce4a6f, 0x09d4ea9f, 0x7cd629b0, 0xb2af31a4, 0x23312a3f, 0x9430c6a5, 0x66c035a2, 0xbc37744e, 0xcaa6fc82, 0xd0b0e090, 0xd81533a7, 0x984af104, 0xdaf741ec, 0x500e7fcd, 0xf62f1791, 0xd68d764d, 0xb04d43ef, 0x4d54ccaa, 0x04dfe496, 0xb5e39ed1, 0x881b4c6a, 0x1fb8c12c, 0x517f4665, 0xea049d5e, 0x355d018c, 0x7473fa87, 0x412efb0b, 0x1d5ab367, 0xd25292db, 0x5633e910, 0x47136dd6, 0x618c9ad7, 0x0c7a37a1, 0x148e59f8, 0x3c89eb13, 0x27eecea9, 0xc935b761, 0xe5ede11c, 0xb13c7a47, 0xdf599cd2, 0x733f55f2, 0xce791814, 0x37bf73c7, 0xcdea53f7, 0xaa5b5ffd, 0x6f14df3d, 0xdb867844, 0xf381caaf, 0xc43eb968, 0x342c3824, 0x405fc2a3, 0xc372161d, 0x250cbce2, 0x498b283c, 0x9541ff0d, 0x017139a8, 0xb3de080c, 0xe49cd8b4, 0xc1906456, 0x84617bcb, 0xb670d532, 0x5c74486c, 0x5742d0b8]);
        T8 = new Uint32Array([0xf4a75051, 0x4165537e, 0x17a4c31a, 0x275e963a, 0xab6bcb3b, 0x9d45f11f, 0xfa58abac, 0xe303934b, 0x30fa5520, 0x766df6ad, 0xcc769188, 0x024c25f5, 0xe5d7fc4f, 0x2acbd7c5, 0x35448026, 0x62a38fb5, 0xb15a49de, 0xba1b6725, 0xea0e9845, 0xfec0e15d, 0x2f7502c3, 0x4cf01281, 0x4697a38d, 0xd3f9c66b, 0x8f5fe703, 0x929c9515, 0x6d7aebbf, 0x5259da95, 0xbe832dd4, 0x7421d358, 0xe0692949, 0xc9c8448e, 0xc2896a75, 0x8e7978f4, 0x583e6b99, 0xb971dd27, 0xe14fb6be, 0x88ad17f0, 0x20ac66c9, 0xce3ab47d, 0xdf4a1863, 0x1a3182e5, 0x51336097, 0x537f4562, 0x6477e0b1, 0x6bae84bb, 0x81a01cfe, 0x082b94f9, 0x48685870, 0x45fd198f, 0xde6c8794, 0x7bf8b752, 0x73d323ab, 0x4b02e272, 0x1f8f57e3, 0x55ab2a66, 0xeb2807b2, 0xb5c2032f, 0xc57b9a86, 0x3708a5d3, 0x2887f230, 0xbfa5b223, 0x036aba02, 0x16825ced, 0xcf1c2b8a, 0x79b492a7, 0x07f2f0f3, 0x69e2a14e, 0xdaf4cd65, 0x05bed506, 0x34621fd1, 0xa6fe8ac4, 0x2e539d34, 0xf355a0a2, 0x8ae13205, 0xf6eb75a4, 0x83ec390b, 0x60efaa40, 0x719f065e, 0x6e1051bd, 0x218af93e, 0xdd063d96, 0x3e05aedd, 0xe6bd464d, 0x548db591, 0xc45d0571, 0x06d46f04, 0x5015ff60, 0x98fb2419, 0xbde997d6, 0x4043cc89, 0xd99e7767, 0xe842bdb0, 0x898b8807, 0x195b38e7, 0xc8eedb79, 0x7c0a47a1, 0x420fe97c, 0x841ec9f8, 0x00000000, 0x80868309, 0x2bed4832, 0x1170ac1e, 0x5a724e6c, 0x0efffbfd, 0x8538560f, 0xaed51e3d, 0x2d392736, 0x0fd9640a, 0x5ca62168, 0x5b54d19b, 0x362e3a24, 0x0a67b10c, 0x57e70f93, 0xee96d2b4, 0x9b919e1b, 0xc0c54f80, 0xdc20a261, 0x774b695a, 0x121a161c, 0x93ba0ae2, 0xa02ae5c0, 0x22e0433c, 0x1b171d12, 0x090d0b0e, 0x8bc7adf2, 0xb6a8b92d, 0x1ea9c814, 0xf1198557, 0x75074caf, 0x99ddbbee, 0x7f60fda3, 0x01269ff7, 0x72f5bc5c, 0x663bc544, 0xfb7e345b, 0x4329768b, 0x23c6dccb, 0xedfc68b6, 0xe4f163b8, 0x31dccad7, 0x63851042, 0x97224013, 0xc6112084, 0x4a247d85, 0xbb3df8d2, 0xf93211ae, 0x29a16dc7, 0x9e2f4b1d, 0xb230f3dc, 0x8652ec0d, 0xc1e3d077, 0xb3166c2b, 0x70b999a9, 0x9448fa11, 0xe9642247, 0xfc8cc4a8, 0xf03f1aa0, 0x7d2cd856, 0x3390ef22, 0x494ec787, 0x38d1c1d9, 0xcaa2fe8c, 0xd40b3698, 0xf581cfa6, 0x7ade28a5, 0xb78e26da, 0xadbfa43f, 0x3a9de42c, 0x78920d50, 0x5fcc9b6a, 0x7e466254, 0x8d13c2f6, 0xd8b8e890, 0x39f75e2e, 0xc3aff582, 0x5d80be9f, 0xd0937c69, 0xd52da96f, 0x2512b3cf, 0xac993bc8, 0x187da710, 0x9c636ee8, 0x3bbb7bdb, 0x267809cd, 0x5918f46e, 0x9ab701ec, 0x4f9aa883, 0x956e65e6, 0xffe67eaa, 0xbccf0821, 0x15e8e6ef, 0xe79bd9ba, 0x6f36ce4a, 0x9f09d4ea, 0xb07cd629, 0xa4b2af31, 0x3f23312a, 0xa59430c6, 0xa266c035, 0x4ebc3774, 0x82caa6fc, 0x90d0b0e0, 0xa7d81533, 0x04984af1, 0xecdaf741, 0xcd500e7f, 0x91f62f17, 0x4dd68d76, 0xefb04d43, 0xaa4d54cc, 0x9604dfe4, 0xd1b5e39e, 0x6a881b4c, 0x2c1fb8c1, 0x65517f46, 0x5eea049d, 0x8c355d01, 0x877473fa, 0x0b412efb, 0x671d5ab3, 0xdbd25292, 0x105633e9, 0xd647136d, 0xd7618c9a, 0xa10c7a37, 0xf8148e59, 0x133c89eb, 0xa927eece, 0x61c935b7, 0x1ce5ede1, 0x47b13c7a, 0xd2df599c, 0xf2733f55, 0x14ce7918, 0xc737bf73, 0xf7cdea53, 0xfdaa5b5f, 0x3d6f14df, 0x44db8678, 0xaff381ca, 0x68c43eb9, 0x24342c38, 0xa3405fc2, 0x1dc37216, 0xe2250cbc, 0x3c498b28, 0x0d9541ff, 0xa8017139, 0x0cb3de08, 0xb4e49cd8, 0x56c19064, 0xcb84617b, 0x32b670d5, 0x6c5c7448, 0xb85742d0]);
        U1 = new Uint32Array([0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927, 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45, 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb, 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381, 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf, 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66, 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28, 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012, 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec, 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e, 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd, 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7, 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89, 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b, 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815, 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f, 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa, 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8, 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36, 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c, 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742, 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea, 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4, 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e, 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360, 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502, 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87, 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd, 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3, 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621, 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f, 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55, 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26, 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844, 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba, 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480, 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce, 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67, 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929, 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713, 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed, 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f, 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
        U2 = new Uint32Array([0x00000000, 0x0b0e090d, 0x161c121a, 0x1d121b17, 0x2c382434, 0x27362d39, 0x3a24362e, 0x312a3f23, 0x58704868, 0x537e4165, 0x4e6c5a72, 0x4562537f, 0x74486c5c, 0x7f466551, 0x62547e46, 0x695a774b, 0xb0e090d0, 0xbbee99dd, 0xa6fc82ca, 0xadf28bc7, 0x9cd8b4e4, 0x97d6bde9, 0x8ac4a6fe, 0x81caaff3, 0xe890d8b8, 0xe39ed1b5, 0xfe8ccaa2, 0xf582c3af, 0xc4a8fc8c, 0xcfa6f581, 0xd2b4ee96, 0xd9bae79b, 0x7bdb3bbb, 0x70d532b6, 0x6dc729a1, 0x66c920ac, 0x57e31f8f, 0x5ced1682, 0x41ff0d95, 0x4af10498, 0x23ab73d3, 0x28a57ade, 0x35b761c9, 0x3eb968c4, 0x0f9357e7, 0x049d5eea, 0x198f45fd, 0x12814cf0, 0xcb3bab6b, 0xc035a266, 0xdd27b971, 0xd629b07c, 0xe7038f5f, 0xec0d8652, 0xf11f9d45, 0xfa119448, 0x934be303, 0x9845ea0e, 0x8557f119, 0x8e59f814, 0xbf73c737, 0xb47dce3a, 0xa96fd52d, 0xa261dc20, 0xf6ad766d, 0xfda37f60, 0xe0b16477, 0xebbf6d7a, 0xda955259, 0xd19b5b54, 0xcc894043, 0xc787494e, 0xaedd3e05, 0xa5d33708, 0xb8c12c1f, 0xb3cf2512, 0x82e51a31, 0x89eb133c, 0x94f9082b, 0x9ff70126, 0x464de6bd, 0x4d43efb0, 0x5051f4a7, 0x5b5ffdaa, 0x6a75c289, 0x617bcb84, 0x7c69d093, 0x7767d99e, 0x1e3daed5, 0x1533a7d8, 0x0821bccf, 0x032fb5c2, 0x32058ae1, 0x390b83ec, 0x241998fb, 0x2f1791f6, 0x8d764dd6, 0x867844db, 0x9b6a5fcc, 0x906456c1, 0xa14e69e2, 0xaa4060ef, 0xb7527bf8, 0xbc5c72f5, 0xd50605be, 0xde080cb3, 0xc31a17a4, 0xc8141ea9, 0xf93e218a, 0xf2302887, 0xef223390, 0xe42c3a9d, 0x3d96dd06, 0x3698d40b, 0x2b8acf1c, 0x2084c611, 0x11aef932, 0x1aa0f03f, 0x07b2eb28, 0x0cbce225, 0x65e6956e, 0x6ee89c63, 0x73fa8774, 0x78f48e79, 0x49deb15a, 0x42d0b857, 0x5fc2a340, 0x54ccaa4d, 0xf741ecda, 0xfc4fe5d7, 0xe15dfec0, 0xea53f7cd, 0xdb79c8ee, 0xd077c1e3, 0xcd65daf4, 0xc66bd3f9, 0xaf31a4b2, 0xa43fadbf, 0xb92db6a8, 0xb223bfa5, 0x83098086, 0x8807898b, 0x9515929c, 0x9e1b9b91, 0x47a17c0a, 0x4caf7507, 0x51bd6e10, 0x5ab3671d, 0x6b99583e, 0x60975133, 0x7d854a24, 0x768b4329, 0x1fd13462, 0x14df3d6f, 0x09cd2678, 0x02c32f75, 0x33e91056, 0x38e7195b, 0x25f5024c, 0x2efb0b41, 0x8c9ad761, 0x8794de6c, 0x9a86c57b, 0x9188cc76, 0xa0a2f355, 0xabacfa58, 0xb6bee14f, 0xbdb0e842, 0xd4ea9f09, 0xdfe49604, 0xc2f68d13, 0xc9f8841e, 0xf8d2bb3d, 0xf3dcb230, 0xeecea927, 0xe5c0a02a, 0x3c7a47b1, 0x37744ebc, 0x2a6655ab, 0x21685ca6, 0x10426385, 0x1b4c6a88, 0x065e719f, 0x0d507892, 0x640a0fd9, 0x6f0406d4, 0x72161dc3, 0x791814ce, 0x48322bed, 0x433c22e0, 0x5e2e39f7, 0x552030fa, 0x01ec9ab7, 0x0ae293ba, 0x17f088ad, 0x1cfe81a0, 0x2dd4be83, 0x26dab78e, 0x3bc8ac99, 0x30c6a594, 0x599cd2df, 0x5292dbd2, 0x4f80c0c5, 0x448ec9c8, 0x75a4f6eb, 0x7eaaffe6, 0x63b8e4f1, 0x68b6edfc, 0xb10c0a67, 0xba02036a, 0xa710187d, 0xac1e1170, 0x9d342e53, 0x963a275e, 0x8b283c49, 0x80263544, 0xe97c420f, 0xe2724b02, 0xff605015, 0xf46e5918, 0xc544663b, 0xce4a6f36, 0xd3587421, 0xd8567d2c, 0x7a37a10c, 0x7139a801, 0x6c2bb316, 0x6725ba1b, 0x560f8538, 0x5d018c35, 0x40139722, 0x4b1d9e2f, 0x2247e964, 0x2949e069, 0x345bfb7e, 0x3f55f273, 0x0e7fcd50, 0x0571c45d, 0x1863df4a, 0x136dd647, 0xcad731dc, 0xc1d938d1, 0xdccb23c6, 0xd7c52acb, 0xe6ef15e8, 0xede11ce5, 0xf0f307f2, 0xfbfd0eff, 0x92a779b4, 0x99a970b9, 0x84bb6bae, 0x8fb562a3, 0xbe9f5d80, 0xb591548d, 0xa8834f9a, 0xa38d4697]);
        U3 = new Uint32Array([0x00000000, 0x0d0b0e09, 0x1a161c12, 0x171d121b, 0x342c3824, 0x3927362d, 0x2e3a2436, 0x23312a3f, 0x68587048, 0x65537e41, 0x724e6c5a, 0x7f456253, 0x5c74486c, 0x517f4665, 0x4662547e, 0x4b695a77, 0xd0b0e090, 0xddbbee99, 0xcaa6fc82, 0xc7adf28b, 0xe49cd8b4, 0xe997d6bd, 0xfe8ac4a6, 0xf381caaf, 0xb8e890d8, 0xb5e39ed1, 0xa2fe8cca, 0xaff582c3, 0x8cc4a8fc, 0x81cfa6f5, 0x96d2b4ee, 0x9bd9bae7, 0xbb7bdb3b, 0xb670d532, 0xa16dc729, 0xac66c920, 0x8f57e31f, 0x825ced16, 0x9541ff0d, 0x984af104, 0xd323ab73, 0xde28a57a, 0xc935b761, 0xc43eb968, 0xe70f9357, 0xea049d5e, 0xfd198f45, 0xf012814c, 0x6bcb3bab, 0x66c035a2, 0x71dd27b9, 0x7cd629b0, 0x5fe7038f, 0x52ec0d86, 0x45f11f9d, 0x48fa1194, 0x03934be3, 0x0e9845ea, 0x198557f1, 0x148e59f8, 0x37bf73c7, 0x3ab47dce, 0x2da96fd5, 0x20a261dc, 0x6df6ad76, 0x60fda37f, 0x77e0b164, 0x7aebbf6d, 0x59da9552, 0x54d19b5b, 0x43cc8940, 0x4ec78749, 0x05aedd3e, 0x08a5d337, 0x1fb8c12c, 0x12b3cf25, 0x3182e51a, 0x3c89eb13, 0x2b94f908, 0x269ff701, 0xbd464de6, 0xb04d43ef, 0xa75051f4, 0xaa5b5ffd, 0x896a75c2, 0x84617bcb, 0x937c69d0, 0x9e7767d9, 0xd51e3dae, 0xd81533a7, 0xcf0821bc, 0xc2032fb5, 0xe132058a, 0xec390b83, 0xfb241998, 0xf62f1791, 0xd68d764d, 0xdb867844, 0xcc9b6a5f, 0xc1906456, 0xe2a14e69, 0xefaa4060, 0xf8b7527b, 0xf5bc5c72, 0xbed50605, 0xb3de080c, 0xa4c31a17, 0xa9c8141e, 0x8af93e21, 0x87f23028, 0x90ef2233, 0x9de42c3a, 0x063d96dd, 0x0b3698d4, 0x1c2b8acf, 0x112084c6, 0x3211aef9, 0x3f1aa0f0, 0x2807b2eb, 0x250cbce2, 0x6e65e695, 0x636ee89c, 0x7473fa87, 0x7978f48e, 0x5a49deb1, 0x5742d0b8, 0x405fc2a3, 0x4d54ccaa, 0xdaf741ec, 0xd7fc4fe5, 0xc0e15dfe, 0xcdea53f7, 0xeedb79c8, 0xe3d077c1, 0xf4cd65da, 0xf9c66bd3, 0xb2af31a4, 0xbfa43fad, 0xa8b92db6, 0xa5b223bf, 0x86830980, 0x8b880789, 0x9c951592, 0x919e1b9b, 0x0a47a17c, 0x074caf75, 0x1051bd6e, 0x1d5ab367, 0x3e6b9958, 0x33609751, 0x247d854a, 0x29768b43, 0x621fd134, 0x6f14df3d, 0x7809cd26, 0x7502c32f, 0x5633e910, 0x5b38e719, 0x4c25f502, 0x412efb0b, 0x618c9ad7, 0x6c8794de, 0x7b9a86c5, 0x769188cc, 0x55a0a2f3, 0x58abacfa, 0x4fb6bee1, 0x42bdb0e8, 0x09d4ea9f, 0x04dfe496, 0x13c2f68d, 0x1ec9f884, 0x3df8d2bb, 0x30f3dcb2, 0x27eecea9, 0x2ae5c0a0, 0xb13c7a47, 0xbc37744e, 0xab2a6655, 0xa621685c, 0x85104263, 0x881b4c6a, 0x9f065e71, 0x920d5078, 0xd9640a0f, 0xd46f0406, 0xc372161d, 0xce791814, 0xed48322b, 0xe0433c22, 0xf75e2e39, 0xfa552030, 0xb701ec9a, 0xba0ae293, 0xad17f088, 0xa01cfe81, 0x832dd4be, 0x8e26dab7, 0x993bc8ac, 0x9430c6a5, 0xdf599cd2, 0xd25292db, 0xc54f80c0, 0xc8448ec9, 0xeb75a4f6, 0xe67eaaff, 0xf163b8e4, 0xfc68b6ed, 0x67b10c0a, 0x6aba0203, 0x7da71018, 0x70ac1e11, 0x539d342e, 0x5e963a27, 0x498b283c, 0x44802635, 0x0fe97c42, 0x02e2724b, 0x15ff6050, 0x18f46e59, 0x3bc54466, 0x36ce4a6f, 0x21d35874, 0x2cd8567d, 0x0c7a37a1, 0x017139a8, 0x166c2bb3, 0x1b6725ba, 0x38560f85, 0x355d018c, 0x22401397, 0x2f4b1d9e, 0x642247e9, 0x692949e0, 0x7e345bfb, 0x733f55f2, 0x500e7fcd, 0x5d0571c4, 0x4a1863df, 0x47136dd6, 0xdccad731, 0xd1c1d938, 0xc6dccb23, 0xcbd7c52a, 0xe8e6ef15, 0xe5ede11c, 0xf2f0f307, 0xfffbfd0e, 0xb492a779, 0xb999a970, 0xae84bb6b, 0xa38fb562, 0x80be9f5d, 0x8db59154, 0x9aa8834f, 0x97a38d46]);
        U4 = new Uint32Array([0x00000000, 0x090d0b0e, 0x121a161c, 0x1b171d12, 0x24342c38, 0x2d392736, 0x362e3a24, 0x3f23312a, 0x48685870, 0x4165537e, 0x5a724e6c, 0x537f4562, 0x6c5c7448, 0x65517f46, 0x7e466254, 0x774b695a, 0x90d0b0e0, 0x99ddbbee, 0x82caa6fc, 0x8bc7adf2, 0xb4e49cd8, 0xbde997d6, 0xa6fe8ac4, 0xaff381ca, 0xd8b8e890, 0xd1b5e39e, 0xcaa2fe8c, 0xc3aff582, 0xfc8cc4a8, 0xf581cfa6, 0xee96d2b4, 0xe79bd9ba, 0x3bbb7bdb, 0x32b670d5, 0x29a16dc7, 0x20ac66c9, 0x1f8f57e3, 0x16825ced, 0x0d9541ff, 0x04984af1, 0x73d323ab, 0x7ade28a5, 0x61c935b7, 0x68c43eb9, 0x57e70f93, 0x5eea049d, 0x45fd198f, 0x4cf01281, 0xab6bcb3b, 0xa266c035, 0xb971dd27, 0xb07cd629, 0x8f5fe703, 0x8652ec0d, 0x9d45f11f, 0x9448fa11, 0xe303934b, 0xea0e9845, 0xf1198557, 0xf8148e59, 0xc737bf73, 0xce3ab47d, 0xd52da96f, 0xdc20a261, 0x766df6ad, 0x7f60fda3, 0x6477e0b1, 0x6d7aebbf, 0x5259da95, 0x5b54d19b, 0x4043cc89, 0x494ec787, 0x3e05aedd, 0x3708a5d3, 0x2c1fb8c1, 0x2512b3cf, 0x1a3182e5, 0x133c89eb, 0x082b94f9, 0x01269ff7, 0xe6bd464d, 0xefb04d43, 0xf4a75051, 0xfdaa5b5f, 0xc2896a75, 0xcb84617b, 0xd0937c69, 0xd99e7767, 0xaed51e3d, 0xa7d81533, 0xbccf0821, 0xb5c2032f, 0x8ae13205, 0x83ec390b, 0x98fb2419, 0x91f62f17, 0x4dd68d76, 0x44db8678, 0x5fcc9b6a, 0x56c19064, 0x69e2a14e, 0x60efaa40, 0x7bf8b752, 0x72f5bc5c, 0x05bed506, 0x0cb3de08, 0x17a4c31a, 0x1ea9c814, 0x218af93e, 0x2887f230, 0x3390ef22, 0x3a9de42c, 0xdd063d96, 0xd40b3698, 0xcf1c2b8a, 0xc6112084, 0xf93211ae, 0xf03f1aa0, 0xeb2807b2, 0xe2250cbc, 0x956e65e6, 0x9c636ee8, 0x877473fa, 0x8e7978f4, 0xb15a49de, 0xb85742d0, 0xa3405fc2, 0xaa4d54cc, 0xecdaf741, 0xe5d7fc4f, 0xfec0e15d, 0xf7cdea53, 0xc8eedb79, 0xc1e3d077, 0xdaf4cd65, 0xd3f9c66b, 0xa4b2af31, 0xadbfa43f, 0xb6a8b92d, 0xbfa5b223, 0x80868309, 0x898b8807, 0x929c9515, 0x9b919e1b, 0x7c0a47a1, 0x75074caf, 0x6e1051bd, 0x671d5ab3, 0x583e6b99, 0x51336097, 0x4a247d85, 0x4329768b, 0x34621fd1, 0x3d6f14df, 0x267809cd, 0x2f7502c3, 0x105633e9, 0x195b38e7, 0x024c25f5, 0x0b412efb, 0xd7618c9a, 0xde6c8794, 0xc57b9a86, 0xcc769188, 0xf355a0a2, 0xfa58abac, 0xe14fb6be, 0xe842bdb0, 0x9f09d4ea, 0x9604dfe4, 0x8d13c2f6, 0x841ec9f8, 0xbb3df8d2, 0xb230f3dc, 0xa927eece, 0xa02ae5c0, 0x47b13c7a, 0x4ebc3774, 0x55ab2a66, 0x5ca62168, 0x63851042, 0x6a881b4c, 0x719f065e, 0x78920d50, 0x0fd9640a, 0x06d46f04, 0x1dc37216, 0x14ce7918, 0x2bed4832, 0x22e0433c, 0x39f75e2e, 0x30fa5520, 0x9ab701ec, 0x93ba0ae2, 0x88ad17f0, 0x81a01cfe, 0xbe832dd4, 0xb78e26da, 0xac993bc8, 0xa59430c6, 0xd2df599c, 0xdbd25292, 0xc0c54f80, 0xc9c8448e, 0xf6eb75a4, 0xffe67eaa, 0xe4f163b8, 0xedfc68b6, 0x0a67b10c, 0x036aba02, 0x187da710, 0x1170ac1e, 0x2e539d34, 0x275e963a, 0x3c498b28, 0x35448026, 0x420fe97c, 0x4b02e272, 0x5015ff60, 0x5918f46e, 0x663bc544, 0x6f36ce4a, 0x7421d358, 0x7d2cd856, 0xa10c7a37, 0xa8017139, 0xb3166c2b, 0xba1b6725, 0x8538560f, 0x8c355d01, 0x97224013, 0x9e2f4b1d, 0xe9642247, 0xe0692949, 0xfb7e345b, 0xf2733f55, 0xcd500e7f, 0xc45d0571, 0xdf4a1863, 0xd647136d, 0x31dccad7, 0x38d1c1d9, 0x23c6dccb, 0x2acbd7c5, 0x15e8e6ef, 0x1ce5ede1, 0x07f2f0f3, 0x0efffbfd, 0x79b492a7, 0x70b999a9, 0x6bae84bb, 0x62a38fb5, 0x5d80be9f, 0x548db591, 0x4f9aa883, 0x4697a38d]);
        function AES() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            AES.prototype.__init__.apply(this, arguments);
        }
        AES.prototype.__init__ = function __init__(key) {
            var self = this;
            var rounds, round_key_count, KC, tk, index, rconpointer, t, tt, i, r, c;
            self.working_mem = ρσ_list_decorate([ new Uint32Array(4), new Uint32Array(4) ]);
            rounds = number_of_rounds[ρσ_bound_index(key.length, number_of_rounds)];
            if (!rounds) {
                throw new ValueError("invalid key size (must be length 16, 24 or 32)");
            }
            self._Ke = [];
            self._Kd = [];
            for (var i = 0; i <= rounds; i++) {
                self._Ke.push(new Uint32Array(4));
                self._Kd.push(new Uint32Array(4));
            }
            round_key_count = (rounds + 1) * 4;
            KC = key.length / 4;
            tk = new Uint32Array(KC);
            convert_to_int32(key, tk);
            index = 0;
            for (var i = 0; i < KC; i++) {
                index = i >> 2;
                (ρσ_expr_temp = (ρσ_expr_temp = self._Ke)[(typeof index === "number" && index < 0) ? ρσ_expr_temp.length + index : index])[ρσ_bound_index(i % 4, ρσ_expr_temp)] = tk[(typeof i === "number" && i < 0) ? tk.length + i : i];
                (ρσ_expr_temp = (ρσ_expr_temp = self._Kd)[ρσ_bound_index(rounds - index, ρσ_expr_temp)])[ρσ_bound_index(i % 4, ρσ_expr_temp)] = tk[(typeof i === "number" && i < 0) ? tk.length + i : i];
            }
            rconpointer = 0;
            t = KC;
            while (t < round_key_count) {
                tt = tk[ρσ_bound_index(KC - 1, tk)];
                tk[0] ^= S[ρσ_bound_index(tt >> 16 & 255, S)] << 24 ^ S[ρσ_bound_index(tt >> 8 & 255, S)] << 16 ^ S[ρσ_bound_index(tt & 255, S)] << 8 ^ S[ρσ_bound_index(tt >> 24 & 255, S)] ^ rcon[(typeof rconpointer === "number" && rconpointer < 0) ? rcon.length + rconpointer : rconpointer] << 24;
                rconpointer += 1;
                if ((KC !== 8 && (typeof KC !== "object" || ρσ_not_equals(KC, 8)))) {
                    for (var i = 1; i < KC; i++) {
                        tk[(typeof i === "number" && i < 0) ? tk.length + i : i] ^= tk[ρσ_bound_index(i - 1, tk)];
                    }
                } else {
                    for (var i = 1; i < (KC / 2); i++) {
                        tk[(typeof i === "number" && i < 0) ? tk.length + i : i] ^= tk[ρσ_bound_index(i - 1, tk)];
                    }
                    tt = tk[ρσ_bound_index(KC / 2 - 1, tk)];
                    tk[ρσ_bound_index(KC / 2, tk)] ^= S[ρσ_bound_index(tt & 255, S)] ^ S[ρσ_bound_index(tt >> 8 & 255, S)] << 8 ^ S[ρσ_bound_index(tt >> 16 & 255, S)] << 16 ^ S[ρσ_bound_index(tt >> 24 & 255, S)] << 24;
                    for (var i = (KC / 2) + 1; i < KC; i++) {
                        tk[(typeof i === "number" && i < 0) ? tk.length + i : i] ^= tk[ρσ_bound_index(i - 1, tk)];
                    }
                }
                i = 0;
                while (i < KC && t < round_key_count) {
                    r = t >> 2;
                    c = t % 4;
                    (ρσ_expr_temp = (ρσ_expr_temp = self._Ke)[(typeof r === "number" && r < 0) ? ρσ_expr_temp.length + r : r])[(typeof c === "number" && c < 0) ? ρσ_expr_temp.length + c : c] = tk[(typeof i === "number" && i < 0) ? tk.length + i : i];
                    (ρσ_expr_temp = (ρσ_expr_temp = self._Kd)[ρσ_bound_index(rounds - r, ρσ_expr_temp)])[(typeof c === "number" && c < 0) ? ρσ_expr_temp.length + c : c] = tk[ρσ_bound_index(i++, tk)];
                    t += 1;
                }
            }
            for (var r = 1; r < rounds; r++) {
                for (var c = 0; c < 4; c++) {
                    tt = (ρσ_expr_temp = (ρσ_expr_temp = self._Kd)[(typeof r === "number" && r < 0) ? ρσ_expr_temp.length + r : r])[(typeof c === "number" && c < 0) ? ρσ_expr_temp.length + c : c];
                    (ρσ_expr_temp = (ρσ_expr_temp = self._Kd)[(typeof r === "number" && r < 0) ? ρσ_expr_temp.length + r : r])[(typeof c === "number" && c < 0) ? ρσ_expr_temp.length + c : c] = U1[ρσ_bound_index(tt >> 24 & 255, U1)] ^ U2[ρσ_bound_index(tt >> 16 & 255, U2)] ^ U3[ρσ_bound_index(tt >> 8 & 255, U3)] ^ U4[ρσ_bound_index(tt & 255, U4)];
                }
            }
        };
        if (!AES.prototype.__init__.__argnames__) Object.defineProperties(AES.prototype.__init__, {
            __argnames__ : {value: ["key"]},
            __module__ : {value: "aes"}
        });
        AES.__argnames__ = AES.prototype.__init__.__argnames__;
        AES.__handles_kwarg_interpolation__ = AES.prototype.__init__.__handles_kwarg_interpolation__;
        AES.prototype._crypt = function _crypt(ciphertext, offset, encrypt) {
            var self = this;
            var R1, R2, R3, R4, o1, o3, SB, K, rounds, a, t, tt;
            if (encrypt) {
                R1 = T1;
                R2 = T2;
                R3 = T3;
                R4 = T4;
                o1 = 1;
                o3 = 3;
                SB = S;
                K = self._Ke;
            } else {
                R1 = T5;
                R2 = T6;
                R3 = T7;
                R4 = T8;
                o1 = 3;
                o3 = 1;
                SB = Si;
                K = self._Kd;
            }
            rounds = K.length - 1;
            a = self.working_mem[0];
            t = self.working_mem[1];
            for (var i = 0; i < 4; i++) {
                t[(typeof i === "number" && i < 0) ? t.length + i : i] ^= (ρσ_expr_temp = K[0])[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
            }
            for (var r = 1; r < rounds; r++) {
                for (var i = 0; i < 4; i++) {
                    a[(typeof i === "number" && i < 0) ? a.length + i : i] = R1[ρσ_bound_index(t[(typeof i === "number" && i < 0) ? t.length + i : i] >> 24 & 255, R1)] ^ R2[ρσ_bound_index(t[ρσ_bound_index((i + o1) % 4, t)] >> 16 & 255, R2)] ^ R3[ρσ_bound_index(t[ρσ_bound_index((i + 2) % 4, t)] >> 8 & 255, R3)] ^ R4[ρσ_bound_index(t[ρσ_bound_index((i + o3) % 4, t)] & 255, R4)] ^ (ρσ_expr_temp = K[(typeof r === "number" && r < 0) ? K.length + r : r])[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
                }
                t.set(a);
            }
            for (var i = 0; i < 4; i++) {
                tt = (ρσ_expr_temp = K[(typeof rounds === "number" && rounds < 0) ? K.length + rounds : rounds])[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
                ciphertext[ρσ_bound_index(offset + 4 * i, ciphertext)] = (SB[ρσ_bound_index(t[(typeof i === "number" && i < 0) ? t.length + i : i] >> 24 & 255, SB)] ^ tt >> 24) & 255;
                ciphertext[ρσ_bound_index(offset + 4 * i + 1, ciphertext)] = (SB[ρσ_bound_index(t[ρσ_bound_index((i + o1) % 4, t)] >> 16 & 255, SB)] ^ tt >> 16) & 255;
                ciphertext[ρσ_bound_index(offset + 4 * i + 2, ciphertext)] = (SB[ρσ_bound_index(t[ρσ_bound_index((i + 2) % 4, t)] >> 8 & 255, SB)] ^ tt >> 8) & 255;
                ciphertext[ρσ_bound_index(offset + 4 * i + 3, ciphertext)] = (SB[ρσ_bound_index(t[ρσ_bound_index((i + o3) % 4, t)] & 255, SB)] ^ tt) & 255;
            }
        };
        if (!AES.prototype._crypt.__argnames__) Object.defineProperties(AES.prototype._crypt, {
            __argnames__ : {value: ["ciphertext", "offset", "encrypt"]},
            __module__ : {value: "aes"}
        });
        AES.prototype.encrypt = function encrypt(plaintext, ciphertext, offset) {
            var self = this;
            convert_to_int32(plaintext, self.working_mem[1], offset, 16);
            return self._crypt(ciphertext, offset, true);
        };
        if (!AES.prototype.encrypt.__argnames__) Object.defineProperties(AES.prototype.encrypt, {
            __argnames__ : {value: ["plaintext", "ciphertext", "offset"]},
            __module__ : {value: "aes"}
        });
        AES.prototype.encrypt32 = function encrypt32(plaintext, ciphertext, offset) {
            var self = this;
            self.working_mem[1].set(plaintext);
            return self._crypt(ciphertext, offset, true);
        };
        if (!AES.prototype.encrypt32.__argnames__) Object.defineProperties(AES.prototype.encrypt32, {
            __argnames__ : {value: ["plaintext", "ciphertext", "offset"]},
            __module__ : {value: "aes"}
        });
        AES.prototype.decrypt = function decrypt(ciphertext, plaintext, offset) {
            var self = this;
            convert_to_int32(ciphertext, self.working_mem[1], offset, 16);
            return self._crypt(plaintext, offset, false);
        };
        if (!AES.prototype.decrypt.__argnames__) Object.defineProperties(AES.prototype.decrypt, {
            __argnames__ : {value: ["ciphertext", "plaintext", "offset"]},
            __module__ : {value: "aes"}
        });
        AES.prototype.decrypt32 = function decrypt32(ciphertext, plaintext, offset) {
            var self = this;
            self.working_mem[1].set(ciphertext);
            return self._crypt(plaintext, offset, false);
        };
        if (!AES.prototype.decrypt32.__argnames__) Object.defineProperties(AES.prototype.decrypt32, {
            __argnames__ : {value: ["ciphertext", "plaintext", "offset"]},
            __module__ : {value: "aes"}
        });
        AES.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        AES.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(AES.prototype, "__bases__", {value: []});

        function random_bytes_insecure(sz) {
            var ans;
            ans = new Uint8Array(sz);
            for (var i = 0; i < sz; i++) {
                ans[(typeof i === "number" && i < 0) ? ans.length + i : i] = Math.floor(Math.random() * 256);
            }
            return ans;
        };
        if (!random_bytes_insecure.__argnames__) Object.defineProperties(random_bytes_insecure, {
            __argnames__ : {value: ["sz"]},
            __module__ : {value: "aes"}
        });

        function random_bytes_secure(sz) {
            var ans;
            ans = new Uint8Array(sz);
            crypto.getRandomValues(ans);
            return ans;
        };
        if (!random_bytes_secure.__argnames__) Object.defineProperties(random_bytes_secure, {
            __argnames__ : {value: ["sz"]},
            __module__ : {value: "aes"}
        });

        random_bytes = (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") ? random_bytes_secure : random_bytes_insecure;
        if (random_bytes === random_bytes_insecure) {
            try {
                noderandom = require("crypto").randomBytes;
                random_bytes = (function() {
                    var ρσ_anonfunc = function (sz) {
                        return new Uint8Array(noderandom(sz));
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["sz"]},
                        __module__ : {value: "aes"}
                    });
                    return ρσ_anonfunc;
                })();
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    print("WARNING: Using insecure RNG for AES");
                } 
            }
        }
        function ModeOfOperation() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ModeOfOperation.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperties(ModeOfOperation.prototype,  {
            "key_as_js": {
                "enumerable": true, 
                "get": function key_as_js() {
                    var self = this;
                    return typed_array_as_js(self.key);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        ModeOfOperation.prototype.__init__ = function __init__(key) {
            var self = this;
            self.key = key || generate_key(32);
            self.aes = new AES(self.key);
        };
        if (!ModeOfOperation.prototype.__init__.__argnames__) Object.defineProperties(ModeOfOperation.prototype.__init__, {
            __argnames__ : {value: ["key"]},
            __module__ : {value: "aes"}
        });
        ModeOfOperation.__argnames__ = ModeOfOperation.prototype.__init__.__argnames__;
        ModeOfOperation.__handles_kwarg_interpolation__ = ModeOfOperation.prototype.__init__.__handles_kwarg_interpolation__;
        ModeOfOperation.prototype.tag_as_bytes = function tag_as_bytes(tag) {
            var self = this;
            if (ρσ_instanceof(tag, Uint8Array)) {
                return tag;
            }
            if (!tag) {
                return new Uint8Array(0);
            }
            if (typeof tag === "string") {
                return string_to_bytes(tag);
            }
            throw new TypeError("Invalid tag, must be a string or a Uint8Array");
        };
        if (!ModeOfOperation.prototype.tag_as_bytes.__argnames__) Object.defineProperties(ModeOfOperation.prototype.tag_as_bytes, {
            __argnames__ : {value: ["tag"]},
            __module__ : {value: "aes"}
        });
        ModeOfOperation.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ModeOfOperation.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ModeOfOperation.prototype, "__bases__", {value: []});
        

        function GaloisField() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            GaloisField.prototype.__init__.apply(this, arguments);
        }
        GaloisField.prototype.__init__ = function __init__(sub_key) {
            var self = this;
            var k32;
            k32 = new Uint32Array(4);
            convert_to_int32(sub_key, k32, 0);
            self.m = self.generate_hash_table(k32);
            self.wmem = new Uint32Array(4);
        };
        if (!GaloisField.prototype.__init__.__argnames__) Object.defineProperties(GaloisField.prototype.__init__, {
            __argnames__ : {value: ["sub_key"]},
            __module__ : {value: "aes"}
        });
        GaloisField.__argnames__ = GaloisField.prototype.__init__.__argnames__;
        GaloisField.__handles_kwarg_interpolation__ = GaloisField.prototype.__init__.__handles_kwarg_interpolation__;
        GaloisField.prototype.power = function power(x, out) {
            var self = this;
            var lsb;
            lsb = x[3] & 1;
            for (var i = 3; i > 0; --i) {
                out[(typeof i === "number" && i < 0) ? out.length + i : i] = x[(typeof i === "number" && i < 0) ? x.length + i : i] >>> 1 | (x[ρσ_bound_index(i - 1, x)] & 1) << 31;
            }
            out[0] = x[0] >>> 1;
            if (lsb) {
                out[0] ^= 3774873600;
            }
        };
        if (!GaloisField.prototype.power.__argnames__) Object.defineProperties(GaloisField.prototype.power, {
            __argnames__ : {value: ["x", "out"]},
            __module__ : {value: "aes"}
        });
        GaloisField.prototype.multiply = function multiply(x, y) {
            var self = this;
            var z_i, v_i, x_i;
            z_i = new Uint32Array(4);
            v_i = new Uint32Array(y);
            for (var i = 0; i < 128; ++i) {
                x_i = x[ρσ_bound_index(i / 32 | 0, x)] & 1 << 31 - i % 32;
                if (x_i) {
                    z_i[0] ^= v_i[0];
                    z_i[1] ^= v_i[1];
                    z_i[2] ^= v_i[2];
                    z_i[3] ^= v_i[3];
                }
                self.power(v_i, v_i);
            }
            return z_i;
        };
        if (!GaloisField.prototype.multiply.__argnames__) Object.defineProperties(GaloisField.prototype.multiply, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "aes"}
        });
        GaloisField.prototype.generate_sub_hash_table = function generate_sub_hash_table(mid) {
            var self = this;
            var bits, size, half, m, i, m_i, m_j, x, y;
            bits = mid.length;
            size = 1 << bits;
            half = size >>> 1;
            m = new Array(size);
            m[(typeof half === "number" && half < 0) ? m.length + half : half] = new Uint32Array(mid);
            i = half >>> 1;
            while (i > 0) {
                m[(typeof i === "number" && i < 0) ? m.length + i : i] = new Uint32Array(4);
                self.power(m[ρσ_bound_index(2 * i, m)], m[(typeof i === "number" && i < 0) ? m.length + i : i]);
                i >>= 1;
            }
            i = 2;
            while (i < half) {
                for (var j = 1; j < i; ++j) {
                    m_i = m[(typeof i === "number" && i < 0) ? m.length + i : i];
                    m_j = m[(typeof j === "number" && j < 0) ? m.length + j : j];
                    m[ρσ_bound_index(i + j, m)] = x = new Uint32Array(4);
                    for (var c = 0; c < 4; c++) {
                        x[(typeof c === "number" && c < 0) ? x.length + c : c] = m_i[(typeof c === "number" && c < 0) ? m_i.length + c : c] ^ m_j[(typeof c === "number" && c < 0) ? m_j.length + c : c];
                    }
                }
                i *= 2;
            }
            m[0] = new Uint32Array(4);
            for (i = half + 1; i < size; ++i) {
                x = m[ρσ_bound_index(i ^ half, m)];
                m[(typeof i === "number" && i < 0) ? m.length + i : i] = y = new Uint32Array(4);
                for (var c = 0; c < 4; c++) {
                    y[(typeof c === "number" && c < 0) ? y.length + c : c] = mid[(typeof c === "number" && c < 0) ? mid.length + c : c] ^ x[(typeof c === "number" && c < 0) ? x.length + c : c];
                }
            }
            return m;
        };
        if (!GaloisField.prototype.generate_sub_hash_table.__argnames__) Object.defineProperties(GaloisField.prototype.generate_sub_hash_table, {
            __argnames__ : {value: ["mid"]},
            __module__ : {value: "aes"}
        });
        GaloisField.prototype.generate_hash_table = function generate_hash_table(key_as_int32_array) {
            var self = this;
            var bits, multiplier, per_int, size, ans, tmp, idx, shft;
            bits = key_as_int32_array.length;
            multiplier = 8 / bits;
            per_int = 4 * multiplier;
            size = 16 * multiplier;
            ans = new Array(size);
            for (var i =0; i < size; ++i) {
                tmp = new Uint32Array(4);
                idx = i / per_int | 0;
                shft = (per_int - 1 - i % per_int) * bits;
                tmp[(typeof idx === "number" && idx < 0) ? tmp.length + idx : idx] = 1 << bits - 1 << shft;
                ans[(typeof i === "number" && i < 0) ? ans.length + i : i] = self.generate_sub_hash_table(self.multiply(tmp, key_as_int32_array));
            }
            return ans;
        };
        if (!GaloisField.prototype.generate_hash_table.__argnames__) Object.defineProperties(GaloisField.prototype.generate_hash_table, {
            __argnames__ : {value: ["key_as_int32_array"]},
            __module__ : {value: "aes"}
        });
        GaloisField.prototype.table_multiply = function table_multiply(x) {
            var self = this;
            var z, idx, x_i, ah;
            z = new Uint32Array(4);
            for (var i = 0; i < 32; ++i) {
                idx = i / 8 | 0;
                x_i = x[(typeof idx === "number" && idx < 0) ? x.length + idx : idx] >>> (7 - i % 8) * 4 & 15;
                ah = (ρσ_expr_temp = (ρσ_expr_temp = self.m)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i])[(typeof x_i === "number" && x_i < 0) ? ρσ_expr_temp.length + x_i : x_i];
                z[0] ^= ah[0];
                z[1] ^= ah[1];
                z[2] ^= ah[2];
                z[3] ^= ah[3];
            }
            return z;
        };
        if (!GaloisField.prototype.table_multiply.__argnames__) Object.defineProperties(GaloisField.prototype.table_multiply, {
            __argnames__ : {value: ["x"]},
            __module__ : {value: "aes"}
        });
        GaloisField.prototype.ghash = function ghash(x, y) {
            var self = this;
            var z;
            z = self.wmem;
            z[0] = y[0] ^ x[0];
            z[1] = y[1] ^ x[1];
            z[2] = y[2] ^ x[2];
            z[3] = y[3] ^ x[3];
            return self.table_multiply(z);
        };
        if (!GaloisField.prototype.ghash.__argnames__) Object.defineProperties(GaloisField.prototype.ghash, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "aes"}
        });
        GaloisField.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        GaloisField.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(GaloisField.prototype, "__bases__", {value: []});

        function generate_key(sz) {
            if (!number_of_rounds[(typeof sz === "number" && sz < 0) ? number_of_rounds.length + sz : sz]) {
                throw new ValueError("Invalid key size, must be: 16, 24 or 32");
            }
            return random_bytes(sz);
        };
        if (!generate_key.__argnames__) Object.defineProperties(generate_key, {
            __argnames__ : {value: ["sz"]},
            __module__ : {value: "aes"}
        });

        function generate_tag(sz) {
            return random_bytes(sz || 32);
        };
        if (!generate_tag.__argnames__) Object.defineProperties(generate_tag, {
            __argnames__ : {value: ["sz"]},
            __module__ : {value: "aes"}
        });

        function typed_array_as_js(x) {
            var name;
            name = x.constructor.name || "Uint8Array";
            return "(new " + name + "(" + JSON.stringify(Array.prototype.slice.call(x)) + "))";
        };
        if (!typed_array_as_js.__argnames__) Object.defineProperties(typed_array_as_js, {
            __argnames__ : {value: ["x"]},
            __module__ : {value: "aes"}
        });

        function CBC() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            CBC.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(CBC, ModeOfOperation);
        CBC.prototype.__init__ = function __init__ () {
            ModeOfOperation.prototype.__init__ && ModeOfOperation.prototype.__init__.apply(this, arguments);
        };
        CBC.prototype.encrypt_bytes = function encrypt_bytes(bytes, tag_bytes, iv) {
            var self = this;
            var first_iv, mlen, padsz, inputbytes, offset, outputbytes, ρσ_unpack;
            iv = first_iv = iv || random_bytes(16);
            mlen = bytes.length + tag_bytes.length;
            padsz = (16 - mlen % 16) % 16;
            inputbytes = new Uint8Array(mlen + padsz);
            if (tag_bytes.length) {
                inputbytes.set(tag_bytes);
            }
            inputbytes.set(bytes, tag_bytes.length);
            offset = 0;
            outputbytes = new Uint8Array(inputbytes.length);
            for (var block = 0; block < inputbytes.length; block += 16) {
                if (block > 0) {
                    ρσ_unpack = [outputbytes, block - 16];
                    iv = ρσ_unpack[0];
                    offset = ρσ_unpack[1];
                }
                for (var i = 0; i < 16; i++) {
                    inputbytes[ρσ_bound_index(block + i, inputbytes)] ^= iv[ρσ_bound_index(offset + i, iv)];
                }
                self.aes.encrypt(inputbytes, outputbytes, block);
            }
            return (function(){
                var ρσ_d = {};
                ρσ_d["iv"] = first_iv;
                ρσ_d["cipherbytes"] = outputbytes;
                return ρσ_d;
            }).call(this);
        };
        if (!CBC.prototype.encrypt_bytes.__argnames__) Object.defineProperties(CBC.prototype.encrypt_bytes, {
            __argnames__ : {value: ["bytes", "tag_bytes", "iv"]},
            __module__ : {value: "aes"}
        });
        CBC.prototype.encrypt = function encrypt(plaintext, tag) {
            var self = this;
            return self.encrypt_bytes(string_to_bytes(plaintext), self.tag_as_bytes(tag));
        };
        if (!CBC.prototype.encrypt.__argnames__) Object.defineProperties(CBC.prototype.encrypt, {
            __argnames__ : {value: ["plaintext", "tag"]},
            __module__ : {value: "aes"}
        });
        CBC.prototype.decrypt_bytes = function decrypt_bytes(inputbytes, tag_bytes, iv) {
            var self = this;
            var offset, outputbytes, ρσ_unpack;
            offset = 0;
            outputbytes = new Uint8Array(inputbytes.length);
            for (var block = 0; block < inputbytes.length; block += 16) {
                self.aes.decrypt(inputbytes, outputbytes, block);
                if (block > 0) {
                    ρσ_unpack = [inputbytes, block - 16];
                    iv = ρσ_unpack[0];
                    offset = ρσ_unpack[1];
                }
                for (var i = 0; i < 16; i++) {
                    outputbytes[ρσ_bound_index(block + i, outputbytes)] ^= iv[ρσ_bound_index(offset + i, iv)];
                }
            }
            for (var i = 0; i < tag_bytes.length; i++) {
                if ((tag_bytes[(typeof i === "number" && i < 0) ? tag_bytes.length + i : i] !== outputbytes[(typeof i === "number" && i < 0) ? outputbytes.length + i : i] && (typeof tag_bytes[(typeof i === "number" && i < 0) ? tag_bytes.length + i : i] !== "object" || ρσ_not_equals(tag_bytes[(typeof i === "number" && i < 0) ? tag_bytes.length + i : i], outputbytes[(typeof i === "number" && i < 0) ? outputbytes.length + i : i])))) {
                    throw new ValueError("Corrupt message");
                }
            }
            outputbytes = outputbytes.subarray(tag_bytes.length);
            return outputbytes;
        };
        if (!CBC.prototype.decrypt_bytes.__argnames__) Object.defineProperties(CBC.prototype.decrypt_bytes, {
            __argnames__ : {value: ["inputbytes", "tag_bytes", "iv"]},
            __module__ : {value: "aes"}
        });
        CBC.prototype.decrypt = function decrypt(output_from_encrypt, tag) {
            var self = this;
            var ans;
            ans = self.decrypt_bytes(output_from_encrypt.cipherbytes, self.tag_as_bytes(tag), output_from_encrypt.iv);
            return str.rstrip(bytes_to_string(ans), "\u0000");
        };
        if (!CBC.prototype.decrypt.__argnames__) Object.defineProperties(CBC.prototype.decrypt, {
            __argnames__ : {value: ["output_from_encrypt", "tag"]},
            __module__ : {value: "aes"}
        });
        CBC.prototype.__repr__ = function __repr__ () {
            if(ModeOfOperation.prototype.__repr__) return ModeOfOperation.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        CBC.prototype.__str__ = function __str__ () {
            if(ModeOfOperation.prototype.__str__) return ModeOfOperation.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(CBC.prototype, "__bases__", {value: [ModeOfOperation]});

        function CTR() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            CTR.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(CTR, ModeOfOperation);
        CTR.prototype.__init__ = function __init__(key, iv) {
            var self = this;
            ModeOfOperation.prototype.__init__.call(self, key);
            self.wmem = new Uint8Array(16);
            self.counter_block = new Uint8Array(iv || 16);
            if ((self.counter_block.length !== 16 && (typeof self.counter_block.length !== "object" || ρσ_not_equals(self.counter_block.length, 16)))) {
                throw new ValueError("iv must be 16 bytes long");
            }
            self.counter_index = 16;
        };
        if (!CTR.prototype.__init__.__argnames__) Object.defineProperties(CTR.prototype.__init__, {
            __argnames__ : {value: ["key", "iv"]},
            __module__ : {value: "aes"}
        });
        CTR.__argnames__ = CTR.prototype.__init__.__argnames__;
        CTR.__handles_kwarg_interpolation__ = CTR.prototype.__init__.__handles_kwarg_interpolation__;
        CTR.prototype._crypt = function _crypt(bytes) {
            var self = this;
            for (var i = 0; i < bytes.length; i++, self.counter_index++) {
                if (self.counter_index === 16) {
                    self.counter_index = 0;
                    self.aes.encrypt(self.counter_block, self.wmem, 0);
                    increment_counter(self.counter_block);
                }
                bytes[(typeof i === "number" && i < 0) ? bytes.length + i : i] ^= (ρσ_expr_temp = self.wmem)[ρσ_bound_index(self.counter_index, ρσ_expr_temp)];
            }
            self.counter_index = 16;
        };
        if (!CTR.prototype._crypt.__argnames__) Object.defineProperties(CTR.prototype._crypt, {
            __argnames__ : {value: ["bytes"]},
            __module__ : {value: "aes"}
        });
        CTR.prototype.encrypt = function encrypt(plaintext, tag) {
            var self = this;
            var outbytes, counterbytes, tag_bytes, t;
            outbytes = string_to_bytes(plaintext);
            counterbytes = new Uint8Array(self.counter_block);
            if (tag) {
                tag_bytes = self.tag_as_bytes(tag);
                t = new Uint8Array(outbytes.length + tag_bytes.length);
                t.set(tag_bytes);
                t.set(outbytes, tag_bytes.length);
                outbytes = t;
            }
            self._crypt(outbytes);
            return (function(){
                var ρσ_d = {};
                ρσ_d["cipherbytes"] = outbytes;
                ρσ_d["counterbytes"] = counterbytes;
                return ρσ_d;
            }).call(this);
        };
        if (!CTR.prototype.encrypt.__argnames__) Object.defineProperties(CTR.prototype.encrypt, {
            __argnames__ : {value: ["plaintext", "tag"]},
            __module__ : {value: "aes"}
        });
        CTR.prototype.__enter__ = function __enter__() {
            var self = this;
            self.before_index = self.counter_index;
            self.before_counter = new Uint8Array(self.counter_block);
        };
        if (!CTR.prototype.__enter__.__module__) Object.defineProperties(CTR.prototype.__enter__, {
            __module__ : {value: "aes"}
        });
        CTR.prototype.__exit__ = function __exit__() {
            var self = this;
            self.counter_index = self.before_index;
            self.counter_block = self.before_counter;
        };
        if (!CTR.prototype.__exit__.__module__) Object.defineProperties(CTR.prototype.__exit__, {
            __module__ : {value: "aes"}
        });
        CTR.prototype.decrypt = function decrypt(output_from_encrypt, tag) {
            var self = this;
            var b, ρσ_with_exception, ρσ_with_suppress, offset, tag_bytes;
            b = new Uint8Array(output_from_encrypt.cipherbytes);
            ρσ_with_exception = undefined;
            var ρσ_with_clause_1 = self;
            ρσ_with_clause_1.__enter__();
            try {
                {
                    self.counter_block = output_from_encrypt.counterbytes;
                    self.counter_index = 16;
                    self._crypt(b);
                }
            } catch(e){
                ρσ_with_exception = e;
            }
            if (ρσ_with_exception === undefined){
                ρσ_with_clause_1.__exit__();
            } else {
                ρσ_with_suppress = false;
                ρσ_with_suppress |= ρσ_bool(ρσ_with_clause_1.__exit__(ρσ_with_exception.constructor, ρσ_with_exception, ρσ_with_exception.stack));
                if (!ρσ_with_suppress) throw ρσ_with_exception;
            }
            offset = 0;
            if (tag) {
                tag_bytes = self.tag_as_bytes(tag);
                for (var i = 0; i < tag_bytes.length; i++) {
                    if ((tag_bytes[(typeof i === "number" && i < 0) ? tag_bytes.length + i : i] !== b[(typeof i === "number" && i < 0) ? b.length + i : i] && (typeof tag_bytes[(typeof i === "number" && i < 0) ? tag_bytes.length + i : i] !== "object" || ρσ_not_equals(tag_bytes[(typeof i === "number" && i < 0) ? tag_bytes.length + i : i], b[(typeof i === "number" && i < 0) ? b.length + i : i])))) {
                        throw new ValueError("Corrupted message");
                    }
                }
                offset = tag_bytes.length;
            }
            return bytes_to_string(b, offset);
        };
        if (!CTR.prototype.decrypt.__argnames__) Object.defineProperties(CTR.prototype.decrypt, {
            __argnames__ : {value: ["output_from_encrypt", "tag"]},
            __module__ : {value: "aes"}
        });
        CTR.prototype.__repr__ = function __repr__ () {
            if(ModeOfOperation.prototype.__repr__) return ModeOfOperation.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        CTR.prototype.__str__ = function __str__ () {
            if(ModeOfOperation.prototype.__str__) return ModeOfOperation.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(CTR.prototype, "__bases__", {value: [ModeOfOperation]});

        function GCM() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            GCM.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(GCM, ModeOfOperation);
        GCM.prototype.__init__ = function __init__() {
            var self = this;
            var key = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var random_iv = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.random_iv : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "random_iv")){
                random_iv = ρσ_kwargs_obj.random_iv;
            }
            var H;
            ModeOfOperation.prototype.__init__.call(self, key);
            self.random_iv = random_iv;
            if (!random_iv) {
                self.current_iv = new Uint8Array(12);
            }
            H = new Uint8Array(16);
            self.aes.encrypt(new Uint8Array(16), H, 0);
            self.galois = new GaloisField(H);
            self.J0 = new Uint32Array(4);
            self.wmem = new Uint32Array(4);
            self.byte_block = new Uint8Array(16);
        };
        if (!GCM.prototype.__init__.__defaults__) Object.defineProperties(GCM.prototype.__init__, {
            __defaults__ : {value: {random_iv:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["key", "random_iv"]},
            __module__ : {value: "aes"}
        });
        GCM.__argnames__ = GCM.prototype.__init__.__argnames__;
        GCM.__handles_kwarg_interpolation__ = GCM.prototype.__init__.__handles_kwarg_interpolation__;
        GCM.prototype.increment_iv = function increment_iv() {
            var self = this;
            var c;
            c = self.current_iv;
            for (var i = 11; i >=0; i--) {
                if (c[(typeof i === "number" && i < 0) ? c.length + i : i] === 255) {
                    if (i === 0) {
                        throw new ValueError("The GCM IV space is exhausted, cannot encrypt anymore messages with this key as doing so would cause the IV to repeat");
                    }
                    c[(typeof i === "number" && i < 0) ? c.length + i : i] = 0;
                } else {
                    c[(typeof i === "number" && i < 0) ? c.length + i : i] += 1;
                    break;
                }
            }
        };
        if (!GCM.prototype.increment_iv.__module__) Object.defineProperties(GCM.prototype.increment_iv, {
            __module__ : {value: "aes"}
        });
        GCM.prototype._create_j0 = function _create_j0(iv) {
            var self = this;
            var J0, tmp;
            J0 = self.J0;
            if (iv.length === 12) {
                convert_to_int32(iv, J0);
                J0[3] = 1;
            } else {
                J0.fill(0);
                tmp = convert_to_int32_pad(iv);
                while (tmp.length) {
                    J0 = self.galois.ghash(J0, tmp);
                    tmp = tmp.subarray(4);
                }
                tmp = new Uint32Array(4);
                tmp.set(from_64_to_32(iv.length * 8), 2);
                J0 = self.galois.ghash(J0, tmp);
            }
            return J0;
        };
        if (!GCM.prototype._create_j0.__argnames__) Object.defineProperties(GCM.prototype._create_j0, {
            __argnames__ : {value: ["iv"]},
            __module__ : {value: "aes"}
        });
        GCM.prototype._start = function _start(iv, additional_data) {
            var self = this;
            var J0, in_block, S, overflow;
            J0 = self._create_j0(iv);
            in_block = new Uint32Array(J0);
            in_block[3] = in_block[3] + 1 & 4294967295;
            S = new Uint32Array(4);
            overflow = additional_data.length % 16;
            for (var i = 0; i < additional_data.length - overflow; i += 16) {
                convert_to_int32(additional_data, self.wmem, i, 16);
                S = self.galois.ghash(S, self.wmem);
            }
            if (overflow) {
                self.byte_block.fill(0);
                self.byte_block.set(additional_data.subarray(additional_data.length - overflow));
                convert_to_int32(self.byte_block, self.wmem);
                S = self.galois.ghash(S, self.wmem);
            }
            return [J0, in_block, S];
        };
        if (!GCM.prototype._start.__argnames__) Object.defineProperties(GCM.prototype._start, {
            __argnames__ : {value: ["iv", "additional_data"]},
            __module__ : {value: "aes"}
        });
        GCM.prototype._finish = function _finish(iv, J0, adata_len, S, outbytes) {
            var self = this;
            var lengths, tag;
            lengths = new Uint32Array(4);
            lengths.set(from_64_to_32(adata_len * 8));
            lengths.set(from_64_to_32(outbytes.length * 8), 2);
            S = self.galois.ghash(S, lengths);
            self.aes.encrypt32(J0, self.byte_block, 0);
            convert_to_int32(self.byte_block, self.wmem);
            tag = new Uint32Array(4);
            for (var i = 0; i < S.length; i++) {
                tag[(typeof i === "number" && i < 0) ? tag.length + i : i] = S[(typeof i === "number" && i < 0) ? S.length + i : i] ^ (ρσ_expr_temp = self.wmem)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
            }
            return (function(){
                var ρσ_d = {};
                ρσ_d["iv"] = iv;
                ρσ_d["cipherbytes"] = outbytes;
                ρσ_d["tag"] = tag;
                return ρσ_d;
            }).call(this);
        };
        if (!GCM.prototype._finish.__argnames__) Object.defineProperties(GCM.prototype._finish, {
            __argnames__ : {value: ["iv", "J0", "adata_len", "S", "outbytes"]},
            __module__ : {value: "aes"}
        });
        GCM.prototype._crypt = function _crypt(iv, bytes, additional_data, decrypt) {
            var self = this;
            var ghash, outbytes, ρσ_unpack, J0, in_block, S, bb, enc, hash_bytes, counter_index, overflow;
            ghash = self.galois.ghash.bind(self.galois);
            outbytes = new Uint8Array(bytes.length);
            ρσ_unpack = self._start(iv, additional_data);
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
            J0 = ρσ_unpack[0];
            in_block = ρσ_unpack[1];
            S = ρσ_unpack[2];
            bb = self.byte_block;
            enc = self.aes.encrypt32.bind(self.aes);
            hash_bytes = (decrypt) ? bytes : outbytes;
            for (var i = 0, counter_index = 16; i < bytes.length; i++, counter_index++) {
                if (counter_index === 16) {
                    enc(in_block, bb, 0);
                    in_block[3] = in_block[3] + 1 & 4294967295;
                    counter_index = 0;
                }
                outbytes[(typeof i === "number" && i < 0) ? outbytes.length + i : i] = bytes[(typeof i === "number" && i < 0) ? bytes.length + i : i] ^ bb[(typeof counter_index === "number" && counter_index < 0) ? bb.length + counter_index : counter_index];
                if (counter_index === 15) {
                    convert_to_int32(hash_bytes, self.wmem, i - 15, 16);
                    S = ghash(S, self.wmem);
                }
            }
            overflow = outbytes.length % 16;
            if (overflow) {
                bb.fill(0);
                bb.set(hash_bytes.subarray(hash_bytes.length - overflow));
                convert_to_int32(bb, self.wmem);
                S = ghash(S, self.wmem);
            }
            return self._finish(iv, J0, additional_data.length, S, outbytes);
        };
        if (!GCM.prototype._crypt.__argnames__) Object.defineProperties(GCM.prototype._crypt, {
            __argnames__ : {value: ["iv", "bytes", "additional_data", "decrypt"]},
            __module__ : {value: "aes"}
        });
        GCM.prototype.encrypt = function encrypt(plaintext, tag) {
            var self = this;
            var iv;
            if (self.random_iv) {
                iv = random_bytes(12);
            } else {
                self.increment_iv();
                iv = self.current_iv;
            }
            return self._crypt(iv, string_to_bytes(plaintext), self.tag_as_bytes(tag), false);
        };
        if (!GCM.prototype.encrypt.__argnames__) Object.defineProperties(GCM.prototype.encrypt, {
            __argnames__ : {value: ["plaintext", "tag"]},
            __module__ : {value: "aes"}
        });
        GCM.prototype.decrypt = function decrypt(output_from_encrypt, tag) {
            var self = this;
            var ans;
            if ((output_from_encrypt.tag.length !== 4 && (typeof output_from_encrypt.tag.length !== "object" || ρσ_not_equals(output_from_encrypt.tag.length, 4)))) {
                throw new ValueError("Corrupted message");
            }
            ans = self._crypt(output_from_encrypt.iv, output_from_encrypt.cipherbytes, self.tag_as_bytes(tag), true);
            if ((ans.tag !== output_from_encrypt.tag && (typeof ans.tag !== "object" || ρσ_not_equals(ans.tag, output_from_encrypt.tag)))) {
                throw new ValueError("Corrupted message");
            }
            return bytes_to_string(ans.cipherbytes);
        };
        if (!GCM.prototype.decrypt.__argnames__) Object.defineProperties(GCM.prototype.decrypt, {
            __argnames__ : {value: ["output_from_encrypt", "tag"]},
            __module__ : {value: "aes"}
        });
        GCM.prototype.__repr__ = function __repr__ () {
            if(ModeOfOperation.prototype.__repr__) return ModeOfOperation.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        GCM.prototype.__str__ = function __str__ () {
            if(ModeOfOperation.prototype.__str__) return ModeOfOperation.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(GCM.prototype, "__bases__", {value: [ModeOfOperation]});

        ρσ_modules.aes.string_to_bytes = string_to_bytes;
        ρσ_modules.aes.bytes_to_string = bytes_to_string;
        ρσ_modules.aes.number_of_rounds = number_of_rounds;
        ρσ_modules.aes.rcon = rcon;
        ρσ_modules.aes.S = S;
        ρσ_modules.aes.Si = Si;
        ρσ_modules.aes.T1 = T1;
        ρσ_modules.aes.T2 = T2;
        ρσ_modules.aes.T3 = T3;
        ρσ_modules.aes.T4 = T4;
        ρσ_modules.aes.T5 = T5;
        ρσ_modules.aes.T6 = T6;
        ρσ_modules.aes.T7 = T7;
        ρσ_modules.aes.T8 = T8;
        ρσ_modules.aes.U1 = U1;
        ρσ_modules.aes.U2 = U2;
        ρσ_modules.aes.U3 = U3;
        ρσ_modules.aes.U4 = U4;
        ρσ_modules.aes.random_bytes = random_bytes;
        ρσ_modules.aes.noderandom = noderandom;
        ρσ_modules.aes.string_to_bytes_encoder = string_to_bytes_encoder;
        ρσ_modules.aes.string_to_bytes_slow = string_to_bytes_slow;
        ρσ_modules.aes.as_hex = as_hex;
        ρσ_modules.aes.bytes_to_string_decoder = bytes_to_string_decoder;
        ρσ_modules.aes.bytes_to_string_slow = bytes_to_string_slow;
        ρσ_modules.aes.increment_counter = increment_counter;
        ρσ_modules.aes.convert_to_int32 = convert_to_int32;
        ρσ_modules.aes.convert_to_int32_pad = convert_to_int32_pad;
        ρσ_modules.aes.from_64_to_32 = from_64_to_32;
        ρσ_modules.aes.AES = AES;
        ρσ_modules.aes.random_bytes_insecure = random_bytes_insecure;
        ρσ_modules.aes.random_bytes_secure = random_bytes_secure;
        ρσ_modules.aes.ModeOfOperation = ModeOfOperation;
        ρσ_modules.aes.GaloisField = GaloisField;
        ρσ_modules.aes.generate_key = generate_key;
        ρσ_modules.aes.generate_tag = generate_tag;
        ρσ_modules.aes.typed_array_as_js = typed_array_as_js;
        ρσ_modules.aes.CBC = CBC;
        ρσ_modules.aes.CTR = CTR;
        ρσ_modules.aes.GCM = GCM;
    })();

    (function(){
        var __name__ = "read_book.globals";
        var _boss, dark_link_color, uid, default_color_schemes, IN_DEVELOP_MODE, runtime, ui_operations, annot_id_uuid_map;
        var random_bytes = ρσ_modules.aes.random_bytes;

        var hexlify = ρσ_modules.encodings.hexlify;

        var _ = ρσ_modules.gettext.gettext;
        var register_callback = ρσ_modules.gettext.register_callback;
        var gt = ρσ_modules.gettext.gettext;

        _boss = null;
        dark_link_color = "#6cb4ee";
        function set_boss(b) {
            _boss = b;
        };
        if (!set_boss.__argnames__) Object.defineProperties(set_boss, {
            __argnames__ : {value: ["b"]},
            __module__ : {value: "read_book.globals"}
        });

        function get_boss() {
            return _boss;
        };
        if (!get_boss.__module__) Object.defineProperties(get_boss, {
            __module__ : {value: "read_book.globals"}
        });

        function current_book() {
            return current_book.book;
        };
        if (!current_book.__module__) Object.defineProperties(current_book, {
            __module__ : {value: "read_book.globals"}
        });

        current_book.book = null;
        function rtl_page_progression() {
            return (current_book().manifest.page_progression_direction === "rtl" || typeof current_book().manifest.page_progression_direction === "object" && ρσ_equals(current_book().manifest.page_progression_direction, "rtl"));
        };
        if (!rtl_page_progression.__module__) Object.defineProperties(rtl_page_progression, {
            __module__ : {value: "read_book.globals"}
        });

        function ltr_page_progression() {
            return !rtl_page_progression();
        };
        if (!ltr_page_progression.__module__) Object.defineProperties(ltr_page_progression, {
            __module__ : {value: "read_book.globals"}
        });

        uid = "calibre-" + hexlify(random_bytes(12));
        function viewport_mode_changer(val) {
            if (val) {
                viewport_mode_changer.val = val;
            }
            return viewport_mode_changer.val;
        };
        if (!viewport_mode_changer.__argnames__) Object.defineProperties(viewport_mode_changer, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "read_book.globals"}
        });

        function current_layout_mode() {
            return current_layout_mode.value;
        };
        if (!current_layout_mode.__module__) Object.defineProperties(current_layout_mode, {
            __module__ : {value: "read_book.globals"}
        });

        current_layout_mode.value = "flow";
        function set_layout_mode(val) {
            current_layout_mode.value = val;
            viewport_mode_changer()(val);
        };
        if (!set_layout_mode.__argnames__) Object.defineProperties(set_layout_mode, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "read_book.globals"}
        });

        function current_spine_item() {
            return current_spine_item.value;
        };
        if (!current_spine_item.__module__) Object.defineProperties(current_spine_item, {
            __module__ : {value: "read_book.globals"}
        });

        current_spine_item.value = null;
        function set_current_spine_item(val) {
            current_spine_item.value = val;
        };
        if (!set_current_spine_item.__argnames__) Object.defineProperties(set_current_spine_item, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "read_book.globals"}
        });

        function toc_anchor_map() {
            return toc_anchor_map.value;
        };
        if (!toc_anchor_map.__module__) Object.defineProperties(toc_anchor_map, {
            __module__ : {value: "read_book.globals"}
        });

        function set_toc_anchor_map(val) {
            toc_anchor_map.value = val;
        };
        if (!set_toc_anchor_map.__argnames__) Object.defineProperties(set_toc_anchor_map, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "read_book.globals"}
        });

        default_color_schemes = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["system"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["foreground"] = "#000000";
                ρσ_d["background"] = "#ffffff";
                ρσ_d["name"] = _("System");
                return ρσ_d;
            }).call(this);
            ρσ_d["white"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["foreground"] = "#000000";
                ρσ_d["background"] = "#ffffff";
                ρσ_d["name"] = _("White");
                return ρσ_d;
            }).call(this);
            ρσ_d["black"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["foreground"] = "#ffffff";
                ρσ_d["background"] = "#000000";
                ρσ_d["link"] = "#4f81bd";
                ρσ_d["name"] = _("Black");
                return ρσ_d;
            }).call(this);
            ρσ_d["sepia-light"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["foreground"] = "#39322B";
                ρσ_d["background"] = "#F6F3E9";
                ρσ_d["name"] = _("Sepia light");
                return ρσ_d;
            }).call(this);
            ρσ_d["sepia-dark"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["background"] = "#39322B";
                ρσ_d["foreground"] = "#F6F3E9";
                ρσ_d["link"] = "#4f81bd";
                ρσ_d["name"] = _("Sepia dark");
                return ρσ_d;
            }).call(this);
            return ρσ_d;
        }).call(this);
        function set_system_colors(spec) {
            var c;
            c = default_color_schemes.system;
            c.foreground = spec.foreground;
            c.background = spec.background;
            delete c.link;
            if (spec.link) {
                c.link = spec.link;
            }
        };
        if (!set_system_colors.__argnames__) Object.defineProperties(set_system_colors, {
            __argnames__ : {value: ["spec"]},
            __module__ : {value: "read_book.globals"}
        });

        register_callback((function() {
            var ρσ_anonfunc = function () {
                var scheme, key;
                var ρσ_Iter0 = ρσ_Iterable(default_color_schemes);
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    key = ρσ_Iter0[ρσ_Index0];
                    scheme = default_color_schemes[(typeof key === "number" && key < 0) ? default_color_schemes.length + key : key];
                    scheme.name = gt(scheme.name);
                }
                if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
                    set_system_colors((function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["background"] = "#111";
                        ρσ_d["foreground"] = "#ddd";
                        ρσ_d["link"] = dark_link_color;
                        return ρσ_d;
                    }).call(this));
                }
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "read_book.globals"}
            });
            return ρσ_anonfunc;
        })());
        IN_DEVELOP_MODE = "__IN_DEVELOP_MODE__";
        runtime = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["is_standalone_viewer"] = false;
            ρσ_d["viewer_in_full_screen"] = false;
            ρσ_d["in_develop_mode"] = IN_DEVELOP_MODE === "1";
            ρσ_d["QT_VERSION"] = 0;
            return ρσ_d;
        }).call(this);
        ui_operations = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["get_file"] = null;
            ρσ_d["get_mathjax_files"] = null;
            ρσ_d["update_url_state"] = null;
            ρσ_d["update_last_read_time"] = null;
            ρσ_d["show_error"] = null;
            ρσ_d["redisplay_book"] = null;
            ρσ_d["reload_book"] = null;
            ρσ_d["forward_gesture"] = null;
            ρσ_d["update_color_scheme"] = null;
            ρσ_d["update_font_size"] = null;
            ρσ_d["goto_cfi"] = null;
            ρσ_d["delete_book"] = null;
            ρσ_d["focus_iframe"] = null;
            ρσ_d["toggle_toc"] = null;
            ρσ_d["toggle_full_screen"] = null;
            ρσ_d["reset_reading_rates"] = null;
            ρσ_d["has_unsynced_changes"] = null;
            ρσ_d["upload_pending_annotations"] = null;
            return ρσ_d;
        }).call(this);
        annot_id_uuid_map = Object.create(null);
        function clear_annot_id_uuid_map() {
            var key;
            var ρσ_Iter1 = ρσ_Iterable(Object.keys(annot_id_uuid_map));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                key = ρσ_Iter1[ρσ_Index1];
                delete annot_id_uuid_map[key];
            }
        };
        if (!clear_annot_id_uuid_map.__module__) Object.defineProperties(clear_annot_id_uuid_map, {
            __module__ : {value: "read_book.globals"}
        });

        function is_dark_theme(set_val) {
            if ((typeof set_val !== "undefined" && set_val !== null)) {
                is_dark_theme.ans = set_val;
            }
            return !!is_dark_theme.ans;
        };
        if (!is_dark_theme.__argnames__) Object.defineProperties(is_dark_theme, {
            __argnames__ : {value: ["set_val"]},
            __module__ : {value: "read_book.globals"}
        });

        ρσ_modules["read_book.globals"]._boss = _boss;
        ρσ_modules["read_book.globals"].dark_link_color = dark_link_color;
        ρσ_modules["read_book.globals"].uid = uid;
        ρσ_modules["read_book.globals"].default_color_schemes = default_color_schemes;
        ρσ_modules["read_book.globals"].IN_DEVELOP_MODE = IN_DEVELOP_MODE;
        ρσ_modules["read_book.globals"].runtime = runtime;
        ρσ_modules["read_book.globals"].ui_operations = ui_operations;
        ρσ_modules["read_book.globals"].annot_id_uuid_map = annot_id_uuid_map;
        ρσ_modules["read_book.globals"].set_boss = set_boss;
        ρσ_modules["read_book.globals"].get_boss = get_boss;
        ρσ_modules["read_book.globals"].current_book = current_book;
        ρσ_modules["read_book.globals"].rtl_page_progression = rtl_page_progression;
        ρσ_modules["read_book.globals"].ltr_page_progression = ltr_page_progression;
        ρσ_modules["read_book.globals"].viewport_mode_changer = viewport_mode_changer;
        ρσ_modules["read_book.globals"].current_layout_mode = current_layout_mode;
        ρσ_modules["read_book.globals"].set_layout_mode = set_layout_mode;
        ρσ_modules["read_book.globals"].current_spine_item = current_spine_item;
        ρσ_modules["read_book.globals"].set_current_spine_item = set_current_spine_item;
        ρσ_modules["read_book.globals"].toc_anchor_map = toc_anchor_map;
        ρσ_modules["read_book.globals"].set_toc_anchor_map = set_toc_anchor_map;
        ρσ_modules["read_book.globals"].set_system_colors = set_system_colors;
        ρσ_modules["read_book.globals"].clear_annot_id_uuid_map = clear_annot_id_uuid_map;
        ρσ_modules["read_book.globals"].is_dark_theme = is_dark_theme;
    })();

    (function(){
        var __name__ = "book_list.router";
        var mode_handlers, default_mode_handler, read_book_mode;
        var absolute_path = ρσ_modules.ajax.absolute_path;
        var encode_query = ρσ_modules.ajax.encode_query;

        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var book_list_container_id = ρσ_modules["book_list.constants"].book_list_container_id;
        var read_book_container_id = ρσ_modules["book_list.constants"].read_book_container_id;
        var cs_top_bar_host_id = ρσ_modules["book_list.constants"].cs_top_bar_host_id;

        var get_current_query = ρσ_modules["book_list.globals"].get_current_query;
        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var current_library_id = ρσ_modules["book_list.library_data"].current_library_id;

        var clear = ρσ_modules.dom.clear;

        var close_all_modals = ρσ_modules.modals.close_all_modals;

        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var encode_query_with_path = ρσ_modules.utils.encode_query_with_path;
        var parse_url_params = ρσ_modules.utils.parse_url_params;
        var request_full_screen = ρσ_modules.utils.request_full_screen;
        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;

        mode_handlers = Object.create(null);
        default_mode_handler = null;
        read_book_mode = "read_book";
        function set_mode_handler(mode, handler) {
            mode_handlers[(typeof mode === "number" && mode < 0) ? mode_handlers.length + mode : mode] = handler;
        };
        if (!set_mode_handler.__argnames__) Object.defineProperties(set_mode_handler, {
            __argnames__ : {value: ["mode", "handler"]},
            __module__ : {value: "book_list.router"}
        });

        function set_default_mode_handler(handler) {
            default_mode_handler = handler;
        };
        if (!set_default_mode_handler.__argnames__) Object.defineProperties(set_default_mode_handler, {
            __argnames__ : {value: ["handler"]},
            __module__ : {value: "book_list.router"}
        });

        function update_window_title() {
            var subtitle = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var title = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? update_window_title.__defaults__.title : arguments[1];
            var sep = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? update_window_title.__defaults__.sep : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "title")){
                title = ρσ_kwargs_obj.title;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "sep")){
                sep = ρσ_kwargs_obj.sep;
            }
            var extra;
            extra = (subtitle) ? sep + subtitle : "";
            document.title = title + extra;
        };
        if (!update_window_title.__defaults__) Object.defineProperties(update_window_title, {
            __defaults__ : {value: {title:"calibre", sep:" :: "}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["subtitle", "title", "sep"]},
            __module__ : {value: "book_list.router"}
        });

        function is_reading_book() {
            var cq;
            cq = get_current_query();
            return cq && cq.mode === read_book_mode;
        };
        if (!is_reading_book.__module__) Object.defineProperties(is_reading_book, {
            __module__ : {value: "book_list.router"}
        });

        function apply_mode() {
            var divid, div, host;
            divid = (is_reading_book()) ? read_book_container_id : book_list_container_id;
            var ρσ_Iter0 = ρσ_Iterable(document.getElementById(divid).parentNode.childNodes);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                div = ρσ_Iter0[ρσ_Index0];
                div.style.display = (div.id === divid) ? "block" : "none";
            }
            if (is_reading_book()) {
                host = document.getElementById(cs_top_bar_host_id);
                if (host) {
                    clear(host);
                }
            }
        };
        if (!apply_mode.__module__) Object.defineProperties(apply_mode, {
            __module__ : {value: "book_list.router"}
        });

        function apply_url(ignore_handler) {
            var prev, data, cb, handler;
            try {
                if (!((window.history.state && ρσ_exists.n(window.history.state.cs_url_state)))) {
                    window.history.replaceState((function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["cs_url_state"] = true;
                        ρσ_d["cs_idx"] = 0;
                        return ρσ_d;
                    }).call(this), "", window.location.href);
                }
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                } else {
                    throw ρσ_Exception;
                }
            }
            close_all_modals();
            prev = get_current_query();
            data = parse_url_params();
            data.mode = data.mode || "book_list";
            if ((typeof prev !== "undefined" && prev !== null ? prev : Object.create(null)).mode === read_book_mode && data.mode !== read_book_mode) {
                try {
                    if (ui_operations.close_book) {
                        ui_operations.close_book();
                    }
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                    } else {
                        throw ρσ_Exception;
                    }
                }
            }
            get_current_query(data);
            apply_mode();
            try {
                cb = window.cs_update_sidebar_active;
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    cb = null;
                } else {
                    throw ρσ_Exception;
                }
            }
            if (cb) {
                try {
                    cb();
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                    } else {
                        throw ρσ_Exception;
                    }
                }
            }
            if (!ignore_handler) {
                handler = mode_handlers[ρσ_bound_index(data.mode, mode_handlers)] || default_mode_handler;
                handler(data);
            }
        };
        if (!apply_url.__argnames__) Object.defineProperties(apply_url, {
            __argnames__ : {value: ["ignore_handler"]},
            __module__ : {value: "book_list.router"}
        });

        function request_full_screen_if_wanted() {
            var opt, has_touch, at_left, likely_wants_fullscreen;
            opt = get_session_data().get("fullscreen_when_opening");
            has_touch = "ontouchstart" in window;
            at_left = window.screenLeft === 0;
            likely_wants_fullscreen = has_touch && at_left;
            if (opt === "auto" && likely_wants_fullscreen || opt === "always") {
                request_full_screen();
            }
        };
        if (!request_full_screen_if_wanted.__module__) Object.defineProperties(request_full_screen_if_wanted, {
            __module__ : {value: "book_list.router"}
        });

        function open_book() {
            var book_id = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var fmt = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var library_id = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? open_book.__defaults__.library_id : arguments[2];
            var replace = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? open_book.__defaults__.replace : arguments[3];
            var extra_query = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? open_book.__defaults__.extra_query : arguments[4];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "library_id")){
                library_id = ρσ_kwargs_obj.library_id;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "replace")){
                replace = ρσ_kwargs_obj.replace;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "extra_query")){
                extra_query = ρσ_kwargs_obj.extra_query;
            }
            var q;
            request_full_screen_if_wanted();
            library_id = library_id || current_library_id();
            q = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["book_id"] = book_id;
                ρσ_d["fmt"] = fmt;
                ρσ_d["library_id"] = library_id;
                return ρσ_d;
            }).call(this);
            if (extra_query && typeof extra_query === "object") {
                Object.assign(q, extra_query);
            }
            ρσ_interpolate_kwargs.call(this, push_state, [q].concat([ρσ_desugar_kwargs({replace: replace, mode: read_book_mode})]));
        };
        if (!open_book.__defaults__) Object.defineProperties(open_book, {
            __defaults__ : {value: {library_id:null, replace:false, extra_query:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["book_id", "fmt", "library_id", "replace", "extra_query"]},
            __module__ : {value: "book_list.router"}
        });

        function open_book_url_in_library(library_id, book_id, fmt, extra_query) {
            var ans, q;
            ans = absolute_path("");
            q = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["book_id"] = book_id;
                ρσ_d["fmt"] = fmt;
                ρσ_d["mode"] = read_book_mode;
                return ρσ_d;
            }).call(this);
            if (library_id) {
                q.library_id = library_id;
            }
            if (extra_query) {
                Object.assign(q, extra_query);
            }
            return ans + encode_query(q, "#");
        };
        if (!open_book_url_in_library.__argnames__) Object.defineProperties(open_book_url_in_library, {
            __argnames__ : {value: ["library_id", "book_id", "fmt", "extra_query"]},
            __module__ : {value: "book_list.router"}
        });

        function search_url_in_library(library_id, search, vl, sort) {
            var ans, q;
            ans = absolute_path("");
            q = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["mode"] = "book_list";
                ρσ_d["search"] = search;
                ρσ_d["panel"] = "book_list";
                return ρσ_d;
            }).call(this);
            if (library_id) {
                q.library_id = library_id;
            }
            if (vl) {
                q.vl = vl;
            }
            if (sort) {
                q.sort = sort;
            }
            return ans + encode_query(q, "#");
        };
        if (!search_url_in_library.__argnames__) Object.defineProperties(search_url_in_library, {
            __argnames__ : {value: ["library_id", "search", "vl", "sort"]},
            __module__ : {value: "book_list.router"}
        });

        function open_book_url(book_id, fmt, extra_query) {
            return open_book_url_in_library(current_library_id(), book_id, fmt, extra_query);
        };
        if (!open_book_url.__argnames__) Object.defineProperties(open_book_url, {
            __argnames__ : {value: ["book_id", "fmt", "extra_query"]},
            __module__ : {value: "book_list.router"}
        });

        function show_note() {
            var field = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var item_id = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var item_value = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var replace = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_note.__defaults__.replace : arguments[3];
            var library_id = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_note.__defaults__.library_id : arguments[4];
            var close_action = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_note.__defaults__.close_action : arguments[5];
            var panel = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_note.__defaults__.panel : arguments[6];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "replace")){
                replace = ρσ_kwargs_obj.replace;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "library_id")){
                library_id = ρσ_kwargs_obj.library_id;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "close_action")){
                close_action = ρσ_kwargs_obj.close_action;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "panel")){
                panel = ρσ_kwargs_obj.panel;
            }
            var lid, q;
            lid = library_id || current_library_id();
            q = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["field"] = field;
                ρσ_d["item"] = item_value + "";
                ρσ_d["item_id"] = (item_id || "") + "";
                ρσ_d["panel"] = panel;
                return ρσ_d;
            }).call(this);
            if (panel === "show_note") {
                q.close_action = close_action;
            }
            if (lid) {
                q.library_id = lid;
            }
            ρσ_interpolate_kwargs.call(this, push_state, [q].concat([ρσ_desugar_kwargs({replace: replace})]));
        };
        if (!show_note.__defaults__) Object.defineProperties(show_note, {
            __defaults__ : {value: {replace:false, library_id:null, close_action:"back", panel:"show_note"}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["field", "item_id", "item_value", "replace", "library_id", "close_action", "panel"]},
            __module__ : {value: "book_list.router"}
        });

        function push_state() {
            var query = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var replace = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? push_state.__defaults__.replace : arguments[1];
            var mode = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? push_state.__defaults__.mode : arguments[2];
            var call_handler = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? push_state.__defaults__.call_handler : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "replace")){
                replace = ρσ_kwargs_obj.replace;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "mode")){
                mode = ρσ_kwargs_obj.mode;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "call_handler")){
                call_handler = ρσ_kwargs_obj.call_handler;
            }
            var k, cur, cur_idx;
            query = (function() {
                var ρσ_Iter = ρσ_Iterable(query), ρσ_Result = Object.create(null), k;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    k = ρσ_Iter[ρσ_Index];
                    if (query[(typeof k === "number" && k < 0) ? query.length + k : k]) {
                        ρσ_Result[k] = (query[(typeof k === "number" && k < 0) ? query.length + k : k]);
                    }
                }
                return ρσ_Result;
            })();
            if (mode !== "book_list") {
                query.mode = mode;
            }
            query = encode_query_with_path(query);
            try {
                cur = window.history.state || Object.create(null);
                cur_idx = cur.cs_idx || 0;
                if (replace) {
                    window.history.replaceState((function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["cs_url_state"] = true;
                        ρσ_d["cs_idx"] = cur_idx;
                        return ρσ_d;
                    }).call(this), "", query);
                } else {
                    window.history.pushState((function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["cs_url_state"] = true;
                        ρσ_d["cs_idx"] = cur_idx + 1;
                        return ρσ_d;
                    }).call(this), "", query);
                }
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    if (replace) {
                        window.history.replaceState(null, "", query);
                    } else {
                        window.history.pushState(null, "", query);
                    }
                } else {
                    throw ρσ_Exception;
                }
            }
            apply_url(!call_handler);
        };
        if (!push_state.__defaults__) Object.defineProperties(push_state, {
            __defaults__ : {value: {replace:false, mode:"book_list", call_handler:true}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["query", "replace", "mode", "call_handler"]},
            __module__ : {value: "book_list.router"}
        });

        function on_pop_state(ev) {
            apply_url();
        };
        if (!on_pop_state.__argnames__) Object.defineProperties(on_pop_state, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "book_list.router"}
        });

        function back() {
            var idx, cq, handler, q;
            try {
                idx = window.history.state && window.history.state.cs_idx || 0;
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    idx = 0;
                } else {
                    throw ρσ_Exception;
                }
            }
            if (idx > 0) {
                window.history.back();
            } else {
                cq = get_current_query();
                handler = mode_handlers[ρσ_bound_index(cq.mode, mode_handlers)] || default_mode_handler;
                if (handler.back_from_current) {
                    q = handler.back_from_current(cq);
                } else {
                    q = Object.create(null);
                }
                ρσ_interpolate_kwargs.call(this, push_state, [q].concat([ρσ_desugar_kwargs({replace: true})]));
            }
        };
        if (!back.__module__) Object.defineProperties(back, {
            __module__ : {value: "book_list.router"}
        });

        function home() {
            var replace = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? home.__defaults__.replace : arguments[0];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "replace")){
                replace = ρσ_kwargs_obj.replace;
            }
            push_state(Object.create(null));
        };
        if (!home.__defaults__) Object.defineProperties(home, {
            __defaults__ : {value: {replace:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["replace"]},
            __module__ : {value: "book_list.router"}
        });

        function report_a_load_failure(container, msg, error_html) {
            var err;
            err = E.div();
            safe_set_inner_html(err, error_html);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.div(msg), err, ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.a, [_("Go back to the home page")].concat([ρσ_desugar_kwargs({onclick: (function() {
                var ρσ_anonfunc = function () {
                    ρσ_interpolate_kwargs.call(this, home, [ρσ_desugar_kwargs({replace: true})]);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.router"}
                });
                return ρσ_anonfunc;
            })(), href: "javascript: void(0)", class_: "blue-link"})]))].concat([ρσ_desugar_kwargs({style: "margin-top: 1em; border-top: solid 1px currentColor; padding-top: 1ex;"})]))].concat([ρσ_desugar_kwargs({style: "margin: 1ex 1em"})])));
        };
        if (!report_a_load_failure.__argnames__) Object.defineProperties(report_a_load_failure, {
            __argnames__ : {value: ["container", "msg", "error_html"]},
            __module__ : {value: "book_list.router"}
        });

        ρσ_modules["book_list.router"].mode_handlers = mode_handlers;
        ρσ_modules["book_list.router"].default_mode_handler = default_mode_handler;
        ρσ_modules["book_list.router"].read_book_mode = read_book_mode;
        ρσ_modules["book_list.router"].set_mode_handler = set_mode_handler;
        ρσ_modules["book_list.router"].set_default_mode_handler = set_default_mode_handler;
        ρσ_modules["book_list.router"].update_window_title = update_window_title;
        ρσ_modules["book_list.router"].is_reading_book = is_reading_book;
        ρσ_modules["book_list.router"].apply_mode = apply_mode;
        ρσ_modules["book_list.router"].apply_url = apply_url;
        ρσ_modules["book_list.router"].request_full_screen_if_wanted = request_full_screen_if_wanted;
        ρσ_modules["book_list.router"].open_book = open_book;
        ρσ_modules["book_list.router"].open_book_url_in_library = open_book_url_in_library;
        ρσ_modules["book_list.router"].search_url_in_library = search_url_in_library;
        ρσ_modules["book_list.router"].open_book_url = open_book_url;
        ρσ_modules["book_list.router"].show_note = show_note;
        ρσ_modules["book_list.router"].push_state = push_state;
        ρσ_modules["book_list.router"].on_pop_state = on_pop_state;
        ρσ_modules["book_list.router"].back = back;
        ρσ_modules["book_list.router"].home = home;
        ρσ_modules["book_list.router"].report_a_load_failure = report_a_load_failure;
    })();

    (function(){
        var __name__ = "read_book.viewport";
        var FUNCTIONS, scroll_viewport, attr;
        FUNCTIONS = "x y scroll_to scroll_into_view reset_globals __reset_transforms window_scroll_pos content_size".split(" ");
        var get_boss = ρσ_modules["read_book.globals"].get_boss;
        var viewport_mode_changer = ρσ_modules["read_book.globals"].viewport_mode_changer;

        var document_height = ρσ_modules.utils.document_height;
        var document_width = ρσ_modules.utils.document_width;
        var ios_major_version = ρσ_modules.utils.ios_major_version;

        function ScrollViewport() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ScrollViewport.prototype.__bind_methods__.call(this);
            ScrollViewport.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ScrollViewport.prototype, "__bind_methods__", {value: function () {
            this.set_mode = ScrollViewport.prototype.set_mode.bind(this);
            this.initialize_on_layout = ScrollViewport.prototype.initialize_on_layout.bind(this);
            this.flow_x = ScrollViewport.prototype.flow_x.bind(this);
            this.flow_y = ScrollViewport.prototype.flow_y.bind(this);
            this.flow_window_scroll_pos = ScrollViewport.prototype.flow_window_scroll_pos.bind(this);
            this.inline_pos = ScrollViewport.prototype.inline_pos.bind(this);
            this.block_pos = ScrollViewport.prototype.block_pos.bind(this);
            this.flow_scroll_to = ScrollViewport.prototype.flow_scroll_to.bind(this);
            this.scroll_to_in_inline_direction = ScrollViewport.prototype.scroll_to_in_inline_direction.bind(this);
            this.scroll_to_in_block_direction = ScrollViewport.prototype.scroll_to_in_block_direction.bind(this);
            this.flow_scroll_into_view = ScrollViewport.prototype.flow_scroll_into_view.bind(this);
            this.scroll_by = ScrollViewport.prototype.scroll_by.bind(this);
            this.scroll_by_in_inline_direction = ScrollViewport.prototype.scroll_by_in_inline_direction.bind(this);
            this.scroll_by_in_block_direction = ScrollViewport.prototype.scroll_by_in_block_direction.bind(this);
            this.flow_reset_globals = ScrollViewport.prototype.flow_reset_globals.bind(this);
            this.flow___reset_transforms = ScrollViewport.prototype.flow___reset_transforms.bind(this);
            this.flow_content_size = ScrollViewport.prototype.flow_content_size.bind(this);
            this.paged_content_inline_size = ScrollViewport.prototype.paged_content_inline_size.bind(this);
            this.paged_content_block_size = ScrollViewport.prototype.paged_content_block_size.bind(this);
            this.inline_size = ScrollViewport.prototype.inline_size.bind(this);
            this.block_size = ScrollViewport.prototype.block_size.bind(this);
            this.update_window_size = ScrollViewport.prototype.update_window_size.bind(this);
            this.width = ScrollViewport.prototype.width.bind(this);
            this.height = ScrollViewport.prototype.height.bind(this);
            this.document_inline_size = ScrollViewport.prototype.document_inline_size.bind(this);
            this.document_block_size = ScrollViewport.prototype.document_block_size.bind(this);
            this.viewport_to_document = ScrollViewport.prototype.viewport_to_document.bind(this);
            this.rect_inline_start = ScrollViewport.prototype.rect_inline_start.bind(this);
            this.rect_inline_end = ScrollViewport.prototype.rect_inline_end.bind(this);
            this.rect_block_start = ScrollViewport.prototype.rect_block_start.bind(this);
            this.rect_block_end = ScrollViewport.prototype.rect_block_end.bind(this);
            this.rect_inline_size = ScrollViewport.prototype.rect_inline_size.bind(this);
            this.rect_block_size = ScrollViewport.prototype.rect_block_size.bind(this);
            this.viewport_to_document_inline = ScrollViewport.prototype.viewport_to_document_inline.bind(this);
            this.viewport_to_document_block = ScrollViewport.prototype.viewport_to_document_block.bind(this);
            this.viewport_to_document_inline_block = ScrollViewport.prototype.viewport_to_document_inline_block.bind(this);
        }});
        ScrollViewport.prototype.__init__ = function __init__() {
            var self = this;
            self.set_mode("flow");
            self.window_width_from_parent = self.window_height_from_parent = null;
            self.rtl = false;
            self.ltr = true;
            self.vertical_writing_mode = false;
            self.horizontal_writing_mode = true;
        };
        if (!ScrollViewport.prototype.__init__.__module__) Object.defineProperties(ScrollViewport.prototype.__init__, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.__argnames__ = ScrollViewport.prototype.__init__.__argnames__;
        ScrollViewport.__handles_kwarg_interpolation__ = ScrollViewport.prototype.__init__.__handles_kwarg_interpolation__;
        ScrollViewport.prototype.set_mode = function set_mode(mode) {
            var self = this;
            var prefix, attr;
            prefix = ((mode === "flow") ? "flow" : "paged") + "_";
            var ρσ_Iter0 = ρσ_Iterable(FUNCTIONS);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                attr = ρσ_Iter0[ρσ_Index0];
                self[(typeof attr === "number" && attr < 0) ? self.length + attr : attr] = self[ρσ_bound_index(prefix + attr, self)];
            }
        };
        if (!ScrollViewport.prototype.set_mode.__argnames__) Object.defineProperties(ScrollViewport.prototype.set_mode, {
            __argnames__ : {value: ["mode"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.initialize_on_layout = function initialize_on_layout(body_style) {
            var self = this;
            var css_vertical_rl, css_vertical_lr;
            self.horizontal_writing_mode = true;
            self.vertical_writing_mode = false;
            self.ltr = true;
            self.rtl = false;
            if (body_style.direction === "rtl") {
                self.rtl = true;
                self.ltr = false;
            }
            css_vertical_rl = body_style.getPropertyValue("writing-mode") === "vertical-rl";
            if (css_vertical_rl) {
                self.vertical_writing_mode = true;
                self.horizontal_writing_mode = false;
                self.rtl = true;
                self.ltr = false;
            } else {
                css_vertical_lr = body_style.getPropertyValue("writing-mode") === "vertical-lr";
                if (css_vertical_lr) {
                    self.vertical_writing_mode = true;
                    self.horizontal_writing_mode = false;
                    self.ltr = true;
                    self.rtl = false;
                }
            }
        };
        if (!ScrollViewport.prototype.initialize_on_layout.__argnames__) Object.defineProperties(ScrollViewport.prototype.initialize_on_layout, {
            __argnames__ : {value: ["body_style"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.flow_x = function flow_x() {
            var self = this;
            if (self.rtl) {
                return -window.pageXOffset;
            }
            return window.pageXOffset;
        };
        if (!ScrollViewport.prototype.flow_x.__module__) Object.defineProperties(ScrollViewport.prototype.flow_x, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.flow_y = function flow_y() {
            var self = this;
            return window.pageYOffset;
        };
        if (!ScrollViewport.prototype.flow_y.__module__) Object.defineProperties(ScrollViewport.prototype.flow_y, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.flow_window_scroll_pos = function flow_window_scroll_pos() {
            var self = this;
            return [window.pageXOffset, window.pageYOffset];
        };
        if (!ScrollViewport.prototype.flow_window_scroll_pos.__module__) Object.defineProperties(ScrollViewport.prototype.flow_window_scroll_pos, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.inline_pos = function inline_pos() {
            var self = this;
            if (self.vertical_writing_mode) {
                return self.y();
            }
            return self.x();
        };
        if (!ScrollViewport.prototype.inline_pos.__module__) Object.defineProperties(ScrollViewport.prototype.inline_pos, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.block_pos = function block_pos() {
            var self = this;
            if (self.horizontal_writing_mode) {
                return self.y();
            }
            return self.x();
        };
        if (!ScrollViewport.prototype.block_pos.__module__) Object.defineProperties(ScrollViewport.prototype.block_pos, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.flow_scroll_to = function flow_scroll_to(x, y) {
            var self = this;
            if (self.rtl) {
                window.scrollTo(-x, y);
            } else {
                window.scrollTo(x, y);
            }
        };
        if (!ScrollViewport.prototype.flow_scroll_to.__argnames__) Object.defineProperties(ScrollViewport.prototype.flow_scroll_to, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.scroll_to_in_inline_direction = function scroll_to_in_inline_direction(pos, preserve_other) {
            var self = this;
            if (self.vertical_writing_mode) {
                self.scroll_to((preserve_other) ? self.x() : 0, pos);
            } else {
                self.scroll_to(pos, (preserve_other) ? self.y() : 0);
            }
        };
        if (!ScrollViewport.prototype.scroll_to_in_inline_direction.__argnames__) Object.defineProperties(ScrollViewport.prototype.scroll_to_in_inline_direction, {
            __argnames__ : {value: ["pos", "preserve_other"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.scroll_to_in_block_direction = function scroll_to_in_block_direction(pos, preserve_other) {
            var self = this;
            if (self.horizontal_writing_mode) {
                self.scroll_to((preserve_other) ? self.x() : 0, pos);
            } else {
                self.scroll_to(pos, (preserve_other) ? self.y() : 0);
            }
        };
        if (!ScrollViewport.prototype.scroll_to_in_block_direction.__argnames__) Object.defineProperties(ScrollViewport.prototype.scroll_to_in_block_direction, {
            __argnames__ : {value: ["pos", "preserve_other"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.flow_scroll_into_view = function flow_scroll_into_view(elem) {
            var self = this;
            elem.scrollIntoView();
        };
        if (!ScrollViewport.prototype.flow_scroll_into_view.__argnames__) Object.defineProperties(ScrollViewport.prototype.flow_scroll_into_view, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.scroll_by = function scroll_by(x, y) {
            var self = this;
            if (self.ltr) {
                window.scrollBy(x, y);
            } else {
                window.scrollBy(-x, y);
            }
        };
        if (!ScrollViewport.prototype.scroll_by.__argnames__) Object.defineProperties(ScrollViewport.prototype.scroll_by, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.scroll_by_in_inline_direction = function scroll_by_in_inline_direction(offset) {
            var self = this;
            if (self.vertical_writing_mode) {
                self.scroll_by(0, offset);
            } else {
                self.scroll_by(offset, 0);
            }
        };
        if (!ScrollViewport.prototype.scroll_by_in_inline_direction.__argnames__) Object.defineProperties(ScrollViewport.prototype.scroll_by_in_inline_direction, {
            __argnames__ : {value: ["offset"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.scroll_by_in_block_direction = function scroll_by_in_block_direction(offset) {
            var self = this;
            if (self.horizontal_writing_mode) {
                self.scroll_by(0, offset);
            } else {
                self.scroll_by(offset, 0);
            }
        };
        if (!ScrollViewport.prototype.scroll_by_in_block_direction.__argnames__) Object.defineProperties(ScrollViewport.prototype.scroll_by_in_block_direction, {
            __argnames__ : {value: ["offset"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.flow_reset_globals = function flow_reset_globals() {
            var self = this;
        };
        if (!ScrollViewport.prototype.flow_reset_globals.__module__) Object.defineProperties(ScrollViewport.prototype.flow_reset_globals, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.flow___reset_transforms = function flow___reset_transforms() {
            var self = this;
        };
        if (!ScrollViewport.prototype.flow___reset_transforms.__module__) Object.defineProperties(ScrollViewport.prototype.flow___reset_transforms, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.flow_content_size = function flow_content_size() {
            var self = this;
            return [document.documentElement.scrollWidth, document.documentElement.scrollHeight];
        };
        if (!ScrollViewport.prototype.flow_content_size.__module__) Object.defineProperties(ScrollViewport.prototype.flow_content_size, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.paged_content_inline_size = function paged_content_inline_size() {
            var self = this;
            var ρσ_unpack, w, h;
            ρσ_unpack = self.content_size();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            w = ρσ_unpack[0];
            h = ρσ_unpack[1];
            return (self.horizontal_writing_mode) ? w : h;
        };
        if (!ScrollViewport.prototype.paged_content_inline_size.__module__) Object.defineProperties(ScrollViewport.prototype.paged_content_inline_size, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.paged_content_block_size = function paged_content_block_size() {
            var self = this;
            var ρσ_unpack, w, h;
            ρσ_unpack = self.content_size();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            w = ρσ_unpack[0];
            h = ρσ_unpack[1];
            return (self.horizontal_writing_mode) ? h : w;
        };
        if (!ScrollViewport.prototype.paged_content_block_size.__module__) Object.defineProperties(ScrollViewport.prototype.paged_content_block_size, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.inline_size = function inline_size() {
            var self = this;
            if (self.horizontal_writing_mode) {
                return self.width();
            }
            return self.height();
        };
        if (!ScrollViewport.prototype.inline_size.__module__) Object.defineProperties(ScrollViewport.prototype.inline_size, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.block_size = function block_size() {
            var self = this;
            if (self.horizontal_writing_mode) {
                return self.height();
            }
            return self.width();
        };
        if (!ScrollViewport.prototype.block_size.__module__) Object.defineProperties(ScrollViewport.prototype.block_size, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.update_window_size = function update_window_size(w, h) {
            var self = this;
            self.window_width_from_parent = w;
            self.window_height_from_parent = h;
        };
        if (!ScrollViewport.prototype.update_window_size.__argnames__) Object.defineProperties(ScrollViewport.prototype.update_window_size, {
            __argnames__ : {value: ["w", "h"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.width = function width() {
            var self = this;
            return window.innerWidth;
        };
        if (!ScrollViewport.prototype.width.__module__) Object.defineProperties(ScrollViewport.prototype.width, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.height = function height() {
            var self = this;
            return window.innerHeight;
        };
        if (!ScrollViewport.prototype.height.__module__) Object.defineProperties(ScrollViewport.prototype.height, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.document_inline_size = function document_inline_size() {
            var self = this;
            if (self.horizontal_writing_mode) {
                return document_width();
            }
            return document_height();
        };
        if (!ScrollViewport.prototype.document_inline_size.__module__) Object.defineProperties(ScrollViewport.prototype.document_inline_size, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.document_block_size = function document_block_size() {
            var self = this;
            if (self.horizontal_writing_mode) {
                return document_height();
            }
            return document_width();
        };
        if (!ScrollViewport.prototype.document_block_size.__module__) Object.defineProperties(ScrollViewport.prototype.document_block_size, {
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.viewport_to_document = function viewport_to_document(x, y, doc) {
            var self = this;
            var topdoc, frame, rect, ρσ_unpack, wx, wy;
            doc = doc || window.document;
            topdoc = window.document;
            while (doc !== topdoc && doc.defaultView) {
                frame = doc.defaultView.frameElement;
                rect = frame.getBoundingClientRect();
                x += rect.left;
                y += rect.top;
                doc = frame.ownerDocument;
            }
            ρσ_unpack = self.window_scroll_pos();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            wx = ρσ_unpack[0];
            wy = ρσ_unpack[1];
            x += wx;
            y += wy;
            if (self.rtl) {
                x *= -1;
            }
            return [x, y];
        };
        if (!ScrollViewport.prototype.viewport_to_document.__argnames__) Object.defineProperties(ScrollViewport.prototype.viewport_to_document, {
            __argnames__ : {value: ["x", "y", "doc"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.rect_inline_start = function rect_inline_start(rect) {
            var self = this;
            if (self.horizontal_writing_mode) {
                return (self.ltr) ? rect.left : rect.right;
            }
            return rect.top;
        };
        if (!ScrollViewport.prototype.rect_inline_start.__argnames__) Object.defineProperties(ScrollViewport.prototype.rect_inline_start, {
            __argnames__ : {value: ["rect"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.rect_inline_end = function rect_inline_end(rect) {
            var self = this;
            if (self.horizontal_writing_mode) {
                return (self.ltr) ? rect.right : rect.left;
            }
            return rect.bottom;
        };
        if (!ScrollViewport.prototype.rect_inline_end.__argnames__) Object.defineProperties(ScrollViewport.prototype.rect_inline_end, {
            __argnames__ : {value: ["rect"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.rect_block_start = function rect_block_start(rect) {
            var self = this;
            if (self.horizontal_writing_mode) {
                return rect.top;
            }
            return (self.ltr) ? rect.left : rect.right;
        };
        if (!ScrollViewport.prototype.rect_block_start.__argnames__) Object.defineProperties(ScrollViewport.prototype.rect_block_start, {
            __argnames__ : {value: ["rect"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.rect_block_end = function rect_block_end(rect) {
            var self = this;
            if (self.horizontal_writing_mode) {
                return rect.bottom;
            }
            return (self.ltr) ? rect.right : rect.left;
        };
        if (!ScrollViewport.prototype.rect_block_end.__argnames__) Object.defineProperties(ScrollViewport.prototype.rect_block_end, {
            __argnames__ : {value: ["rect"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.rect_inline_size = function rect_inline_size(rect) {
            var self = this;
            if (self.horizontal_writing_mode) {
                return rect.width;
            }
            return rect.height;
        };
        if (!ScrollViewport.prototype.rect_inline_size.__argnames__) Object.defineProperties(ScrollViewport.prototype.rect_inline_size, {
            __argnames__ : {value: ["rect"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.rect_block_size = function rect_block_size(rect) {
            var self = this;
            if (self.horizontal_writing_mode) {
                return rect.height;
            }
            return rect.width;
        };
        if (!ScrollViewport.prototype.rect_block_size.__argnames__) Object.defineProperties(ScrollViewport.prototype.rect_block_size, {
            __argnames__ : {value: ["rect"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.viewport_to_document_inline = function viewport_to_document_inline(pos, doc) {
            var self = this;
            if (self.horizontal_writing_mode) {
                return self.viewport_to_document(pos, 0, doc)[0];
            }
            return self.viewport_to_document(0, pos, doc)[1];
        };
        if (!ScrollViewport.prototype.viewport_to_document_inline.__argnames__) Object.defineProperties(ScrollViewport.prototype.viewport_to_document_inline, {
            __argnames__ : {value: ["pos", "doc"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.viewport_to_document_block = function viewport_to_document_block(pos, doc) {
            var self = this;
            if (self.horizontal_writing_mode) {
                return self.viewport_to_document(0, pos, doc)[1];
            }
            return self.viewport_to_document(pos, 0, doc)[0];
        };
        if (!ScrollViewport.prototype.viewport_to_document_block.__argnames__) Object.defineProperties(ScrollViewport.prototype.viewport_to_document_block, {
            __argnames__ : {value: ["pos", "doc"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.viewport_to_document_inline_block = function viewport_to_document_inline_block(inline, block, doc) {
            var self = this;
            if (self.horizontal_writing_mode) {
                return self.viewport_to_document(inline, block, doc);
            }
            return self.viewport_to_document(block, inline, doc);
        };
        if (!ScrollViewport.prototype.viewport_to_document_inline_block.__argnames__) Object.defineProperties(ScrollViewport.prototype.viewport_to_document_inline_block, {
            __argnames__ : {value: ["inline", "block", "doc"]},
            __module__ : {value: "read_book.viewport"}
        });
        ScrollViewport.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ScrollViewport.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ScrollViewport.prototype, "__bases__", {value: []});

        function IOSScrollViewport() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            IOSScrollViewport.prototype.__bind_methods__.call(this);
            IOSScrollViewport.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(IOSScrollViewport, ScrollViewport);
        Object.defineProperty(IOSScrollViewport.prototype, "__bind_methods__", {value: function () {
            ScrollViewport.prototype.__bind_methods__ && ScrollViewport.prototype.__bind_methods__.call(this);
            this.width = IOSScrollViewport.prototype.width.bind(this);
            this.height = IOSScrollViewport.prototype.height.bind(this);
            this._scroll_implementation = IOSScrollViewport.prototype._scroll_implementation.bind(this);
            this.paged_scroll_to = IOSScrollViewport.prototype.paged_scroll_to.bind(this);
            this.transform_val = IOSScrollViewport.prototype.transform_val.bind(this);
            this.paged_x = IOSScrollViewport.prototype.paged_x.bind(this);
            this.paged_y = IOSScrollViewport.prototype.paged_y.bind(this);
            this.paged_scroll_into_view = IOSScrollViewport.prototype.paged_scroll_into_view.bind(this);
            this.paged_window_scroll_pos = IOSScrollViewport.prototype.paged_window_scroll_pos.bind(this);
            this.paged_content_size = IOSScrollViewport.prototype.paged_content_size.bind(this);
            this.paged___reset_transforms = IOSScrollViewport.prototype.paged___reset_transforms.bind(this);
            this.paged_reset_globals = IOSScrollViewport.prototype.paged_reset_globals.bind(this);
        }});
        IOSScrollViewport.prototype.__init__ = function __init__ () {
            ScrollViewport.prototype.__init__ && ScrollViewport.prototype.__init__.apply(this, arguments);
        };
        IOSScrollViewport.prototype.width = function width() {
            var self = this;
            return self.window_width_from_parent || window.innerWidth;
        };
        if (!IOSScrollViewport.prototype.width.__module__) Object.defineProperties(IOSScrollViewport.prototype.width, {
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.height = function height() {
            var self = this;
            return self.window_height_from_parent || window.innerHeight;
        };
        if (!IOSScrollViewport.prototype.height.__module__) Object.defineProperties(IOSScrollViewport.prototype.height, {
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype._scroll_implementation = function _scroll_implementation(x, y) {
            var self = this;
            if (x === 0 && y === 0) {
                document.documentElement.style.transform = "none";
            } else {
                x *= -1;
                y *= -1;
                document.documentElement.style.transform = "translateX(" + ρσ_str.format("{}", x) + "px) translateY(" + ρσ_str.format("{}", y) + "px)";
            }
        };
        if (!IOSScrollViewport.prototype._scroll_implementation.__argnames__) Object.defineProperties(IOSScrollViewport.prototype._scroll_implementation, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.paged_scroll_to = function paged_scroll_to(x, y) {
            var self = this;
            var boss;
            x = x || 0;
            y = y || 0;
            if (self.ltr) {
                self._scroll_implementation(x, y);
            } else {
                self._scroll_implementation(-x, y);
            }
            boss = get_boss();
            if (boss) {
                boss.onscroll();
            }
        };
        if (!IOSScrollViewport.prototype.paged_scroll_to.__argnames__) Object.defineProperties(IOSScrollViewport.prototype.paged_scroll_to, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.transform_val = function transform_val(y) {
            var self = this;
            var raw, idx, ans;
            raw = document.documentElement.style.transform;
            if (!raw || raw === "none") {
                return 0;
            }
            idx = (y) ? raw.lastIndexOf("(") : raw.indexOf("(");
            raw = raw.slice(idx + 1);
            ans = parseInt(raw);
            if (isNaN(ans)) {
                ans = 0;
            }
            return ans;
        };
        if (!IOSScrollViewport.prototype.transform_val.__argnames__) Object.defineProperties(IOSScrollViewport.prototype.transform_val, {
            __argnames__ : {value: ["y"]},
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.paged_x = function paged_x() {
            var self = this;
            var ans;
            ans = self.transform_val();
            if (self.ltr) {
                ans *= -1;
            }
            return ans;
        };
        if (!IOSScrollViewport.prototype.paged_x.__module__) Object.defineProperties(IOSScrollViewport.prototype.paged_x, {
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.paged_y = function paged_y() {
            var self = this;
            return -1 * self.transform_val(true);
        };
        if (!IOSScrollViewport.prototype.paged_y.__module__) Object.defineProperties(IOSScrollViewport.prototype.paged_y, {
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.paged_scroll_into_view = function paged_scroll_into_view(elem) {
            var self = this;
            var left, p;
            left = elem.offsetLeft;
            if (left === null) {
                return;
            }
            elem.scrollIntoView();
            window.scrollTo(0, 0);
            p = elem.offsetParent;
            while (p) {
                left += p.offsetLeft;
                p = p.offsetParent;
            }
            self._scroll_implementation(max(0, left), 0);
        };
        if (!IOSScrollViewport.prototype.paged_scroll_into_view.__argnames__) Object.defineProperties(IOSScrollViewport.prototype.paged_scroll_into_view, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.paged_window_scroll_pos = function paged_window_scroll_pos() {
            var self = this;
            return [self.transform_val(), self.transform_val(true)];
        };
        if (!IOSScrollViewport.prototype.paged_window_scroll_pos.__module__) Object.defineProperties(IOSScrollViewport.prototype.paged_window_scroll_pos, {
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.paged_content_size = function paged_content_size() {
            var self = this;
            var w, h;
            w = document.documentElement.scrollWidth;
            h = document.documentElement.scrollHeight;
            return [w - self.transform_val(), h - self.transform_val(true)];
        };
        if (!IOSScrollViewport.prototype.paged_content_size.__module__) Object.defineProperties(IOSScrollViewport.prototype.paged_content_size, {
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.paged___reset_transforms = function paged___reset_transforms() {
            var self = this;
            var s;
            s = document.documentElement.style;
            if (s.transform !== "none") {
                s.transform = "none";
            }
        };
        if (!IOSScrollViewport.prototype.paged___reset_transforms.__module__) Object.defineProperties(IOSScrollViewport.prototype.paged___reset_transforms, {
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.paged_reset_globals = function paged_reset_globals() {
            var self = this;
            self.__reset_transforms();
        };
        if (!IOSScrollViewport.prototype.paged_reset_globals.__module__) Object.defineProperties(IOSScrollViewport.prototype.paged_reset_globals, {
            __module__ : {value: "read_book.viewport"}
        });
        IOSScrollViewport.prototype.__repr__ = function __repr__ () {
            if(ScrollViewport.prototype.__repr__) return ScrollViewport.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        IOSScrollViewport.prototype.__str__ = function __str__ () {
            if(ScrollViewport.prototype.__str__) return ScrollViewport.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(IOSScrollViewport.prototype, "__bases__", {value: [ScrollViewport]});

        if (1 < ios_major_version && ios_major_version < 15) {
            scroll_viewport = new IOSScrollViewport;
        } else {
            scroll_viewport = new ScrollViewport;
        }
        var ρσ_Iter1 = ρσ_Iterable(FUNCTIONS);
        for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
            attr = ρσ_Iter1[ρσ_Index1];
            if (!scroll_viewport[ρσ_bound_index("paged_" + attr, scroll_viewport)]) {
                scroll_viewport[ρσ_bound_index("paged_" + attr, scroll_viewport)] = scroll_viewport[(typeof attr === "number" && attr < 0) ? scroll_viewport.length + attr : attr];
            }
        }
        viewport_mode_changer(scroll_viewport.set_mode);
        function get_unit_size_in_pixels(unit) {
            var d, ans;
            d = document.createElement("span");
            d.style.position = "absolute";
            d.style.visibility = "hidden";
            d.style.width = "1" + ρσ_str.format("{}", unit) + "";
            d.style.fontSize = "1" + ρσ_str.format("{}", unit) + "";
            d.style.paddingTop = d.style.paddingBottom = d.style.paddingLeft = d.style.paddingRight = "0";
            d.style.marginTop = d.style.marginBottom = d.style.marginLeft = d.style.marginRight = "0";
            d.style.borderStyle = "none";
            document.body.appendChild(d);
            ans = d.clientWidth;
            document.body.removeChild(d);
            return ans;
        };
        if (!get_unit_size_in_pixels.__argnames__) Object.defineProperties(get_unit_size_in_pixels, {
            __argnames__ : {value: ["unit"]},
            __module__ : {value: "read_book.viewport"}
        });

        function rem_size(reset) {
            var d;
            if (reset) {
                rem_size.ans = null;
                return;
            }
            if (!rem_size.ans) {
                d = document.createElement("span");
                d.style.position = "absolute";
                d.style.visibility = "hidden";
                d.style.width = "1rem";
                d.style.fontSize = "1rem";
                d.style.paddingTop = d.style.paddingBottom = d.style.paddingLeft = d.style.paddingRight = "0";
                d.style.marginTop = d.style.marginBottom = d.style.marginLeft = d.style.marginRight = "0";
                d.style.borderStyle = "none";
                document.body.appendChild(d);
                rem_size.ans = max(2, d.clientWidth);
                document.body.removeChild(d);
            }
            return rem_size.ans;
        };
        if (!rem_size.__argnames__) Object.defineProperties(rem_size, {
            __argnames__ : {value: ["reset"]},
            __module__ : {value: "read_book.viewport"}
        });

        function line_height(reset) {
            var ds, lh;
            if (reset) {
                line_height.ans = null;
                return;
            }
            if (!line_height.ans) {
                ds = window.getComputedStyle(document.body);
                try {
                    lh = float(ds.lineHeight);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        try {
                            lh = 1.2 * float(ds.fontSize);
                        } catch (ρσ_Exception) {
                            ρσ_last_exception = ρσ_Exception;
                            {
                                lh = 15;
                            } 
                        }
                    } 
                }
                line_height.ans = max(5, lh);
            }
            return line_height.ans;
        };
        if (!line_height.__argnames__) Object.defineProperties(line_height, {
            __argnames__ : {value: ["reset"]},
            __module__ : {value: "read_book.viewport"}
        });

        ρσ_modules["read_book.viewport"].FUNCTIONS = FUNCTIONS;
        ρσ_modules["read_book.viewport"].scroll_viewport = scroll_viewport;
        ρσ_modules["read_book.viewport"].attr = attr;
        ρσ_modules["read_book.viewport"].ScrollViewport = ScrollViewport;
        ρσ_modules["read_book.viewport"].IOSScrollViewport = IOSScrollViewport;
        ρσ_modules["read_book.viewport"].get_unit_size_in_pixels = get_unit_size_in_pixels;
        ρσ_modules["read_book.viewport"].rem_size = rem_size;
        ρσ_modules["read_book.viewport"].line_height = line_height;
    })();

    (function(){
        var __name__ = "read_book.cfi";
        var escape_pat, unescape_pat;
        var scroll_viewport = ρσ_modules["read_book.viewport"].scroll_viewport;
        var rem_size = ρσ_modules["read_book.viewport"].rem_size;

        escape_pat = /[\[\],^();~@!]/g;
        unescape_pat = /[\^](.)/g;
        function escape_for_cfi(raw) {
            return (raw || "").replace(escape_pat, "^$&");
        };
        if (!escape_for_cfi.__argnames__) Object.defineProperties(escape_for_cfi, {
            __argnames__ : {value: ["raw"]},
            __module__ : {value: "read_book.cfi"}
        });

        function unescape_from_cfi(raw) {
            return (raw || "").replace(unescape_pat, "$1");
        };
        if (!unescape_from_cfi.__argnames__) Object.defineProperties(unescape_from_cfi, {
            __argnames__ : {value: ["raw"]},
            __module__ : {value: "read_book.cfi"}
        });

        function fstr(d) {
            var ans, n;
            ans = "";
            if (d < 0) {
                ans = "-";
                d = -d;
            }
            n = Math.floor(d);
            ans += n;
            n = Math.round((d - n) * 100);
            if (n !== 0) {
                ans += "." + ((n % 10 === 0) ? n / 10 : n);
            }
            return ans;
        };
        if (!fstr.__argnames__) Object.defineProperties(fstr, {
            __argnames__ : {value: ["d"]},
            __module__ : {value: "read_book.cfi"}
        });

        function get_current_time(target) {
            return fstr(target.currentTime || 0);
        };
        if (!get_current_time.__argnames__) Object.defineProperties(get_current_time, {
            __argnames__ : {value: ["target"]},
            __module__ : {value: "read_book.cfi"}
        });

        function id_is_unique(idval) {
            var multiples;
            try {
                multiples = document.querySelectorAll("[id=" + window.CSS.escape(idval) + "]");
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    return false;
                } 
            }
            if (multiples && multiples.length < 2) {
                return true;
            }
            return false;
        };
        if (!id_is_unique.__argnames__) Object.defineProperties(id_is_unique, {
            __argnames__ : {value: ["idval"]},
            __module__ : {value: "read_book.cfi"}
        });

        function range_has_point(range_, x, y) {
            var rects, rect;
            rects = range_.getClientRects();
            for (var i = 0; i < rects.length; i++) {
                rect = rects[(typeof i === "number" && i < 0) ? rects.length + i : i];
                if (rect.left <= x && x <= rect.right && rect.top <= y && y <= rect.bottom) {
                    return true;
                }
            }
            return false;
        };
        if (!range_has_point.__argnames__) Object.defineProperties(range_has_point, {
            __argnames__ : {value: ["range_", "x", "y"]},
            __module__ : {value: "read_book.cfi"}
        });

        function offset_in_text_node(node, range_, x, y) {
            var limits, pivot, lr, rr;
            limits = [0, node.nodeValue.length];
            while (limits[0] !== limits[1]) {
                pivot = Math.floor((limits[0] + limits[1]) / 2);
                lr = [limits[0], pivot];
                rr = [pivot+1, limits[1]];
                range_.setStart(node, pivot);
                range_.setEnd(node, pivot + 1);
                if (range_has_point(range_, x, y)) {
                    return pivot;
                }
                range_.setStart(node, rr[0]);
                range_.setEnd(node, rr[1]);
                if (range_has_point(range_, x, y)) {
                    limits = rr;
                    continue;
                }
                range_.setStart(node, lr[0]);
                range_.setEnd(node, lr[1]);
                if (range_has_point(range_, x, y)) {
                    limits = lr;
                    continue;
                }
                break;
            }
            return limits[0];
        };
        if (!offset_in_text_node.__argnames__) Object.defineProperties(offset_in_text_node, {
            __argnames__ : {value: ["node", "range_", "x", "y"]},
            __module__ : {value: "read_book.cfi"}
        });

        function find_offset_for_point(x, y, node, cdoc) {
            var range_, child;
            range_ = cdoc.createRange();
            child = node.firstChild;
            while (child) {
                if (Node.TEXT_NODE <= (ρσ_cond_temp = child.nodeType) && ρσ_cond_temp <= Node.ENTITY_NODE && child.nodeValue && child.nodeValue.length) {
                    range_.setStart(child, 0);
                    range_.setEnd(child, child.nodeValue.length);
                    if (range_has_point(range_, x, y)) {
                        return [child, offset_in_text_node(child, range_, x, y)];
                    }
                }
                child = child.nextSibling;
            }
            return [null, null];
        };
        if (!find_offset_for_point.__argnames__) Object.defineProperties(find_offset_for_point, {
            __argnames__ : {value: ["x", "y", "node", "cdoc"]},
            __module__ : {value: "read_book.cfi"}
        });

        function set_current_time(target, val) {
            if (target.currentTime === undefined) {
                return;
            }
            if (target.readyState === 4 || target.readyState === "complete") {
                target.currentTime = val + 0;
            } else {
                target.addEventListener("canplay", (function() {
                    var ρσ_anonfunc = function () {
                        target.currentTime = val;
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.cfi"}
                    });
                    return ρσ_anonfunc;
                })(), false);
            }
        };
        if (!set_current_time.__argnames__) Object.defineProperties(set_current_time, {
            __argnames__ : {value: ["target", "val"]},
            __module__ : {value: "read_book.cfi"}
        });

        function is_text_node(node) {
            return node.nodeType === Node.TEXT_NODE || node.nodeType === Node.CDATA_SECTION_NODE;
        };
        if (!is_text_node.__argnames__) Object.defineProperties(is_text_node, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "read_book.cfi"}
        });

        function text_length_in_range_wrapper(node) {
            var p, ans;
            p = node.firstChild;
            ans = 0;
            while (p) {
                if (is_text_node(p)) {
                    ans += p.nodeValue.length;
                } else if (p.nodeType === Node.ELEMENT_NODE && ρσ_exists.d(p.dataset).calibreRangeWrapper) {
                    ans += text_length_in_range_wrapper(p);
                }
                p = p.nextSibling;
            }
            return ans;
        };
        if (!text_length_in_range_wrapper.__argnames__) Object.defineProperties(text_length_in_range_wrapper, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "read_book.cfi"}
        });

        function adjust_node_for_text_offset(node) {
            var offset, adjusted, p;
            if (node.parentNode && ρσ_exists.d(node.parentNode.dataset).calibreRangeWrapper) {
                node = node.parentNode;
            }
            offset = 0;
            adjusted = false;
            while (true) {
                p = node.previousSibling;
                if (!p || p.nodeType > Node.COMMENT_NODE) {
                    break;
                }
                if (is_text_node(p)) {
                    offset += p.nodeValue.length;
                } else if (p.nodeType === Node.ELEMENT_NODE && ρσ_exists.d(p.dataset).calibreRangeWrapper) {
                    offset += text_length_in_range_wrapper(p);
                }
                node = p;
                adjusted = true;
            }
            if (adjusted && node.nodeType === Node.ELEMENT_NODE && ρσ_exists.d(node.dataset).calibreRangeWrapper) {
                if (!node.firstChild || node.firstChild.nodeType !== Node.TEXT_NODE) {
                    node.insertBefore(document.createTextNode(""), node.firstChild || null);
                }
                node = node.firstChild;
            }
            return [node, offset, adjusted];
        };
        if (!adjust_node_for_text_offset.__argnames__) Object.defineProperties(adjust_node_for_text_offset, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "read_book.cfi"}
        });

        function unwrapped_nodes(range_wrapper) {
            var ans, child;
            ans = [];
            var ρσ_Iter0 = ρσ_Iterable(range_wrapper.childNodes);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                child = ρσ_Iter0[ρσ_Index0];
                if (child.nodeType === Node.ELEMENT_NODE && ρσ_exists.d(child.dataset).calibreRangeWrapper) {
                    ans = ans.concat(unwrapped_nodes(child));
                } else {
                    ans.push(child);
                }
            }
            return ans;
        };
        if (!unwrapped_nodes.__argnames__) Object.defineProperties(unwrapped_nodes, {
            __argnames__ : {value: ["range_wrapper"]},
            __module__ : {value: "read_book.cfi"}
        });

        function increment_index_for_child(child, index, sentinel) {
            var is_element, nodes;
            is_element = child.nodeType === Node.ELEMENT_NODE;
            if (is_element && ρσ_exists.d(child.dataset).calibreRangeWrapper) {
                nodes = unwrapped_nodes(child);
                index = increment_index_for_children(nodes, index, sentinel);
            } else {
                index |= 1;
                if (is_element) {
                    index += 1;
                }
            }
            return index;
        };
        if (!increment_index_for_child.__argnames__) Object.defineProperties(increment_index_for_child, {
            __argnames__ : {value: ["child", "index", "sentinel"]},
            __module__ : {value: "read_book.cfi"}
        });

        function increment_index_for_children(children, index, sentinel) {
            var child, i;
            for (var ρσ_Index1 = 0; ρσ_Index1 < children.length; ρσ_Index1++) {
                i = ρσ_Index1;
                child = children[(typeof i === "number" && i < 0) ? children.length + i : i];
                index = increment_index_for_child(child, index, sentinel);
                if (child === sentinel) {
                    break;
                }
            }
            return index;
        };
        if (!increment_index_for_children.__argnames__) Object.defineProperties(increment_index_for_children, {
            __argnames__ : {value: ["children", "index", "sentinel"]},
            __module__ : {value: "read_book.cfi"}
        });

        function non_range_wrapper_parent(node) {
            var p, child;
            p = node.parentNode;
            child = node;
            while (ρσ_exists.d(p.dataset).calibreRangeWrapper) {
                child = p;
                p = p.parentNode;
            }
            return [p, child];
        };
        if (!non_range_wrapper_parent.__argnames__) Object.defineProperties(non_range_wrapper_parent, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "read_book.cfi"}
        });

        function encode(doc, node, offset, tail) {
            var cfi, q, ρσ_unpack, adjusted_node, additional_offset, adjusted, is_first, p, sentinel, win, index, id, idspec;
            cfi = tail || "";
            if (node.nodeType === Node.ELEMENT_NODE) {
                if (typeof offset === "number") {
                    q = node.childNodes.item(offset);
                    if (q) {
                        if (q.nodeType === Node.ELEMENT_NODE) {
                            node = q;
                            if (ρσ_exists.d(node.dataset).calibreRangeWrapper) {
                                if (!node.firstChild) {
                                    node.appendChild(document.createTextNode(""));
                                }
                                node = node.firstChild;
                            }
                        }
                    }
                } else if (ρσ_exists.d(node.dataset).calibreRangeWrapper) {
                    if (!node.firstChild) {
                        node.appendChild(document.createTextNode(""));
                    }
                    node = node.firstChild;
                }
            }
            if (is_text_node(node)) {
                offset = offset || 0;
                ρσ_unpack = adjust_node_for_text_offset(node);
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
                adjusted_node = ρσ_unpack[0];
                additional_offset = ρσ_unpack[1];
                adjusted = ρσ_unpack[2];
                if (adjusted) {
                    node = adjusted_node;
                    offset += additional_offset;
                }
                cfi = ":" + offset + cfi;
            } else if (node.nodeType !== Node.ELEMENT_NODE) {
                print("Offsets for nodes of type " + ρσ_str.format("{}", node.nodeType) + " are not handled");
            }
            is_first = true;
            while (node !== doc) {
                ρσ_unpack = non_range_wrapper_parent(node);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                p = ρσ_unpack[0];
                sentinel = ρσ_unpack[1];
                if (!p) {
                    if ((node.nodeType === Node.DOCUMENT_NODE || typeof node.nodeType === "object" && ρσ_equals(node.nodeType, Node.DOCUMENT_NODE))) {
                        win = node.defaultView;
                        if (win.frameElement) {
                            node = win.frameElement;
                            cfi = "!" + cfi;
                            continue;
                        }
                    }
                    break;
                }
                index = increment_index_for_children(p.childNodes, 0, sentinel);
                if (is_first) {
                    is_first = false;
                    if (node.nodeType === Node.ELEMENT_NODE && ρσ_exists.d(node.dataset).calibreRangeWrapper) {
                        index -= 1;
                    }
                }
                id = node.id;
                idspec = "";
                if (id && id_is_unique(id)) {
                    idspec = "[" + escape_for_cfi(id) + "]";
                }
                cfi = "/" + index + idspec + cfi;
                node = p;
            }
            return cfi;
        };
        if (!encode.__argnames__) Object.defineProperties(encode, {
            __argnames__ : {value: ["doc", "node", "offset", "tail"]},
            __module__ : {value: "read_book.cfi"}
        });

        function node_at_index(nodes, target, index, iter_text_nodes) {
            var node, is_element, ρσ_unpack, q, i;
            for (var ρσ_Index2 = 0; ρσ_Index2 < nodes.length; ρσ_Index2++) {
                i = ρσ_Index2;
                node = nodes[(typeof i === "number" && i < 0) ? nodes.length + i : i];
                is_element = node.nodeType === Node.ELEMENT_NODE;
                if (is_element && ρσ_exists.d(node.dataset).calibreRangeWrapper) {
                    ρσ_unpack = node_at_index(unwrapped_nodes(node), target, index, iter_text_nodes);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                    q = ρσ_unpack[0];
                    index = ρσ_unpack[1];
                    if (q) {
                        return [q, index];
                    }
                    continue;
                }
                if (iter_text_nodes && !is_text_node(node) || !iter_text_nodes && !is_element) {
                    continue;
                }
                if (index === target) {
                    return [node, index];
                }
                index += 1;
            }
            return [null, index];
        };
        if (!node_at_index.__argnames__) Object.defineProperties(node_at_index, {
            __argnames__ : {value: ["nodes", "target", "index", "iter_text_nodes"]},
            __module__ : {value: "read_book.cfi"}
        });

        function node_for_path_step(parent, target, assertion) {
            var q, is_element;
            if (assertion) {
                q = document.getElementById(assertion);
                if (q && id_is_unique(assertion)) {
                    return q;
                }
            }
            is_element = ρσ_equals(target % 2, 0);
            target = Math.floor(target / 2);
            if (is_element && target > 0) {
                target -= 1;
            }
            return node_at_index(parent.childNodes, target, 0, !is_element)[0];
        };
        if (!node_for_path_step.__argnames__) Object.defineProperties(node_for_path_step, {
            __argnames__ : {value: ["parent", "target", "assertion"]},
            __module__ : {value: "read_book.cfi"}
        });

        function node_for_text_offset(nodes, offset, first_node) {
            var last_text_node, seen_first, node, l, ρσ_unpack, qn, ok, i;
            last_text_node = null;
            seen_first = false;
            for (var ρσ_Index3 = 0; ρσ_Index3 < nodes.length; ρσ_Index3++) {
                i = ρσ_Index3;
                node = nodes[(typeof i === "number" && i < 0) ? nodes.length + i : i];
                if (!seen_first) {
                    if (!first_node || node.isSameNode(first_node)) {
                        seen_first = true;
                    } else {
                        continue;
                    }
                }
                if (is_text_node(node)) {
                    l = node.nodeValue.length;
                    if (offset <= l) {
                        return [node, offset, true];
                    }
                    last_text_node = node;
                    offset -= l;
                } else if (node.nodeType === Node.ELEMENT_NODE && ρσ_exists.d(node.dataset).calibreRangeWrapper) {
                    ρσ_unpack = node_for_text_offset(unwrapped_nodes(node), offset);
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
                    qn = ρσ_unpack[0];
                    offset = ρσ_unpack[1];
                    ok = ρσ_unpack[2];
                    if (ok) {
                        return [qn, offset, true];
                    }
                }
            }
            return [last_text_node, offset, false];
        };
        if (!node_for_text_offset.__argnames__) Object.defineProperties(node_for_text_offset, {
            __argnames__ : {value: ["nodes", "offset", "first_node"]},
            __module__ : {value: "read_book.cfi"}
        });

        function decode(cfi, doc) {
            var simple_node_regex, error, node, orig_cfi, r, target, assertion, q, decoded, offset, orig_offset, ρσ_unpack, qnode, ok;
            doc = doc || window.document;
            simple_node_regex = /^\/(\d+)(\[[^\]]*\])?/;
            error = null;
            node = doc;
            orig_cfi = cfi;
            while (cfi.length > 0 && !error) {
                r = cfi.match(simple_node_regex);
                if (r) {
                    target = parseInt(r[1]);
                    assertion = r[2];
                    if (assertion) {
                        assertion = unescape_from_cfi(assertion.slice(1, assertion.length - 1));
                    }
                    q = node_for_path_step(node, target, assertion);
                    if (q) {
                        node = q;
                        cfi = cfi.substr(r[0].length);
                    } else {
                        if (target) {
                            error = "No matching child found for CFI: " + ρσ_str.format("{}", orig_cfi) + " leftover: " + ρσ_str.format("{}", cfi) + "";
                            break;
                        } else {
                            cfi = cfi.substr(r[0].length);
                        }
                    }
                } else if (cfi[0] === "!") {
                    if (node.contentDocument) {
                        node = node.contentDocument;
                        cfi = cfi.substr(1);
                    } else {
                        error = "Cannot reference " + node.nodeName + "'s content: " + cfi;
                    }
                } else {
                    break;
                }
            }
            if (error) {
                print(error);
                return null;
            }
            decoded = Object.create(null);
            error = null;
            offset = null;
            r = cfi.match(/^:(\d+)/);
            if (r) {
                offset = parseInt(r[1]);
                cfi = cfi.substr(r[0].length);
            }
            r = cfi.match(/^~(-?\d+(\.\d+)?)/);
            if (r) {
                decoded.time = r[1] - 0;
                cfi = cfi.substr(r[0].length);
            }
            r = cfi.match(/^@(-?\d+(\.\d+)?):(-?\d+(\.\d+)?)/);
            if (r) {
                decoded.x = r[1] - 0;
                decoded.y = r[3] - 0;
                cfi = cfi.substr(r[0].length);
            }
            r = cfi.match(/^\[([^\]]+)\]/);
            if (r) {
                assertion = r[1];
                cfi = cfi.substr(r[0].length);
                r = assertion.match(/;s=([ab])$/);
                if (r) {
                    if (r.index > 0 && assertion[ρσ_bound_index(r.index - 1, assertion)] !== "^") {
                        assertion = assertion.substr(0, r.index);
                        decoded.forward = r[1] === "a";
                    }
                    assertion = unescape_from_cfi(assertion);
                }
            }
            if (offset !== null) {
                orig_offset = offset;
                if (ρσ_exists.d(node.parentNode).nodeType === Node.ELEMENT_NODE && ρσ_exists.d(node.parentNode.dataset).calibreRangeWrapper) {
                    node = node.parentNode;
                }
                ρσ_unpack = node_for_text_offset(node.parentNode.childNodes, offset, node);
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
                qnode = ρσ_unpack[0];
                offset = ρσ_unpack[1];
                ok = ρσ_unpack[2];
                if (!ok) {
                    error = "Offset out of range: " + orig_offset;
                }
                if (qnode) {
                    node = qnode;
                }
                decoded.offset = offset;
            }
            decoded.node = node;
            if (error) {
                decoded.error = error;
            } else if (cfi.length > 0) {
                decoded.error = "Undecoded CFI: " + cfi;
            }
            if (decoded.error) {
                print(decoded.error);
            }
            return decoded;
        };
        if (!decode.__argnames__) Object.defineProperties(decode, {
            __argnames__ : {value: ["cfi", "doc"]},
            __module__ : {value: "read_book.cfi"}
        });

        function cfi_sort_key(cfi) {
            var simple_node_regex, steps, r, target, ans, offset;
            simple_node_regex = /^\/(\d+)(\[[^\]]*\])?/;
            steps = [];
            while (cfi.length > 0) {
                r = cfi.match(simple_node_regex);
                if (r) {
                    target = parseInt(r[1]);
                    cfi = cfi.substr(r[0].length);
                    steps.push(target);
                } else if (cfi[0] === "!") {
                    cfi = cfi.substr(1);
                } else {
                    break;
                }
            }
            ans = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["steps"] = steps;
                ρσ_d["text_offset"] = 0;
                ρσ_d["temporal_offset"] = 0;
                ρσ_d["spatial_offset"] = [0, 0];
                return ρσ_d;
            }).call(this);
            r = cfi.match(/^:(\d+)/);
            if (r) {
                offset = parseInt(r[1]);
                ans["text_offset"] = offset;
                cfi = cfi.substr(r[0].length);
            }
            r = cfi.match(/^~(-?\d+(\.\d+)?)/);
            if (r) {
                ans["temporal_offset"] = r[1] - 0;
                cfi = cfi.substr(r[0].length);
            }
            r = cfi.match(/^@(-?\d+(\.\d+)?):(-?\d+(\.\d+)?)/);
            if (r) {
                ans["spatial_offset"] = [r[1] - 0, r[3] - 0];
                cfi = cfi.substr(r[0].length);
            }
            return ans;
        };
        if (!cfi_sort_key.__argnames__) Object.defineProperties(cfi_sort_key, {
            __argnames__ : {value: ["cfi"]},
            __module__ : {value: "read_book.cfi"}
        });

        function create_cfi_cmp(key_map) {
            if (!key_map) {
                key_map = Object.create(null);
            }
            function cfi_cmp(a_cfi, b_cfi) {
                var a, b, diff, i;
                a = key_map[(typeof a_cfi === "number" && a_cfi < 0) ? key_map.length + a_cfi : a_cfi];
                if (!a) {
                    a = key_map[(typeof a_cfi === "number" && a_cfi < 0) ? key_map.length + a_cfi : a_cfi] = cfi_sort_key(a_cfi);
                }
                b = key_map[(typeof b_cfi === "number" && b_cfi < 0) ? key_map.length + b_cfi : b_cfi];
                if (!b) {
                    b = key_map[(typeof b_cfi === "number" && b_cfi < 0) ? key_map.length + b_cfi : b_cfi] = cfi_sort_key(b_cfi);
                }
                var ρσ_Iter4 = ρσ_Iterable(range(min(a.steps.length, b.steps.length)));
                for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                    i = ρσ_Iter4[ρσ_Index4];
                    diff = (ρσ_expr_temp = a.steps)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i] - (ρσ_expr_temp = b.steps)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
                    if (diff !== 0) {
                        return diff;
                    }
                }
                diff = a.steps.length - b.steps.length;
                if (diff !== 0) {
                    return diff;
                }
                if (a.temporal_offset !== b.temporal_offset) {
                    return a.temporal_offset - b.temporal_offset;
                }
                if (a.spatial_offset[0] !== b.spatial_offset[0]) {
                    return a.spatial_offset[0] - b.spatial_offset[0];
                }
                if (a.spatial_offset[1] !== b.spatial_offset[1]) {
                    return a.spatial_offset[1] - b.spatial_offset[1];
                }
                if (a.text_offset !== b.text_offset) {
                    return a.text_offset - b.text_offset;
                }
                return 0;
            };
            if (!cfi_cmp.__argnames__) Object.defineProperties(cfi_cmp, {
                __argnames__ : {value: ["a_cfi", "b_cfi"]},
                __module__ : {value: "read_book.cfi"}
            });

            return cfi_cmp;
        };
        if (!create_cfi_cmp.__argnames__) Object.defineProperties(create_cfi_cmp, {
            __argnames__ : {value: ["key_map"]},
            __module__ : {value: "read_book.cfi"}
        });

        function sort_cfis(array_of_cfis) {
            var key_map, cfi;
            key_map = (function() {
                var ρσ_Iter = ρσ_Iterable(array_of_cfis), ρσ_Result = Object.create(null), cfi;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    cfi = ρσ_Iter[ρσ_Index];
                    ρσ_Result[cfi] = (cfi_sort_key(cfi));
                }
                return ρσ_Result;
            })();
            Array.prototype.sort.call(array_of_cfis, create_cfi_cmp(key_map));
        };
        if (!sort_cfis.__argnames__) Object.defineProperties(sort_cfis, {
            __argnames__ : {value: ["array_of_cfis"]},
            __module__ : {value: "read_book.cfi"}
        });

        function at(x, y, doc) {
            var cdoc, target, tail, offset, name, cd, rect, px, py, ρσ_unpack;
            doc = doc || window.document;
            cdoc = doc;
            target = null;
            tail = "";
            offset = null;
            name = null;
            while (true) {
                target = cdoc.elementFromPoint(x, y);
                if (!target || target === cdoc.documentElement || target === cdoc.body) {
                    return null;
                }
                name = target.localName;
                if (!ρσ_in(name, (function(){
                    var s = ρσ_set();
                    s.jsset.add("iframe");
                    s.jsset.add("embed");
                    s.jsset.add("object");
                    return s;
                })())) {
                    break;
                }
                cd = target.contentDocument;
                if (!cd) {
                    break;
                }
                rect = target.getBoundingClientRect();
                x -= rect.left;
                y -= rect.top;
                cdoc = cd;
            }
            (target.parentNode || target).normalize();
            if (ρσ_in(name, (function(){
                var s = ρσ_set();
                s.jsset.add("audio");
                s.jsset.add("video");
                return s;
            })())) {
                tail = "~" + get_current_time(target);
            }
            if (ρσ_in(name, (function(){
                var s = ρσ_set();
                s.jsset.add("img");
                s.jsset.add("video");
                return s;
            })())) {
                rect = target.getBoundingClientRect();
                px = (x - rect.left) * 100 / target.offsetWidth;
                py = (y - rect.top) * 100 / target.offsetHeight;
                tail = str.format("{}@{}:{}", tail, fstr(px), fstr(py));
            } else if (name !== "audio") {
                ρσ_unpack = find_offset_for_point(x, y, target, cdoc);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                target = ρσ_unpack[0];
                offset = ρσ_unpack[1];
                if (target === null) {
                    return null;
                }
            }
            return encode(doc, target, offset, tail);
        };
        if (!at.__argnames__) Object.defineProperties(at, {
            __argnames__ : {value: ["x", "y", "doc"]},
            __module__ : {value: "read_book.cfi"}
        });

        function decode_with_range(cfi, doc) {
            var decoded, node, ndoc, range_, position_at_end_of_range, node_len, offset, rect;
            doc = doc || window.document;
            decoded = decode(cfi, doc);
            if (!decoded || !decoded.node) {
                return null;
            }
            node = decoded.node;
            ndoc = node.ownerDocument;
            if (!ndoc) {
                print(str.format("CFI node has no owner document: {} {}", cfi, node));
                return null;
            }
            range_ = null;
            position_at_end_of_range = null;
            if (typeof decoded.offset === "number") {
                node_len = (node.nodeValue) ? node.nodeValue.length : 0;
                if (!node_len && ρσ_exists.d(ρσ_exists.d(node.nextSibling).dataset).calibreRangeWrapper && ρσ_exists.d(node.nextSibling.firstChild).nodeType === Node.TEXT_NODE) {
                    node = node.nextSibling.firstChild;
                    node_len = (node.nodeValue) ? node.nodeValue.length : 0;
                }
                if (node_len) {
                    range_ = ndoc.createRange();
                    offset = decoded.offset;
                    position_at_end_of_range = false;
                    if (offset >= node_len) {
                        offset = node_len - 1;
                        position_at_end_of_range = true;
                    }
                    range_.setStart(node, offset);
                    range_.setEnd(node, offset + 1);
                    rect = range_.getBoundingClientRect();
                    if (!rect) {
                        print(str.format("Could not find caret position for {} (offset: {})", cfi, decoded.offset));
                        range_ = null;
                    }
                } else {
                    print("Caret offset pointed to an empty text node or a non-text node for " + ρσ_str.format("{}", cfi) + ", (offset: " + ρσ_str.format("{}", decoded.offset) + ")");
                    range_ = null;
                }
            }
            decoded.range = range_;
            decoded.use_range_end_pos = position_at_end_of_range;
            return decoded;
        };
        if (!decode_with_range.__argnames__) Object.defineProperties(decode_with_range, {
            __argnames__ : {value: ["cfi", "doc"]},
            __module__ : {value: "read_book.cfi"}
        });

        function decoded_range_to_document_position(decoded) {
            var rect, inserted_node, inline_vs_pos, block_vs_pos;
            rect = decoded.range.getBoundingClientRect();
            inserted_node = null;
            if (!rect.width && !rect.height && !rect.left && !rect.right) {
                inserted_node = document.createTextNode(" ");
                decoded.range.insertNode(inserted_node);
                rect = decoded.range.getBoundingClientRect();
            }
            if (decoded.use_range_end_pos) {
                inline_vs_pos = scroll_viewport.rect_inline_end(rect);
            } else {
                inline_vs_pos = scroll_viewport.rect_inline_start(rect);
            }
            if (decoded.forward) {
                block_vs_pos = scroll_viewport.rect_block_end(rect);
            } else {
                block_vs_pos = scroll_viewport.rect_block_start(rect);
            }
            if (inserted_node) {
                inserted_node.parentNode.removeChild(inserted_node);
            }
            return scroll_viewport.viewport_to_document_inline_block(inline_vs_pos, block_vs_pos, decoded.node.ownerDocument);
        };
        if (!decoded_range_to_document_position.__argnames__) Object.defineProperties(decoded_range_to_document_position, {
            __argnames__ : {value: ["decoded"]},
            __module__ : {value: "read_book.cfi"}
        });

        function decoded_node_or_spatial_offset_to_document_position(decoded) {
            var node, rect, ρσ_unpack, percentx, percenty, viewx, viewy, doc_left, doc_top, block_vs_pos, inline_vs_pos;
            node = decoded.node;
            rect = node.getBoundingClientRect();
            ρσ_unpack = [decoded.x, decoded.y];
            percentx = ρσ_unpack[0];
            percenty = ρσ_unpack[1];
            if (typeof percentx === "number" && node.offsetWidth && typeof percenty === "number" && node.offsetHeight) {
                viewx = rect.left + percentx * node.offsetWidth / 100;
                viewy = rect.top + percenty * node.offsetHeight / 100;
                ρσ_unpack = scroll_viewport.viewport_to_document(viewx, viewy, node.ownerDocument);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                doc_left = ρσ_unpack[0];
                doc_top = ρσ_unpack[1];
                return [doc_left, doc_top];
            } else {
                if (decoded.forward) {
                    block_vs_pos = scroll_viewport.rect_block_end(rect);
                } else {
                    block_vs_pos = scroll_viewport.rect_block_start(rect);
                }
                inline_vs_pos = scroll_viewport.rect_inline_start(rect);
                return scroll_viewport.viewport_to_document_inline_block(inline_vs_pos, block_vs_pos, node.ownerDocument);
            }
        };
        if (!decoded_node_or_spatial_offset_to_document_position.__argnames__) Object.defineProperties(decoded_node_or_spatial_offset_to_document_position, {
            __argnames__ : {value: ["decoded"]},
            __module__ : {value: "read_book.cfi"}
        });

        function decoded_to_document_position(decoded) {
            var node;
            node = decoded.node;
            if (decoded.range !== null) {
                return decoded_range_to_document_position(decoded);
            } else if (node !== null && node.getBoundingClientRect) {
                return decoded_node_or_spatial_offset_to_document_position(decoded);
            }
            return [null, null];
        };
        if (!decoded_to_document_position.__argnames__) Object.defineProperties(decoded_to_document_position, {
            __argnames__ : {value: ["decoded"]},
            __module__ : {value: "read_book.cfi"}
        });

        function scroll_to(cfi, callback, doc) {
            var decoded, fn;
            decoded = decode_with_range(cfi, doc);
            if (!decoded) {
                print("No location information found for cfi: " + cfi);
                return;
            }
            if (typeof decoded.time === "number") {
                set_current_time(decoded.node, decoded.time);
            }
            function handle_text_node() {
                var r, ρσ_unpack, so, eo, original_node, node_parent, original_node_index, ndoc, span;
                r = decoded.range;
                ρσ_unpack = [r.startOffset, r.endOffset];
                so = ρσ_unpack[0];
                eo = ρσ_unpack[1];
                original_node = r.startContainer;
                node_parent = original_node.parentNode;
                original_node_index = 0;
                for (var i = 0; i < node_parent.childNodes.length; i++) {
                    if ((ρσ_expr_temp = node_parent.childNodes)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i].isSameNode(original_node)) {
                        original_node_index = i;
                        break;
                    }
                }
                ndoc = original_node.ownerDocument || document;
                span = ndoc.createElement("span");
                span.setAttribute("style", "border-width: 0; padding: 0; margin: 0");
                r.surroundContents(span);
                scroll_viewport.scroll_into_view(span);
                return (function() {
                    var ρσ_anonfunc = function () {
                        var p, node, offset, ρσ_unpack, doc_x, doc_y;
                        p = span.parentNode;
                        var ρσ_Iter5 = ρσ_Iterable(span.childNodes);
                        for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                            node = ρσ_Iter5[ρσ_Index5];
                            span.removeChild(node);
                            p.insertBefore(node, span);
                        }
                        p.removeChild(span);
                        p.normalize();
                        original_node = (ρσ_expr_temp = node_parent.childNodes)[(typeof original_node_index === "number" && original_node_index < 0) ? ρσ_expr_temp.length + original_node_index : original_node_index];
                        if (!original_node) {
                            return;
                        }
                        offset = so;
                        while (offset > -1) {
                            try {
                                r.setStart(original_node, offset);
                                break;
                            } catch (ρσ_Exception) {
                                ρσ_last_exception = ρσ_Exception;
                                {
                                    offset -= 1;
                                } 
                            }
                        }
                        offset = eo;
                        while (offset > -1) {
                            try {
                                r.setEnd(original_node, offset);
                                break;
                            } catch (ρσ_Exception) {
                                ρσ_last_exception = ρσ_Exception;
                                {
                                    offset -= 1;
                                } 
                            }
                        }
                        ρσ_unpack = decoded_range_to_document_position(decoded);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                        doc_x = ρσ_unpack[0];
                        doc_y = ρσ_unpack[1];
                        if (doc_x === null || doc_y === null) {
                            return;
                        }
                        if (scroll_viewport.rtl) {
                            doc_x += scroll_viewport.width();
                        }
                        if (callback) {
                            callback(doc_x, doc_y);
                        }
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.cfi"}
                    });
                    return ρσ_anonfunc;
                })();
            };
            if (!handle_text_node.__module__) Object.defineProperties(handle_text_node, {
                __module__ : {value: "read_book.cfi"}
            });

            function handle_element_node() {
                var node;
                node = decoded.node;
                if (node.nodeType === Node.TEXT_NODE) {
                    node = decoded.node = node.parentNode;
                }
                if (!node.scrollIntoView) {
                    return;
                }
                scroll_viewport.scroll_into_view(node);
                return (function() {
                    var ρσ_anonfunc = function () {
                        var ρσ_unpack, doc_x, doc_y;
                        ρσ_unpack = decoded_node_or_spatial_offset_to_document_position(decoded);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                        doc_x = ρσ_unpack[0];
                        doc_y = ρσ_unpack[1];
                        if (doc_x === null || doc_y === null) {
                            return;
                        }
                        if (scroll_viewport.rtl) {
                            doc_x += scroll_viewport.width();
                        }
                        if (callback) {
                            callback(doc_x, doc_y);
                        }
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.cfi"}
                    });
                    return ρσ_anonfunc;
                })();
            };
            if (!handle_element_node.__module__) Object.defineProperties(handle_element_node, {
                __module__ : {value: "read_book.cfi"}
            });

            if (decoded.range !== null) {
                fn = handle_text_node();
            } else {
                fn = handle_element_node();
            }
            setTimeout(fn, 10);
        };
        if (!scroll_to.__argnames__) Object.defineProperties(scroll_to, {
            __argnames__ : {value: ["cfi", "callback", "doc"]},
            __module__ : {value: "read_book.cfi"}
        });

        function at_point(x, y) {
            var cfi, decoded, ρσ_unpack, cfix, cfiy;
            function dist(p1, p2) {
                Math.sqrt(Math.pow(p1[0] - p2[0], 2), Math.pow(p1[1] - p2[1], 2));
            };
            if (!dist.__argnames__) Object.defineProperties(dist, {
                __argnames__ : {value: ["p1", "p2"]},
                __module__ : {value: "read_book.cfi"}
            });

            try {
                cfi = at(x, y);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    cfi = null;
                } 
            }
            if (cfi === null) {
                return null;
            }
            try {
                decoded = decode_with_range(cfi);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    decoded = null;
                } 
            }
            if (!decoded) {
                return null;
            }
            if (cfi) {
                try {
                    ρσ_unpack = decoded_to_document_position(decoded);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                    cfix = ρσ_unpack[0];
                    cfiy = ρσ_unpack[1];
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        cfix = cfiy = null;
                    } 
                }
                if (cfix === null || cfiy === null || dist(scroll_viewport.viewport_to_document(x, y), [cfix, cfiy]) > 50) {
                    cfi = null;
                }
            }
            return cfi;
        };
        if (!at_point.__argnames__) Object.defineProperties(at_point, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "read_book.cfi"}
        });

        function at_current() {
            var ρσ_unpack, wini, winb, deltai, deltab, startb, endb, starti, endi, up_boundb, up_boundi, low_boundb, low_boundi, at_point_conditional, curb, cfi, x, y, de, rect, px, py;
            ρσ_unpack = [scroll_viewport.inline_size() - 1, scroll_viewport.block_size() - 1];
            wini = ρσ_unpack[0];
            winb = ρσ_unpack[1];
            deltai = deltab = max(8, min(Math.ceil(rem_size() / 2), 32));
            if (scroll_viewport.horizontal_writing_mode) {
                startb = 0;
                endb = winb;
                if (scroll_viewport.ltr) {
                    starti = 0;
                    endi = wini;
                } else {
                    starti = wini;
                    endi = 0;
                    deltai = -deltai;
                }
            } else {
                starti = 0;
                endi = winb;
                if (scroll_viewport.rtl) {
                    startb = winb;
                    endb = 0;
                    deltab = -deltab;
                } else {
                    startb = 0;
                    endb = winb;
                }
            }
            up_boundb = max(startb, endb);
            up_boundi = max(starti, endi);
            low_boundb = min(startb, endb);
            low_boundi = min(starti, endi);
            function at_point_vertical_mode(i, b) {
                return at_point(b, i);
            };
            if (!at_point_vertical_mode.__argnames__) Object.defineProperties(at_point_vertical_mode, {
                __argnames__ : {value: ["i", "b"]},
                __module__ : {value: "read_book.cfi"}
            });

            at_point_conditional = (scroll_viewport.vertical_writing_mode) ? at_point_vertical_mode : at_point;
            function i_loop(curb) {
                var curi, cfi;
                curi = starti;
                while (low_boundi <= curi && curi <= up_boundi) {
                    cfi = at_point_conditional(curi, curb);
                    if (cfi) {
                        return cfi;
                    }
                    curi += deltai;
                }
            };
            if (!i_loop.__argnames__) Object.defineProperties(i_loop, {
                __argnames__ : {value: ["curb"]},
                __module__ : {value: "read_book.cfi"}
            });

            curb = startb;
            cfi = null;
            while (low_boundb <= curb && curb <= up_boundb && !cfi) {
                cfi = i_loop(curb);
                curb += deltab;
            }
            if (cfi) {
                return cfi;
            }
            ρσ_unpack = [scroll_viewport.x() + ((scroll_viewport.ltr) ? 0 : scroll_viewport.width()), 
            scroll_viewport.y()];
            x = ρσ_unpack[0];
            y = ρσ_unpack[1];
            de = document.documentElement;
            rect = de.getBoundingClientRect();
            px = x * 100 / rect.width;
            py = y * 100 / rect.height;
            cfi = str.format("/2@{}:{}", fstr(px), fstr(py));
            return cfi;
        };
        if (!at_current.__module__) Object.defineProperties(at_current, {
            __module__ : {value: "read_book.cfi"}
        });

        function cfi_for_selection(r) {
            if (!r) {
                r = window.getSelection().getRangeAt(0);
            }
            function pos(container, offset) {
                var nt;
                nt = container.nodeType;
                if (nt === Node.TEXT_NODE || nt === Node.CDATA_SECTION_NODE || nt === Node.COMMENT_NODE) {
                    return [container, offset];
                }
                if (nt === Node.ELEMENT_NODE && offset && container.childNodes.length > offset) {
                    return [(ρσ_expr_temp = container.childNodes)[(typeof offset === "number" && offset < 0) ? ρσ_expr_temp.length + offset : offset], 
                    0];
                }
                return [container, offset];
            };
            if (!pos.__argnames__) Object.defineProperties(pos, {
                __argnames__ : {value: ["container", "offset"]},
                __module__ : {value: "read_book.cfi"}
            });

            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["start"] = encode.apply(this, [r.startContainer.ownerDocument].concat(pos(r.startContainer, r.startOffset)));
                ρσ_d["end"] = encode.apply(this, [r.endContainer.ownerDocument].concat(pos(r.endContainer, r.endOffset)));
                return ρσ_d;
            }).call(this);
        };
        if (!cfi_for_selection.__argnames__) Object.defineProperties(cfi_for_selection, {
            __argnames__ : {value: ["r"]},
            __module__ : {value: "read_book.cfi"}
        });

        function range_from_cfi(start, end) {
            var r;
            start = decode(start);
            end = decode(end);
            if (!start || start.error || !end || end.error) {
                return;
            }
            r = document.createRange();
            r.setStart(start.node, start.offset);
            r.setEnd(end.node, end.offset);
            return r;
        };
        if (!range_from_cfi.__argnames__) Object.defineProperties(range_from_cfi, {
            __argnames__ : {value: ["start", "end"]},
            __module__ : {value: "read_book.cfi"}
        });

        ρσ_modules["read_book.cfi"].escape_pat = escape_pat;
        ρσ_modules["read_book.cfi"].unescape_pat = unescape_pat;
        ρσ_modules["read_book.cfi"].escape_for_cfi = escape_for_cfi;
        ρσ_modules["read_book.cfi"].unescape_from_cfi = unescape_from_cfi;
        ρσ_modules["read_book.cfi"].fstr = fstr;
        ρσ_modules["read_book.cfi"].get_current_time = get_current_time;
        ρσ_modules["read_book.cfi"].id_is_unique = id_is_unique;
        ρσ_modules["read_book.cfi"].range_has_point = range_has_point;
        ρσ_modules["read_book.cfi"].offset_in_text_node = offset_in_text_node;
        ρσ_modules["read_book.cfi"].find_offset_for_point = find_offset_for_point;
        ρσ_modules["read_book.cfi"].set_current_time = set_current_time;
        ρσ_modules["read_book.cfi"].is_text_node = is_text_node;
        ρσ_modules["read_book.cfi"].text_length_in_range_wrapper = text_length_in_range_wrapper;
        ρσ_modules["read_book.cfi"].adjust_node_for_text_offset = adjust_node_for_text_offset;
        ρσ_modules["read_book.cfi"].unwrapped_nodes = unwrapped_nodes;
        ρσ_modules["read_book.cfi"].increment_index_for_child = increment_index_for_child;
        ρσ_modules["read_book.cfi"].increment_index_for_children = increment_index_for_children;
        ρσ_modules["read_book.cfi"].non_range_wrapper_parent = non_range_wrapper_parent;
        ρσ_modules["read_book.cfi"].encode = encode;
        ρσ_modules["read_book.cfi"].node_at_index = node_at_index;
        ρσ_modules["read_book.cfi"].node_for_path_step = node_for_path_step;
        ρσ_modules["read_book.cfi"].node_for_text_offset = node_for_text_offset;
        ρσ_modules["read_book.cfi"].decode = decode;
        ρσ_modules["read_book.cfi"].cfi_sort_key = cfi_sort_key;
        ρσ_modules["read_book.cfi"].create_cfi_cmp = create_cfi_cmp;
        ρσ_modules["read_book.cfi"].sort_cfis = sort_cfis;
        ρσ_modules["read_book.cfi"].at = at;
        ρσ_modules["read_book.cfi"].decode_with_range = decode_with_range;
        ρσ_modules["read_book.cfi"].decoded_range_to_document_position = decoded_range_to_document_position;
        ρσ_modules["read_book.cfi"].decoded_node_or_spatial_offset_to_document_position = decoded_node_or_spatial_offset_to_document_position;
        ρσ_modules["read_book.cfi"].decoded_to_document_position = decoded_to_document_position;
        ρσ_modules["read_book.cfi"].scroll_to = scroll_to;
        ρσ_modules["read_book.cfi"].at_point = at_point;
        ρσ_modules["read_book.cfi"].at_current = at_current;
        ρσ_modules["read_book.cfi"].cfi_for_selection = cfi_for_selection;
        ρσ_modules["read_book.cfi"].range_from_cfi = range_from_cfi;
    })();

    (function(){
        var __name__ = "read_book.annotations";
        var no_cfi, field_map, getter_map;
        var _ = ρσ_modules.gettext.gettext;

        var create_cfi_cmp = ρσ_modules["read_book.cfi"].create_cfi_cmp;
        var cfi_sort_key = ρσ_modules["read_book.cfi"].cfi_sort_key;

        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        no_cfi = "/99999999";
        function bookmark_get_cfi(b) {
            if (b.pos_type === "epubcfi") {
                return b.pos.slice(8, -1);
            }
            return no_cfi;
        };
        if (!bookmark_get_cfi.__argnames__) Object.defineProperties(bookmark_get_cfi, {
            __argnames__ : {value: ["b"]},
            __module__ : {value: "read_book.annotations"}
        });

        function highlight_get_cfi(hl) {
            var cfi, si;
            cfi = hl.start_cfi;
            if (cfi) {
                si = (ρσ_exists.n(hl.spine_index)) ? "/" + ρσ_str.format("{}", hl.spine_index) + "" : no_cfi;
                return si + cfi;
            }
            return no_cfi;
        };
        if (!highlight_get_cfi.__argnames__) Object.defineProperties(highlight_get_cfi, {
            __argnames__ : {value: ["hl"]},
            __module__ : {value: "read_book.annotations"}
        });

        function sort_annot_list(annots, get_cfi_func) {
            var key_map, cfi, annot, cfi_cmp;
            key_map = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d[no_cfi] = cfi_sort_key(no_cfi);
                return ρσ_d;
            }).call(this);
            var ρσ_Iter0 = ρσ_Iterable(annots);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                annot = ρσ_Iter0[ρσ_Index0];
                cfi = get_cfi_func(annot);
                if (cfi && !key_map[(typeof cfi === "number" && cfi < 0) ? key_map.length + cfi : cfi]) {
                    key_map[(typeof cfi === "number" && cfi < 0) ? key_map.length + cfi : cfi] = cfi_sort_key(cfi);
                }
            }
            cfi_cmp = create_cfi_cmp(key_map);
            annots.sort((function() {
                var ρσ_anonfunc = function (a, b) {
                    var acfi, bcfi;
                    acfi = get_cfi_func(a);
                    bcfi = get_cfi_func(b);
                    return cfi_cmp(acfi, bcfi);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["a", "b"]},
                    __module__ : {value: "read_book.annotations"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!sort_annot_list.__argnames__) Object.defineProperties(sort_annot_list, {
            __argnames__ : {value: ["annots", "get_cfi_func"]},
            __module__ : {value: "read_book.annotations"}
        });

        function annots_descending_cmp(a, b) {
            return (a.timestamp > b.timestamp) ? -1 : (a.timestamp < b.timestamp) ? 1 : 0;
        };
        if (!annots_descending_cmp.__argnames__) Object.defineProperties(annots_descending_cmp, {
            __argnames__ : {value: ["a", "b"]},
            __module__ : {value: "read_book.annotations"}
        });

        function merge_annots_with_identical_field(annots_a, annots_b, field, cfi_getter_func) {
            var title_groups, changed, all_annots, q, a, tg, seen, ans, title, candidates;
            title_groups = Object.create(null);
            changed = false;
            all_annots = annots_a.concat(annots_b);
            var ρσ_Iter1 = ρσ_Iterable(all_annots);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                a = ρσ_Iter1[ρσ_Index1];
                q = title_groups[ρσ_bound_index(a[(typeof field === "number" && field < 0) ? a.length + field : field], title_groups)];
                if (!q) {
                    q = title_groups[ρσ_bound_index(a[(typeof field === "number" && field < 0) ? a.length + field : field], title_groups)] = [];
                }
                q.push(a);
            }
            var ρσ_Iter2 = ρσ_Iterable(Object.values(title_groups));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                tg = ρσ_Iter2[ρσ_Index2];
                tg.sort(annots_descending_cmp);
            }
            seen = Object.create(null);
            ans = [];
            var ρσ_Iter3 = ρσ_Iterable(all_annots);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                a = ρσ_Iter3[ρσ_Index3];
                title = a[(typeof field === "number" && field < 0) ? a.length + field : field];
                if (!seen[(typeof title === "number" && title < 0) ? seen.length + title : title]) {
                    seen[(typeof title === "number" && title < 0) ? seen.length + title : title] = true;
                    candidates = title_groups[(typeof title === "number" && title < 0) ? title_groups.length + title : title];
                    if (!changed && candidates.length > 1 && candidates[0].timestamp !== candidates[1].timestamp) {
                        changed = true;
                    }
                    ans.push(title_groups[(typeof title === "number" && title < 0) ? title_groups.length + title : title][0]);
                }
            }
            if (ans.length !== annots_a.length || ans.length !== annots_b.length) {
                changed = true;
            }
            if (changed) {
                sort_annot_list(ans, cfi_getter_func);
            }
            return [changed, ans];
        };
        if (!merge_annots_with_identical_field.__argnames__) Object.defineProperties(merge_annots_with_identical_field, {
            __argnames__ : {value: ["annots_a", "annots_b", "field", "cfi_getter_func"]},
            __module__ : {value: "read_book.annotations"}
        });

        field_map = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["bookmark"] = "title";
            ρσ_d["highlight"] = "uuid";
            return ρσ_d;
        }).call(this);
        getter_map = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["bookmark"] = bookmark_get_cfi;
            ρσ_d["highlight"] = highlight_get_cfi;
            return ρσ_d;
        }).call(this);
        function merge_annot_lists(a, b, field) {
            var key_field;
            key_field = field_map[(typeof field === "number" && field < 0) ? field_map.length + field : field];
            return merge_annots_with_identical_field(a, b, key_field, getter_map[(typeof field === "number" && field < 0) ? getter_map.length + field : field]);
        };
        if (!merge_annot_lists.__argnames__) Object.defineProperties(merge_annot_lists, {
            __argnames__ : {value: ["a", "b", "field"]},
            __module__ : {value: "read_book.annotations"}
        });

        function merge_annotation_maps(a, b) {
            var updated, ans, a_items, b_items, ρσ_unpack, changed, field;
            updated = false;
            ans = Object.create(null);
            var ρσ_Iter4 = ρσ_Iterable(field_map);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                field = ρσ_Iter4[ρσ_Index4];
                a_items = a[(typeof field === "number" && field < 0) ? a.length + field : field] || [];
                b_items = b[(typeof field === "number" && field < 0) ? b.length + field : field] || [];
                if (!a_items.length) {
                    ans[(typeof field === "number" && field < 0) ? ans.length + field : field] = b_items;
                    updated = true;
                    continue;
                }
                if (!b_items.length) {
                    ans[(typeof field === "number" && field < 0) ? ans.length + field : field] = a_items;
                    continue;
                }
                ρσ_unpack = merge_annot_lists(a_items, b_items, field);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                changed = ρσ_unpack[0];
                ans[(typeof field === "number" && field < 0) ? ans.length + field : field] = ρσ_unpack[1];
                if (changed) {
                    updated = true;
                }
            }
            return [updated, ans];
        };
        if (!merge_annotation_maps.__argnames__) Object.defineProperties(merge_annotation_maps, {
            __argnames__ : {value: ["a", "b"]},
            __module__ : {value: "read_book.annotations"}
        });

        function AnnotationsManager() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            AnnotationsManager.prototype.__bind_methods__.call(this);
            AnnotationsManager.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(AnnotationsManager.prototype, "__bind_methods__", {value: function () {
            this.sync_annots_to_server = AnnotationsManager.prototype.sync_annots_to_server.bind(this);
            this.set_bookmarks = AnnotationsManager.prototype.set_bookmarks.bind(this);
            this.all_bookmarks = AnnotationsManager.prototype.all_bookmarks.bind(this);
            this.add_bookmark = AnnotationsManager.prototype.add_bookmark.bind(this);
            this.remove_bookmark = AnnotationsManager.prototype.remove_bookmark.bind(this);
            this.edit_bookmark = AnnotationsManager.prototype.edit_bookmark.bind(this);
            this.default_bookmark_title = AnnotationsManager.prototype.default_bookmark_title.bind(this);
            this.set_highlights = AnnotationsManager.prototype.set_highlights.bind(this);
            this.all_highlights = AnnotationsManager.prototype.all_highlights.bind(this);
            this.merge_highlights = AnnotationsManager.prototype.merge_highlights.bind(this);
            this.remove_highlight = AnnotationsManager.prototype.remove_highlight.bind(this);
            this.delete_highlight = AnnotationsManager.prototype.delete_highlight.bind(this);
            this.notes_for_highlight = AnnotationsManager.prototype.notes_for_highlight.bind(this);
            this.text_for_highlight = AnnotationsManager.prototype.text_for_highlight.bind(this);
            this.set_notes_for_highlight = AnnotationsManager.prototype.set_notes_for_highlight.bind(this);
            this.style_for_highlight = AnnotationsManager.prototype.style_for_highlight.bind(this);
            this.data_for_highlight = AnnotationsManager.prototype.data_for_highlight.bind(this);
            this.spine_index_for_highlight = AnnotationsManager.prototype.spine_index_for_highlight.bind(this);
            this.cfi_for_highlight = AnnotationsManager.prototype.cfi_for_highlight.bind(this);
            this.add_highlight = AnnotationsManager.prototype.add_highlight.bind(this);
            this.highlights_for_currently_showing = AnnotationsManager.prototype.highlights_for_currently_showing.bind(this);
        }});
        AnnotationsManager.prototype.__init__ = function __init__(view) {
            var self = this;
            self.view = view;
            self.set_highlights();
            self.set_bookmarks();
        };
        if (!AnnotationsManager.prototype.__init__.__argnames__) Object.defineProperties(AnnotationsManager.prototype.__init__, {
            __argnames__ : {value: ["view"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.__argnames__ = AnnotationsManager.prototype.__init__.__argnames__;
        AnnotationsManager.__handles_kwarg_interpolation__ = AnnotationsManager.prototype.__init__.__handles_kwarg_interpolation__;
        AnnotationsManager.prototype.sync_annots_to_server = function sync_annots_to_server(which) {
            var self = this;
            var amap;
            if (ui_operations.annots_changed) {
                amap = Object.create(null);
                if (!which || which === "bookmarks") {
                    amap.bookmark = self.bookmarks.as_array();
                }
                if (!which || which === "highlights") {
                    amap.highlight = Object.values(self.highlights);
                }
                ui_operations.annots_changed(amap);
            }
        };
        if (!AnnotationsManager.prototype.sync_annots_to_server.__argnames__) Object.defineProperties(AnnotationsManager.prototype.sync_annots_to_server, {
            __argnames__ : {value: ["which"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.set_bookmarks = function set_bookmarks(bookmarks) {
            var self = this;
            bookmarks = bookmarks || [];
            self.bookmarks = list(bookmarks);
        };
        if (!AnnotationsManager.prototype.set_bookmarks.__argnames__) Object.defineProperties(AnnotationsManager.prototype.set_bookmarks, {
            __argnames__ : {value: ["bookmarks"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.all_bookmarks = function all_bookmarks() {
            var self = this;
            return self.bookmarks;
        };
        if (!AnnotationsManager.prototype.all_bookmarks.__module__) Object.defineProperties(AnnotationsManager.prototype.all_bookmarks, {
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.add_bookmark = function add_bookmark(title, cfi) {
            var self = this;
            var b;
            if (!title || !cfi) {
                return;
            }
            self.bookmarks = (function() {
                var ρσ_Iter = ρσ_Iterable(self.bookmarks), ρσ_Result = [], b;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    b = ρσ_Iter[ρσ_Index];
                    if (b.title !== title) {
                        ρσ_Result.push(b);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
            self.bookmarks.push((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "bookmark";
                ρσ_d["timestamp"] = (new Date).toISOString();
                ρσ_d["pos_type"] = "epubcfi";
                ρσ_d["pos"] = cfi;
                ρσ_d["title"] = title;
                return ρσ_d;
            }).call(this));
            sort_annot_list(self.bookmarks, bookmark_get_cfi);
            self.sync_annots_to_server("bookmarks");
        };
        if (!AnnotationsManager.prototype.add_bookmark.__argnames__) Object.defineProperties(AnnotationsManager.prototype.add_bookmark, {
            __argnames__ : {value: ["title", "cfi"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.remove_bookmark = function remove_bookmark(title) {
            var self = this;
            var changed, b;
            changed = false;
            var ρσ_Iter5 = ρσ_Iterable(self.bookmarks);
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                b = ρσ_Iter5[ρσ_Index5];
                if (b.title === title) {
                    b.removed = true;
                    b.timestamp = (new Date).toISOString();
                    changed = true;
                }
            }
            if (changed) {
                self.sync_annots_to_server("bookmarks");
            }
            return changed;
        };
        if (!AnnotationsManager.prototype.remove_bookmark.__argnames__) Object.defineProperties(AnnotationsManager.prototype.remove_bookmark, {
            __argnames__ : {value: ["title"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.edit_bookmark = function edit_bookmark(title, new_title) {
            var self = this;
            var changed, b;
            changed = false;
            var ρσ_Iter6 = ρσ_Iterable(self.bookmarks);
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                b = ρσ_Iter6[ρσ_Index6];
                if (b.title === title) {
                    b.title = new_title;
                    b.timestamp = (new Date).toISOString();
                    changed = true;
                }
            }
            if (changed) {
                self.sync_annots_to_server("bookmarks");
            }
            return changed;
        };
        if (!AnnotationsManager.prototype.edit_bookmark.__argnames__) Object.defineProperties(AnnotationsManager.prototype.edit_bookmark, {
            __argnames__ : {value: ["title", "new_title"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.default_bookmark_title = function default_bookmark_title(base_default_title) {
            var self = this;
            var all_titles, bm, c, default_title;
            all_titles = (function() {
                var ρσ_Iter = ρσ_Iterable(self.bookmarks), ρσ_Result = Object.create(null), bm;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    bm = ρσ_Iter[ρσ_Index];
                    if (!bm.removed) {
                        ρσ_Result[bm.title] = (true);
                    }
                }
                return ρσ_Result;
            })();
            base_default_title = base_default_title || _("Bookmark");
            c = 0;
            while (true) {
                c += 1;
                default_title = "" + ρσ_str.format("{}", base_default_title) + " #" + ρσ_str.format("{}", c) + "";
                if (!all_titles[(typeof default_title === "number" && default_title < 0) ? all_titles.length + default_title : default_title]) {
                    return default_title;
                }
            }
        };
        if (!AnnotationsManager.prototype.default_bookmark_title.__argnames__) Object.defineProperties(AnnotationsManager.prototype.default_bookmark_title, {
            __argnames__ : {value: ["base_default_title"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.set_highlights = function set_highlights(highlights) {
            var self = this;
            var h;
            highlights = highlights || [];
            self.highlights = (function() {
                var ρσ_Iter = ρσ_Iterable(highlights), ρσ_Result = Object.create(null), h;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    h = ρσ_Iter[ρσ_Index];
                    ρσ_Result[h.uuid] = (h);
                }
                return ρσ_Result;
            })();
        };
        if (!AnnotationsManager.prototype.set_highlights.__argnames__) Object.defineProperties(AnnotationsManager.prototype.set_highlights, {
            __argnames__ : {value: ["highlights"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.all_highlights = function all_highlights() {
            var self = this;
            var ans;
            ans = (function() {
                var ρσ_Iter = ρσ_Iterable(Object.values(self.highlights)), ρσ_Result = [], h;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    h = ρσ_Iter[ρσ_Index];
                    if (!h.removed) {
                        ρσ_Result.push(h);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })().as_array();
            sort_annot_list(ans, highlight_get_cfi);
            return ans;
        };
        if (!AnnotationsManager.prototype.all_highlights.__module__) Object.defineProperties(AnnotationsManager.prototype.all_highlights, {
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.merge_highlights = function merge_highlights(highlights) {
            var self = this;
            var updated, base, newvals, ρσ_unpack, ans;
            highlights = highlights || [];
            updated = false;
            if (highlights.length) {
                base = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["highlight"] = Object.values(self.highlights);
                    return ρσ_d;
                }).call(this);
                newvals = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["highlight"] = highlights;
                    return ρσ_d;
                }).call(this);
                ρσ_unpack = merge_annotation_maps(base, newvals);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                updated = ρσ_unpack[0];
                ans = ρσ_unpack[1];
                if (updated) {
                    self.set_highlights(ans.highlight);
                }
            }
            return updated;
        };
        if (!AnnotationsManager.prototype.merge_highlights.__argnames__) Object.defineProperties(AnnotationsManager.prototype.merge_highlights, {
            __argnames__ : {value: ["highlights"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.remove_highlight = function remove_highlight(uuid) {
            var self = this;
            var h;
            h = (ρσ_expr_temp = self.highlights)[(typeof uuid === "number" && uuid < 0) ? ρσ_expr_temp.length + uuid : uuid];
            if (h) {
                h.timestamp = (new Date).toISOString();
                h.removed = true;
                delete h.style;
                delete h.highlighted_text;
                delete h.start_cfi;
                delete h.end_cfi;
                delete h.notes;
                delete h.spine_name;
                delete h.spine_index;
                delete h.toc_family_titles;
                return true;
            }
        };
        if (!AnnotationsManager.prototype.remove_highlight.__argnames__) Object.defineProperties(AnnotationsManager.prototype.remove_highlight, {
            __argnames__ : {value: ["uuid"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.delete_highlight = function delete_highlight(uuid) {
            var self = this;
            if (self.remove_highlight(uuid)) {
                self.sync_annots_to_server("highlights");
            }
        };
        if (!AnnotationsManager.prototype.delete_highlight.__argnames__) Object.defineProperties(AnnotationsManager.prototype.delete_highlight, {
            __argnames__ : {value: ["uuid"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.notes_for_highlight = function notes_for_highlight(uuid) {
            var self = this;
            var h;
            h = (uuid) ? (ρσ_expr_temp = self.highlights)[(typeof uuid === "number" && uuid < 0) ? ρσ_expr_temp.length + uuid : uuid] : null;
            if (h) {
                return h.notes;
            }
        };
        if (!AnnotationsManager.prototype.notes_for_highlight.__argnames__) Object.defineProperties(AnnotationsManager.prototype.notes_for_highlight, {
            __argnames__ : {value: ["uuid"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.text_for_highlight = function text_for_highlight(uuid) {
            var self = this;
            var h;
            h = (uuid) ? (ρσ_expr_temp = self.highlights)[(typeof uuid === "number" && uuid < 0) ? ρσ_expr_temp.length + uuid : uuid] : null;
            if (h) {
                return h.highlighted_text;
            }
        };
        if (!AnnotationsManager.prototype.text_for_highlight.__argnames__) Object.defineProperties(AnnotationsManager.prototype.text_for_highlight, {
            __argnames__ : {value: ["uuid"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.set_notes_for_highlight = function set_notes_for_highlight(uuid, notes) {
            var self = this;
            var h;
            h = (ρσ_expr_temp = self.highlights)[(typeof uuid === "number" && uuid < 0) ? ρσ_expr_temp.length + uuid : uuid];
            if (h) {
                if (notes) {
                    h.notes = notes;
                } else {
                    delete h.notes;
                }
                self.sync_annots_to_server("highlights");
                return true;
            }
            return false;
        };
        if (!AnnotationsManager.prototype.set_notes_for_highlight.__argnames__) Object.defineProperties(AnnotationsManager.prototype.set_notes_for_highlight, {
            __argnames__ : {value: ["uuid", "notes"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.style_for_highlight = function style_for_highlight(uuid) {
            var self = this;
            var h;
            h = (ρσ_expr_temp = self.highlights)[(typeof uuid === "number" && uuid < 0) ? ρσ_expr_temp.length + uuid : uuid];
            if (h) {
                return h.style;
            }
        };
        if (!AnnotationsManager.prototype.style_for_highlight.__argnames__) Object.defineProperties(AnnotationsManager.prototype.style_for_highlight, {
            __argnames__ : {value: ["uuid"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.data_for_highlight = function data_for_highlight(uuid) {
            var self = this;
            return (ρσ_expr_temp = self.highlights)[(typeof uuid === "number" && uuid < 0) ? ρσ_expr_temp.length + uuid : uuid];
        };
        if (!AnnotationsManager.prototype.data_for_highlight.__argnames__) Object.defineProperties(AnnotationsManager.prototype.data_for_highlight, {
            __argnames__ : {value: ["uuid"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.spine_index_for_highlight = function spine_index_for_highlight(uuid, spine) {
            var self = this;
            var h, ans, name, idx;
            h = (ρσ_expr_temp = self.highlights)[(typeof uuid === "number" && uuid < 0) ? ρσ_expr_temp.length + uuid : uuid];
            if (!h) {
                return -1;
            }
            ans = h.spine_index;
            name = h.spine_name;
            if (name) {
                idx = spine.indexOf(name);
                if (idx > -1) {
                    ans = idx;
                }
            }
            return ans;
        };
        if (!AnnotationsManager.prototype.spine_index_for_highlight.__argnames__) Object.defineProperties(AnnotationsManager.prototype.spine_index_for_highlight, {
            __argnames__ : {value: ["uuid", "spine"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.cfi_for_highlight = function cfi_for_highlight(uuid, spine_index) {
            var self = this;
            var h, x;
            h = (ρσ_expr_temp = self.highlights)[(typeof uuid === "number" && uuid < 0) ? ρσ_expr_temp.length + uuid : uuid];
            if (h) {
                x = 2 * (spine_index + 1);
                return "epubcfi(/" + ρσ_str.format("{}", x) + "" + ρσ_str.format("{}", h.start_cfi) + ")";
            }
        };
        if (!AnnotationsManager.prototype.cfi_for_highlight.__argnames__) Object.defineProperties(AnnotationsManager.prototype.cfi_for_highlight, {
            __argnames__ : {value: ["uuid", "spine_index"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.add_highlight = function add_highlight(msg, style, notes, toc_family) {
            var self = this;
            var now, uuid, annot, toc_family_titles, x;
            now = (new Date).toISOString();
            var ρσ_Iter7 = ρσ_Iterable(msg.removed_highlights);
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                uuid = ρσ_Iter7[ρσ_Index7];
                self.remove_highlight(uuid);
            }
            annot = (ρσ_expr_temp = self.highlights)[ρσ_bound_index(msg.uuid, ρσ_expr_temp)] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "highlight";
                ρσ_d["timestamp"] = now;
                ρσ_d["uuid"] = msg.uuid;
                ρσ_d["highlighted_text"] = msg.highlighted_text;
                ρσ_d["start_cfi"] = msg.bounds.start;
                ρσ_d["end_cfi"] = msg.bounds.end;
                ρσ_d["style"] = style;
                ρσ_d["spine_name"] = self.view.currently_showing.name;
                ρσ_d["spine_index"] = self.view.currently_showing.spine_index;
                return ρσ_d;
            }).call(this);
            if (notes) {
                annot.notes = notes;
            }
            if ((typeof toc_family !== "undefined" && toc_family !== null ? toc_family : Object.create(null)).length) {
                toc_family_titles = [];
                var ρσ_Iter8 = ρσ_Iterable(toc_family);
                for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                    x = ρσ_Iter8[ρσ_Index8];
                    if (x.title) {
                        toc_family_titles.push(x.title);
                    }
                }
                annot.toc_family_titles = toc_family_titles;
            }
            self.sync_annots_to_server("highlights");
        };
        if (!AnnotationsManager.prototype.add_highlight.__argnames__) Object.defineProperties(AnnotationsManager.prototype.add_highlight, {
            __argnames__ : {value: ["msg", "style", "notes", "toc_family"]},
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.highlights_for_currently_showing = function highlights_for_currently_showing() {
            var self = this;
            var name, ans, h;
            name = self.view.currently_showing.name;
            ans = [];
            var ρσ_Iter9 = ρσ_Iterable(Object.values(self.highlights));
            for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                h = ρσ_Iter9[ρσ_Index9];
                if (h.spine_name === name && !h.removed && h.start_cfi) {
                    ans.push(h);
                }
            }
            return ans;
        };
        if (!AnnotationsManager.prototype.highlights_for_currently_showing.__module__) Object.defineProperties(AnnotationsManager.prototype.highlights_for_currently_showing, {
            __module__ : {value: "read_book.annotations"}
        });
        AnnotationsManager.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        AnnotationsManager.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(AnnotationsManager.prototype, "__bases__", {value: []});

        ρσ_modules["read_book.annotations"].no_cfi = no_cfi;
        ρσ_modules["read_book.annotations"].field_map = field_map;
        ρσ_modules["read_book.annotations"].getter_map = getter_map;
        ρσ_modules["read_book.annotations"].bookmark_get_cfi = bookmark_get_cfi;
        ρσ_modules["read_book.annotations"].highlight_get_cfi = highlight_get_cfi;
        ρσ_modules["read_book.annotations"].sort_annot_list = sort_annot_list;
        ρσ_modules["read_book.annotations"].annots_descending_cmp = annots_descending_cmp;
        ρσ_modules["read_book.annotations"].merge_annots_with_identical_field = merge_annots_with_identical_field;
        ρσ_modules["read_book.annotations"].merge_annot_lists = merge_annot_lists;
        ρσ_modules["read_book.annotations"].merge_annotation_maps = merge_annotation_maps;
        ρσ_modules["read_book.annotations"].AnnotationsManager = AnnotationsManager;
    })();

    (function(){
        var __name__ = "read_book.db";
        var DB_NAME, DB_VERSION;
        var base64decode = ρσ_modules.encodings.base64decode;
        var base64encode = ρσ_modules.encodings.base64encode;

        var _ = ρσ_modules.gettext.gettext;

        var is_reading_book = ρσ_modules["book_list.router"].is_reading_book;

        var error_dialog = ρσ_modules.modals.error_dialog;

        var merge_annotation_maps = ρσ_modules["read_book.annotations"].merge_annotation_maps;

        var get_interface_data = ρσ_modules.session.get_interface_data;

        var username_key = ρσ_modules.utils.username_key;

        function upgrade_schema(idb, old_version, new_version, transaction) {
            var books_store;
            print("upgrade_schema:", old_version, new_version);
            if (!idb.objectStoreNames.contains("books")) {
                idb.createObjectStore("books", (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["keyPath"] = "key";
                    return ρσ_d;
                }).call(this));
            }
            if (!idb.objectStoreNames.contains("files")) {
                idb.createObjectStore("files");
            }
            if (!idb.objectStoreNames.contains("mathjax")) {
                idb.createObjectStore("mathjax");
            }
            if (!idb.objectStoreNames.contains("objects")) {
                idb.createObjectStore("objects", (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["keyPath"] = "key";
                    return ρσ_d;
                }).call(this));
            }
            books_store = transaction.objectStore("books");
            if (!books_store.indexNames.contains("recent_index")) {
                books_store.createIndex("recent_index", "recent_date");
            }
        };
        if (!upgrade_schema.__argnames__) Object.defineProperties(upgrade_schema, {
            __argnames__ : {value: ["idb", "old_version", "new_version", "transaction"]},
            __module__ : {value: "read_book.db"}
        });

        function file_store_name(book, name) {
            return book.book_hash + " " + name;
        };
        if (!file_store_name.__argnames__) Object.defineProperties(file_store_name, {
            __argnames__ : {value: ["book", "name"]},
            __module__ : {value: "read_book.db"}
        });

        function get_error_details(event) {
            var desc;
            desc = event.target;
            if (desc.error && desc.error.toString) {
                desc = desc.error.toString();
            } else if (desc.errorCode) {
                desc = desc.errorCode;
            } else if (desc.error) {
                desc = desc.error;
                if (desc.name === "QuotaExceededError") {
                    desc = _("Offline storage quota exceeded! Try deleting some stored books first.");
                } else if (desc.name) {
                    desc = desc.name;
                }
            }
            return desc || "Unknown Error";
        };
        if (!get_error_details.__argnames__) Object.defineProperties(get_error_details, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "read_book.db"}
        });

        function new_book(key, metadata) {
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["key"] = key;
                ρσ_d["is_complete"] = false;
                ρσ_d["stored_files"] = Object.create(null);
                ρσ_d["book_hash"] = null;
                ρσ_d["metadata"] = metadata;
                ρσ_d["manifest"] = null;
                ρσ_d["cover_width"] = null;
                ρσ_d["cover_height"] = null;
                ρσ_d["cover_name"] = null;
                ρσ_d["recent_date"] = new Date;
                ρσ_d["last_read"] = Object.create(null);
                ρσ_d["last_read_position"] = Object.create(null);
                ρσ_d["saved_reading_rates"] = Object.create(null);
                ρσ_d["annotations_map"] = Object.create(null);
                return ρσ_d;
            }).call(this);
        };
        if (!new_book.__argnames__) Object.defineProperties(new_book, {
            __argnames__ : {value: ["key", "metadata"]},
            __module__ : {value: "read_book.db"}
        });

        DB_NAME = "calibre";
        DB_VERSION = 1;
        function indexed_db_api() {
            if ((typeof window !== "undefined" && window !== null)) {
                return window.indexedDB;
            }
            if ((typeof self !== "undefined" && self !== null)) {
                return self.indexedDB;
            }
        };
        if (!indexed_db_api.__module__) Object.defineProperties(indexed_db_api, {
            __module__ : {value: "read_book.db"}
        });

        function DB() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            DB.prototype.__bind_methods__.call(this);
            DB.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(DB.prototype, "__bind_methods__", {value: function () {
            this.show_error = DB.prototype.show_error.bind(this);
            this.initialize_stage1 = DB.prototype.initialize_stage1.bind(this);
            this.initialize_stage2 = DB.prototype.initialize_stage2.bind(this);
            this.display_error = DB.prototype.display_error.bind(this);
            this.do_op = DB.prototype.do_op.bind(this);
            this.set_pending_annot_upload = DB.prototype.set_pending_annot_upload.bind(this);
            this.get_all_pending_annot_uploads = DB.prototype.get_all_pending_annot_uploads.bind(this);
            this.clear_pending_annot_upload = DB.prototype.clear_pending_annot_upload.bind(this);
            this.get_book = DB.prototype.get_book.bind(this);
            this.get_mathjax_info = DB.prototype.get_mathjax_info.bind(this);
            this.save_manifest = DB.prototype.save_manifest.bind(this);
            this.store_file = DB.prototype.store_file.bind(this);
            this.store_cover = DB.prototype.store_cover.bind(this);
            this.store_file_stage2 = DB.prototype.store_file_stage2.bind(this);
            this.clear_mathjax = DB.prototype.clear_mathjax.bind(this);
            this.store_mathjax_file = DB.prototype.store_mathjax_file.bind(this);
            this.finish_book = DB.prototype.finish_book.bind(this);
            this.finish_mathjax = DB.prototype.finish_mathjax.bind(this);
            this.update_last_read_time = DB.prototype.update_last_read_time.bind(this);
            this.update_metadata = DB.prototype.update_metadata.bind(this);
            this.save_reading_rates = DB.prototype.save_reading_rates.bind(this);
            this.update_annotations_data_from_key = DB.prototype.update_annotations_data_from_key.bind(this);
            this.get_file = DB.prototype.get_file.bind(this);
            this.get_book_file = DB.prototype.get_book_file.bind(this);
            this.get_mathjax_files = DB.prototype.get_mathjax_files.bind(this);
            this.get_books_by_recent_date = DB.prototype.get_books_by_recent_date.bind(this);
            this.get_recently_read_books = DB.prototype.get_recently_read_books.bind(this);
            this.get_downloaded_books = DB.prototype.get_downloaded_books.bind(this);
            this.has_book_matching = DB.prototype.has_book_matching.bind(this);
            this.delete_book = DB.prototype.delete_book.bind(this);
            this.delete_books_matching = DB.prototype.delete_books_matching.bind(this);
        }});
        DB.prototype.__init__ = function __init__(callback, show_read_book_error) {
            var self = this;
            self.initialized = false;
            self.is_ok = false;
            self.initialize_error_msg = null;
            self.callback = callback;
            self.show_read_book_error = show_read_book_error;
            self.initialize_stage1();
        };
        if (!DB.prototype.__init__.__argnames__) Object.defineProperties(DB.prototype.__init__, {
            __argnames__ : {value: ["callback", "show_read_book_error"]},
            __module__ : {value: "read_book.db"}
        });
        DB.__argnames__ = DB.prototype.__init__.__argnames__;
        DB.__handles_kwarg_interpolation__ = DB.prototype.__init__.__handles_kwarg_interpolation__;
        DB.prototype.show_error = function show_error(title, msg, det_msg) {
            var self = this;
            if (!(typeof window !== "undefined" && window !== null) || is_reading_book()) {
                self.show_read_book_error(title, msg, det_msg);
            } else {
                error_dialog(title, msg, det_msg);
            }
        };
        if (!DB.prototype.show_error.__argnames__) Object.defineProperties(DB.prototype.show_error, {
            __argnames__ : {value: ["title", "msg", "det_msg"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.initialize_stage1 = function initialize_stage1() {
            var self = this;
            var idb, request;
            idb = indexed_db_api();
            if (!idb) {
                self.initialize_error_msg = _("Your browser does not support IndexedDB. Cannot read books. Consider using a modern browser, such as Chrome or Firefox.");
                self.initialized = true;
                setTimeout(self.callback, 0);
                return;
            }
            request = idb.open(DB_NAME, DB_VERSION);
            request.onupgradeneeded = (function() {
                var ρσ_anonfunc = function (event) {
                    upgrade_schema(event.target.result, event.oldVersion, event.newVersion, event.target.transaction);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            request.onblocked = (function() {
                var ρσ_anonfunc = function (event) {
                    self.initialize_error_msg = _("Please close all other browser tabs with calibre open");
                    self.initialized = true;
                    console.log(event);
                    self.callback();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            request.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    self.initialize_error_msg = _("You must allow calibre to use IndexedDB storage in your browser to read books");
                    self.initialized = true;
                    console.log(event);
                    self.callback();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            request.onsuccess = (function() {
                var ρσ_anonfunc = function (event) {
                    var blob, idb, store, req;
                    blob = new Blob(ρσ_list_decorate([ "test" ]), (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["type"] = "text/plain";
                        return ρσ_d;
                    }).call(this));
                    idb = event.target.result;
                    store = idb.transaction(ρσ_list_decorate([ "files" ]), "readwrite").objectStore("files");
                    try {
                        req = store.put(blob, ":-test-blob-:");
                    } catch (ρσ_Exception) {
                        ρσ_last_exception = ρσ_Exception;
                        {
                            self.initialize_stage2(idb, false);
                            return;
                        } 
                    }
                    req.onsuccess = (function() {
                        var ρσ_anonfunc = function (event) {
                            self.initialize_stage2(idb, true);
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["event"]},
                            __module__ : {value: "read_book.db"}
                        });
                        return ρσ_anonfunc;
                    })();
                    req.onerror = (function() {
                        var ρσ_anonfunc = function (event) {
                            setTimeout(self.initialize_stage2.bind(null, idb, false), 0);
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["event"]},
                            __module__ : {value: "read_book.db"}
                        });
                        return ρσ_anonfunc;
                    })();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!DB.prototype.initialize_stage1.__module__) Object.defineProperties(DB.prototype.initialize_stage1, {
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.initialize_stage2 = function initialize_stage2(idb, supports_blobs) {
            var self = this;
            self.idb = idb;
            self.supports_blobs = supports_blobs;
            self.initialized = true;
            self.is_ok = true;
            if (!supports_blobs) {
                print("WARNING: browser does not support blob storage, calibre falling back to base64 encoding");
            }
            idb.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    self.display_error(null, event);
                    if (console.dir) {
                        console.dir(event);
                    } else {
                        console.log(event);
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            idb.onversionchange = (function() {
                var ρσ_anonfunc = function (event) {
                    idb.close();
                    self.show_error(_("Database upgraded!"), _("A newer version of calibre is available, please click the Reload button in your browser."));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            function try_persist(lock) {
                if (!lock) {
                    return;
                }
                return window.navigator.storage.persisted().then((function() {
                    var ρσ_anonfunc = function (already_persistent) {
                        if (!already_persistent) {
                            return window.navigator.storage.persist();
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["already_persistent"]},
                        __module__ : {value: "read_book.db"}
                    });
                    return ρσ_anonfunc;
                })());
            };
            if (!try_persist.__argnames__) Object.defineProperties(try_persist, {
                __argnames__ : {value: ["lock"]},
                __module__ : {value: "read_book.db"}
            });

            if (ρσ_exists.d(ρσ_exists.d((typeof window !== "undefined" && window !== null ? window : Object.create(null)).navigator).storage).persist) {
                if (window.navigator.locks) {
                    window.navigator.locks.request("calibre-storage-persist", (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["ifAvailable"] = true;
                        return ρσ_d;
                    }).call(this), try_persist);
                } else {
                    window.navigator.storage.persisted().then((function() {
                        var ρσ_anonfunc = function (already_persistent) {
                            if (!already_persistent) {
                                window.navigator.storage.persist();
                            }
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["already_persistent"]},
                            __module__ : {value: "read_book.db"}
                        });
                        return ρσ_anonfunc;
                    })());
                }
            }
            self.callback();
        };
        if (!DB.prototype.initialize_stage2.__argnames__) Object.defineProperties(DB.prototype.initialize_stage2, {
            __argnames__ : {value: ["idb", "supports_blobs"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.display_error = function display_error(msg, event) {
            var self = this;
            if (event.already_displayed_by_calibre) {
                return;
            }
            event.already_displayed_by_calibre = true;
            msg = msg || _("There was an error while interacting with the database used to store books for offline reading. Click \"Show details\" for more information.");
            self.show_error(_("Cannot read book"), msg, get_error_details(event));
        };
        if (!DB.prototype.display_error.__argnames__) Object.defineProperties(DB.prototype.display_error, {
            __argnames__ : {value: ["msg", "event"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.do_op = function do_op() {
            var self = this;
            var stores = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var data = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var error_msg = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var proceed = ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[3];
            var op = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? do_op.__defaults__.op : arguments[4];
            var store = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? do_op.__defaults__.store : arguments[5];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "op")){
                op = ρσ_kwargs_obj.op;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "store")){
                store = ρσ_kwargs_obj.store;
            }
            var transaction, req;
            store = store || stores[0];
            if (op === "get") {
                transaction = self.idb.transaction(stores);
                req = transaction.objectStore(store).get(data);
                req.onsuccess = (function() {
                    var ρσ_anonfunc = function (event) {
                        if (proceed) {
                            proceed(req.result);
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["event"]},
                        __module__ : {value: "read_book.db"}
                    });
                    return ρσ_anonfunc;
                })();
            } else if (op === "put") {
                transaction = self.idb.transaction(stores, "readwrite");
                req = transaction.objectStore(store).put(data);
                if (proceed) {
                    req.onsuccess = proceed;
                }
            } else if (op === "delete") {
                transaction = self.idb.transaction(stores, "readwrite");
                req = transaction.objectStore(store).delete(data);
                if (proceed) {
                    req.onsuccess = proceed;
                }
            }
            req.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    self.display_error(error_msg, event);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!DB.prototype.do_op.__defaults__) Object.defineProperties(DB.prototype.do_op, {
            __defaults__ : {value: {op:"get", store:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["stores", "data", "error_msg", "proceed", "op", "store"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.set_pending_annot_upload = function set_pending_annot_upload(library_id, book_id, fmt, amap) {
            var self = this;
            var key, entry;
            key = "pending-annot-upload:" + ρσ_str.format("{}", library_id) + "/" + ρσ_str.format("{}", book_id) + "/" + ρσ_str.format("{}", fmt) + "";
            entry = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["key"] = key;
                ρσ_d["library_id"] = library_id;
                ρσ_d["book_id"] = book_id;
                ρσ_d["fmt"] = fmt;
                ρσ_d["amap"] = amap;
                return ρσ_d;
            }).call(this);
            ρσ_interpolate_kwargs.call(self, self.do_op, [ρσ_list_decorate([ "objects" ]), entry, _("Failed to save pending annotation upload"), (function() {
                var ρσ_anonfunc = function () {
                    null;
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })()].concat([ρσ_desugar_kwargs({op: "put"})]));
        };
        if (!DB.prototype.set_pending_annot_upload.__argnames__) Object.defineProperties(DB.prototype.set_pending_annot_upload, {
            __argnames__ : {value: ["library_id", "book_id", "fmt", "amap"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.get_all_pending_annot_uploads = function get_all_pending_annot_uploads(proceed) {
            var self = this;
            var transaction, store, key_range, entries, req;
            transaction = self.idb.transaction(ρσ_list_decorate([ "objects" ]));
            store = transaction.objectStore("objects");
            key_range = IDBKeyRange.bound("pending-annot-upload:", "pending-annot-upload:\uffff");
            entries = [];
            req = store.openCursor(key_range);
            req.onsuccess = (function() {
                var ρσ_anonfunc = function (event) {
                    var cursor;
                    cursor = event.target.result;
                    if (cursor) {
                        entries.push(cursor.value);
                        cursor.continue();
                    } else {
                        proceed(entries);
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            req.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    self.display_error(_("Failed to read pending annotation uploads"), event);
                    proceed([]);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!DB.prototype.get_all_pending_annot_uploads.__argnames__) Object.defineProperties(DB.prototype.get_all_pending_annot_uploads, {
            __argnames__ : {value: ["proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.clear_pending_annot_upload = function clear_pending_annot_upload(library_id, book_id, fmt, proceed) {
            var self = this;
            var key;
            key = "pending-annot-upload:" + ρσ_str.format("{}", library_id) + "/" + ρσ_str.format("{}", book_id) + "/" + ρσ_str.format("{}", fmt) + "";
            ρσ_interpolate_kwargs.call(self, self.do_op, [ρσ_list_decorate([ "objects" ]), key, _("Failed to clear pending annotation upload"), proceed || (function() {
                var ρσ_anonfunc = function () {
                    null;
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })()].concat([ρσ_desugar_kwargs({op: "delete"})]));
        };
        if (!DB.prototype.clear_pending_annot_upload.__argnames__) Object.defineProperties(DB.prototype.clear_pending_annot_upload, {
            __argnames__ : {value: ["library_id", "book_id", "fmt", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.get_book = function get_book(library_id, book_id, fmt, metadata, proceed) {
            var self = this;
            var key;
            fmt = fmt.toUpperCase();
            book_id = int(book_id);
            key = [library_id, book_id, fmt];
            self.do_op(ρσ_list_decorate([ "books" ]), key, _("Failed to read from the books database"), (function() {
                var ρσ_anonfunc = function (result) {
                    if (result && !result.annotations_map) {
                        result.annotations_map = Object.create(null);
                    }
                    proceed(result || new_book(key, metadata));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["result"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!DB.prototype.get_book.__argnames__) Object.defineProperties(DB.prototype.get_book, {
            __argnames__ : {value: ["library_id", "book_id", "fmt", "metadata", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.get_mathjax_info = function get_mathjax_info(proceed) {
            var self = this;
            self.do_op(ρσ_list_decorate([ "objects" ]), "mathjax-info", _("Failed to read from the objects database"), (function() {
                var ρσ_anonfunc = function (result) {
                    proceed(result || (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["key"] = "mathjax-info";
                        return ρσ_d;
                    }).call(this));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["result"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!DB.prototype.get_mathjax_info.__argnames__) Object.defineProperties(DB.prototype.get_mathjax_info, {
            __argnames__ : {value: ["proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.save_manifest = function save_manifest(book, manifest, proceed) {
            var self = this;
            var newest_epoch, newest_pos, pos, username, unkey;
            book.manifest = manifest;
            book.metadata = manifest.metadata;
            book.book_hash = manifest.book_hash.hash;
            book.stored_files = Object.create(null);
            book.is_complete = false;
            newest_epoch = newest_pos = null;
            var ρσ_Iter0 = ρσ_Iterable(manifest.last_read_positions);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                pos = ρσ_Iter0[ρσ_Index0];
                if (newest_epoch === null || pos.epoch > newest_epoch) {
                    newest_epoch = pos.epoch;
                    newest_pos = pos.cfi;
                }
            }
            username = get_interface_data().username;
            unkey = username_key(username);
            if (newest_pos && username) {
                (ρσ_expr_temp = book.last_read)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey] = new Date(newest_epoch * 1e3);
                (ρσ_expr_temp = book.last_read_position)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey] = newest_pos;
            }
            if (manifest.annotations_map) {
                (ρσ_expr_temp = book.annotations_map)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey] = manifest.annotations_map;
            }
            delete manifest.metadata;
            delete manifest.last_read_positions;
            delete manifest.annotations_map;
            ρσ_interpolate_kwargs.call(self, self.do_op, [ρσ_list_decorate([ "books" ]), book, _("Failed to write to the books database"), proceed].concat([ρσ_desugar_kwargs({op: "put"})]));
        };
        if (!DB.prototype.save_manifest.__argnames__) Object.defineProperties(DB.prototype.save_manifest, {
            __argnames__ : {value: ["book", "manifest", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.store_file = function store_file(book, name, xhr, proceed, is_cover) {
            var self = this;
            var store_as_text, fname, needs_encoding, mt;
            store_as_text = xhr.responseType === "text" || !xhr.responseType;
            fname = file_store_name(book, name);
            needs_encoding = !store_as_text && !self.supports_blobs;
            mt = ρσ_exists.d((ρσ_expr_temp = book.manifest.files)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]).mimetype;
            if (!mt && is_cover) {
                mt = "image/jpeg";
            }
            (ρσ_expr_temp = book.stored_files)[(typeof fname === "number" && fname < 0) ? ρσ_expr_temp.length + fname : fname] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["encoded"] = needs_encoding;
                ρσ_d["mimetype"] = mt;
                ρσ_d["store_as_text"] = store_as_text;
                return ρσ_d;
            }).call(this);
            if (is_cover) {
                self.store_cover(book, needs_encoding, xhr.response, name, fname, proceed);
            } else {
                self.store_file_stage2(needs_encoding, xhr.response, name, fname, proceed);
            }
        };
        if (!DB.prototype.store_file.__argnames__) Object.defineProperties(DB.prototype.store_file, {
            __argnames__ : {value: ["book", "name", "xhr", "proceed", "is_cover"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.store_cover = function store_cover(book, needs_encoding, data, name, fname, proceed) {
            var self = this;
            var blob, url, img, proceeded;
            blob = data;
            if (needs_encoding) {
                blob = new Blob(ρσ_list_decorate([ data ]), (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "image/jpeg";
                    return ρσ_d;
                }).call(this));
            }
            url = window.URL.createObjectURL(blob);
            img = new Image;
            book.cover_name = name;
            proceeded = false;
            function done() {
                if (!proceeded) {
                    proceeded = true;
                    window.URL.revokeObjectURL(url);
                    self.store_file_stage2(needs_encoding, data, name, fname, proceed);
                }
            };
            if (!done.__module__) Object.defineProperties(done, {
                __module__ : {value: "read_book.db"}
            });

            img.onload = (function() {
                var ρσ_anonfunc = function () {
                    book.cover_width = this.width;
                    book.cover_height = this.height;
                    done();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            img.onerror = (function() {
                var ρσ_anonfunc = function () {
                    print("WARNING: Failed to read dimensions of cover");
                    done();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            img.src = url;
        };
        if (!DB.prototype.store_cover.__argnames__) Object.defineProperties(DB.prototype.store_cover, {
            __argnames__ : {value: ["book", "needs_encoding", "data", "name", "fname", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.store_file_stage2 = function store_file_stage2(needs_encoding, data, name, fname, proceed) {
            var self = this;
            var req;
            if (needs_encoding) {
                data = base64encode(new Uint8Array(data));
            }
            req = self.idb.transaction(ρσ_list_decorate([ "files" ]), "readwrite").objectStore("files").put(data, fname);
            req.onsuccess = (function() {
                var ρσ_anonfunc = function (event) {
                    proceed();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            req.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    proceed(_("Failed to store book data ({0}) with error: {1}").format(name, get_error_details(event)));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!DB.prototype.store_file_stage2.__argnames__) Object.defineProperties(DB.prototype.store_file_stage2, {
            __argnames__ : {value: ["needs_encoding", "data", "name", "fname", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.clear_mathjax = function clear_mathjax(proceed) {
            var self = this;
            self.idb.transaction(ρσ_list_decorate([ "mathjax" ]), "readwrite").objectStore("mathjax").clear().onsuccess = proceed;
        };
        if (!DB.prototype.clear_mathjax.__argnames__) Object.defineProperties(DB.prototype.clear_mathjax, {
            __argnames__ : {value: ["proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.store_mathjax_file = function store_mathjax_file(name, xhr, proceed) {
            var self = this;
            var data, req;
            data = xhr.response;
            if (!self.supports_blobs) {
                data = base64encode(new Uint8Array(data));
            }
            req = self.idb.transaction(ρσ_list_decorate([ "mathjax" ]), "readwrite").objectStore("mathjax").put(data, name);
            req.onsuccess = (function() {
                var ρσ_anonfunc = function (event) {
                    proceed();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            req.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    proceed(_("Failed to store mathjax file ({0}) with error: {1}").format(name, get_error_details(event)));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!DB.prototype.store_mathjax_file.__argnames__) Object.defineProperties(DB.prototype.store_mathjax_file, {
            __argnames__ : {value: ["name", "xhr", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.finish_book = function finish_book(book, proceed) {
            var self = this;
            book.is_complete = true;
            ρσ_interpolate_kwargs.call(self, self.do_op, [ρσ_list_decorate([ "books" ]), book, _("Failed to write to the books database"), proceed].concat([ρσ_desugar_kwargs({op: "put"})]));
        };
        if (!DB.prototype.finish_book.__argnames__) Object.defineProperties(DB.prototype.finish_book, {
            __argnames__ : {value: ["book", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.finish_mathjax = function finish_mathjax(mathjax_info, proceed) {
            var self = this;
            ρσ_interpolate_kwargs.call(self, self.do_op, [ρσ_list_decorate([ "objects" ]), mathjax_info, _("Failed to write to the objects database"), proceed].concat([ρσ_desugar_kwargs({op: "put"})]));
        };
        if (!DB.prototype.finish_mathjax.__argnames__) Object.defineProperties(DB.prototype.finish_mathjax, {
            __argnames__ : {value: ["mathjax_info", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.update_last_read_time = function update_last_read_time(book) {
            var self = this;
            var unkey, now;
            unkey = username_key(get_interface_data().username);
            now = new Date;
            (ρσ_expr_temp = book.last_read)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey] = book.recent_date = now;
            ρσ_interpolate_kwargs.call(self, self.do_op, [ρσ_list_decorate([ "books" ]), book, _("Failed to write to the books database")].concat([ρσ_desugar_kwargs({op: "put"})]));
        };
        if (!DB.prototype.update_last_read_time.__argnames__) Object.defineProperties(DB.prototype.update_last_read_time, {
            __argnames__ : {value: ["book"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.update_metadata = function update_metadata(book, new_metadata) {
            var self = this;
            var key;
            if (book.metadata) {
                var ρσ_Iter1 = ρσ_Iterable(Object.keys(new_metadata));
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    key = ρσ_Iter1[ρσ_Index1];
                    (ρσ_expr_temp = book.metadata)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = new_metadata[(typeof key === "number" && key < 0) ? new_metadata.length + key : key];
                }
                ρσ_interpolate_kwargs.call(self, self.do_op, [ρσ_list_decorate([ "books" ]), book, _("Failed to write to the books database"), (function() {
                    var ρσ_anonfunc = function () {
                        null;
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.db"}
                    });
                    return ρσ_anonfunc;
                })()].concat([ρσ_desugar_kwargs({op: "put"})]));
            }
        };
        if (!DB.prototype.update_metadata.__argnames__) Object.defineProperties(DB.prototype.update_metadata, {
            __argnames__ : {value: ["book", "new_metadata"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.save_reading_rates = function save_reading_rates(book, rates) {
            var self = this;
            book.saved_reading_rates = rates;
            ρσ_interpolate_kwargs.call(self, self.do_op, [ρσ_list_decorate([ "books" ]), book, _("Failed to write to the books database"), (function() {
                var ρσ_anonfunc = function () {
                    null;
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })()].concat([ρσ_desugar_kwargs({op: "put"})]));
        };
        if (!DB.prototype.save_reading_rates.__argnames__) Object.defineProperties(DB.prototype.save_reading_rates, {
            __argnames__ : {value: ["book", "rates"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.update_annotations_data_from_key = function update_annotations_data_from_key(library_id, book_id, fmt, new_data) {
            var self = this;
            var unkey;
            unkey = username_key(get_interface_data().username);
            self.get_book(library_id, book_id, fmt, null, (function() {
                var ρσ_anonfunc = function (book) {
                    var changed, existing, ρσ_unpack, updated, merged;
                    if (book.metadata) {
                        changed = false;
                        if (new_data.last_read_position) {
                            (ρσ_expr_temp = book.last_read)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey] = book.recent_date = new_data.last_read;
                            (ρσ_expr_temp = book.last_read_position)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey] = new_data.last_read_position;
                            changed = true;
                        }
                        if (!book.annotations_map) {
                            book.annotations_map = {};
                        }
                        if (new_data.annotations_map) {
                            existing = (ρσ_expr_temp = book.annotations_map)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey];
                            if (!existing) {
                                changed = true;
                                (ρσ_expr_temp = book.annotations_map)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey] = new_data.annotations_map;
                            } else {
                                ρσ_unpack = merge_annotation_maps(existing, new_data.annotations_map);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                                updated = ρσ_unpack[0];
                                merged = ρσ_unpack[1];
                                if (updated) {
                                    changed = true;
                                    (ρσ_expr_temp = book.annotations_map)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey] = merged;
                                }
                            }
                        }
                        if (changed) {
                            ρσ_interpolate_kwargs.call(self, self.do_op, [ρσ_list_decorate([ "books" ]), book, _("Failed to write to the books database"), (function() {
                                var ρσ_anonfunc = function () {
                                    null;
                                };
                                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                    __module__ : {value: "read_book.db"}
                                });
                                return ρσ_anonfunc;
                            })()].concat([ρσ_desugar_kwargs({op: "put"})]));
                        }
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["book"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!DB.prototype.update_annotations_data_from_key.__argnames__) Object.defineProperties(DB.prototype.update_annotations_data_from_key, {
            __argnames__ : {value: ["library_id", "book_id", "fmt", "new_data"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.get_file = function get_file(book, name, proceed) {
            var self = this;
            var key, err;
            key = file_store_name(book, name);
            err = _("Failed to read the file {0} for the book {1} from the browser offline cache.").format(name, book.metadata.title);
            self.do_op(ρσ_list_decorate([ "files" ]), key, err, (function() {
                var ρσ_anonfunc = function (result) {
                    var bad, fdata, mt;
                    if (!result) {
                        bad = err + _(" This usually means the cache is close to full. Clear the browser cache from the browser settings.");
                        self.show_error(_("Cannot read file from book"), bad);
                        return;
                    }
                    fdata = (ρσ_expr_temp = book.stored_files)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
                    mt = fdata.mimetype || "application/octet-stream";
                    if (fdata.encoded) {
                        result = new Blob(ρσ_list_decorate([ base64decode(result) ]), (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["type"] = mt;
                            return ρσ_d;
                        }).call(this));
                    }
                    proceed(result, name, mt, book);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["result"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!DB.prototype.get_file.__argnames__) Object.defineProperties(DB.prototype.get_file, {
            __argnames__ : {value: ["book", "name", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.get_book_file = function get_book_file(book_hash, stored_files, name, proceed) {
            var self = this;
            var stores, key, transaction, req;
            stores = ρσ_list_decorate([ "files" ]);
            key = file_store_name((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["book_hash"] = book_hash;
                return ρσ_d;
            }).call(this), name);
            transaction = self.idb.transaction(stores);
            req = transaction.objectStore(stores[0]).get(key);
            req.onsuccess = (function() {
                var ρσ_anonfunc = function (event) {
                    var fdata, mt, result;
                    if (!req.result) {
                        proceed((function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["ok"] = false;
                            ρσ_d["name"] = name;
                            ρσ_d["details"] = "ENOENT";
                            return ρσ_d;
                        }).call(this));
                        return;
                    }
                    fdata = stored_files[(typeof key === "number" && key < 0) ? stored_files.length + key : key];
                    mt = fdata.mimetype || "application/octet-stream";
                    if (fdata.encoded) {
                        result = new Blob(ρσ_list_decorate([ base64decode(result) ]), (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["type"] = mt;
                            return ρσ_d;
                        }).call(this));
                    }
                    proceed((function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["ok"] = true;
                        ρσ_d["result"] = req.result;
                        ρσ_d["name"] = name;
                        ρσ_d["mt"] = mt;
                        return ρσ_d;
                    }).call(this));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            req.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    var details;
                    details = get_error_details(event);
                    proceed((function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["ok"] = false;
                        ρσ_d["name"] = name;
                        ρσ_d["details"] = details;
                        return ρσ_d;
                    }).call(this));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!DB.prototype.get_book_file.__argnames__) Object.defineProperties(DB.prototype.get_book_file, {
            __argnames__ : {value: ["book_hash", "stored_files", "name", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.get_mathjax_files = function get_mathjax_files(proceed) {
            var self = this;
            var c, data;
            c = self.idb.transaction("mathjax").objectStore("mathjax").openCursor();
            c.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    var err;
                    err = _("Failed to read the MathJax files from the browser offline cache.");
                    self.display_error(err, event);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            data = Object.create(null);
            c.onsuccess = (function() {
                var ρσ_anonfunc = function (event) {
                    var cursor, ρσ_unpack, name, result, mt;
                    cursor = event.target.result;
                    if (cursor) {
                        ρσ_unpack = [cursor.key, cursor.value];
                        name = ρσ_unpack[0];
                        result = ρσ_unpack[1];
                        if (!(ρσ_instanceof(result, Blob))) {
                            mt = (name.endswith(".woff")) ? "application/x-font-woff" : "text/javascript";
                            result = new Blob(ρσ_list_decorate([ base64decode(result) ]), (function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["type"] = mt;
                                return ρσ_d;
                            }).call(this));
                        }
                        data[(typeof name === "number" && name < 0) ? data.length + name : name] = result;
                        cursor.continue();
                    } else {
                        proceed(data);
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!DB.prototype.get_mathjax_files.__argnames__) Object.defineProperties(DB.prototype.get_mathjax_files, {
            __argnames__ : {value: ["proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.get_books_by_recent_date = function get_books_by_recent_date() {
            var self = this;
            var proceed = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var limit = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? get_books_by_recent_date.__defaults__.limit : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "limit")){
                limit = ρσ_kwargs_obj.limit;
            }
            var c, books;
            c = self.idb.transaction(ρσ_list_decorate([ "books" ]), "readonly").objectStore("books").index("recent_index").openCursor(null, "prev");
            books = [];
            c.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    var err;
                    err = _("Failed to read recent books from local storage");
                    self.display_error(err, event);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            c.onsuccess = (function() {
                var ρσ_anonfunc = function (ev) {
                    var cursor;
                    cursor = ev.target.result;
                    if (cursor) {
                        books.push(cursor.value);
                    }
                    if (limit !== null && books.length >= limit || !cursor) {
                        proceed(books);
                        return;
                    }
                    if (cursor) {
                        cursor.continue();
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!DB.prototype.get_books_by_recent_date.__defaults__) Object.defineProperties(DB.prototype.get_books_by_recent_date, {
            __defaults__ : {value: {limit:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["proceed", "limit"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.get_recently_read_books = function get_recently_read_books(proceed, limit) {
            var self = this;
            self.get_books_by_recent_date(proceed, limit || 3);
        };
        if (!DB.prototype.get_recently_read_books.__argnames__) Object.defineProperties(DB.prototype.get_recently_read_books, {
            __argnames__ : {value: ["proceed", "limit"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.get_downloaded_books = function get_downloaded_books(proceed) {
            var self = this;
            self.get_books_by_recent_date(proceed);
        };
        if (!DB.prototype.get_downloaded_books.__argnames__) Object.defineProperties(DB.prototype.get_downloaded_books, {
            __argnames__ : {value: ["proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.has_book_matching = function has_book_matching(library_id, book_id, proceed) {
            var self = this;
            var c;
            c = self.idb.transaction(ρσ_list_decorate([ "books" ]), "readonly").objectStore("books").index("recent_index").openCursor(null, "prev");
            c.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    proceed(false);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            book_id = int(book_id);
            c.onsuccess = (function() {
                var ρσ_anonfunc = function (ev) {
                    var cursor, book;
                    cursor = ev.target.result;
                    if (cursor) {
                        book = cursor.value;
                        if (book.key[0] === library_id && book.key[1] === book_id) {
                            proceed(true);
                            return;
                        }
                        cursor.continue();
                    } else {
                        proceed(false);
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!DB.prototype.has_book_matching.__argnames__) Object.defineProperties(DB.prototype.has_book_matching, {
            __argnames__ : {value: ["library_id", "book_id", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.delete_book = function delete_book(book, proceed) {
            var self = this;
            var c, files, books, filenames;
            c = self.idb.transaction(ρσ_list_decorate([ "books", "files" ]), "readwrite");
            files = c.objectStore("files");
            books = c.objectStore("books");
            filenames = Object.keys(book.stored_files);
            c.oncomplete = (function() {
                var ρσ_anonfunc = function (event) {
                    proceed(book);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            c.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                    proceed(book, c.error.toString());
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            function next_step() {
                var r;
                if (filenames.length) {
                    r = files.delete(filenames.pop());
                    r.onsuccess = next_step;
                } else {
                    books.delete(book.key);
                }
            };
            if (!next_step.__module__) Object.defineProperties(next_step, {
                __module__ : {value: "read_book.db"}
            });

            next_step();
        };
        if (!DB.prototype.delete_book.__argnames__) Object.defineProperties(DB.prototype.delete_book, {
            __argnames__ : {value: ["book", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.delete_books_matching = function delete_books_matching(library_id, book_id, proceed) {
            var self = this;
            var c, matches;
            c = self.idb.transaction(ρσ_list_decorate([ "books" ]), "readonly").objectStore("books").index("recent_index").openCursor(null, "prev");
            c.onerror = (function() {
                var ρσ_anonfunc = function (event) {
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
            book_id = int(book_id);
            matches = [];
            function delete_all() {
                var book;
                if (matches.length) {
                    book = matches.pop();
                    self.delete_book(book, delete_all);
                } else {
                    if (proceed) {
                        proceed();
                    }
                }
            };
            if (!delete_all.__module__) Object.defineProperties(delete_all, {
                __module__ : {value: "read_book.db"}
            });

            c.onsuccess = (function() {
                var ρσ_anonfunc = function (ev) {
                    var cursor, book;
                    cursor = ev.target.result;
                    if (cursor) {
                        book = cursor.value;
                        if (book.key[0] === library_id && book.key[1] === book_id) {
                            matches.push(book);
                        }
                        cursor.continue();
                    } else {
                        delete_all();
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.db"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!DB.prototype.delete_books_matching.__argnames__) Object.defineProperties(DB.prototype.delete_books_matching, {
            __argnames__ : {value: ["library_id", "book_id", "proceed"]},
            __module__ : {value: "read_book.db"}
        });
        DB.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        DB.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(DB.prototype, "__bases__", {value: []});

        function get_db(callback, show_read_book_error) {
            if (!get_db.ans) {
                get_db.ans = new DB(callback, show_read_book_error);
            }
            return get_db.ans;
        };
        if (!get_db.__argnames__) Object.defineProperties(get_db, {
            __argnames__ : {value: ["callback", "show_read_book_error"]},
            __module__ : {value: "read_book.db"}
        });

        ρσ_modules["read_book.db"].DB_NAME = DB_NAME;
        ρσ_modules["read_book.db"].DB_VERSION = DB_VERSION;
        ρσ_modules["read_book.db"].upgrade_schema = upgrade_schema;
        ρσ_modules["read_book.db"].file_store_name = file_store_name;
        ρσ_modules["read_book.db"].get_error_details = get_error_details;
        ρσ_modules["read_book.db"].new_book = new_book;
        ρσ_modules["read_book.db"].indexed_db_api = indexed_db_api;
        ρσ_modules["read_book.db"].DB = DB;
        ρσ_modules["read_book.db"].get_db = get_db;
    })();

    (function(){
        var __name__ = "iframe_comm";
        var LOADING_DOC, instance_numbers;
        var GCM = ρσ_modules.aes.GCM;

        var E = ρσ_modules.elementmaker.E;

        var traceback = ρσ_modules.traceback;

        var get_translations = ρσ_modules["book_list.globals"].get_translations;
        var main_js = ρσ_modules["book_list.globals"].main_js;

        var get_font_family = ρσ_modules["book_list.theme"].get_font_family;

        var ensure_id = ρσ_modules.dom.ensure_id;

        var install = ρσ_modules.gettext.install;

        LOADING_DOC = "\n<!DOCTYPE html>\n<html>\n<head>\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n<script type=\"text/javascript\" id=\"bootstrap\">\nwindow.iframe_entry_point = '__ENTRY_POINT__';  // different in different iframes\nwindow.default_font_family = '__FONT__';  // from the theme\n__SCRIPT__\nend_script\n</head>\n<body>\n<div style=\"font-size:larger; font-weight: bold; margin-top:48vh; text-align:center\">\n__BS__\n</div>\n</body>\n</html>\n".replace("end_script", "<" + "/script>");
        function Messenger() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            Messenger.prototype.__bind_methods__.call(this);
            Messenger.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(Messenger.prototype, "__bind_methods__", {value: function () {
            this.reset = Messenger.prototype.reset.bind(this);
            this.encrypt = Messenger.prototype.encrypt.bind(this);
            this.decrypt = Messenger.prototype.decrypt.bind(this);
        }});
        Messenger.prototype.__init__ = function __init__() {
            var self = this;
            self.secret = new Uint8Array(64);
        };
        if (!Messenger.prototype.__init__.__module__) Object.defineProperties(Messenger.prototype.__init__, {
            __module__ : {value: "iframe_comm"}
        });
        Messenger.__argnames__ = Messenger.prototype.__init__.__argnames__;
        Messenger.__handles_kwarg_interpolation__ = Messenger.prototype.__init__.__handles_kwarg_interpolation__;
        Messenger.prototype.reset = function reset() {
            var self = this;
            window.crypto.getRandomValues(self.secret);
            self.gcm_to_iframe = new GCM(self.secret.subarray(0, 32));
            self.gcm_from_iframe = new GCM(self.secret.subarray(32));
        };
        if (!Messenger.prototype.reset.__module__) Object.defineProperties(Messenger.prototype.reset, {
            __module__ : {value: "iframe_comm"}
        });
        Messenger.prototype.encrypt = function encrypt(data) {
            var self = this;
            return self.gcm_to_iframe.encrypt(JSON.stringify(data));
        };
        if (!Messenger.prototype.encrypt.__argnames__) Object.defineProperties(Messenger.prototype.encrypt, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "iframe_comm"}
        });
        Messenger.prototype.decrypt = function decrypt(data) {
            var self = this;
            return JSON.parse(self.gcm_from_iframe.decrypt(data));
        };
        if (!Messenger.prototype.decrypt.__argnames__) Object.defineProperties(Messenger.prototype.decrypt, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "iframe_comm"}
        });
        Messenger.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        Messenger.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(Messenger.prototype, "__bases__", {value: []});

        function IframeWrapper() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            IframeWrapper.prototype.__bind_methods__.call(this);
            IframeWrapper.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(IframeWrapper.prototype, "__bind_methods__", {value: function () {
            this.destroy = IframeWrapper.prototype.destroy.bind(this);
            this.create_srcdoc = IframeWrapper.prototype.create_srcdoc.bind(this);
            this.init = IframeWrapper.prototype.init.bind(this);
            this.reset = IframeWrapper.prototype.reset.bind(this);
            this._send_message = IframeWrapper.prototype._send_message.bind(this);
            this.send_message = IframeWrapper.prototype.send_message.bind(this);
            this.send_unencrypted_message = IframeWrapper.prototype.send_unencrypted_message.bind(this);
            this.handle_message = IframeWrapper.prototype.handle_message.bind(this);
            this.on_iframe_ready = IframeWrapper.prototype.on_iframe_ready.bind(this);
        }});
        Object.defineProperties(IframeWrapper.prototype,  {
            "iframe": {
                "enumerable": true, 
                "get": function iframe() {
                    var self = this;
                    return document.getElementById(self.iframe_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        IframeWrapper.prototype.__init__ = function __init__(handlers, iframe, entry_point, bootstrap_text) {
            var self = this;
            var k;
            self.messenger = new Messenger;
            self.iframe_id = ensure_id(iframe, "content-iframe");
            self.reload_count = 0;
            if (ρσ_in(":", entry_point)) {
                self.needs_init = iframe.src !== entry_point;
                self.srcdoc_created = true;
                self.constructor_url = entry_point;
                self.entry_point = null;
            } else {
                self.needs_init = true;
                self.srcdoc_created = false;
                self.constructor_url = null;
                self.entry_point = entry_point;
            }
            self.ready = false;
            self.encrypted_communications = false;
            self.bootstrap_text = bootstrap_text || "";
            self.handlers = (function() {
                var ρσ_Iter = ρσ_Iterable(handlers), ρσ_Result = Object.create(null), k;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    k = ρσ_Iter[ρσ_Index];
                    ρσ_Result[k] = (handlers[(typeof k === "number" && k < 0) ? handlers.length + k : k]);
                }
                return ρσ_Result;
            })();
            self.on_ready_handler = self.handlers.ready;
            self.handlers.ready = self.on_iframe_ready;
            window.addEventListener("message", self.handle_message, false);
        };
        if (!IframeWrapper.prototype.__init__.__argnames__) Object.defineProperties(IframeWrapper.prototype.__init__, {
            __argnames__ : {value: ["handlers", "iframe", "entry_point", "bootstrap_text"]},
            __module__ : {value: "iframe_comm"}
        });
        IframeWrapper.__argnames__ = IframeWrapper.prototype.__init__.__argnames__;
        IframeWrapper.__handles_kwarg_interpolation__ = IframeWrapper.prototype.__init__.__handles_kwarg_interpolation__;
        IframeWrapper.prototype.destroy = function destroy() {
            var self = this;
            window.removeEventListener("message", self.handle_message, false);
        };
        if (!IframeWrapper.prototype.destroy.__module__) Object.defineProperties(IframeWrapper.prototype.destroy, {
            __module__ : {value: "iframe_comm"}
        });
        IframeWrapper.prototype.create_srcdoc = function create_srcdoc() {
            var self = this;
            var r, data;
            r = /__([A-Z][A-Z_0-9]*[A-Z0-9])__/g;
            if (self.entry_point) {
                data = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["BS"] = self.bootstrap_text;
                    ρσ_d["SCRIPT"] = main_js();
                    ρσ_d["FONT"] = get_font_family();
                    ρσ_d["ENTRY_POINT"] = self.entry_point;
                    return ρσ_d;
                }).call(this);
                self.iframe.srcdoc = LOADING_DOC.replace(r, (function() {
                    var ρσ_anonfunc = function (match, field) {
                        return data[(typeof field === "number" && field < 0) ? data.length + field : field];
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["match", "field"]},
                        __module__ : {value: "iframe_comm"}
                    });
                    return ρσ_anonfunc;
                })());
            } else {
                self.iframe.src = self.constructor_url;
            }
            self.srcdoc_created = true;
        };
        if (!IframeWrapper.prototype.create_srcdoc.__module__) Object.defineProperties(IframeWrapper.prototype.create_srcdoc, {
            __module__ : {value: "iframe_comm"}
        });
        IframeWrapper.prototype.init = function init() {
            var self = this;
            var iframe, sdoc, ch;
            if (!self.needs_init) {
                return;
            }
            self.needs_init = false;
            iframe = self.iframe;
            if (self.srcdoc_created) {
                if (self.entry_point) {
                    sdoc = iframe.srcdoc;
                    iframe.srcdoc = "<p>&nbsp;</p>";
                    iframe.srcdoc = sdoc;
                } else {
                    self.reload_count += 1;
                    ch = (ρσ_in("?", self.constructor_url)) ? "&" : "?";
                    iframe.src = self.constructor_url + ("" + ρσ_str.format("{}", ch) + "rc=" + ρσ_str.format("{}", self.reload_count) + "");
                }
            } else {
                self.create_srcdoc();
            }
        };
        if (!IframeWrapper.prototype.init.__module__) Object.defineProperties(IframeWrapper.prototype.init, {
            __module__ : {value: "iframe_comm"}
        });
        IframeWrapper.prototype.reset = function reset() {
            var self = this;
            self.ready = false;
            self.needs_init = true;
            self.encrypted_communications = false;
        };
        if (!IframeWrapper.prototype.reset.__module__) Object.defineProperties(IframeWrapper.prototype.reset, {
            __module__ : {value: "iframe_comm"}
        });
        IframeWrapper.prototype._send_message = function _send_message(action, encrypted, data) {
            var self = this;
            var msg;
            if (!self.ready) {
                return;
            }
            data.action = action;
            msg = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["data"] = data;
                ρσ_d["encrypted"] = encrypted;
                return ρσ_d;
            }).call(this);
            if (encrypted) {
                msg.data = self.messenger.encrypt(data);
            }
            self.iframe.contentWindow.postMessage(msg, "*");
        };
        if (!IframeWrapper.prototype._send_message.__argnames__) Object.defineProperties(IframeWrapper.prototype._send_message, {
            __argnames__ : {value: ["action", "encrypted", "data"]},
            __module__ : {value: "iframe_comm"}
        });
        IframeWrapper.prototype.send_message = function send_message() {
            var self = this;
            var action = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var data = arguments[arguments.length-1];
            if (data === null || typeof data !== "object" || data [ρσ_kwargs_symbol] !== true) data = {};
            self._send_message(action, self.encrypted_communications, data);
        };
        if (!IframeWrapper.prototype.send_message.__handles_kwarg_interpolation__) Object.defineProperties(IframeWrapper.prototype.send_message, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["action"]},
            __module__ : {value: "iframe_comm"}
        });
        IframeWrapper.prototype.send_unencrypted_message = function send_unencrypted_message() {
            var self = this;
            var action = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var data = arguments[arguments.length-1];
            if (data === null || typeof data !== "object" || data [ρσ_kwargs_symbol] !== true) data = {};
            self._send_message(action, false, data);
        };
        if (!IframeWrapper.prototype.send_unencrypted_message.__handles_kwarg_interpolation__) Object.defineProperties(IframeWrapper.prototype.send_unencrypted_message, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["action"]},
            __module__ : {value: "iframe_comm"}
        });
        IframeWrapper.prototype.handle_message = function handle_message(event) {
            var self = this;
            var data, func;
            if (event.source !== ρσ_exists.d(self.iframe).contentWindow) {
                return;
            }
            data = event.data;
            if (self.encrypted_communications) {
                if (data.tag === undefined) {
                    print("Ignoring unencrypted message from iframe:", data);
                    return;
                }
                try {
                    data = self.messenger.decrypt(data);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        var e = ρσ_Exception;
                        print("Could not decrypt message from iframe:");
                        console.log(e);
                        traceback.print_exc();
                        return;
                    } else {
                        throw ρσ_Exception;
                    }
                }
            }
            if (!data.action) {
                return;
            }
            func = (ρσ_expr_temp = self.handlers)[ρσ_bound_index(data.action, ρσ_expr_temp)];
            if (func) {
                func(data);
            } else {
                print("Unknown action in message from iframe to parent:", data.action);
            }
        };
        if (!IframeWrapper.prototype.handle_message.__argnames__) Object.defineProperties(IframeWrapper.prototype.handle_message, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "iframe_comm"}
        });
        IframeWrapper.prototype.on_iframe_ready = function on_iframe_ready(data) {
            var self = this;
            var msg, callback;
            self.messenger.reset();
            msg = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["secret"] = self.messenger.secret;
                ρσ_d["translations"] = get_translations();
                return ρσ_d;
            }).call(this);
            self.ready = true;
            callback = null;
            if (self.on_ready_handler) {
                callback = self.on_ready_handler(msg);
            }
            self._send_message("initialize", false, msg);
            self.encrypted_communications = true;
            if (callback) {
                callback();
            }
        };
        if (!IframeWrapper.prototype.on_iframe_ready.__argnames__) Object.defineProperties(IframeWrapper.prototype.on_iframe_ready, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "iframe_comm"}
        });
        IframeWrapper.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        IframeWrapper.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(IframeWrapper.prototype, "__bases__", {value: []});
        

        function create_wrapped_iframe(handlers, bootstrap_text, entry_point, kw) {
            var iframe, ans;
            if (ρσ_in(":", entry_point)) {
                kw.src = entry_point;
                kw.sandbox = (kw.sandbox || "") + " allow-same-origin";
            }
            iframe = ρσ_interpolate_kwargs.call(E, E.iframe, [ρσ_desugar_kwargs(kw)]);
            ans = new IframeWrapper(handlers, iframe, entry_point, bootstrap_text);
            return [iframe, ans];
        };
        if (!create_wrapped_iframe.__argnames__) Object.defineProperties(create_wrapped_iframe, {
            __argnames__ : {value: ["handlers", "bootstrap_text", "entry_point", "kw"]},
            __module__ : {value: "iframe_comm"}
        });

        instance_numbers = Object.create(null);
        function IframeClient() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            IframeClient.prototype.__bind_methods__.call(this);
            IframeClient.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(IframeClient.prototype, "__bind_methods__", {value: function () {
            this.send_ready = IframeClient.prototype.send_ready.bind(this);
            this.initialize = IframeClient.prototype.initialize.bind(this);
            this.print_to_parent = IframeClient.prototype.print_to_parent.bind(this);
            this.handle_message = IframeClient.prototype.handle_message.bind(this);
            this.send_message = IframeClient.prototype.send_message.bind(this);
        }});
        IframeClient.prototype.__init__ = function __init__(handlers, name) {
            var self = this;
            var k;
            self.encrypted_communications = false;
            self.name = name;
            if (!instance_numbers[ρσ_bound_index(self.name, instance_numbers)]) {
                instance_numbers[ρσ_bound_index(self.name, instance_numbers)] = 0;
            }
            instance_numbers[ρσ_bound_index(self.name, instance_numbers)] += 1;
            self.instance_num = instance_numbers[ρσ_bound_index(self.name, instance_numbers)];
            self.handlers = (function() {
                var ρσ_Iter = ρσ_Iterable(handlers), ρσ_Result = Object.create(null), k;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    k = ρσ_Iter[ρσ_Index];
                    ρσ_Result[k] = (handlers[(typeof k === "number" && k < 0) ? handlers.length + k : k]);
                }
                return ρσ_Result;
            })();
            self.initialize_handler = handlers.initialize;
            self.handlers.initialize = self.initialize;
            self.ready_sent = false;
            window.addEventListener("message", self.handle_message, false);
            window.addEventListener("load", self.send_ready, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["once"] = true;
                return ρσ_d;
            }).call(this));
        };
        if (!IframeClient.prototype.__init__.__argnames__) Object.defineProperties(IframeClient.prototype.__init__, {
            __argnames__ : {value: ["handlers", "name"]},
            __module__ : {value: "iframe_comm"}
        });
        IframeClient.__argnames__ = IframeClient.prototype.__init__.__argnames__;
        IframeClient.__handles_kwarg_interpolation__ = IframeClient.prototype.__init__.__handles_kwarg_interpolation__;
        IframeClient.prototype.send_ready = function send_ready() {
            var self = this;
            if (!self.ready_sent) {
                self.send_message("ready", Object.create(null));
                self.ready_sent = true;
            }
        };
        if (!IframeClient.prototype.send_ready.__module__) Object.defineProperties(IframeClient.prototype.send_ready, {
            __module__ : {value: "iframe_comm"}
        });
        IframeClient.prototype.initialize = function initialize(data) {
            var self = this;
            var ρσ_unpack;
            ρσ_unpack = [new GCM(data.secret.subarray(0, 32)), new GCM(data.secret.subarray(32))];
            self.gcm_from_parent = ρσ_unpack[0];
            self.gcm_to_parent = ρσ_unpack[1];
            self.encrypted_communications = true;
            if (data.translations) {
                install(data.translations);
            }
            print = self.print_to_parent;
            if (self.initialize_handler) {
                self.initialize_handler(data);
            }
        };
        if (!IframeClient.prototype.initialize.__argnames__) Object.defineProperties(IframeClient.prototype.initialize, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "iframe_comm"}
        });
        IframeClient.prototype.print_to_parent = function print_to_parent() {
            var self = this;
            var args = Array.prototype.slice.call(arguments, 0);
            if (arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) args.pop();
            ρσ_interpolate_kwargs.call(self, self.send_message, ["print"].concat([ρσ_desugar_kwargs({string: " ".join(map(str, args))})]));
        };
        if (!IframeClient.prototype.print_to_parent.__handles_kwarg_interpolation__) Object.defineProperties(IframeClient.prototype.print_to_parent, {
            __handles_kwarg_interpolation__ : {value: true},
            __module__ : {value: "iframe_comm"}
        });
        IframeClient.prototype.handle_message = function handle_message(event) {
            var self = this;
            var msg, data, func, details;
            if (event.source !== window.parent) {
                return;
            }
            msg = event.data;
            data = msg.data;
            if (msg.encrypted) {
                if (!self.gcm_from_parent) {
                    print("the iframe " + ρσ_str.format("{}", self.name) + "-" + ρσ_str.format("{}", self.instance_num) + " got an encrypted message from its parent without being initialized");
                    return;
                }
                try {
                    data = JSON.parse(self.gcm_from_parent.decrypt(data));
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        var e = ρσ_Exception;
                        print("Could not process message from parent:");
                        console.log(e);
                        return;
                    } else {
                        throw ρσ_Exception;
                    }
                }
            }
            if (!data || !data.action) {
                console.log("Got a null message from parent in iframe, ignoring");
                return;
            }
            func = (ρσ_expr_temp = self.handlers)[ρσ_bound_index(data.action, ρσ_expr_temp)];
            if (func) {
                try {
                    func(data);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        var e = ρσ_Exception;
                        console.log("Error in iframe message handler {}:".format((typeof data !== "undefined" && data !== null ? data : Object.create(null)).action));
                        console.log(e);
                        details = traceback.format_exc();
                        console.log(details);
                        ρσ_interpolate_kwargs.call(self, self.send_message, ["error"].concat([ρσ_desugar_kwargs({title: "Error in message handler", details: details, msg: e.toString()})]));
                    } else {
                        throw ρσ_Exception;
                    }
                }
            } else {
                print("Unknown action in message to iframe from parent: " + data.action);
            }
        };
        if (!IframeClient.prototype.handle_message.__argnames__) Object.defineProperties(IframeClient.prototype.handle_message, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "iframe_comm"}
        });
        IframeClient.prototype.send_message = function send_message(action, data) {
            var self = this;
            data.action = action;
            data.iframe_id = "" + ρσ_str.format("{}", self.name) + "-" + ρσ_str.format("{}", self.instance_num) + "";
            if (self.encrypted_communications) {
                data = self.gcm_to_parent.encrypt(JSON.stringify(data));
            }
            window.parent.postMessage(data, "*");
        };
        if (!IframeClient.prototype.send_message.__argnames__) Object.defineProperties(IframeClient.prototype.send_message, {
            __argnames__ : {value: ["action", "data"]},
            __module__ : {value: "iframe_comm"}
        });
        IframeClient.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        IframeClient.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(IframeClient.prototype, "__bases__", {value: []});

        ρσ_modules.iframe_comm.LOADING_DOC = LOADING_DOC;
        ρσ_modules.iframe_comm.instance_numbers = instance_numbers;
        ρσ_modules.iframe_comm.Messenger = Messenger;
        ρσ_modules.iframe_comm.IframeWrapper = IframeWrapper;
        ρσ_modules.iframe_comm.create_wrapped_iframe = create_wrapped_iframe;
        ρσ_modules.iframe_comm.IframeClient = IframeClient;
    })();

    (function(){
        var __name__ = "read_book.settings";
        var opts, styles_id;
        var E = ρσ_modules.elementmaker.E;

        var dark_link_color = ρσ_modules["read_book.globals"].dark_link_color;
        var runtime = ρσ_modules["read_book.globals"].runtime;

        var session_defaults = ρσ_modules.session.session_defaults;

        opts = Object.create(null);
        function update_settings(settings) {
            settings = Object.assign(Object.create(null), session_defaults(), settings);
            opts.base_font_size = max(8, min(settings.base_font_size, 64));
            opts.color_scheme = settings.color_scheme;
            opts.columns_per_screen = settings.columns_per_screen;
            opts.cover_preserve_aspect_ratio = !!settings.cover_preserve_aspect_ratio;
            opts.hide_tooltips = settings.hide_tooltips;
            opts.is_dark_theme = !!settings.is_dark_theme;
            opts.lines_per_sec_auto = settings.lines_per_sec_auto;
            opts.lines_per_sec_smooth = settings.lines_per_sec_smooth;
            opts.margin_left = max(0, settings.margin_left);
            opts.margin_right = max(0, settings.margin_right);
            opts.margin_top = max(0, settings.margin_top);
            opts.margin_bottom = max(0, settings.margin_bottom);
            opts.override_book_colors = settings.override_book_colors;
            opts.paged_wheel_scrolls_by_screen = !!settings.paged_wheel_scrolls_by_screen;
            opts.paged_wheel_section_jumps = !!settings.paged_wheel_section_jumps;
            opts.paged_pixel_scroll_threshold = settings.paged_pixel_scroll_threshold;
            opts.scroll_auto_boundary_delay = settings.scroll_auto_boundary_delay;
            opts.scroll_mouse_boundary_delay = settings.scroll_mouse_boundary_delay;
            opts.scroll_stop_boundaries = !!settings.scroll_stop_boundaries;
            opts.reverse_page_turn_zones = !!settings.reverse_page_turn_zones;
            opts.user_stylesheet = settings.user_stylesheet;
            opts.gesture_overrides = settings.gesture_overrides;
        };
        if (!update_settings.__argnames__) Object.defineProperties(update_settings, {
            __argnames__ : {value: ["settings"]},
            __module__ : {value: "read_book.settings"}
        });

        update_settings();
        function apply_font_size() {
            if (!runtime.is_standalone_viewer) {
                document.documentElement.style.fontSize = "{}px".format(opts.base_font_size);
            }
        };
        if (!apply_font_size.__module__) Object.defineProperties(apply_font_size, {
            __module__ : {value: "read_book.settings"}
        });

        function default_selection_colors() {
            if (opts.is_dark_theme) {
                return [dark_link_color, "#111"];
            }
            return ["#3297FD", "#fff"];
        };
        if (!default_selection_colors.__module__) Object.defineProperties(default_selection_colors, {
            __module__ : {value: "read_book.settings"}
        });

        function make_selection_background_opaque(selbg) {
            if (selbg && selbg.startsWith("#") && len(selbg) === 7) {
                selbg += "fe";
            }
            return selbg;
        };
        if (!make_selection_background_opaque.__argnames__) Object.defineProperties(make_selection_background_opaque, {
            __argnames__ : {value: ["selbg"]},
            __module__ : {value: "read_book.settings"}
        });

        styles_id = "calibre-color-scheme-style-overrides";
        function apply_colors(is_content_popup) {
            var des, elem, ss, text, c, ρσ_unpack, selbg, selfg, hints_box_css;
            des = document.documentElement.style;
            des.setProperty("--calibre-viewer-background-color", opts.color_scheme.background);
            des.setProperty("--calibre-viewer-foreground-color", opts.color_scheme.foreground);
            des.colorScheme = (opts.is_dark_theme) ? "dark" : "light";
            if (opts.color_scheme.link) {
                des.setProperty("--calibre-viewer-link-color", opts.color_scheme.link);
            }
            var ρσ_Iter0 = ρσ_Iterable(ρσ_list_decorate([ document.documentElement, document.body ]));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                elem = ρσ_Iter0[ρσ_Index0];
                elem.style.color = opts.color_scheme.foreground;
                elem.style.backgroundColor = "transparent";
            }
            des.backgroundColor = "transparent";
            ss = document.getElementById("calibre-color-scheme-style-overrides");
            if (!ss) {
                ss = ρσ_interpolate_kwargs.call(E, E.style, [ρσ_desugar_kwargs({id: styles_id, type: "text/css"})]);
                document.documentElement.appendChild(ss);
            }
            text = "";
            if (runtime.is_standalone_viewer && ρσ_in("macos", window.navigator.userAgent)) {
                text += "\n* { -webkit-hyphenate-character: \"-\" !important }\n";
            }
            if (opts.override_book_colors !== "never") {
                text = "body";
                if (opts.override_book_colors === "dark") {
                    text += ".calibre-viewer-dark-colors";
                }
                text += "\n        * {\n            color: " + ρσ_str.format("{}", opts.color_scheme.foreground) + " !important; /**/\n            background-color: " + ρσ_str.format("{}", opts.color_scheme.background) + " !important; /**/\n            border-color: " + ρσ_str.format("{}", opts.color_scheme.foreground) + " !important; /**/\n        }";
            }
            if (opts.color_scheme.link) {
                c = opts.color_scheme.link;
                text += "\nhtml > body :link, html > body :link * { color: " + ρσ_str.format("{}", c) + " !important } html > body :visited, html > body :visited * { color: " + ρσ_str.format("{}", c) + " !important }";
            }
            ρσ_unpack = default_selection_colors();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            selbg = ρσ_unpack[0];
            selfg = ρσ_unpack[1];
            selbg = make_selection_background_opaque(selbg);
            text += "\n::selection { background-color: " + ρσ_str.format("{}", selbg) + "; color: " + ρσ_str.format("{}", selfg) + " }";
            text += "\n::selection:window-inactive { background-color: " + ρσ_str.format("{}", selbg) + "; color: " + ρσ_str.format("{}", selfg) + " }";
            if (!is_content_popup) {
                text += "\nhtml::-webkit-scrollbar, body::-webkit-scrollbar { display: none !important }";
                text += "\nhtml, body { scrollbar-width: none !important }";
                text += "\n\n\n        .crw-has-dot::after {\n            content: \"\";            vertical-align: text-top;            background-color: currentColor !important;            text-decoration: none !important;            display: inline-block;            height: 0.7ex;            width: 0.7ex;            border-radius: 50%;        }\n        ";
            }
            hints_box_css = "\n            display: inline-block !important;            position: absolute !important;            text-indent: 0 !important;            text-decoration: none !important;            font-weight: bold !important;            color: " + ρσ_str.format("{}", selfg) + " !important;            background: " + ρσ_str.format("{}", selbg) + " !important;            cursor: default !important;            padding: 1px !important;            border: solid 1px " + ρσ_str.format("{}", opts.color_scheme.foreground) + " !important;    ";
            text += "\n\n\n        .calibre-reference-mode [data-calibre-ref-num]::before {\n            content: attr(data-calibre-ref-num) !important;            " + ρσ_str.format("{}", hints_box_css) + "\n        }\n    ";
            text += "\n\n\n        .calibre-hint-visible::before {\n            content: attr(data-calibre-hint-render) !important;            " + ρσ_str.format("{}", hints_box_css) + "\n        }\n\n        .calibre-hint-enter::before {\n            background: #FF5733 !important;         }\n\n        .calibre-animated-hint {\n            animation-name: calibre-animate-hint;             animation-duration: 0.3s;             animation-timing-function: ease-out;             display: inline-block !important;             text-indent: 0 !important;         }\n        @keyframes calibre-animate-hint {\n            from { transform: scale(1); }\n            to { transform: scale(2); }\n        }\n    ";
            ss.textContent = text;
        };
        if (!apply_colors.__argnames__) Object.defineProperties(apply_colors, {
            __argnames__ : {value: ["is_content_popup"]},
            __module__ : {value: "read_book.settings"}
        });

        function set_selection_style(style) {
            var ρσ_unpack, selbg, selfg, sheet, css_text, prop, rule;
            if (!style) {
                ρσ_unpack = default_selection_colors();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                selbg = ρσ_unpack[0];
                selfg = ρσ_unpack[1];
                style = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["color"] = selfg;
                    ρσ_d["background-color"] = selbg;
                    return ρσ_d;
                }).call(this);
            }
            sheet = document.getElementById(styles_id);
            if (!sheet) {
                return;
            }
            css_text = "";
            if (style.selbg) {
                style.selbg = make_selection_background_opaque(style.selbg);
            }
            var ρσ_Iter1 = ρσ_Iterable(Object.keys(style));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                prop = ρσ_Iter1[ρσ_Index1];
                css_text += "" + ρσ_str.format("{}", prop) + ": " + ρσ_str.format("{}", style[(typeof prop === "number" && prop < 0) ? style.length + prop : prop]) + "; ";
            }
            var ρσ_Iter2 = ρσ_Iterable(sheet.sheet.cssRules);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                rule = ρσ_Iter2[ρσ_Index2];
                if (rule.type === rule.STYLE_RULE && rule.selectorText.indexOf("selection") > -1) {
                    rule.style.cssText = css_text;
                }
            }
        };
        if (!set_selection_style.__argnames__) Object.defineProperties(set_selection_style, {
            __argnames__ : {value: ["style"]},
            __module__ : {value: "read_book.settings"}
        });

        function set_color_scheme_class() {
            document.documentElement.classList.add("is-calibre-viewer");
            if (opts.is_dark_theme) {
                document.body.classList.add("calibre-viewer-dark-colors");
                document.body.classList.remove("calibre-viewer-light-colors");
            } else {
                document.body.classList.add("calibre-viewer-light-colors");
                document.body.classList.remove("calibre-viewer-dark-colors");
            }
        };
        if (!set_color_scheme_class.__module__) Object.defineProperties(set_color_scheme_class, {
            __module__ : {value: "read_book.settings"}
        });

        function apply_stylesheet() {
            var sid, style;
            sid = "calibre-browser-viewer-user-stylesheet";
            style = document.getElementById(sid);
            if (!style) {
                if (!opts.user_stylesheet) {
                    return;
                }
                style = ρσ_interpolate_kwargs.call(E, E.style, [ρσ_desugar_kwargs({type: "text/css", id: sid})]);
                document.documentElement.appendChild(style);
            }
            style.textContent = opts.user_stylesheet;
        };
        if (!apply_stylesheet.__module__) Object.defineProperties(apply_stylesheet, {
            __module__ : {value: "read_book.settings"}
        });

        function apply_settings(is_content_popup) {
            apply_font_size();
            apply_colors(is_content_popup);
            apply_stylesheet();
        };
        if (!apply_settings.__argnames__) Object.defineProperties(apply_settings, {
            __argnames__ : {value: ["is_content_popup"]},
            __module__ : {value: "read_book.settings"}
        });

        ρσ_modules["read_book.settings"].opts = opts;
        ρσ_modules["read_book.settings"].styles_id = styles_id;
        ρσ_modules["read_book.settings"].update_settings = update_settings;
        ρσ_modules["read_book.settings"].apply_font_size = apply_font_size;
        ρσ_modules["read_book.settings"].default_selection_colors = default_selection_colors;
        ρσ_modules["read_book.settings"].make_selection_background_opaque = make_selection_background_opaque;
        ρσ_modules["read_book.settings"].apply_colors = apply_colors;
        ρσ_modules["read_book.settings"].set_selection_style = set_selection_style;
        ρσ_modules["read_book.settings"].set_color_scheme_class = set_color_scheme_class;
        ρσ_modules["read_book.settings"].apply_stylesheet = apply_stylesheet;
        ρσ_modules["read_book.settings"].apply_settings = apply_settings;
    })();

    (function(){
        var __name__ = "read_book.resources";
        var JSON_XHTML_MIMETYPE, mathjax_data, js_types, k, resource_tag_names, ns_rmap, ns_count, hide_tooltips;
        var E = ρσ_modules.elementmaker.E;

        var base64decode = ρσ_modules.encodings.base64decode;
        var utf8_decode = ρσ_modules.encodings.utf8_decode;

        var clear = ρσ_modules.dom.clear;
        var remove_all_attributes = ρσ_modules.dom.remove_all_attributes;

        var runtime = ρσ_modules["read_book.globals"].runtime;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var opts = ρσ_modules["read_book.settings"].opts;

        JSON_XHTML_MIMETYPE = "application/calibre+xhtml+json";
        function decode_component(x) {
            return utf8_decode(base64decode(x));
        };
        if (!decode_component.__argnames__) Object.defineProperties(decode_component, {
            __argnames__ : {value: ["x"]},
            __module__ : {value: "read_book.resources"}
        });

        function decode_url(x) {
            var parts;
            parts = x.split("#", 1);
            return [decode_component(parts[0]), parts[1] || ""];
        };
        if (!decode_url.__argnames__) Object.defineProperties(decode_url, {
            __argnames__ : {value: ["x"]},
            __module__ : {value: "read_book.resources"}
        });

        function create_link_pat(book) {
            return new RegExp(book.manifest.link_uid + "\\|([^|]+)\\|", "g");
        };
        if (!create_link_pat.__argnames__) Object.defineProperties(create_link_pat, {
            __argnames__ : {value: ["book"]},
            __module__ : {value: "read_book.resources"}
        });

        function load_resources(book, root_name, previous_resources, proceed) {
            var ans, pending_resources, link_pat;
            ans = Object.create(null);
            pending_resources = [root_name];
            link_pat = create_link_pat(book);
            function do_one() {
                var name, k, data;
                name = pending_resources.shift();
                if (!name) {
                    var ρσ_Iter0 = ρσ_Iterable(previous_resources);
                    for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                        k = ρσ_Iter0[ρσ_Index0];
                        delete previous_resources[k];
                    }
                    if ((ρσ_expr_temp = book.manifest.files)[(typeof root_name === "number" && root_name < 0) ? ρσ_expr_temp.length + root_name : root_name].has_maths) {
                        return load_mathjax(book, ans, proceed);
                    }
                    return proceed(ans);
                }
                if (ans[(typeof name === "number" && name < 0) ? ans.length + name : name]) {
                    return setTimeout(do_one, 0);
                }
                if (previous_resources[(typeof name === "number" && name < 0) ? previous_resources.length + name : name]) {
                    ans[(typeof name === "number" && name < 0) ? ans.length + name : name] = data = previous_resources[(typeof name === "number" && name < 0) ? previous_resources.length + name : name];
                    if (typeof data[0] === "string") {
                        find_virtualized_resources(data[0]);
                    }
                    return setTimeout(do_one, 0);
                }
                ui_operations.get_file(book, name, got_one);
            };
            if (!do_one.__module__) Object.defineProperties(do_one, {
                __module__ : {value: "read_book.resources"}
            });

            function got_one(data, name, mimetype) {
                ans[(typeof name === "number" && name < 0) ? ans.length + name : name] = [data, mimetype];
                if (typeof data === "string" && ρσ_exists.d((ρσ_expr_temp = book.manifest.files)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]).is_virtualized) {
                    find_virtualized_resources(data);
                }
                return setTimeout(do_one, 0);
            };
            if (!got_one.__argnames__) Object.defineProperties(got_one, {
                __argnames__ : {value: ["data", "name", "mimetype"]},
                __module__ : {value: "read_book.resources"}
            });

            function find_virtualized_resources(text) {
                var seen, already_pending, x, m, name;
                seen = set();
                already_pending = (function() {
                    var ρσ_Iter = ρσ_Iterable(pending_resources), ρσ_Result = ρσ_set(), x;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        x = ρσ_Iter[ρσ_Index];
                        ρσ_Result.add(x.name);
                    }
                    return ρσ_Result;
                })();
                link_pat.lastIndex = 0;
                while (true) {
                    m = link_pat.exec(text);
                    if (!m) {
                        break;
                    }
                    name = decode_url(m[1])[0];
                    if (ρσ_in(name, seen) || ρσ_in(name, already_pending)) {
                        continue;
                    }
                    seen.add(name);
                    pending_resources.push(name);
                }
            };
            if (!find_virtualized_resources.__argnames__) Object.defineProperties(find_virtualized_resources, {
                __argnames__ : {value: ["text"]},
                __module__ : {value: "read_book.resources"}
            });

            do_one();
        };
        if (!load_resources.__argnames__) Object.defineProperties(load_resources, {
            __argnames__ : {value: ["book", "root_name", "previous_resources", "proceed"]},
            __module__ : {value: "read_book.resources"}
        });

        mathjax_data = null;
        function load_mathjax(book, resource_data, proceed) {
            if (mathjax_data === null) {
                ui_operations.get_mathjax_files((function() {
                    var ρσ_anonfunc = function (data) {
                        mathjax_data = data;
                        resource_data["..mathjax-files.."] = data;
                        proceed(resource_data);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["data"]},
                        __module__ : {value: "read_book.resources"}
                    });
                    return ρσ_anonfunc;
                })());
            } else {
                resource_data["..mathjax-files.."] = mathjax_data;
                proceed(resource_data);
            }
        };
        if (!load_mathjax.__argnames__) Object.defineProperties(load_mathjax, {
            __argnames__ : {value: ["book", "resource_data", "proceed"]},
            __module__ : {value: "read_book.resources"}
        });

        function finalize_resources(book, root_name, resource_data) {
            var blob_url_map, root_data, link_pat, mathjax, ρσ_unpack, data, mimetype, name, unresolved_deps_map, resolved, num, text, unresolved_deps, unresolved;
            blob_url_map = Object.create(null);
            root_data = null;
            link_pat = create_link_pat(book);
            mathjax = resource_data["..mathjax-files.."];
            delete resource_data["..mathjax-files.."];
            var ρσ_Iter1 = ρσ_Iterable(resource_data);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                name = ρσ_Iter1[ρσ_Index1];
                ρσ_unpack = resource_data[(typeof name === "number" && name < 0) ? resource_data.length + name : name];
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                data = ρσ_unpack[0];
                mimetype = ρσ_unpack[1];
                if (typeof data !== "string") {
                    blob_url_map[(typeof name === "number" && name < 0) ? blob_url_map.length + name : name] = window.URL.createObjectURL(data);
                }
            }
            var ρσ_Iter2 = ρσ_Iterable(blob_url_map);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                name = ρσ_Iter2[ρσ_Index2];
                delete resource_data[name];
            }
            function add_virtualized_resource(name, text, mimetype) {
                if (name === root_name) {
                    root_data = JSON.parse(text);
                } else {
                    blob_url_map[(typeof name === "number" && name < 0) ? blob_url_map.length + name : name] = window.URL.createObjectURL(new Blob(ρσ_list_decorate([ text ]), (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["type"] = mimetype;
                        return ρσ_d;
                    }).call(this)));
                }
            };
            if (!add_virtualized_resource.__argnames__) Object.defineProperties(add_virtualized_resource, {
                __argnames__ : {value: ["name", "text", "mimetype"]},
                __module__ : {value: "read_book.resources"}
            });

            function replace_deps(text) {
                var replacements, unresolved_deps, m, ρσ_unpack, dname, frag, rtext, index, sz, repl;
                replacements = [];
                unresolved_deps = set();
                link_pat.lastIndex = 0;
                while (true) {
                    m = link_pat.exec(text);
                    if (!m) {
                        break;
                    }
                    ρσ_unpack = decode_url(m[1]);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                    dname = ρσ_unpack[0];
                    frag = ρσ_unpack[1];
                    if (blob_url_map[(typeof dname === "number" && dname < 0) ? blob_url_map.length + dname : dname]) {
                        rtext = blob_url_map[(typeof dname === "number" && dname < 0) ? blob_url_map.length + dname : dname];
                        if (frag) {
                            rtext += "#" + frag;
                        }
                        replacements.push([m.index, m[0].length, rtext]);
                    } else {
                        unresolved_deps.add(dname);
                    }
                }
                var ρσ_Iter3 = ρσ_Iterable(reversed(replacements));
                for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                    ρσ_unpack = ρσ_flatten(ρσ_Iter3[ρσ_Index3]);
                    index = ρσ_unpack[0];
                    sz = ρσ_unpack[1];
                    repl = ρσ_unpack[2];
                    text = text.slice(0, index) + repl + text.slice(index + sz);
                }
                return [unresolved_deps, text];
            };
            if (!replace_deps.__argnames__) Object.defineProperties(replace_deps, {
                __argnames__ : {value: ["text"]},
                __module__ : {value: "read_book.resources"}
            });

            unresolved_deps_map = Object.create(null);
            function has_unresolvable_deps(name) {
                var deps, x;
                deps = unresolved_deps_map[(typeof name === "number" && name < 0) ? unresolved_deps_map.length + name : name];
                if (!deps || !deps.length) {
                    return false;
                }
                var ρσ_Iter4 = ρσ_Iterable(deps);
                for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                    x = ρσ_Iter4[ρσ_Index4];
                    if (!blob_url_map[(typeof x === "number" && x < 0) ? blob_url_map.length + x : x]) {
                        return true;
                    }
                }
                return false;
            };
            if (!has_unresolvable_deps.__argnames__) Object.defineProperties(has_unresolvable_deps, {
                __argnames__ : {value: ["name"]},
                __module__ : {value: "read_book.resources"}
            });

            while (true) {
                resolved = [];
                num = 0;
                var ρσ_Iter5 = ρσ_Iterable(resource_data);
                for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                    name = ρσ_Iter5[ρσ_Index5];
                    if (!blob_url_map[(typeof name === "number" && name < 0) ? blob_url_map.length + name : name]) {
                        num += 1;
                        ρσ_unpack = resource_data[(typeof name === "number" && name < 0) ? resource_data.length + name : name];
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                        text = ρσ_unpack[0];
                        mimetype = ρσ_unpack[1];
                        if (!has_unresolvable_deps(name)) {
                            ρσ_unpack = replace_deps(text);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                            unresolved_deps = ρσ_unpack[0];
                            text = ρσ_unpack[1];
                            unresolved_deps_map[(typeof name === "number" && name < 0) ? unresolved_deps_map.length + name : name] = unresolved_deps;
                            if (!unresolved_deps.length) {
                                add_virtualized_resource(name, text, mimetype);
                                resolved.push(name);
                            }
                        }
                    }
                }
                if (!num) {
                    break;
                }
                if (!resolved.length) {
                    unresolved = (function() {
                        var ρσ_Iter = ρσ_Iterable(resource_data), ρσ_Result = [], name;
                        for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                            name = ρσ_Iter[ρσ_Index];
                            if (!blob_url_map[(typeof name === "number" && name < 0) ? blob_url_map.length + name : name]) {
                                ρσ_Result.push(name);
                            }
                        }
                        ρσ_Result = ρσ_list_constructor(ρσ_Result);
                        return ρσ_Result;
                    })();
                    print("ERROR: Could not resolve all dependencies of {} because of a cyclic dependency. Remaining deps: {}".format(root_name, unresolved));
                    var ρσ_Iter6 = ρσ_Iterable(resource_data);
                    for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                        name = ρσ_Iter6[ρσ_Index6];
                        if (!blob_url_map[(typeof name === "number" && name < 0) ? blob_url_map.length + name : name]) {
                            ρσ_unpack = resource_data[(typeof name === "number" && name < 0) ? resource_data.length + name : name];
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                            text = ρσ_unpack[0];
                            mimetype = ρσ_unpack[1];
                            text = replace_deps(text)[1];
                            add_virtualized_resource(name, text, mimetype);
                        }
                    }
                    break;
                }
                var ρσ_Iter7 = ρσ_Iterable(resolved);
                for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                    name = ρσ_Iter7[ρσ_Index7];
                    delete resource_data[name];
                }
            }
            return [root_data, mathjax, blob_url_map];
        };
        if (!finalize_resources.__argnames__) Object.defineProperties(finalize_resources, {
            __argnames__ : {value: ["book", "root_name", "resource_data"]},
            __module__ : {value: "read_book.resources"}
        });

        js_types = (function() {
            var ρσ_Iter = ρσ_Iterable("text/javascript text/ecmascript application/javascript application/ecmascript".split(" ")), ρσ_Result = Object.create(null), k;
            for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                k = ρσ_Iter[ρσ_Index];
                ρσ_Result[k] = (true);
            }
            return ρσ_Result;
        })();
        resource_tag_names = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["script"] = "src";
            ρσ_d["link"] = "href";
            ρσ_d["img"] = "src";
            ρσ_d["image"] = "xlink:href";
            return ρσ_d;
        }).call(this);
        ns_rmap = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["http://www.w3.org/2000/svg"] = "svg";
            ρσ_d["http://www.w3.org/1999/xlink"] = "xlink";
            ρσ_d["http://www.w3.org/1998/Math/MathML"] = "math";
            ρσ_d["http://www.w3.org/XML/1998/namespace"] = "xml";
            ρσ_d["http://www.idpf.org/2007/ops"] = "epub";
            return ρσ_d;
        }).call(this);
        ns_count = 0;
        hide_tooltips = false;
        function get_prefix(ns) {
            var ans;
            ans = ns_rmap[(typeof ns === "number" && ns < 0) ? ns_rmap.length + ns : ns];
            if (!ans) {
                ns_rmap[(typeof ns === "number" && ns < 0) ? ns_rmap.length + ns : ns] = ans = "ns" + ns_count;
                ns_count += 1;
            }
            return ans + ":";
        };
        if (!get_prefix.__argnames__) Object.defineProperties(get_prefix, {
            __argnames__ : {value: ["ns"]},
            __module__ : {value: "read_book.resources"}
        });

        function apply_attributes(src, elem, ns_map) {
            var attributes, ns, name, a;
            attributes = src.a;
            if (!attributes) {
                return;
            }
            var ρσ_Iter8 = ρσ_Iterable(attributes);
            for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                a = ρσ_Iter8[ρσ_Index8];
                if (a[2]) {
                    ns = ns_map[ρσ_bound_index(a[2], ns_map)];
                    elem.setAttributeNS(ns, get_prefix(ns) + a[0], a[1]);
                } else {
                    name = a[0];
                    if (hide_tooltips && (name === "title" || name === "alt")) {
                        continue;
                    }
                    elem.setAttribute(name, a[1]);
                }
            }
        };
        if (!apply_attributes.__argnames__) Object.defineProperties(apply_attributes, {
            __argnames__ : {value: ["src", "elem", "ns_map"]},
            __module__ : {value: "read_book.resources"}
        });

        function is_loadable_link(attributes) {
            var x, a;
            var ρσ_Iter9 = ρσ_Iterable(attributes);
            for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                a = ρσ_Iter9[ρσ_Index9];
                if (a[0].toLowerCase() === "rel" && a[1]) {
                    var ρσ_Iter10 = ρσ_Iterable(a[1].split(" "));
                    for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                        x = ρσ_Iter10[ρσ_Index10];
                        if (x.toLowerCase() === "stylesheet") {
                            return true;
                        }
                    }
                }
            }
            return false;
        };
        if (!is_loadable_link.__argnames__) Object.defineProperties(is_loadable_link, {
            __argnames__ : {value: ["attributes"]},
            __module__ : {value: "read_book.resources"}
        });

        function process_stack(stack, tag_map, ns_map, load_required, onload) {
            var ρσ_unpack, node, parent, tag_id, src, elem, loadable, attr, a, load_callback;
            while (stack.length) {
                ρσ_unpack = stack.pop();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                node = ρσ_unpack[0];
                parent = ρσ_unpack[1];
                if (tag_map) {
                    tag_id = node[0];
                    src = tag_map[(typeof tag_id === "number" && tag_id < 0) ? tag_map.length + tag_id : tag_id];
                } else {
                    src = node;
                    tag_id = process_stack.tag_id++;
                }
                if (src.s) {
                    if (src.n) {
                        elem = document.createElementNS(ns_map[ρσ_bound_index(src.s, ns_map)], src.n);
                    } else {
                        if (src.l) {
                            parent.appendChild(document.createTextNode(src.l));
                        }
                        continue;
                    }
                } else {
                    elem = document.createElement(src.n);
                }
                loadable = false;
                attr = resource_tag_names[ρσ_bound_index(src.n, resource_tag_names)];
                if (attr) {
                    if (ρσ_not_equals(attr.indexOf(":"), -1)) {
                        attr = attr.replace("xlink:", "");
                    }
                    if (src.a) {
                        var ρσ_Iter11 = ρσ_Iterable(src.a);
                        for (var ρσ_Index11 = 0; ρσ_Index11 < ρσ_Iter11.length; ρσ_Index11++) {
                            a = ρσ_Iter11[ρσ_Index11];
                            if (a[0] === attr) {
                                loadable = (src.n === "link") ? is_loadable_link(src.a) : true;
                                break;
                            }
                        }
                    }
                }
                if (loadable) {
                    load_required.add(tag_id);
                    load_callback = onload.bind(tag_id);
                    elem.addEventListener("load", load_callback);
                    elem.addEventListener("error", load_callback);
                }
                apply_attributes(src, elem, ns_map);
                parent.appendChild(elem);
                if (src.x) {
                    if (src.n === "script" && js_types[ρσ_bound_index((elem.getAttribute("type") || "text/javascript").toLowerCase(), js_types)] === true) {
                        elem.text = src.x;
                    } else {
                        elem.appendChild(document.createTextNode(src.x));
                    }
                }
                if (src.l) {
                    parent.appendChild(document.createTextNode(src.l));
                }
                if (tag_map) {
                    for (var i = node.length - 1; i >= 1; i--) {
                        stack.push([node[i], elem]);
                    }
                } else if (node.c) {
                    for (var i = node.c.length; i-- > 0;) {
                        stack.push([node.c[i], elem]);
                    }
                }
            }
        };
        if (!process_stack.__argnames__) Object.defineProperties(process_stack, {
            __argnames__ : {value: ["stack", "tag_map", "ns_map", "load_required", "onload"]},
            __module__ : {value: "read_book.resources"}
        });

        function unserialize_html(serialized_data, proceed, postprocess_dom, root_name) {
            var html, ns_map, base, load_required, proceeded, hang_timeout, body_done, child, ev;
            hide_tooltips = opts.hide_tooltips;
            if (serialized_data.tag_map) {
                return unserialize_html_legacy(serialized_data, proceed, postprocess_dom, root_name);
            }
            html = serialized_data.tree;
            ns_map = serialized_data.ns_map;
            remove_all_attributes(document.documentElement, document.head, document.body);
            clear(document.head, document.body);
            apply_attributes(html, document.documentElement, ns_map);
            document.head.appendChild(ρσ_interpolate_kwargs.call(E, E.style, ["html::-webkit-scrollbar, body::-webkit-scrollbar { display: none !important }"].concat([ρσ_desugar_kwargs({type: "text/css"})])));
            if (runtime.is_standalone_viewer && root_name) {
                if (root_name.indexOf("/") > -1) {
                    base = window.location.pathname.rpartition("/")[0];
                    base = "" + ρσ_str.format("{}", window.location.protocol) + "//" + ρσ_str.format("{}", window.location.hostname) + "" + ρσ_str.format("{}", base) + "/" + root_name;
                    document.head.appendChild(ρσ_interpolate_kwargs.call(E, E.base, [ρσ_desugar_kwargs({href: base})]));
                }
            }
            if (!runtime.is_standalone_viewer) {
                document.head.appendChild(ρσ_interpolate_kwargs.call(E, E.style, ["html {{ font-family: {} }}".format(window.default_font_family || "sans-serif")].concat([ρσ_desugar_kwargs({type: "text/css"})])));
            }
            load_required = set();
            proceeded = false;
            hang_timeout = 5;
            function hangcheck() {
                if (!proceeded) {
                    proceeded = true;
                    print("WARNING: All resources did not load in " + ρσ_str.format("{}", hang_timeout) + " seconds, proceeding anyway (" + ρσ_str.format("{}", load_required.length) + " resources left)");
                    proceed();
                }
            };
            if (!hangcheck.__module__) Object.defineProperties(hangcheck, {
                __module__ : {value: "read_book.resources"}
            });

            function onload() {
                load_required.discard(this);
                if (!load_required.length && !proceeded) {
                    proceeded = true;
                    proceed();
                }
            };
            if (!onload.__module__) Object.defineProperties(onload, {
                __module__ : {value: "read_book.resources"}
            });

            function process_children(node, parent) {
                var stack, child;
                if (!node.c) {
                    return;
                }
                stack = [];
                for (var i = node.c.length; i-- > 0;) {
                    child = node.c[i];
                    if (child.n !== "meta" && child.n !== "base") {
                        stack.push([child, parent]);
                    }
                }
                process_stack(stack, null, ns_map, load_required, onload);
            };
            if (!process_children.__argnames__) Object.defineProperties(process_children, {
                __argnames__ : {value: ["node", "parent"]},
                __module__ : {value: "read_book.resources"}
            });

            body_done = false;
            process_stack.tag_id = 1;
            var ρσ_Iter12 = ρσ_Iterable(html.c);
            for (var ρσ_Index12 = 0; ρσ_Index12 < ρσ_Iter12.length; ρσ_Index12++) {
                child = ρσ_Iter12[ρσ_Index12];
                if (child.n === "head") {
                    process_children(child, document.head);
                } else if (child.n === "body") {
                    if (!document.body) {
                        document.documentElement.appendChild(document.createElement("body"));
                    }
                    if (!body_done) {
                        body_done = true;
                        apply_attributes(child, document.body, ns_map);
                    }
                    if (child.x) {
                        document.body.appendChild(document.createTextNode(child.x));
                    }
                    process_children(child, document.body);
                }
            }
            if (postprocess_dom) {
                postprocess_dom();
            }
            ev = document.createEvent("Event");
            ev.initEvent("DOMContentLoaded", true, true);
            document.dispatchEvent(ev);
            if (load_required.length) {
                setTimeout(hangcheck, hang_timeout * 1e3);
            } else {
                proceeded = true;
                proceed();
            }
        };
        if (!unserialize_html.__argnames__) Object.defineProperties(unserialize_html, {
            __argnames__ : {value: ["serialized_data", "proceed", "postprocess_dom", "root_name"]},
            __module__ : {value: "read_book.resources"}
        });

        function unserialize_html_legacy(serialized_data, proceed, postprocess_dom, root_name) {
            var tag_map, tree, ns_map, html, ρσ_unpack, head, body, base, load_required, proceeded, hang_timeout, stack, bnode, ev;
            tag_map = serialized_data.tag_map;
            tree = serialized_data.tree;
            ns_map = serialized_data.ns_map;
            html = tag_map[0];
            remove_all_attributes(document.documentElement);
            apply_attributes(html, document.documentElement, ns_map);
            ρσ_unpack = [tree[1], tree[2]];
            head = ρσ_unpack[0];
            body = ρσ_unpack[1];
            clear(document.head, document.body);
            remove_all_attributes(document.head, document.body);
            document.head.appendChild(ρσ_interpolate_kwargs.call(E, E.style, ["html::-webkit-scrollbar, body::-webkit-scrollbar { display: none !important }"].concat([ρσ_desugar_kwargs({type: "text/css"})])));
            if (runtime.is_standalone_viewer && root_name) {
                if (root_name.indexOf("/") > -1) {
                    base = window.location.pathname.rpartition("/")[0];
                    base = "" + ρσ_str.format("{}", window.location.protocol) + "//" + ρσ_str.format("{}", window.location.hostname) + "" + ρσ_str.format("{}", base) + "/" + root_name;
                    document.head.appendChild(ρσ_interpolate_kwargs.call(E, E.base, [ρσ_desugar_kwargs({href: base})]));
                }
            }
            if (!runtime.is_standalone_viewer) {
                document.head.appendChild(ρσ_interpolate_kwargs.call(E, E.style, ["html {{ font-family: {} }}".format(window.default_font_family || "sans-serif")].concat([ρσ_desugar_kwargs({type: "text/css"})])));
            }
            load_required = set();
            proceeded = false;
            hang_timeout = 5;
            function hangcheck() {
                if (!proceeded) {
                    proceeded = true;
                    print("WARNING: All resources did not load in " + ρσ_str.format("{}", hang_timeout) + " seconds, proceeding anyway (" + ρσ_str.format("{}", load_required.length) + " resources left)");
                    proceed();
                }
            };
            if (!hangcheck.__module__) Object.defineProperties(hangcheck, {
                __module__ : {value: "read_book.resources"}
            });

            function onload() {
                load_required.discard(this);
                if (!load_required.length && !proceeded) {
                    proceeded = true;
                    proceed();
                }
            };
            if (!onload.__module__) Object.defineProperties(onload, {
                __module__ : {value: "read_book.resources"}
            });

            stack = [];
            for (var i = head.length - 1; i >= 1; i--) {
                stack.push([head[i], document.head]);
            }
            process_stack(stack, tag_map, ns_map, load_required, onload);
            bnode = tag_map[ρσ_bound_index(body[0], tag_map)];
            apply_attributes(bnode, document.body, ns_map);
            if (bnode.x) {
                document.body.appendChild(document.createTextNode(bnode.x));
            }
            for (var i = body.length - 1; i >= 1; i--) {
                stack.push([body[i], document.body]);
            }
            process_stack(stack, tag_map, ns_map, load_required, onload);
            if (postprocess_dom) {
                postprocess_dom();
            }
            ev = document.createEvent("Event");
            ev.initEvent("DOMContentLoaded", true, true);
            document.dispatchEvent(ev);
            if (load_required.length) {
                setTimeout(hangcheck, hang_timeout * 1e3);
            } else {
                proceeded = true;
                proceed();
            }
        };
        if (!unserialize_html_legacy.__argnames__) Object.defineProperties(unserialize_html_legacy, {
            __argnames__ : {value: ["serialized_data", "proceed", "postprocess_dom", "root_name"]},
            __module__ : {value: "read_book.resources"}
        });

        function text_from_serialized_html(data, get_anchor_offset_map) {
            var serialized_data, tag_map, ans, no_visit, ignore_text, stack, child, anchor_offset_map, text_pos, ρσ_unpack, node, text_ignored_in_parent, src, x, aid, ignore_text_in_node_and_children;
            serialized_data = JSON.parse(data);
            tag_map = serialized_data.tag_map;
            ans = [];
            no_visit = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["script"] = true;
                ρσ_d["style"] = true;
                ρσ_d["title"] = true;
                ρσ_d["head"] = true;
                return ρσ_d;
            }).call(this);
            ignore_text = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["img"] = true;
                ρσ_d["math"] = true;
                ρσ_d["rt"] = true;
                ρσ_d["rp"] = true;
                ρσ_d["rtc"] = true;
                return ρσ_d;
            }).call(this);
            ignore_text;
            if (tag_map) {
                stack = [[serialized_data.tree[2], false]];
            } else {
                stack = [];
                var ρσ_Iter13 = ρσ_Iterable(serialized_data.tree.c);
                for (var ρσ_Index13 = 0; ρσ_Index13 < ρσ_Iter13.length; ρσ_Index13++) {
                    child = ρσ_Iter13[ρσ_Index13];
                    if (child.n === "body") {
                        stack.push([child, false]);
                    }
                }
            }
            anchor_offset_map = Object.create(null);
            text_pos = 0;
            while (stack.length) {
                ρσ_unpack = stack.pop();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                node = ρσ_unpack[0];
                text_ignored_in_parent = ρσ_unpack[1];
                if (typeof node === "string") {
                    ans.push(node);
                    text_pos += node.length;
                    continue;
                }
                src = (tag_map) ? tag_map[ρσ_bound_index(node[0], tag_map)] : node;
                if (get_anchor_offset_map && src.a) {
                    for (var i = 0; i < src.a.length; i++) {
                        x = (ρσ_expr_temp = src.a)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
                        if (x[0] === "id") {
                            aid = x[1];
                            if (typeof anchor_offset_map[(typeof aid === "number" && aid < 0) ? anchor_offset_map.length + aid : aid] !== "number") {
                                anchor_offset_map[(typeof aid === "number" && aid < 0) ? anchor_offset_map.length + aid : aid] = text_pos;
                            }
                        }
                    }
                }
                if (no_visit[ρσ_bound_index(src.n, no_visit)]) {
                    continue;
                }
                ignore_text_in_node_and_children = text_ignored_in_parent || !!ignore_text[src.n];
                if (!ignore_text_in_node_and_children && src.x) {
                    ans.push(src.x);
                    text_pos += src.x.length;
                }
                if (!text_ignored_in_parent && src.l) {
                    stack.push([src.l, ignore_text_in_node_and_children]);
                }
                if (tag_map) {
                    for (var i = node.length - 1; i >= 1; i--) {
                        stack.push([node[i], ignore_text_in_node_and_children]);
                    }
                } else {
                    if (src.c) {
                        for (var i = src.c.length; i-- > 0;) {
                            stack.push([src.c[i], ignore_text_in_node_and_children]);
                        }
                    }
                }
            }
            ans = ans.join("");
            if (get_anchor_offset_map) {
                return [ans, anchor_offset_map];
            }
            return ans;
        };
        if (!text_from_serialized_html.__argnames__) Object.defineProperties(text_from_serialized_html, {
            __argnames__ : {value: ["data", "get_anchor_offset_map"]},
            __module__ : {value: "read_book.resources"}
        });

        ρσ_modules["read_book.resources"].JSON_XHTML_MIMETYPE = JSON_XHTML_MIMETYPE;
        ρσ_modules["read_book.resources"].mathjax_data = mathjax_data;
        ρσ_modules["read_book.resources"].js_types = js_types;
        ρσ_modules["read_book.resources"].k = k;
        ρσ_modules["read_book.resources"].resource_tag_names = resource_tag_names;
        ρσ_modules["read_book.resources"].ns_rmap = ns_rmap;
        ρσ_modules["read_book.resources"].ns_count = ns_count;
        ρσ_modules["read_book.resources"].hide_tooltips = hide_tooltips;
        ρσ_modules["read_book.resources"].decode_component = decode_component;
        ρσ_modules["read_book.resources"].decode_url = decode_url;
        ρσ_modules["read_book.resources"].create_link_pat = create_link_pat;
        ρσ_modules["read_book.resources"].load_resources = load_resources;
        ρσ_modules["read_book.resources"].load_mathjax = load_mathjax;
        ρσ_modules["read_book.resources"].finalize_resources = finalize_resources;
        ρσ_modules["read_book.resources"].get_prefix = get_prefix;
        ρσ_modules["read_book.resources"].apply_attributes = apply_attributes;
        ρσ_modules["read_book.resources"].is_loadable_link = is_loadable_link;
        ρσ_modules["read_book.resources"].process_stack = process_stack;
        ρσ_modules["read_book.resources"].unserialize_html = unserialize_html;
        ρσ_modules["read_book.resources"].unserialize_html_legacy = unserialize_html_legacy;
        ρσ_modules["read_book.resources"].text_from_serialized_html = text_from_serialized_html;
    })();

    (function(){
        var __name__ = "read_book.footnotes";
        var block_names, block_display_styles, ok_list_types;
        var clear = ρσ_modules.dom.clear;

        var IframeClient = ρσ_modules.iframe_comm.IframeClient;

        var runtime = ρσ_modules["read_book.globals"].runtime;
        var current_spine_item = ρσ_modules["read_book.globals"].current_spine_item;
        var set_current_spine_item = ρσ_modules["read_book.globals"].set_current_spine_item;

        var finalize_resources = ρσ_modules["read_book.resources"].finalize_resources;
        var unserialize_html = ρσ_modules["read_book.resources"].unserialize_html;

        var apply_settings = ρσ_modules["read_book.settings"].apply_settings;
        var set_color_scheme_class = ρσ_modules["read_book.settings"].set_color_scheme_class;
        var update_settings = ρσ_modules["read_book.settings"].update_settings;

        block_names = dict.fromkeys(['p', 'div', 'li', 'td', 'h1', 'h2', 'h2', 'h3', 'h4', 'h5', 'h6', 'body'], true).as_object();
        block_display_styles = dict.fromkeys(['block', 'list-item', 'table-cell', 'table'], true).as_object();
        function elem_roles(elem) {
            return (function() {
                var ρσ_Iter = ρσ_Iterable((elem.getAttribute("role") || "").split(" ")), ρσ_Result = Object.create(null), k;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    k = ρσ_Iter[ρσ_Index];
                    ρσ_Result[k.toLowerCase()] = (true);
                }
                return ρσ_Result;
            })();
        };
        if (!elem_roles.__argnames__) Object.defineProperties(elem_roles, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.footnotes"}
        });

        function epub_type(elem) {
            var a;
            var ρσ_Iter0 = ρσ_Iterable(elem.attributes);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                a = ρσ_Iter0[ρσ_Index0];
                if (ρσ_equals(a.nodeName.toLowerCase(), "epub:type") && a.nodeValue) {
                    return a.nodeValue;
                }
            }
        };
        if (!epub_type.__argnames__) Object.defineProperties(epub_type, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.footnotes"}
        });

        function get_containing_block(node) {
            while (node && node.tagName && block_names[ρσ_bound_index(node.tagName.toLowerCase(), block_names)] !== true) {
                node = node.parentNode;
            }
            return node;
        };
        if (!get_containing_block.__argnames__) Object.defineProperties(get_containing_block, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "read_book.footnotes"}
        });

        function is_footnote_link(a, dest_name, dest_frag, src_name, link_to_map) {
            var roles, ρσ_unpack, x, num, style, children, text_children, eid, files_linking_to_self, files_linking_to_anchor, cb, ltext, ctext;
            roles = elem_roles(a);
            if (roles["doc-noteref"] || roles["doc-biblioref"] || roles["doc-glossref"]) {
                return true;
            }
            if (roles["doc-link"]) {
                return false;
            }
            if (epub_type(a) === "noteref") {
                return true;
            }
            ρσ_unpack = [a, 3];
            x = ρσ_unpack[0];
            num = ρσ_unpack[1];
            while (x && num > 0) {
                style = window.getComputedStyle(x);
                if (!(ρσ_expr_temp = is_footnote_link.inline_displays)[ρσ_bound_index(style.display, ρσ_expr_temp)]) {
                    break;
                }
                if ((ρσ_expr_temp = is_footnote_link.vert_aligns)[ρσ_bound_index(style.verticalAlign, ρσ_expr_temp)]) {
                    return true;
                }
                x = x.parentNode;
                num -= 1;
            }
            children = (function() {
                var ρσ_Iter = ρσ_Iterable(a.childNodes), ρσ_Result = [], x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    if (x.nodeType === Node.ELEMENT_NODE) {
                        ρσ_Result.push(x);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
            if ((children.length === 1 || typeof children.length === "object" && ρσ_equals(children.length, 1))) {
                style = window.getComputedStyle(children[0]);
                if ((ρσ_expr_temp = is_footnote_link.inline_displays)[ρσ_bound_index(style.display, ρσ_expr_temp)] && (ρσ_expr_temp = is_footnote_link.vert_aligns)[ρσ_bound_index(style.verticalAlign, ρσ_expr_temp)]) {
                    text_children = (function() {
                        var ρσ_Iter = ρσ_Iterable(a.childNodes), ρσ_Result = [], x;
                        for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                            x = ρσ_Iter[ρσ_Index];
                            if (x.nodeType === Node.TEXT_NODE && x.nodeValue && /\S+/.test(x.nodeValue)) {
                                ρσ_Result.push(x);
                            }
                        }
                        ρσ_Result = ρσ_list_constructor(ρσ_Result);
                        return ρσ_Result;
                    })();
                    if (!text_children.length) {
                        return true;
                    }
                }
            }
            eid = a.getAttribute("id") || a.getAttribute("name");
            files_linking_to_self = link_to_map[(typeof src_name === "number" && src_name < 0) ? link_to_map.length + src_name : src_name];
            if (eid && files_linking_to_self) {
                files_linking_to_anchor = files_linking_to_self[(typeof eid === "number" && eid < 0) ? files_linking_to_self.length + eid : eid] || [];
                if (files_linking_to_anchor.length > 1 || (files_linking_to_anchor.length === 1 || typeof files_linking_to_anchor.length === "object" && ρσ_equals(files_linking_to_anchor.length, 1)) && files_linking_to_anchor[0] !== src_name) {
                    cb = get_containing_block(a);
                    if (!cb || ρσ_equals(cb.tagName.toLowerCase(), "body")) {
                        return false;
                    }
                    ltext = a.textContent;
                    if (!ltext) {
                        return false;
                    }
                    ctext = cb.textContent;
                    if (!ctext) {
                        return false;
                    }
                    if (ctext.strip() === ltext.strip()) {
                        return false;
                    }
                    return true;
                }
            }
            return false;
        };
        if (!is_footnote_link.__argnames__) Object.defineProperties(is_footnote_link, {
            __argnames__ : {value: ["a", "dest_name", "dest_frag", "src_name", "link_to_map"]},
            __module__ : {value: "read_book.footnotes"}
        });

        is_footnote_link.inline_displays = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["inline"] = true;
            ρσ_d["inline-block"] = true;
            return ρσ_d;
        }).call(this);
        is_footnote_link.vert_aligns = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["sub"] = true;
            ρσ_d["super"] = true;
            ρσ_d["top"] = true;
            ρσ_d["bottom"] = true;
            return ρσ_d;
        }).call(this);
        function is_epub_footnote(node) {
            var et, roles;
            et = epub_type(node);
            if (et) {
                et = et.toLowerCase();
                if (et === "note" || et === "footnote" || et === "rearnote") {
                    return true;
                }
            }
            roles = elem_roles(node);
            if (roles["doc-note"] || roles["doc-footnote"] || roles["doc-rearnote"]) {
                return true;
            }
            return false;
        };
        if (!is_epub_footnote.__argnames__) Object.defineProperties(is_epub_footnote, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "read_book.footnotes"}
        });

        function get_note_container(node) {
            while (node && block_names[ρσ_bound_index(node.tagName.toLowerCase(), block_names)] !== true && block_display_styles[ρσ_bound_index(window.getComputedStyle(node).display, block_display_styles)] !== true) {
                node = node.parentNode;
            }
            return node;
        };
        if (!get_note_container.__argnames__) Object.defineProperties(get_note_container, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "read_book.footnotes"}
        });

        function get_parents_and_self(node) {
            var ans;
            ans = [];
            while (node && node !== document.body) {
                ans.push(node);
                node = node.parentNode;
            }
            return ans;
        };
        if (!get_parents_and_self.__argnames__) Object.defineProperties(get_parents_and_self, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "read_book.footnotes"}
        });

        function get_page_break(node) {
            var style;
            style = window.getComputedStyle(node);
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["before"] = (ρσ_expr_temp = get_page_break.on)[ρσ_bound_index(style.getPropertyValue("page-break-before"), ρσ_expr_temp)] === true;
                ρσ_d["after"] = (ρσ_expr_temp = get_page_break.on)[ρσ_bound_index(style.getPropertyValue("page-break-after"), ρσ_expr_temp)] === true;
                return ρσ_d;
            }).call(this);
        };
        if (!get_page_break.__argnames__) Object.defineProperties(get_page_break, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "read_book.footnotes"}
        });

        get_page_break.on = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["always"] = true;
            ρσ_d["left"] = true;
            ρσ_d["right"] = true;
            return ρσ_d;
        }).call(this);
        function hide_children(node) {
            var child;
            var ρσ_Iter1 = ρσ_Iterable(node.childNodes);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                child = ρσ_Iter1[ρσ_Index1];
                if (child.nodeType === Node.ELEMENT_NODE) {
                    if (child.do_not_hide) {
                        hide_children(child);
                        delete child.do_not_hide;
                    } else {
                        child.style.display = "none";
                    }
                }
            }
        };
        if (!hide_children.__argnames__) Object.defineProperties(hide_children, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "read_book.footnotes"}
        });

        function unhide_tree(elem) {
            var c;
            elem.do_not_hide = true;
            var ρσ_Iter2 = ρσ_Iterable(elem.getElementsByTagName("*"));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                c = ρσ_Iter2[ρσ_Index2];
                c.do_not_hide = true;
            }
        };
        if (!unhide_tree.__argnames__) Object.defineProperties(unhide_tree, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.footnotes"}
        });

        ok_list_types = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["disc"] = true;
            ρσ_d["circle"] = true;
            ρσ_d["square"] = true;
            return ρσ_d;
        }).call(this);
        function is_new_footnote_start(elem, start_elem) {
            var c;
            c = get_note_container(elem);
            return c !== start_elem && c !== start_elem.firstElementChild;
        };
        if (!is_new_footnote_start.__argnames__) Object.defineProperties(is_new_footnote_start, {
            __argnames__ : {value: ["elem", "start_elem"]},
            __module__ : {value: "read_book.footnotes"}
        });

        function show_footnote(target, known_anchors) {
            var start_elem, style, elem, found_note_start, eid, pb;
            if (!target) {
                return;
            }
            start_elem = document.getElementById(target);
            if (!start_elem) {
                return;
            }
            start_elem = get_note_container(start_elem);
            var ρσ_Iter3 = ρσ_Iterable(get_parents_and_self(start_elem));
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                elem = ρσ_Iter3[ρσ_Index3];
                elem.do_not_hide = true;
                style = window.getComputedStyle(elem);
                if (style.display === "list-item" && ok_list_types[ρσ_bound_index(style.listStyleType, ok_list_types)] !== true) {
                    elem.style.listStyleType = "none";
                }
            }
            if (is_epub_footnote(start_elem)) {
                unhide_tree(start_elem);
            } else {
                found_note_start = false;
                var ρσ_Iter4 = ρσ_Iterable(document.documentElement.getElementsByTagName("*"));
                for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                    elem = ρσ_Iter4[ρσ_Index4];
                    if (found_note_start) {
                        eid = elem.getAttribute("id");
                        if (eid !== target && known_anchors[(typeof eid === "number" && eid < 0) ? known_anchors.length + eid : eid] && is_new_footnote_start(elem, start_elem)) {
                            delete get_note_container(elem).do_not_hide;
                            break;
                        }
                        pb = get_page_break(elem);
                        if (pb.before) {
                            break;
                        }
                        if (pb.after) {
                            unhide_tree(elem);
                            break;
                        }
                        elem.do_not_hide = true;
                    } else if (elem === start_elem) {
                        found_note_start = true;
                    }
                }
            }
            hide_children(document.body);
            window.location.hash = "#" + target;
        };
        if (!show_footnote.__argnames__) Object.defineProperties(show_footnote, {
            __argnames__ : {value: ["target", "known_anchors"]},
            __module__ : {value: "read_book.footnotes"}
        });

        function PopupIframeBoss() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            PopupIframeBoss.prototype.__bind_methods__.call(this);
            PopupIframeBoss.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(PopupIframeBoss.prototype, "__bind_methods__", {value: function () {
            this.initialize = PopupIframeBoss.prototype.initialize.bind(this);
            this.on_keydown = PopupIframeBoss.prototype.on_keydown.bind(this);
            this.on_error = PopupIframeBoss.prototype.on_error.bind(this);
            this.display = PopupIframeBoss.prototype.display.bind(this);
            this.connect_links = PopupIframeBoss.prototype.connect_links.bind(this);
            this.link_activated = PopupIframeBoss.prototype.link_activated.bind(this);
            this.activate_link = PopupIframeBoss.prototype.activate_link.bind(this);
            this.on_clear = PopupIframeBoss.prototype.on_clear.bind(this);
            this.show_only_footnote = PopupIframeBoss.prototype.show_only_footnote.bind(this);
            this.content_loaded = PopupIframeBoss.prototype.content_loaded.bind(this);
        }});
        PopupIframeBoss.prototype.__init__ = function __init__() {
            var self = this;
            var handlers;
            handlers = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["initialize"] = self.initialize;
                ρσ_d["clear"] = self.on_clear;
                ρσ_d["display"] = self.display;
                return ρσ_d;
            }).call(this);
            self.comm = new IframeClient(handlers, "popup-iframe");
            self.blob_url_map = Object.create(null);
            self.name = null;
            self.frag = null;
            self.link_attr = null;
        };
        if (!PopupIframeBoss.prototype.__init__.__module__) Object.defineProperties(PopupIframeBoss.prototype.__init__, {
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.__argnames__ = PopupIframeBoss.prototype.__init__.__argnames__;
        PopupIframeBoss.__handles_kwarg_interpolation__ = PopupIframeBoss.prototype.__init__.__handles_kwarg_interpolation__;
        PopupIframeBoss.prototype.initialize = function initialize(data) {
            var self = this;
            window.addEventListener("error", self.on_error);
            window.addEventListener("keydown", self.on_keydown);
            document.addEventListener("contextmenu", (function() {
                var ρσ_anonfunc = function (ev) {
                    ev.preventDefault();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.footnotes"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!PopupIframeBoss.prototype.initialize.__argnames__) Object.defineProperties(PopupIframeBoss.prototype.initialize, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.prototype.on_keydown = function on_keydown(ev) {
            var self = this;
            if (ev.key === "Escape") {
                ρσ_interpolate_kwargs.call(self.comm, self.comm.send_message, ["close_requested"].concat([ρσ_desugar_kwargs({from_keypress: true})]));
            }
        };
        if (!PopupIframeBoss.prototype.on_keydown.__argnames__) Object.defineProperties(PopupIframeBoss.prototype.on_keydown, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.prototype.on_error = function on_error(evt) {
            var self = this;
            var msg, script_url, line_number, column_number, error_object;
            msg = evt.message;
            script_url = evt.filename;
            line_number = evt.lineno;
            column_number = evt.colno;
            error_object = evt.error;
            [evt.stopPropagation(), evt.preventDefault()];
            if (error_object === null) {
                console.log("Unhandled error from external javascript, ignoring: " + ρσ_str.format("{}", msg) + " " + ρσ_str.format("{}", script_url) + " " + ρσ_str.format("{}", line_number) + ":" + ρσ_str.format("{}", column_number) + "");
            } else {
                console.log(error_object);
            }
        };
        if (!PopupIframeBoss.prototype.on_error.__argnames__) Object.defineProperties(PopupIframeBoss.prototype.on_error, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.prototype.display = function display(data) {
            var self = this;
            var spine, index, name, ρσ_unpack, root_data;
            self.book = data.book;
            self.name = data.name;
            self.frag = data.frag;
            self.link_attr = "data-" + self.book.manifest.link_uid;
            spine = self.book.manifest.spine;
            index = spine.indexOf(data.name);
            set_current_spine_item((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["name"] = data.name;
                ρσ_d["is_first"] = index === 0;
                ρσ_d["is_last"] = index === spine.length - 1;
                ρσ_d["index"] = index;
                ρσ_d["initial_position"] = data.initial_position;
                return ρσ_d;
            }).call(this));
            update_settings(data.settings);
            var ρσ_Iter5 = ρσ_Iterable(self.blob_url_map);
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                name = ρσ_Iter5[ρσ_Index5];
                window.URL.revokeObjectURL((ρσ_expr_temp = self.blob_url_map)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]);
            }
            document.body.style.removeProperty("font-family");
            ρσ_unpack = finalize_resources(self.book, data.name, data.resource_data);
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
            root_data = ρσ_unpack[0];
            self.mathjax = ρσ_unpack[1];
            self.blob_url_map = ρσ_unpack[2];
            self.resource_urls = unserialize_html(root_data, self.content_loaded, self.show_only_footnote, data.name);
        };
        if (!PopupIframeBoss.prototype.display.__argnames__) Object.defineProperties(PopupIframeBoss.prototype.display, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.prototype.connect_links = function connect_links() {
            var self = this;
            var a;
            var ρσ_Iter6 = ρσ_Iterable(document.body.querySelectorAll("a[" + ρσ_str.format("{}", self.link_attr) + "]"));
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                a = ρσ_Iter6[ρσ_Index6];
                a.addEventListener("click", self.link_activated);
            }
            if (runtime.is_standalone_viewer) {
                var ρσ_Iter7 = ρσ_Iterable(document.body.querySelectorAll("a[target]"));
                for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                    a = ρσ_Iter7[ρσ_Index7];
                    a.removeAttribute("target");
                }
            }
        };
        if (!PopupIframeBoss.prototype.connect_links.__module__) Object.defineProperties(PopupIframeBoss.prototype.connect_links, {
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.prototype.link_activated = function link_activated(evt) {
            var self = this;
            var data;
            try {
                data = JSON.parse(evt.currentTarget.getAttribute(self.link_attr));
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    print("WARNING: Failed to parse link data {}, ignoring".format(ρσ_exists.c(ρσ_exists.d(evt.currentTarget).getAttribute)(self.link_attr)));
                    return;
                } 
            }
            self.activate_link(data.name, data.frag, evt.currentTarget);
        };
        if (!PopupIframeBoss.prototype.link_activated.__argnames__) Object.defineProperties(PopupIframeBoss.prototype.link_activated, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.prototype.activate_link = function activate_link(name, frag, target_elem) {
            var self = this;
            var is_popup, title;
            if (!name) {
                name = current_spine_item().name;
            }
            try {
                is_popup = is_footnote_link(target_elem, name, frag, current_spine_item().name, self.book.manifest.link_to_map || Object.create(null));
                title = target_elem.textContent;
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    var traceback = ρσ_modules.traceback;

                    traceback.print_exc();
                    is_popup = false;
                    title = "";
                } 
            }
            ρσ_interpolate_kwargs.call(self.comm, self.comm.send_message, ["link_activated"].concat([ρσ_desugar_kwargs({is_popup: is_popup, name: name, frag: frag, title: title})]));
        };
        if (!PopupIframeBoss.prototype.activate_link.__argnames__) Object.defineProperties(PopupIframeBoss.prototype.activate_link, {
            __argnames__ : {value: ["name", "frag", "target_elem"]},
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.prototype.on_clear = function on_clear(data) {
            var self = this;
            clear(document.head);
            clear(document.body);
            document.body.textContent = data.text;
            self.name = null;
            self.frag = null;
        };
        if (!PopupIframeBoss.prototype.on_clear.__argnames__) Object.defineProperties(PopupIframeBoss.prototype.on_clear, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.prototype.show_only_footnote = function show_only_footnote() {
            var self = this;
            var known_anchors, ltm, k;
            known_anchors = Object.create(null);
            ltm = (ρσ_expr_temp = ρσ_exists.d(self.book.manifest.link_to_map))[ρσ_bound_index(self.name, ρσ_expr_temp)];
            if (ltm) {
                known_anchors = (function() {
                    var ρσ_Iter = ρσ_Iterable(Object.keys(ltm)), ρσ_Result = Object.create(null), k;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        k = ρσ_Iter[ρσ_Index];
                        ρσ_Result[k] = (true);
                    }
                    return ρσ_Result;
                })();
            }
            show_footnote(self.frag, known_anchors);
        };
        if (!PopupIframeBoss.prototype.show_only_footnote.__module__) Object.defineProperties(PopupIframeBoss.prototype.show_only_footnote, {
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.prototype.content_loaded = function content_loaded() {
            var self = this;
            if (!self.comm.encrypted_communications) {
                window.setTimeout(self.content_loaded, 2);
                return;
            }
            self.connect_links();
            document.head.removeChild(document.head.firstChild);
            document.body.classList.add("calibre-footnote-container");
            set_color_scheme_class();
            apply_settings(true);
            ρσ_interpolate_kwargs.call(self.comm, self.comm.send_message, ["content_loaded"].concat([ρσ_desugar_kwargs({height: document.documentElement.scrollHeight + 25})]));
        };
        if (!PopupIframeBoss.prototype.content_loaded.__module__) Object.defineProperties(PopupIframeBoss.prototype.content_loaded, {
            __module__ : {value: "read_book.footnotes"}
        });
        PopupIframeBoss.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        PopupIframeBoss.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(PopupIframeBoss.prototype, "__bases__", {value: []});

        function main() {
            main.boss = new PopupIframeBoss;
        };
        if (!main.__module__) Object.defineProperties(main, {
            __module__ : {value: "read_book.footnotes"}
        });

        ρσ_modules["read_book.footnotes"].block_names = block_names;
        ρσ_modules["read_book.footnotes"].block_display_styles = block_display_styles;
        ρσ_modules["read_book.footnotes"].ok_list_types = ok_list_types;
        ρσ_modules["read_book.footnotes"].elem_roles = elem_roles;
        ρσ_modules["read_book.footnotes"].epub_type = epub_type;
        ρσ_modules["read_book.footnotes"].get_containing_block = get_containing_block;
        ρσ_modules["read_book.footnotes"].is_footnote_link = is_footnote_link;
        ρσ_modules["read_book.footnotes"].is_epub_footnote = is_epub_footnote;
        ρσ_modules["read_book.footnotes"].get_note_container = get_note_container;
        ρσ_modules["read_book.footnotes"].get_parents_and_self = get_parents_and_self;
        ρσ_modules["read_book.footnotes"].get_page_break = get_page_break;
        ρσ_modules["read_book.footnotes"].hide_children = hide_children;
        ρσ_modules["read_book.footnotes"].unhide_tree = unhide_tree;
        ρσ_modules["read_book.footnotes"].is_new_footnote_start = is_new_footnote_start;
        ρσ_modules["read_book.footnotes"].show_footnote = show_footnote;
        ρσ_modules["read_book.footnotes"].PopupIframeBoss = PopupIframeBoss;
        ρσ_modules["read_book.footnotes"].main = main;
    })();

    (function(){
        var __name__ = "select";
        var caret_position_from_point, safe_nodes;
        if ((typeof document !== "undefined" && document !== null ? document : Object.create(null)).caretPositionFromPoint) {
            caret_position_from_point = document.caretPositionFromPoint.bind(document);
        } else {
            caret_position_from_point = (function() {
                var ρσ_anonfunc = function (x, y) {
                    var r;
                    r = document.caretRangeFromPoint(x, y);
                    if (r) {
                        return (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["offsetNode"] = r.startContainer;
                            ρσ_d["offset"] = r.startOffset;
                            return ρσ_d;
                        }).call(this);
                    }
                    return null;
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["x", "y"]},
                    __module__ : {value: "select"}
                });
                return ρσ_anonfunc;
            })();
        }
        function word_boundary_regex() {
            var ans;
            ans = word_boundary_regex.ans;
            if (ans === undefined) {
                ans = word_boundary_regex.ans = /[\s!-#%-\x2A,-/:;\x3F@\x5B-\x5D_\x7B}\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E3B\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/;
            }
            return ans;
        };
        if (!word_boundary_regex.__module__) Object.defineProperties(word_boundary_regex, {
            __module__ : {value: "select"}
        });

        function expand_offset_to_word(string, offset) {
            var start, pat, ρσ_unpack, end, sz;
            start = offset;
            pat = word_boundary_regex();
            while (start >= 1 && !pat.test(string.charAt(start - 1))) {
                start -= 1;
            }
            ρσ_unpack = [offset, string.length];
            end = ρσ_unpack[0];
            sz = ρσ_unpack[1];
            while (end < sz && !pat.test(string.charAt(end))) {
                end += 1;
            }
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["word"] = string.slice(start, end);
                ρσ_d["start"] = start;
                ρσ_d["end"] = end;
                return ρσ_d;
            }).call(this);
        };
        if (!expand_offset_to_word.__argnames__) Object.defineProperties(expand_offset_to_word, {
            __argnames__ : {value: ["string", "offset"]},
            __module__ : {value: "select"}
        });

        function word_at_point(x, y) {
            var p, word_info, r;
            p = caret_position_from_point(x, y);
            if (p && ρσ_exists.d(p.offsetNode).nodeType === Node.TEXT_NODE) {
                word_info = expand_offset_to_word(p.offsetNode.data, p.offset);
                if (word_info.word) {
                    r = document.createRange();
                    r.setStart(p.offsetNode, word_info.start);
                    r.setEnd(p.offsetNode, word_info.end);
                    return r;
                }
            }
        };
        if (!word_at_point.__argnames__) Object.defineProperties(word_at_point, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "select"}
        });

        function first_visible_word() {
            var width, height, xdelta, ydelta, r, x, y;
            width = window.innerWidth;
            height = window.innerHeight;
            xdelta = Math.floor(width / 10);
            ydelta = Math.floor(height / 10);
            var ρσ_Iter0 = ρσ_Iterable(range(0, height, ydelta));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                y = ρσ_Iter0[ρσ_Index0];
                var ρσ_Iter1 = ρσ_Iterable(range(0, width, xdelta));
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    x = ρσ_Iter1[ρσ_Index1];
                    r = word_at_point(x, y);
                    if ((typeof r !== "undefined" && r !== null)) {
                        return r;
                    }
                }
            }
        };
        if (!first_visible_word.__module__) Object.defineProperties(first_visible_word, {
            __module__ : {value: "select"}
        });

        function empty_range_extents() {
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["start"] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["x"] = 0;
                    ρσ_d["y"] = 0;
                    ρσ_d["height"] = 0;
                    ρσ_d["width"] = 0;
                    ρσ_d["onscreen"] = false;
                    ρσ_d["selected_prev"] = false;
                    return ρσ_d;
                }).call(this);
                ρσ_d["end"] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["x"] = 0;
                    ρσ_d["y"] = 0;
                    ρσ_d["height"] = 0;
                    ρσ_d["width"] = 0;
                    ρσ_d["onscreen"] = false;
                    ρσ_d["selected_prev"] = false;
                    return ρσ_d;
                }).call(this);
                return ρσ_d;
            }).call(this);
        };
        if (!empty_range_extents.__module__) Object.defineProperties(empty_range_extents, {
            __module__ : {value: "select"}
        });

        safe_nodes = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["img"] = true;
            ρσ_d["br"] = true;
            ρσ_d["hr"] = true;
            return ρσ_d;
        }).call(this);
        function get_selection_node_at_boundary(node, start) {
            var stack, top, name, c;
            stack = [];
            stack.push((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["node"] = node;
                ρσ_d["visited"] = false;
                return ρσ_d;
            }).call(this));
            while (stack.length > 0) {
                top = stack[stack.length-1];
                name = (top.node.nodeName) ? top.node.nodeName.toLowerCase() : "";
                if (top.node.nodeType === Node.TEXT_NODE || safe_nodes[(typeof name === "number" && name < 0) ? safe_nodes.length + name : name]) {
                    return top.node;
                } else if (top.visited) {
                    stack.pop();
                } else {
                    top.visited = true;
                    if (top.node.childNodes) {
                        var ρσ_Iter2 = ρσ_Iterable((start) ? top.node.childNodes : reversed(top.node.childNodes));
                        for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                            c = ρσ_Iter2[ρσ_Index2];
                            stack.push((function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["node"] = c;
                                ρσ_d["visited"] = false;
                                return ρσ_d;
                            }).call(this));
                        }
                    }
                }
            }
        };
        if (!get_selection_node_at_boundary.__argnames__) Object.defineProperties(get_selection_node_at_boundary, {
            __argnames__ : {value: ["node", "start"]},
            __module__ : {value: "select"}
        });

        function range_extents(q, in_flow_mode) {
            var ans, start, end, rect;
            ans = empty_range_extents();
            if (!q) {
                return ans;
            }
            start = q.cloneRange();
            end = q.cloneRange();
            function rect_onscreen(r) {
                if (r.right <= window.innerWidth && r.bottom <= window.innerHeight && r.left >= 0 && r.top >= -1) {
                    return true;
                }
                return false;
            };
            if (!rect_onscreen.__argnames__) Object.defineProperties(rect_onscreen, {
                __argnames__ : {value: ["r"]},
                __module__ : {value: "select"}
            });

            function apply_rect_to_ans(rect, ans) {
                ans.x = Math.round(rect.left);
                ans.y = Math.round(rect.top);
                ans.height = Math.round(rect.height);
                ans.width = Math.round(rect.width);
                ans.onscreen = rect_onscreen(rect);
                return ans;
            };
            if (!apply_rect_to_ans.__argnames__) Object.defineProperties(apply_rect_to_ans, {
                __argnames__ : {value: ["rect", "ans"]},
                __module__ : {value: "select"}
            });

            function for_boundary(r, ans, is_start) {
                var rect, node, boundary_node, rects, erect;
                rect = r.getBoundingClientRect();
                if (rect.height === 0 && rect.width === 0) {
                    if (ρσ_exists.d(r.startContainer).nodeType === Node.ELEMENT_NODE) {
                        node = r.startContainer;
                        if (r.startOffset && node.childNodes.length > r.startOffset) {
                            node = (ρσ_expr_temp = node.childNodes)[ρσ_bound_index(r.startOffset, ρσ_expr_temp)];
                        }
                        boundary_node = get_selection_node_at_boundary(node, is_start);
                        if (boundary_node) {
                            if (boundary_node.nodeType === Node.TEXT_NODE) {
                                if (is_start) {
                                    r.setStart(boundary_node, 0);
                                    r.setEnd(boundary_node, 0);
                                } else {
                                    r.setStart(boundary_node, boundary_node.length);
                                    r.setEnd(boundary_node, boundary_node.length);
                                }
                                rect = r.getBoundingClientRect();
                            } else {
                                rect = boundary_node.getBoundingClientRect();
                                if (!is_start) {
                                    ans.selected_prev = true;
                                }
                            }
                        } else if (node.getClientRects) {
                            rects = node.getClientRects();
                            if (rects.length) {
                                erect = rects[0];
                                rect = (function(){
                                    var ρσ_d = Object.create(null);
                                    ρσ_d["left"] = erect.left;
                                    ρσ_d["top"] = erect.top;
                                    ρσ_d["right"] = erect.left + 2;
                                    ρσ_d["bottom"] = erect.top + 2;
                                    ρσ_d["width"] = 2;
                                    ρσ_d["height"] = 2;
                                    return ρσ_d;
                                }).call(this);
                            }
                        }
                    }
                }
                apply_rect_to_ans(rect, ans);
            };
            if (!for_boundary.__argnames__) Object.defineProperties(for_boundary, {
                __argnames__ : {value: ["r", "ans", "is_start"]},
                __module__ : {value: "select"}
            });

            if (q.startContainer.nodeType === Node.ELEMENT_NODE) {
                start.collapse(true);
                for_boundary(start, ans.start, true);
            } else if (q.startOffset === 0 && q.startContainer.length === 0) {
                start.collapse(true);
                for_boundary(start, ans.start, true);
            } else if (q.startOffset === q.startContainer.length) {
                start.setStart(q.startContainer, q.startOffset - 1);
                start.setEnd(q.startContainer, q.startOffset);
                rect = start.getBoundingClientRect();
                apply_rect_to_ans(rect, ans.start).selected_prev = true;
            } else {
                start.setStart(q.startContainer, q.startOffset);
                start.setEnd(q.startContainer, q.startOffset + 1);
                rect = start.getBoundingClientRect();
                apply_rect_to_ans(rect, ans.start);
            }
            if (q.endContainer.nodeType === Node.ELEMENT_NODE) {
                end.collapse(false);
                for_boundary(end, ans.end, false);
            } else if (q.endOffset === 0 && q.endContainer.length === 0) {
                end.collapse(false);
                for_boundary(end, ans.end, false);
            } else if (q.endOffset === q.endContainer.length) {
                end.setStart(q.endContainer, q.endOffset - 1);
                end.setEnd(q.endContainer, q.endOffset);
                rect = end.getBoundingClientRect();
                apply_rect_to_ans(rect, ans.end).selected_prev = true;
            } else {
                end.setStart(q.endContainer, q.endOffset);
                end.setEnd(q.endContainer, q.endOffset + 1);
                rect = end.getBoundingClientRect();
                apply_rect_to_ans(rect, ans.end);
            }
            if (ans.end.height === 2 && ans.start.height > 2) {
                ans.end.height = ans.start.height;
            }
            if (ans.start.height === 2 && ans.end.height > 2) {
                ans.start.height = ans.end.height;
            }
            return ans;
        };
        if (!range_extents.__argnames__) Object.defineProperties(range_extents, {
            __argnames__ : {value: ["q", "in_flow_mode"]},
            __module__ : {value: "select"}
        });

        function selection_extents(in_flow_mode) {
            var sel;
            sel = window.getSelection();
            if (!sel || !sel.rangeCount || sel.isCollapsed) {
                return empty_range_extents();
            }
            return range_extents(sel.getRangeAt(0), in_flow_mode);
        };
        if (!selection_extents.__argnames__) Object.defineProperties(selection_extents, {
            __argnames__ : {value: ["in_flow_mode"]},
            __module__ : {value: "select"}
        });

        function is_start_closer_to_point(pos) {
            var sel, p, r, sr, er;
            sel = window.getSelection();
            if (!sel.rangeCount) {
                return;
            }
            p = caret_position_from_point(pos.x, pos.y);
            if (p) {
                r = sel.getRangeAt(0);
                sr = document.createRange();
                sr.setStart(r.startContainer, r.startOffset);
                sr.setEnd(p.offsetNode, p.offset);
                er = document.createRange();
                er.setStart(p.offsetNode, p.offset);
                er.setEnd(r.endContainer, r.endOffset);
                return sr.toString().length < er.toString().length;
            }
            return false;
        };
        if (!is_start_closer_to_point.__argnames__) Object.defineProperties(is_start_closer_to_point, {
            __argnames__ : {value: ["pos"]},
            __module__ : {value: "select"}
        });

        function move_end_of_selection(pos, start) {
            var sel, p, r, q, new_range, other_boundary_changed;
            sel = window.getSelection();
            if (!sel.rangeCount) {
                return;
            }
            p = caret_position_from_point(pos.x, pos.y);
            if (!p) {
                return;
            }
            r = sel.getRangeAt(0);
            if (start === null) {
                q = document.createRange();
                q.setStart(p.offsetNode, p.offset);
                q.setEnd(p.offsetNode, p.offset);
                if (r.compareBoundaryPoints(window.Range.START_TO_START, q) >= 0) {
                    start = true;
                } else if (r.compareBoundaryPoints(window.Range.END_TO_END, q) <= 0) {
                    start = false;
                } else {
                    start = false;
                }
            }
            new_range = document.createRange();
            if (start) {
                new_range.setStart(p.offsetNode, p.offset);
                new_range.setEnd(r.endContainer, r.endOffset);
                other_boundary_changed = r.endContainer !== new_range.endContainer || r.endOffset !== new_range.endOffset;
            } else {
                new_range.setStart(r.startContainer, r.startOffset);
                new_range.setEnd(p.offsetNode, p.offset);
                other_boundary_changed = r.startContainer !== new_range.startContainer || r.startOffset !== new_range.startOffset;
            }
            if (new_range.collapsed && other_boundary_changed) {
                return;
            }
            sel.removeAllRanges();
            sel.addRange(new_range);
        };
        if (!move_end_of_selection.__argnames__) Object.defineProperties(move_end_of_selection, {
            __argnames__ : {value: ["pos", "start"]},
            __module__ : {value: "select"}
        });

        ρσ_modules.select.caret_position_from_point = caret_position_from_point;
        ρσ_modules.select.safe_nodes = safe_nodes;
        ρσ_modules.select.word_boundary_regex = word_boundary_regex;
        ρσ_modules.select.expand_offset_to_word = expand_offset_to_word;
        ρσ_modules.select.word_at_point = word_at_point;
        ρσ_modules.select.first_visible_word = first_visible_word;
        ρσ_modules.select.empty_range_extents = empty_range_extents;
        ρσ_modules.select.get_selection_node_at_boundary = get_selection_node_at_boundary;
        ρσ_modules.select.range_extents = range_extents;
        ρσ_modules.select.selection_extents = selection_extents;
        ρσ_modules.select.is_start_closer_to_point = is_start_closer_to_point;
        ρσ_modules.select.move_end_of_selection = move_end_of_selection;
    })();

    (function(){
        var __name__ = "fs_images";
        function is_svg_fs_markup(names, svg) {
            if (svg !== null) {
                if (names.length === 2 || names.length === 3) {
                    if (names[names.length-1] === "image" && names[names.length-2] === "svg") {
                        if (names.length === 2 || names[0] === "div") {
                            if (svg.width === "100%" && svg.height === "100%") {
                                return true;
                            }
                        }
                    }
                }
            }
            return false;
        };
        if (!is_svg_fs_markup.__argnames__) Object.defineProperties(is_svg_fs_markup, {
            __argnames__ : {value: ["names", "svg"]},
            __module__ : {value: "fs_images"}
        });

        function fix_fullscreen_svg_images() {
            var child_names, name, node, names, svg;
            child_names = [];
            var ρσ_Iter0 = ρσ_Iterable(document.body.childNodes);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                node = ρσ_Iter0[ρσ_Index0];
                if (node.tagName) {
                    name = node.tagName.toLowerCase();
                    if (name !== "style" && name !== "script") {
                        child_names.push(name);
                    }
                    if (child_names.length > 1) {
                        break;
                    }
                }
            }
            if (child_names.length === 1 && (child_names[0] === "div" || child_names[0] === "svg")) {
                names = [];
                svg = null;
                var ρσ_Iter1 = ρσ_Iterable(document.body.querySelectorAll("*"));
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    node = ρσ_Iter1[ρσ_Index1];
                    if (node.tagName) {
                        name = node.tagName.toLowerCase();
                        if (name !== "style" && name !== "script") {
                            names.push(name);
                            if (name === "svg") {
                                svg = node;
                            }
                        }
                    }
                }
                if (is_svg_fs_markup(names, svg)) {
                    svg.setAttribute("width", "100vw");
                    svg.setAttribute("height", "100vh");
                }
            }
        };
        if (!fix_fullscreen_svg_images.__module__) Object.defineProperties(fix_fullscreen_svg_images, {
            __module__ : {value: "fs_images"}
        });

        ρσ_modules.fs_images.is_svg_fs_markup = is_svg_fs_markup;
        ρσ_modules.fs_images.fix_fullscreen_svg_images = fix_fullscreen_svg_images;
    })();

    (function(){
        var __name__ = "range_utils";
        var wrapper_counter;
        function is_non_empty_text_node(node) {
            return (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.CDATA_SECTION_NODE) && node.nodeValue.length > 0;
        };
        if (!is_non_empty_text_node.__argnames__) Object.defineProperties(is_non_empty_text_node, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "range_utils"}
        });

        function is_element_visible(elem) {
            var s;
            s = window.getComputedStyle(elem);
            return s.display !== "none" && s.visibility !== "hidden";
        };
        if (!is_element_visible.__argnames__) Object.defineProperties(is_element_visible, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "range_utils"}
        });

        function is_node_visible(node) {
            var current;
            if (node.nodeType !== Node.ELEMENT_NODE) {
                node = node.parentElement;
                if (!node) {
                    return false;
                }
            }
            current = node;
            while (current) {
                if (!is_element_visible(current)) {
                    return false;
                }
                current = current.parentElement;
            }
            return true;
        };
        if (!is_node_visible.__argnames__) Object.defineProperties(is_node_visible, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "range_utils"}
        });

        function select_nodes_from_range(r, predicate) {
            var parent, doc, iterator, in_range, ans, check_for_end, node;
            parent = r.commonAncestorContainer;
            doc = parent.ownerDocument || document;
            iterator = doc.createNodeIterator(parent);
            in_range = false;
            ans = [];
            check_for_end = !((r.startContainer.isSameNode(r.endContainer) && r.startContainer.isSameNode(parent)));
            while (true) {
                node = iterator.nextNode();
                if (!node) {
                    break;
                }
                if (!in_range && node.isSameNode(r.startContainer)) {
                    in_range = true;
                }
                if (in_range) {
                    if (predicate(node)) {
                        ans.push(node);
                    }
                    if (check_for_end && node.isSameNode(r.endContainer)) {
                        break;
                    }
                }
            }
            return ans;
        };
        if (!select_nodes_from_range.__argnames__) Object.defineProperties(select_nodes_from_range, {
            __argnames__ : {value: ["r", "predicate"]},
            __module__ : {value: "range_utils"}
        });

        function select_first_node_from_range(r, predicate) {
            var parent, doc, iterator, in_range, check_for_end, node;
            parent = r.commonAncestorContainer;
            doc = parent.ownerDocument || document;
            iterator = doc.createNodeIterator(parent);
            in_range = false;
            check_for_end = !((r.startContainer.isSameNode(r.endContainer) && r.startContainer.isSameNode(parent)));
            while (true) {
                node = iterator.nextNode();
                if (!node) {
                    break;
                }
                if (!in_range && node.isSameNode(r.startContainer)) {
                    in_range = true;
                }
                if (in_range) {
                    if (predicate(node)) {
                        return node;
                    }
                    if (check_for_end && node.isSameNode(r.endContainer)) {
                        break;
                    }
                }
            }
        };
        if (!select_first_node_from_range.__argnames__) Object.defineProperties(select_first_node_from_range, {
            __argnames__ : {value: ["r", "predicate"]},
            __module__ : {value: "range_utils"}
        });

        function text_nodes_in_range(r) {
            return select_nodes_from_range(r, is_non_empty_text_node);
        };
        if (!text_nodes_in_range.__argnames__) Object.defineProperties(text_nodes_in_range, {
            __argnames__ : {value: ["r"]},
            __module__ : {value: "range_utils"}
        });

        function all_annots_in_range(r, annot_id_uuid_map, ans) {
            var parent, doc, iterator, is_full_tree, in_range, check_for_end, node, annot_id;
            parent = r.commonAncestorContainer;
            doc = parent.ownerDocument || document;
            iterator = doc.createNodeIterator(parent);
            is_full_tree = parent === doc.documentElement;
            in_range = is_full_tree;
            check_for_end = !is_full_tree && !((r.startContainer.isSameNode(r.endContainer) && r.startContainer.isSameNode(parent)));
            while (true) {
                node = iterator.nextNode();
                if (!node) {
                    break;
                }
                if (!in_range && node.isSameNode(r.startContainer)) {
                    in_range = true;
                }
                if (in_range) {
                    if (node.dataset && node.dataset.calibreRangeWrapper) {
                        annot_id = annot_id_uuid_map[ρσ_bound_index(node.dataset.calibreRangeWrapper, annot_id_uuid_map)];
                        if (annot_id) {
                            if (!ans) {
                                return annot_id;
                            }
                            ans[(typeof annot_id === "number" && annot_id < 0) ? ans.length + annot_id : annot_id] = true;
                        }
                    }
                    if (check_for_end && node.isSameNode(r.endContainer)) {
                        break;
                    }
                }
            }
            return ans;
        };
        if (!all_annots_in_range.__argnames__) Object.defineProperties(all_annots_in_range, {
            __argnames__ : {value: ["r", "annot_id_uuid_map", "ans"]},
            __module__ : {value: "range_utils"}
        });

        function first_annot_in_range(r, annot_id_uuid_map) {
            return all_annots_in_range(r, annot_id_uuid_map);
        };
        if (!first_annot_in_range.__argnames__) Object.defineProperties(first_annot_in_range, {
            __argnames__ : {value: ["r", "annot_id_uuid_map"]},
            __module__ : {value: "range_utils"}
        });

        function all_annots_in_selection(sel, annot_id_uuid_map) {
            var ans, i;
            ans = {};
            for (var ρσ_Index0 = 0; ρσ_Index0 < sel.rangeCount; ρσ_Index0++) {
                i = ρσ_Index0;
                all_annots_in_range(sel.getRangeAt(i), annot_id_uuid_map, ans);
            }
            return Object.keys(ans);
        };
        if (!all_annots_in_selection.__argnames__) Object.defineProperties(all_annots_in_selection, {
            __argnames__ : {value: ["sel", "annot_id_uuid_map"]},
            __module__ : {value: "range_utils"}
        });

        function remove(node) {
            if (node.parentNode) {
                node.parentNode.removeChild(node);
            }
        };
        if (!remove.__argnames__) Object.defineProperties(remove, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "range_utils"}
        });

        function replace_node(replacement, node) {
            var p;
            p = node.parentNode;
            p.insertBefore(replacement, node);
            remove(node);
            return p;
        };
        if (!replace_node.__argnames__) Object.defineProperties(replace_node, {
            __argnames__ : {value: ["replacement", "node"]},
            __module__ : {value: "range_utils"}
        });

        function unwrap(node) {
            var r, p;
            r = (node.ownerDocument || document).createRange();
            r.selectNodeContents(node);
            p = replace_node(r.extractContents(), node);
            if (p) {
                p.normalize();
            }
        };
        if (!unwrap.__argnames__) Object.defineProperties(unwrap, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "range_utils"}
        });

        function unwrap_crw(crw) {
            var node;
            var ρσ_Iter1 = ρσ_Iterable(document.querySelectorAll("span[data-calibre-range-wrapper=\"" + ρσ_str.format("{}", crw) + "\"]"));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                node = ρσ_Iter1[ρσ_Index1];
                unwrap(node);
            }
        };
        if (!unwrap_crw.__argnames__) Object.defineProperties(unwrap_crw, {
            __argnames__ : {value: ["crw"]},
            __module__ : {value: "range_utils"}
        });

        function unwrap_all_crw() {
            var node;
            var ρσ_Iter2 = ρσ_Iterable(document.querySelectorAll("span[data-calibre-range-wrapper]"));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                node = ρσ_Iter2[ρσ_Index2];
                unwrap(node);
            }
        };
        if (!unwrap_all_crw.__module__) Object.defineProperties(unwrap_all_crw, {
            __module__ : {value: "range_utils"}
        });

        function select_crw(crw) {
            var nodes, r, sel;
            nodes = document.querySelectorAll("span[data-calibre-range-wrapper=\"" + ρσ_str.format("{}", crw) + "\"]");
            if (nodes && nodes.length) {
                r = document.createRange();
                r.setStart(nodes[0].firstChild, 0);
                r.setEnd(nodes[nodes.length-1].lastChild, nodes[nodes.length-1].lastChild.nodeValue.length);
                sel = window.getSelection();
                sel.removeAllRanges();
                sel.addRange(r);
                return true;
            }
            print("range-wrapper: " + ρσ_str.format("{}", crw) + " does not exist");
            return false;
        };
        if (!select_crw.__argnames__) Object.defineProperties(select_crw, {
            __argnames__ : {value: ["crw"]},
            __module__ : {value: "range_utils"}
        });

        function wrap_range(r, wrapper) {
            try {
                r.surroundContents(wrapper);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    wrapper.appendChild(r.extractContents());
                    r.insertNode(wrapper);
                } 
            }
        };
        if (!wrap_range.__argnames__) Object.defineProperties(wrap_range, {
            __argnames__ : {value: ["r", "wrapper"]},
            __module__ : {value: "range_utils"}
        });

        function create_wrapper_function(wrapper_elem, r, intersecting_wrappers, process_wrapper, all_wrappers) {
            var start_node, end_node, start_offset, end_offset;
            start_node = r.startContainer;
            end_node = r.endContainer;
            start_offset = r.startOffset;
            end_offset = r.endOffset;
            function wrap_node(node) {
                var current_range, current_wrapper, crw;
                current_range = (node.ownerDocument || document).createRange();
                current_wrapper = wrapper_elem.cloneNode();
                current_range.selectNodeContents(node);
                if (node.isSameNode(start_node)) {
                    current_range.setStart(node, start_offset);
                    start_node = current_wrapper;
                    start_offset = 0;
                }
                if (node.isSameNode(end_node)) {
                    current_range.setEnd(node, end_offset);
                    end_node = current_wrapper;
                    end_offset = 1;
                }
                if (current_range.collapsed) {
                    return;
                }
                crw = ρσ_exists.d(ρσ_exists.d(node.parentNode).dataset).calibreRangeWrapper;
                if (crw) {
                    intersecting_wrappers[(typeof crw === "number" && crw < 0) ? intersecting_wrappers.length + crw : crw] = true;
                }
                wrap_range(current_range, current_wrapper);
                if (process_wrapper) {
                    process_wrapper(current_wrapper);
                }
                all_wrappers.push(current_wrapper);
            };
            if (!wrap_node.__argnames__) Object.defineProperties(wrap_node, {
                __argnames__ : {value: ["node"]},
                __module__ : {value: "range_utils"}
            });

            return wrap_node;
        };
        if (!create_wrapper_function.__argnames__) Object.defineProperties(create_wrapper_function, {
            __argnames__ : {value: ["wrapper_elem", "r", "intersecting_wrappers", "process_wrapper", "all_wrappers"]},
            __module__ : {value: "range_utils"}
        });

        wrapper_counter = 0;
        function wrap_text_in_range(styler, r, class_to_add_to_last, process_wrapper) {
            var sel, wrapper_elem, intersecting_wrappers, all_wrappers, wrap_node, ancestor, crw;
            if (!r) {
                sel = window.getSelection();
                if (!sel || !sel.rangeCount) {
                    return [null, []];
                }
                r = sel.getRangeAt(0);
            }
            if (r.isCollapsed) {
                return [null, []];
            }
            wrapper_elem = document.createElement("span");
            wrapper_elem.dataset.calibreRangeWrapper = ++wrapper_counter + "";
            if (styler) {
                styler(wrapper_elem);
            }
            intersecting_wrappers = Object.create(null);
            all_wrappers = [];
            wrap_node = create_wrapper_function(wrapper_elem, r, intersecting_wrappers, process_wrapper, all_wrappers);
            text_nodes_in_range(r).map(wrap_node);
            ancestor = r.commonAncestorContainer;
            if (ancestor.nodeType === Node.TEXT_NODE) {
                ancestor = ancestor.parentNode;
            }
            ancestor.normalize();
            crw = wrapper_elem.dataset.calibreRangeWrapper;
            delete intersecting_wrappers[crw];
            if (class_to_add_to_last && all_wrappers.length) {
                all_wrappers[all_wrappers.length-1].classList.add(class_to_add_to_last);
            }
            return [crw, Object.keys(intersecting_wrappers)];
        };
        if (!wrap_text_in_range.__argnames__) Object.defineProperties(wrap_text_in_range, {
            __argnames__ : {value: ["styler", "r", "class_to_add_to_last", "process_wrapper"]},
            __module__ : {value: "range_utils"}
        });

        function last_span_for_crw(crw) {
            var nodes;
            nodes = document.querySelectorAll("span[data-calibre-range-wrapper=\"" + ρσ_str.format("{}", crw) + "\"]");
            if (nodes && nodes.length) {
                return nodes[nodes.length-1];
            }
        };
        if (!last_span_for_crw.__argnames__) Object.defineProperties(last_span_for_crw, {
            __argnames__ : {value: ["crw"]},
            __module__ : {value: "range_utils"}
        });

        function reset_highlight_counter() {
            wrapper_counter = 0;
        };
        if (!reset_highlight_counter.__module__) Object.defineProperties(reset_highlight_counter, {
            __module__ : {value: "range_utils"}
        });

        function get_annot_id_for(node, offset, annot_id_uuid_map) {
            if (!node) {
                return;
            }
            if (node.nodeType === Node.ELEMENT_NODE) {
                if (ρσ_exists.d(node.dataset).calibreRangeWrapper) {
                    return annot_id_uuid_map[ρσ_bound_index(node.dataset.calibreRangeWrapper, annot_id_uuid_map)];
                }
                if (offset === 0) {
                    if (ρσ_exists.d(node.firstChild).nodeType === Node.ELEMENT_NODE && ρσ_exists.d(node.firstChild.dataset).calibreRangeWrapper) {
                        return annot_id_uuid_map[ρσ_bound_index(node.firstChild.dataset.calibreRangeWrapper, annot_id_uuid_map)];
                    }
                } else if (offset < node.childNodes.length) {
                    node = (ρσ_expr_temp = node.childNodes)[(typeof offset === "number" && offset < 0) ? ρσ_expr_temp.length + offset : offset];
                    return get_annot_id_for(node, 0, annot_id_uuid_map);
                }
            } else if (node.nodeType === Node.TEXT_NODE) {
                if (ρσ_exists.d(node.parentNode).nodeType === Node.ELEMENT_NODE && ρσ_exists.d(node.parentNode.dataset).calibreRangeWrapper) {
                    return annot_id_uuid_map[ρσ_bound_index(node.parentNode.dataset.calibreRangeWrapper, annot_id_uuid_map)];
                }
            }
        };
        if (!get_annot_id_for.__argnames__) Object.defineProperties(get_annot_id_for, {
            __argnames__ : {value: ["node", "offset", "annot_id_uuid_map"]},
            __module__ : {value: "range_utils"}
        });

        function highlight_associated_with_selection(sel, annot_id_uuid_map) {
            var annot_id, r;
            if (sel.rangeCount) {
                annot_id = get_annot_id_for(sel.focusNode, sel.focusOffset, annot_id_uuid_map) || get_annot_id_for(sel.anchorNode, sel.anchorOffset, annot_id_uuid_map);
                if (annot_id) {
                    return annot_id;
                }
                for (var i = 0; i < sel.rangeCount; i++) {
                    r = sel.getRangeAt(i);
                    annot_id = first_annot_in_range(r, annot_id_uuid_map);
                    if (annot_id) {
                        return annot_id;
                    }
                }
            }
        };
        if (!highlight_associated_with_selection.__argnames__) Object.defineProperties(highlight_associated_with_selection, {
            __argnames__ : {value: ["sel", "annot_id_uuid_map"]},
            __module__ : {value: "range_utils"}
        });

        ρσ_modules.range_utils.wrapper_counter = wrapper_counter;
        ρσ_modules.range_utils.is_non_empty_text_node = is_non_empty_text_node;
        ρσ_modules.range_utils.is_element_visible = is_element_visible;
        ρσ_modules.range_utils.is_node_visible = is_node_visible;
        ρσ_modules.range_utils.select_nodes_from_range = select_nodes_from_range;
        ρσ_modules.range_utils.select_first_node_from_range = select_first_node_from_range;
        ρσ_modules.range_utils.text_nodes_in_range = text_nodes_in_range;
        ρσ_modules.range_utils.all_annots_in_range = all_annots_in_range;
        ρσ_modules.range_utils.first_annot_in_range = first_annot_in_range;
        ρσ_modules.range_utils.all_annots_in_selection = all_annots_in_selection;
        ρσ_modules.range_utils.remove = remove;
        ρσ_modules.range_utils.replace_node = replace_node;
        ρσ_modules.range_utils.unwrap = unwrap;
        ρσ_modules.range_utils.unwrap_crw = unwrap_crw;
        ρσ_modules.range_utils.unwrap_all_crw = unwrap_all_crw;
        ρσ_modules.range_utils.select_crw = select_crw;
        ρσ_modules.range_utils.wrap_range = wrap_range;
        ρσ_modules.range_utils.create_wrapper_function = create_wrapper_function;
        ρσ_modules.range_utils.wrap_text_in_range = wrap_text_in_range;
        ρσ_modules.range_utils.last_span_for_crw = last_span_for_crw;
        ρσ_modules.range_utils.reset_highlight_counter = reset_highlight_counter;
        ρσ_modules.range_utils.get_annot_id_for = get_annot_id_for;
        ρσ_modules.range_utils.highlight_associated_with_selection = highlight_associated_with_selection;
    })();

    (function(){
        var __name__ = "read_book.anchor_visibility";
        var anchor_position_cache;
        var current_layout_mode = ρσ_modules["read_book.globals"].current_layout_mode;
        var get_boss = ρσ_modules["read_book.globals"].get_boss;

        var scroll_viewport = ρσ_modules["read_book.viewport"].scroll_viewport;

        anchor_position_cache = Object.create(null);
        function invalidate_anchor_position_cache() {
            anchor_position_cache = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["layout_mode"] = current_layout_mode();
                ρσ_d["width"] = scroll_viewport.width();
                ρσ_d["height"] = scroll_viewport.height();
                ρσ_d["positions"] = {};
                return ρσ_d;
            }).call(this);
        };
        if (!invalidate_anchor_position_cache.__module__) Object.defineProperties(invalidate_anchor_position_cache, {
            __module__ : {value: "read_book.anchor_visibility"}
        });

        function ensure_anchor_cache_valid() {
            var a;
            a = anchor_position_cache;
            if (a.layout_mode !== current_layout_mode() || a.width !== scroll_viewport.width() || a.height !== scroll_viewport.height()) {
                invalidate_anchor_position_cache();
            }
        };
        if (!ensure_anchor_cache_valid.__module__) Object.defineProperties(ensure_anchor_cache_valid, {
            __module__ : {value: "read_book.anchor_visibility"}
        });

        function ensure_page_list_target_is_displayed(elem) {
            if (elem && window.getComputedStyle(elem).display === "none") {
                elem.textContent = "";
                elem.setAttribute("style", "all: revert");
            }
        };
        if (!ensure_page_list_target_is_displayed.__argnames__) Object.defineProperties(ensure_page_list_target_is_displayed, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.anchor_visibility"}
        });

        function position_for_anchor(anchor, is_page_list_anchor) {
            var cache, val, anchor_funcs, elem, q;
            ensure_anchor_cache_valid();
            cache = anchor_position_cache.positions;
            val = cache[(typeof anchor === "number" && anchor < 0) ? cache.length + anchor : anchor];
            if ((typeof val !== "undefined" && val !== null)) {
                return val;
            }
            anchor_funcs = get_boss().anchor_funcs;
            if (anchor) {
                elem = document.getElementById(anchor);
                if (!elem) {
                    q = document.getElementsByName(anchor);
                    if (q && q.length) {
                        elem = q[0];
                    }
                }
            } else {
                elem = document.body;
            }
            if (is_page_list_anchor) {
                ensure_page_list_target_is_displayed(elem);
            }
            val = (elem) ? anchor_funcs.pos_for_elem(elem) : anchor_funcs.pos_for_elem();
            cache[(typeof anchor === "number" && anchor < 0) ? cache.length + anchor : anchor] = val;
            return val;
        };
        if (!position_for_anchor.__argnames__) Object.defineProperties(position_for_anchor, {
            __argnames__ : {value: ["anchor", "is_page_list_anchor"]},
            __module__ : {value: "read_book.anchor_visibility"}
        });

        function is_anchor_on_screen(anchor) {
            var pos, anchor_funcs;
            pos = position_for_anchor(anchor);
            anchor_funcs = get_boss().anchor_funcs;
            return anchor_funcs.visibility(pos) === 0;
        };
        if (!is_anchor_on_screen.__argnames__) Object.defineProperties(is_anchor_on_screen, {
            __argnames__ : {value: ["anchor"]},
            __module__ : {value: "read_book.anchor_visibility"}
        });

        ρσ_modules["read_book.anchor_visibility"].anchor_position_cache = anchor_position_cache;
        ρσ_modules["read_book.anchor_visibility"].invalidate_anchor_position_cache = invalidate_anchor_position_cache;
        ρσ_modules["read_book.anchor_visibility"].ensure_anchor_cache_valid = ensure_anchor_cache_valid;
        ρσ_modules["read_book.anchor_visibility"].ensure_page_list_target_is_displayed = ensure_page_list_target_is_displayed;
        ρσ_modules["read_book.anchor_visibility"].position_for_anchor = position_for_anchor;
        ρσ_modules["read_book.anchor_visibility"].is_anchor_on_screen = is_anchor_on_screen;
    })();

    (function(){
        var __name__ = "read_book.extract";
        var annot_id_uuid_map = ρσ_modules["read_book.globals"].annot_id_uuid_map;

        function get_elements(x, y) {
            var ans, tl, annot_id, elem;
            ans = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["link"] = null;
                ρσ_d["img"] = null;
                ρσ_d["highlight"] = null;
                ρσ_d["crw"] = null;
                return ρσ_d;
            }).call(this);
            var ρσ_Iter0 = ρσ_Iterable(document.elementsFromPoint(x, y));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                elem = ρσ_Iter0[ρσ_Index0];
                tl = elem.tagName.toLowerCase();
                if (tl === "a" && elem.getAttribute("href") && !ans.link) {
                    ans.link = elem.getAttribute("href");
                } else if ((tl === "img" || tl === "image") && elem.getAttribute("data-calibre-src") && !ans.img) {
                    ans.img = elem.getAttribute("data-calibre-src");
                } else if (ρσ_exists.d(elem.dataset).calibreRangeWrapper) {
                    ans.crw = elem.dataset.calibreRangeWrapper;
                    annot_id = annot_id_uuid_map[ρσ_bound_index(ans.crw, annot_id_uuid_map)];
                    if (annot_id) {
                        ans.highlight = annot_id;
                    }
                }
            }
            return ans;
        };
        if (!get_elements.__argnames__) Object.defineProperties(get_elements, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "read_book.extract"}
        });

        ρσ_modules["read_book.extract"].get_elements = get_elements;
    })();

    (function(){
        var __name__ = "read_book.find";
        var ignored_tags, block_tags_for_tts, cache;
        ignored_tags = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["style"] = true;
            ρσ_d["script"] = true;
            ρσ_d["noscript"] = true;
            ρσ_d["title"] = true;
            ρσ_d["meta"] = true;
            ρσ_d["head"] = true;
            ρσ_d["link"] = true;
            ρσ_d["html"] = true;
            ρσ_d["img"] = true;
            ρσ_d["rt"] = true;
            ρσ_d["rp"] = true;
            ρσ_d["rtc"] = true;
            return ρσ_d;
        }).call(this);
        block_tags_for_tts = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["h1"] = true;
            ρσ_d["h2"] = true;
            ρσ_d["h3"] = true;
            ρσ_d["h4"] = true;
            ρσ_d["h5"] = true;
            ρσ_d["h6"] = true;
            ρσ_d["p"] = true;
            ρσ_d["div"] = true;
            ρσ_d["table"] = true;
            ρσ_d["th"] = true;
            ρσ_d["tr"] = true;
            ρσ_d["td"] = true;
            ρσ_d["section"] = true;
            ρσ_d["article"] = true;
            return ρσ_d;
        }).call(this);
        function build_text_map(for_tts) {
            var node_list, flat_text, text_node_type, element_node_type, in_ruby;
            node_list = [];
            flat_text = "";
            text_node_type = Node.TEXT_NODE;
            element_node_type = Node.ELEMENT_NODE;
            in_ruby = 0;
            function process_node(node) {
                var nt, text, rtext, tag, is_ruby_tag, children, i;
                nt = node.nodeType;
                if (nt === text_node_type) {
                    text = node.nodeValue;
                    if (text && text.length) {
                        if (in_ruby) {
                            rtext = text.trim();
                            if (rtext.length) {
                                node_list.push({node: node, offset: flat_text.length, length: rtext.length, offset_in_node: text.length - text.trimStart().length});
                                flat_text += rtext;
                            }
                        } else {
                            node_list.push({node: node, offset: flat_text.length, length: text.length});
                            flat_text += text;
                        }
                    }
                } else if (nt === element_node_type) {
                    if (!node.hasChildNodes()) {
                        return;
                    }
                    tag = node.tagName.toLowerCase();
                    if (ignored_tags[(typeof tag === "number" && tag < 0) ? ignored_tags.length + tag : tag]) {
                        return;
                    }
                    is_ruby_tag = tag === "ruby";
                    if (is_ruby_tag) {
                        in_ruby += 1;
                    }
                    children = node.childNodes;
                    for (var ρσ_Index0 = 0; ρσ_Index0 < children.length; ρσ_Index0++) {
                        i = ρσ_Index0;
                        process_node(children[i]);
                    }
                    if (is_ruby_tag) {
                        in_ruby -= 1;
                    }
                    if (for_tts && block_tags_for_tts[(typeof tag === "number" && tag < 0) ? block_tags_for_tts.length + tag : tag]) {
                        if (flat_text.length && " \n\t\r".indexOf(flat_text[flat_text.length-1]) > -1) {
                            flat_text = flat_text.slice(0, -1) + "\u2029";
                        } else if (node_list.length) {
                            flat_text += "\u2029";
                            node_list[node_list.length-1].length += 1;
                        }
                    }
                }
            };
            if (!process_node.__argnames__) Object.defineProperties(process_node, {
                __argnames__ : {value: ["node"]},
                __module__ : {value: "read_book.find"}
            });

            process_node(document.body);
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["timestamp"] = window.performance.now();
                ρσ_d["flat_text"] = flat_text;
                ρσ_d["node_list"] = node_list;
                return ρσ_d;
            }).call(this);
        };
        if (!build_text_map.__argnames__) Object.defineProperties(build_text_map, {
            __argnames__ : {value: ["for_tts"]},
            __module__ : {value: "read_book.find"}
        });

        function index_for_node(node, node_list) {
            var entry;
            var ρσ_Iter1 = ρσ_Iterable(node_list);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                entry = ρσ_Iter1[ρσ_Index1];
                if (entry.node.isSameNode(node)) {
                    return entry.offset;
                }
            }
        };
        if (!index_for_node.__argnames__) Object.defineProperties(index_for_node, {
            __argnames__ : {value: ["node", "node_list"]},
            __module__ : {value: "read_book.find"}
        });

        function tts_word_regex() {
            return /[\p{Letter}\p{Mark}\p{Number}\p{Punctuation}\p{Cf}]{1,50}/gu;
        };
        if (!tts_word_regex.__module__) Object.defineProperties(tts_word_regex, {
            __module__ : {value: "read_book.find"}
        });

        function cached_tts_text_map() {
            if (!cache.tts_text_map) {
                cache.tts_text_map = build_text_map(true);
            }
            return cache.tts_text_map;
        };
        if (!cached_tts_text_map.__module__) Object.defineProperties(cached_tts_text_map, {
            __module__ : {value: "read_book.find"}
        });

        function tts_data(text_node, offset) {
            var offset_in_flat_text, text_map, match, first, last, marked_text, text, start, trailer;
            offset_in_flat_text = offset || 0;
            text_map = cached_tts_text_map();
            if (text_node) {
                offset_in_flat_text += index_for_node(text_node, text_map.node_list) || 0;
            }
            match = null;
            first = true;
            last = null;
            marked_text = [];
            text = text_map.flat_text.slice(offset_in_flat_text);
            for (match of text.matchAll(tts_word_regex())) {
                start = match.index;
                if (first) {
                    first = false;
                    if (start) {
                        marked_text.push(text.slice(0, start));
                    }
                } else if (start > last) {
                    marked_text.push(text.slice(last, start));
                }
                marked_text.push(start + offset_in_flat_text);
                marked_text.push(match[0]);
                last = start + match[0].length;
            }
            if (last === null) {
                marked_text.push(text);
            } else {
                trailer = text.slice(last);
                if (trailer) {
                    marked_text.push(trailer);
                }
            }
            return marked_text;
        };
        if (!tts_data.__argnames__) Object.defineProperties(tts_data, {
            __argnames__ : {value: ["text_node", "offset"]},
            __module__ : {value: "read_book.find"}
        });

        function find_node_for_index_binary(node_list, idx_in_flat_text, start) {
            var end, mid, q, limit, start_node, start_offset;
            start = start || 0;
            end = node_list.length - 1;
            while (start <= end) {
                mid = Math.floor((start + end) / 2);
                q = node_list[(typeof mid === "number" && mid < 0) ? node_list.length + mid : mid];
                limit = q.offset + q.length;
                if (q.offset <= idx_in_flat_text && limit > idx_in_flat_text) {
                    start_node = q.node;
                    start_offset = idx_in_flat_text - q.offset;
                    return [start_node, start_offset + (q.offset_in_node || 0), mid];
                }
                if (limit <= idx_in_flat_text) {
                    start = mid + 1;
                } else {
                    end = mid - 1;
                }
            }
            return [null, null, null];
        };
        if (!find_node_for_index_binary.__argnames__) Object.defineProperties(find_node_for_index_binary, {
            __argnames__ : {value: ["node_list", "idx_in_flat_text", "start"]},
            __module__ : {value: "read_book.find"}
        });

        function get_occurrence_data(node_list, start, end) {
            var ρσ_unpack, start_node, start_offset, start_pos, end_node, end_offset, node_pos;
            ρσ_unpack = find_node_for_index_binary(node_list, start);
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
            start_node = ρσ_unpack[0];
            start_offset = ρσ_unpack[1];
            start_pos = ρσ_unpack[2];
            if (start_node !== null) {
                ρσ_unpack = find_node_for_index_binary(node_list, end, start_pos);
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
                end_node = ρσ_unpack[0];
                end_offset = ρσ_unpack[1];
                node_pos = ρσ_unpack[2];
                if (end_node !== null) {
                    return (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["start_node"] = start_node;
                        ρσ_d["start_offset"] = start_offset;
                        ρσ_d["start_pos"] = start_pos;
                        ρσ_d["end_node"] = end_node;
                        ρσ_d["end_offset"] = end_offset;
                        ρσ_d["end_pos"] = node_pos;
                        return ρσ_d;
                    }).call(this);
                }
            }
        };
        if (!get_occurrence_data.__argnames__) Object.defineProperties(get_occurrence_data, {
            __argnames__ : {value: ["node_list", "start", "end"]},
            __module__ : {value: "read_book.find"}
        });

        function find_specific_occurrence(q, num, before_len, after_len, text_map, from_offset) {
            var from_idx, flat_text, match_num, idx;
            if (!q || !q.length) {
                return;
            }
            from_idx = from_offset || 0;
            flat_text = text_map.flat_text;
            match_num = -1;
            while (true) {
                idx = flat_text.indexOf(q, from_idx);
                if (idx < 0) {
                    break;
                }
                match_num += 1;
                from_idx = idx + 1;
                if (match_num < num) {
                    continue;
                }
                return get_occurrence_data(text_map.node_list, idx + before_len, idx + q.length - after_len);
            }
        };
        if (!find_specific_occurrence.__argnames__) Object.defineProperties(find_specific_occurrence, {
            __argnames__ : {value: ["q", "num", "before_len", "after_len", "text_map", "from_offset"]},
            __module__ : {value: "read_book.find"}
        });

        cache = Object.create(null);
        function reset_find_caches() {
            cache = Object.create(null);
        };
        if (!reset_find_caches.__module__) Object.defineProperties(reset_find_caches, {
            __module__ : {value: "read_book.find"}
        });

        function select_find_result(match) {
            var sel;
            sel = window.getSelection();
            try {
                sel.setBaseAndExtent(match.start_node, match.start_offset, match.end_node, match.end_offset);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    return false;
                } 
            }
            return bool(sel.rangeCount && sel.toString());
        };
        if (!select_find_result.__argnames__) Object.defineProperties(select_find_result, {
            __argnames__ : {value: ["match"]},
            __module__ : {value: "read_book.find"}
        });

        function select_search_result(sr) {
            var q, before_len, after_len, after, match;
            window.getSelection().removeAllRanges();
            if (!cache.text_map) {
                cache.text_map = build_text_map();
            }
            q = "";
            before_len = after_len = 0;
            if (sr.before) {
                q = sr.before.slice(-15);
                before_len = q.length;
            }
            q += sr.text;
            if (sr.after) {
                after = sr.after.slice(0, 15);
                after_len = after.length;
                q += after;
            }
            match = find_specific_occurrence(q, int(sr.index), before_len, after_len, cache.text_map, sr.from_offset);
            if (!match) {
                return false;
            }
            return select_find_result(match);
        };
        if (!select_search_result.__argnames__) Object.defineProperties(select_search_result, {
            __argnames__ : {value: ["sr"]},
            __module__ : {value: "read_book.find"}
        });

        function find_word_length(text_map, idx) {
            var r, match, word_length;
            r = tts_word_regex();
            r.lastIndex = idx;
            match = r.exec(text_map.flat_text);
            word_length = 5;
            if (match) {
                word_length = ρσ_exists.d(match[0]).length || 5;
            }
            return word_length;
        };
        if (!find_word_length.__argnames__) Object.defineProperties(find_word_length, {
            __argnames__ : {value: ["text_map", "idx"]},
            __module__ : {value: "read_book.find"}
        });

        function select_tts_mark(idx_in_flat_text, last_idx_in_flat_text) {
            var text_map, match;
            window.getSelection().removeAllRanges();
            text_map = cached_tts_text_map();
            if (idx_in_flat_text === last_idx_in_flat_text) {
                match = get_occurrence_data(text_map.node_list, idx_in_flat_text, idx_in_flat_text + find_word_length(text_map, idx_in_flat_text));
            } else {
                match = get_occurrence_data(text_map.node_list, idx_in_flat_text, last_idx_in_flat_text + find_word_length(text_map, last_idx_in_flat_text));
            }
            if (!match) {
                return false;
            }
            return select_find_result(match);
        };
        if (!select_tts_mark.__argnames__) Object.defineProperties(select_tts_mark, {
            __argnames__ : {value: ["idx_in_flat_text", "last_idx_in_flat_text"]},
            __module__ : {value: "read_book.find"}
        });

        ρσ_modules["read_book.find"].ignored_tags = ignored_tags;
        ρσ_modules["read_book.find"].block_tags_for_tts = block_tags_for_tts;
        ρσ_modules["read_book.find"].cache = cache;
        ρσ_modules["read_book.find"].build_text_map = build_text_map;
        ρσ_modules["read_book.find"].index_for_node = index_for_node;
        ρσ_modules["read_book.find"].tts_word_regex = tts_word_regex;
        ρσ_modules["read_book.find"].cached_tts_text_map = cached_tts_text_map;
        ρσ_modules["read_book.find"].tts_data = tts_data;
        ρσ_modules["read_book.find"].find_node_for_index_binary = find_node_for_index_binary;
        ρσ_modules["read_book.find"].get_occurrence_data = get_occurrence_data;
        ρσ_modules["read_book.find"].find_specific_occurrence = find_specific_occurrence;
        ρσ_modules["read_book.find"].reset_find_caches = reset_find_caches;
        ρσ_modules["read_book.find"].select_find_result = select_find_result;
        ρσ_modules["read_book.find"].select_search_result = select_search_result;
        ρσ_modules["read_book.find"].find_word_length = find_word_length;
        ρσ_modules["read_book.find"].select_tts_mark = select_tts_mark;
    })();

    (function(){
        var __name__ = "read_book.flow_mode";
        var small_scroll_events, last_change_spine_item_request, DIRECTION, scroll_animator, flick_animator, drag_scroller, anchor_funcs;
        var set_css = ρσ_modules.dom.set_css;

        var wrap_range = ρσ_modules.range_utils.wrap_range;
        var unwrap = ρσ_modules.range_utils.unwrap;

        var cfi_scroll_to = ρσ_modules["read_book.cfi"].scroll_to;

        var current_spine_item = ρσ_modules["read_book.globals"].current_spine_item;
        var get_boss = ρσ_modules["read_book.globals"].get_boss;
        var rtl_page_progression = ρσ_modules["read_book.globals"].rtl_page_progression;
        var ltr_page_progression = ρσ_modules["read_book.globals"].ltr_page_progression;

        var opts = ρσ_modules["read_book.settings"].opts;

        var line_height = ρσ_modules["read_book.viewport"].line_height;
        var rem_size = ρσ_modules["read_book.viewport"].rem_size;
        var scroll_viewport = ρσ_modules["read_book.viewport"].scroll_viewport;

        function flow_to_scroll_fraction(frac, on_initial_load) {
            scroll_viewport.scroll_to_in_block_direction(scroll_viewport.document_block_size() * frac);
        };
        if (!flow_to_scroll_fraction.__argnames__) Object.defineProperties(flow_to_scroll_fraction, {
            __argnames__ : {value: ["frac", "on_initial_load"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        small_scroll_events = [];
        function clear_small_scrolls() {
            small_scroll_events = [];
        };
        if (!clear_small_scrolls.__module__) Object.defineProperties(clear_small_scrolls, {
            __module__ : {value: "read_book.flow_mode"}
        });

        function dispatch_small_scrolls() {
            var now, amt, x;
            if (small_scroll_events.length) {
                now = window.performance.now();
                if (now - small_scroll_events[small_scroll_events.length-1].time <= 2e3) {
                    window.setTimeout(dispatch_small_scrolls, 100);
                    return;
                }
                amt = 0;
                var ρσ_Iter0 = ρσ_Iterable(small_scroll_events);
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    x = ρσ_Iter0[ρσ_Index0];
                    amt += x.amt;
                }
                clear_small_scrolls();
                get_boss().report_human_scroll(amt / scroll_viewport.document_block_size());
            }
        };
        if (!dispatch_small_scrolls.__module__) Object.defineProperties(dispatch_small_scrolls, {
            __module__ : {value: "read_book.flow_mode"}
        });

        function add_small_scroll(amt) {
            small_scroll_events.push((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["amt"] = amt;
                ρσ_d["time"] = window.performance.now();
                return ρσ_d;
            }).call(this));
            window.setTimeout(dispatch_small_scrolls, 100);
        };
        if (!add_small_scroll.__argnames__) Object.defineProperties(add_small_scroll, {
            __argnames__ : {value: ["amt"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function report_human_scroll(amt) {
            var h, is_large_scroll;
            h = scroll_viewport.height();
            is_large_scroll = abs(amt) / h >= .5;
            if (amt > 0) {
                if (is_large_scroll) {
                    clear_small_scrolls();
                    get_boss().report_human_scroll(amt / scroll_viewport.document_block_size());
                } else {
                    add_small_scroll(amt);
                }
            } else if (amt === 0 || is_large_scroll) {
                clear_small_scrolls();
            }
        };
        if (!report_human_scroll.__argnames__) Object.defineProperties(report_human_scroll, {
            __argnames__ : {value: ["amt"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        last_change_spine_item_request = Object.create(null);
        function _check_for_scroll_end(func, obj, args, report, apply_mouse_boundary_delay) {
            var before, should_flip_progression_direction, now, csi, go_to_previous_page;
            before = scroll_viewport.block_pos();
            should_flip_progression_direction = func.apply(obj, args);
            now = window.performance.now();
            scroll_animator.sync(now);
            if (scroll_viewport.block_pos() === before) {
                csi = current_spine_item();
                if (last_change_spine_item_request.name === csi.name && now - last_change_spine_item_request.at < 2e3) {
                    return false;
                }
                if (apply_mouse_boundary_delay && opts.scroll_mouse_boundary_delay > 0) {
                    if (last_change_spine_item_request.denied === null) {
                        last_change_spine_item_request.denied = now;
                    }
                    if (now - last_change_spine_item_request.denied < opts.scroll_mouse_boundary_delay * 1e3) {
                        return false;
                    }
                    last_change_spine_item_request.denied = null;
                }
                last_change_spine_item_request.name = csi.name;
                last_change_spine_item_request.at = now;
                go_to_previous_page = args[0] < 0;
                if (should_flip_progression_direction) {
                    go_to_previous_page = !go_to_previous_page;
                }
                (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["next_spine_item"].concat([ρσ_desugar_kwargs({previous: go_to_previous_page})])));
                return false;
            }
            last_change_spine_item_request.denied = null;
            if (report) {
                report_human_scroll(scroll_viewport.block_pos() - before);
            }
            return true;
        };
        if (!_check_for_scroll_end.__argnames__) Object.defineProperties(_check_for_scroll_end, {
            __argnames__ : {value: ["func", "obj", "args", "report", "apply_mouse_boundary_delay"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function check_for_scroll_end(func) {
            return (function() {
                var ρσ_anonfunc = function () {
                    return _check_for_scroll_end(func, this, arguments, false, true);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.flow_mode"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!check_for_scroll_end.__argnames__) Object.defineProperties(check_for_scroll_end, {
            __argnames__ : {value: ["func"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function check_for_scroll_end_and_report(func) {
            return (function() {
                var ρσ_anonfunc = function () {
                    return _check_for_scroll_end(func, this, arguments, true, true);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.flow_mode"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!check_for_scroll_end_and_report.__argnames__) Object.defineProperties(check_for_scroll_end_and_report, {
            __argnames__ : {value: ["func"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function check_for_scroll_end_and_report_no_delay(func) {
            return (function() {
                var ρσ_anonfunc = function () {
                    return _check_for_scroll_end(func, this, arguments, true, false);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.flow_mode"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!check_for_scroll_end_and_report_no_delay.__argnames__) Object.defineProperties(check_for_scroll_end_and_report_no_delay, {
            __argnames__ : {value: ["func"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        
        var scroll_by_and_check_next_page = check_for_scroll_end_and_report((function() {
            var ρσ_anonfunc = function scroll_by_and_check_next_page(y) {
                scroll_viewport.scroll_by_in_block_direction(y);
                return false;
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["y"]},
                __module__ : {value: "read_book.flow_mode"}
            });
            return ρσ_anonfunc;
        })());

        function flow_onwheel(evt) {
            var di, db, WheelEvent, dx;
            di = db = 0;
            WheelEvent = window.WheelEvent;
            if (evt.deltaY) {
                if (evt.deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
                    db = evt.deltaY;
                } else if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE) {
                    db = line_height() * evt.deltaY;
                }
                if (evt.deltaMode === WheelEvent.DOM_DELTA_PAGE) {
                    db = (scroll_viewport.block_size() - 30) * evt.deltaY;
                }
            }
            if (evt.deltaX) {
                if (evt.deltaMode === WheelEvent.DOM_DELTA_PIXEL) {
                    dx = evt.deltaX;
                } else if (evt.deltaMode === WheelEvent.DOM_DELTA_LINE) {
                    dx = line_height() * evt.deltaX;
                } else {
                    dx = (scroll_viewport.block_size() - 30) * evt.deltaX;
                }
                if (scroll_viewport.horizontal_writing_mode) {
                    di = dx;
                } else {
                    if (scroll_viewport.rtl) {
                        db = -dx;
                    } else {
                        db = dx;
                    }
                }
            }
            if (Math.abs(di) >= 1) {
                scroll_viewport.scroll_by_in_inline_direction(di);
            }
            if (Math.abs(db) >= 1) {
                scroll_by_and_check_next_page(db);
            }
        };
        if (!flow_onwheel.__argnames__) Object.defineProperties(flow_onwheel, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        
        var goto_boundary = check_for_scroll_end((function() {
            var ρσ_anonfunc = function goto_boundary(dir) {
                var position;
                position = (dir === DIRECTION.Up) ? 0 : scroll_viewport.document_block_size();
                scroll_viewport.scroll_to_in_block_direction(position);
                get_boss().report_human_scroll();
                return false;
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["dir"]},
                __module__ : {value: "read_book.flow_mode"}
            });
            return ρσ_anonfunc;
        })());

        function _scroll_by_page(direction, flip_if_rtl_page_progression) {
            var b;
            b = scroll_viewport.block_size() - 10;
            scroll_viewport.scroll_by_in_block_direction(b * direction);
            return flip_if_rtl_page_progression && rtl_page_progression();
        };
        if (!_scroll_by_page.__argnames__) Object.defineProperties(_scroll_by_page, {
            __argnames__ : {value: ["direction", "flip_if_rtl_page_progression"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        
        var scroll_by_page = check_for_scroll_end_and_report((function() {
            var ρσ_anonfunc = function scroll_by_page(direction, flip_if_rtl_page_progression) {
                _scroll_by_page(direction, flip_if_rtl_page_progression);
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["direction", "flip_if_rtl_page_progression"]},
                __module__ : {value: "read_book.flow_mode"}
            });
            return ρσ_anonfunc;
        })());

        
        var scroll_by_page_no_delay = check_for_scroll_end_and_report_no_delay((function() {
            var ρσ_anonfunc = function scroll_by_page_no_delay(direction, flip_if_rtl_page_progression) {
                _scroll_by_page(direction, flip_if_rtl_page_progression);
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["direction", "flip_if_rtl_page_progression"]},
                __module__ : {value: "read_book.flow_mode"}
            });
            return ρσ_anonfunc;
        })());

        function scroll_to_extend_annotation(backward, horizontal, by_page) {
            var direction, h, before;
            direction = (backward) ? -1 : 1;
            h = line_height();
            if (by_page) {
                h = ((horizontal) ? window.innerWidth : window.innerHeight) - h;
            }
            if (horizontal) {
                before = window.pageXOffset;
                window.scrollBy(h * direction, 0);
                return window.pageXOffset !== before;
            }
            before = window.pageYOffset;
            window.scrollBy(0, h * direction);
            return window.pageYOffset !== before;
        };
        if (!scroll_to_extend_annotation.__argnames__) Object.defineProperties(scroll_to_extend_annotation, {
            __argnames__ : {value: ["backward", "horizontal", "by_page"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function is_auto_scroll_active() {
            return scroll_animator.is_active();
        };
        if (!is_auto_scroll_active.__module__) Object.defineProperties(is_auto_scroll_active, {
            __module__ : {value: "read_book.flow_mode"}
        });

        function start_autoscroll() {
            scroll_animator.start(DIRECTION.Down, true);
        };
        if (!start_autoscroll.__module__) Object.defineProperties(start_autoscroll, {
            __module__ : {value: "read_book.flow_mode"}
        });

        function toggle_autoscroll() {
            var running;
            if (is_auto_scroll_active()) {
                cancel_scroll();
                running = false;
            } else {
                start_autoscroll();
                running = true;
            }
            (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["autoscroll_state_changed"].concat([ρσ_desugar_kwargs({running: running})])));
        };
        if (!toggle_autoscroll.__module__) Object.defineProperties(toggle_autoscroll, {
            __module__ : {value: "read_book.flow_mode"}
        });

        function handle_shortcut(sc_name, evt) {
            if (sc_name === "down") {
                scroll_animator.start(DIRECTION.Down, false);
                return true;
            }
            if (sc_name === "up") {
                scroll_animator.start(DIRECTION.Up, false);
                return true;
            }
            if (sc_name === "start_of_file") {
                goto_boundary(DIRECTION.Up);
                return true;
            }
            if (sc_name === "end_of_file") {
                goto_boundary(DIRECTION.Down);
                return true;
            }
            if (sc_name === "left") {
                scroll_by_and_check_next_page((ltr_page_progression()) ? -15 : 15, 0);
                return true;
            }
            if (sc_name === "right") {
                scroll_by_and_check_next_page((ltr_page_progression()) ? 15 : -15, 0);
                return true;
            }
            if (sc_name === "start_of_book") {
                (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["goto_doc_boundary"].concat([ρσ_desugar_kwargs({start: true})])));
                return true;
            }
            if (sc_name === "end_of_book") {
                (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["goto_doc_boundary"].concat([ρσ_desugar_kwargs({start: false})])));
                return true;
            }
            if (sc_name === "pageup") {
                scroll_by_page_no_delay(-1, false);
                return true;
            }
            if (sc_name === "pagedown") {
                scroll_by_page_no_delay(1, false);
                return true;
            }
            if (sc_name === "toggle_autoscroll") {
                toggle_autoscroll();
                return true;
            }
            if (sc_name.startsWith("scrollspeed_")) {
                scroll_animator.sync();
            }
            return false;
        };
        if (!handle_shortcut.__argnames__) Object.defineProperties(handle_shortcut, {
            __argnames__ : {value: ["sc_name", "evt"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function layout(is_single_page) {
            var body_style;
            add_visibility_listener();
            line_height(true);
            rem_size(true);
            ρσ_interpolate_kwargs.call(this, set_css, [document.body].concat([ρσ_desugar_kwargs({margin: "0", border_width: "0", padding: "0"})]));
            body_style = window.getComputedStyle(document.body);
            scroll_viewport.initialize_on_layout(body_style);
            document.documentElement.style.overflow = (scroll_viewport.vertical_writing_mode) ? "visible" : "hidden";
        };
        if (!layout.__argnames__) Object.defineProperties(layout, {
            __argnames__ : {value: ["is_single_page"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function auto_scroll_resume() {
            scroll_animator.wait = false;
            scroll_animator.sync();
        };
        if (!auto_scroll_resume.__module__) Object.defineProperties(auto_scroll_resume, {
            __module__ : {value: "read_book.flow_mode"}
        });

        function add_visibility_listener() {
            if (add_visibility_listener.done) {
                return;
            }
            add_visibility_listener.done = true;
            document.addEventListener("visibilitychange", (function() {
                var ρσ_anonfunc = function () {
                    if (document.visibilityState === "visible") {
                        scroll_animator.sync();
                    } else {
                        scroll_animator.pause();
                    }
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.flow_mode"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!add_visibility_listener.__module__) Object.defineProperties(add_visibility_listener, {
            __module__ : {value: "read_book.flow_mode"}
        });

        function cancel_scroll() {
            scroll_animator.stop();
        };
        if (!cancel_scroll.__module__) Object.defineProperties(cancel_scroll, {
            __module__ : {value: "read_book.flow_mode"}
        });

        function is_scroll_end(pos) {
            return !((0 <= pos && pos <= scroll_viewport.document_block_size() - scroll_viewport.block_size()));
        };
        if (!is_scroll_end.__argnames__) Object.defineProperties(is_scroll_end, {
            __argnames__ : {value: ["pos"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        DIRECTION = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["Up"] = -1;
            ρσ_d["up"] = -1;
            ρσ_d["Down"] = 1;
            ρσ_d["down"] = 1;
            ρσ_d["UP"] = -1;
            ρσ_d["DOWN"] = 1;
            return ρσ_d;
        }).call(this);
        function ScrollAnimator() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ScrollAnimator.prototype.__bind_methods__.call(this);
            ScrollAnimator.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ScrollAnimator.prototype, "__bind_methods__", {value: function () {
            this.is_running = ScrollAnimator.prototype.is_running.bind(this);
            this.is_active = ScrollAnimator.prototype.is_active.bind(this);
            this.start = ScrollAnimator.prototype.start.bind(this);
            this.smooth_scroll = ScrollAnimator.prototype.smooth_scroll.bind(this);
            this.auto_scroll = ScrollAnimator.prototype.auto_scroll.bind(this);
            this.request_next_spine_item = ScrollAnimator.prototype.request_next_spine_item.bind(this);
            this.report = ScrollAnimator.prototype.report.bind(this);
            this.sync = ScrollAnimator.prototype.sync.bind(this);
            this.stop = ScrollAnimator.prototype.stop.bind(this);
            this.stop_auto_spine_transition = ScrollAnimator.prototype.stop_auto_spine_transition.bind(this);
            this.pause = ScrollAnimator.prototype.pause.bind(this);
            this.resume = ScrollAnimator.prototype.resume.bind(this);
        }});
        ScrollAnimator.prototype.__init__ = function __init__() {
            var self = this;
            self.animation_id = null;
            self.auto = false;
            self.auto_timer = null;
            self.paused = false;
        };
        if (!ScrollAnimator.prototype.__init__.__module__) Object.defineProperties(ScrollAnimator.prototype.__init__, {
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.__argnames__ = ScrollAnimator.prototype.__init__.__argnames__;
        ScrollAnimator.__handles_kwarg_interpolation__ = ScrollAnimator.prototype.__init__.__handles_kwarg_interpolation__;
        ScrollAnimator.prototype.is_running = function is_running() {
            var self = this;
            return self.animation_id !== null || self.auto_timer !== null;
        };
        if (!ScrollAnimator.prototype.is_running.__module__) Object.defineProperties(ScrollAnimator.prototype.is_running, {
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.is_active = function is_active() {
            var self = this;
            return self.is_running() && (self.auto || self.auto_timer !== null);
        };
        if (!ScrollAnimator.prototype.is_active.__module__) Object.defineProperties(ScrollAnimator.prototype.is_active, {
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.start = function start(direction, auto) {
            var self = this;
            var now;
            cancel_drag_scroll();
            if (self.wait) {
                return;
            }
            now = window.performance.now();
            self.end_time = now + self.DURATION;
            self.stop_auto_spine_transition();
            if (!self.is_running() || direction !== self.direction || auto !== self.auto) {
                if (self.auto && !auto) {
                    self.pause();
                }
                self.stop();
                self.auto = auto;
                self.direction = direction;
                self.start_time = now;
                self.start_offset = scroll_viewport.block_pos();
                self.csi_idx = current_spine_item().index;
                self.animation_id = window.requestAnimationFrame((auto) ? self.auto_scroll : self.smooth_scroll);
            }
        };
        if (!ScrollAnimator.prototype.start.__argnames__) Object.defineProperties(ScrollAnimator.prototype.start, {
            __argnames__ : {value: ["direction", "auto"]},
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.smooth_scroll = function smooth_scroll(ts) {
            var self = this;
            var duration, progress, scroll_target, amt;
            duration = self.end_time - self.start_time;
            if (duration <= 0) {
                self.animation_id = null;
                return;
            }
            progress = max(0, min(1, (ts - self.start_time) / duration));
            scroll_target = self.start_offset;
            scroll_target += Math.trunc(self.direction * progress * duration * line_height() * opts.lines_per_sec_smooth) / 1e3;
            scroll_viewport.scroll_to_in_block_direction(scroll_target);
            amt = scroll_viewport.block_pos() - self.start_offset;
            if (is_scroll_end(scroll_target) && (!opts.scroll_stop_boundaries || abs(amt) < 3 && duration === self.DURATION)) {
                self.animation_id = null;
                self.wait = true;
                report_human_scroll(amt);
                (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["next_spine_item"].concat([ρσ_desugar_kwargs({previous: self.direction === DIRECTION.Up})])));
            } else if (progress < 1) {
                self.animation_id = window.requestAnimationFrame(self.smooth_scroll);
            } else if (self.paused) {
                self.resume();
            } else {
                self.animation_id = null;
                report_human_scroll(amt);
            }
        };
        if (!ScrollAnimator.prototype.smooth_scroll.__argnames__) Object.defineProperties(ScrollAnimator.prototype.smooth_scroll, {
            __argnames__ : {value: ["ts"]},
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.auto_scroll = function auto_scroll(ts) {
            var self = this;
            var elapsed, scroll_target, scroll_finished;
            elapsed = max(0, ts - self.start_time);
            scroll_target = self.start_offset;
            scroll_target += Math.trunc(self.direction * elapsed * line_height() * opts.lines_per_sec_auto) / 1e3;
            scroll_viewport.scroll_to_in_block_direction(scroll_target);
            scroll_finished = is_scroll_end(scroll_target);
            if (elapsed >= 1e3) {
                self.sync(ts);
            }
            if (scroll_finished) {
                self.pause();
                if (opts.scroll_auto_boundary_delay >= 0) {
                    self.auto_timer = setTimeout(self.request_next_spine_item, opts.scroll_auto_boundary_delay * 1e3);
                }
            } else {
                self.animation_id = window.requestAnimationFrame(self.auto_scroll);
            }
        };
        if (!ScrollAnimator.prototype.auto_scroll.__argnames__) Object.defineProperties(ScrollAnimator.prototype.auto_scroll, {
            __argnames__ : {value: ["ts"]},
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.request_next_spine_item = function request_next_spine_item() {
            var self = this;
            self.auto_timer = null;
            (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["next_spine_item"].concat([ρσ_desugar_kwargs({previous: self.direction === DIRECTION.Up})])));
        };
        if (!ScrollAnimator.prototype.request_next_spine_item.__module__) Object.defineProperties(ScrollAnimator.prototype.request_next_spine_item, {
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.report = function report() {
            var self = this;
            var amt;
            amt = scroll_viewport.block_pos() - self.start_offset;
            if (abs(amt) > 0 && self.csi_idx === current_spine_item().index) {
                report_human_scroll(amt);
            }
        };
        if (!ScrollAnimator.prototype.report.__module__) Object.defineProperties(ScrollAnimator.prototype.report, {
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.sync = function sync(ts) {
            var self = this;
            if (self.auto) {
                self.report();
                self.csi_idx = current_spine_item().index;
                self.start_time = ts || window.performance.now();
                self.start_offset = scroll_viewport.block_pos();
            } else {
                self.resume();
            }
        };
        if (!ScrollAnimator.prototype.sync.__argnames__) Object.defineProperties(ScrollAnimator.prototype.sync, {
            __argnames__ : {value: ["ts"]},
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.stop = function stop() {
            var self = this;
            self.auto = false;
            if (self.animation_id !== null) {
                window.cancelAnimationFrame(self.animation_id);
                self.animation_id = null;
                self.report();
            }
            self.stop_auto_spine_transition();
        };
        if (!ScrollAnimator.prototype.stop.__module__) Object.defineProperties(ScrollAnimator.prototype.stop, {
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.stop_auto_spine_transition = function stop_auto_spine_transition() {
            var self = this;
            if (self.auto_timer !== null) {
                clearTimeout(self.auto_timer);
                self.auto_timer = null;
                self.paused = false;
            }
        };
        if (!ScrollAnimator.prototype.stop_auto_spine_transition.__module__) Object.defineProperties(ScrollAnimator.prototype.stop_auto_spine_transition, {
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.pause = function pause() {
            var self = this;
            if (self.auto) {
                self.paused = self.direction;
                self.stop();
            } else {
                self.paused = false;
            }
        };
        if (!ScrollAnimator.prototype.pause.__module__) Object.defineProperties(ScrollAnimator.prototype.pause, {
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.resume = function resume() {
            var self = this;
            if (self.paused) {
                self.start(self.paused, true);
                self.paused = false;
            }
        };
        if (!ScrollAnimator.prototype.resume.__module__) Object.defineProperties(ScrollAnimator.prototype.resume, {
            __module__ : {value: "read_book.flow_mode"}
        });
        ScrollAnimator.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ScrollAnimator.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ScrollAnimator.prototype, "__bases__", {value: []});
        ScrollAnimator.prototype.DURATION = 100;

        scroll_animator = new ScrollAnimator;
        function FlickAnimator() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            FlickAnimator.prototype.__bind_methods__.call(this);
            FlickAnimator.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(FlickAnimator.prototype, "__bind_methods__", {value: function () {
            this.cancel_current_drag_scroll = FlickAnimator.prototype.cancel_current_drag_scroll.bind(this);
            this.start = FlickAnimator.prototype.start.bind(this);
            this.auto_scroll = FlickAnimator.prototype.auto_scroll.bind(this);
            this.scroll_y = FlickAnimator.prototype.scroll_y.bind(this);
            this.scroll_x = FlickAnimator.prototype.scroll_x.bind(this);
            this.stop = FlickAnimator.prototype.stop.bind(this);
        }});
        FlickAnimator.prototype.__init__ = function __init__() {
            var self = this;
            self.animation_id = null;
        };
        if (!FlickAnimator.prototype.__init__.__module__) Object.defineProperties(FlickAnimator.prototype.__init__, {
            __module__ : {value: "read_book.flow_mode"}
        });
        FlickAnimator.__argnames__ = FlickAnimator.prototype.__init__.__argnames__;
        FlickAnimator.__handles_kwarg_interpolation__ = FlickAnimator.prototype.__init__.__handles_kwarg_interpolation__;
        FlickAnimator.prototype.cancel_current_drag_scroll = function cancel_current_drag_scroll() {
            var self = this;
            cancel_drag_scroll();
        };
        if (!FlickAnimator.prototype.cancel_current_drag_scroll.__module__) Object.defineProperties(FlickAnimator.prototype.cancel_current_drag_scroll, {
            __module__ : {value: "read_book.flow_mode"}
        });
        FlickAnimator.prototype.start = function start(gesture) {
            var self = this;
            var now, points, times, ρσ_unpack, i, t, elapsed, delta, velocity;
            self.cancel_current_drag_scroll();
            self.vertical = gesture.axis === "vertical";
            now = window.performance.now();
            points = times = null;
            var ρσ_Iter1 = ρσ_Iterable(enumerate(gesture.times));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                ρσ_unpack = ρσ_Iter1[ρσ_Index1];
                i = ρσ_unpack[0];
                t = ρσ_unpack[1];
                if (now - t < self.VELOCITY_HISTORY) {
                    ρσ_unpack = [gesture.points.slice(i), gesture.times.slice(i)];
                    points = ρσ_unpack[0];
                    times = ρσ_unpack[1];
                    break;
                }
            }
            if (times && times.length > 1) {
                elapsed = (times[times.length-1] - times[0]) / 1e3;
                if (elapsed > 0 && points.length > 1) {
                    delta = points[0] - points[points.length-1];
                    velocity = delta / elapsed;
                    if (abs(velocity) > self.MIMUMUM_VELOCITY) {
                        self.amplitude = self.SPEED_FACTOR * velocity;
                        self.start_time = now;
                        self.animation_id = window.requestAnimationFrame(self.auto_scroll);
                    }
                }
            }
        };
        if (!FlickAnimator.prototype.start.__argnames__) Object.defineProperties(FlickAnimator.prototype.start, {
            __argnames__ : {value: ["gesture"]},
            __module__ : {value: "read_book.flow_mode"}
        });
        FlickAnimator.prototype.auto_scroll = function auto_scroll(ts) {
            var self = this;
            var elapsed, delta;
            if (self.animation_id === null) {
                return;
            }
            elapsed = window.performance.now() - self.start_time;
            delta = self.amplitude * Math.exp(-elapsed / self.DECEL_TIME_CONSTANT);
            if (abs(delta) >= 1) {
                delta = Math.round(delta);
                if (self.vertical) {
                    self.scroll_y(delta);
                } else {
                    self.scroll_x(delta);
                }
                self.animation_id = window.requestAnimationFrame(self.auto_scroll);
            }
        };
        if (!FlickAnimator.prototype.auto_scroll.__argnames__) Object.defineProperties(FlickAnimator.prototype.auto_scroll, {
            __argnames__ : {value: ["ts"]},
            __module__ : {value: "read_book.flow_mode"}
        });
        FlickAnimator.prototype.scroll_y = function scroll_y(delta) {
            var self = this;
            window.scrollBy(0, delta);
        };
        if (!FlickAnimator.prototype.scroll_y.__argnames__) Object.defineProperties(FlickAnimator.prototype.scroll_y, {
            __argnames__ : {value: ["delta"]},
            __module__ : {value: "read_book.flow_mode"}
        });
        FlickAnimator.prototype.scroll_x = function scroll_x(delta) {
            var self = this;
            window.scrollBy(delta, 0);
        };
        if (!FlickAnimator.prototype.scroll_x.__argnames__) Object.defineProperties(FlickAnimator.prototype.scroll_x, {
            __argnames__ : {value: ["delta"]},
            __module__ : {value: "read_book.flow_mode"}
        });
        FlickAnimator.prototype.stop = function stop() {
            var self = this;
            if (self.animation_id !== null) {
                window.cancelAnimationFrame(self.animation_id);
                self.animation_id = null;
            }
        };
        if (!FlickAnimator.prototype.stop.__module__) Object.defineProperties(FlickAnimator.prototype.stop, {
            __module__ : {value: "read_book.flow_mode"}
        });
        FlickAnimator.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        FlickAnimator.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(FlickAnimator.prototype, "__bases__", {value: []});
        FlickAnimator.prototype.SPEED_FACTOR = .04;
        FlickAnimator.prototype.DECEL_TIME_CONSTANT = 325;
        FlickAnimator.prototype.VELOCITY_HISTORY = 300;
        FlickAnimator.prototype.MIMUMUM_VELOCITY = 100;

        flick_animator = new FlickAnimator;
        function DragScroller() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            DragScroller.prototype.__bind_methods__.call(this);
            DragScroller.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(DragScroller.prototype, "__bind_methods__", {value: function () {
            this.is_running = DragScroller.prototype.is_running.bind(this);
            this.smooth_scroll = DragScroller.prototype.smooth_scroll.bind(this);
            this.start = DragScroller.prototype.start.bind(this);
            this.stop = DragScroller.prototype.stop.bind(this);
        }});
        DragScroller.prototype.__init__ = function __init__() {
            var self = this;
            self.animation_id = null;
            self.direction = 1;
            self.speed_factor = 1;
            self.start_time = self.end_time = 0;
            self.start_offset = 0;
        };
        if (!DragScroller.prototype.__init__.__module__) Object.defineProperties(DragScroller.prototype.__init__, {
            __module__ : {value: "read_book.flow_mode"}
        });
        DragScroller.__argnames__ = DragScroller.prototype.__init__.__argnames__;
        DragScroller.__handles_kwarg_interpolation__ = DragScroller.prototype.__init__.__handles_kwarg_interpolation__;
        DragScroller.prototype.is_running = function is_running() {
            var self = this;
            return self.animation_id !== null;
        };
        if (!DragScroller.prototype.is_running.__module__) Object.defineProperties(DragScroller.prototype.is_running, {
            __module__ : {value: "read_book.flow_mode"}
        });
        DragScroller.prototype.smooth_scroll = function smooth_scroll(ts) {
            var self = this;
            var duration, progress, scroll_target;
            duration = self.end_time - self.start_time;
            if (duration <= 0) {
                self.animation_id = null;
                self.start(self.direction, self.speed_factor);
                return;
            }
            progress = max(0, min(1, (ts - self.start_time) / duration));
            scroll_target = self.start_offset;
            scroll_target += Math.trunc(self.direction * progress * duration * line_height() * opts.lines_per_sec_smooth * self.speed_factor) / 1e3;
            scroll_viewport.scroll_to_in_block_direction(scroll_target);
            if (progress < 1) {
                self.animation_id = window.requestAnimationFrame(self.smooth_scroll);
            } else {
                self.animation_id = null;
                self.start(self.direction, self.speed_factor);
            }
        };
        if (!DragScroller.prototype.smooth_scroll.__argnames__) Object.defineProperties(DragScroller.prototype.smooth_scroll, {
            __argnames__ : {value: ["ts"]},
            __module__ : {value: "read_book.flow_mode"}
        });
        DragScroller.prototype.start = function start(direction, speed_factor) {
            var self = this;
            var now;
            now = window.performance.now();
            self.end_time = now + self.DURATION;
            if (!self.is_running() || direction !== self.direction || speed_factor !== self.speed_factor) {
                self.stop();
                self.direction = direction;
                self.speed_factor = speed_factor;
                self.start_time = now;
                self.start_offset = scroll_viewport.block_pos();
                self.animation_id = window.requestAnimationFrame(self.smooth_scroll);
            }
        };
        if (!DragScroller.prototype.start.__argnames__) Object.defineProperties(DragScroller.prototype.start, {
            __argnames__ : {value: ["direction", "speed_factor"]},
            __module__ : {value: "read_book.flow_mode"}
        });
        DragScroller.prototype.stop = function stop() {
            var self = this;
            if (self.animation_id !== null) {
                window.cancelAnimationFrame(self.animation_id);
                self.animation_id = null;
            }
        };
        if (!DragScroller.prototype.stop.__module__) Object.defineProperties(DragScroller.prototype.stop, {
            __module__ : {value: "read_book.flow_mode"}
        });
        DragScroller.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        DragScroller.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(DragScroller.prototype, "__bases__", {value: []});
        DragScroller.prototype.DURATION = 100;

        drag_scroller = new DragScroller;
        function cancel_drag_scroll() {
            drag_scroller.stop();
        };
        if (!cancel_drag_scroll.__module__) Object.defineProperties(cancel_drag_scroll, {
            __module__ : {value: "read_book.flow_mode"}
        });

        function start_drag_scroll(delta) {
            var limit, direction, speed_factor;
            limit = (delta < 0) ? opts.margin_top : opts.margin_bottom;
            direction = (delta >= 0) ? 1 : -1;
            speed_factor = min(abs(delta), limit) / limit;
            speed_factor *= 2 - speed_factor;
            drag_scroller.start(direction, 2 * speed_factor);
        };
        if (!start_drag_scroll.__argnames__) Object.defineProperties(start_drag_scroll, {
            __argnames__ : {value: ["delta"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function handle_gesture(gesture) {
            var delta;
            flick_animator.stop();
            if (gesture.resolved_action === "animated_scroll") {
                flick_animator.start(gesture);
            } else if (gesture.resolved_action === "pan") {
                if (gesture.points.length > 1 && !gesture.is_held) {
                    delta = (ρσ_expr_temp = gesture.points)[ρσ_expr_temp.length-2] - (ρσ_expr_temp = gesture.points)[ρσ_expr_temp.length-1];
                    if (Math.abs(delta) >= 1) {
                        if (gesture.axis === "vertical") {
                            if (scroll_viewport.vertical_writing_mode) {
                                scroll_viewport.scroll_by(delta, 0);
                            } else {
                                scroll_by_and_check_next_page(delta);
                            }
                        } else {
                            if (scroll_viewport.vertical_writing_mode) {
                                scroll_by_and_check_next_page(delta);
                            } else {
                                scroll_viewport.scroll_by(delta, 0);
                            }
                        }
                    }
                }
            } else if (gesture.resolved_action === "prev_page" || gesture.resolved_action === "prev_screen") {
                scroll_by_page(-1, false);
            } else if (gesture.resolved_action === "next_page" || gesture.resolved_action === "next_screen") {
                scroll_by_page(1, false);
            }
        };
        if (!handle_gesture.__argnames__) Object.defineProperties(handle_gesture, {
            __argnames__ : {value: ["gesture"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        anchor_funcs = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["pos_for_elem"] = (function() {
                var ρσ_anonfunc = function pos_for_elem(elem) {
                    var br;
                    if (!elem) {
                        return (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["block"] = 0;
                            ρσ_d["inline"] = 0;
                            return ρσ_d;
                        }).call(this);
                    }
                    br = elem.getBoundingClientRect();
                    return (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["block"] = scroll_viewport.viewport_to_document_block(scroll_viewport.rect_block_start(br), elem.ownerDocument);
                        ρσ_d["inline"] = scroll_viewport.viewport_to_document_inline(scroll_viewport.rect_inline_start(br), elem.ownerDocument);
                        return ρσ_d;
                    }).call(this);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["elem"]},
                    __module__ : {value: "read_book.flow_mode"}
                });
                return ρσ_anonfunc;
            })();
            ρσ_d["visibility"] = (function() {
                var ρσ_anonfunc = function visibility(pos) {
                    var q;
                    q = pos.block;
                    if (scroll_viewport.vertical_writing_mode && scroll_viewport.rtl) {
                        q = -q;
                    }
                    if (q + 1 < scroll_viewport.block_pos()) {
                        return -1;
                    }
                    if (q <= scroll_viewport.block_pos() + scroll_viewport.block_size()) {
                        return 0;
                    }
                    return 1;
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["pos"]},
                    __module__ : {value: "read_book.flow_mode"}
                });
                return ρσ_anonfunc;
            })();
            ρσ_d["cmp"] = (function() {
                var ρσ_anonfunc = function cmp(a, b) {
                    return a.block - b.block || a.inline - b.inline;
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["a", "b"]},
                    __module__ : {value: "read_book.flow_mode"}
                });
                return ρσ_anonfunc;
            })();
            ρσ_d["get_bounding_client_rect"] = (function() {
                var ρσ_anonfunc = function (elem) {
                    return elem.getBoundingClientRect();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["elem"]},
                    __module__ : {value: "read_book.flow_mode"}
                });
                return ρσ_anonfunc;
            })();
            return ρσ_d;
        }).call(this);
        function auto_scroll_action(action) {
            if (action === "toggle") {
                toggle_autoscroll();
            } else if (action === "start") {
                if (!is_auto_scroll_active()) {
                    toggle_autoscroll();
                }
            } else if (action === "stop") {
                if (is_auto_scroll_active()) {
                    toggle_autoscroll();
                }
            } else if (action === "resume") {
                auto_scroll_resume();
            }
            return is_auto_scroll_active();
        };
        if (!auto_scroll_action.__argnames__) Object.defineProperties(auto_scroll_action, {
            __argnames__ : {value: ["action"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function closest_preceding_element(p) {
            while (p && !p.scrollIntoView) {
                p = p.previousSibling || p.parentNode;
            }
            return p;
        };
        if (!closest_preceding_element.__argnames__) Object.defineProperties(closest_preceding_element, {
            __argnames__ : {value: ["p"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function ensure_selection_visible() {
            var s, p, r, rect, wrapper;
            s = window.getSelection();
            p = s.anchorNode;
            if (!p) {
                return;
            }
            p = closest_preceding_element(p);
            if ((typeof p !== "undefined" && p !== null ? p : Object.create(null)).scrollIntoView) {
                p.scrollIntoView();
            }
            r = s.getRangeAt(0);
            if (!r) {
                return;
            }
            rect = r.getBoundingClientRect();
            if (!rect) {
                return;
            }
            if (rect.top < 0 || rect.top >= window.innerHeight || rect.left < 0 || rect.left >= window.innerWidth) {
                wrapper = document.createElement("span");
                wrap_range(r, wrapper);
                wrapper.scrollIntoView();
                unwrap(wrapper);
            }
        };
        if (!ensure_selection_visible.__module__) Object.defineProperties(ensure_selection_visible, {
            __module__ : {value: "read_book.flow_mode"}
        });

        function ensure_selection_boundary_visible(use_end) {
            var sel, rr, r, node, x, y;
            sel = window.getSelection();
            try {
                rr = sel.getRangeAt(0);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    rr = null;
                } 
            }
            if (rr) {
                r = rr.getBoundingClientRect();
                if (r) {
                    node = (use_end) ? sel.focusNode : sel.anchorNode;
                    x = (use_end) ? scroll_viewport.rect_inline_end(r) : scroll_viewport.rect_inline_start(r);
                    if (x < 0 || x >= window.innerWidth) {
                        x = ρσ_interpolate_kwargs.call(scroll_viewport, scroll_viewport.viewport_to_document_inline, [x].concat([ρσ_desugar_kwargs({doc: node.ownerDocument})]));
                        if (use_end) {
                            x -= line_height();
                        }
                        scroll_viewport.scroll_to_in_inline_direction(x, true);
                    }
                    y = (use_end) ? scroll_viewport.rect_block_end(r) : scroll_viewport.rect_block_start(r);
                    if (y < 0 || y >= window.innerHeight) {
                        y = ρσ_interpolate_kwargs.call(scroll_viewport, scroll_viewport.viewport_to_document_block, [y].concat([ρσ_desugar_kwargs({doc: node.ownerDocument})]));
                        if (use_end) {
                            y -= line_height();
                        }
                        scroll_viewport.scroll_to_in_block_direction(y, true);
                    }
                }
            }
        };
        if (!ensure_selection_boundary_visible.__argnames__) Object.defineProperties(ensure_selection_boundary_visible, {
            __argnames__ : {value: ["use_end"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        function jump_to_cfi(cfi) {
            cfi_scroll_to(cfi, (function() {
                var ρσ_anonfunc = function (x, y) {
                    if (scroll_viewport.horizontal_writing_mode) {
                        scroll_viewport.scroll_to_in_block_direction(y);
                    } else {
                        scroll_viewport.scroll_to_in_block_direction(x);
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["x", "y"]},
                    __module__ : {value: "read_book.flow_mode"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!jump_to_cfi.__argnames__) Object.defineProperties(jump_to_cfi, {
            __argnames__ : {value: ["cfi"]},
            __module__ : {value: "read_book.flow_mode"}
        });

        ρσ_modules["read_book.flow_mode"].small_scroll_events = small_scroll_events;
        ρσ_modules["read_book.flow_mode"].last_change_spine_item_request = last_change_spine_item_request;
        ρσ_modules["read_book.flow_mode"].DIRECTION = DIRECTION;
        ρσ_modules["read_book.flow_mode"].scroll_animator = scroll_animator;
        ρσ_modules["read_book.flow_mode"].flick_animator = flick_animator;
        ρσ_modules["read_book.flow_mode"].drag_scroller = drag_scroller;
        ρσ_modules["read_book.flow_mode"].anchor_funcs = anchor_funcs;
        ρσ_modules["read_book.flow_mode"].flow_to_scroll_fraction = flow_to_scroll_fraction;
        ρσ_modules["read_book.flow_mode"].clear_small_scrolls = clear_small_scrolls;
        ρσ_modules["read_book.flow_mode"].dispatch_small_scrolls = dispatch_small_scrolls;
        ρσ_modules["read_book.flow_mode"].add_small_scroll = add_small_scroll;
        ρσ_modules["read_book.flow_mode"].report_human_scroll = report_human_scroll;
        ρσ_modules["read_book.flow_mode"]._check_for_scroll_end = _check_for_scroll_end;
        ρσ_modules["read_book.flow_mode"].check_for_scroll_end = check_for_scroll_end;
        ρσ_modules["read_book.flow_mode"].check_for_scroll_end_and_report = check_for_scroll_end_and_report;
        ρσ_modules["read_book.flow_mode"].check_for_scroll_end_and_report_no_delay = check_for_scroll_end_and_report_no_delay;
        ρσ_modules["read_book.flow_mode"].scroll_by_and_check_next_page = scroll_by_and_check_next_page;
        ρσ_modules["read_book.flow_mode"].flow_onwheel = flow_onwheel;
        ρσ_modules["read_book.flow_mode"].goto_boundary = goto_boundary;
        ρσ_modules["read_book.flow_mode"]._scroll_by_page = _scroll_by_page;
        ρσ_modules["read_book.flow_mode"].scroll_by_page = scroll_by_page;
        ρσ_modules["read_book.flow_mode"].scroll_by_page_no_delay = scroll_by_page_no_delay;
        ρσ_modules["read_book.flow_mode"].scroll_to_extend_annotation = scroll_to_extend_annotation;
        ρσ_modules["read_book.flow_mode"].is_auto_scroll_active = is_auto_scroll_active;
        ρσ_modules["read_book.flow_mode"].start_autoscroll = start_autoscroll;
        ρσ_modules["read_book.flow_mode"].toggle_autoscroll = toggle_autoscroll;
        ρσ_modules["read_book.flow_mode"].handle_shortcut = handle_shortcut;
        ρσ_modules["read_book.flow_mode"].layout = layout;
        ρσ_modules["read_book.flow_mode"].auto_scroll_resume = auto_scroll_resume;
        ρσ_modules["read_book.flow_mode"].add_visibility_listener = add_visibility_listener;
        ρσ_modules["read_book.flow_mode"].cancel_scroll = cancel_scroll;
        ρσ_modules["read_book.flow_mode"].is_scroll_end = is_scroll_end;
        ρσ_modules["read_book.flow_mode"].ScrollAnimator = ScrollAnimator;
        ρσ_modules["read_book.flow_mode"].FlickAnimator = FlickAnimator;
        ρσ_modules["read_book.flow_mode"].DragScroller = DragScroller;
        ρσ_modules["read_book.flow_mode"].cancel_drag_scroll = cancel_drag_scroll;
        ρσ_modules["read_book.flow_mode"].start_drag_scroll = start_drag_scroll;
        ρσ_modules["read_book.flow_mode"].handle_gesture = handle_gesture;
        ρσ_modules["read_book.flow_mode"].auto_scroll_action = auto_scroll_action;
        ρσ_modules["read_book.flow_mode"].closest_preceding_element = closest_preceding_element;
        ρσ_modules["read_book.flow_mode"].ensure_selection_visible = ensure_selection_visible;
        ρσ_modules["read_book.flow_mode"].ensure_selection_boundary_visible = ensure_selection_boundary_visible;
        ρσ_modules["read_book.flow_mode"].jump_to_cfi = jump_to_cfi;
    })();

    (function(){
        var __name__ = "read_book.touch";
        var HOLD_THRESHOLD, TAP_THRESHOLD, SWIPE_THRESHOLD, TAP_LINK_THRESHOLD, PINCH_THRESHOLD, GESTURE, k, gesture_id, main_touch_handler, left_margin_handler, right_margin_handler;
        var _ = ρσ_modules.gettext.gettext;

        var get_boss = ρσ_modules["read_book.globals"].get_boss;
        var ltr_page_progression = ρσ_modules["read_book.globals"].ltr_page_progression;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var opts = ρσ_modules["read_book.settings"].opts;

        var get_unit_size_in_pixels = ρσ_modules["read_book.viewport"].get_unit_size_in_pixels;
        var scroll_viewport = ρσ_modules["read_book.viewport"].scroll_viewport;

        HOLD_THRESHOLD = 750;
        TAP_THRESHOLD = 8;
        SWIPE_THRESHOLD = 64;
        TAP_LINK_THRESHOLD = 5;
        PINCH_THRESHOLD = 20;
        GESTURE = (function() {
            var ρσ_Iter = ρσ_Iterable([
    'back_zone_tap',
    'forward_zone_tap',
    'control_zone_tap',
    'long_tap',
    'two_finger_tap',
    'pinch_in',
    'pinch_out',

    'flick_inline_backward',
    'flick_inline_forward',
    'flick_block_backward',
    'flick_block_forward',

    'swipe_inline_backward_in_progress',
    'swipe_inline_forward_in_progress',
    'swipe_block_backward_in_progress',
    'swipe_block_forward_in_progress',

    'swipe_inline_backward_hold',
    'swipe_inline_forward_hold',
    'swipe_block_backward_hold',
    'swipe_block_forward_hold',

    'tap',
    'swipe',
    'pinch',
]), ρσ_Result = Object.create(null), k;
            for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                k = ρσ_Iter[ρσ_Index];
                ρσ_Result[k] = (k);
            }
            return ρσ_Result;
        })();
        function GESTURE_NAMES() {
            var ans;
            ans = GESTURE_NAMES.ans;
            if (!ans) {
                GESTURE_NAMES.ans = ans = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["back_zone_tap"] = _("Tap on back zone");
                    ρσ_d["forward_zone_tap"] = _("Tap on forward zone");
                    ρσ_d["control_zone_tap"] = _("Tap in the controls zone");
                    ρσ_d["long_tap"] = _("Long tap");
                    ρσ_d["two_finger_tap"] = _("Two finger tap");
                    ρσ_d["pinch_in"] = _("Pinch in");
                    ρσ_d["pinch_out"] = _("Pinch out");
                    ρσ_d["flick_inline_backward"] = _("Flick in writing direction, to go back");
                    ρσ_d["flick_inline_forward"] = _("Flick in writing direction, to go forward");
                    ρσ_d["flick_block_backward"] = _("Flick perpendicular to writing direction, to go forward");
                    ρσ_d["flick_block_forward"] = _("Flick perpendicular to writing direction, to go back");
                    ρσ_d["swipe_inline_backward_in_progress"] = _("Drag finger in writing direction, to go back");
                    ρσ_d["swipe_inline_forward_in_progress"] = _("Drag finger in writing direction, to go forward");
                    ρσ_d["swipe_block_backward_in_progress"] = _("Drag finger perpendicular to writing direction, to go back");
                    ρσ_d["swipe_block_forward_in_progress"] = _("Drag finger perpendicular to writing direction, to go forward");
                    ρσ_d["swipe_inline_backward_hold"] = _("Drag and hold finger in writing direction, to go back");
                    ρσ_d["swipe_inline_forward_hold"] = _("Drag and hold finger in writing direction, to go forward");
                    ρσ_d["swipe_block_backward_hold"] = _("Drag and hold finger perpendicular to writing direction, to go back");
                    ρσ_d["swipe_block_forward_hold"] = _("Drag and hold finger perpendicular to writing direction, to go forward");
                    return ρσ_d;
                }).call(this);
            }
            return ans;
        };
        if (!GESTURE_NAMES.__module__) Object.defineProperties(GESTURE_NAMES, {
            __module__ : {value: "read_book.touch"}
        });

        gesture_id = 0;
        function touch_id(touch) {
            return touch.identifier + "";
        };
        if (!touch_id.__argnames__) Object.defineProperties(touch_id, {
            __argnames__ : {value: ["touch"]},
            __module__ : {value: "read_book.touch"}
        });

        function copy_touch(t) {
            var now;
            now = window.performance.now();
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["identifier"] = touch_id(t);
                ρσ_d["page_x"] = [t.pageX];
                ρσ_d["page_y"] = [t.pageY];
                ρσ_d["viewport_x"] = [t.clientX];
                ρσ_d["viewport_y"] = [t.clientY];
                ρσ_d["active"] = true;
                ρσ_d["mtimes"] = [now];
                ρσ_d["ctime"] = now;
                ρσ_d["is_held"] = false;
                ρσ_d["x_velocity"] = 0;
                ρσ_d["y_velocity"] = 0;
                return ρσ_d;
            }).call(this);
        };
        if (!copy_touch.__argnames__) Object.defineProperties(copy_touch, {
            __argnames__ : {value: ["t"]},
            __module__ : {value: "read_book.touch"}
        });

        function update_touch(t, touch) {
            var now;
            now = window.performance.now();
            t.mtimes.push(now);
            [t.page_x.push(touch.pageX), t.page_y.push(touch.pageY)];
            [t.viewport_x.push(touch.clientX), t.viewport_y.push(touch.clientY)];
        };
        if (!update_touch.__argnames__) Object.defineProperties(update_touch, {
            __argnames__ : {value: ["t", "touch"]},
            __module__ : {value: "read_book.touch"}
        });

        function max_displacement(points) {
            var ans, first, delta, p;
            ans = 0;
            first = points[0];
            if (!(typeof first !== "undefined" && first !== null)) {
                return ans;
            }
            var ρσ_Iter0 = ρσ_Iterable(points);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                p = ρσ_Iter0[ρσ_Index0];
                delta = abs(p - first);
                if (delta > ans) {
                    ans = delta;
                }
            }
            return ans;
        };
        if (!max_displacement.__argnames__) Object.defineProperties(max_displacement, {
            __argnames__ : {value: ["points"]},
            __module__ : {value: "read_book.touch"}
        });

        function interpret_single_gesture(touch, gesture_id) {
            var max_x_displacement, max_y_displacement, ans, delta_x, delta_y, max_disp, pts, positive;
            max_x_displacement = max_displacement(touch.viewport_x);
            max_y_displacement = max_displacement(touch.viewport_y);
            ans = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["active"] = touch.active;
                ρσ_d["is_held"] = touch.is_held;
                ρσ_d["id"] = gesture_id;
                ρσ_d["start_time"] = touch.ctime;
                return ρσ_d;
            }).call(this);
            if (max(max_x_displacement, max_y_displacement) < TAP_THRESHOLD) {
                ans.type = GESTURE.tap;
                ans.viewport_x = touch.viewport_x[0];
                ans.viewport_y = touch.viewport_y[0];
                return ans;
            }
            if (touch.viewport_y.length < 2) {
                return ans;
            }
            delta_x = abs((ρσ_expr_temp = touch.viewport_x)[ρσ_expr_temp.length-1] - touch.viewport_x[0]);
            delta_y = abs((ρσ_expr_temp = touch.viewport_y)[ρσ_expr_temp.length-1] - touch.viewport_y[0]);
            max_disp = max(delta_y, delta_x);
            if (max_disp > SWIPE_THRESHOLD && min(delta_x, delta_y) / max_disp < .35) {
                ans.type = GESTURE.swipe;
                ans.axis = (delta_y > delta_x) ? "vertical" : "horizontal";
                ans.points = pts = (ans.axis === "vertical") ? touch.viewport_y : touch.viewport_x;
                ans.times = touch.mtimes;
                positive = pts[pts.length-1] > pts[0];
                if (ans.axis === "vertical") {
                    ans.direction = (positive) ? "down" : "up";
                    ans.velocity = touch.y_velocity;
                } else {
                    ans.direction = (positive) ? "right" : "left";
                    ans.velocity = touch.x_velocity;
                }
                return ans;
            }
            return ans;
        };
        if (!interpret_single_gesture.__argnames__) Object.defineProperties(interpret_single_gesture, {
            __argnames__ : {value: ["touch", "gesture_id"]},
            __module__ : {value: "read_book.touch"}
        });

        function interpret_double_gesture(touch1, touch2, gesture_id) {
            var ans, max_x_displacement1, max_x_displacement2, max_y_displacement1, max_y_displacement2, initial_distance, final_distance, distance;
            ans = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["active"] = touch1.active || touch2.active;
                ρσ_d["is_held"] = touch1.is_held || touch2.is_held;
                ρσ_d["id"] = gesture_id;
                return ρσ_d;
            }).call(this);
            max_x_displacement1 = max_displacement(touch1.viewport_x);
            max_x_displacement2 = max_displacement(touch2.viewport_x);
            max_y_displacement1 = max_displacement(touch1.viewport_y);
            max_y_displacement2 = max_displacement(touch2.viewport_y);
            if (max(max_x_displacement1, max_y_displacement1) < TAP_THRESHOLD && max(max_x_displacement2, max_y_displacement2) < TAP_THRESHOLD) {
                ans.type = GESTURE.two_finger_tap;
                ans.viewport_x1 = touch1.viewport_x[0];
                ans.viewport_y1 = touch1.viewport_y[0];
                ans.viewport_x2 = touch2.viewport_x[0];
                ans.viewport_y2 = touch2.viewport_y[0];
                return ans;
            }
            initial_distance = Math.sqrt(Math.pow((touch1.viewport_x[0] - touch2.viewport_x[0]), 2) + Math.pow((touch1.viewport_y[0] - touch2.viewport_y[0]), 2));
            final_distance = Math.sqrt(Math.pow(((ρσ_expr_temp = touch1.viewport_x)[ρσ_expr_temp.length-1] - (ρσ_expr_temp = touch2.viewport_x)[ρσ_expr_temp.length-1]), 2) + Math.pow(((ρσ_expr_temp = touch1.viewport_y)[ρσ_expr_temp.length-1] - (ρσ_expr_temp = touch2.viewport_y)[ρσ_expr_temp.length-1]), 2));
            distance = abs(final_distance - initial_distance);
            if (distance > PINCH_THRESHOLD) {
                ans.type = GESTURE.pinch;
                ans.direction = (final_distance < initial_distance) ? "in" : "out";
                ans.distance = distance;
                return ans;
            }
            return ans;
        };
        if (!interpret_double_gesture.__argnames__) Object.defineProperties(interpret_double_gesture, {
            __argnames__ : {value: ["touch1", "touch2", "gesture_id"]},
            __module__ : {value: "read_book.touch"}
        });

        function element_from_point(x, y) {
            return document.elementFromPoint(x, y);
        };
        if (!element_from_point.__argnames__) Object.defineProperties(element_from_point, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "read_book.touch"}
        });

        function find_link(x, y) {
            var p;
            p = element_from_point(x, y);
            while (p) {
                if (p.tagName && p.tagName.toLowerCase() === "a" && p.hasAttribute("href")) {
                    return p;
                }
                p = p.parentNode;
            }
        };
        if (!find_link.__argnames__) Object.defineProperties(find_link, {
            __argnames__ : {value: ["x", "y"]},
            __module__ : {value: "read_book.touch"}
        });

        function tap_on_link(gesture) {
            var x, y, link, delta_y, delta_x;
            var ρσ_Iter1 = ρσ_Iterable(ρσ_list_decorate([ 0, TAP_LINK_THRESHOLD, -TAP_LINK_THRESHOLD ]));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                delta_x = ρσ_Iter1[ρσ_Index1];
                var ρσ_Iter2 = ρσ_Iterable(ρσ_list_decorate([ 0, TAP_LINK_THRESHOLD, -TAP_LINK_THRESHOLD ]));
                for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                    delta_y = ρσ_Iter2[ρσ_Index2];
                    x = gesture.viewport_x + delta_x;
                    y = gesture.viewport_y + delta_y;
                    link = find_link(x, y);
                    if (link) {
                        link.click();
                        return true;
                    }
                }
            }
            return false;
        };
        if (!tap_on_link.__argnames__) Object.defineProperties(tap_on_link, {
            __argnames__ : {value: ["gesture"]},
            __module__ : {value: "read_book.touch"}
        });

        function TouchHandler() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            TouchHandler.prototype.__bind_methods__.call(this);
            TouchHandler.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(TouchHandler.prototype, "__bind_methods__", {value: function () {
            this.prune_expired_touches = TouchHandler.prototype.prune_expired_touches.bind(this);
            this.reset_handlers = TouchHandler.prototype.reset_handlers.bind(this);
            this.start_hold_timer = TouchHandler.prototype.start_hold_timer.bind(this);
            this.stop_hold_timer = TouchHandler.prototype.stop_hold_timer.bind(this);
            this.check_for_hold = TouchHandler.prototype.check_for_hold.bind(this);
            this.handle_touchstart = TouchHandler.prototype.handle_touchstart.bind(this);
            this.handle_touchmove = TouchHandler.prototype.handle_touchmove.bind(this);
            this.handle_touchend = TouchHandler.prototype.handle_touchend.bind(this);
            this.handle_touchcancel = TouchHandler.prototype.handle_touchcancel.bind(this);
            this.dispatch_gesture = TouchHandler.prototype.dispatch_gesture.bind(this);
        }});
        Object.defineProperties(TouchHandler.prototype,  {
            "has_active_touches": {
                "enumerable": true, 
                "get": function has_active_touches() {
                    var self = this;
                    var t, tid;
                    var ρσ_Iter3 = ρσ_Iterable(self.ongoing_touches);
                    for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                        tid = ρσ_Iter3[ρσ_Index3];
                        t = (ρσ_expr_temp = self.ongoing_touches)[(typeof tid === "number" && tid < 0) ? ρσ_expr_temp.length + tid : tid];
                        if (t.active) {
                            return true;
                        }
                    }
                    return false;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        TouchHandler.prototype.__init__ = function __init__() {
            var self = this;
            self.ongoing_touches = Object.create(null);
            self.gesture_id = null;
            self.hold_timer = null;
            self.handled_tap_hold = false;
        };
        if (!TouchHandler.prototype.__init__.__module__) Object.defineProperties(TouchHandler.prototype.__init__, {
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.__argnames__ = TouchHandler.prototype.__init__.__argnames__;
        TouchHandler.__handles_kwarg_interpolation__ = TouchHandler.prototype.__init__.__handles_kwarg_interpolation__;
        TouchHandler.prototype.prune_expired_touches = function prune_expired_touches() {
            var self = this;
            var now, expired, t, tid;
            now = window.performance.now();
            expired = [];
            var ρσ_Iter4 = ρσ_Iterable(self.ongoing_touches);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                tid = ρσ_Iter4[ρσ_Index4];
                t = (ρσ_expr_temp = self.ongoing_touches)[(typeof tid === "number" && tid < 0) ? ρσ_expr_temp.length + tid : tid];
                if (t.active) {
                    if (now - (ρσ_expr_temp = t.mtimes)[ρσ_expr_temp.length-1] > 3e3) {
                        expired.push(touch_id(t));
                    }
                }
            }
            var ρσ_Iter5 = ρσ_Iterable(expired);
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                tid = ρσ_Iter5[ρσ_Index5];
                delete self.ongoing_touches[tid];
            }
        };
        if (!TouchHandler.prototype.prune_expired_touches.__module__) Object.defineProperties(TouchHandler.prototype.prune_expired_touches, {
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.prototype.reset_handlers = function reset_handlers() {
            var self = this;
            self.stop_hold_timer();
            self.ongoing_touches = Object.create(null);
            self.gesture_id = null;
            self.handled_tap_hold = false;
        };
        if (!TouchHandler.prototype.reset_handlers.__module__) Object.defineProperties(TouchHandler.prototype.reset_handlers, {
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.prototype.start_hold_timer = function start_hold_timer() {
            var self = this;
            self.stop_hold_timer();
            self.hold_timer = window.setTimeout(self.check_for_hold, 50);
        };
        if (!TouchHandler.prototype.start_hold_timer.__module__) Object.defineProperties(TouchHandler.prototype.start_hold_timer, {
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.prototype.stop_hold_timer = function stop_hold_timer() {
            var self = this;
            if (self.hold_timer !== null) {
                window.clearTimeout(self.hold_timer);
                self.hold_timer = null;
            }
        };
        if (!TouchHandler.prototype.stop_hold_timer.__module__) Object.defineProperties(TouchHandler.prototype.stop_hold_timer, {
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.prototype.check_for_hold = function check_for_hold() {
            var self = this;
            var now, found_hold, touch, touchid;
            if (len(self.ongoing_touches) > 0) {
                now = window.performance.now();
                found_hold = false;
                var ρσ_Iter6 = ρσ_Iterable(self.ongoing_touches);
                for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                    touchid = ρσ_Iter6[ρσ_Index6];
                    touch = (ρσ_expr_temp = self.ongoing_touches)[(typeof touchid === "number" && touchid < 0) ? ρσ_expr_temp.length + touchid : touchid];
                    if (touch.active && now - (ρσ_expr_temp = touch.mtimes)[ρσ_expr_temp.length-1] > HOLD_THRESHOLD) {
                        touch.is_held = true;
                        found_hold = true;
                    }
                }
                if (found_hold) {
                    self.dispatch_gesture();
                }
                self.start_hold_timer();
            }
        };
        if (!TouchHandler.prototype.check_for_hold.__module__) Object.defineProperties(TouchHandler.prototype.check_for_hold, {
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.prototype.handle_touchstart = function handle_touchstart(ev) {
            var self = this;
            var touch;
            if (typeof ev.cancelable !== "boolean" || ev.cancelable) {
                ev.preventDefault();
            }
            ev.stopPropagation();
            self.prune_expired_touches();
            var ρσ_Iter7 = ρσ_Iterable(ev.changedTouches);
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                touch = ρσ_Iter7[ρσ_Index7];
                (ρσ_expr_temp = self.ongoing_touches)[ρσ_bound_index(touch_id(touch), ρσ_expr_temp)] = copy_touch(touch);
                if (self.gesture_id === null) {
                    gesture_id += 1;
                    self.gesture_id = gesture_id;
                    self.handled_tap_hold = false;
                }
            }
            if (len(self.ongoing_touches) > 0) {
                self.start_hold_timer();
            }
        };
        if (!TouchHandler.prototype.handle_touchstart.__argnames__) Object.defineProperties(TouchHandler.prototype.handle_touchstart, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.prototype.handle_touchmove = function handle_touchmove(ev) {
            var self = this;
            var t, touch;
            if (typeof ev.cancelable !== "boolean" || ev.cancelable) {
                ev.preventDefault();
            }
            ev.stopPropagation();
            var ρσ_Iter8 = ρσ_Iterable(ev.changedTouches);
            for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                touch = ρσ_Iter8[ρσ_Index8];
                t = (ρσ_expr_temp = self.ongoing_touches)[ρσ_bound_index(touch_id(touch), ρσ_expr_temp)];
                if (t) {
                    update_touch(t, touch);
                    self.dispatch_gesture();
                }
            }
        };
        if (!TouchHandler.prototype.handle_touchmove.__argnames__) Object.defineProperties(TouchHandler.prototype.handle_touchmove, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.prototype.handle_touchend = function handle_touchend(ev) {
            var self = this;
            var t, touch;
            if (typeof ev.cancelable !== "boolean" || ev.cancelable) {
                ev.preventDefault();
            }
            ev.stopPropagation();
            var ρσ_Iter9 = ρσ_Iterable(ev.changedTouches);
            for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                touch = ρσ_Iter9[ρσ_Index9];
                t = (ρσ_expr_temp = self.ongoing_touches)[ρσ_bound_index(touch_id(touch), ρσ_expr_temp)];
                if (t) {
                    t.active = false;
                    update_touch(t, touch);
                }
            }
            self.prune_expired_touches();
            if (!self.has_active_touches) {
                self.dispatch_gesture();
                self.reset_handlers();
            }
        };
        if (!TouchHandler.prototype.handle_touchend.__argnames__) Object.defineProperties(TouchHandler.prototype.handle_touchend, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.prototype.handle_touchcancel = function handle_touchcancel(ev) {
            var self = this;
            var tid, touch;
            if (typeof ev.cancelable !== "boolean" || ev.cancelable) {
                ev.preventDefault();
            }
            ev.stopPropagation();
            var ρσ_Iter10 = ρσ_Iterable(ev.changedTouches);
            for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                touch = ρσ_Iter10[ρσ_Index10];
                tid = touch_id(touch);
                delete self.ongoing_touches[tid];
            }
            self.gesture_id = null;
            self.handled_tap_hold = false;
        };
        if (!TouchHandler.prototype.handle_touchcancel.__argnames__) Object.defineProperties(TouchHandler.prototype.handle_touchcancel, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.prototype.dispatch_gesture = function dispatch_gesture() {
            var self = this;
            var touches, num, gesture, t;
            touches = self.ongoing_touches;
            num = len(touches);
            gesture = Object.create(null);
            if (num === 1) {
                gesture = interpret_single_gesture(touches[ρσ_bound_index(Object.keys(touches)[0], touches)], self.gesture_id);
            } else if (num === 2) {
                t = Object.keys(touches);
                gesture = interpret_double_gesture(touches[ρσ_bound_index(t[0], touches)], touches[ρσ_bound_index(t[1], touches)], self.gesture_id);
            }
            if (!(typeof gesture !== "undefined" && gesture !== null ? gesture : Object.create(null)).type) {
                return;
            }
            self.handle_gesture(gesture);
        };
        if (!TouchHandler.prototype.dispatch_gesture.__module__) Object.defineProperties(TouchHandler.prototype.dispatch_gesture, {
            __module__ : {value: "read_book.touch"}
        });
        TouchHandler.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        TouchHandler.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(TouchHandler.prototype, "__bases__", {value: []});
        

        function inch_in_pixels() {
            var ans;
            ans = inch_in_pixels.ans;
            if (!ans) {
                ans = inch_in_pixels.ans = max(2, get_unit_size_in_pixels("in"));
            }
            return ans;
        };
        if (!inch_in_pixels.__module__) Object.defineProperties(inch_in_pixels, {
            __module__ : {value: "read_book.touch"}
        });

        function BookTouchHandler() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            BookTouchHandler.prototype.__bind_methods__.call(this);
            BookTouchHandler.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(BookTouchHandler, TouchHandler);
        Object.defineProperty(BookTouchHandler.prototype, "__bind_methods__", {value: function () {
            TouchHandler.prototype.__bind_methods__ && TouchHandler.prototype.__bind_methods__.call(this);
            this.handle_gesture = BookTouchHandler.prototype.handle_gesture.bind(this);
            this.__repr__ = BookTouchHandler.prototype.__repr__.bind(this);
        }});
        BookTouchHandler.prototype.__init__ = function __init__() {
            var self = this;
            var for_side_margin = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.for_side_margin : arguments[0];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "for_side_margin")){
                for_side_margin = ρσ_kwargs_obj.for_side_margin;
            }
            self.for_side_margin = for_side_margin;
            TouchHandler.prototype.__init__.call(self);
        };
        if (!BookTouchHandler.prototype.__init__.__defaults__) Object.defineProperties(BookTouchHandler.prototype.__init__, {
            __defaults__ : {value: {for_side_margin:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["for_side_margin"]},
            __module__ : {value: "read_book.touch"}
        });
        BookTouchHandler.__argnames__ = BookTouchHandler.prototype.__init__.__argnames__;
        BookTouchHandler.__handles_kwarg_interpolation__ = BookTouchHandler.prototype.__init__.__handles_kwarg_interpolation__;
        BookTouchHandler.prototype.handle_gesture = function handle_gesture(gesture) {
            var self = this;
            var inch, limit, backward_dir, direction, inline_dir, axis;
            if (gesture.type === GESTURE.tap) {
                if (gesture.is_held) {
                    if (!self.for_side_margin && !self.handled_tap_hold && window.performance.now() - gesture.start_time >= HOLD_THRESHOLD) {
                        self.handled_tap_hold = true;
                        gesture.type = GESTURE.long_tap;
                        get_boss().handle_gesture(gesture);
                    }
                    return;
                }
                if (!gesture.active) {
                    if (self.for_side_margin || !tap_on_link(gesture)) {
                        inch = inch_in_pixels();
                        if (gesture.viewport_y < min(100, scroll_viewport.height() / 4)) {
                            gesture.type = GESTURE.control_zone_tap;
                        } else {
                            limit = inch;
                            if (ltr_page_progression() && !opts.reverse_page_turn_zones) {
                                if (gesture.viewport_x < min(limit, scroll_viewport.width() / 4)) {
                                    gesture.type = GESTURE.back_zone_tap;
                                } else {
                                    gesture.type = GESTURE.forward_zone_tap;
                                }
                            } else {
                                if (gesture.viewport_x > max(scroll_viewport.width() - limit, scroll_viewport.width() * (3 / 4))) {
                                    gesture.type = GESTURE.back_zone_tap;
                                } else {
                                    gesture.type = GESTURE.forward_zone_tap;
                                }
                            }
                        }
                    }
                }
            } else if (gesture.type === GESTURE.pinch) {
                if (gesture.active) {
                    return;
                }
                gesture.type = (gesture.direction === "in") ? GESTURE.pinch_in : GESTURE.pinch_out;
            } else if (gesture.type === GESTURE.two_finger_tap) {
                if (gesture.active) {
                    return;
                }
            } else if (gesture.type === "swipe") {
                backward_dir = (gesture.axis === "vertical") ? "down" : (ltr_page_progression()) ? "right" : "left";
                direction = (gesture.direction === backward_dir) ? "backward" : "forward";
                inline_dir = (scroll_viewport.vertical_writing_mode) ? "vertical" : "horizontal";
                axis = (gesture.axis === inline_dir) ? "inline" : "block";
                if (gesture.active) {
                    gesture.type = GESTURE[ρσ_bound_index("swipe_" + ρσ_str.format("{}", axis) + "_" + ρσ_str.format("{}", direction) + "" + ((gesture.is_held) ? "_hold" : "_in_progress"), GESTURE)];
                } else if (!gesture.is_held) {
                    gesture.type = GESTURE[ρσ_bound_index("flick_" + ρσ_str.format("{}", axis) + "_" + ρσ_str.format("{}", direction) + "", GESTURE)];
                }
            }
            if (self.for_side_margin) {
                ui_operations.forward_gesture(gesture);
            } else {
                get_boss().handle_gesture(gesture);
            }
        };
        if (!BookTouchHandler.prototype.handle_gesture.__argnames__) Object.defineProperties(BookTouchHandler.prototype.handle_gesture, {
            __argnames__ : {value: ["gesture"]},
            __module__ : {value: "read_book.touch"}
        });
        BookTouchHandler.prototype.__repr__ = function __repr__() {
            var self = this;
            return "BookTouchHandler:for_side_margin:" + self.for_side_margin;
        };
        if (!BookTouchHandler.prototype.__repr__.__module__) Object.defineProperties(BookTouchHandler.prototype.__repr__, {
            __module__ : {value: "read_book.touch"}
        });
        BookTouchHandler.prototype.__str__ = function __str__ () {
            if(TouchHandler.prototype.__str__) return TouchHandler.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(BookTouchHandler.prototype, "__bases__", {value: [TouchHandler]});

        main_touch_handler = new BookTouchHandler;
        left_margin_handler = new BookTouchHandler("left");
        right_margin_handler = new BookTouchHandler("right");
        function install_handlers(elem, handler, passive) {
            var options;
            options = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["capture"] = true;
                ρσ_d["passive"] = !!passive;
                return ρσ_d;
            }).call(this);
            elem.addEventListener("touchstart", handler.handle_touchstart, options);
            elem.addEventListener("touchmove", handler.handle_touchmove, options);
            elem.addEventListener("touchend", handler.handle_touchend, options);
            elem.addEventListener("touchcancel", handler.handle_touchcancel, options);
        };
        if (!install_handlers.__argnames__) Object.defineProperties(install_handlers, {
            __argnames__ : {value: ["elem", "handler", "passive"]},
            __module__ : {value: "read_book.touch"}
        });

        function create_handlers() {
            install_handlers(document, main_touch_handler);
            document.body.style.touchAction = "none";
        };
        if (!create_handlers.__module__) Object.defineProperties(create_handlers, {
            __module__ : {value: "read_book.touch"}
        });

        function reset_handlers() {
            main_touch_handler.reset_handlers();
        };
        if (!reset_handlers.__module__) Object.defineProperties(reset_handlers, {
            __module__ : {value: "read_book.touch"}
        });

        function set_left_margin_handler(elem) {
            install_handlers(elem, left_margin_handler);
        };
        if (!set_left_margin_handler.__argnames__) Object.defineProperties(set_left_margin_handler, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.touch"}
        });

        function set_right_margin_handler(elem) {
            install_handlers(elem, right_margin_handler);
        };
        if (!set_right_margin_handler.__argnames__) Object.defineProperties(set_right_margin_handler, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.touch"}
        });

        ρσ_modules["read_book.touch"].HOLD_THRESHOLD = HOLD_THRESHOLD;
        ρσ_modules["read_book.touch"].TAP_THRESHOLD = TAP_THRESHOLD;
        ρσ_modules["read_book.touch"].SWIPE_THRESHOLD = SWIPE_THRESHOLD;
        ρσ_modules["read_book.touch"].TAP_LINK_THRESHOLD = TAP_LINK_THRESHOLD;
        ρσ_modules["read_book.touch"].PINCH_THRESHOLD = PINCH_THRESHOLD;
        ρσ_modules["read_book.touch"].GESTURE = GESTURE;
        ρσ_modules["read_book.touch"].k = k;
        ρσ_modules["read_book.touch"].gesture_id = gesture_id;
        ρσ_modules["read_book.touch"].main_touch_handler = main_touch_handler;
        ρσ_modules["read_book.touch"].left_margin_handler = left_margin_handler;
        ρσ_modules["read_book.touch"].right_margin_handler = right_margin_handler;
        ρσ_modules["read_book.touch"].GESTURE_NAMES = GESTURE_NAMES;
        ρσ_modules["read_book.touch"].touch_id = touch_id;
        ρσ_modules["read_book.touch"].copy_touch = copy_touch;
        ρσ_modules["read_book.touch"].update_touch = update_touch;
        ρσ_modules["read_book.touch"].max_displacement = max_displacement;
        ρσ_modules["read_book.touch"].interpret_single_gesture = interpret_single_gesture;
        ρσ_modules["read_book.touch"].interpret_double_gesture = interpret_double_gesture;
        ρσ_modules["read_book.touch"].element_from_point = element_from_point;
        ρσ_modules["read_book.touch"].find_link = find_link;
        ρσ_modules["read_book.touch"].tap_on_link = tap_on_link;
        ρσ_modules["read_book.touch"].TouchHandler = TouchHandler;
        ρσ_modules["read_book.touch"].inch_in_pixels = inch_in_pixels;
        ρσ_modules["read_book.touch"].BookTouchHandler = BookTouchHandler;
        ρσ_modules["read_book.touch"].install_handlers = install_handlers;
        ρσ_modules["read_book.touch"].create_handlers = create_handlers;
        ρσ_modules["read_book.touch"].reset_handlers = reset_handlers;
        ρσ_modules["read_book.touch"].set_left_margin_handler = set_left_margin_handler;
        ρσ_modules["read_book.touch"].set_right_margin_handler = set_right_margin_handler;
    })();

    (function(){
        var __name__ = "read_book.gestures";
        var only_flow_swipe_mode_actions, only_tap_actions, default_actions_for_gesture, allowed_actions_for_two_fingers;
        var GESTURE = ρσ_modules["read_book.touch"].GESTURE;

        var opts = ρσ_modules["read_book.settings"].opts;

        var _ = ρσ_modules.gettext.gettext;

        function get_action_descriptions() {
            if (!get_action_descriptions.ans) {
                get_action_descriptions.ans = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["prev_page"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Previous page");
                        ρσ_d["long"] = _("Scroll to the previous page, if more than one page is displayed on the screen only a single page is scrolled");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["next_page"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Next page");
                        ρσ_d["long"] = _("Scroll to the next page, if more than one page is displayed on the screen only a single page is scrolled");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["prev_screen"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Previous screen");
                        ρσ_d["long"] = _("Scroll to the previous screen, if more than one page is displayed on the screen all pages are scrolled");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["next_screen"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Next screen");
                        ρσ_d["long"] = _("Scroll to the next screen, if more than one page is displayed on the screen all pages are scrolled");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["show_chrome"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Show controls");
                        ρσ_d["long"] = _("Show the controls for the viewer including Preferences, Go to, etc.");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["highlight_or_inspect"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Highlight or inspect");
                        ρσ_d["long"] = _("Highlight the word under the tap point or view the image under the tap or select the highlight under the tap");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["decrease_font_size"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Make text smaller");
                        ρσ_d["long"] = _("Decrease the font size");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["increase_font_size"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Make text bigger");
                        ρσ_d["long"] = _("Increase the font size");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["next_section"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Next chapter");
                        ρσ_d["long"] = _("Scroll to the start of the next section or chapter in the book");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["prev_section"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Previous chapter");
                        ρσ_d["long"] = _("Scroll to the start of the previous section or chapter in the book");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["pan"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Pan the contents");
                        ρσ_d["long"] = _("Scroll the screen contents in tandem with finger movement");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["animated_scroll"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("Flick scroll");
                        ρσ_d["long"] = _("Scroll the screen contents with momentum based on how fast you flick your finger");
                        return ρσ_d;
                    }).call(this);
                    ρσ_d["none"] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["short"] = _("No action");
                        ρσ_d["long"] = _("Ignore this gesture performing no action in response to it");
                        return ρσ_d;
                    }).call(this);
                    return ρσ_d;
                }).call(this);
            }
            return get_action_descriptions.ans;
        };
        if (!get_action_descriptions.__module__) Object.defineProperties(get_action_descriptions, {
            __module__ : {value: "read_book.gestures"}
        });

        only_flow_swipe_mode_actions = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["pan"] = true;
            ρσ_d["animated_scroll"] = true;
            return ρσ_d;
        }).call(this);
        only_tap_actions = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["highlight_or_inspect"] = true;
            return ρσ_d;
        }).call(this);
        default_actions_for_gesture = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["common"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d[GESTURE.back_zone_tap] = "prev_page";
                ρσ_d[GESTURE.forward_zone_tap] = "next_page";
                ρσ_d[GESTURE.control_zone_tap] = "show_chrome";
                ρσ_d[GESTURE.long_tap] = "highlight_or_inspect";
                ρσ_d[GESTURE.two_finger_tap] = "show_chrome";
                ρσ_d[GESTURE.pinch_in] = "decrease_font_size";
                ρσ_d[GESTURE.pinch_out] = "increase_font_size";
                return ρσ_d;
            }).call(this);
            ρσ_d["flow_mode"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d[GESTURE.swipe_inline_backward_in_progress] = "pan";
                ρσ_d[GESTURE.swipe_inline_forward_in_progress] = "pan";
                ρσ_d[GESTURE.swipe_block_backward_in_progress] = "pan";
                ρσ_d[GESTURE.swipe_block_forward_in_progress] = "pan";
                ρσ_d[GESTURE.flick_block_forward] = "animated_scroll";
                ρσ_d[GESTURE.flick_block_backward] = "animated_scroll";
                ρσ_d[GESTURE.flick_inline_forward] = "animated_scroll";
                ρσ_d[GESTURE.flick_inline_backward] = "animated_scroll";
                return ρσ_d;
            }).call(this);
            ρσ_d["paged_mode"] = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d[GESTURE.flick_block_forward] = "next_section";
                ρσ_d[GESTURE.flick_block_backward] = "prev_section";
                ρσ_d[GESTURE.flick_inline_forward] = "next_screen";
                ρσ_d[GESTURE.flick_inline_backward] = "prev_screen";
                ρσ_d[GESTURE.swipe_inline_forward_hold] = "next_screen";
                ρσ_d[GESTURE.swipe_inline_backward_hold] = "prev_screen";
                return ρσ_d;
            }).call(this);
            return ρσ_d;
        }).call(this);
        function current_action_for_gesture_type(overrides, gesture_type, in_flow_mode) {
            var mode, mode_overrides, common_overrides;
            mode = (in_flow_mode) ? "flow_mode" : "paged_mode";
            mode_overrides = overrides[(typeof mode === "number" && mode < 0) ? overrides.length + mode : mode] || Object.create(null);
            if (mode_overrides[(typeof gesture_type === "number" && gesture_type < 0) ? mode_overrides.length + gesture_type : gesture_type]) {
                return mode_overrides[(typeof gesture_type === "number" && gesture_type < 0) ? mode_overrides.length + gesture_type : gesture_type];
            }
            common_overrides = overrides.common || Object.create(null);
            if (common_overrides[(typeof gesture_type === "number" && gesture_type < 0) ? common_overrides.length + gesture_type : gesture_type]) {
                return common_overrides[(typeof gesture_type === "number" && gesture_type < 0) ? common_overrides.length + gesture_type : gesture_type];
            }
            if ((ρσ_expr_temp = default_actions_for_gesture[(typeof mode === "number" && mode < 0) ? default_actions_for_gesture.length + mode : mode])[(typeof gesture_type === "number" && gesture_type < 0) ? ρσ_expr_temp.length + gesture_type : gesture_type]) {
                return (ρσ_expr_temp = default_actions_for_gesture[(typeof mode === "number" && mode < 0) ? default_actions_for_gesture.length + mode : mode])[(typeof gesture_type === "number" && gesture_type < 0) ? ρσ_expr_temp.length + gesture_type : gesture_type];
            }
            return (ρσ_expr_temp = default_actions_for_gesture.common)[(typeof gesture_type === "number" && gesture_type < 0) ? ρσ_expr_temp.length + gesture_type : gesture_type] || "none";
        };
        if (!current_action_for_gesture_type.__argnames__) Object.defineProperties(current_action_for_gesture_type, {
            __argnames__ : {value: ["overrides", "gesture_type", "in_flow_mode"]},
            __module__ : {value: "read_book.gestures"}
        });

        function action_for_gesture(gesture, in_flow_mode) {
            return current_action_for_gesture_type(opts.gesture_overrides, gesture.type, in_flow_mode);
        };
        if (!action_for_gesture.__argnames__) Object.defineProperties(action_for_gesture, {
            __argnames__ : {value: ["gesture", "in_flow_mode"]},
            __module__ : {value: "read_book.gestures"}
        });

        function allowed_actions_for_tap() {
            return (function() {
                var ρσ_Iter = ρσ_Iterable(Object.keys(get_action_descriptions())), ρσ_Result = [], ac;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    ac = ρσ_Iter[ρσ_Index];
                    if (!only_flow_swipe_mode_actions[(typeof ac === "number" && ac < 0) ? only_flow_swipe_mode_actions.length + ac : ac]) {
                        ρσ_Result.push(ac);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
        };
        if (!allowed_actions_for_tap.__module__) Object.defineProperties(allowed_actions_for_tap, {
            __module__ : {value: "read_book.gestures"}
        });

        function allowed_actions_for_paged_mode_swipe() {
            return (function() {
                var ρσ_Iter = ρσ_Iterable(Object.keys(get_action_descriptions())), ρσ_Result = [], ac;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    ac = ρσ_Iter[ρσ_Index];
                    if (!only_flow_swipe_mode_actions[(typeof ac === "number" && ac < 0) ? only_flow_swipe_mode_actions.length + ac : ac] && !only_tap_actions[(typeof ac === "number" && ac < 0) ? only_tap_actions.length + ac : ac]) {
                        ρσ_Result.push(ac);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
        };
        if (!allowed_actions_for_paged_mode_swipe.__module__) Object.defineProperties(allowed_actions_for_paged_mode_swipe, {
            __module__ : {value: "read_book.gestures"}
        });

        allowed_actions_for_two_fingers = allowed_actions_for_paged_mode_swipe;
        function allowed_actions_for_flow_mode_flick() {
            return (function() {
                var ρσ_Iter = ρσ_Iterable(Object.keys(get_action_descriptions())), ρσ_Result = [], ac;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    ac = ρσ_Iter[ρσ_Index];
                    if (!only_tap_actions[(typeof ac === "number" && ac < 0) ? only_tap_actions.length + ac : ac]) {
                        ρσ_Result.push(ac);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
        };
        if (!allowed_actions_for_flow_mode_flick.__module__) Object.defineProperties(allowed_actions_for_flow_mode_flick, {
            __module__ : {value: "read_book.gestures"}
        });

        function allowed_actions_for_flow_mode_drag() {
            return ρσ_list_decorate([ "pan", "none" ]);
        };
        if (!allowed_actions_for_flow_mode_drag.__module__) Object.defineProperties(allowed_actions_for_flow_mode_drag, {
            __module__ : {value: "read_book.gestures"}
        });

        ρσ_modules["read_book.gestures"].only_flow_swipe_mode_actions = only_flow_swipe_mode_actions;
        ρσ_modules["read_book.gestures"].only_tap_actions = only_tap_actions;
        ρσ_modules["read_book.gestures"].default_actions_for_gesture = default_actions_for_gesture;
        ρσ_modules["read_book.gestures"].allowed_actions_for_two_fingers = allowed_actions_for_two_fingers;
        ρσ_modules["read_book.gestures"].get_action_descriptions = get_action_descriptions;
        ρσ_modules["read_book.gestures"].current_action_for_gesture_type = current_action_for_gesture_type;
        ρσ_modules["read_book.gestures"].action_for_gesture = action_for_gesture;
        ρσ_modules["read_book.gestures"].allowed_actions_for_tap = allowed_actions_for_tap;
        ρσ_modules["read_book.gestures"].allowed_actions_for_paged_mode_swipe = allowed_actions_for_paged_mode_swipe;
        ρσ_modules["read_book.gestures"].allowed_actions_for_flow_mode_flick = allowed_actions_for_flow_mode_flick;
        ρσ_modules["read_book.gestures"].allowed_actions_for_flow_mode_drag = allowed_actions_for_flow_mode_drag;
    })();

    (function(){
        var __name__ = "complete";
        var ensure_id = ρσ_modules.dom.ensure_id;
        var unique_id = ρσ_modules.dom.unique_id;
        var clear = ρσ_modules.dom.clear;
        var svgicon = ρσ_modules.dom.svgicon;

        var _ = ρσ_modules.gettext.gettext;

        var E = ρσ_modules.elementmaker.E;

        var local_storage = ρσ_modules.session.local_storage;

        var CompletionPopup = ρσ_modules.popups.CompletionPopup;

        var uniq = ρσ_modules.utils.uniq;

        function EditWithComplete() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            EditWithComplete.prototype.__bind_methods__.call(this);
            EditWithComplete.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(EditWithComplete.prototype, "__bind_methods__", {value: function () {
            this.apply_completion = EditWithComplete.prototype.apply_completion.bind(this);
            this.onkeydown = EditWithComplete.prototype.onkeydown.bind(this);
            this.oninput = EditWithComplete.prototype.oninput.bind(this);
            this.hide_completion_popup = EditWithComplete.prototype.hide_completion_popup.bind(this);
            this.add_associated_widget = EditWithComplete.prototype.add_associated_widget.bind(this);
            this.set_all_items = EditWithComplete.prototype.set_all_items.bind(this);
        }});
        Object.defineProperties(EditWithComplete.prototype,  {
            "text_input": {
                "enumerable": true, 
                "get": function text_input() {
                    var self = this;
                    return document.getElementById(self.input_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        EditWithComplete.prototype.__init__ = function __init__() {
            var self = this;
            var name = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var placeholder = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.placeholder : arguments[1];
            var tooltip = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.tooltip : arguments[2];
            var parent = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.parent : arguments[3];
            var input_type = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.input_type : arguments[4];
            var onenterkey = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? __init__.__defaults__.onenterkey : arguments[5];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "placeholder")){
                placeholder = ρσ_kwargs_obj.placeholder;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "tooltip")){
                tooltip = ρσ_kwargs_obj.tooltip;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "parent")){
                parent = ρσ_kwargs_obj.parent;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "input_type")){
                input_type = ρσ_kwargs_obj.input_type;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "onenterkey")){
                onenterkey = ρσ_kwargs_obj.onenterkey;
            }
            var inpt;
            inpt = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: input_type, name: name, title: tooltip || "", placeholder: placeholder || "", autocomplete: "off", style: "width: 0; flex-grow: 1; min-width: 6em"})]);
            self.input_id = ensure_id(inpt);
            self.onenterkey = onenterkey;
            self.completion_popup = ρσ_interpolate_kwargs_constructor.call(Object.create(CompletionPopup.prototype), false, CompletionPopup, [ρσ_desugar_kwargs({parent: parent, onselect: self.apply_completion})]);
            inpt.addEventListener("keydown", self.onkeydown);
            inpt.addEventListener("input", self.oninput);
            self.completion_popup.add_associated_widget(inpt);
            if (parent) {
                parent.appendChild(inpt);
            }
        };
        if (!EditWithComplete.prototype.__init__.__defaults__) Object.defineProperties(EditWithComplete.prototype.__init__, {
            __defaults__ : {value: {placeholder:null, tooltip:null, parent:null, input_type:"text", onenterkey:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["name", "placeholder", "tooltip", "parent", "input_type", "onenterkey"]},
            __module__ : {value: "complete"}
        });
        EditWithComplete.__argnames__ = EditWithComplete.prototype.__init__.__argnames__;
        EditWithComplete.__handles_kwarg_interpolation__ = EditWithComplete.prototype.__init__.__handles_kwarg_interpolation__;
        EditWithComplete.prototype.apply_completion = function apply_completion(text) {
            var self = this;
            var ti;
            if (text) {
                ti = self.text_input;
                ti.value = text;
                ti.focus();
                return true;
            }
        };
        if (!EditWithComplete.prototype.apply_completion.__argnames__) Object.defineProperties(EditWithComplete.prototype.apply_completion, {
            __argnames__ : {value: ["text"]},
            __module__ : {value: "complete"}
        });
        EditWithComplete.prototype.onkeydown = function onkeydown(event) {
            var self = this;
            var ti;
            if (self.completion_popup.is_visible && self.completion_popup.handle_keydown(event)) {
                [event.preventDefault(), event.stopPropagation()];
                return;
            }
            if (event.key === "Enter") {
                if (self.completion_popup.is_visible) {
                    if (self.apply_completion(self.completion_popup.current_text)) {
                        self.completion_popup.hide();
                        [event.preventDefault(), event.stopPropagation()];
                        return;
                    }
                }
                if (self.onenterkey) {
                    [event.preventDefault(), event.stopPropagation()];
                    self.onenterkey();
                }
            } else if (event.key === "Tab") {
                if (self.completion_popup.is_visible) {
                    if (self.apply_completion(self.completion_popup.current_text)) {
                        self.completion_popup.hide();
                    } else {
                        self.completion_popup.move_highlight();
                    }
                    [event.preventDefault(), event.stopPropagation()];
                }
            } else if (event.key === "ArrowDown") {
                ti = self.text_input;
                if (!ti.value) {
                    self.completion_popup.set_query("");
                    self.completion_popup.popup(ti);
                    [event.preventDefault(), event.stopPropagation()];
                }
            }
        };
        if (!EditWithComplete.prototype.onkeydown.__argnames__) Object.defineProperties(EditWithComplete.prototype.onkeydown, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "complete"}
        });
        EditWithComplete.prototype.oninput = function oninput(event) {
            var self = this;
            var ti;
            ti = self.text_input;
            self.completion_popup.set_query(ti.value || "");
            self.completion_popup.popup(ti);
        };
        if (!EditWithComplete.prototype.oninput.__argnames__) Object.defineProperties(EditWithComplete.prototype.oninput, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "complete"}
        });
        EditWithComplete.prototype.hide_completion_popup = function hide_completion_popup() {
            var self = this;
            self.completion_popup.hide();
        };
        if (!EditWithComplete.prototype.hide_completion_popup.__module__) Object.defineProperties(EditWithComplete.prototype.hide_completion_popup, {
            __module__ : {value: "complete"}
        });
        EditWithComplete.prototype.add_associated_widget = function add_associated_widget(widget_or_id) {
            var self = this;
            self.completion_popup.add_associated_widget(widget_or_id);
        };
        if (!EditWithComplete.prototype.add_associated_widget.__argnames__) Object.defineProperties(EditWithComplete.prototype.add_associated_widget, {
            __argnames__ : {value: ["widget_or_id"]},
            __module__ : {value: "complete"}
        });
        EditWithComplete.prototype.set_all_items = function set_all_items(items) {
            var self = this;
            self.completion_popup.set_all_items(items);
        };
        if (!EditWithComplete.prototype.set_all_items.__argnames__) Object.defineProperties(EditWithComplete.prototype.set_all_items, {
            __argnames__ : {value: ["items"]},
            __module__ : {value: "complete"}
        });
        EditWithComplete.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        EditWithComplete.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(EditWithComplete.prototype, "__bases__", {value: []});
        

        function create_search_bar() {
            var action = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var name = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var tooltip = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_search_bar.__defaults__.tooltip : arguments[2];
            var placeholder = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_search_bar.__defaults__.placeholder : arguments[3];
            var button = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_search_bar.__defaults__.button : arguments[4];
            var history_size = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_search_bar.__defaults__.history_size : arguments[5];
            var associated_widgets = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_search_bar.__defaults__.associated_widgets : arguments[6];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "tooltip")){
                tooltip = ρσ_kwargs_obj.tooltip;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "placeholder")){
                placeholder = ρσ_kwargs_obj.placeholder;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "button")){
                button = ρσ_kwargs_obj.button;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "history_size")){
                history_size = ρσ_kwargs_obj.history_size;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "associated_widgets")){
                associated_widgets = ρσ_kwargs_obj.associated_widgets;
            }
            var parent, ewc, history_name, inp, w;
            parent = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display:flex; gap: 0.65rem; align-items: center; justify-content: space-between", data_component: "search_box"})]);
            ewc = ρσ_interpolate_kwargs_constructor.call(Object.create(EditWithComplete.prototype), false, EditWithComplete, [name].concat([ρσ_desugar_kwargs({parent: parent, tooltip: tooltip || placeholder, placeholder: placeholder, input_type: "search"})]));
            parent.lastChild.style.width = "100%";
            history_name = "search-bar-history-" + name;
            function update_completion_items() {
                var items;
                items = local_storage().get(history_name);
                if ((typeof items !== "undefined" && items !== null ? items : Object.create(null)).length) {
                    ewc.set_all_items(items);
                }
            };
            if (!update_completion_items.__module__) Object.defineProperties(update_completion_items, {
                __module__ : {value: "complete"}
            });

            update_completion_items();
            function trigger() {
                var text, items, idx;
                text = ewc.text_input.value;
                ewc.hide_completion_popup();
                action(text);
                if (text && text.strip()) {
                    items = local_storage().get(history_name) || [];
                    idx = items.indexOf(text);
                    if (idx > -1) {
                        items.splice(idx, 1);
                    }
                    items.unshift(text);
                    local_storage().set(history_name, uniq(items.slice(0, history_size)));
                    update_completion_items();
                }
            };
            if (!trigger.__module__) Object.defineProperties(trigger, {
                __module__ : {value: "complete"}
            });

            ewc.onenterkey = trigger;
            inp = parent.querySelector("input");
            inp.addEventListener("search", trigger);
            if (button === "icon-button") {
                button = ρσ_interpolate_kwargs.call(E, E.a, [svgicon("search")].concat([ρσ_desugar_kwargs({class_: "calibre-icon-button", style: "margin-left: auto", href: "javascript:void(0)", title: _("Search"), onmousedown: (function() {
                    var ρσ_anonfunc = function (evt) {
                        evt.preventDefault();
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["evt"]},
                        __module__ : {value: "complete"}
                    });
                    return ρσ_anonfunc;
                })()})]));
                parent.appendChild(button);
            }
            if (button) {
                ewc.add_associated_widget(button);
                button.addEventListener("click", trigger);
            }
            if (associated_widgets !== null) {
                var ρσ_Iter0 = ρσ_Iterable(associated_widgets);
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    w = ρσ_Iter0[ρσ_Index0];
                    ewc.add_associated_widget(w);
                }
            }
            return parent;
        };
        if (!create_search_bar.__defaults__) Object.defineProperties(create_search_bar, {
            __defaults__ : {value: {tooltip:null, placeholder:null, button:null, history_size:100, associated_widgets:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["action", "name", "tooltip", "placeholder", "button", "history_size", "associated_widgets"]},
            __module__ : {value: "complete"}
        });

        function create_simple_input_with_history_native() {
            var name = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var tooltip = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_simple_input_with_history_native.__defaults__.tooltip : arguments[1];
            var placeholder = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_simple_input_with_history_native.__defaults__.placeholder : arguments[2];
            var history_size = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_simple_input_with_history_native.__defaults__.history_size : arguments[3];
            var input_type = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_simple_input_with_history_native.__defaults__.input_type : arguments[4];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "tooltip")){
                tooltip = ρσ_kwargs_obj.tooltip;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "placeholder")){
                placeholder = ρσ_kwargs_obj.placeholder;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "history_size")){
                history_size = ρσ_kwargs_obj.history_size;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "input_type")){
                input_type = ρσ_kwargs_obj.input_type;
            }
            var dl_id, dl, history_name, ans;
            dl_id = unique_id();
            dl = document.createElement("datalist");
            dl.id = dl_id;
            history_name = "simple_input_history_" + ρσ_str.format("{}", name) + "";
            function update_completion_items(x) {
                var items, dl, item;
                items = local_storage().get(history_name);
                dl = x || document.getElementById(dl_id);
                if (dl) {
                    clear(dl);
                    if ((typeof items !== "undefined" && items !== null ? items : Object.create(null)).length) {
                        var ρσ_Iter1 = ρσ_Iterable(items);
                        for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                            item = ρσ_Iter1[ρσ_Index1];
                            dl.appendChild(ρσ_interpolate_kwargs.call(E, E.option, [ρσ_desugar_kwargs({value: item})]));
                        }
                    }
                }
            };
            if (!update_completion_items.__argnames__) Object.defineProperties(update_completion_items, {
                __argnames__ : {value: ["x"]},
                __module__ : {value: "complete"}
            });

            function save_completion_items() {
                var text, items, idx;
                text = document.getElementById(dl_id).nextSibling.value;
                if (text && text.strip()) {
                    items = local_storage().get(history_name) || [];
                    idx = items.indexOf(text);
                    if (idx > -1) {
                        items.splice(idx, 1);
                    }
                    items.unshift(text);
                    local_storage().set(history_name, uniq(items.slice(0, history_size)));
                    update_completion_items();
                }
            };
            if (!save_completion_items.__module__) Object.defineProperties(save_completion_items, {
                __module__ : {value: "complete"}
            });

            update_completion_items(dl);
            ans = ρσ_interpolate_kwargs.call(E, E.span, [dl, ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: input_type, name: name, list: dl_id, title: tooltip || "", placeholder: placeholder || ""})])].concat([ρσ_desugar_kwargs({data_calibre_history_input: "1"})]));
            ans.addEventListener("save_history", save_completion_items);
            return ans;
        };
        if (!create_simple_input_with_history_native.__defaults__) Object.defineProperties(create_simple_input_with_history_native, {
            __defaults__ : {value: {tooltip:null, placeholder:null, history_size:100, input_type:"text"}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["name", "tooltip", "placeholder", "history_size", "input_type"]},
            __module__ : {value: "complete"}
        });

        function create_simple_input_with_history() {
            var name = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var tooltip = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_simple_input_with_history.__defaults__.tooltip : arguments[1];
            var placeholder = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_simple_input_with_history.__defaults__.placeholder : arguments[2];
            var history_size = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_simple_input_with_history.__defaults__.history_size : arguments[3];
            var input_type = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_simple_input_with_history.__defaults__.input_type : arguments[4];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "tooltip")){
                tooltip = ρσ_kwargs_obj.tooltip;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "placeholder")){
                placeholder = ρσ_kwargs_obj.placeholder;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "history_size")){
                history_size = ρσ_kwargs_obj.history_size;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "input_type")){
                input_type = ρσ_kwargs_obj.input_type;
            }
            var parent, ewc, history_name;
            parent = ρσ_interpolate_kwargs.call(E, E.span, [ρσ_desugar_kwargs({data_calibre_history_input: "1"})]);
            ewc = ρσ_interpolate_kwargs_constructor.call(Object.create(EditWithComplete.prototype), false, EditWithComplete, [name].concat([ρσ_desugar_kwargs({parent: parent, tooltip: tooltip, placeholder: placeholder, input_type: input_type})]));
            history_name = "simple_input_history_" + ρσ_str.format("{}", name) + "";
            function update_completion_items() {
                var items;
                items = local_storage().get(history_name);
                if ((typeof items !== "undefined" && items !== null ? items : Object.create(null)).length) {
                    ewc.set_all_items(items);
                }
            };
            if (!update_completion_items.__module__) Object.defineProperties(update_completion_items, {
                __module__ : {value: "complete"}
            });

            update_completion_items();
            function save_completion_items() {
                var text, items, idx;
                text = ewc.text_input.value;
                if (text && text.strip()) {
                    items = local_storage().get(history_name) || [];
                    idx = items.indexOf(text);
                    if (idx > -1) {
                        items.splice(idx, 1);
                    }
                    items.unshift(text);
                    local_storage().set(history_name, uniq(items.slice(0, history_size)));
                    update_completion_items();
                }
            };
            if (!save_completion_items.__module__) Object.defineProperties(save_completion_items, {
                __module__ : {value: "complete"}
            });

            parent.addEventListener("save_history", save_completion_items);
            return parent;
        };
        if (!create_simple_input_with_history.__defaults__) Object.defineProperties(create_simple_input_with_history, {
            __defaults__ : {value: {tooltip:null, placeholder:null, history_size:100, input_type:"text"}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["name", "tooltip", "placeholder", "history_size", "input_type"]},
            __module__ : {value: "complete"}
        });

        function main(container) {
            container.appendChild(ρσ_interpolate_kwargs.call(this, create_search_bar, [print, "test-search-bar"].concat([ρσ_desugar_kwargs({placeholder: "Testing search bar"})])));
            container.firstChild.lastChild.focus();
        };
        if (!main.__argnames__) Object.defineProperties(main, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "complete"}
        });

        ρσ_modules.complete.EditWithComplete = EditWithComplete;
        ρσ_modules.complete.create_search_bar = create_search_bar;
        ρσ_modules.complete.create_simple_input_with_history_native = create_simple_input_with_history_native;
        ρσ_modules.complete.create_simple_input_with_history = create_simple_input_with_history;
        ρσ_modules.complete.main = main;
    })();

    (function(){
        var __name__ = "read_book.highlights";
        var ICON_SIZE_VAL, ICON_SIZE_UNIT, ICON_SIZE, builtin_colors_light, builtin_colors_dark, builtin_decorations_light, builtin_decorations_dark, all_style_keys, url_pat, closing_bracket_map, opening_brackets;
        var E = ρσ_modules.elementmaker.E;

        var encode_query = ρσ_modules.ajax.encode_query;

        var get_current_query = ρσ_modules["book_list.globals"].get_current_query;
        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var create_search_bar = ρσ_modules.complete.create_search_bar;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var svgicon = ρσ_modules.dom.svgicon;
        var unique_id = ρσ_modules.dom.unique_id;

        var _ = ρσ_modules.gettext.gettext;
        var ngettext = ρσ_modules.gettext.ngettext;

        var create_custom_dialog = ρσ_modules.modals.create_custom_dialog;
        var error_dialog = ρσ_modules.modals.error_dialog;
        var get_text_dialog = ρσ_modules.modals.get_text_dialog;
        var question_dialog = ρσ_modules.modals.question_dialog;
        var warning_dialog = ρσ_modules.modals.warning_dialog;

        var current_book = ρσ_modules["read_book.globals"].current_book;
        var is_dark_theme = ρσ_modules["read_book.globals"].is_dark_theme;
        var runtime = ρσ_modules["read_book.globals"].runtime;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var create_button = ρσ_modules.widgets.create_button;

        ICON_SIZE_VAL = 3;
        ICON_SIZE_UNIT = "ex";
        ICON_SIZE = "" + ρσ_str.format("{}", ICON_SIZE_VAL) + "" + ρσ_str.format("{}", ICON_SIZE_UNIT) + "";
        builtin_colors_light = {"yellow": "#ffeb6b", "green": "#c0ed72", "blue": "#add8ff", "red": "#ffb0ca", "purple": "#d9b2ff"};
        builtin_colors_dark = {"yellow": "#906e00", "green": "#306f50", "blue": "#265589", "red": "#a23e5a", "purple": "#505088"};
        builtin_decorations_light = builtin_decorations_dark = {"wavy": {"text-decoration-style": "wavy", "text-decoration-color": "red", "text-decoration-line": "underline"}, "strikeout": {"text-decoration-line": "line-through", "text-decoration-color": "red"}};
        function builtin_friendly_name(kind, which) {
            if (kind === "color") {
                return (ρσ_expr_temp = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["yellow"] = _("Yellow highlight");
                    ρσ_d["green"] = _("Green highlight");
                    ρσ_d["blue"] = _("Blue highlight");
                    ρσ_d["red"] = _("Pink highlight");
                    ρσ_d["purple"] = _("Purple highlight");
                    return ρσ_d;
                }).call(this))[(typeof which === "number" && which < 0) ? ρσ_expr_temp.length + which : which] || _("Unknown highlight");
            }
            return (ρσ_expr_temp = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["wavy"] = _("Red wavy underline");
                ρσ_d["strikeout"] = _("Red strikeout");
                return ρσ_d;
            }).call(this))[(typeof which === "number" && which < 0) ? ρσ_expr_temp.length + which : which] || _("Unknown underline");
        };
        if (!builtin_friendly_name.__argnames__) Object.defineProperties(builtin_friendly_name, {
            __argnames__ : {value: ["kind", "which"]},
            __module__ : {value: "read_book.highlights"}
        });

        function builtin_color(which, is_dark) {
            return ((is_dark) ? builtin_colors_dark[(typeof which === "number" && which < 0) ? builtin_colors_dark.length + which : which] : builtin_colors_light[(typeof which === "number" && which < 0) ? builtin_colors_light.length + which : which]) || builtin_colors_light.yellow;
        };
        if (!builtin_color.__argnames__) Object.defineProperties(builtin_color, {
            __argnames__ : {value: ["which", "is_dark"]},
            __module__ : {value: "read_book.highlights"}
        });

        function default_color(is_dark) {
            return builtin_color("yellow", is_dark);
        };
        if (!default_color.__argnames__) Object.defineProperties(default_color, {
            __argnames__ : {value: ["is_dark"]},
            __module__ : {value: "read_book.highlights"}
        });

        function all_builtin_styles() {
            var ans, col, which;
            ans = [];
            var ρσ_Iter0 = ρσ_Iterable(builtin_colors_light);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                col = ρσ_Iter0[ρσ_Index0];
                ans.push((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "builtin";
                    ρσ_d["kind"] = "color";
                    ρσ_d["which"] = col;
                    return ρσ_d;
                }).call(this));
            }
            var ρσ_Iter1 = ρσ_Iterable(builtin_decorations_light);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                which = ρσ_Iter1[ρσ_Index1];
                ans.push((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "builtin";
                    ρσ_d["kind"] = "decoration";
                    ρσ_d["which"] = which;
                    return ρσ_d;
                }).call(this));
            }
            return ans;
        };
        if (!all_builtin_styles.__module__) Object.defineProperties(all_builtin_styles, {
            __module__ : {value: "read_book.highlights"}
        });

        all_style_keys = 'type kind which light dark background-color text-decoration-line text-decoration-color text-decoration-style'.split(' ');
        function custom_color_theme(name, lightbg, darkbg) {
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "custom";
                ρσ_d["kind"] = "color";
                ρσ_d["light"] = lightbg;
                ρσ_d["dark"] = darkbg;
                ρσ_d["friendly_name"] = name;
                return ρσ_d;
            }).call(this);
        };
        if (!custom_color_theme.__argnames__) Object.defineProperties(custom_color_theme, {
            __argnames__ : {value: ["name", "lightbg", "darkbg"]},
            __module__ : {value: "read_book.highlights"}
        });

        function custom_decoration_theme(name, line_position, line_style, line_color) {
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "custom";
                ρσ_d["kind"] = "decoration";
                ρσ_d["text-decoration-line"] = line_position;
                ρσ_d["text-decoration-style"] = line_style;
                ρσ_d["text-decoration-color"] = line_color;
                ρσ_d["friendly_name"] = name;
                return ρσ_d;
            }).call(this);
        };
        if (!custom_decoration_theme.__argnames__) Object.defineProperties(custom_decoration_theme, {
            __argnames__ : {value: ["name", "line_position", "line_style", "line_color"]},
            __module__ : {value: "read_book.highlights"}
        });

        function style_key(style) {
            return (function() {
                var ρσ_Iter = ρσ_Iterable(all_style_keys), ρσ_Result = [], k;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    k = ρσ_Iter[ρσ_Index];
                    ρσ_Result.push("" + ρσ_str.format("{}", k) + ":" + ρσ_str.format("{}", style[(typeof k === "number" && k < 0) ? style.length + k : k]) + "");
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })().join(";");
        };
        if (!style_key.__argnames__) Object.defineProperties(style_key, {
            __argnames__ : {value: ["style"]},
            __module__ : {value: "read_book.highlights"}
        });

        function HighlightStyle() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            HighlightStyle.prototype.__bind_methods__.call(this);
            HighlightStyle.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(HighlightStyle.prototype, "__bind_methods__", {value: function () {
            this.make_swatch = HighlightStyle.prototype.make_swatch.bind(this);
            this.highlight_shade = HighlightStyle.prototype.highlight_shade.bind(this);
            this.serialized = HighlightStyle.prototype.serialized.bind(this);
        }});
        Object.defineProperties(HighlightStyle.prototype,  {
            "friendly_name": {
                "enumerable": true, 
                "get": function friendly_name() {
                    var self = this;
                    var s;
                    s = self.style;
                    if (s.type === "builtin") {
                        return builtin_friendly_name(s.kind, s.which);
                    }
                    return s.friendly_name || _("Custom style");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        HighlightStyle.prototype.__init__ = function __init__(style) {
            var self = this;
            if (typeof style === "string") {
                style = JSON.parse(style);
            }
            self.style = style || (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "builtin";
                ρσ_d["kind"] = "color";
                ρσ_d["which"] = "yellow";
                return ρσ_d;
            }).call(this);
            self.key = style_key(self.style);
        };
        if (!HighlightStyle.prototype.__init__.__argnames__) Object.defineProperties(HighlightStyle.prototype.__init__, {
            __argnames__ : {value: ["style"]},
            __module__ : {value: "read_book.highlights"}
        });
        HighlightStyle.__argnames__ = HighlightStyle.prototype.__init__.__argnames__;
        HighlightStyle.__handles_kwarg_interpolation__ = HighlightStyle.prototype.__init__.__handles_kwarg_interpolation__;
        HighlightStyle.prototype.make_swatch = function make_swatch(container, is_dark) {
            var self = this;
            var style, s, br, tdl, tds, tdc, q, bg;
            style = container.style;
            style.width = style.height = style.minimumWidth = style.minimumHeight = style.maximumWidth = style.maximumHeight = ICON_SIZE;
            s = self.style;
            br = ICON_SIZE_VAL / 4;
            if (s.kind === "decoration") {
                tdl = tds = tdc = null;
                if (s.type === "builtin") {
                    q = (is_dark) ? builtin_decorations_dark[ρσ_bound_index(s.which, builtin_decorations_dark)] : builtin_decorations_dark[ρσ_bound_index(s.which, builtin_decorations_dark)];
                } else {
                    q = s;
                }
                tdl = q["text-decoration-line"] || null;
                tds = q["text-decoration-style"] || null;
                tdc = q["text-decoration-color"] || null;
                container.textContent = "ab";
                style.paddingLeft = style.paddingRight = style.paddingTop = style.paddingBottom = "0.25ex";
                style.borderStyle = "solid";
                style.borderWidth = "1px";
                style.borderRadius = "" + ρσ_str.format("{}", br) + "" + ρσ_str.format("{}", ICON_SIZE_UNIT) + "";
                style.fontSize = "smaller";
                style.fontWeight = "bold";
                if (tdl) {
                    style.textDecorationLine = tdl;
                }
                if (tds) {
                    style.textDecorationStyle = tds;
                }
                if (tdc) {
                    style.textDecorationColor = tdc;
                }
                return container;
            }
            bg = null;
            if (s.type === "builtin") {
                bg = builtin_color(s.which, is_dark);
            } else if (s.type === "custom") {
                bg = (is_dark) ? s.dark : s.light;
            }
            if (bg === null && s["background-color"]) {
                bg = s["background-color"];
            }
            if (bg) {
                style.backgroundColor = bg;
                style.borderRadius = "" + ρσ_str.format("{}", br) + "" + ρσ_str.format("{}", ICON_SIZE_UNIT) + "";
            }
            return container;
        };
        if (!HighlightStyle.prototype.make_swatch.__argnames__) Object.defineProperties(HighlightStyle.prototype.make_swatch, {
            __argnames__ : {value: ["container", "is_dark"]},
            __module__ : {value: "read_book.highlights"}
        });
        HighlightStyle.prototype.highlight_shade = function highlight_shade(is_dark) {
            var self = this;
            var s, defs;
            s = self.style;
            if (s.kind === "decoration") {
                if (s.type === "builtin") {
                    defs = (is_dark) ? builtin_decorations_dark[ρσ_bound_index(s.which, builtin_decorations_dark)] : builtin_decorations_light[ρσ_bound_index(s.which, builtin_decorations_light)];
                } else {
                    defs = s;
                }
                return defs["text-decoration-color"] || "red";
            }
            if (s.type === "builtin") {
                return builtin_color(s.which, is_dark);
            }
            if (s.type === "custom") {
                return (is_dark) ? s.dark : s.light;
            }
            return s["background-color"] || default_color(is_dark);
        };
        if (!HighlightStyle.prototype.highlight_shade.__argnames__) Object.defineProperties(HighlightStyle.prototype.highlight_shade, {
            __argnames__ : {value: ["is_dark"]},
            __module__ : {value: "read_book.highlights"}
        });
        HighlightStyle.prototype.serialized = function serialized() {
            var self = this;
            return JSON.stringify(self.style);
        };
        if (!HighlightStyle.prototype.serialized.__module__) Object.defineProperties(HighlightStyle.prototype.serialized, {
            __module__ : {value: "read_book.highlights"}
        });
        HighlightStyle.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        HighlightStyle.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(HighlightStyle.prototype, "__bases__", {value: []});
        

        function highlight_style_as_css(s, is_dark, foreground) {
            function styler(node) {
                var keys, bg, fg;
                function set(name, val) {
                    if (val) {
                        node.style.setProperty(name, val, "important");
                    }
                };
                if (!set.__argnames__) Object.defineProperties(set, {
                    __argnames__ : {value: ["name", "val"]},
                    __module__ : {value: "read_book.highlights"}
                });

                if (s.kind === "decoration") {
                    if (s.type === "builtin") {
                        keys = (is_dark) ? builtin_decorations_dark[ρσ_bound_index(s.which, builtin_decorations_dark)] : builtin_decorations_light[ρσ_bound_index(s.which, builtin_decorations_light)];
                    } else {
                        keys = s;
                    }
                    set("text-decoration-line", keys["text-decoration-line"]);
                    set("text-decoration-color", keys["text-decoration-color"]);
                    set("text-decoration-style", keys["text-decoration-style"]);
                    return;
                }
                bg = null;
                fg = foreground || null;
                if (s.type === "builtin") {
                    bg = builtin_color(s.which, is_dark);
                } else if (s.type === "custom") {
                    bg = (is_dark) ? s.dark : s.light;
                } else if (s.color) {
                    fg = s.color;
                }
                set("background-color", bg || s["background-color"] || default_color(is_dark));
                set("color", fg || s.color || foreground);
            };
            if (!styler.__argnames__) Object.defineProperties(styler, {
                __argnames__ : {value: ["node"]},
                __module__ : {value: "read_book.highlights"}
            });

            return styler;
        };
        if (!highlight_style_as_css.__argnames__) Object.defineProperties(highlight_style_as_css, {
            __argnames__ : {value: ["s", "is_dark", "foreground"]},
            __module__ : {value: "read_book.highlights"}
        });

        function custom_styles_equal(a, b) {
            var seen, k;
            seen = Object.create(null);
            var ρσ_Iter2 = ρσ_Iterable(a);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                k = ρσ_Iter2[ρσ_Index2];
                seen[(typeof k === "number" && k < 0) ? seen.length + k : k] = true;
                if (a[(typeof k === "number" && k < 0) ? a.length + k : k] !== b[(typeof k === "number" && k < 0) ? b.length + k : k]) {
                    return false;
                }
            }
            var ρσ_Iter3 = ρσ_Iterable(b);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                k = ρσ_Iter3[ρσ_Index3];
                if (!seen[(typeof k === "number" && k < 0) ? seen.length + k : k]) {
                    if (a[(typeof k === "number" && k < 0) ? a.length + k : k] !== b[(typeof k === "number" && k < 0) ? b.length + k : k]) {
                        return false;
                    }
                }
            }
            return true;
        };
        if (!custom_styles_equal.__argnames__) Object.defineProperties(custom_styles_equal, {
            __argnames__ : {value: ["a", "b"]},
            __module__ : {value: "read_book.highlights"}
        });

        function all_styles() {
            var ans, custom_highlight_styles, raw;
            ans = [];
            custom_highlight_styles = get_session_data().get("custom_highlight_styles");
            var ρσ_Iter4 = ρσ_Iterable(custom_highlight_styles);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                raw = ρσ_Iter4[ρσ_Index4];
                ans.push(new HighlightStyle(raw));
            }
            var ρσ_Iter5 = ρσ_Iterable(all_builtin_styles());
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                raw = ρσ_Iter5[ρσ_Index5];
                ans.push(new HighlightStyle(raw));
            }
            return ans;
        };
        if (!all_styles.__module__) Object.defineProperties(all_styles, {
            __module__ : {value: "read_book.highlights"}
        });

        function AddStyle() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            AddStyle.prototype.__bind_methods__.call(this);
            AddStyle.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(AddStyle.prototype, "__bind_methods__", {value: function () {
            this.focus = AddStyle.prototype.focus.bind(this);
            this.init = AddStyle.prototype.init.bind(this);
            this.change_type = AddStyle.prototype.change_type.bind(this);
        }});
        Object.defineProperties(AddStyle.prototype,  {
            "style_type": {
                "enumerable": true, 
                "get": function style_type() {
                    var self = this;
                    return self.get_container().querySelector("input[name=style_type]:checked").value;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "color_type": {
                "enumerable": true, 
                "get": function color_type() {
                    var self = this;
                    return self.get_container().querySelector("input[name=color_type]:checked").value;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "friendly_name": {
                "enumerable": true, 
                "get": function friendly_name() {
                    var self = this;
                    return self.get_container().querySelector("input[name=friendly_name]").value;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "created_style": {
                "enumerable": true, 
                "get": function created_style() {
                    var self = this;
                    var c, name, col;
                    c = self.get_container();
                    name = self.friendly_name;
                    if (self.style_type === "color") {
                        return custom_color_theme(name, c.querySelector("input[name=light_color]").value, c.querySelector("input[name=dark_color]").value);
                    }
                    if (self.color_type === "currentColor") {
                        col = "currentColor";
                    } else {
                        col = c.querySelector("input[name=decoration_color]").value;
                    }
                    return custom_decoration_theme(name, c.querySelector("select[name=text_decoration_line]").value, c.querySelector("select[name=text_decoration_style]").value, col);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        AddStyle.prototype.__init__ = function __init__(get_container, hide_self) {
            var self = this;
            self.get_container = get_container;
            self.hide_self = hide_self;
            function onkeydown(ev) {
                ev.stopPropagation();
                if (ev.key === "Escape") {
                    hide_self(null);
                }
            };
            if (!onkeydown.__argnames__) Object.defineProperties(onkeydown, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "read_book.highlights"}
            });

            get_container().appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.div(_("Style name:"), " ", ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "friendly_name", onkeydown: onkeydown, placeholder: _("Name for this style")})])), E.div(" "), E.div(_("Type of style:"), " ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "style_type", value: "color", onchange: self.change_type, checked: true})]), _("Color")), "  ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "style_type", value: "decoration", onchange: self.change_type})]), _("Underline"))), ρσ_interpolate_kwargs.call(E, E.div, [E.div(E.label(_("Color for light color themes: "), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "color", name: "light_color", value: "#ffff00"})]))), E.div(" "), E.div(E.label(_("Color for dark color themes: "), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "color", name: "dark_color", value: "#cccc00"})])))].concat([ρσ_desugar_kwargs({name: "color-container", style: "margin-top:1rem; border-top: solid; padding-top: 1rem"})])), ρσ_interpolate_kwargs.call(E, E.div, [E.div(_("Color for the line: "), E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "color_type", value: "currentColor", checked: true})]), _("Text color")), " ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "color_type", value: "custom_color"})]), _("Custom color:")), " ", ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "color", name: "decoration_color", value: "#ff0000", onchange: (function() {
                var ρσ_anonfunc = function () {
                    self.get_container().querySelector("input[value=custom_color]").checked = true;
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })()})])), E.div(" "), E.div(E.label(_("Position of line: "), ρσ_interpolate_kwargs.call(E, E.select, [ρσ_interpolate_kwargs.call(E, E.option, [_("Underline")].concat([ρσ_desugar_kwargs({value: "underline"})])), ρσ_interpolate_kwargs.call(E, E.option, [_("Over-line")].concat([ρσ_desugar_kwargs({value: "overline"})])), ρσ_interpolate_kwargs.call(E, E.option, [_("Strikeout")].concat([ρσ_desugar_kwargs({value: "strike-through"})]))].concat([ρσ_desugar_kwargs({name: "text_decoration_line"})])))), E.div(" "), E.div(E.label(_("Style of line: "), ρσ_interpolate_kwargs.call(E, E.select, [ρσ_interpolate_kwargs.call(E, E.option, [_("Solid")].concat([ρσ_desugar_kwargs({value: "solid"})])), ρσ_interpolate_kwargs.call(E, E.option, [_("Double")].concat([ρσ_desugar_kwargs({value: "double"})])), ρσ_interpolate_kwargs.call(E, E.option, [_("Dotted")].concat([ρσ_desugar_kwargs({value: "dotted"})])), ρσ_interpolate_kwargs.call(E, E.option, [_("Dashed")].concat([ρσ_desugar_kwargs({value: "dashed"})])), ρσ_interpolate_kwargs.call(E, E.option, [_("Wavy")].concat([ρσ_desugar_kwargs({value: "wavy"})]))].concat([ρσ_desugar_kwargs({name: "text_decoration_style"})]))))].concat([ρσ_desugar_kwargs({name: "decoration-container", style: "margin-top:1rem; border-top: solid; padding-top: 1rem"})])), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Discard"), "close", (function() {
                var ρσ_anonfunc = function (ev) {
                    ev.stopPropagation();
                    hide_self(null);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })()), create_button(_("Save"), "check", (function() {
                var ρσ_anonfunc = function (ev) {
                    ev.stopPropagation();
                    if (!self.friendly_name) {
                        return ρσ_interpolate_kwargs.call(this, error_dialog, [_("No name specified"), _("You must give your custom style a name")].concat([ρσ_desugar_kwargs({on_close: self.focus})]));
                    }
                    hide_self(self.created_style);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })())].concat([ρσ_desugar_kwargs({style: "margin-top:1rem; border-top: solid; padding-top: 1rem; display: flex; width: 100%; justify-content: space-between"})]))].concat([ρσ_desugar_kwargs({style: "margin: 1rem; text-align: left"})])));
            self.change_type();
        };
        if (!AddStyle.prototype.__init__.__argnames__) Object.defineProperties(AddStyle.prototype.__init__, {
            __argnames__ : {value: ["get_container", "hide_self"]},
            __module__ : {value: "read_book.highlights"}
        });
        AddStyle.__argnames__ = AddStyle.prototype.__init__.__argnames__;
        AddStyle.__handles_kwarg_interpolation__ = AddStyle.prototype.__init__.__handles_kwarg_interpolation__;
        AddStyle.prototype.focus = function focus() {
            var self = this;
            self.get_container().querySelector("input[name=friendly_name]").focus();
        };
        if (!AddStyle.prototype.focus.__module__) Object.defineProperties(AddStyle.prototype.focus, {
            __module__ : {value: "read_book.highlights"}
        });
        AddStyle.prototype.init = function init() {
            var self = this;
            self.get_container().querySelector("input[name=friendly_name]").value = "";
            self.focus();
        };
        if (!AddStyle.prototype.init.__module__) Object.defineProperties(AddStyle.prototype.init, {
            __module__ : {value: "read_book.highlights"}
        });
        AddStyle.prototype.change_type = function change_type() {
            var self = this;
            var c, q;
            c = self.get_container();
            q = self.style_type;
            c.querySelector("[name=color-container]").style.display = (q === "color") ? "block" : "none";
            c.querySelector("[name=decoration-container]").style.display = (q === "decoration") ? "block" : "none";
        };
        if (!AddStyle.prototype.change_type.__module__) Object.defineProperties(AddStyle.prototype.change_type, {
            __module__ : {value: "read_book.highlights"}
        });
        AddStyle.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        AddStyle.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(AddStyle.prototype, "__bases__", {value: []});
        
        
        
        

        function EditNotesAndColors() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            EditNotesAndColors.prototype.__bind_methods__.call(this);
            EditNotesAndColors.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(EditNotesAndColors.prototype, "__bind_methods__", {value: function () {
            this.hide_add_style = EditNotesAndColors.prototype.hide_add_style.bind(this);
            this.add_new_style = EditNotesAndColors.prototype.add_new_style.bind(this);
            this.set_visibility_of_remove_button = EditNotesAndColors.prototype.set_visibility_of_remove_button.bind(this);
            this.add_color = EditNotesAndColors.prototype.add_color.bind(this);
            this.remove_custom_color = EditNotesAndColors.prototype.remove_custom_color.bind(this);
            this.do_remove_custom_color = EditNotesAndColors.prototype.do_remove_custom_color.bind(this);
            this.change_color = EditNotesAndColors.prototype.change_color.bind(this);
            this.make_swatch_current = EditNotesAndColors.prototype.make_swatch_current.bind(this);
        }});
        Object.defineProperties(EditNotesAndColors.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById(self.container_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "notes_edit": {
                "enumerable": true, 
                "get": function notes_edit() {
                    var self = this;
                    return self.container.getElementsByTagName("textarea")[0];
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "current_notes": {
                "enumerable": true, 
                "get": function current_notes() {
                    var self = this;
                    return self.notes_edit.value || "";
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "current_style": {
                "enumerable": true, 
                "get": function current_style() {
                    var self = this;
                    var style;
                    style = self.container.getElementsByClassName("current-swatch")[0].dataset.style;
                    return new HighlightStyle(JSON.parse(style));
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        EditNotesAndColors.prototype.__init__ = function __init__(container, is_dark_theme, current_notes, current_style, annot_id, close_editor) {
            var self = this;
            var remove_button, apply_button, stop_propagation, c, custom_highlight_styles, raw, parent;
            self.initial_style = current_style;
            self.is_dark_theme = is_dark_theme;
            self.annot_id = annot_id;
            function finish() {
                close_editor(true);
            };
            if (!finish.__module__) Object.defineProperties(finish, {
                __module__ : {value: "read_book.highlights"}
            });

            function abort() {
                close_editor(false);
            };
            if (!abort.__module__) Object.defineProperties(abort, {
                __module__ : {value: "read_book.highlights"}
            });

            function handle_keypress(ev) {
                ev.stopPropagation();
                if (ev.key === "Escape") {
                    abort();
                } else if (ev.key === "Enter" && ev.ctrlKey) {
                    finish();
                }
            };
            if (!handle_keypress.__argnames__) Object.defineProperties(handle_keypress, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "read_book.highlights"}
            });

            remove_button = create_button(_("Remove style"), "trash", self.remove_custom_color, _("Remove this custom highlight style"));
            remove_button.classList.add("remove-custom-color");
            apply_button = create_button((self.annot_id) ? _("Apply") : _("Create"), "check", finish, ((self.annot_id) ? _("Finish editing highlight") : _("Create highlight")) + " [Ctrl+Enter]", true);
            apply_button.style.marginLeft = apply_button.style.marginTop = "auto";
            stop_propagation = (function() {
                var ρσ_anonfunc = function (ev) {
                    ev.stopPropagation();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })();
            c = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.textarea, [ρσ_desugar_kwargs({placeholder: _("Add notes for this highlight. Double click or long tap on a highlight to read its notes."), rows: "10", spellcheck: "true", style: "width: 90%;", onkeydown: handle_keypress})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "color-block", style: "display: flex; flex-wrap: wrap; width: 100%; justify-content: center"})]), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Cancel"), "close", abort, _("Abort") + " [Esc]"), E.span(" "), remove_button, apply_button].concat([ρσ_desugar_kwargs({style: "width: 100%; display: flex; flex-wrap: wrap"})]))].concat([ρσ_desugar_kwargs({ontouchstart: stop_propagation, ontouchmove: stop_propagation, ontouchend: stop_propagation, ontouchcancel: stop_propagation, oncontextmenu: stop_propagation})]))].concat([ρσ_desugar_kwargs({style: "background: " + ρσ_str.format("{}", get_color("window-background")) + "; margin: auto; text-align: center; padding: 1ex;", onclick: stop_propagation, id: unique_id()})]));
            self.container_id = c.id;
            container.appendChild(c);
            container.style.maxWidth = "40rem";
            container.style.width = "90%";
            c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display:none"})]));
            self.add_style = new AddStyle((function() {
                var ρσ_anonfunc = function () {
                    return self.container.lastChild;
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })(), self.hide_add_style);
            self.seen_colors = Object.create(null);
            custom_highlight_styles = get_session_data().get("custom_highlight_styles");
            var ρσ_Iter6 = ρσ_Iterable(custom_highlight_styles);
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                raw = ρσ_Iter6[ρσ_Index6];
                self.add_color(new HighlightStyle(raw)).classList.add("custom-style");
            }
            var ρσ_Iter7 = ρσ_Iterable(all_builtin_styles());
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                raw = ρσ_Iter7[ρσ_Index7];
                self.add_color(new HighlightStyle(raw));
            }
            if (!c.querySelector(".current-swatch")) {
                self.add_color(self.initial_style, true);
            }
            parent = c.getElementsByClassName("color-block")[0];
            parent.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [svgicon("plus", ICON_SIZE, ICON_SIZE)].concat([ρσ_desugar_kwargs({style: "padding: 4px; margin: 4px;", title: _("Add a new highlight style"), class_: "simple-link", onclick: (function() {
                var ρσ_anonfunc = function (ev) {
                    var c;
                    ev.stopPropagation();
                    c = self.container;
                    c.firstChild.style.display = "none";
                    c.lastChild.style.display = "block";
                    self.add_style.init();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })()})])));
            self.set_visibility_of_remove_button();
            window.setTimeout(self.notes_edit.focus.bind(self.notes_edit), 0);
            if (current_notes) {
                self.notes_edit.value = current_notes;
            }
        };
        if (!EditNotesAndColors.prototype.__init__.__argnames__) Object.defineProperties(EditNotesAndColors.prototype.__init__, {
            __argnames__ : {value: ["container", "is_dark_theme", "current_notes", "current_style", "annot_id", "close_editor"]},
            __module__ : {value: "read_book.highlights"}
        });
        EditNotesAndColors.__argnames__ = EditNotesAndColors.prototype.__init__.__argnames__;
        EditNotesAndColors.__handles_kwarg_interpolation__ = EditNotesAndColors.prototype.__init__.__handles_kwarg_interpolation__;
        EditNotesAndColors.prototype.hide_add_style = function hide_add_style(new_style) {
            var self = this;
            var c;
            c = self.container;
            c.firstChild.style.display = "block";
            c.lastChild.style.display = "none";
            if (new_style) {
                self.add_new_style(new_style);
            }
            self.notes_edit.focus();
        };
        if (!EditNotesAndColors.prototype.hide_add_style.__argnames__) Object.defineProperties(EditNotesAndColors.prototype.hide_add_style, {
            __argnames__ : {value: ["new_style"]},
            __module__ : {value: "read_book.highlights"}
        });
        EditNotesAndColors.prototype.add_new_style = function add_new_style(new_style) {
            var self = this;
            var hs, item, q, sd, new_styles, seen, hso, style;
            hs = new HighlightStyle(new_style);
            item = self.add_color(hs, true);
            if (!item) {
                var ρσ_Iter8 = ρσ_Iterable(self.container.getElementsByClassName("swatch"));
                for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                    q = ρσ_Iter8[ρσ_Index8];
                    if (q.dataset.key === hs.key) {
                        item = q;
                        break;
                    }
                }
            }
            if (item) {
                item.classList.add("custom-style");
                self.make_swatch_current(item);
                sd = get_session_data();
                new_styles = [new_style];
                seen = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d[hs.key] = true;
                    return ρσ_d;
                }).call(this);
                var ρσ_Iter9 = ρσ_Iterable(sd.get("custom_highlight_styles"));
                for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                    style = ρσ_Iter9[ρσ_Index9];
                    hso = new HighlightStyle(style);
                    if (!seen[ρσ_bound_index(hso.key, seen)]) {
                        new_styles.push(style);
                    }
                }
                sd.set("custom_highlight_styles", new_styles);
            }
        };
        if (!EditNotesAndColors.prototype.add_new_style.__argnames__) Object.defineProperties(EditNotesAndColors.prototype.add_new_style, {
            __argnames__ : {value: ["new_style"]},
            __module__ : {value: "read_book.highlights"}
        });
        EditNotesAndColors.prototype.set_visibility_of_remove_button = function set_visibility_of_remove_button() {
            var self = this;
            var c, item;
            c = self.container;
            item = c.querySelector(".current-swatch.custom-style");
            c.querySelector(".remove-custom-color").style.display = (item) ? "flex" : "none";
        };
        if (!EditNotesAndColors.prototype.set_visibility_of_remove_button.__module__) Object.defineProperties(EditNotesAndColors.prototype.set_visibility_of_remove_button, {
            __module__ : {value: "read_book.highlights"}
        });
        EditNotesAndColors.prototype.add_color = function add_color(hs, at_start) {
            var self = this;
            var ic, is_current, sqbg, item, parent;
            if ((ρσ_expr_temp = self.seen_colors)[ρσ_bound_index(hs.key, ρσ_expr_temp)]) {
                return;
            }
            (ρσ_expr_temp = self.seen_colors)[ρσ_bound_index(hs.key, ρσ_expr_temp)] = true;
            ic = E.div();
            hs.make_swatch(ic, self.is_dark_theme);
            ic.classList.add("simple-link");
            is_current = hs.key === self.initial_style.key;
            sqbg = (is_current) ? get_color("window-background2") : "unset";
            item = ρσ_interpolate_kwargs.call(E, E.div, [ic].concat([ρσ_desugar_kwargs({style: "padding: 4px; background-color: " + ρσ_str.format("{}", sqbg) + "; margin: 4px; border-radius: " + ρσ_str.format("{}", ICON_SIZE_VAL / 4) + "" + ρσ_str.format("{}", ICON_SIZE_UNIT) + "", onclick: self.change_color, title: hs.friendly_name})]));
            if (is_current) {
                item.classList.add("current-swatch");
            }
            item.classList.add("swatch");
            item.dataset.style = hs.serialized();
            item.dataset.key = hs.key;
            parent = self.container.getElementsByClassName("color-block")[0];
            if (at_start) {
                parent.insertBefore(item, parent.firstChild);
            } else {
                parent.appendChild(item);
            }
            return item;
        };
        if (!EditNotesAndColors.prototype.add_color.__argnames__) Object.defineProperties(EditNotesAndColors.prototype.add_color, {
            __argnames__ : {value: ["hs", "at_start"]},
            __module__ : {value: "read_book.highlights"}
        });
        EditNotesAndColors.prototype.remove_custom_color = function remove_custom_color() {
            var self = this;
            question_dialog(_("Are you sure?"), _("Do you want to permanently delete this highlighting style?"), (function() {
                var ρσ_anonfunc = function (yes) {
                    if (yes) {
                        self.do_remove_custom_color();
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["yes"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!EditNotesAndColors.prototype.remove_custom_color.__module__) Object.defineProperties(EditNotesAndColors.prototype.remove_custom_color, {
            __module__ : {value: "read_book.highlights"}
        });
        EditNotesAndColors.prototype.do_remove_custom_color = function do_remove_custom_color() {
            var self = this;
            var item, cct, p, sd, custom_highlight_styles, ans, x;
            item = self.container.getElementsByClassName("current-swatch")[0];
            cct = JSON.parse(item.dataset.style);
            p = item.parentNode;
            p.removeChild(item);
            self.make_swatch_current(p.firstChild);
            sd = get_session_data();
            custom_highlight_styles = sd.get("custom_highlight_styles");
            ans = [];
            var ρσ_Iter10 = ρσ_Iterable(custom_highlight_styles);
            for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                x = ρσ_Iter10[ρσ_Index10];
                if (!custom_styles_equal(x, cct)) {
                    ans.push(x);
                }
            }
            sd.set("custom_highlight_styles", ans);
        };
        if (!EditNotesAndColors.prototype.do_remove_custom_color.__module__) Object.defineProperties(EditNotesAndColors.prototype.do_remove_custom_color, {
            __module__ : {value: "read_book.highlights"}
        });
        EditNotesAndColors.prototype.change_color = function change_color(evt) {
            var self = this;
            evt.stopPropagation();
            self.make_swatch_current(evt.currentTarget);
        };
        if (!EditNotesAndColors.prototype.change_color.__argnames__) Object.defineProperties(EditNotesAndColors.prototype.change_color, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.highlights"}
        });
        EditNotesAndColors.prototype.make_swatch_current = function make_swatch_current(item) {
            var self = this;
            var child;
            var ρσ_Iter11 = ρσ_Iterable(item.parentNode.childNodes);
            for (var ρσ_Index11 = 0; ρσ_Index11 < ρσ_Iter11.length; ρσ_Index11++) {
                child = ρσ_Iter11[ρσ_Index11];
                child.style.backgroundColor = "unset";
                child.classList.remove("current-swatch");
            }
            item.style.backgroundColor = get_color("window-background2");
            item.classList.add("current-swatch");
            self.notes_edit.focus();
            self.set_visibility_of_remove_button();
        };
        if (!EditNotesAndColors.prototype.make_swatch_current.__argnames__) Object.defineProperties(EditNotesAndColors.prototype.make_swatch_current, {
            __argnames__ : {value: ["item"]},
            __module__ : {value: "read_book.highlights"}
        });
        EditNotesAndColors.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        EditNotesAndColors.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(EditNotesAndColors.prototype, "__bases__", {value: []});
        
        
        
        

        function get_container_id() {
            if (!get_container_id.ans) {
                get_container_id.ans = unique_id();
            }
            return get_container_id.ans;
        };
        if (!get_container_id.__module__) Object.defineProperties(get_container_id, {
            __module__ : {value: "read_book.highlights"}
        });

        function get_container() {
            return document.getElementById(get_container_id());
        };
        if (!get_container.__module__) Object.defineProperties(get_container, {
            __module__ : {value: "read_book.highlights"}
        });

        function get_current_link_prefix() {
            var link_prefix;
            if (runtime.is_standalone_viewer) {
                return current_book().calibre_book_url;
            }
            link_prefix = window.location.href;
            return link_prefix.slice(0, link_prefix.indexOf("#") + 1);
        };
        if (!get_current_link_prefix.__module__) Object.defineProperties(get_current_link_prefix, {
            __module__ : {value: "read_book.highlights"}
        });

        function link_to_epubcfi(epubcfi, link_prefix, current_query) {
            var link;
            if (runtime.is_standalone_viewer) {
                current_query = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["open_at"] = epubcfi;
                    return ρσ_d;
                }).call(this);
                link = encode_query(current_query);
            } else {
                if (!current_query) {
                    current_query = Object.assign(Object.create(null), get_current_query());
                }
                current_query.bookpos = epubcfi;
                link = encode_query(current_query).slice(1);
            }
            return link_prefix + link.replace(/\)/g, "%29").replace(/\(/g, "%28");
        };
        if (!link_to_epubcfi.__argnames__) Object.defineProperties(link_to_epubcfi, {
            __argnames__ : {value: ["epubcfi", "link_prefix", "current_query"]},
            __module__ : {value: "read_book.highlights"}
        });

        function render_highlight_as_text() {
            var hl = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var lines = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var link_prefix = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var current_query = ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[3];
            var as_markdown = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? render_highlight_as_text.__defaults__.as_markdown : arguments[4];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "as_markdown")){
                as_markdown = ρσ_kwargs_obj.as_markdown;
            }
            var date, cfi, spine_index, link, notes;
            lines.push(hl.highlighted_text);
            date = new Date(hl.timestamp).toLocaleString();
            if (as_markdown) {
                cfi = hl.start_cfi;
                spine_index = (1 + hl.spine_index) * 2;
                link = link_to_epubcfi("epubcfi(/" + ρσ_str.format("{}", spine_index) + "" + ρσ_str.format("{}", cfi) + ")", link_prefix, current_query);
                date = "[" + ρσ_str.format("{}", date) + "](" + ρσ_str.format("{}", link) + ")";
            }
            lines.push(date);
            notes = hl.notes;
            if (notes) {
                lines.push("");
                lines.push(notes);
            }
            lines.push("");
            if (as_markdown) {
                lines.push("-".repeat(20));
            } else {
                lines.push("───");
            }
            lines.push("");
        };
        if (!render_highlight_as_text.__defaults__) Object.defineProperties(render_highlight_as_text, {
            __defaults__ : {value: {as_markdown:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["hl", "lines", "link_prefix", "current_query", "as_markdown"]},
            __module__ : {value: "read_book.highlights"}
        });

        function ChapterGroup() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ChapterGroup.prototype.__bind_methods__.call(this);
            ChapterGroup.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ChapterGroup.prototype, "__bind_methods__", {value: function () {
            this.add_annot = ChapterGroup.prototype.add_annot.bind(this);
            this.group_for_title = ChapterGroup.prototype.group_for_title.bind(this);
            this.render_as_text = ChapterGroup.prototype.render_as_text.bind(this);
        }});
        ChapterGroup.prototype.__init__ = function __init__(title, level) {
            var self = this;
            self.level = level || 0;
            self.title = title || "";
            self.subgroups = {};
            self.subgroups_in_order = [];
            self.annotations = [];
        };
        if (!ChapterGroup.prototype.__init__.__argnames__) Object.defineProperties(ChapterGroup.prototype.__init__, {
            __argnames__ : {value: ["title", "level"]},
            __module__ : {value: "read_book.highlights"}
        });
        ChapterGroup.__argnames__ = ChapterGroup.prototype.__init__.__argnames__;
        ChapterGroup.__handles_kwarg_interpolation__ = ChapterGroup.prototype.__init__.__handles_kwarg_interpolation__;
        ChapterGroup.prototype.add_annot = function add_annot(a) {
            var self = this;
            var titles, node, title;
            titles = a["toc_family_titles"];
            if (!titles) {
                titles = ρσ_list_decorate([ _("Unknown chapter") ]);
            }
            node = self;
            var ρσ_Iter12 = ρσ_Iterable(titles);
            for (var ρσ_Index12 = 0; ρσ_Index12 < ρσ_Iter12.length; ρσ_Index12++) {
                title = ρσ_Iter12[ρσ_Index12];
                node = node.group_for_title(title);
            }
            node.annotations.push(a);
        };
        if (!ChapterGroup.prototype.add_annot.__argnames__) Object.defineProperties(ChapterGroup.prototype.add_annot, {
            __argnames__ : {value: ["a"]},
            __module__ : {value: "read_book.highlights"}
        });
        ChapterGroup.prototype.group_for_title = function group_for_title(title) {
            var self = this;
            var ans;
            ans = (ρσ_expr_temp = self.subgroups)[(typeof title === "number" && title < 0) ? ρσ_expr_temp.length + title : title];
            if (!ans) {
                ans = new ChapterGroup(title, self.level + 1);
                (ρσ_expr_temp = self.subgroups)[(typeof title === "number" && title < 0) ? ρσ_expr_temp.length + title : title] = ans;
                self.subgroups_in_order.push(title);
            }
            return ans;
        };
        if (!ChapterGroup.prototype.group_for_title.__argnames__) Object.defineProperties(ChapterGroup.prototype.group_for_title, {
            __argnames__ : {value: ["title"]},
            __module__ : {value: "read_book.highlights"}
        });
        ChapterGroup.prototype.render_as_text = function render_as_text(lines, link_prefix, current_query, as_markdown) {
            var self = this;
            var hl, sg, title;
            if (self.title) {
                lines.push("#".repeat(self.level) + " " + self.title);
                lines.push("");
            }
            var ρσ_Iter13 = ρσ_Iterable(self.annotations);
            for (var ρσ_Index13 = 0; ρσ_Index13 < ρσ_Iter13.length; ρσ_Index13++) {
                hl = ρσ_Iter13[ρσ_Index13];
                render_highlight_as_text(hl, lines, link_prefix, current_query, as_markdown);
            }
            var ρσ_Iter14 = ρσ_Iterable(self.subgroups_in_order);
            for (var ρσ_Index14 = 0; ρσ_Index14 < ρσ_Iter14.length; ρσ_Index14++) {
                title = ρσ_Iter14[ρσ_Index14];
                sg = (ρσ_expr_temp = self.subgroups)[(typeof title === "number" && title < 0) ? ρσ_expr_temp.length + title : title];
                sg.render_as_text(lines, link_prefix, current_query, as_markdown);
            }
        };
        if (!ChapterGroup.prototype.render_as_text.__argnames__) Object.defineProperties(ChapterGroup.prototype.render_as_text, {
            __argnames__ : {value: ["lines", "link_prefix", "current_query", "as_markdown"]},
            __module__ : {value: "read_book.highlights"}
        });
        ChapterGroup.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ChapterGroup.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ChapterGroup.prototype, "__bases__", {value: []});

        function show_export_dialog(annotations_manager, book_metadata) {
            var sd, fmt, all_highlights, selected_highlight_items, key, e, h, ta_id, href, idx, current_query, link_prefix;
            sd = get_session_data();
            fmt = sd.get("highlights_export_format");
            if (['text', 'markdown', 'calibre_annotations_collection'].indexOf(fmt) < 0) {
                fmt = "text";
            }
            all_highlights = annotations_manager.all_highlights();
            selected_highlight_items = all_selected_entries();
            if (selected_highlight_items.length) {
                key = (function() {
                    var ρσ_Iter = ρσ_Iterable(selected_highlight_items), ρσ_Result = Object.create(null), e;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        e = ρσ_Iter[ρσ_Index];
                        ρσ_Result[e.dataset.uuid] = (true);
                    }
                    return ρσ_Result;
                })();
                all_highlights = (function() {
                    var ρσ_Iter = ρσ_Iterable(all_highlights), ρσ_Result = [], h;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        h = ρσ_Iter[ρσ_Index];
                        if (key[ρσ_bound_index(h.uuid, key)]) {
                            ρσ_Result.push(h);
                        }
                    }
                    ρσ_Result = ρσ_list_constructor(ρσ_Result);
                    return ρσ_Result;
                })();
            }
            ta_id = unique_id();
            href = window.location.href;
            idx = href.indexOf("#");
            href = href.slice(0, idx + 1);
            current_query = Object.assign(Object.create(null), get_current_query());
            link_prefix = get_current_link_prefix();
            function update_text() {
                var data, as_markdown, lines, root, a;
                if (fmt === "calibre_annotations_collection") {
                    data = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["version"] = 1;
                        ρσ_d["type"] = "calibre_annotation_collection";
                        ρσ_d["annotations"] = all_highlights;
                        return ρσ_d;
                    }).call(this);
                    document.getElementById(ta_id).textContent = JSON.stringify(data, null, 2);
                    return;
                }
                as_markdown = fmt === "markdown";
                lines = [];
                root = new ChapterGroup;
                var ρσ_Iter15 = ρσ_Iterable(all_highlights);
                for (var ρσ_Index15 = 0; ρσ_Index15 < ρσ_Iter15.length; ρσ_Index15++) {
                    a = ρσ_Iter15[ρσ_Index15];
                    root.add_annot(a);
                }
                root.render_as_text(lines, link_prefix, current_query, as_markdown);
                document.getElementById(ta_id).textContent = lines.join("\n");
            };
            if (!update_text.__module__) Object.defineProperties(update_text, {
                __module__ : {value: "read_book.highlights"}
            });

            function fmt_item(text, val) {
                var ans;
                ans = E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "format", value: val, checked: val === fmt})]), " ", text);
                ans.style.marginRight = "1rem";
                ans.firstChild.addEventListener("change", (function() {
                    var ρσ_anonfunc = function (ev) {
                        fmt = this.value;
                        sd.set("highlights_export_format", this.value);
                        update_text();
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "read_book.highlights"}
                    });
                    return ρσ_anonfunc;
                })());
                return ans;
            };
            if (!fmt_item.__argnames__) Object.defineProperties(fmt_item, {
                __argnames__ : {value: ["text", "val"]},
                __module__ : {value: "read_book.highlights"}
            });

            create_custom_dialog(_("Export highlights"), (function() {
                var ρσ_anonfunc = function (modal_container, close_modal) {
                    modal_container.appendChild(E.div(E.div(_("Format for exported highlights:")), E.div(fmt_item(_("Plain text"), "text"), fmt_item(_("Markdown"), "markdown"), fmt_item("calibre", "calibre_annotations_collection")), ρσ_interpolate_kwargs.call(E, E.textarea, [ρσ_desugar_kwargs({style: "margin-top: 1ex; resize: none; max-height: 25vh", readonly: true, rows: "20", cols: "80", id: ta_id})]), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Copy"), "copy", (function() {
                        var ρσ_anonfunc = function (ev) {
                            var x;
                            x = document.getElementById(ta_id);
                            x.focus();
                            x.select();
                            document.execCommand("copy");
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["ev"]},
                            __module__ : {value: "read_book.highlights"}
                        });
                        return ρσ_anonfunc;
                    })()), create_button(_("Download"), "cloud-download", (function() {
                        var ρσ_anonfunc = function (ev) {
                            var text, ext, mt, title, filename, file, url, a;
                            text = document.getElementById(ta_id).textContent;
                            ext = (fmt === "markdown") ? "md" : (fmt === "text") ? "txt" : "json";
                            mt = (fmt === "markdown") ? "text/markdown" : (fmt === "text") ? "text/plain" : "application/json";
                            title = (typeof book_metadata !== "undefined" && book_metadata !== null ? book_metadata : Object.create(null)).title || _("Unknown");
                            filename = (ρσ_expr_temp = _("{title} - highlights"), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.format, [ρσ_desugar_kwargs({title: title})])) + ("." + ρσ_str.format("{}", ext) + "");
                            file = new Blob(ρσ_list_decorate([ text ]), (function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["type"] = mt;
                                return ρσ_d;
                            }).call(this));
                            url = window.URL.createObjectURL(file);
                            a = ρσ_interpolate_kwargs.call(E, E.a, [ρσ_desugar_kwargs({href: url, download: filename})]);
                            document.body.appendChild(a);
                            a.click();
                            window.setTimeout((function() {
                                var ρσ_anonfunc = function () {
                                    document.body.removeChild(a);
                                    window.URL.revokeObjectURL(url);
                                };
                                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                    __module__ : {value: "read_book.highlights"}
                                });
                                return ρσ_anonfunc;
                            })(), 0);
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["ev"]},
                            __module__ : {value: "read_book.highlights"}
                        });
                        return ρσ_anonfunc;
                    })())].concat([ρσ_desugar_kwargs({class_: "button-box"})]))));
                    window.setTimeout(update_text, 0);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["modal_container", "close_modal"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!show_export_dialog.__argnames__) Object.defineProperties(show_export_dialog, {
            __argnames__ : {value: ["annotations_manager", "book_metadata"]},
            __module__ : {value: "read_book.highlights"}
        });

        function focus_search() {
            var c;
            c = get_container();
            c.querySelector("input").focus();
        };
        if (!focus_search.__module__) Object.defineProperties(focus_search, {
            __module__ : {value: "read_book.highlights"}
        });

        function find(backwards) {
            var c, text, all_highlights, current, start, q, h;
            c = get_container();
            text = c.querySelector("input").value;
            if (!text) {
                return false;
            }
            all_highlights = list(c.querySelectorAll(".highlight")).as_array();
            current = c.querySelector(".highlight.current");
            if (current) {
                start = all_highlights.indexOf(current);
                if (backwards) {
                    all_highlights = all_highlights.slice(0, start).reverse().concat(all_highlights.slice(start).reverse());
                } else {
                    all_highlights = all_highlights.slice(start + 1).concat(all_highlights.slice(0, start + 1));
                }
            } else if (backwards) {
                all_highlights.reverse();
            }
            q = text.toLowerCase();
            var ρσ_Iter16 = ρσ_Iterable(all_highlights);
            for (var ρσ_Index16 = 0; ρσ_Index16 < ρσ_Iter16.length; ρσ_Index16++) {
                h = ρσ_Iter16[ρσ_Index16];
                if (h.dataset.title.toLowerCase().indexOf(q) > -1 || h.dataset.notes.toLowerCase().indexOf(q) > -1) {
                    set_current_highlight_entry(h);
                    h.scrollIntoView();
                    if (h === current) {
                        ρσ_interpolate_kwargs.call(this, warning_dialog, [_("Not found"), _("No other matches found for: {}").format(text)].concat([ρσ_desugar_kwargs({on_close: focus_search})]));
                    }
                    return true;
                }
            }
            ρσ_interpolate_kwargs.call(this, warning_dialog, [_("Not found"), _("No matches found for: {}").format(text)].concat([ρσ_desugar_kwargs({on_close: focus_search})]));
            return false;
        };
        if (!find.__argnames__) Object.defineProperties(find, {
            __argnames__ : {value: ["backwards"]},
            __module__ : {value: "read_book.highlights"}
        });

        function find_previous() {
            return find(true);
        };
        if (!find_previous.__module__) Object.defineProperties(find_previous, {
            __module__ : {value: "read_book.highlights"}
        });

        function find_next() {
            return find(false);
        };
        if (!find_next.__module__) Object.defineProperties(find_next, {
            __module__ : {value: "read_book.highlights"}
        });

        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var ans, sel, qsel, current;
                ans = "";
                sel = "#" + get_container_id();
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .ac-button"].concat([ρσ_desugar_kwargs({margin_left: "1rem", margin_top: "1ex"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .sel-button"].concat([ρσ_desugar_kwargs({display: "none"})]));
                sel += " .toc-group";
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " h3"].concat([ρσ_desugar_kwargs({display: "flex", align_items: "center", cursor: "pointer", margin_top: "1ex"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".expanded .caret-right"].concat([ρσ_desugar_kwargs({display: "none"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".collapsed .caret-down"].concat([ρσ_desugar_kwargs({display: "none"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".collapsed > div"].concat([ρσ_desugar_kwargs({display: "none"})]));
                qsel = sel + " .highlight";
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [qsel].concat([ρσ_desugar_kwargs({margin_top: "1ex", border_top: "solid 1px", padding_top: "1ex", cursor: "pointer"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [qsel + " .notes"].concat([ρσ_desugar_kwargs({display: "none", margin_top: "1ex", max_height: "20ex", overflow: "auto"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [qsel + " .actions"].concat([ρσ_desugar_kwargs({display: "none", margin_top: "1ex", justify_content: "space-between", flex_wrap: "wrap", gap: "0.65rem"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [qsel + " .title"].concat([ρσ_desugar_kwargs({display: "flex", align_items: "center"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [qsel + " .title-row"].concat([ρσ_desugar_kwargs({display: "flex", align_items: "center", justify_content: "space-between"})]));
                current = qsel + ".current";
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [current + " .title"].concat([ρσ_desugar_kwargs({font_weight: "bold", font_size: "larger"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [current + " .notes"].concat([ρσ_desugar_kwargs({display: "block"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [current + " .actions"].concat([ρσ_desugar_kwargs({display: "flex"})]));
                return ans;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "read_book.highlights"}
            });
            return ρσ_anonfunc;
        })());
        url_pat = /\bhttps?:\/\/\S{3,}/gi;
        closing_bracket_map = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["("] = ")";
            ρσ_d["["] = "]";
            ρσ_d["{"] = "}";
            ρσ_d["<"] = ">";
            ρσ_d["*"] = "*";
            ρσ_d["\""] = "\"";
            ρσ_d["'"] = "'";
            return ρσ_d;
        }).call(this);
        opening_brackets = Object.keys(closing_bracket_map).join("");
        function url(text, s, e) {
            var q, idx;
            while (".,?!".indexOf(text[ρσ_bound_index(e - 1, text)]) > -1 && e > 1) {
                e -= 1;
            }
            if (s > 0 && e <= text.length && closing_bracket_map[ρσ_bound_index(text[ρσ_bound_index(s - 1, text)], closing_bracket_map)]) {
                q = closing_bracket_map[ρσ_bound_index(text[ρσ_bound_index(s - 1, text)], closing_bracket_map)];
                idx = text.indexOf(q, s);
                if (idx > s) {
                    e = idx;
                }
            }
            return [s, e];
        };
        if (!url.__annotations__) Object.defineProperties(url, {
            __annotations__ : {value: {text: str, s: int, e: int}},
            __argnames__ : {value: ["text", "s", "e"]},
            __module__ : {value: "read_book.highlights"}
        });

        function render_notes(notes, container, make_urls_clickable) {
            var current_para, line;
            current_para = E.p();
            function add_para() {
                container.appendChild(current_para);
                if (container.childNodes.length > 1) {
                    container.lastChild.style.marginTop = "2ex";
                }
                current_para = E.p();
            };
            if (!add_para.__module__) Object.defineProperties(add_para, {
                __module__ : {value: "read_book.highlights"}
            });

            function add_line(line) {
                var urls, m, pos, ρσ_unpack, s, e;
                url_pat.lastIndex = 0;
                urls = [];
                while (make_urls_clickable) {
                    m = url_pat.exec(line);
                    if (!m) {
                        break;
                    }
                    urls.push(url(line, m.index, url_pat.lastIndex));
                }
                if (!urls.length) {
                    current_para.appendChild(document.createTextNode(line));
                    return;
                }
                pos = 0;
                var ρσ_Iter17 = ρσ_Iterable(urls);
                for (var ρσ_Index17 = 0; ρσ_Index17 < ρσ_Iter17.length; ρσ_Index17++) {
                    ρσ_unpack = ρσ_Iter17[ρσ_Index17];
                    s = ρσ_unpack[0];
                    e = ρσ_unpack[1];
                    if (s > pos) {
                        current_para.appendChild(document.createTextNode(line.slice(pos, s)));
                    }
                    current_para.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [line.slice(s, e)].concat([ρσ_desugar_kwargs({href: "javascript: void(0)", class_: "blue-link", onclick: ui_operations.open_url.bind(null, line.slice(s, e))})])));
                }
                if (urls[urls.length-1][1] < line.length) {
                    current_para.appendChild(document.createTextNode(line.slice(urls[urls.length-1][1])));
                }
            };
            if (!add_line.__argnames__) Object.defineProperties(add_line, {
                __argnames__ : {value: ["line"]},
                __module__ : {value: "read_book.highlights"}
            });

            var ρσ_Iter18 = ρσ_Iterable(notes.splitlines());
            for (var ρσ_Index18 = 0; ρσ_Index18 < ρσ_Iter18.length; ρσ_Index18++) {
                line = ρσ_Iter18[ρσ_Index18];
                if (!line || !line.strip()) {
                    if (current_para.childNodes.length) {
                        add_para();
                        continue;
                    }
                }
                add_line(line);
            }
            if (current_para.childNodes.length) {
                add_para();
            }
            return container;
        };
        if (!render_notes.__argnames__) Object.defineProperties(render_notes, {
            __argnames__ : {value: ["notes", "container", "make_urls_clickable"]},
            __module__ : {value: "read_book.highlights"}
        });

        function highlight_entry_clicked(ev) {
            set_current_highlight_entry(ev.currentTarget);
        };
        if (!highlight_entry_clicked.__argnames__) Object.defineProperties(highlight_entry_clicked, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.highlights"}
        });

        function set_current_highlight_entry(entry) {
            var c, h;
            c = get_container();
            var ρσ_Iter19 = ρσ_Iterable(c.querySelectorAll(".highlight"));
            for (var ρσ_Index19 = 0; ρσ_Index19 < ρσ_Iter19.length; ρσ_Index19++) {
                h = ρσ_Iter19[ρσ_Index19];
                h.classList.remove("current");
            }
            entry.classList.add("current");
        };
        if (!set_current_highlight_entry.__argnames__) Object.defineProperties(set_current_highlight_entry, {
            __argnames__ : {value: ["entry"]},
            __module__ : {value: "read_book.highlights"}
        });

        function show_in_text(annot_id, view) {
            view.highlight_action(annot_id, "goto");
        };
        if (!show_in_text.__argnames__) Object.defineProperties(show_in_text, {
            __argnames__ : {value: ["annot_id", "view"]},
            __module__ : {value: "read_book.highlights"}
        });

        function remove_highlight(annot_id, view, ev) {
            var entry;
            entry = ev.currentTarget.closest(".highlight");
            question_dialog(_("Are you sure?"), _("Do you want to permanently delete this highlight?"), (function() {
                var ρσ_anonfunc = function (yes) {
                    if (yes) {
                        entry.style.display = "none";
                        view.highlight_action(annot_id, "delete");
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["yes"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!remove_highlight.__argnames__) Object.defineProperties(remove_highlight, {
            __argnames__ : {value: ["annot_id", "view", "ev"]},
            __module__ : {value: "read_book.highlights"}
        });

        function edit_notes(annot_id, notes, view, ev) {
            var entry;
            entry = ev.currentTarget.closest(".highlight");
            ρσ_interpolate_kwargs.call(this, get_text_dialog, [_("Notes"), (function() {
                var ρσ_anonfunc = function (ok, text) {
                    var nc;
                    if (!ok) {
                        return;
                    }
                    text = text || "";
                    nc = entry.querySelector(".notes");
                    clear(nc);
                    view.set_notes_for_highlight(annot_id, text);
                    render_notes(text, nc);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ok", "text"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })()].concat([ρσ_desugar_kwargs({initial_text: notes || null})]));
        };
        if (!edit_notes.__argnames__) Object.defineProperties(edit_notes, {
            __argnames__ : {value: ["annot_id", "notes", "view", "ev"]},
            __module__ : {value: "read_book.highlights"}
        });

        function all_selected_entries() {
            return (function() {
                var ρσ_Iter = ρσ_Iterable(document.querySelectorAll(".highlight input:checked")), ρσ_Result = [], e;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    e = ρσ_Iter[ρσ_Index];
                    ρσ_Result.push(e.closest(".highlight"));
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
        };
        if (!all_selected_entries.__module__) Object.defineProperties(all_selected_entries, {
            __module__ : {value: "read_book.highlights"}
        });

        function item_select_toggled() {
            var entries, e;
            entries = all_selected_entries();
            var ρσ_Iter20 = ρσ_Iterable(document.querySelectorAll("#" + ρσ_str.format("{}", get_container_id()) + " .sel-button"));
            for (var ρσ_Index20 = 0; ρσ_Index20 < ρσ_Iter20.length; ρσ_Index20++) {
                e = ρσ_Iter20[ρσ_Index20];
                e.style.display = (entries.length) ? "inline-flex" : "none";
            }
        };
        if (!item_select_toggled.__module__) Object.defineProperties(item_select_toggled, {
            __module__ : {value: "read_book.highlights"}
        });

        function clear_selection() {
            var e;
            var ρσ_Iter21 = ρσ_Iterable(document.querySelectorAll(".highlight input:checked"));
            for (var ρσ_Index21 = 0; ρσ_Index21 < ρσ_Iter21.length; ρσ_Index21++) {
                e = ρσ_Iter21[ρσ_Index21];
                e.checked = false;
            }
            item_select_toggled();
        };
        if (!clear_selection.__module__) Object.defineProperties(clear_selection, {
            __module__ : {value: "read_book.highlights"}
        });

        function select_all() {
            var e;
            var ρσ_Iter22 = ρσ_Iterable(document.querySelectorAll(".highlight input"));
            for (var ρσ_Index22 = 0; ρσ_Index22 < ρσ_Iter22.length; ρσ_Index22++) {
                e = ρσ_Iter22[ρσ_Index22];
                e.checked = true;
            }
        };
        if (!select_all.__module__) Object.defineProperties(select_all, {
            __module__ : {value: "read_book.highlights"}
        });

        function delete_selection(annotations_manager, view) {
            var selected_highlight_items, text;
            selected_highlight_items = all_selected_entries();
            if (!selected_highlight_items.length) {
                return;
            }
            text = ngettext("Do you want to permanently delete the selected highlight?", "Do you want to permanently delete the {} selected highlights?", selected_highlight_items.length).format(selected_highlight_items.length);
            question_dialog(_("Are you sure?"), text, (function() {
                var ρσ_anonfunc = function (yes) {
                    var entry;
                    if (yes) {
                        var ρσ_Iter23 = ρσ_Iterable(selected_highlight_items);
                        for (var ρσ_Index23 = 0; ρσ_Index23 < ρσ_Iter23.length; ρσ_Index23++) {
                            entry = ρσ_Iter23[ρσ_Index23];
                            entry.style.display = "none";
                            view.highlight_action(entry.dataset.uuid, "delete");
                        }
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["yes"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!delete_selection.__argnames__) Object.defineProperties(delete_selection, {
            __argnames__ : {value: ["annotations_manager", "view"]},
            __module__ : {value: "read_book.highlights"}
        });

        function highlight_entry(h, onclick, view, hide_panel) {
            var hs, swatch, ans;
            function action(func, ev) {
                [ev.stopPropagation(), ev.preventDefault()];
                onclick(func);
            };
            if (!action.__argnames__) Object.defineProperties(action, {
                __argnames__ : {value: ["func", "ev"]},
                __module__ : {value: "read_book.highlights"}
            });

            hs = new HighlightStyle(h.style);
            swatch = E.div();
            hs.make_swatch(swatch, is_dark_theme());
            ans = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [swatch, ρσ_interpolate_kwargs.call(E, E.div, [h.highlighted_text].concat([ρσ_desugar_kwargs({style: "margin-left: 1rem"})]))].concat([ρσ_desugar_kwargs({class_: "title"})])), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox", onchange: item_select_toggled, onkeydown: (function() {
                var ρσ_anonfunc = function (ev) {
                    if (ev.key === "Escape") {
                        ev.stopPropagation();
                        ev.preventDefault();
                        hide_panel();
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })()})])].concat([ρσ_desugar_kwargs({style: "margin-left: 1rem", onclick: (function() {
                var ρσ_anonfunc = function (ev) {
                    ev.stopPropagation();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })()})]))].concat([ρσ_desugar_kwargs({class_: "title-row"})])), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Show in book"), "book", action.bind(null, show_in_text.bind(null, h.uuid))), E.span(" "), create_button(_("Edit notes"), "edit", edit_notes.bind(null, h.uuid, h.notes, view)), E.span(" "), create_button(_("Remove highlight"), "trash", remove_highlight.bind(null, h.uuid, view))].concat([ρσ_desugar_kwargs({class_: "actions"})])), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "notes"})])].concat([ρσ_desugar_kwargs({class_: "highlight", data_uuid: h.uuid, onclick: highlight_entry_clicked})]));
            if (h.notes) {
                render_notes(h.notes, ans.querySelector(".notes"), true);
            }
            ans.dataset.notes = h.notes || "";
            ans.dataset.title = h.highlighted_text || "";
            return ans;
        };
        if (!highlight_entry.__argnames__) Object.defineProperties(highlight_entry, {
            __argnames__ : {value: ["h", "onclick", "view", "hide_panel"]},
            __module__ : {value: "read_book.highlights"}
        });

        function create_icon_button(icon, title, action) {
            return ρσ_interpolate_kwargs.call(E, E.a, [svgicon(icon)].concat([ρσ_desugar_kwargs({class_: "calibre-icon-button ac-button", title: title, onclick: (function() {
                var ρσ_anonfunc = function (ev) {
                    ev.preventDefault();
                    action();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })(), onmousedown: (function() {
                var ρσ_anonfunc = function (e) {
                    e.preventDefault();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["e"]},
                    __module__ : {value: "read_book.highlights"}
                });
                return ρσ_anonfunc;
            })()})]));
        };
        if (!create_icon_button.__argnames__) Object.defineProperties(create_icon_button, {
            __argnames__ : {value: ["icon", "title", "action"]},
            __module__ : {value: "read_book.highlights"}
        });

        function create_highlights_panel(annotations_manager, hide_panel, book, container, onclick) {
            var next_button, prev_button, sb, clear_button, delete_button, all_button, export_button, c, toc_groups, toc_tt, toc, lines, ρσ_unpack, i, node, tt, h, highlights, g, ic, group;
            next_button = create_icon_button("chevron-down", _("Next match"), find_next);
            prev_button = create_icon_button("chevron-up", _("Previous match"), find_previous);
            sb = ρσ_interpolate_kwargs.call(this, create_search_bar, [find_next, "search-in-highlights"].concat([ρσ_desugar_kwargs({placeholder: _("Search") + "…", button: next_button, associated_widgets: ρσ_list_decorate([ prev_button ])})]));
            sb.style.flexGrow = "10";
            sb.classList.add("ac-button");
            clear_button = ρσ_interpolate_kwargs.call(this, create_button, [_("Clear"), "close", clear_selection, _("Clear selection")].concat([ρσ_desugar_kwargs({class_: "ac-button sel-button"})]));
            delete_button = ρσ_interpolate_kwargs.call(this, create_button, [_("Remove"), "trash", delete_selection.bind(null, annotations_manager, annotations_manager.view), _("Remove selected highlights")].concat([ρσ_desugar_kwargs({class_: "ac-button sel-button"})]));
            all_button = ρσ_interpolate_kwargs.call(this, create_button, [_("All"), "plus", select_all, _("Select all highlights")].concat([ρσ_desugar_kwargs({class_: "ac-button sel-button"})]));
            export_button = ρσ_interpolate_kwargs.call(this, create_button, [_("Export"), "cloud-download", show_export_dialog.bind(null, annotations_manager, book.metadata), _("Export all or selected highlights")].concat([ρσ_desugar_kwargs({class_: "ac-button"})]));
            c = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [sb, next_button, prev_button, clear_button, all_button, delete_button, export_button].concat([ρσ_desugar_kwargs({style: "display: flex; flex-wrap: wrap; margin-top: -1ex; align-items: center"})]))].concat([ρσ_desugar_kwargs({style: "padding: 1rem", id: get_container_id()})]));
            container.appendChild(c);
            toc_groups = Object.create(null);
            toc_tt = Object.create(null);
            var ρσ_Iter24 = ρσ_Iterable(annotations_manager.all_highlights());
            for (var ρσ_Index24 = 0; ρσ_Index24 < ρσ_Iter24.length; ρσ_Index24++) {
                h = ρσ_Iter24[ρσ_Index24];
                toc = _("Unknown");
                if (ρσ_exists.d(h.toc_family_titles).length) {
                    toc = (ρσ_expr_temp = h.toc_family_titles)[ρσ_expr_temp.length-1];
                }
                if (!toc_groups[(typeof toc === "number" && toc < 0) ? toc_groups.length + toc : toc]) {
                    toc_groups[(typeof toc === "number" && toc < 0) ? toc_groups.length + toc : toc] = [];
                    if (ρσ_exists.d(h.toc_family_titles).length) {
                        lines = [];
                        var ρσ_Iter25 = ρσ_Iterable(enumerate(h.toc_family_titles));
                        for (var ρσ_Index25 = 0; ρσ_Index25 < ρσ_Iter25.length; ρσ_Index25++) {
                            ρσ_unpack = ρσ_Iter25[ρσ_Index25];
                            i = ρσ_unpack[0];
                            node = ρσ_unpack[1];
                            lines.push("  ".repeat(i) + "➤ " + node);
                        }
                        tt = ngettext("Table of Contents section:", "Table of Contents sections:", lines.length);
                        tt += "\n" + "\n".join(lines);
                        toc_tt[(typeof toc === "number" && toc < 0) ? toc_tt.length + toc : toc] = tt;
                    }
                }
                toc_groups[(typeof toc === "number" && toc < 0) ? toc_groups.length + toc : toc].push(h);
            }
            function tree_icon(which) {
                var ans;
                ans = svgicon(which);
                ans.classList.add(which);
                return ans;
            };
            if (!tree_icon.__argnames__) Object.defineProperties(tree_icon, {
                __argnames__ : {value: ["which"]},
                __module__ : {value: "read_book.highlights"}
            });

            var ρσ_Iter26 = ρσ_Iterable(Object.keys(toc_groups));
            for (var ρσ_Index26 = 0; ρσ_Index26 < ρσ_Iter26.length; ρσ_Index26++) {
                group = ρσ_Iter26[ρσ_Index26];
                highlights = toc_groups[(typeof group === "number" && group < 0) ? toc_groups.length + group : group];
                g = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.h3, [tree_icon("caret-right"), tree_icon("caret-down"), E.div(" " + group)].concat([ρσ_desugar_kwargs({title: toc_tt[(typeof group === "number" && group < 0) ? toc_tt.length + group : group] || "", onclick: (function() {
                    var ρσ_anonfunc = function (ev) {
                        var tg;
                        tg = ev.currentTarget.closest(".toc-group");
                        if (tg.classList.contains("expanded")) {
                            tg.classList.remove("expanded");
                            tg.classList.add("collapsed");
                        } else {
                            tg.classList.remove("collapsed");
                            tg.classList.add("expanded");
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "read_book.highlights"}
                    });
                    return ρσ_anonfunc;
                })()})])), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-left: 1rem"})])].concat([ρσ_desugar_kwargs({class_: "toc-group expanded"})]));
                c.appendChild(g);
                ic = g.lastChild;
                var ρσ_Iter27 = ρσ_Iterable(highlights);
                for (var ρσ_Index27 = 0; ρσ_Index27 < ρσ_Iter27.length; ρσ_Index27++) {
                    h = ρσ_Iter27[ρσ_Index27];
                    ic.appendChild(highlight_entry(h, onclick, annotations_manager.view, hide_panel));
                }
            }
        };
        if (!create_highlights_panel.__argnames__) Object.defineProperties(create_highlights_panel, {
            __argnames__ : {value: ["annotations_manager", "hide_panel", "book", "container", "onclick"]},
            __module__ : {value: "read_book.highlights"}
        });

        ρσ_modules["read_book.highlights"].ICON_SIZE_VAL = ICON_SIZE_VAL;
        ρσ_modules["read_book.highlights"].ICON_SIZE_UNIT = ICON_SIZE_UNIT;
        ρσ_modules["read_book.highlights"].ICON_SIZE = ICON_SIZE;
        ρσ_modules["read_book.highlights"].builtin_colors_light = builtin_colors_light;
        ρσ_modules["read_book.highlights"].builtin_colors_dark = builtin_colors_dark;
        ρσ_modules["read_book.highlights"].builtin_decorations_light = builtin_decorations_light;
        ρσ_modules["read_book.highlights"].builtin_decorations_dark = builtin_decorations_dark;
        ρσ_modules["read_book.highlights"].all_style_keys = all_style_keys;
        ρσ_modules["read_book.highlights"].url_pat = url_pat;
        ρσ_modules["read_book.highlights"].closing_bracket_map = closing_bracket_map;
        ρσ_modules["read_book.highlights"].opening_brackets = opening_brackets;
        ρσ_modules["read_book.highlights"].builtin_friendly_name = builtin_friendly_name;
        ρσ_modules["read_book.highlights"].builtin_color = builtin_color;
        ρσ_modules["read_book.highlights"].default_color = default_color;
        ρσ_modules["read_book.highlights"].all_builtin_styles = all_builtin_styles;
        ρσ_modules["read_book.highlights"].custom_color_theme = custom_color_theme;
        ρσ_modules["read_book.highlights"].custom_decoration_theme = custom_decoration_theme;
        ρσ_modules["read_book.highlights"].style_key = style_key;
        ρσ_modules["read_book.highlights"].HighlightStyle = HighlightStyle;
        ρσ_modules["read_book.highlights"].highlight_style_as_css = highlight_style_as_css;
        ρσ_modules["read_book.highlights"].custom_styles_equal = custom_styles_equal;
        ρσ_modules["read_book.highlights"].all_styles = all_styles;
        ρσ_modules["read_book.highlights"].AddStyle = AddStyle;
        ρσ_modules["read_book.highlights"].EditNotesAndColors = EditNotesAndColors;
        ρσ_modules["read_book.highlights"].get_container_id = get_container_id;
        ρσ_modules["read_book.highlights"].get_container = get_container;
        ρσ_modules["read_book.highlights"].get_current_link_prefix = get_current_link_prefix;
        ρσ_modules["read_book.highlights"].link_to_epubcfi = link_to_epubcfi;
        ρσ_modules["read_book.highlights"].render_highlight_as_text = render_highlight_as_text;
        ρσ_modules["read_book.highlights"].ChapterGroup = ChapterGroup;
        ρσ_modules["read_book.highlights"].show_export_dialog = show_export_dialog;
        ρσ_modules["read_book.highlights"].focus_search = focus_search;
        ρσ_modules["read_book.highlights"].find = find;
        ρσ_modules["read_book.highlights"].find_previous = find_previous;
        ρσ_modules["read_book.highlights"].find_next = find_next;
        ρσ_modules["read_book.highlights"].url = url;
        ρσ_modules["read_book.highlights"].render_notes = render_notes;
        ρσ_modules["read_book.highlights"].highlight_entry_clicked = highlight_entry_clicked;
        ρσ_modules["read_book.highlights"].set_current_highlight_entry = set_current_highlight_entry;
        ρσ_modules["read_book.highlights"].show_in_text = show_in_text;
        ρσ_modules["read_book.highlights"].remove_highlight = remove_highlight;
        ρσ_modules["read_book.highlights"].edit_notes = edit_notes;
        ρσ_modules["read_book.highlights"].all_selected_entries = all_selected_entries;
        ρσ_modules["read_book.highlights"].item_select_toggled = item_select_toggled;
        ρσ_modules["read_book.highlights"].clear_selection = clear_selection;
        ρσ_modules["read_book.highlights"].select_all = select_all;
        ρσ_modules["read_book.highlights"].delete_selection = delete_selection;
        ρσ_modules["read_book.highlights"].highlight_entry = highlight_entry;
        ρσ_modules["read_book.highlights"].create_icon_button = create_icon_button;
        ρσ_modules["read_book.highlights"].create_highlights_panel = create_highlights_panel;
    })();

    (function(){
        var __name__ = "read_book.shortcuts";
        var capital_letters, x;
        var _ = ρσ_modules.gettext.gettext;

        var runtime = ρσ_modules["read_book.globals"].runtime;

        function parse_key_repr(sc) {
            var parts, key, ans, q, modifier;
            parts = sc.split("+");
            if (sc.endsWith("++")) {
                parts = parts.slice(0, -2);
                parts.push("+");
            }
            key = parts[parts.length-1];
            ans = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["key"] = key;
                ρσ_d["altKey"] = false;
                ρσ_d["ctrlKey"] = false;
                ρσ_d["metaKey"] = false;
                ρσ_d["shiftKey"] = false;
                return ρσ_d;
            }).call(this);
            var ρσ_Iter0 = ρσ_Iterable(parts.slice(0, -1));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                modifier = ρσ_Iter0[ρσ_Index0];
                q = modifier.toLowerCase();
                if (q === "ctrl") {
                    ans.ctrlKey = true;
                } else if (q === "alt") {
                    ans.altKey = true;
                } else if (q === "meta" || q === "cmd") {
                    ans.metaKey = true;
                } else if (q === "shift") {
                    ans.shiftKey = true;
                }
            }
            return ans;
        };
        if (!parse_key_repr.__argnames__) Object.defineProperties(parse_key_repr, {
            __argnames__ : {value: ["sc"]},
            __module__ : {value: "read_book.shortcuts"}
        });

        function desc(sc, group, short, long) {
            var pkey, x;
            if (typeof sc === "string") {
                sc = [sc];
            }
            pkey = [];
            var ρσ_Iter1 = ρσ_Iterable(sc);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                x = ρσ_Iter1[ρσ_Index1];
                pkey.push(parse_key_repr(x));
            }
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["group"] = group;
                ρσ_d["short"] = short;
                ρσ_d["long"] = long;
                ρσ_d["shortcuts"] = pkey;
                return ρσ_d;
            }).call(this);
        };
        if (!desc.__argnames__) Object.defineProperties(desc, {
            __argnames__ : {value: ["sc", "group", "short", "long"]},
            __module__ : {value: "read_book.shortcuts"}
        });

        function keyevent_as_shortcut(evt) {
            var key;
            key = evt.key;
            if (capital_letters[(typeof key === "number" && key < 0) ? capital_letters.length + key : key] && evt.shiftKey) {
                key = key.toLowerCase();
            }
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["key"] = key;
                ρσ_d["altKey"] = evt.altKey;
                ρσ_d["ctrlKey"] = evt.ctrlKey;
                ρσ_d["metaKey"] = evt.metaKey;
                ρσ_d["shiftKey"] = evt.shiftKey;
                return ρσ_d;
            }).call(this);
        };
        if (!keyevent_as_shortcut.__argnames__) Object.defineProperties(keyevent_as_shortcut, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.shortcuts"}
        });

        function shortcut_differs(a, b) {
            return !((a.key === b.key && a.altKey === b.altKey && a.ctrlKey === b.ctrlKey && a.metaKey === b.metaKey && a.shiftKey === b.shiftKey));
        };
        if (!shortcut_differs.__argnames__) Object.defineProperties(shortcut_differs, {
            __argnames__ : {value: ["a", "b"]},
            __module__ : {value: "read_book.shortcuts"}
        });

        capital_letters = (function() {
            var ρσ_Iter = ρσ_Iterable("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), ρσ_Result = Object.create(null), x;
            for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                x = ρσ_Iter[ρσ_Index];
                ρσ_Result[x] = (true);
            }
            return ρσ_Result;
        })();
        function get_key_text(evt) {
            var key;
            key = evt.key;
            if (key) {
                if (evt.code && key.toLowerCase() !== key && evt.code.startsWith("Key") && capital_letters[(typeof key === "number" && key < 0) ? capital_letters.length + key : key]) {
                    key = key.toLowerCase();
                }
            }
            return key;
        };
        if (!get_key_text.__argnames__) Object.defineProperties(get_key_text, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.shortcuts"}
        });

        function keyevent_to_index(evt) {
            var parts, mod;
            parts = [];
            var ρσ_Iter2 = ρσ_Iterable(['altKey', 'ctrlKey', 'metaKey', 'shiftKey']);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                mod = ρσ_Iter2[ρσ_Index2];
                parts.push((evt[(typeof mod === "number" && mod < 0) ? evt.length + mod : mod]) ? "y" : "n");
            }
            return parts.join("") + get_key_text(evt);
        };
        if (!keyevent_to_index.__argnames__) Object.defineProperties(keyevent_to_index, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.shortcuts"}
        });

        function key_as_text(evt) {
            var mods, x, key;
            mods = [];
            var ρσ_Iter3 = ρσ_Iterable(ρσ_list_decorate([ "alt", "ctrl", "meta", "shift" ]));
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                x = ρσ_Iter3[ρσ_Index3];
                if (evt[ρσ_bound_index(x + "Key", evt)]) {
                    if (ρσ_in("macos", window.navigator.userAgent)) {
                        if (x === "alt") {
                            x = "option";
                        } else if (x === "meta") {
                            x = "⌘";
                        }
                    }
                    mods.push(x.capitalize());
                }
            }
            mods = "+".join(mods);
            if (mods) {
                mods += "+";
            }
            key = get_key_text(evt);
            if (key === " ") {
                key = "Space";
            }
            return mods + key;
        };
        if (!key_as_text.__argnames__) Object.defineProperties(key_as_text, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.shortcuts"}
        });

        function common_shortcuts() {
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["start_of_file"] = desc(['Ctrl+ArrowUp', 'Ctrl+ArrowLeft', 'Home'], "scroll", _("Scroll to the beginning of the current file"), _("When the e-book is made of multiple individual files, scroll to the start of the current file"));
                ρσ_d["start_of_book"] = desc("Ctrl+Home", "scroll", _("Scroll to the beginning of the book"));
                ρσ_d["end_of_book"] = desc("Ctrl+End", "scroll", _("Scroll to the end of the book"));
                ρσ_d["end_of_file"] = desc(['Ctrl+ArrowDown', 'Ctrl+ArrowRight', 'End'], "scroll", _("Scroll to the end of the current file"), _("When the e-book is made of multiple individual files, scroll to the end of the current file"));
                ρσ_d["up"] = desc("ArrowUp", "scroll", _("Scroll backwards smoothly (by screen-fulls in paged mode)"), _("Scroll backwards, smoothly in flow mode and by screen fulls in paged mode"));
                ρσ_d["down"] = desc("ArrowDown", "scroll", _("Scroll forwards smoothly (by screen-fulls in paged mode)"), _("Scroll forwards, smoothly in flow mode and by screen fulls in paged mode"));
                ρσ_d["left"] = desc("ArrowLeft", "scroll", _("Scroll left"), _("Scroll leftwards by a little in flow mode and by a page in paged mode"));
                ρσ_d["right"] = desc("ArrowRight", "scroll", _("Scroll right"), _("Scroll rightwards by a little in flow mode and by a page in paged mode"));
                ρσ_d["pageup"] = desc(['PageUp', 'Shift+ '], "scroll", _("Scroll backwards by screen-fulls"));
                ρσ_d["pagedown"] = desc([' ', 'PageDown'], "scroll", _("Scroll forwards by screen-fulls"));
                ρσ_d["previous_section"] = desc("Ctrl+PageUp", "scroll", _("Scroll to the previous section"));
                ρσ_d["next_section"] = desc("Ctrl+PageDown", "scroll", _("Scroll to the next section"));
                ρσ_d["back"] = desc(['Alt+ArrowLeft'], "scroll", _("Back"));
                ρσ_d["forward"] = desc(['Alt+ArrowRight'], "scroll", _("Forward"));
                ρσ_d["toggle_toc"] = desc("Ctrl+t", "ui", _("Show/hide Table of Contents"));
                ρσ_d["read_aloud"] = desc("Ctrl+s", "ui", _("Read aloud"));
                ρσ_d["toggle_hints"] = desc("Alt+f", "ui", _("Follow links with the keyboard"));
                ρσ_d["copy_to_clipboard"] = desc(['Ctrl+c', 'Meta+c'], "ui", _("Copy to clipboard"));
                ρσ_d["copy_location_to_clipboard"] = desc(['Alt+c'], "ui", _("Copy current location to clipboard"));
                ρσ_d["copy_location_as_url_to_clipboard"] = desc(['Ctrl+Shift+c'], "ui", _("Copy current location as calibre:// URL to clipboard"));
                ρσ_d["start_search"] = desc(['/', 'Ctrl+f', 'Cmd+f'], "ui", _("Start search"));
                ρσ_d["next_match"] = desc(['F3', 'Enter'], "ui", _("Find next"));
                ρσ_d["previous_match"] = desc(['Shift+F3', 'Shift+Enter'], "ui", _("Find previous"));
                ρσ_d["increase_font_size"] = desc(['Ctrl+=', 'Ctrl++', 'Ctrl+Shift++', 'Ctrl+Shift+=', 'Meta++', 'Meta+Shift++', 'Meta+Shift+='], "ui", _("Increase font size"));
                ρσ_d["decrease_font_size"] = desc(['Ctrl+-', 'Ctrl+_', 'Ctrl+Shift+-', 'Ctrl+Shift+_', 'Meta+-', 'Meta+_'], "ui", _("Decrease font size"));
                ρσ_d["default_font_size"] = desc("Ctrl+0", "ui", _("Restore default font size"));
                ρσ_d["increase_number_of_columns"] = desc(['Ctrl+]'], "ui", _("Increase number of pages per screen"));
                ρσ_d["decrease_number_of_columns"] = desc(['Ctrl+['], "ui", _("Decrease number of pages per screen"));
                ρσ_d["reset_number_of_columns"] = desc(['Ctrl+Alt+c'], "ui", _("Make number of pages per screen automatic"));
                ρσ_d["toggle_full_screen"] = desc(['F11', 'Ctrl+Shift+f'], "ui", _("Toggle full screen"));
                ρσ_d["toggle_paged_mode"] = desc("Ctrl+m", "ui", _("Toggle between Paged mode and Flow mode for text layout"));
                ρσ_d["toggle_scrollbar"] = desc("Ctrl+w", "ui", _("Toggle the scrollbar"));
                ρσ_d["toggle_reference_mode"] = desc("Ctrl+x", "ui", _("Toggle the Reference mode"));
                ρσ_d["toggle_bookmarks"] = desc(['Ctrl+b'], "ui", _("Show/hide bookmarks"));
                ρσ_d["new_bookmark"] = desc(['Ctrl+Alt+b'], "ui", _("Create a new bookmark"));
                ρσ_d["metadata"] = desc(['Ctrl+n', 'Ctrl+e'], "ui", _("Show the book metadata"));
                ρσ_d["show_profiles"] = desc(['Alt+p'], "ui", _("Change settings quickly by creating and switching to \"profiles\""));
                ρσ_d["reload_book"] = desc(['Ctrl+Alt+F5', 'Ctrl+Alt+r'], "ui", _("Reload book"));
                ρσ_d["extend_selection_by_word"] = desc(['Ctrl+Shift+ArrowRight'], "ui", _("Alter the current selection forward by a word"));
                ρσ_d["shrink_selection_by_word"] = desc(['Ctrl+Shift+ArrowLeft'], "ui", _("Alter the current selection backwards by a word"));
                ρσ_d["extend_selection_by_character"] = desc(['Shift+ArrowRight'], "ui", _("Alter the current selection forward by a character"));
                ρσ_d["shrink_selection_by_character"] = desc(['Shift+ArrowLeft'], "ui", _("Alter the current selection backwards by a character"));
                ρσ_d["extend_selection_by_line"] = desc(['Shift+ArrowDown'], "ui", _("Alter the current selection forward by a line"));
                ρσ_d["extend_selection_to_start_of_line"] = desc(['Shift+Home'], "ui", _("Extend the current selection to the start of the line"));
                ρσ_d["extend_selection_to_end_of_line"] = desc(['Shift+End'], "ui", _("Extend the current selection to the end of the line"));
                ρσ_d["select_all"] = desc(["Ctrl+a"], "ui", _("Select all"));
                ρσ_d["shrink_selection_by_line"] = desc(['Shift+ArrowUp'], "ui", _("Alter the current selection backwards by a line"));
                ρσ_d["extend_selection_by_paragraph"] = desc(['Ctrl+Shift+ArrowDown'], "ui", _("Alter the current selection forward by a paragraph"));
                ρσ_d["shrink_selection_by_paragraph"] = desc(['Ctrl+Shift+ArrowUp'], "ui", _("Alter the current selection backwards by a paragraph"));
                ρσ_d["show_chrome"] = desc(['Escape', 'ContextMenu'], "ui", _("Show the E-book viewer controls"));
                ρσ_d["preferences"] = desc(['Ctrl+,', 'Ctrl+Escape', 'Meta+Escape', 'Meta+,'], "ui", _("Show E-book viewer preferences"));
                ρσ_d["goto_location"] = desc([';', ':', 'Shift+:', 'Shift+;', 'Ctrl+g'], "ui", _("Go to a specified book location or position"));
                ρσ_d["toggle_autoscroll"] = desc("Ctrl+ ", "scroll", _("Toggle auto-scroll"));
                ρσ_d["scrollspeed_increase"] = desc("Alt+ArrowUp", "scroll", _("Auto scroll faster"));
                ρσ_d["scrollspeed_decrease"] = desc("Alt+ArrowDown", "scroll", _("Auto scroll slower"));
                return ρσ_d;
            }).call(this);
        };
        if (!common_shortcuts.__module__) Object.defineProperties(common_shortcuts, {
            __module__ : {value: "read_book.shortcuts"}
        });

        function shortcuts_definition() {
            var ans;
            ans = shortcuts_definition.ans;
            if (!ans) {
                ans = shortcuts_definition.ans = common_shortcuts();
                if (runtime.is_standalone_viewer) {
                    add_standalone_viewer_shortcuts(ans);
                } else {
                    ans["sync_book"] = desc([], "ui", _("Sync last read position/annotations"));
                }
            }
            return ans;
        };
        if (!shortcuts_definition.__module__) Object.defineProperties(shortcuts_definition, {
            __module__ : {value: "read_book.shortcuts"}
        });

        function shortcuts_group_desc() {
            var ans;
            ans = shortcuts_group_desc.ans;
            if (!ans) {
                ans = shortcuts_group_desc.ans = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["scroll"] = _("Navigation");
                    ρσ_d["ui"] = _("Interface");
                    return ρσ_d;
                }).call(this);
            }
            return ans;
        };
        if (!shortcuts_group_desc.__module__) Object.defineProperties(shortcuts_group_desc, {
            __module__ : {value: "read_book.shortcuts"}
        });

        function add_standalone_viewer_shortcuts(sc) {
            var ismacos, quit_shortcut;
            ismacos = ρσ_in("macos", window.navigator.userAgent);
            sc["toggle_inspector"] = desc(['Ctrl+i'], "ui", _("Show/hide Inspector"));
            sc["toggle_lookup"] = desc(['Ctrl+l'], "ui", _("Show/hide the word lookup panel"));
            quit_shortcut = (ismacos) ? "Meta+q" : "Ctrl+q";
            sc["quit"] = desc(quit_shortcut, "ui", _("Quit the E-book viewer"));
            sc["print"] = desc("Ctrl+p", "ui", _("Print book to PDF"));
            sc["toggle_toolbar"] = desc("Ctrl+F11", "ui", _("Toggle the toolbar"));
            sc["toggle_highlights"] = desc("Ctrl+h", "ui", _("Toggle the highlights panel"));
            sc["edit_book"] = desc("Ctrl+d", "ui", _("Edit this book"));
        };
        if (!add_standalone_viewer_shortcuts.__argnames__) Object.defineProperties(add_standalone_viewer_shortcuts, {
            __argnames__ : {value: ["sc"]},
            __module__ : {value: "read_book.shortcuts"}
        });

        function create_shortcut_map(custom_shortcuts) {
            var ans, scd, entry, shortcuts, sc, sc_name;
            ans = Object.create(null);
            scd = shortcuts_definition();
            var ρσ_Iter4 = ρσ_Iterable(Object.keys(scd));
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                sc_name = ρσ_Iter4[ρσ_Index4];
                entry = scd[(typeof sc_name === "number" && sc_name < 0) ? scd.length + sc_name : sc_name];
                shortcuts = entry.shortcuts;
                if (custom_shortcuts && custom_shortcuts[(typeof sc_name === "number" && sc_name < 0) ? custom_shortcuts.length + sc_name : sc_name]) {
                    shortcuts = custom_shortcuts[(typeof sc_name === "number" && sc_name < 0) ? custom_shortcuts.length + sc_name : sc_name];
                }
                var ρσ_Iter5 = ρσ_Iterable(shortcuts);
                for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                    sc = ρσ_Iter5[ρσ_Index5];
                    ans[ρσ_bound_index(keyevent_to_index(sc), ans)] = sc_name;
                }
            }
            return ans;
        };
        if (!create_shortcut_map.__argnames__) Object.defineProperties(create_shortcut_map, {
            __argnames__ : {value: ["custom_shortcuts"]},
            __module__ : {value: "read_book.shortcuts"}
        });

        function shortcut_for_key_event(evt, shortcut_map) {
            var idx;
            idx = keyevent_to_index(evt);
            return shortcut_map[(typeof idx === "number" && idx < 0) ? shortcut_map.length + idx : idx];
        };
        if (!shortcut_for_key_event.__argnames__) Object.defineProperties(shortcut_for_key_event, {
            __argnames__ : {value: ["evt", "shortcut_map"]},
            __module__ : {value: "read_book.shortcuts"}
        });

        ρσ_modules["read_book.shortcuts"].capital_letters = capital_letters;
        ρσ_modules["read_book.shortcuts"].x = x;
        ρσ_modules["read_book.shortcuts"].parse_key_repr = parse_key_repr;
        ρσ_modules["read_book.shortcuts"].desc = desc;
        ρσ_modules["read_book.shortcuts"].keyevent_as_shortcut = keyevent_as_shortcut;
        ρσ_modules["read_book.shortcuts"].shortcut_differs = shortcut_differs;
        ρσ_modules["read_book.shortcuts"].get_key_text = get_key_text;
        ρσ_modules["read_book.shortcuts"].keyevent_to_index = keyevent_to_index;
        ρσ_modules["read_book.shortcuts"].key_as_text = key_as_text;
        ρσ_modules["read_book.shortcuts"].common_shortcuts = common_shortcuts;
        ρσ_modules["read_book.shortcuts"].shortcuts_definition = shortcuts_definition;
        ρσ_modules["read_book.shortcuts"].shortcuts_group_desc = shortcuts_group_desc;
        ρσ_modules["read_book.shortcuts"].add_standalone_viewer_shortcuts = add_standalone_viewer_shortcuts;
        ρσ_modules["read_book.shortcuts"].create_shortcut_map = create_shortcut_map;
        ρσ_modules["read_book.shortcuts"].shortcut_for_key_event = shortcut_for_key_event;
    })();

    (function(){
        var __name__ = "read_book.hints";
        var clear = ρσ_modules.dom.clear;

        var E = ρσ_modules.elementmaker.E;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var _ = ρσ_modules.gettext.gettext;

        var shortcut_for_key_event = ρσ_modules["read_book.shortcuts"].shortcut_for_key_event;

        function Hints() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            Hints.prototype.__bind_methods__.call(this);
            Hints.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(Hints.prototype, "__bind_methods__", {value: function () {
            this.reset = Hints.prototype.reset.bind(this);
            this.focus = Hints.prototype.focus.bind(this);
            this.hide = Hints.prototype.hide.bind(this);
            this.show = Hints.prototype.show.bind(this);
            this.on_keydown = Hints.prototype.on_keydown.bind(this);
            this.container_clicked = Hints.prototype.container_clicked.bind(this);
            this.apply_prefix = Hints.prototype.apply_prefix.bind(this);
            this.send_message = Hints.prototype.send_message.bind(this);
            this.handle_message = Hints.prototype.handle_message.bind(this);
            this.no_hints_found = Hints.prototype.no_hints_found.bind(this);
        }});
        Object.defineProperties(Hints.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById("book-hints-overlay");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "is_visible": {
                "enumerable": true, 
                "get": function is_visible() {
                    var self = this;
                    return self.container.style.display !== "none";
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        Hints.prototype.__init__ = function __init__(view) {
            var self = this;
            var container;
            self.view = view;
            container = self.container;
            container.setAttribute("tabindex", "0");
            container.style.overflow = "hidden";
            container.addEventListener("keydown", self.on_keydown, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("click", self.container_clicked, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            self.reset();
        };
        if (!Hints.prototype.__init__.__argnames__) Object.defineProperties(Hints.prototype.__init__, {
            __argnames__ : {value: ["view"]},
            __module__ : {value: "read_book.hints"}
        });
        Hints.__argnames__ = Hints.prototype.__init__.__argnames__;
        Hints.__handles_kwarg_interpolation__ = Hints.prototype.__init__.__handles_kwarg_interpolation__;
        Hints.prototype.reset = function reset() {
            var self = this;
            self.hints_map = Object.create(null);
            self.current_prefix = "";
        };
        if (!Hints.prototype.reset.__module__) Object.defineProperties(Hints.prototype.reset, {
            __module__ : {value: "read_book.hints"}
        });
        Hints.prototype.focus = function focus() {
            var self = this;
            self.container.focus();
        };
        if (!Hints.prototype.focus.__module__) Object.defineProperties(Hints.prototype.focus, {
            __module__ : {value: "read_book.hints"}
        });
        Hints.prototype.hide = function hide() {
            var self = this;
            if (self.is_visible) {
                self.container.style.display = "none";
                self.send_message("hide");
                self.reset();
                self.view.focus_iframe();
            }
        };
        if (!Hints.prototype.hide.__module__) Object.defineProperties(Hints.prototype.hide, {
            __module__ : {value: "read_book.hints"}
        });
        Hints.prototype.show = function show() {
            var self = this;
            var c;
            if (!self.is_visible) {
                self.reset();
                c = self.container;
                c.style.display = "block";
                clear(c);
                self.focus();
                self.send_message("show");
            }
        };
        if (!Hints.prototype.show.__module__) Object.defineProperties(Hints.prototype.show, {
            __module__ : {value: "read_book.hints"}
        });
        Hints.prototype.on_keydown = function on_keydown(ev) {
            var self = this;
            var hint_keys, q, sc_name;
            [ev.preventDefault(), ev.stopPropagation()];
            if (ev.key === "Escape") {
                self.hide();
                return;
            }
            if (ev.key === "Enter") {
                if (self.current_prefix) {
                    self.apply_prefix(true);
                }
                return;
            }
            if (ev.key === "Backspace") {
                if (self.current_prefix) {
                    self.current_prefix = self.current_prefix.slice(0, -1);
                    self.apply_prefix();
                }
                return;
            }
            hint_keys = list("1234567890abcdefghijklmnopqrstuvwxyz");
            q = ev.key.toLowerCase();
            if (hint_keys.indexOf(q) > -1) {
                self.current_prefix += q;
                self.apply_prefix();
            }
            sc_name = shortcut_for_key_event(ev, self.view.keyboard_shortcut_map);
            if (!sc_name) {
                return;
            }
        };
        if (!Hints.prototype.on_keydown.__argnames__) Object.defineProperties(Hints.prototype.on_keydown, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.hints"}
        });
        Hints.prototype.container_clicked = function container_clicked(ev) {
            var self = this;
            [ev.stopPropagation(), ev.preventDefault()];
            self.hide();
        };
        if (!Hints.prototype.container_clicked.__argnames__) Object.defineProperties(Hints.prototype.container_clicked, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.hints"}
        });
        Hints.prototype.apply_prefix = function apply_prefix(accept_full_match) {
            var self = this;
            var matches, q, k;
            matches = [];
            if (self.current_prefix) {
                var ρσ_Iter0 = ρσ_Iterable(Object.keys(self.hints_map));
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    k = ρσ_Iter0[ρσ_Index0];
                    if (k === "_length") {
                        continue;
                    }
                    q = encode(int(k));
                    if (accept_full_match) {
                        if (q === self.current_prefix) {
                            matches.push(k);
                            break;
                        }
                    } else if (q.startswith(self.current_prefix)) {
                        matches.push(k);
                    }
                }
            }
            if (matches.length === 1) {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["activate"].concat([ρσ_desugar_kwargs({hint: (ρσ_expr_temp = self.hints_map)[ρσ_bound_index(matches[0], ρσ_expr_temp)]})]));
                self.hide();
            } else {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["apply_prefix"].concat([ρσ_desugar_kwargs({prefix: self.current_prefix})]));
            }
        };
        if (!Hints.prototype.apply_prefix.__argnames__) Object.defineProperties(Hints.prototype.apply_prefix, {
            __argnames__ : {value: ["accept_full_match"]},
            __module__ : {value: "read_book.hints"}
        });
        Hints.prototype.send_message = function send_message() {
            var self = this;
            var type = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            ρσ_interpolate_kwargs.call(self.view.iframe_wrapper, self.view.iframe_wrapper.send_message, ["hints"].concat([ρσ_desugar_kwargs(kw, {type: type})]));
        };
        if (!Hints.prototype.send_message.__handles_kwarg_interpolation__) Object.defineProperties(Hints.prototype.send_message, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["type"]},
            __module__ : {value: "read_book.hints"}
        });
        Hints.prototype.handle_message = function handle_message(msg) {
            var self = this;
            if (msg.type === "shown") {
                self.reset();
                self.hints_map = msg.hints_map;
                if (!self.hints_map._length) {
                    self.no_hints_found();
                }
            }
        };
        if (!Hints.prototype.handle_message.__argnames__) Object.defineProperties(Hints.prototype.handle_message, {
            __argnames__ : {value: ["msg"]},
            __module__ : {value: "read_book.hints"}
        });
        Hints.prototype.no_hints_found = function no_hints_found() {
            var self = this;
            var c;
            c = self.container;
            c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("No links found. Press Esc to close")].concat([ρσ_desugar_kwargs({style: "position: absolute; margin: auto; top: 50%; left: 50%; background: " + ρσ_str.format("{}", get_color("window-background")) + ";" + " padding: 1rem; border: solid 1px currentColor; border-radius: 4px; transform: translate(-50%, -50%);"})])));
        };
        if (!Hints.prototype.no_hints_found.__module__) Object.defineProperties(Hints.prototype.no_hints_found, {
            __module__ : {value: "read_book.hints"}
        });
        Hints.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        Hints.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(Hints.prototype, "__bases__", {value: []});
        
        

        function is_visible(a) {
            var rect;
            if (!a.offsetParent) {
                return false;
            }
            rect = a.getBoundingClientRect();
            return rect.left >= 0 && rect.top >= 0 && rect.left < window.innerWidth && rect.top < window.innerHeight;
        };
        if (!is_visible.__argnames__) Object.defineProperties(is_visible, {
            __argnames__ : {value: ["a"]},
            __module__ : {value: "read_book.hints"}
        });

        function encode(i) {
            return i.toString(36).toLowerCase();
        };
        if (!encode.__argnames__) Object.defineProperties(encode, {
            __argnames__ : {value: ["i"]},
            __module__ : {value: "read_book.hints"}
        });

        function hint_visible_links() {
            var i, hint_map, h, a;
            i = 0;
            hint_map = Object.create(null);
            var ρσ_Iter1 = ρσ_Iterable(document.body.querySelectorAll("a[href]"));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                a = ρσ_Iter1[ρσ_Index1];
                if (is_visible(a)) {
                    i += 1;
                    h = i + "";
                    a.dataset.calibreHintRender = encode(i);
                    a.dataset.calibreHintValue = h;
                    a.classList.add("calibre-hint-visible");
                    hint_map[(typeof h === "number" && h < 0) ? hint_map.length + h : h] = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["type"] = "link";
                        ρσ_d["value"] = i;
                        return ρσ_d;
                    }).call(this);
                }
            }
            hint_map._length = i;
            return hint_map;
        };
        if (!hint_visible_links.__module__) Object.defineProperties(hint_visible_links, {
            __module__ : {value: "read_book.hints"}
        });

        function unhint_links() {
            var a;
            var ρσ_Iter2 = ρσ_Iterable(document.body.querySelectorAll("a[href]"));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                a = ρσ_Iter2[ρσ_Index2];
                a.classList.remove("calibre-hint-visible", "calibre-hint-enter");
                delete a.dataset.calibreHintRender;
                delete a.dataset.calibreHintValue;
            }
        };
        if (!unhint_links.__module__) Object.defineProperties(unhint_links, {
            __module__ : {value: "read_book.hints"}
        });

        function apply_prefix_to_hints(prefix) {
            var val, r, leftover, a;
            var ρσ_Iter3 = ρσ_Iterable(document.body.querySelectorAll("[data-calibre-hint-value]"));
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                a = ρσ_Iter3[ρσ_Index3];
                val = int(a.dataset.calibreHintValue);
                r = encode(val);
                a.classList.remove("calibre-hint-enter");
                if (!prefix || r.startsWith(prefix)) {
                    a.classList.add("calibre-hint-visible");
                    a.dataset.calibreHintRender = leftover = r.slice(prefix.length) || " ";
                    if (leftover === " ") {
                        a.classList.add("calibre-hint-enter");
                    }
                } else {
                    a.classList.remove("calibre-hint-visible");
                }
            }
        };
        if (!apply_prefix_to_hints.__argnames__) Object.defineProperties(apply_prefix_to_hints, {
            __argnames__ : {value: ["prefix"]},
            __module__ : {value: "read_book.hints"}
        });

        ρσ_modules["read_book.hints"].Hints = Hints;
        ρσ_modules["read_book.hints"].is_visible = is_visible;
        ρσ_modules["read_book.hints"].encode = encode;
        ρσ_modules["read_book.hints"].hint_visible_links = hint_visible_links;
        ρσ_modules["read_book.hints"].unhint_links = unhint_links;
        ρσ_modules["read_book.hints"].apply_prefix_to_hints = apply_prefix_to_hints;
    })();

    (function(){
        var __name__ = "read_book.mathjax";
        var standalone_proceed_data;
        var E = ρσ_modules.elementmaker.E;

        var runtime = ρσ_modules["read_book.globals"].runtime;

        function get_url(mathjax_files, name) {
            var ans;
            ans = mathjax_files[(typeof name === "number" && name < 0) ? mathjax_files.length + name : name];
            if (!ans) {
                return name;
            }
            if (typeof ans !== "string") {
                ans = mathjax_files[(typeof name === "number" && name < 0) ? mathjax_files.length + name : name] = window.URL.createObjectURL(ans);
            }
            return ans;
        };
        if (!get_url.__argnames__) Object.defineProperties(get_url, {
            __argnames__ : {value: ["mathjax_files", "name"]},
            __module__ : {value: "read_book.mathjax"}
        });

        function postprocess(link_uid) {
            var href, a;
            var ρσ_Iter0 = ρσ_Iterable(document.getElementsByTagName("a"));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                a = ρσ_Iter0[ρσ_Index0];
                href = a.getAttribute("href");
                if (href && href.startswith("#")) {
                    a.setAttribute("href", "javascript: void(0)");
                    a.setAttribute("data-" + link_uid, JSON.stringify((function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["frag"] = href.slice(1);
                        return ρσ_d;
                    }).call(this)));
                }
            }
        };
        if (!postprocess.__argnames__) Object.defineProperties(postprocess, {
            __argnames__ : {value: ["link_uid"]},
            __module__ : {value: "read_book.mathjax"}
        });

        function load_mathjax(src) {
            var script;
            script = ρσ_interpolate_kwargs.call(E, E.script, [ρσ_desugar_kwargs({type: "text/javascript"})]);
            script.async = true;
            script.src = src;
            document.head.appendChild(script);
        };
        if (!load_mathjax.__argnames__) Object.defineProperties(load_mathjax, {
            __argnames__ : {value: ["src"]},
            __module__ : {value: "read_book.mathjax"}
        });

        standalone_proceed_data = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["link_uid"] = null;
            ρσ_d["proceed"] = null;
            ρσ_d["event_listender_added"] = false;
            return ρσ_d;
        }).call(this);
        function standalone_proceed() {
            if (standalone_proceed_data.proceed) {
                postprocess(standalone_proceed_data.link_uid);
                standalone_proceed_data.proceed();
                standalone_proceed_data.proceed = null;
            }
        };
        if (!standalone_proceed.__module__) Object.defineProperties(standalone_proceed, {
            __module__ : {value: "read_book.mathjax"}
        });

        function apply_mathjax(mathjax_files, link_uid, proceed) {
            var es, s;
            if (runtime.is_standalone_viewer) {
                if (!standalone_proceed_data.event_listender_added) {
                    standalone_proceed_data.event_listender_added = true;
                    document.documentElement.addEventListener("calibre-mathjax-typeset-done", standalone_proceed);
                }
                if (standalone_proceed_data.proceed) {
                    print("MathJax apply called while a previous apply is still running");
                }
                standalone_proceed_data.link_uid = link_uid;
                standalone_proceed_data.proceed = proceed;
                load_mathjax("" + ρσ_str.format("{}", runtime.FAKE_PROTOCOL) + "://" + ρσ_str.format("{}", runtime.SANDBOX_HOST) + "/mathjax/startup.js");
                return;
            }
            window.MathJax = {};
            window.MathJax.startup = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["ready"] = (function() {
                    var ρσ_anonfunc = function () {
                        window.MathJax.startup.defaultReady();
                        window.MathJax.startup.output.font.addFontURLs = (function() {
                            var ρσ_anonfunc = function (styles, fonts, url) {
                                var base, clone, font, key, font_name, full_name, src, name;
                                base = url.partition("/")[2];
                                var ρσ_Iter1 = ρσ_Iterable(fonts);
                                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                                    name = ρσ_Iter1[ρσ_Index1];
                                    clone = {};
                                    font = fonts[(typeof name === "number" && name < 0) ? fonts.length + name : name];
                                    var ρσ_Iter2 = ρσ_Iterable(Object.keys(font));
                                    for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                                        key = ρσ_Iter2[ρσ_Index2];
                                        clone[(typeof key === "number" && key < 0) ? clone.length + key : key] = font[(typeof key === "number" && key < 0) ? font.length + key : key];
                                    }
                                    font_name = clone.src.partition("/")[2].partition("\"")[0];
                                    full_name = base + "/" + font_name;
                                    src = get_url(mathjax_files, full_name);
                                    clone.src = clone.src.replace(/".+?"/, "\"" + ρσ_str.format("{}", src) + "\"");
                                    styles[(typeof name === "number" && name < 0) ? styles.length + name : name] = clone;
                                }
                            };
                            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                __argnames__ : {value: ["styles", "fonts", "url"]},
                                __module__ : {value: "read_book.mathjax"}
                            });
                            return ρσ_anonfunc;
                        })();
                        window.MathJax.startup.promise.then((function() {
                            var ρσ_anonfunc = function () {
                                postprocess(link_uid);
                                proceed();
                            };
                            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                __module__ : {value: "read_book.mathjax"}
                            });
                            return ρσ_anonfunc;
                        })());
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.mathjax"}
                    });
                    return ρσ_anonfunc;
                })();
                return ρσ_d;
            }).call(this);
            window.MathJax.loader = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["load"] = ['input/tex-full', 'input/asciimath', 'input/mml', 'output/chtml'];
                ρσ_d["require"] = (function() {
                    var ρσ_anonfunc = function (url) {
                        return new Promise((function() {
                            var ρσ_anonfunc = function (resolve, reject) {
                                var name, script;
                                name = url.partition("/")[2];
                                script = document.createElement("script");
                                script.charset = "UTF-8";
                                script.onload = (function() {
                                    var ρσ_anonfunc = function () {
                                        resolve(url);
                                    };
                                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                        __module__ : {value: "read_book.mathjax"}
                                    });
                                    return ρσ_anonfunc;
                                })();
                                script.onerror = (function() {
                                    var ρσ_anonfunc = function () {
                                        reject(url);
                                    };
                                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                        __module__ : {value: "read_book.mathjax"}
                                    });
                                    return ρσ_anonfunc;
                                })();
                                script.src = get_url(mathjax_files, name);
                                document.head.appendChild(script);
                            };
                            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                __argnames__ : {value: ["resolve", "reject"]},
                                __module__ : {value: "read_book.mathjax"}
                            });
                            return ρσ_anonfunc;
                        })());
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["url"]},
                        __module__ : {value: "read_book.mathjax"}
                    });
                    return ρσ_anonfunc;
                })();
                return ρσ_d;
            }).call(this);
            var ρσ_Iter3 = ρσ_Iterable(document.scripts);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                s = ρσ_Iter3[ρσ_Index3];
                if (s.type === "text/x-mathjax-config") {
                    es = document.createElement("script");
                    es.text = s.text;
                    document.head.appendChild(es);
                    document.head.removeChild(es);
                }
            }
            load_mathjax(get_url(mathjax_files, "startup.js"));
        };
        if (!apply_mathjax.__argnames__) Object.defineProperties(apply_mathjax, {
            __argnames__ : {value: ["mathjax_files", "link_uid", "proceed"]},
            __module__ : {value: "read_book.mathjax"}
        });

        ρσ_modules["read_book.mathjax"].standalone_proceed_data = standalone_proceed_data;
        ρσ_modules["read_book.mathjax"].get_url = get_url;
        ρσ_modules["read_book.mathjax"].postprocess = postprocess;
        ρσ_modules["read_book.mathjax"].load_mathjax = load_mathjax;
        ρσ_modules["read_book.mathjax"].standalone_proceed = standalone_proceed;
        ρσ_modules["read_book.mathjax"].apply_mathjax = apply_mathjax;
    })();

    (function(){
        var __name__ = "read_book.paged_mode";
        var _in_paged_mode, col_size, screen_inline, screen_block, cols_per_screen, gap, col_and_gap, last_scrolled_to_column, is_full_screen_layout, scroll_resize_bug_watcher, wheel_handler, onwheel, anchor_funcs, resize_manager, drag_scroller;
        var traceback = ρσ_modules.traceback;

        var E = ρσ_modules.elementmaker.E;

        var set_important_css = ρσ_modules.dom.set_important_css;

        var cfi_at_current = ρσ_modules["read_book.cfi"].at_current;
        var cfi_at_point = ρσ_modules["read_book.cfi"].at_point;
        var cfi_scroll_to = ρσ_modules["read_book.cfi"].scroll_to;

        var current_spine_item = ρσ_modules["read_book.globals"].current_spine_item;
        var get_boss = ρσ_modules["read_book.globals"].get_boss;
        var rtl_page_progression = ρσ_modules["read_book.globals"].rtl_page_progression;

        var opts = ρσ_modules["read_book.settings"].opts;

        var scroll_viewport = ρσ_modules["read_book.viewport"].scroll_viewport;
        var line_height = ρσ_modules["read_book.viewport"].line_height;
        var rem_size = ρσ_modules["read_book.viewport"].rem_size;
        var get_unit_size_in_pixels = ρσ_modules["read_book.viewport"].get_unit_size_in_pixels;

        var get_elem_data = ρσ_modules.utils.get_elem_data;
        var set_elem_data = ρσ_modules.utils.set_elem_data;

        function first_child(parent) {
            var c, count;
            c = parent.firstChild;
            count = 0;
            while ((typeof c !== "undefined" && c !== null ? c : Object.create(null)).nodeType !== Node.ELEMENT_NODE && count < 20) {
                c = (typeof c !== "undefined" && c !== null ? c : Object.create(null)).nextSibling;
                count += 1;
            }
            if ((typeof c !== "undefined" && c !== null ? c : Object.create(null)).nodeType === Node.ELEMENT_NODE) {
                return c;
            }
        };
        if (!first_child.__argnames__) Object.defineProperties(first_child, {
            __argnames__ : {value: ["parent"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function has_start_text(elem) {
            var c;
            var ρσ_Iter0 = ρσ_Iterable(elem.childNodes);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                c = ρσ_Iter0[ρσ_Index0];
                if (c.nodeType !== Node.TEXT_NODE) {
                    break;
                }
                if (c.nodeType === Node.TEXT_NODE && c.nodeValue && /\S/.test(c.nodeValue)) {
                    return true;
                }
            }
            return false;
        };
        if (!has_start_text.__argnames__) Object.defineProperties(has_start_text, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function handle_rtl_body(body_style) {
            if (body_style.direction === "rtl") {
                document.documentElement.style.overflow = "visible";
            }
        };
        if (!handle_rtl_body.__argnames__) Object.defineProperties(handle_rtl_body, {
            __argnames__ : {value: ["body_style"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function create_page_div(elem) {
            var div;
            div = E("blank-page-div", " \n    ");
            document.body.appendChild(div);
            ρσ_interpolate_kwargs.call(this, set_important_css, [div].concat([ρσ_desugar_kwargs({break_before: "column", break_inside: "avoid", display: "block", white_space: "pre", background_color: "transparent", background_image: "none", border_width: "0", float: "none", position: "static", min_height: "100vh"})]));
        };
        if (!create_page_div.__argnames__) Object.defineProperties(create_page_div, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        _in_paged_mode = false;
        function in_paged_mode() {
            return _in_paged_mode;
        };
        if (!in_paged_mode.__module__) Object.defineProperties(in_paged_mode, {
            __module__ : {value: "read_book.paged_mode"}
        });

        col_size = screen_inline = screen_block = cols_per_screen = gap = col_and_gap = last_scrolled_to_column = 0;
        is_full_screen_layout = false;
        function get_number_of_cols(dont_return_integer) {
            var ans;
            if (is_full_screen_layout) {
                return 1;
            }
            ans = (scroll_viewport.paged_content_inline_size() + gap) / col_and_gap;
            if (!dont_return_integer) {
                ans = Math.floor(ans);
            }
            return ans;
        };
        if (!get_number_of_cols.__argnames__) Object.defineProperties(get_number_of_cols, {
            __argnames__ : {value: ["dont_return_integer"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function reset_paged_mode_globals() {
            scroll_viewport.reset_globals();
            col_size = screen_inline = screen_block = cols_per_screen = gap = col_and_gap = last_scrolled_to_column = 0;
            is_full_screen_layout = _in_paged_mode = false;
            resize_manager.reset();
        };
        if (!reset_paged_mode_globals.__module__) Object.defineProperties(reset_paged_mode_globals, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function column_at(pos) {
            var si;
            si = scroll_viewport.paged_content_inline_size();
            if (pos >= si - col_and_gap) {
                pos = si - col_size + 10;
            }
            return Math.floor(max(0, pos + gap - 1) / col_and_gap);
        };
        if (!column_at.__argnames__) Object.defineProperties(column_at, {
            __argnames__ : {value: ["pos"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function fit_images() {
            var inline_limited_images, block_limited_images, img_tags, bounding_rects, img_tag, maxb, img, br, previously_limited, data, image_start, col_start, column_start_to_image_start, image_block_size, image_inline_size, image_inline_end, i, ρσ_unpack, max_inline_size;
            inline_limited_images = [];
            block_limited_images = [];
            img_tags = document.getElementsByTagName("img");
            bounding_rects = [];
            var ρσ_Iter1 = ρσ_Iterable(img_tags);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                img_tag = ρσ_Iter1[ρσ_Index1];
                bounding_rects.push(get_bounding_client_rect(img_tag));
            }
            maxb = screen_block;
            for (var ρσ_Index2 = 0; ρσ_Index2 < img_tags.length; ρσ_Index2++) {
                i = ρσ_Index2;
                img = img_tags[(typeof i === "number" && i < 0) ? img_tags.length + i : i];
                br = bounding_rects[(typeof i === "number" && i < 0) ? bounding_rects.length + i : i];
                previously_limited = get_elem_data(img, "inline-limited", false);
                data = get_elem_data(img, "img-data", null);
                if (data === null) {
                    data = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["left"] = br.left;
                        ρσ_d["right"] = br.right;
                        ρσ_d["height"] = br.height;
                        ρσ_d["display"] = img.style.display;
                        return ρσ_d;
                    }).call(this);
                    set_elem_data(img, "img-data", data);
                }
                image_start = scroll_viewport.viewport_to_document_inline(scroll_viewport.rect_inline_start(br), img.ownerDocument);
                col_start = column_at(image_start) * col_and_gap;
                column_start_to_image_start = image_start - col_start;
                image_block_size = scroll_viewport.rect_block_size(br);
                image_inline_size = scroll_viewport.rect_inline_size(br);
                image_inline_end = column_start_to_image_start + image_inline_size;
                if (previously_limited || image_inline_end > col_size) {
                    inline_limited_images.push([img, col_size - column_start_to_image_start]);
                }
                previously_limited = get_elem_data(img, "block-limited", false);
                if (previously_limited || image_block_size > maxb || image_block_size === maxb && image_inline_size > col_size) {
                    block_limited_images.push(img);
                }
                if (previously_limited) {
                    ρσ_interpolate_kwargs.call(this, set_important_css, [img].concat([ρσ_desugar_kwargs({break_before: "auto", display: data.display})]));
                }
                ρσ_interpolate_kwargs.call(this, set_important_css, [img].concat([ρσ_desugar_kwargs({break_inside: "avoid"})]));
            }
            var ρσ_Iter3 = ρσ_Iterable(inline_limited_images);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                ρσ_unpack = ρσ_Iter3[ρσ_Index3];
                img_tag = ρσ_unpack[0];
                max_inline_size = ρσ_unpack[1];
                if (scroll_viewport.vertical_writing_mode) {
                    img_tag.style.setProperty("max-height", max_inline_size + "px");
                } else {
                    img_tag.style.setProperty("max-width", max_inline_size + "px");
                }
                set_elem_data(img_tag, "inline-limited", true);
            }
            var ρσ_Iter4 = ρσ_Iterable(block_limited_images);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                img_tag = ρσ_Iter4[ρσ_Index4];
                if (scroll_viewport.vertical_writing_mode) {
                    ρσ_interpolate_kwargs.call(this, set_important_css, [img_tag].concat([ρσ_desugar_kwargs({break_before: "always", max_width: "100vw"})]));
                } else {
                    ρσ_interpolate_kwargs.call(this, set_important_css, [img_tag].concat([ρσ_desugar_kwargs({break_before: "always", max_height: "100vh"})]));
                }
                set_elem_data(img_tag, "block-limited", true);
            }
        };
        if (!fit_images.__module__) Object.defineProperties(fit_images, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function cps_by_em_size() {
            var ans, fs;
            ans = cps_by_em_size.ans;
            fs = window.getComputedStyle(document.body).fontSize;
            if (!ans || cps_by_em_size.at_font_size !== fs) {
                if (fs === 0) {
                    ans = cps_by_em_size.ans = 16;
                } else {
                    ans = cps_by_em_size.ans = max(2, get_unit_size_in_pixels("rem"));
                }
                cps_by_em_size.at_font_size = fs;
            }
            return ans;
        };
        if (!cps_by_em_size.__module__) Object.defineProperties(cps_by_em_size, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function calc_columns_per_screen() {
            var cps;
            cps = opts.columns_per_screen || Object.create(null);
            cps = (scroll_viewport.width() > scroll_viewport.height()) ? cps.landscape : cps.portrait;
            try {
                cps = int(cps);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    cps = 0;
                } 
            }
            if (!cps) {
                cps = int(Math.floor(scroll_viewport.inline_size() / (35 * cps_by_em_size())));
            }
            cps = max(1, min(cps || 1, 20));
            return cps;
        };
        if (!calc_columns_per_screen.__module__) Object.defineProperties(calc_columns_per_screen, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function get_columns_per_screen_data() {
            var which;
            which = (scroll_viewport.width() > scroll_viewport.height()) ? "landscape" : "portrait";
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["which"] = which;
                ρσ_d["cps"] = calc_columns_per_screen();
                return ρσ_d;
            }).call(this);
        };
        if (!get_columns_per_screen_data.__module__) Object.defineProperties(get_columns_per_screen_data, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function will_columns_per_screen_change() {
            return ρσ_not_equals(calc_columns_per_screen(), cols_per_screen);
        };
        if (!will_columns_per_screen_change.__module__) Object.defineProperties(will_columns_per_screen_change, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function ScrollResizeBugWatcher() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ScrollResizeBugWatcher.prototype.__bind_methods__.call(this);
            ScrollResizeBugWatcher.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ScrollResizeBugWatcher.prototype, "__bind_methods__", {value: function () {
            this.layout_done = ScrollResizeBugWatcher.prototype.layout_done.bind(this);
            this.scrolled = ScrollResizeBugWatcher.prototype.scrolled.bind(this);
            this.cancel_timer = ScrollResizeBugWatcher.prototype.cancel_timer.bind(this);
            this.check_for_resize_bug = ScrollResizeBugWatcher.prototype.check_for_resize_bug.bind(this);
            this.redo_scroll = ScrollResizeBugWatcher.prototype.redo_scroll.bind(this);
        }});
        ScrollResizeBugWatcher.prototype.__init__ = function __init__() {
            var self = this;
            self.max_time = 750;
            self.last_layout_at = 0;
            self.last_command = null;
            self.doc_size = 0;
            self.timer = null;
        };
        if (!ScrollResizeBugWatcher.prototype.__init__.__module__) Object.defineProperties(ScrollResizeBugWatcher.prototype.__init__, {
            __module__ : {value: "read_book.paged_mode"}
        });
        ScrollResizeBugWatcher.__argnames__ = ScrollResizeBugWatcher.prototype.__init__.__argnames__;
        ScrollResizeBugWatcher.__handles_kwarg_interpolation__ = ScrollResizeBugWatcher.prototype.__init__.__handles_kwarg_interpolation__;
        ScrollResizeBugWatcher.prototype.layout_done = function layout_done() {
            var self = this;
            self.last_layout_at = window.performance.now();
            self.last_command = null;
            self.cancel_timer();
        };
        if (!ScrollResizeBugWatcher.prototype.layout_done.__module__) Object.defineProperties(ScrollResizeBugWatcher.prototype.layout_done, {
            __module__ : {value: "read_book.paged_mode"}
        });
        ScrollResizeBugWatcher.prototype.scrolled = function scrolled(pos, limit) {
            var self = this;
            var now;
            self.cancel_timer();
            now = window.performance.now();
            if (now - self.last_layout_at < self.max_time && self.last_command !== null) {
                self.doc_size = scroll_viewport.paged_content_inline_size();
                self.check_for_resize_bug();
            }
        };
        if (!ScrollResizeBugWatcher.prototype.scrolled.__argnames__) Object.defineProperties(ScrollResizeBugWatcher.prototype.scrolled, {
            __argnames__ : {value: ["pos", "limit"]},
            __module__ : {value: "read_book.paged_mode"}
        });
        ScrollResizeBugWatcher.prototype.cancel_timer = function cancel_timer() {
            var self = this;
            if (self.timer !== null) {
                window.clearTimeout(self.timer);
                self.timer = null;
            }
        };
        if (!ScrollResizeBugWatcher.prototype.cancel_timer.__module__) Object.defineProperties(ScrollResizeBugWatcher.prototype.cancel_timer, {
            __module__ : {value: "read_book.paged_mode"}
        });
        ScrollResizeBugWatcher.prototype.check_for_resize_bug = function check_for_resize_bug() {
            var self = this;
            var sz, now;
            sz = scroll_viewport.paged_content_inline_size();
            if ((sz !== self.doc_size && (typeof sz !== "object" || ρσ_not_equals(sz, self.doc_size)))) {
                return self.redo_scroll();
            }
            now = window.performance.now();
            if (now - self.last_layout_at < self.max_time) {
                window.setTimeout(self.check_for_resize_bug, 10);
            } else {
                self.timer = null;
            }
        };
        if (!ScrollResizeBugWatcher.prototype.check_for_resize_bug.__module__) Object.defineProperties(ScrollResizeBugWatcher.prototype.check_for_resize_bug, {
            __module__ : {value: "read_book.paged_mode"}
        });
        ScrollResizeBugWatcher.prototype.redo_scroll = function redo_scroll() {
            var self = this;
            if (self.last_command) {
                self.last_command();
                self.last_command = null;
            }
            self.timer = null;
            self.doc_size = 0;
        };
        if (!ScrollResizeBugWatcher.prototype.redo_scroll.__module__) Object.defineProperties(ScrollResizeBugWatcher.prototype.redo_scroll, {
            __module__ : {value: "read_book.paged_mode"}
        });
        ScrollResizeBugWatcher.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ScrollResizeBugWatcher.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ScrollResizeBugWatcher.prototype, "__bases__", {value: []});

        scroll_resize_bug_watcher = new ScrollResizeBugWatcher;
        function layout(is_single_page, on_resize) {
            var body_style, first_layout, cps, single_screen, svgs, has_svg, imgs, only_img, num, elems, n, margin_size, overhang, c, c2, has_no_more_than_two_columns;
            line_height(true);
            rem_size(true);
            body_style = window.getComputedStyle(document.body);
            scroll_viewport.initialize_on_layout(body_style);
            first_layout = !_in_paged_mode;
            cps = calc_columns_per_screen();
            if (first_layout) {
                handle_rtl_body(body_style);
                single_screen = scroll_viewport.document_block_size() < scroll_viewport.block_size() + 75;
                first_layout = true;
                svgs = document.getElementsByTagName("svg");
                has_svg = svgs.length > 0;
                imgs = document.getElementsByTagName("img");
                only_img = imgs.length === 1 && document.getElementsByTagName("div").length < 3 && document.getElementsByTagName("p").length < 2;
                if (only_img && window.getComputedStyle(imgs[0]).zIndex < 0) {
                    imgs[0].style.zIndex = "0";
                }
                if (!single_screen && cps > 1) {
                    num = cps - 1;
                    elems = document.querySelectorAll("body > *");
                    if (elems.length === 1) {
                        elems[0].style.height = "auto";
                    }
                    while (num > 0) {
                        num -= 1;
                        create_page_div();
                    }
                }
            }
            n = cols_per_screen = cps;
            col_size = screen_inline = scroll_viewport.inline_size();
            margin_size = (scroll_viewport.horizontal_writing_mode) ? opts.margin_left + opts.margin_right : opts.margin_top + opts.margin_bottom;
            margin_size = max(1, margin_size);
            gap = margin_size;
            if (n > 1) {
                overhang = (screen_inline + gap) % n;
                if (overhang !== 0) {
                    gap += n - overhang;
                }
                col_size = Math.floor((screen_inline + gap) / n) - gap;
            }
            screen_block = scroll_viewport.block_size();
            col_and_gap = col_size + gap;
            ρσ_interpolate_kwargs.call(this, set_important_css, [document.body].concat([ρσ_desugar_kwargs({column_gap: gap + "px", column_width: col_size + "px", column_rule: "0px inset blue", min_width: "0", max_width: "none", min_height: "0", max_height: "100vh", column_fill: "auto", margin: "0", border_width: "0", padding: "0", box_sizing: "content-box", width: scroll_viewport.width() + "px", height: scroll_viewport.height() + "px", overflow_wrap: "break-word"})]));
            document.body.style.setProperty("-webkit-margin-collapse", "separate");
            c = first_child(document.body);
            if (c) {
                ρσ_interpolate_kwargs.call(this, set_important_css, [c].concat([ρσ_desugar_kwargs({break_before: "avoid"})]));
                if (c.tagName.toLowerCase() === "div") {
                    c2 = first_child(c);
                    if (c2 && !has_start_text(c)) {
                        ρσ_interpolate_kwargs.call(this, set_important_css, [c2].concat([ρσ_desugar_kwargs({break_before: "avoid"})]));
                    }
                }
            }
            if (first_layout) {
                is_full_screen_layout = is_single_page;
                if (!is_full_screen_layout) {
                    has_no_more_than_two_columns = scroll_viewport.paged_content_inline_size() < 2 * screen_inline + 10;
                    if (has_no_more_than_two_columns && single_screen) {
                        if (only_img && imgs.length && get_bounding_client_rect(imgs[0]).left < screen_inline) {
                            is_full_screen_layout = true;
                        }
                        if (has_svg && (svgs.length === 1 || typeof svgs.length === "object" && ρσ_equals(svgs.length, 1)) && get_bounding_client_rect(svgs[0]).left < screen_inline) {
                            is_full_screen_layout = true;
                        }
                    }
                }
                if (is_full_screen_layout && only_img && cols_per_screen > 1) {
                    cols_per_screen = 1;
                    col_size = screen_inline;
                    col_and_gap = col_size + gap;
                    document.body.style.columnWidth = "100vw";
                }
            }
            function check_column_sizes() {
                var nc, data;
                nc = get_number_of_cols(true);
                if (Math.floor(nc) !== nc) {
                    data = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["col_size"] = col_size;
                        ρσ_d["gap"] = gap;
                        ρσ_d["scrollWidth"] = scroll_viewport.paged_content_inline_size();
                        ρσ_d["ncols"] = nc;
                        ρσ_d["screen_inline"] = screen_inline;
                        return ρσ_d;
                    }).call(this);
                    print("WARNING: column layout broken, probably because there is some non-reflowable content in the book whose inline size is greater than the column size", data);
                }
            };
            if (!check_column_sizes.__module__) Object.defineProperties(check_column_sizes, {
                __module__ : {value: "read_book.paged_mode"}
            });

            check_column_sizes();
            _in_paged_mode = true;
            fit_images();
            scroll_resize_bug_watcher.layout_done();
            return gap;
        };
        if (!layout.__argnames__) Object.defineProperties(layout, {
            __argnames__ : {value: ["is_single_page", "on_resize"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function current_scroll_offset() {
            return scroll_viewport.inline_pos();
        };
        if (!current_scroll_offset.__module__) Object.defineProperties(current_scroll_offset, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function scroll_to_offset(offset) {
            scroll_viewport.scroll_to_in_inline_direction(offset);
        };
        if (!scroll_to_offset.__argnames__) Object.defineProperties(scroll_to_offset, {
            __argnames__ : {value: ["offset"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function scroll_to_column() {
            var number = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var notify = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? scroll_to_column.__defaults__.notify : arguments[1];
            var duration = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? scroll_to_column.__defaults__.duration : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "notify")){
                notify = ρσ_kwargs_obj.notify;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "duration")){
                duration = ρσ_kwargs_obj.duration;
            }
            var pos, limit;
            last_scrolled_to_column = number;
            pos = number * col_and_gap;
            limit = scroll_viewport.paged_content_inline_size() - scroll_viewport.inline_size();
            pos = min(pos, limit);
            scroll_to_offset(pos);
            scroll_resize_bug_watcher.scrolled(pos, limit);
        };
        if (!scroll_to_column.__defaults__) Object.defineProperties(scroll_to_column, {
            __defaults__ : {value: {notify:false, duration:1e3}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["number", "notify", "duration"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function scroll_to_pos() {
            var pos = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var notify = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? scroll_to_pos.__defaults__.notify : arguments[1];
            var duration = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? scroll_to_pos.__defaults__.duration : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "notify")){
                notify = ρσ_kwargs_obj.notify;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "duration")){
                duration = ρσ_kwargs_obj.duration;
            }
            if (typeof pos !== "number") {
                print(pos, "is not a number, cannot scroll to it!");
                return;
            }
            if (is_full_screen_layout) {
                scroll_to_offset(0);
                last_scrolled_to_column = 0;
                return;
            }
            ρσ_interpolate_kwargs.call(this, scroll_to_column, [column_at(pos)].concat([ρσ_desugar_kwargs({notify: notify, duration: duration})]));
        };
        if (!scroll_to_pos.__defaults__) Object.defineProperties(scroll_to_pos, {
            __defaults__ : {value: {notify:false, duration:1e3}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["pos", "notify", "duration"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function scroll_to_previous_position(fsd) {
            fsd = fsd || next_spine_item.forward_scroll_data;
            next_spine_item.forward_scroll_data = null;
            if (0 < (ρσ_cond_temp = fsd.cols_left) && ρσ_cond_temp < cols_per_screen && cols_per_screen < get_number_of_cols()) {
                scroll_resize_bug_watcher.last_command = scroll_to_previous_position.bind(null, fsd);
                scroll_to_column(fsd.current_col);
                return true;
            }
        };
        if (!scroll_to_previous_position.__argnames__) Object.defineProperties(scroll_to_previous_position, {
            __argnames__ : {value: ["fsd"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function scroll_to_fraction(frac, on_initial_load) {
            var pos;
            if (on_initial_load && frac === 1 && is_return() && scroll_to_previous_position()) {
                return;
            }
            scroll_resize_bug_watcher.last_command = scroll_to_fraction.bind(null, frac, false);
            pos = Math.floor(scroll_viewport.paged_content_inline_size() * frac);
            scroll_to_pos(pos);
        };
        if (!scroll_to_fraction.__argnames__) Object.defineProperties(scroll_to_fraction, {
            __argnames__ : {value: ["frac", "on_initial_load"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function column_boundaries() {
            var l;
            l = column_at(current_scroll_offset() + 10);
            return [l, l + cols_per_screen];
        };
        if (!column_boundaries.__module__) Object.defineProperties(column_boundaries, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function column_at_current_scroll_offset() {
            return column_at(current_scroll_offset() + 10);
        };
        if (!column_at_current_scroll_offset.__module__) Object.defineProperties(column_at_current_scroll_offset, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function current_column_location() {
            if (is_full_screen_layout) {
                return 0;
            }
            return column_at_current_scroll_offset() * col_and_gap;
        };
        if (!current_column_location.__module__) Object.defineProperties(current_column_location, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function number_of_cols_left() {
            var current_col, cols_left;
            current_col = column_at(current_scroll_offset() + 10);
            cols_left = get_number_of_cols() - (current_col + cols_per_screen);
            return Math.max(0, cols_left);
        };
        if (!number_of_cols_left.__module__) Object.defineProperties(number_of_cols_left, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function next_screen_location() {
            var cc, ans, limit, current_pos;
            if (is_full_screen_layout) {
                return -1;
            }
            cc = current_column_location();
            ans = cc + screen_inline + 1;
            if (cols_per_screen > 1 && 0 < (ρσ_cond_temp = number_of_cols_left()) && ρσ_cond_temp < cols_per_screen) {
                return -1;
            }
            limit = scroll_viewport.paged_content_inline_size() - scroll_viewport.inline_size();
            if (limit < col_and_gap) {
                return -1;
            }
            if (ans > limit) {
                current_pos = Math.ceil(current_scroll_offset());
                ans = (current_pos < limit) ? limit : -1;
                if (cols_per_screen === 1 && ans !== -1 && ans - current_pos < col_size) {
                    ans = -1;
                }
            }
            return ans;
        };
        if (!next_screen_location.__module__) Object.defineProperties(next_screen_location, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function previous_screen_location() {
            var cc, ans;
            if (is_full_screen_layout) {
                return -1;
            }
            cc = current_column_location();
            ans = cc - cols_per_screen * col_and_gap;
            if (ans < 0) {
                ans = (current_scroll_offset() > 15) ? 0 : -1;
            }
            return ans;
        };
        if (!previous_screen_location.__module__) Object.defineProperties(previous_screen_location, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function next_col_location() {
            var cc, ans, limit;
            if (is_full_screen_layout) {
                return -1;
            }
            cc = current_column_location();
            ans = cc + col_and_gap;
            limit = scroll_viewport.paged_content_inline_size() - scroll_viewport.inline_size();
            if (ans > limit) {
                if (Math.ceil(current_scroll_offset()) < limit && column_at(limit) > column_at_current_scroll_offset()) {
                    ans = limit;
                } else {
                    ans = -1;
                }
            }
            return ans;
        };
        if (!next_col_location.__module__) Object.defineProperties(next_col_location, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function previous_col_location() {
            var cc, ans;
            if (is_full_screen_layout) {
                return -1;
            }
            cc = current_column_location();
            ans = cc - col_and_gap;
            if (ans < 0) {
                if (Math.floor(current_scroll_offset()) > 0 && column_at(0) < column_at_current_scroll_offset()) {
                    ans = 0;
                } else {
                    ans = -1;
                }
            }
            return ans;
        };
        if (!previous_col_location.__module__) Object.defineProperties(previous_col_location, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function jump_to_anchor(name) {
            var elem, elems;
            elem = document.getElementById(name);
            if (!elem) {
                elems = document.getElementsByName(name);
                if (elems) {
                    elem = elems[0];
                }
            }
            if (!elem) {
                return;
            }
            scroll_to_elem(elem);
        };
        if (!jump_to_anchor.__argnames__) Object.defineProperties(jump_to_anchor, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function scrollable_element(elem) {
            if (!in_paged_mode() || window.getComputedStyle(elem).display.indexOf("inline") < 0 || !elem.firstElementChild) {
                return elem;
            }
            if (window.getComputedStyle(elem.firstElementChild).display.indexOf("block") > -1 && elem.getBoundingClientRect().top < -100) {
                return elem.firstElementChild;
            }
            return elem;
        };
        if (!scrollable_element.__argnames__) Object.defineProperties(scrollable_element, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function scroll_to_elem(elem) {
            var br, inline_start;
            elem = scrollable_element(elem);
            scroll_viewport.scroll_into_view(elem);
            if (in_paged_mode()) {
                br = get_bounding_client_rect(elem);
                if (br.top < -100) {
                    if (scroll_viewport.horizontal_writing_mode) {
                        inline_start = (scroll_viewport.ltr) ? elem.scrollLeft : elem.scrollRight;
                    } else {
                        inline_start = elem.scrollTop;
                    }
                } else {
                    inline_start = scroll_viewport.rect_inline_start(br);
                }
                scroll_to_pos(scroll_viewport.viewport_to_document_inline(inline_start + 2, elem.ownerDocument));
            }
        };
        if (!scroll_to_elem.__argnames__) Object.defineProperties(scroll_to_elem, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function snap_to_selection() {
            var sel, r, node, pos;
            if (in_paged_mode()) {
                sel = window.getSelection();
                r = sel.getRangeAt(0).getBoundingClientRect();
                node = sel.anchorNode;
                pos = ρσ_interpolate_kwargs.call(scroll_viewport, scroll_viewport.viewport_to_document_inline, [scroll_viewport.rect_inline_start(r)].concat([ρσ_desugar_kwargs({doc: node.ownerDocument})]));
                scroll_to_pos(pos + 5);
            }
        };
        if (!snap_to_selection.__module__) Object.defineProperties(snap_to_selection, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function ensure_selection_boundary_visible(use_end) {
            var sel, rr, r, cnum, node, x, pos;
            sel = window.getSelection();
            try {
                rr = sel.getRangeAt(0);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    rr = null;
                } 
            }
            if (rr) {
                r = rr.getBoundingClientRect();
                if (r) {
                    cnum = column_at_current_scroll_offset();
                    scroll_to_column(cnum);
                    node = (use_end) ? sel.focusNode : sel.anchorNode;
                    x = (use_end) ? scroll_viewport.rect_inline_end(r) : scroll_viewport.rect_inline_start(r);
                    if (x < 0 || x >= scroll_viewport.inline_size()) {
                        pos = ρσ_interpolate_kwargs.call(scroll_viewport, scroll_viewport.viewport_to_document_inline, [x].concat([ρσ_desugar_kwargs({doc: node.ownerDocument})]));
                        scroll_to_pos(pos + 5);
                    }
                }
            }
        };
        if (!ensure_selection_boundary_visible.__argnames__) Object.defineProperties(ensure_selection_boundary_visible, {
            __argnames__ : {value: ["use_end"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function jump_to_cfi(cfi) {
            scroll_resize_bug_watcher.last_command = jump_to_cfi.bind(null, cfi);
            cfi_scroll_to(cfi, (function() {
                var ρσ_anonfunc = function (x, y) {
                    if (scroll_viewport.horizontal_writing_mode) {
                        scroll_to_pos(x);
                    } else {
                        scroll_to_pos(y);
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["x", "y"]},
                    __module__ : {value: "read_book.paged_mode"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!jump_to_cfi.__argnames__) Object.defineProperties(jump_to_cfi, {
            __argnames__ : {value: ["cfi"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function current_cfi() {
            var ans, left, right, ρσ_unpack, top, bottom, midx, deltax, deltay, midy, yidx, yb, ya, ys, xidx, xb, xa, xs, cfi, curx, cury, cnum;
            ans = null;
            if (in_paged_mode()) {
                for (var ρσ_Index5 = 0; ρσ_Index5 < cols_per_screen; ρσ_Index5++) {
                    cnum = ρσ_Index5;
                    left = cnum * (col_and_gap + gap);
                    right = left + col_size;
                    ρσ_unpack = [0, scroll_viewport.height()];
                    top = ρσ_unpack[0];
                    bottom = ρσ_unpack[1];
                    midx = Math.floor((right - left) / 2);
                    deltax = Math.floor((right - left) / 24);
                    deltay = Math.floor((bottom - top) / 24);
                    midy = Math.floor((bottom - top) / 2);
                    yidx = 0;
                    while (true) {
                        ρσ_unpack = [midy - yidx * deltay, midy + yidx * deltay];
                        yb = ρσ_unpack[0];
                        ya = ρσ_unpack[1];
                        if (yb <= top || ya >= bottom) {
                            break;
                        }
                        yidx += 1;
                        ys = (ya === yb) ? [ya] : [yb, ya];
                        var ρσ_Iter6 = ρσ_Iterable(ys);
                        for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                            cury = ρσ_Iter6[ρσ_Index6];
                            xidx = 0;
                            while (true) {
                                ρσ_unpack = [midx - xidx * deltax, midx + xidx * deltax];
                                xb = ρσ_unpack[0];
                                xa = ρσ_unpack[1];
                                if (xb <= left || xa >= right) {
                                    break;
                                }
                                xidx += 1;
                                xs = (xa === xb) ? [xa] : [xb, xa];
                                var ρσ_Iter7 = ρσ_Iterable(xs);
                                for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                                    curx = ρσ_Iter7[ρσ_Index7];
                                    cfi = cfi_at_point(curx, cury);
                                    if (cfi) {
                                        return cfi;
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                try {
                    ans = cfi_at_current() || null;
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        traceback.print_exc();
                    } 
                }
            }
            return ans;
        };
        if (!current_cfi.__module__) Object.defineProperties(current_cfi, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function progress_frac(frac) {
            var limit;
            if (in_paged_mode()) {
                limit = scroll_viewport.paged_content_inline_size() - scroll_viewport.inline_size();
                if (limit <= 0) {
                    return 1;
                }
                return current_scroll_offset() / limit;
            }
            limit = scroll_viewport.document_block_size() - scroll_viewport.block_size();
            if (limit <= 0) {
                return 1;
            }
            return Math.max(0, Math.min(scroll_viewport.block_pos() / limit, 1));
        };
        if (!progress_frac.__argnames__) Object.defineProperties(progress_frac, {
            __argnames__ : {value: ["frac"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function page_counts() {
            var doc_size, screen_size, pos;
            if (in_paged_mode()) {
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["current"] = column_at_current_scroll_offset();
                    ρσ_d["total"] = get_number_of_cols();
                    ρσ_d["pages_per_screen"] = cols_per_screen;
                    return ρσ_d;
                }).call(this);
            }
            doc_size = scroll_viewport.document_block_size();
            screen_size = scroll_viewport.block_size();
            pos = scroll_viewport.block_pos();
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["current"] = Math.floor((pos + 10) / screen_size);
                ρσ_d["total"] = Math.floor(doc_size / screen_size);
                ρσ_d["pages_per_screen"] = 1;
                return ρσ_d;
            }).call(this);
        };
        if (!page_counts.__module__) Object.defineProperties(page_counts, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function next_spine_item(backward) {
            var csi;
            if (!backward) {
                csi = current_spine_item();
                next_spine_item.forward_scroll_data = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["cols_per_screen"] = cols_per_screen;
                    ρσ_d["cols_left"] = number_of_cols_left();
                    ρσ_d["spine_index"] = csi.index;
                    ρσ_d["spine_name"] = csi.name;
                    ρσ_d["current_col"] = column_at(current_scroll_offset() + 10);
                    return ρσ_d;
                }).call(this);
            }
            (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["next_spine_item"].concat([ρσ_desugar_kwargs({previous: backward})])));
        };
        if (!next_spine_item.__argnames__) Object.defineProperties(next_spine_item, {
            __argnames__ : {value: ["backward"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function is_return() {
            var fsd, csi;
            fsd = next_spine_item.forward_scroll_data;
            csi = current_spine_item();
            return fsd && fsd.cols_per_screen === cols_per_screen && fsd.spine_index === csi.index && fsd.spine_name === csi.name;
        };
        if (!is_return.__module__) Object.defineProperties(is_return, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function WheelState() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            WheelState.prototype.__bind_methods__.call(this);
            WheelState.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(WheelState.prototype, "__bind_methods__", {value: function () {
            this.reset = WheelState.prototype.reset.bind(this);
            this.add_pixel_scroll = WheelState.prototype.add_pixel_scroll.bind(this);
        }});
        WheelState.prototype.__init__ = function __init__ () {
                    };
        WheelState.prototype.reset = function reset() {
            var self = this;
            self.last_event_mode = WheelState.prototype.last_event_mode;
            self.last_event_at = WheelState.prototype.last_event_at;
            self.last_event_backwards = WheelState.prototype.last_event_backwards;
            self.accumulated_scroll = WheelState.prototype.accumulated_scroll;
        };
        if (!WheelState.prototype.reset.__module__) Object.defineProperties(WheelState.prototype.reset, {
            __module__ : {value: "read_book.paged_mode"}
        });
        WheelState.prototype.add_pixel_scroll = function add_pixel_scroll(backward, delta, scroll_func) {
            var self = this;
            var now;
            now = window.performance.now();
            if (now - self.last_event_at > 1e3 || self.last_event_backwards !== backward || self.last_event_mode !== "pixel") {
                self.accumulated_scroll = 0;
            }
            self.last_event_mode = "pixel";
            self.last_event_at = now;
            self.last_event_backwards = backward;
            self.accumulated_scroll += delta;
            if (self.accumulated_scroll > opts.paged_pixel_scroll_threshold) {
                self.reset();
                scroll_func(backward);
            }
        };
        if (!WheelState.prototype.add_pixel_scroll.__argnames__) Object.defineProperties(WheelState.prototype.add_pixel_scroll, {
            __argnames__ : {value: ["backward", "delta", "scroll_func"]},
            __module__ : {value: "read_book.paged_mode"}
        });
        WheelState.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        WheelState.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(WheelState.prototype, "__bases__", {value: []});
        WheelState.prototype.last_event_mode = "page";
        WheelState.prototype.last_event_at = -1e4;
        WheelState.prototype.last_event_backwards = false;
        WheelState.prototype.accumulated_scroll = 0;

        function HandleWheel() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            HandleWheel.prototype.__bind_methods__.call(this);
            HandleWheel.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(HandleWheel.prototype, "__bind_methods__", {value: function () {
            this.onwheel = HandleWheel.prototype.onwheel.bind(this);
            this.do_scroll = HandleWheel.prototype.do_scroll.bind(this);
            this.do_section_jump = HandleWheel.prototype.do_section_jump.bind(this);
        }});
        HandleWheel.prototype.__init__ = function __init__() {
            var self = this;
            self.vertical_state = new WheelState;
            self.horizontal_state = new WheelState;
        };
        if (!HandleWheel.prototype.__init__.__module__) Object.defineProperties(HandleWheel.prototype.__init__, {
            __module__ : {value: "read_book.paged_mode"}
        });
        HandleWheel.__argnames__ = HandleWheel.prototype.__init__.__argnames__;
        HandleWheel.__handles_kwarg_interpolation__ = HandleWheel.prototype.__init__.__handles_kwarg_interpolation__;
        HandleWheel.prototype.onwheel = function onwheel(evt) {
            var self = this;
            var major_axis_vertical, backward;
            if (!((evt.deltaY || evt.deltaX))) {
                return;
            }
            major_axis_vertical = true;
            if (evt.deltaY) {
                if (evt.deltaX) {
                    major_axis_vertical = Math.abs(evt.deltaY) >= Math.abs(evt.deltaX);
                }
            } else {
                major_axis_vertical = false;
            }
            if (major_axis_vertical) {
                backward = evt.deltaY < 0;
                if (evt.deltaMode === window.WheelEvent.DOM_DELTA_PIXEL) {
                    self.vertical_state.add_pixel_scroll(backward, Math.abs(evt.deltaY), self.do_scroll);
                } else {
                    self.vertical_state.reset();
                    self.do_scroll(backward);
                }
            } else {
                if (opts.paged_wheel_section_jumps) {
                    backward = evt.deltaX < 0;
                    if (evt.deltaMode === window.WheelEvent.DOM_DELTA_PIXEL) {
                        self.horizontal_state.add_pixel_scroll(backward, Math.abs(evt.deltaX), self.do_section_jump);
                    } else {
                        self.horizontal_state.reset();
                        self.do_section_jump(backward);
                    }
                }
            }
        };
        if (!HandleWheel.prototype.onwheel.__argnames__) Object.defineProperties(HandleWheel.prototype.onwheel, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.paged_mode"}
        });
        HandleWheel.prototype.do_scroll = function do_scroll(backward) {
            var self = this;
            var pos;
            if (opts.paged_wheel_scrolls_by_screen) {
                pos = (backward) ? previous_screen_location() : next_screen_location();
            } else {
                pos = (backward) ? previous_col_location() : next_col_location();
            }
            if (pos === -1) {
                next_spine_item(backward);
            } else {
                scroll_to_pos(pos);
            }
        };
        if (!HandleWheel.prototype.do_scroll.__argnames__) Object.defineProperties(HandleWheel.prototype.do_scroll, {
            __argnames__ : {value: ["backward"]},
            __module__ : {value: "read_book.paged_mode"}
        });
        HandleWheel.prototype.do_section_jump = function do_section_jump(backward) {
            var self = this;
            (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["next_section"].concat([ρσ_desugar_kwargs({forward: !backward})])));
        };
        if (!HandleWheel.prototype.do_section_jump.__argnames__) Object.defineProperties(HandleWheel.prototype.do_section_jump, {
            __argnames__ : {value: ["backward"]},
            __module__ : {value: "read_book.paged_mode"}
        });
        HandleWheel.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        HandleWheel.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(HandleWheel.prototype, "__bases__", {value: []});

        wheel_handler = new HandleWheel;
        onwheel = wheel_handler.onwheel;
        function scroll_by_page(backward, by_screen, flip_if_rtl_page_progression) {
            var pos, pages, nc, scrolled_frac;
            if (flip_if_rtl_page_progression && rtl_page_progression()) {
                backward = !backward;
            }
            if (by_screen) {
                pos = (backward) ? previous_screen_location() : next_screen_location();
                pages = cols_per_screen;
            } else {
                pos = (backward) ? previous_col_location() : next_col_location();
                pages = 1;
            }
            if (pos === -1) {
                next_spine_item(backward);
            } else {
                if (!backward) {
                    nc = get_number_of_cols();
                    scrolled_frac = (nc > 0) ? pages / nc : 0;
                    get_boss().report_human_scroll(scrolled_frac);
                } else {
                    get_boss().report_human_scroll();
                }
                scroll_to_pos(pos);
            }
        };
        if (!scroll_by_page.__argnames__) Object.defineProperties(scroll_by_page, {
            __argnames__ : {value: ["backward", "by_screen", "flip_if_rtl_page_progression"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function scroll_to_extend_annotation(backward) {
            var pos;
            pos = (backward) ? previous_col_location() : next_col_location();
            if (pos === -1) {
                return false;
            }
            scroll_to_pos(pos);
            return true;
        };
        if (!scroll_to_extend_annotation.__argnames__) Object.defineProperties(scroll_to_extend_annotation, {
            __argnames__ : {value: ["backward"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function handle_shortcut(sc_name, evt) {
            if (sc_name === "up") {
                ρσ_interpolate_kwargs.call(this, scroll_by_page, [ρσ_desugar_kwargs({backward: true, by_screen: true, flip_if_rtl_page_progression: false})]);
                return true;
            }
            if (sc_name === "down") {
                ρσ_interpolate_kwargs.call(this, scroll_by_page, [ρσ_desugar_kwargs({backward: false, by_screen: true, flip_if_rtl_page_progression: false})]);
                return true;
            }
            if (sc_name === "start_of_file") {
                get_boss().report_human_scroll();
                scroll_to_offset(0);
                return true;
            }
            if (sc_name === "end_of_file") {
                get_boss().report_human_scroll();
                scroll_to_offset(scroll_viewport.document_inline_size());
                return true;
            }
            if (sc_name === "left") {
                ρσ_interpolate_kwargs.call(this, scroll_by_page, [ρσ_desugar_kwargs({backward: true, by_screen: false, flip_if_rtl_page_progression: true})]);
                return true;
            }
            if (sc_name === "right") {
                ρσ_interpolate_kwargs.call(this, scroll_by_page, [ρσ_desugar_kwargs({backward: false, by_screen: false, flip_if_rtl_page_progression: true})]);
                return true;
            }
            if (sc_name === "start_of_book") {
                get_boss().report_human_scroll();
                (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["goto_doc_boundary"].concat([ρσ_desugar_kwargs({start: true})])));
                return true;
            }
            if (sc_name === "end_of_book") {
                get_boss().report_human_scroll();
                (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["goto_doc_boundary"].concat([ρσ_desugar_kwargs({start: false})])));
                return true;
            }
            if (sc_name === "pageup") {
                ρσ_interpolate_kwargs.call(this, scroll_by_page, [ρσ_desugar_kwargs({backward: true, by_screen: true, flip_if_rtl_page_progression: false})]);
                return true;
            }
            if (sc_name === "pagedown") {
                ρσ_interpolate_kwargs.call(this, scroll_by_page, [ρσ_desugar_kwargs({backward: false, by_screen: true, flip_if_rtl_page_progression: false})]);
                return true;
            }
            if (sc_name === "toggle_autoscroll") {
                auto_scroll_action("toggle");
                return true;
            }
            return false;
        };
        if (!handle_shortcut.__argnames__) Object.defineProperties(handle_shortcut, {
            __argnames__ : {value: ["sc_name", "evt"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function handle_gesture(gesture) {
            if (gesture.resolved_action === "next_section") {
                (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["next_section"].concat([ρσ_desugar_kwargs({forward: true})])));
            } else if (gesture.resolved_action === "prev_section") {
                (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["next_section"].concat([ρσ_desugar_kwargs({forward: false})])));
            } else if (gesture.resolved_action === "next_screen") {
                scroll_by_page(false, true);
            } else if (gesture.resolved_action === "prev_screen") {
                scroll_by_page(true, true);
            } else if (gesture.resolved_action === "prev_page") {
                scroll_by_page(true, false);
            } else if (gesture.resolved_action === "next_page") {
                scroll_by_page(false, false);
            }
        };
        if (!handle_gesture.__argnames__) Object.defineProperties(handle_gesture, {
            __argnames__ : {value: ["gesture"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function get_bounding_client_rect(elem) {
            var br, r;
            br = elem.getBoundingClientRect();
            if (br.width === 0 && br.height === 0 && br.x === 0 && br.y === 0) {
                r = document.createRange();
                r.selectNodeContents(elem);
                br = r.getBoundingClientRect();
            }
            return br;
        };
        if (!get_bounding_client_rect.__argnames__) Object.defineProperties(get_bounding_client_rect, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        anchor_funcs = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["pos_for_elem"] = (function() {
                var ρσ_anonfunc = function pos_for_elem(elem) {
                    var br, pos;
                    if (!elem) {
                        return 0;
                    }
                    elem = scrollable_element(elem);
                    br = get_bounding_client_rect(elem);
                    pos = scroll_viewport.viewport_to_document_inline(scroll_viewport.rect_inline_start(br));
                    return column_at(pos);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["elem"]},
                    __module__ : {value: "read_book.paged_mode"}
                });
                return ρσ_anonfunc;
            })();
            ρσ_d["visibility"] = (function() {
                var ρσ_anonfunc = function visibility(pos) {
                    var first;
                    first = column_at(current_scroll_offset() + 10);
                    if (pos < first) {
                        return -1;
                    }
                    if (pos < first + cols_per_screen) {
                        return 0;
                    }
                    return 1;
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["pos"]},
                    __module__ : {value: "read_book.paged_mode"}
                });
                return ρσ_anonfunc;
            })();
            ρσ_d["cmp"] = (function() {
                var ρσ_anonfunc = function cmp(a, b) {
                    return a - b;
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["a", "b"]},
                    __module__ : {value: "read_book.paged_mode"}
                });
                return ρσ_anonfunc;
            })();
            ρσ_d["get_bounding_client_rect"] = get_bounding_client_rect;
            return ρσ_d;
        }).call(this);
        function ResizeManager() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ResizeManager.prototype.__bind_methods__.call(this);
            ResizeManager.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ResizeManager.prototype, "__bind_methods__", {value: function () {
            this.reset = ResizeManager.prototype.reset.bind(this);
            this.start_resize = ResizeManager.prototype.start_resize.bind(this);
            this.end_resize = ResizeManager.prototype.end_resize.bind(this);
            this.is_inverse_transition = ResizeManager.prototype.is_inverse_transition.bind(this);
        }});
        ResizeManager.prototype.__init__ = function __init__() {
            var self = this;
            self.reset();
        };
        if (!ResizeManager.prototype.__init__.__module__) Object.defineProperties(ResizeManager.prototype.__init__, {
            __module__ : {value: "read_book.paged_mode"}
        });
        ResizeManager.__argnames__ = ResizeManager.prototype.__init__.__argnames__;
        ResizeManager.__handles_kwarg_interpolation__ = ResizeManager.prototype.__init__.__handles_kwarg_interpolation__;
        ResizeManager.prototype.reset = function reset() {
            var self = this;
            self.resize_in_progress = null;
            self.last_transition = null;
        };
        if (!ResizeManager.prototype.reset.__module__) Object.defineProperties(ResizeManager.prototype.reset, {
            __module__ : {value: "read_book.paged_mode"}
        });
        ResizeManager.prototype.start_resize = function start_resize(width, height) {
            var self = this;
            self.resize_in_progress = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["width"] = width;
                ρσ_d["height"] = height;
                ρσ_d["column"] = last_scrolled_to_column;
                return ρσ_d;
            }).call(this);
        };
        if (!ResizeManager.prototype.start_resize.__argnames__) Object.defineProperties(ResizeManager.prototype.start_resize, {
            __argnames__ : {value: ["width", "height"]},
            __module__ : {value: "read_book.paged_mode"}
        });
        ResizeManager.prototype.end_resize = function end_resize() {
            var self = this;
            var ρσ_unpack, rp, transition;
            if (!self.resize_in_progress) {
                return;
            }
            ρσ_unpack = [self.resize_in_progress, null];
            rp = ρσ_unpack[0];
            self.resize_in_progress = ρσ_unpack[1];
            transition = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["before"] = rp;
                ρσ_d["after"] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["width"] = scroll_viewport.width();
                    ρσ_d["height"] = scroll_viewport.height();
                    ρσ_d["column"] = last_scrolled_to_column;
                    return ρσ_d;
                }).call(this);
                return ρσ_d;
            }).call(this);
            if (self.is_inverse_transition(transition)) {
                if (transition.after.column !== self.last_transition.before.column) {
                    scroll_to_column(transition.after.column);
                    transition.after.column = last_scrolled_to_column;
                }
            }
            self.last_transition = transition;
        };
        if (!ResizeManager.prototype.end_resize.__module__) Object.defineProperties(ResizeManager.prototype.end_resize, {
            __module__ : {value: "read_book.paged_mode"}
        });
        ResizeManager.prototype.is_inverse_transition = function is_inverse_transition(transition) {
            var self = this;
            var p, n;
            p = self.last_transition;
            if (!p) {
                return false;
            }
            p = p.after;
            n = transition.before;
            return p.column === n.column && p.width === n.width && p.height === n.height;
        };
        if (!ResizeManager.prototype.is_inverse_transition.__argnames__) Object.defineProperties(ResizeManager.prototype.is_inverse_transition, {
            __argnames__ : {value: ["transition"]},
            __module__ : {value: "read_book.paged_mode"}
        });
        ResizeManager.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ResizeManager.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ResizeManager.prototype, "__bases__", {value: []});

        resize_manager = new ResizeManager;
        function prepare_for_resize(width, height) {
            resize_manager.start_resize(width, height);
        };
        if (!prepare_for_resize.__argnames__) Object.defineProperties(prepare_for_resize, {
            __argnames__ : {value: ["width", "height"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function resize_done() {
            resize_manager.end_resize();
        };
        if (!resize_done.__module__) Object.defineProperties(resize_done, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function auto_scroll_action(action) {
            if (action === "toggle") {
                (ρσ_expr_temp = get_boss(), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.send_message, ["error"].concat([ρσ_desugar_kwargs({errkey: "no-auto-scroll-in-paged-mode", is_non_critical: true})])));
            }
            return false;
        };
        if (!auto_scroll_action.__argnames__) Object.defineProperties(auto_scroll_action, {
            __argnames__ : {value: ["action"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        function DragScroller() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            DragScroller.prototype.__bind_methods__.call(this);
            DragScroller.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(DragScroller.prototype, "__bind_methods__", {value: function () {
            this.is_running = DragScroller.prototype.is_running.bind(this);
            this.start = DragScroller.prototype.start.bind(this);
            this.do_one_page_turn = DragScroller.prototype.do_one_page_turn.bind(this);
            this.stop = DragScroller.prototype.stop.bind(this);
        }});
        DragScroller.prototype.__init__ = function __init__() {
            var self = this;
            self.backward = false;
            self.timer_id = null;
        };
        if (!DragScroller.prototype.__init__.__module__) Object.defineProperties(DragScroller.prototype.__init__, {
            __module__ : {value: "read_book.paged_mode"}
        });
        DragScroller.__argnames__ = DragScroller.prototype.__init__.__argnames__;
        DragScroller.__handles_kwarg_interpolation__ = DragScroller.prototype.__init__.__handles_kwarg_interpolation__;
        DragScroller.prototype.is_running = function is_running() {
            var self = this;
            return self.timer_id !== null;
        };
        if (!DragScroller.prototype.is_running.__module__) Object.defineProperties(DragScroller.prototype.is_running, {
            __module__ : {value: "read_book.paged_mode"}
        });
        DragScroller.prototype.start = function start(backward) {
            var self = this;
            if (!self.is_running() || backward !== self.backward) {
                self.stop();
                self.backward = backward;
                self.timer_id = window.setTimeout(self.do_one_page_turn, self.INTERVAL);
            }
        };
        if (!DragScroller.prototype.start.__argnames__) Object.defineProperties(DragScroller.prototype.start, {
            __argnames__ : {value: ["backward"]},
            __module__ : {value: "read_book.paged_mode"}
        });
        DragScroller.prototype.do_one_page_turn = function do_one_page_turn() {
            var self = this;
            var pos;
            pos = (self.backward) ? previous_col_location() : next_col_location();
            if (pos >= 0) {
                scroll_to_pos(pos);
                self.timer_id = window.setTimeout(self.do_one_page_turn, self.INTERVAL * 2);
            } else {
                self.stop();
            }
        };
        if (!DragScroller.prototype.do_one_page_turn.__module__) Object.defineProperties(DragScroller.prototype.do_one_page_turn, {
            __module__ : {value: "read_book.paged_mode"}
        });
        DragScroller.prototype.stop = function stop() {
            var self = this;
            if (self.timer_id !== null) {
                window.clearTimeout(self.timer_id);
                self.timer_id = null;
            }
        };
        if (!DragScroller.prototype.stop.__module__) Object.defineProperties(DragScroller.prototype.stop, {
            __module__ : {value: "read_book.paged_mode"}
        });
        DragScroller.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        DragScroller.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(DragScroller.prototype, "__bases__", {value: []});
        DragScroller.prototype.INTERVAL = 500;

        drag_scroller = new DragScroller;
        function cancel_drag_scroll() {
            drag_scroller.stop();
        };
        if (!cancel_drag_scroll.__module__) Object.defineProperties(cancel_drag_scroll, {
            __module__ : {value: "read_book.paged_mode"}
        });

        function start_drag_scroll(delta) {
            drag_scroller.start(delta < 0);
        };
        if (!start_drag_scroll.__argnames__) Object.defineProperties(start_drag_scroll, {
            __argnames__ : {value: ["delta"]},
            __module__ : {value: "read_book.paged_mode"}
        });

        ρσ_modules["read_book.paged_mode"]._in_paged_mode = _in_paged_mode;
        ρσ_modules["read_book.paged_mode"].col_size = col_size;
        ρσ_modules["read_book.paged_mode"].screen_inline = screen_inline;
        ρσ_modules["read_book.paged_mode"].screen_block = screen_block;
        ρσ_modules["read_book.paged_mode"].cols_per_screen = cols_per_screen;
        ρσ_modules["read_book.paged_mode"].gap = gap;
        ρσ_modules["read_book.paged_mode"].col_and_gap = col_and_gap;
        ρσ_modules["read_book.paged_mode"].last_scrolled_to_column = last_scrolled_to_column;
        ρσ_modules["read_book.paged_mode"].is_full_screen_layout = is_full_screen_layout;
        ρσ_modules["read_book.paged_mode"].scroll_resize_bug_watcher = scroll_resize_bug_watcher;
        ρσ_modules["read_book.paged_mode"].wheel_handler = wheel_handler;
        ρσ_modules["read_book.paged_mode"].onwheel = onwheel;
        ρσ_modules["read_book.paged_mode"].anchor_funcs = anchor_funcs;
        ρσ_modules["read_book.paged_mode"].resize_manager = resize_manager;
        ρσ_modules["read_book.paged_mode"].drag_scroller = drag_scroller;
        ρσ_modules["read_book.paged_mode"].first_child = first_child;
        ρσ_modules["read_book.paged_mode"].has_start_text = has_start_text;
        ρσ_modules["read_book.paged_mode"].handle_rtl_body = handle_rtl_body;
        ρσ_modules["read_book.paged_mode"].create_page_div = create_page_div;
        ρσ_modules["read_book.paged_mode"].in_paged_mode = in_paged_mode;
        ρσ_modules["read_book.paged_mode"].get_number_of_cols = get_number_of_cols;
        ρσ_modules["read_book.paged_mode"].reset_paged_mode_globals = reset_paged_mode_globals;
        ρσ_modules["read_book.paged_mode"].column_at = column_at;
        ρσ_modules["read_book.paged_mode"].fit_images = fit_images;
        ρσ_modules["read_book.paged_mode"].cps_by_em_size = cps_by_em_size;
        ρσ_modules["read_book.paged_mode"].calc_columns_per_screen = calc_columns_per_screen;
        ρσ_modules["read_book.paged_mode"].get_columns_per_screen_data = get_columns_per_screen_data;
        ρσ_modules["read_book.paged_mode"].will_columns_per_screen_change = will_columns_per_screen_change;
        ρσ_modules["read_book.paged_mode"].ScrollResizeBugWatcher = ScrollResizeBugWatcher;
        ρσ_modules["read_book.paged_mode"].layout = layout;
        ρσ_modules["read_book.paged_mode"].current_scroll_offset = current_scroll_offset;
        ρσ_modules["read_book.paged_mode"].scroll_to_offset = scroll_to_offset;
        ρσ_modules["read_book.paged_mode"].scroll_to_column = scroll_to_column;
        ρσ_modules["read_book.paged_mode"].scroll_to_pos = scroll_to_pos;
        ρσ_modules["read_book.paged_mode"].scroll_to_previous_position = scroll_to_previous_position;
        ρσ_modules["read_book.paged_mode"].scroll_to_fraction = scroll_to_fraction;
        ρσ_modules["read_book.paged_mode"].column_boundaries = column_boundaries;
        ρσ_modules["read_book.paged_mode"].column_at_current_scroll_offset = column_at_current_scroll_offset;
        ρσ_modules["read_book.paged_mode"].current_column_location = current_column_location;
        ρσ_modules["read_book.paged_mode"].number_of_cols_left = number_of_cols_left;
        ρσ_modules["read_book.paged_mode"].next_screen_location = next_screen_location;
        ρσ_modules["read_book.paged_mode"].previous_screen_location = previous_screen_location;
        ρσ_modules["read_book.paged_mode"].next_col_location = next_col_location;
        ρσ_modules["read_book.paged_mode"].previous_col_location = previous_col_location;
        ρσ_modules["read_book.paged_mode"].jump_to_anchor = jump_to_anchor;
        ρσ_modules["read_book.paged_mode"].scrollable_element = scrollable_element;
        ρσ_modules["read_book.paged_mode"].scroll_to_elem = scroll_to_elem;
        ρσ_modules["read_book.paged_mode"].snap_to_selection = snap_to_selection;
        ρσ_modules["read_book.paged_mode"].ensure_selection_boundary_visible = ensure_selection_boundary_visible;
        ρσ_modules["read_book.paged_mode"].jump_to_cfi = jump_to_cfi;
        ρσ_modules["read_book.paged_mode"].current_cfi = current_cfi;
        ρσ_modules["read_book.paged_mode"].progress_frac = progress_frac;
        ρσ_modules["read_book.paged_mode"].page_counts = page_counts;
        ρσ_modules["read_book.paged_mode"].next_spine_item = next_spine_item;
        ρσ_modules["read_book.paged_mode"].is_return = is_return;
        ρσ_modules["read_book.paged_mode"].WheelState = WheelState;
        ρσ_modules["read_book.paged_mode"].HandleWheel = HandleWheel;
        ρσ_modules["read_book.paged_mode"].scroll_by_page = scroll_by_page;
        ρσ_modules["read_book.paged_mode"].scroll_to_extend_annotation = scroll_to_extend_annotation;
        ρσ_modules["read_book.paged_mode"].handle_shortcut = handle_shortcut;
        ρσ_modules["read_book.paged_mode"].handle_gesture = handle_gesture;
        ρσ_modules["read_book.paged_mode"].get_bounding_client_rect = get_bounding_client_rect;
        ρσ_modules["read_book.paged_mode"].ResizeManager = ResizeManager;
        ρσ_modules["read_book.paged_mode"].prepare_for_resize = prepare_for_resize;
        ρσ_modules["read_book.paged_mode"].resize_done = resize_done;
        ρσ_modules["read_book.paged_mode"].auto_scroll_action = auto_scroll_action;
        ρσ_modules["read_book.paged_mode"].DragScroller = DragScroller;
        ρσ_modules["read_book.paged_mode"].cancel_drag_scroll = cancel_drag_scroll;
        ρσ_modules["read_book.paged_mode"].start_drag_scroll = start_drag_scroll;
    })();

    (function(){
        var __name__ = "read_book.referencing";
        var current_spine_item = ρσ_modules["read_book.globals"].current_spine_item;

        function elem_for_ref(refnum) {
            refnum = int(refnum);
            return (ρσ_expr_temp = document.getElementsByTagName("p"))[ρσ_bound_index(refnum - 1, ρσ_expr_temp)];
        };
        if (!elem_for_ref.__argnames__) Object.defineProperties(elem_for_ref, {
            __argnames__ : {value: ["refnum"]},
            __module__ : {value: "read_book.referencing"}
        });

        function start_reference_mode() {
            var si, ρσ_unpack, i, p;
            si = current_spine_item().index;
            var ρσ_Iter0 = ρσ_Iterable(enumerate(document.getElementsByTagName("p")));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                ρσ_unpack = ρσ_Iter0[ρσ_Index0];
                i = ρσ_unpack[0];
                p = ρσ_unpack[1];
                p.dataset.calibreRefNum = "" + ρσ_str.format("{}", si) + "." + ρσ_str.format("{}", i + 1) + "";
            }
            document.body.classList.add("calibre-reference-mode");
        };
        if (!start_reference_mode.__module__) Object.defineProperties(start_reference_mode, {
            __module__ : {value: "read_book.referencing"}
        });

        function end_reference_mode() {
            document.body.classList.remove("calibre-reference-mode");
        };
        if (!end_reference_mode.__module__) Object.defineProperties(end_reference_mode, {
            __module__ : {value: "read_book.referencing"}
        });

        ρσ_modules["read_book.referencing"].elem_for_ref = elem_for_ref;
        ρσ_modules["read_book.referencing"].start_reference_mode = start_reference_mode;
        ρσ_modules["read_book.referencing"].end_reference_mode = end_reference_mode;
    })();

    (function(){
        var __name__ = "read_book.smil";
        var is_anchor_on_screen = ρσ_modules["read_book.anchor_visibility"].is_anchor_on_screen;

        var get_boss = ρσ_modules["read_book.globals"].get_boss;

        function flatten_seq(seq, par_list) {
            var par, child;
            if (seq.par) {
                var ρσ_Iter0 = ρσ_Iterable(seq.par);
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    par = ρσ_Iter0[ρσ_Index0];
                    if (par.anchor) {
                        par_list.push(par);
                    }
                }
            }
            if (seq.seq) {
                var ρσ_Iter1 = ρσ_Iterable(seq.seq);
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    child = ρσ_Iter1[ρσ_Index1];
                    flatten_seq(child, par_list);
                }
            }
        };
        if (!flatten_seq.__argnames__) Object.defineProperties(flatten_seq, {
            __argnames__ : {value: ["seq", "par_list"]},
            __module__ : {value: "read_book.smil"}
        });

        function flatten_smil_map(smil_map) {
            var anchor_map, par_list, i;
            anchor_map = Object.create(null);
            par_list = [];
            if (smil_map) {
                flatten_seq(smil_map, par_list);
            }
            par_list.sort((function() {
                var ρσ_anonfunc = function (a, b) {
                    return a.num - b.num;
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["a", "b"]},
                    __module__ : {value: "read_book.smil"}
                });
                return ρσ_anonfunc;
            })());
            for (var ρσ_Index2 = 0; ρσ_Index2 < par_list.length; ρσ_Index2++) {
                i = ρσ_Index2;
                anchor_map[ρσ_bound_index(par_list[(typeof i === "number" && i < 0) ? par_list.length + i : i].anchor, anchor_map)] = i;
            }
            return [anchor_map, par_list];
        };
        if (!flatten_smil_map.__argnames__) Object.defineProperties(flatten_smil_map, {
            __argnames__ : {value: ["smil_map"]},
            __module__ : {value: "read_book.smil"}
        });

        function get_smil_audio_map(smil_map) {
            var audio_map, v;
            audio_map = Object.create(null);
            function flatten(seq) {
                var a, par, child;
                if (seq.par) {
                    var ρσ_Iter3 = ρσ_Iterable(seq.par);
                    for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                        par = ρσ_Iter3[ρσ_Index3];
                        if (par.audio) {
                            a = audio_map[ρσ_bound_index(par.audio, audio_map)];
                            if (!a) {
                                a = audio_map[ρσ_bound_index(par.audio, audio_map)] = [];
                            }
                            a.push(par);
                        }
                    }
                }
                if (seq.seq) {
                    var ρσ_Iter4 = ρσ_Iterable(seq.seq);
                    for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                        child = ρσ_Iter4[ρσ_Index4];
                        flatten(child);
                    }
                }
            };
            if (!flatten.__argnames__) Object.defineProperties(flatten, {
                __argnames__ : {value: ["seq"]},
                __module__ : {value: "read_book.smil"}
            });

            if (smil_map) {
                flatten(smil_map);
                var ρσ_Iter5 = ρσ_Iterable(Object.values(audio_map));
                for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                    v = ρσ_Iter5[ρσ_Index5];
                    v.sort((function() {
                        var ρσ_anonfunc = function (a, b) {
                            return a.start - b.start;
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["a", "b"]},
                            __module__ : {value: "read_book.smil"}
                        });
                        return ρσ_anonfunc;
                    })());
                }
            }
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["audio_files"] = audio_map;
                return ρσ_d;
            }).call(this);
        };
        if (!get_smil_audio_map.__argnames__) Object.defineProperties(get_smil_audio_map, {
            __argnames__ : {value: ["smil_map"]},
            __module__ : {value: "read_book.smil"}
        });

        function get_smil_id_for_timestamp(audio_file_name, timestamp, smil_audio_map, prev_idx) {
            var pars, i;
            pars = (ρσ_expr_temp = smil_audio_map.audio_files)[(typeof audio_file_name === "number" && audio_file_name < 0) ? ρσ_expr_temp.length + audio_file_name : audio_file_name];
            if (!pars) {
                return [null, null];
            }
            prev_idx = prev_idx || 0;
            if (prev_idx >= pars.length || prev_idx < 0) {
                prev_idx = 0;
            }
            for (var ρσ_Index6 = prev_idx; ρσ_Index6 < pars.length; ρσ_Index6++) {
                i = ρσ_Index6;
                if (pars[(typeof i === "number" && i < 0) ? pars.length + i : i].start <= timestamp && timestamp <= pars[(typeof i === "number" && i < 0) ? pars.length + i : i].end) {
                    return [pars[(typeof i === "number" && i < 0) ? pars.length + i : i].anchor, i];
                }
            }
            for (var ρσ_Index7 = 0; ρσ_Index7 < prev_idx; ρσ_Index7++) {
                i = ρσ_Index7;
                if (pars[(typeof i === "number" && i < 0) ? pars.length + i : i].start <= timestamp && timestamp <= pars[(typeof i === "number" && i < 0) ? pars.length + i : i].end) {
                    return [pars[(typeof i === "number" && i < 0) ? pars.length + i : i].anchor, i];
                }
            }
            return [null, null];
        };
        if (!get_smil_id_for_timestamp.__argnames__) Object.defineProperties(get_smil_id_for_timestamp, {
            __argnames__ : {value: ["audio_file_name", "timestamp", "smil_audio_map", "prev_idx"]},
            __module__ : {value: "read_book.smil"}
        });

        function next_audio_file_for_spine_item(audio_file_name, smil_audio_map) {
            var keys, idx;
            if (audio_file_name) {
                keys = Object.keys(smil_audio_map);
                idx = keys.indexOf(audio_file_name);
                if (0 <= idx && idx < keys.length - 1) {
                    return [keys[ρσ_bound_index(idx + 1, keys)], smil_audio_map[ρσ_bound_index(keys[ρσ_bound_index(idx + 1, keys)], smil_audio_map)]];
                }
            }
            return [null, null];
        };
        if (!next_audio_file_for_spine_item.__argnames__) Object.defineProperties(next_audio_file_for_spine_item, {
            __argnames__ : {value: ["audio_file_name", "smil_audio_map"]},
            __module__ : {value: "read_book.smil"}
        });

        function first_par(smil_map) {
            var par_list, par;
            par_list = flatten_smil_map(smil_map)[1];
            var ρσ_Iter8 = ρσ_Iterable(par_list);
            for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                par = ρσ_Iter8[ρσ_Index8];
                if (par.anchor) {
                    return par;
                }
            }
            return null;
        };
        if (!first_par.__argnames__) Object.defineProperties(first_par, {
            __argnames__ : {value: ["smil_map"]},
            __module__ : {value: "read_book.smil"}
        });

        function find_next_audio_in_spine(spine_idx, book_manifest) {
            var spine, file_map, q, f, par, i;
            spine = book_manifest.spine;
            file_map = book_manifest.files;
            for (var ρσ_Index9 = spine_idx + 1; ρσ_Index9 < spine.length; ρσ_Index9++) {
                i = ρσ_Index9;
                q = spine[(typeof i === "number" && i < 0) ? spine.length + i : i];
                f = file_map[(typeof q === "number" && q < 0) ? file_map.length + q : q];
                if (f && f.smil_map) {
                    par = first_par(f.smil_map);
                    if (par) {
                        return [q, par];
                    }
                }
            }
            return [null, null];
        };
        if (!find_next_audio_in_spine.__argnames__) Object.defineProperties(find_next_audio_in_spine, {
            __argnames__ : {value: ["spine_idx", "book_manifest"]},
            __module__ : {value: "read_book.smil"}
        });

        function smil_element_at(pos, anchor_map, par_list) {
            var elem, af, br, par;
            if (pos) {
                elem = document.elementFromPoint(pos.x, pos.y);
                if (elem && elem.id && ρσ_exists.n(anchor_map[ρσ_bound_index(elem.id, anchor_map)])) {
                    return par_list[ρσ_bound_index(anchor_map[ρσ_bound_index(elem.id, anchor_map)], par_list)];
                }
                af = get_boss().anchor_funcs;
                var ρσ_Iter10 = ρσ_Iterable(par_list);
                for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                    par = ρσ_Iter10[ρσ_Index10];
                    if (par.anchor && par.audio) {
                        elem = document.getElementById(par.anchor);
                        if (elem) {
                            br = af.get_bounding_client_rect(elem);
                            if (br.x <= (ρσ_cond_temp = pos.x) && ρσ_cond_temp <= br.x + br.width && br.y <= (ρσ_cond_temp = pos.y) && ρσ_cond_temp <= br.y + br.height) {
                                return par;
                            }
                        }
                    }
                }
                return null;
            } else {
                var ρσ_Iter11 = ρσ_Iterable(par_list);
                for (var ρσ_Index11 = 0; ρσ_Index11 < ρσ_Iter11.length; ρσ_Index11++) {
                    par = ρσ_Iter11[ρσ_Index11];
                    if (par.anchor && par.audio && is_anchor_on_screen(par.anchor)) {
                        return par;
                    }
                }
                var ρσ_Iter12 = ρσ_Iterable(par_list);
                for (var ρσ_Index12 = 0; ρσ_Index12 < ρσ_Iter12.length; ρσ_Index12++) {
                    par = ρσ_Iter12[ρσ_Index12];
                    if (par.audio) {
                        return par;
                    }
                }
                return null;
            }
        };
        if (!smil_element_at.__argnames__) Object.defineProperties(smil_element_at, {
            __argnames__ : {value: ["pos", "anchor_map", "par_list"]},
            __module__ : {value: "read_book.smil"}
        });

        function mark_smil_element(anchor) {
            var elem, sel;
            elem = document.getElementById(anchor);
            if (elem) {
                sel = window.getSelection();
                sel.selectAllChildren(elem);
                return bool(sel.rangeCount && sel.toString());
            }
            return false;
        };
        if (!mark_smil_element.__argnames__) Object.defineProperties(mark_smil_element, {
            __argnames__ : {value: ["anchor"]},
            __module__ : {value: "read_book.smil"}
        });

        ρσ_modules["read_book.smil"].flatten_seq = flatten_seq;
        ρσ_modules["read_book.smil"].flatten_smil_map = flatten_smil_map;
        ρσ_modules["read_book.smil"].get_smil_audio_map = get_smil_audio_map;
        ρσ_modules["read_book.smil"].get_smil_id_for_timestamp = get_smil_id_for_timestamp;
        ρσ_modules["read_book.smil"].next_audio_file_for_spine_item = next_audio_file_for_spine_item;
        ρσ_modules["read_book.smil"].first_par = first_par;
        ρσ_modules["read_book.smil"].find_next_audio_in_spine = find_next_audio_in_spine;
        ρσ_modules["read_book.smil"].smil_element_at = smil_element_at;
        ρσ_modules["read_book.smil"].mark_smil_element = mark_smil_element;
    })();

    (function(){
        var __name__ = "read_book.toc";
        var E = ρσ_modules.elementmaker.E;

        var create_search_bar = ρσ_modules.complete.create_search_bar;

        var ensure_id = ρσ_modules.dom.ensure_id;
        var set_css = ρσ_modules.dom.set_css;
        var svgicon = ρσ_modules.dom.svgicon;

        var _ = ρσ_modules.gettext.gettext;

        var error_dialog = ρσ_modules.modals.error_dialog;

        var position_for_anchor = ρσ_modules["read_book.anchor_visibility"].position_for_anchor;

        var current_book = ρσ_modules["read_book.globals"].current_book;
        var current_layout_mode = ρσ_modules["read_book.globals"].current_layout_mode;
        var current_spine_item = ρσ_modules["read_book.globals"].current_spine_item;
        var get_boss = ρσ_modules["read_book.globals"].get_boss;
        var set_toc_anchor_map = ρσ_modules["read_book.globals"].set_toc_anchor_map;
        var toc_anchor_map = ρσ_modules["read_book.globals"].toc_anchor_map;

        var scroll_viewport = ρσ_modules["read_book.viewport"].scroll_viewport;

        var create_tree = ρσ_modules.widgets.create_tree;
        var find_text_in_tree = ρσ_modules.widgets.find_text_in_tree;
        var scroll_tree_item_into_view = ρσ_modules.widgets.scroll_tree_item_into_view;

        function update_visible_toc_nodes(visible_anchors) {
            update_visible_toc_nodes.data = visible_anchors;
        };
        if (!update_visible_toc_nodes.__argnames__) Object.defineProperties(update_visible_toc_nodes, {
            __argnames__ : {value: ["visible_anchors"]},
            __module__ : {value: "read_book.toc"}
        });

        update_visible_toc_nodes.data = Object.create(null);
        function iter_toc_descendants(node, callback) {
            var child;
            var ρσ_Iter0 = ρσ_Iterable(node.children);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                child = ρσ_Iter0[ρσ_Index0];
                if (callback(child)) {
                    return;
                }
                iter_toc_descendants(child, callback);
            }
        };
        if (!iter_toc_descendants.__argnames__) Object.defineProperties(iter_toc_descendants, {
            __argnames__ : {value: ["node", "callback"]},
            __module__ : {value: "read_book.toc"}
        });

        function get_toc_nodes_bordering_spine_item(toc, csi) {
            var spine, ρσ_unpack, spine_before, spine_after, which, before, after, prev, name;
            toc = toc || current_book().manifest.toc;
            csi = csi || current_spine_item();
            spine = current_book().manifest.spine;
            ρσ_unpack = [Object.create(null), Object.create(null)];
            spine_before = ρσ_unpack[0];
            spine_after = ρσ_unpack[1];
            which = spine_before;
            before = after = prev = null;
            var ρσ_Iter1 = ρσ_Iterable(spine);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                name = ρσ_Iter1[ρσ_Index1];
                if (name === csi) {
                    which = spine_after;
                } else {
                    which[(typeof name === "number" && name < 0) ? which.length + name : name] = true;
                }
            }
            iter_toc_descendants(toc, (function() {
                var ρσ_anonfunc = function (node) {
                    if (node.dest) {
                        if (spine_before[ρσ_bound_index(node.dest, spine_before)]) {
                            prev = node;
                        } else if (spine_after[ρσ_bound_index(node.dest, spine_after)]) {
                            if (!before) {
                                before = prev;
                            }
                            if (!after) {
                                after = node;
                            }
                            return true;
                        }
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["node"]},
                    __module__ : {value: "read_book.toc"}
                });
                return ρσ_anonfunc;
            })());
            if (!before && prev !== null) {
                before = prev;
            }
            return [before, after];
        };
        if (!get_toc_nodes_bordering_spine_item.__argnames__) Object.defineProperties(get_toc_nodes_bordering_spine_item, {
            __argnames__ : {value: ["toc", "csi"]},
            __module__ : {value: "read_book.toc"}
        });

        function get_border_nodes(toc, id_map) {
            var data, ρσ_unpack, before, after, sb, sa;
            data = update_visible_toc_nodes.data;
            ρσ_unpack = [data.before, data.after];
            before = ρσ_unpack[0];
            after = ρσ_unpack[1];
            if (before) {
                before = id_map[(typeof before === "number" && before < 0) ? id_map.length + before : before];
            }
            if (after) {
                after = id_map[(typeof after === "number" && after < 0) ? id_map.length + after : after];
            }
            if (before && after) {
                return [before, after];
            }
            ρσ_unpack = get_toc_nodes_bordering_spine_item(toc);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            sb = ρσ_unpack[0];
            sa = ρσ_unpack[1];
            before = before || sb;
            after = after || sa;
            return [before, after];
        };
        if (!get_border_nodes.__argnames__) Object.defineProperties(get_border_nodes, {
            __argnames__ : {value: ["toc", "id_map"]},
            __module__ : {value: "read_book.toc"}
        });

        function family_for_toc_node(toc_node_id, parent_map, id_map) {
            var toc, ρσ_unpack, family, node, parent;
            if (!id_map || !parent_map) {
                toc = current_book().manifest.toc;
                ρσ_unpack = get_toc_maps(toc);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                parent_map = ρσ_unpack[0];
                id_map = ρσ_unpack[1];
            }
            family = [];
            node = id_map[(typeof toc_node_id === "number" && toc_node_id < 0) ? id_map.length + toc_node_id : toc_node_id];
            while (node && node.title) {
                family.unshift(node);
                parent = parent_map[ρσ_bound_index(node.id, parent_map)];
                node = null;
                if (parent) {
                    node = id_map[ρσ_bound_index(parent.id, id_map)];
                }
            }
            return family;
        };
        if (!family_for_toc_node.__argnames__) Object.defineProperties(family_for_toc_node, {
            __argnames__ : {value: ["toc_node_id", "parent_map", "id_map"]},
            __module__ : {value: "read_book.toc"}
        });

        function get_page_list_id_map(page_list) {
            return (function() {
                var ρσ_Iter = ρσ_Iterable(page_list), ρσ_Result = Object.create(null), x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    ρσ_Result[x.id] = (x);
                }
                return ρσ_Result;
            })();
        };
        if (!get_page_list_id_map.__argnames__) Object.defineProperties(get_page_list_id_map, {
            __argnames__ : {value: ["page_list"]},
            __module__ : {value: "read_book.toc"}
        });

        function get_page_list_before(page_list, id_map) {
            var csi, spine, ρσ_unpack, spine_before, spine_after, which, before, prev, name, item;
            csi = csi || current_spine_item();
            spine = current_book().manifest.spine;
            ρσ_unpack = [Object.create(null), Object.create(null)];
            spine_before = ρσ_unpack[0];
            spine_after = ρσ_unpack[1];
            which = spine_before;
            before = prev = null;
            var ρσ_Iter2 = ρσ_Iterable(spine);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                name = ρσ_Iter2[ρσ_Index2];
                if (name === csi) {
                    which = spine_after;
                } else {
                    which[(typeof name === "number" && name < 0) ? which.length + name : name] = true;
                }
            }
            var ρσ_Iter3 = ρσ_Iterable(page_list);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                item = ρσ_Iter3[ρσ_Index3];
                if (item.dest) {
                    if (spine_before[ρσ_bound_index(item.dest, spine_before)]) {
                        prev = item;
                    } else if (spine_after[ρσ_bound_index(item.dest, spine_after)]) {
                        if (!before) {
                            before = prev;
                        }
                        break;
                    }
                }
            }
            return before;
        };
        if (!get_page_list_before.__argnames__) Object.defineProperties(get_page_list_before, {
            __argnames__ : {value: ["page_list", "id_map"]},
            __module__ : {value: "read_book.toc"}
        });

        function get_current_pagelist_items() {
            var ans, page_list, data, id_map, before;
            ans = Object.create(null);
            page_list = current_book().manifest.page_list;
            data = ρσ_exists.d(update_visible_toc_nodes.data).page_list;
            if (!data || !page_list) {
                return ans;
            }
            id_map = get_page_list_id_map(page_list);
            if (data.has_visible) {
                ans = data.visible_anchors;
            } else {
                if (ρσ_exists.n(data.before)) {
                    ans[ρσ_bound_index(data.before, ans)] = true;
                } else {
                    before = get_page_list_before(page_list, id_map);
                    if ((typeof before !== "undefined" && before !== null)) {
                        ans[ρσ_bound_index(before.id, ans)] = true;
                    }
                }
            }
            return (function() {
                var ρσ_Iter = ρσ_Iterable(Object.keys(ans)), ρσ_Result = [], x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    ρσ_Result.push(id_map[(typeof x === "number" && x < 0) ? id_map.length + x : x]);
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
        };
        if (!get_current_pagelist_items.__module__) Object.defineProperties(get_current_pagelist_items, {
            __module__ : {value: "read_book.toc"}
        });

        function get_current_toc_nodes() {
            var toc, ρσ_unpack, parent_map, id_map, data, ans, before, r, fam, x;
            toc = current_book().manifest.toc;
            ρσ_unpack = get_toc_maps(toc);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            parent_map = ρσ_unpack[0];
            id_map = ρσ_unpack[1];
            data = update_visible_toc_nodes.data;
            ans = Object.create(null);
            if (data.has_visible) {
                ans = data.visible_anchors;
            } else {
                if (data.before) {
                    ans[ρσ_bound_index(data.before, ans)] = true;
                } else {
                    before = get_border_nodes(toc, id_map)[0];
                    if (before) {
                        ans[ρσ_bound_index(before.id, ans)] = true;
                    }
                }
            }
            r = [];
            var ρσ_Iter4 = ρσ_Iterable(Object.keys(ans));
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                x = ρσ_Iter4[ρσ_Index4];
                fam = family_for_toc_node(x, parent_map, id_map);
                if ((typeof fam !== "undefined" && fam !== null ? fam : Object.create(null)).length) {
                    r.push(fam);
                }
            }
            return r;
        };
        if (!get_current_toc_nodes.__module__) Object.defineProperties(get_current_toc_nodes, {
            __module__ : {value: "read_book.toc"}
        });

        function get_highlighted_toc_nodes(toc, parent_map, id_map, skip_parents) {
            var data, ans, before, p, node_id;
            data = update_visible_toc_nodes.data;
            ans = Object.create(null);
            if (data.has_visible) {
                ans = data.visible_anchors;
            } else {
                if (data.before) {
                    ans[ρσ_bound_index(data.before, ans)] = true;
                } else {
                    before = get_border_nodes(toc, id_map)[0];
                    if (before) {
                        ans[ρσ_bound_index(before.id, ans)] = true;
                    }
                }
            }
            if (!skip_parents) {
                var ρσ_Iter5 = ρσ_Iterable(Object.keys(ans));
                for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                    node_id = ρσ_Iter5[ρσ_Index5];
                    p = parent_map[(typeof node_id === "number" && node_id < 0) ? parent_map.length + node_id : node_id];
                    while (p && p.title) {
                        ans[ρσ_bound_index(p.id, ans)] = true;
                        p = parent_map[ρσ_bound_index(p.id, parent_map)];
                    }
                }
            }
            return ans;
        };
        if (!get_highlighted_toc_nodes.__argnames__) Object.defineProperties(get_highlighted_toc_nodes, {
            __argnames__ : {value: ["toc", "parent_map", "id_map", "skip_parents"]},
            __module__ : {value: "read_book.toc"}
        });

        function get_toc_maps(toc) {
            var ρσ_unpack, parent_map, id_map;
            if (!toc) {
                toc = current_book().manifest.toc;
            }
            ρσ_unpack = [Object.create(null), Object.create(null)];
            parent_map = ρσ_unpack[0];
            id_map = ρσ_unpack[1];
            function process_node(node, parent) {
                var c;
                id_map[ρσ_bound_index(node.id, id_map)] = node;
                parent_map[ρσ_bound_index(node.id, parent_map)] = parent;
                var ρσ_Iter6 = ρσ_Iterable(node.children);
                for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                    c = ρσ_Iter6[ρσ_Index6];
                    process_node(c, node);
                }
            };
            if (!process_node.__argnames__) Object.defineProperties(process_node, {
                __argnames__ : {value: ["node", "parent"]},
                __module__ : {value: "read_book.toc"}
            });

            process_node(toc);
            return [parent_map, id_map];
        };
        if (!get_toc_maps.__argnames__) Object.defineProperties(get_toc_maps, {
            __argnames__ : {value: ["toc"]},
            __module__ : {value: "read_book.toc"}
        });

        function get_book_mark_title() {
            var toc, ρσ_unpack, parent_map, id_map, highlighted_toc_nodes, node, node_id;
            toc = current_book().manifest.toc;
            ρσ_unpack = get_toc_maps(toc);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            parent_map = ρσ_unpack[0];
            id_map = ρσ_unpack[1];
            highlighted_toc_nodes = get_highlighted_toc_nodes(toc, parent_map, id_map, true);
            var ρσ_Iter7 = ρσ_Iterable(Object.keys(highlighted_toc_nodes));
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                node_id = ρσ_Iter7[ρσ_Index7];
                node = id_map[(typeof node_id === "number" && node_id < 0) ? id_map.length + node_id : node_id];
                if (node.title) {
                    return node.title;
                }
            }
            return "";
        };
        if (!get_book_mark_title.__module__) Object.defineProperties(get_book_mark_title, {
            __module__ : {value: "read_book.toc"}
        });

        function create_toc_tree(toc, onclick) {
            var ρσ_unpack, parent_map, id_map, highlighted_toc_nodes;
            ρσ_unpack = get_toc_maps(toc);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            parent_map = ρσ_unpack[0];
            id_map = ρσ_unpack[1];
            highlighted_toc_nodes = get_highlighted_toc_nodes(toc, parent_map, id_map);
            function populate_data(node, li, a) {
                var title;
                li.dataset.tocDest = node.dest || "";
                li.dataset.tocFrag = node.frag || "";
                title = node.title || "";
                if (highlighted_toc_nodes[ρσ_bound_index(node.id, highlighted_toc_nodes)]) {
                    a.appendChild(E.b(E.i(title)));
                } else {
                    a.textContent = title;
                }
            };
            if (!populate_data.__argnames__) Object.defineProperties(populate_data, {
                __argnames__ : {value: ["node", "li", "a"]},
                __module__ : {value: "read_book.toc"}
            });

            return create_tree(toc, populate_data, onclick);
        };
        if (!create_toc_tree.__argnames__) Object.defineProperties(create_toc_tree, {
            __argnames__ : {value: ["toc", "onclick"]},
            __module__ : {value: "read_book.toc"}
        });

        function do_search(text) {
            var container, a;
            container = document.getElementById(this);
            a = find_text_in_tree(container, text);
            if (!text) {
                return;
            }
            if (!a) {
                return error_dialog(_("No matches found"), _("The text \"{}\" was not found in the Table of Contents").format(text));
            }
            scroll_tree_item_into_view(a);
        };
        if (!do_search.__argnames__) Object.defineProperties(do_search, {
            __argnames__ : {value: ["text"]},
            __module__ : {value: "read_book.toc"}
        });

        function create_toc_panel(book, container, onclick) {
            var toc_panel, toc_panel_id, search_button, t, search_bar, child;
            function handle_click(event, li) {
                if (event.button === 0) {
                    onclick(li.dataset.tocDest, li.dataset.tocFrag);
                }
            };
            if (!handle_click.__argnames__) Object.defineProperties(handle_click, {
                __argnames__ : {value: ["event", "li"]},
                __module__ : {value: "read_book.toc"}
            });

            toc_panel = create_toc_tree(book.manifest.toc, handle_click);
            toc_panel_id = ensure_id(toc_panel);
            ρσ_interpolate_kwargs.call(this, set_css, [container].concat([ρσ_desugar_kwargs({display: "flex", flex_direction: "column", height: "100%", min_height: "100%", overflow: "hidden", max_height: "100vh", max_width: "100vw"})]));
            ρσ_interpolate_kwargs.call(this, set_css, [toc_panel].concat([ρσ_desugar_kwargs({flex_grow: "10"})]));
            container.appendChild(toc_panel);
            search_button = ρσ_interpolate_kwargs.call(E, E.a, [svgicon("search")].concat([ρσ_desugar_kwargs({class_: "calibre-icon-button", href: "javascript:void(0)", title: _("Search"), onmousedown: (function() {
                var ρσ_anonfunc = function (e) {
                    e.preventDefault();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["e"]},
                    __module__ : {value: "read_book.toc"}
                });
                return ρσ_anonfunc;
            })()})]));
            t = _("Search Table of Contents");
            search_bar = ρσ_interpolate_kwargs.call(this, create_search_bar, [do_search.bind(toc_panel_id), "search-book-toc"].concat([ρσ_desugar_kwargs({button: search_button, placeholder: t})]));
            ρσ_interpolate_kwargs.call(this, set_css, [search_bar].concat([ρσ_desugar_kwargs({flex_grow: "10", margin_right: "1em"})]));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [search_bar, search_button].concat([ρσ_desugar_kwargs({style: "margin: 1ex 1em; display: flex; align-items: center"})])));
            var ρσ_Iter8 = ρσ_Iterable(container.childNodes);
            for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                child = ρσ_Iter8[ρσ_Index8];
                child.style.flexShrink = "0";
            }
            toc_panel.style.flexGrow = "100";
            toc_panel.style.flexShrink = "1";
            toc_panel.style.overflow = "auto";
        };
        if (!create_toc_panel.__argnames__) Object.defineProperties(create_toc_panel, {
            __argnames__ : {value: ["book", "container", "onclick"]},
            __module__ : {value: "read_book.toc"}
        });

        function recalculate_toc_anchor_positions(tam, plam) {
            var name, am, anchors, pos_map, ρσ_unpack, i, anchor, anchor_funcs, current_map;
            name = current_spine_item().name;
            am = Object.create(null);
            anchors = [];
            pos_map = Object.create(null);
            var ρσ_Iter9 = ρσ_Iterable(enumerate(tam[(typeof name === "number" && name < 0) ? tam.length + name : name] || []));
            for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                ρσ_unpack = ρσ_Iter9[ρσ_Index9];
                i = ρσ_unpack[0];
                anchor = ρσ_unpack[1];
                am[ρσ_bound_index(anchor.id, am)] = position_for_anchor(anchor.frag);
                anchors.push(anchor.id);
                pos_map[ρσ_bound_index(anchor.id, pos_map)] = i;
            }
            anchor_funcs = get_boss().anchor_funcs;
            anchors.sort((function() {
                var ρσ_anonfunc = function (a, b) {
                    return anchor_funcs.cmp(am[(typeof a === "number" && a < 0) ? am.length + a : a], am[(typeof b === "number" && b < 0) ? am.length + b : b]) || pos_map[(typeof a === "number" && a < 0) ? pos_map.length + a : a] - pos_map[(typeof b === "number" && b < 0) ? pos_map.length + b : b];
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["a", "b"]},
                    __module__ : {value: "read_book.toc"}
                });
                return ρσ_anonfunc;
            })());
            current_map = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["layout_mode"] = current_layout_mode();
                ρσ_d["width"] = scroll_viewport.width();
                ρσ_d["height"] = scroll_viewport.height();
                ρσ_d["pos_map"] = am;
                ρσ_d["sorted_anchors"] = anchors;
                return ρσ_d;
            }).call(this);
            am = Object.create(null);
            anchors = [];
            pos_map = Object.create(null);
            if (plam) {
                var ρσ_Iter10 = ρσ_Iterable(enumerate(plam[(typeof name === "number" && name < 0) ? plam.length + name : name] || []));
                for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                    ρσ_unpack = ρσ_Iter10[ρσ_Index10];
                    i = ρσ_unpack[0];
                    anchor = ρσ_unpack[1];
                    am[ρσ_bound_index(anchor.id, am)] = position_for_anchor(anchor.frag, true);
                    anchors.push(anchor.id);
                    pos_map[ρσ_bound_index(anchor.id, pos_map)] = i;
                }
            }
            anchors.sort((function() {
                var ρσ_anonfunc = function (a, b) {
                    return anchor_funcs.cmp(am[(typeof a === "number" && a < 0) ? am.length + a : a], am[(typeof b === "number" && b < 0) ? am.length + b : b]) || pos_map[(typeof a === "number" && a < 0) ? pos_map.length + a : a] - pos_map[(typeof b === "number" && b < 0) ? pos_map.length + b : b];
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["a", "b"]},
                    __module__ : {value: "read_book.toc"}
                });
                return ρσ_anonfunc;
            })());
            current_map.page_list_pos_map = am;
            current_map.page_list_sorted_anchors = anchors;
            set_toc_anchor_map(current_map);
            return current_map;
        };
        if (!recalculate_toc_anchor_positions.__argnames__) Object.defineProperties(recalculate_toc_anchor_positions, {
            __argnames__ : {value: ["tam", "plam"]},
            __module__ : {value: "read_book.toc"}
        });

        function current_toc_anchor_map(tam, plam) {
            var current_map;
            current_map = toc_anchor_map();
            if (!((current_map && current_map.layout_mode === current_layout_mode() && current_map.width === scroll_viewport.width() && current_map.height === scroll_viewport.height()))) {
                current_map = recalculate_toc_anchor_positions(tam, plam);
            }
            return current_map;
        };
        if (!current_toc_anchor_map.__argnames__) Object.defineProperties(current_toc_anchor_map, {
            __argnames__ : {value: ["tam", "plam"]},
            __module__ : {value: "read_book.toc"}
        });

        function update_visible_toc_anchors(toc_anchor_map, page_list_anchor_map, recalculate) {
            var anchor_funcs, tam, before, after, visible_anchors, has_visible, pos, visibility, anchor_id, ans;
            if (recalculate) {
                recalculate_toc_anchor_positions(toc_anchor_map, page_list_anchor_map);
            }
            anchor_funcs = get_boss().anchor_funcs;
            tam = current_toc_anchor_map(toc_anchor_map, page_list_anchor_map);
            before = after = null;
            visible_anchors = Object.create(null);
            has_visible = false;
            var ρσ_Iter11 = ρσ_Iterable(tam.sorted_anchors);
            for (var ρσ_Index11 = 0; ρσ_Index11 < ρσ_Iter11.length; ρσ_Index11++) {
                anchor_id = ρσ_Iter11[ρσ_Index11];
                pos = (ρσ_expr_temp = tam.pos_map)[(typeof anchor_id === "number" && anchor_id < 0) ? ρσ_expr_temp.length + anchor_id : anchor_id];
                visibility = anchor_funcs.visibility(pos);
                if (visibility < 0) {
                    before = anchor_id;
                } else if (visibility === 0) {
                    has_visible = true;
                    visible_anchors[(typeof anchor_id === "number" && anchor_id < 0) ? visible_anchors.length + anchor_id : anchor_id] = true;
                } else if (visibility > 0) {
                    after = anchor_id;
                    break;
                }
            }
            ans = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["visible_anchors"] = visible_anchors;
                ρσ_d["has_visible"] = has_visible;
                ρσ_d["before"] = before;
                ρσ_d["after"] = after;
                ρσ_d["sorted_anchors"] = tam.sorted_anchors;
                return ρσ_d;
            }).call(this);
            before = after = null;
            visible_anchors = Object.create(null);
            has_visible = false;
            var ρσ_Iter12 = ρσ_Iterable(tam.page_list_sorted_anchors);
            for (var ρσ_Index12 = 0; ρσ_Index12 < ρσ_Iter12.length; ρσ_Index12++) {
                anchor_id = ρσ_Iter12[ρσ_Index12];
                pos = (ρσ_expr_temp = tam.page_list_pos_map)[(typeof anchor_id === "number" && anchor_id < 0) ? ρσ_expr_temp.length + anchor_id : anchor_id];
                visibility = anchor_funcs.visibility(pos);
                if (visibility < 0) {
                    before = anchor_id;
                } else if (visibility === 0) {
                    has_visible = true;
                    visible_anchors[(typeof anchor_id === "number" && anchor_id < 0) ? visible_anchors.length + anchor_id : anchor_id] = true;
                } else if (visibility > 0) {
                    after = anchor_id;
                    break;
                }
            }
            ans.page_list = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["visible_anchors"] = visible_anchors;
                ρσ_d["has_visible"] = has_visible;
                ρσ_d["before"] = before;
                ρσ_d["after"] = after;
                ρσ_d["sorted_anchors"] = tam.page_list_sorted_anchors;
                return ρσ_d;
            }).call(this);
            return ans;
        };
        if (!update_visible_toc_anchors.__argnames__) Object.defineProperties(update_visible_toc_anchors, {
            __argnames__ : {value: ["toc_anchor_map", "page_list_anchor_map", "recalculate"]},
            __module__ : {value: "read_book.toc"}
        });

        function find_anchor_before_range(r, toc_anchor_map, page_list_anchor_map) {
            var name, prev_anchor, tam, anchors, amap, x, anchor, is_before, elem, q, anchor_id;
            name = current_spine_item().name;
            prev_anchor = null;
            tam = current_toc_anchor_map(toc_anchor_map, page_list_anchor_map);
            anchors = toc_anchor_map[(typeof name === "number" && name < 0) ? toc_anchor_map.length + name : name];
            if (anchors) {
                amap = (function() {
                    var ρσ_Iter = ρσ_Iterable(anchors), ρσ_Result = Object.create(null), x;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        x = ρσ_Iter[ρσ_Index];
                        ρσ_Result[x.id] = (x);
                    }
                    return ρσ_Result;
                })();
                var ρσ_Iter13 = ρσ_Iterable(tam.sorted_anchors);
                for (var ρσ_Index13 = 0; ρσ_Index13 < ρσ_Iter13.length; ρσ_Index13++) {
                    anchor_id = ρσ_Iter13[ρσ_Index13];
                    anchor = amap[(typeof anchor_id === "number" && anchor_id < 0) ? amap.length + anchor_id : anchor_id];
                    is_before = true;
                    if (anchor.frag) {
                        elem = document.getElementById(anchor.frag);
                        if (elem) {
                            q = document.createRange();
                            q.selectNode(elem);
                            if (q.compareBoundaryPoints(window.Range.START_TO_START, r) > 0) {
                                is_before = false;
                            }
                        }
                    }
                    if (is_before) {
                        prev_anchor = anchor;
                    } else {
                        break;
                    }
                }
            }
            return prev_anchor;
        };
        if (!find_anchor_before_range.__argnames__) Object.defineProperties(find_anchor_before_range, {
            __argnames__ : {value: ["r", "toc_anchor_map", "page_list_anchor_map"]},
            __module__ : {value: "read_book.toc"}
        });

        ρσ_modules["read_book.toc"].update_visible_toc_nodes = update_visible_toc_nodes;
        ρσ_modules["read_book.toc"].iter_toc_descendants = iter_toc_descendants;
        ρσ_modules["read_book.toc"].get_toc_nodes_bordering_spine_item = get_toc_nodes_bordering_spine_item;
        ρσ_modules["read_book.toc"].get_border_nodes = get_border_nodes;
        ρσ_modules["read_book.toc"].family_for_toc_node = family_for_toc_node;
        ρσ_modules["read_book.toc"].get_page_list_id_map = get_page_list_id_map;
        ρσ_modules["read_book.toc"].get_page_list_before = get_page_list_before;
        ρσ_modules["read_book.toc"].get_current_pagelist_items = get_current_pagelist_items;
        ρσ_modules["read_book.toc"].get_current_toc_nodes = get_current_toc_nodes;
        ρσ_modules["read_book.toc"].get_highlighted_toc_nodes = get_highlighted_toc_nodes;
        ρσ_modules["read_book.toc"].get_toc_maps = get_toc_maps;
        ρσ_modules["read_book.toc"].get_book_mark_title = get_book_mark_title;
        ρσ_modules["read_book.toc"].create_toc_tree = create_toc_tree;
        ρσ_modules["read_book.toc"].do_search = do_search;
        ρσ_modules["read_book.toc"].create_toc_panel = create_toc_panel;
        ρσ_modules["read_book.toc"].recalculate_toc_anchor_positions = recalculate_toc_anchor_positions;
        ρσ_modules["read_book.toc"].current_toc_anchor_map = current_toc_anchor_map;
        ρσ_modules["read_book.toc"].update_visible_toc_anchors = update_visible_toc_anchors;
        ρσ_modules["read_book.toc"].find_anchor_before_range = find_anchor_before_range;
    })();

    (function(){
        var __name__ = "read_book.iframe";
        var FORCE_FLOW_MODE, CALIBRE_VERSION, ONSCROLL_DEBOUNCE_TIME, ERS_SUPPORTED_FEATURES, drag_mouse_position;
        var traceback = ρσ_modules.traceback;

        var first_visible_word = ρσ_modules.select.first_visible_word;
        var is_start_closer_to_point = ρσ_modules.select.is_start_closer_to_point;
        var move_end_of_selection = ρσ_modules.select.move_end_of_selection;
        var selection_extents = ρσ_modules.select.selection_extents;
        var word_at_point = ρσ_modules.select.word_at_point;

        var fix_fullscreen_svg_images = ρσ_modules.fs_images.fix_fullscreen_svg_images;

        var IframeClient = ρσ_modules.iframe_comm.IframeClient;

        var all_annots_in_selection = ρσ_modules.range_utils.all_annots_in_selection;
        var highlight_associated_with_selection = ρσ_modules.range_utils.highlight_associated_with_selection;
        var last_span_for_crw = ρσ_modules.range_utils.last_span_for_crw;
        var reset_highlight_counter = ρσ_modules.range_utils.reset_highlight_counter;
        var select_crw = ρσ_modules.range_utils.select_crw;
        var unwrap_all_crw = ρσ_modules.range_utils.unwrap_all_crw;
        var unwrap_crw = ρσ_modules.range_utils.unwrap_crw;
        var wrap_text_in_range = ρσ_modules.range_utils.wrap_text_in_range;

        var ensure_page_list_target_is_displayed = ρσ_modules["read_book.anchor_visibility"].ensure_page_list_target_is_displayed;
        var invalidate_anchor_position_cache = ρσ_modules["read_book.anchor_visibility"].invalidate_anchor_position_cache;

        var cfi_for_selection = ρσ_modules["read_book.cfi"].cfi_for_selection;
        var range_from_cfi = ρσ_modules["read_book.cfi"].range_from_cfi;

        var get_elements = ρσ_modules["read_book.extract"].get_elements;

        var reset_find_caches = ρσ_modules["read_book.find"].reset_find_caches;
        var select_search_result = ρσ_modules["read_book.find"].select_search_result;
        var select_tts_mark = ρσ_modules["read_book.find"].select_tts_mark;
        var tts_data = ρσ_modules["read_book.find"].tts_data;

        var flow_anchor_funcs = ρσ_modules["read_book.flow_mode"].anchor_funcs;

        var flow_auto_scroll_action = ρσ_modules["read_book.flow_mode"].auto_scroll_action;

        var cancel_drag_scroll_flow = ρσ_modules["read_book.flow_mode"].cancel_drag_scroll;

        var ensure_selection_boundary_visible_flow = ρσ_modules["read_book.flow_mode"].ensure_selection_boundary_visible;

        var ensure_selection_visible = ρσ_modules["read_book.flow_mode"].ensure_selection_visible;
        var flow_onwheel = ρσ_modules["read_book.flow_mode"].flow_onwheel;
        var flow_to_scroll_fraction = ρσ_modules["read_book.flow_mode"].flow_to_scroll_fraction;

        var flow_handle_gesture = ρσ_modules["read_book.flow_mode"].handle_gesture;

        var flow_handle_shortcut = ρσ_modules["read_book.flow_mode"].handle_shortcut;

        var flow_jump_to_cfi = ρσ_modules["read_book.flow_mode"].jump_to_cfi;

        var flow_layout = ρσ_modules["read_book.flow_mode"].layout;

        var flow_scroll_by_page = ρσ_modules["read_book.flow_mode"].scroll_by_page;

        var flow_annotation_scroll = ρσ_modules["read_book.flow_mode"].scroll_to_extend_annotation;

        var start_drag_scroll_flow = ρσ_modules["read_book.flow_mode"].start_drag_scroll;

        var is_footnote_link = ρσ_modules["read_book.footnotes"].is_footnote_link;

        var action_for_gesture = ρσ_modules["read_book.gestures"].action_for_gesture;

        var annot_id_uuid_map = ρσ_modules["read_book.globals"].annot_id_uuid_map;
        var clear_annot_id_uuid_map = ρσ_modules["read_book.globals"].clear_annot_id_uuid_map;
        var current_book = ρσ_modules["read_book.globals"].current_book;
        var current_layout_mode = ρσ_modules["read_book.globals"].current_layout_mode;
        var current_spine_item = ρσ_modules["read_book.globals"].current_spine_item;
        var runtime = ρσ_modules["read_book.globals"].runtime;
        var set_boss = ρσ_modules["read_book.globals"].set_boss;
        var set_current_spine_item = ρσ_modules["read_book.globals"].set_current_spine_item;
        var set_layout_mode = ρσ_modules["read_book.globals"].set_layout_mode;
        var set_toc_anchor_map = ρσ_modules["read_book.globals"].set_toc_anchor_map;

        var highlight_style_as_css = ρσ_modules["read_book.highlights"].highlight_style_as_css;

        var apply_prefix_to_hints = ρσ_modules["read_book.hints"].apply_prefix_to_hints;
        var hint_visible_links = ρσ_modules["read_book.hints"].hint_visible_links;
        var unhint_links = ρσ_modules["read_book.hints"].unhint_links;

        var apply_mathjax = ρσ_modules["read_book.mathjax"].apply_mathjax;

        var paged_anchor_funcs = ρσ_modules["read_book.paged_mode"].anchor_funcs;

        var paged_auto_scroll_action = ρσ_modules["read_book.paged_mode"].auto_scroll_action;

        var calc_columns_per_screen = ρσ_modules["read_book.paged_mode"].calc_columns_per_screen;
        var current_cfi = ρσ_modules["read_book.paged_mode"].current_cfi;
        var get_columns_per_screen_data = ρσ_modules["read_book.paged_mode"].get_columns_per_screen_data;
        var page_counts = ρσ_modules["read_book.paged_mode"].page_counts;
        var progress_frac = ρσ_modules["read_book.paged_mode"].progress_frac;
        var reset_paged_mode_globals = ρσ_modules["read_book.paged_mode"].reset_paged_mode_globals;
        var scroll_to_elem = ρσ_modules["read_book.paged_mode"].scroll_to_elem;
        var snap_to_selection = ρσ_modules["read_book.paged_mode"].snap_to_selection;
        var will_columns_per_screen_change = ρσ_modules["read_book.paged_mode"].will_columns_per_screen_change;

        var cancel_drag_scroll_paged = ρσ_modules["read_book.paged_mode"].cancel_drag_scroll;

        var ensure_selection_boundary_visible_paged = ρσ_modules["read_book.paged_mode"].ensure_selection_boundary_visible;

        var paged_handle_gesture = ρσ_modules["read_book.paged_mode"].handle_gesture;

        var paged_handle_shortcut = ρσ_modules["read_book.paged_mode"].handle_shortcut;

        var paged_jump_to_cfi = ρσ_modules["read_book.paged_mode"].jump_to_cfi;

        var paged_layout = ρσ_modules["read_book.paged_mode"].layout;

        var paged_onwheel = ρσ_modules["read_book.paged_mode"].onwheel;

        var paged_prepare_for_resize = ρσ_modules["read_book.paged_mode"].prepare_for_resize;

        var paged_resize_done = ρσ_modules["read_book.paged_mode"].resize_done;

        var paged_scroll_by_page = ρσ_modules["read_book.paged_mode"].scroll_by_page;

        var paged_annotation_scroll = ρσ_modules["read_book.paged_mode"].scroll_to_extend_annotation;

        var paged_scroll_to_fraction = ρσ_modules["read_book.paged_mode"].scroll_to_fraction;

        var start_drag_scroll_paged = ρσ_modules["read_book.paged_mode"].start_drag_scroll;

        var elem_for_ref = ρσ_modules["read_book.referencing"].elem_for_ref;
        var end_reference_mode = ρσ_modules["read_book.referencing"].end_reference_mode;
        var start_reference_mode = ρσ_modules["read_book.referencing"].start_reference_mode;

        var finalize_resources = ρσ_modules["read_book.resources"].finalize_resources;
        var unserialize_html = ρσ_modules["read_book.resources"].unserialize_html;

        var apply_colors = ρσ_modules["read_book.settings"].apply_colors;
        var apply_font_size = ρσ_modules["read_book.settings"].apply_font_size;
        var apply_settings = ρσ_modules["read_book.settings"].apply_settings;
        var apply_stylesheet = ρσ_modules["read_book.settings"].apply_stylesheet;
        var opts = ρσ_modules["read_book.settings"].opts;
        var set_color_scheme_class = ρσ_modules["read_book.settings"].set_color_scheme_class;
        var set_selection_style = ρσ_modules["read_book.settings"].set_selection_style;
        var update_settings = ρσ_modules["read_book.settings"].update_settings;

        var create_shortcut_map = ρσ_modules["read_book.shortcuts"].create_shortcut_map;
        var keyevent_as_shortcut = ρσ_modules["read_book.shortcuts"].keyevent_as_shortcut;
        var shortcut_for_key_event = ρσ_modules["read_book.shortcuts"].shortcut_for_key_event;

        var flatten_smil_map = ρσ_modules["read_book.smil"].flatten_smil_map;
        var mark_smil_element = ρσ_modules["read_book.smil"].mark_smil_element;
        var smil_element_at = ρσ_modules["read_book.smil"].smil_element_at;

        var find_anchor_before_range = ρσ_modules["read_book.toc"].find_anchor_before_range;
        var update_visible_toc_anchors = ρσ_modules["read_book.toc"].update_visible_toc_anchors;

        var create_touch_handlers = ρσ_modules["read_book.touch"].create_handlers;

        var reset_touch_handlers = ρσ_modules["read_book.touch"].reset_handlers;

        var scroll_viewport = ρσ_modules["read_book.viewport"].scroll_viewport;

        var debounce = ρσ_modules.utils.debounce;
        var is_ios = ρσ_modules.utils.is_ios;

        FORCE_FLOW_MODE = false;
        CALIBRE_VERSION = "9.10.0";
        ONSCROLL_DEBOUNCE_TIME = 1e3;
        ERS_SUPPORTED_FEATURES = (function(){
            var s = ρσ_set();
            s.jsset.add("dom-manipulation");
            s.jsset.add("layout-changes");
            s.jsset.add("touch-events");
            s.jsset.add("mouse-events");
            s.jsset.add("keyboard-events");
            s.jsset.add("spine-scripting");
            return s;
        })();
        function layout_style() {
            return (current_layout_mode() === "flow") ? "scrolling" : "paginated";
        };
        if (!layout_style.__module__) Object.defineProperties(layout_style, {
            __module__ : {value: "read_book.iframe"}
        });

        drag_mouse_position = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["x"] = null;
            ρσ_d["y"] = null;
            return ρσ_d;
        }).call(this);
        function cancel_drag_scroll() {
            cancel_drag_scroll_flow();
            cancel_drag_scroll_paged();
        };
        if (!cancel_drag_scroll.__module__) Object.defineProperties(cancel_drag_scroll, {
            __module__ : {value: "read_book.iframe"}
        });

        function EPUBReadingSystem() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            EPUBReadingSystem.prototype.__bind_methods__.call(this);
            EPUBReadingSystem.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(EPUBReadingSystem.prototype, "__bind_methods__", {value: function () {
            this.hasFeature = EPUBReadingSystem.prototype.hasFeature.bind(this);
            this.__repr__ = EPUBReadingSystem.prototype.__repr__.bind(this);
            this.__str__ = EPUBReadingSystem.prototype.__str__.bind(this);
        }});
        Object.defineProperties(EPUBReadingSystem.prototype,  {
            "name": {
                "enumerable": true, 
                "get": function name() {
                    var self = this;
                    return "calibre";
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "version": {
                "enumerable": true, 
                "get": function version() {
                    var self = this;
                    return CALIBRE_VERSION;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "layoutStyle": {
                "enumerable": true, 
                "get": function layoutStyle() {
                    var self = this;
                    return layout_style();
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        EPUBReadingSystem.prototype.__init__ = function __init__ () {
                    };
        EPUBReadingSystem.prototype.hasFeature = function hasFeature(feature, version) {
            var self = this;
            return ρσ_in(feature, ERS_SUPPORTED_FEATURES);
        };
        if (!EPUBReadingSystem.prototype.hasFeature.__argnames__) Object.defineProperties(EPUBReadingSystem.prototype.hasFeature, {
            __argnames__ : {value: ["feature", "version"]},
            __module__ : {value: "read_book.iframe"}
        });
        EPUBReadingSystem.prototype.__repr__ = function __repr__() {
            var self = this;
            return "{name:" + ρσ_str.format("{}", self.name) + ", version:" + ρσ_str.format("{}", self.version) + ", layoutStyle:" + ρσ_str.format("{}", self.layoutStyle) + "}";
        };
        if (!EPUBReadingSystem.prototype.__repr__.__module__) Object.defineProperties(EPUBReadingSystem.prototype.__repr__, {
            __module__ : {value: "read_book.iframe"}
        });
        EPUBReadingSystem.prototype.__str__ = function __str__() {
            var self = this;
            return self.__repr__();
        };
        if (!EPUBReadingSystem.prototype.__str__.__module__) Object.defineProperties(EPUBReadingSystem.prototype.__str__, {
            __module__ : {value: "read_book.iframe"}
        });
        Object.defineProperty(EPUBReadingSystem.prototype, "__bases__", {value: []});
        
        
        

        function FullBookSearch() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            FullBookSearch.prototype.__init__.apply(this, arguments);
        }
        FullBookSearch.prototype.__init__ = function __init__() {
            var self = this;
            var start_spine_index;
            start_spine_index = ρσ_exists.d(current_spine_item()).index;
            if (!(typeof start_spine_index !== "undefined" && start_spine_index !== null)) {
                start_spine_index = -1;
            }
            self.start_spine_index = start_spine_index;
            self.progress_frac_at_start = progress_frac();
            self.first_result_shown = false;
        };
        if (!FullBookSearch.prototype.__init__.__module__) Object.defineProperties(FullBookSearch.prototype.__init__, {
            __module__ : {value: "read_book.iframe"}
        });
        FullBookSearch.__argnames__ = FullBookSearch.prototype.__init__.__argnames__;
        FullBookSearch.__handles_kwarg_interpolation__ = FullBookSearch.prototype.__init__.__handles_kwarg_interpolation__;
        FullBookSearch.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        FullBookSearch.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(FullBookSearch.prototype, "__bases__", {value: []});

        function IframeBoss() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            IframeBoss.prototype.__bind_methods__.call(this);
            IframeBoss.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(IframeBoss.prototype, "__bind_methods__", {value: function () {
            this.on_overlay_visibility_changed = IframeBoss.prototype.on_overlay_visibility_changed.bind(this);
            this.modify_selection = IframeBoss.prototype.modify_selection.bind(this);
            this.initialize = IframeBoss.prototype.initialize.bind(this);
            this.onerror = IframeBoss.prototype.onerror.bind(this);
            this.display = IframeBoss.prototype.display.bind(this);
            this.on_scroll_to_frac = IframeBoss.prototype.on_scroll_to_frac.bind(this);
            this.toggle_autoscroll = IframeBoss.prototype.toggle_autoscroll.bind(this);
            this.handle_gesture = IframeBoss.prototype.handle_gesture.bind(this);
            this.handle_long_tap = IframeBoss.prototype.handle_long_tap.bind(this);
            this.gesture_from_margin = IframeBoss.prototype.gesture_from_margin.bind(this);
            this.native_gesture = IframeBoss.prototype.native_gesture.bind(this);
            this.fake_wheel_event = IframeBoss.prototype.fake_wheel_event.bind(this);
            this.report_human_scroll = IframeBoss.prototype.report_human_scroll.bind(this);
            this.on_scroll_to_anchor = IframeBoss.prototype.on_scroll_to_anchor.bind(this);
            this.on_next_screen = IframeBoss.prototype.on_next_screen.bind(this);
            this.change_font_size = IframeBoss.prototype.change_font_size.bind(this);
            this.viewer_font_size_changed = IframeBoss.prototype.viewer_font_size_changed.bind(this);
            this.change_number_of_columns = IframeBoss.prototype.change_number_of_columns.bind(this);
            this.relayout_on_font_size_change = IframeBoss.prototype.relayout_on_font_size_change.bind(this);
            this.number_of_columns_changed = IframeBoss.prototype.number_of_columns_changed.bind(this);
            this.change_scroll_speed = IframeBoss.prototype.change_scroll_speed.bind(this);
            this.change_stylesheet = IframeBoss.prototype.change_stylesheet.bind(this);
            this.change_color_scheme = IframeBoss.prototype.change_color_scheme.bind(this);
            this.content_loaded = IframeBoss.prototype.content_loaded.bind(this);
            this.content_loaded_stage2 = IframeBoss.prototype.content_loaded_stage2.bind(this);
            this.calculate_progress_frac = IframeBoss.prototype.calculate_progress_frac.bind(this);
            this.get_current_cfi = IframeBoss.prototype.get_current_cfi.bind(this);
            this.update_cfi = IframeBoss.prototype.update_cfi.bind(this);
            this.update_toc_position = IframeBoss.prototype.update_toc_position.bind(this);
            this.onscroll = IframeBoss.prototype.onscroll.bind(this);
            this.no_latency_onscroll = IframeBoss.prototype.no_latency_onscroll.bind(this);
            this.onresize = IframeBoss.prototype.onresize.bind(this);
            this.onselectionchange = IframeBoss.prototype.onselectionchange.bind(this);
            this.onresize_stage2 = IframeBoss.prototype.onresize_stage2.bind(this);
            this.received_window_size = IframeBoss.prototype.received_window_size.bind(this);
            this.onwheel = IframeBoss.prototype.onwheel.bind(this);
            this.onmousemove = IframeBoss.prototype.onmousemove.bind(this);
            this.onmouseup = IframeBoss.prototype.onmouseup.bind(this);
            this.ondoubleclick = IframeBoss.prototype.ondoubleclick.bind(this);
            this.onkeydown = IframeBoss.prototype.onkeydown.bind(this);
            this.on_handle_navigation_shortcut = IframeBoss.prototype.on_handle_navigation_shortcut.bind(this);
            this.oncontextmenu = IframeBoss.prototype.oncontextmenu.bind(this);
            this.send_message = IframeBoss.prototype.send_message.bind(this);
            this.connect_links = IframeBoss.prototype.connect_links.bind(this);
            this.listen_for_image_double_clicks = IframeBoss.prototype.listen_for_image_double_clicks.bind(this);
            this.image_double_clicked = IframeBoss.prototype.image_double_clicked.bind(this);
            this.link_activated = IframeBoss.prototype.link_activated.bind(this);
            this.activate_link = IframeBoss.prototype.activate_link.bind(this);
            this.on_fake_popup_activation = IframeBoss.prototype.on_fake_popup_activation.bind(this);
            this.scroll_to_anchor = IframeBoss.prototype.scroll_to_anchor.bind(this);
            this.scroll_to_pagelist_ref = IframeBoss.prototype.scroll_to_pagelist_ref.bind(this);
            this.scroll_to_ref = IframeBoss.prototype.scroll_to_ref.bind(this);
            this.on_scroll_to_ref = IframeBoss.prototype.on_scroll_to_ref.bind(this);
            this.show_search_result = IframeBoss.prototype.show_search_result.bind(this);
            this.add_search_result_to_history_stack = IframeBoss.prototype.add_search_result_to_history_stack.bind(this);
            this.ensure_search_result_visible = IframeBoss.prototype.ensure_search_result_visible.bind(this);
            this.set_reference_mode = IframeBoss.prototype.set_reference_mode.bind(this);
            this.apply_highlight = IframeBoss.prototype.apply_highlight.bind(this);
            this.annotations_msg_received = IframeBoss.prototype.annotations_msg_received.bind(this);
            this.apply_highlights_on_load = IframeBoss.prototype.apply_highlights_on_load.bind(this);
            this.replace_highlights = IframeBoss.prototype.replace_highlights.bind(this);
            this.add_highlight_listeners = IframeBoss.prototype.add_highlight_listeners.bind(this);
            this.highlight_wrapper_dblclicked = IframeBoss.prototype.highlight_wrapper_dblclicked.bind(this);
            this.copy_selection = IframeBoss.prototype.copy_selection.bind(this);
            this.tts_msg_received = IframeBoss.prototype.tts_msg_received.bind(this);
            this.mark_word_being_spoken = IframeBoss.prototype.mark_word_being_spoken.bind(this);
            this.audio_ebook_msg_received = IframeBoss.prototype.audio_ebook_msg_received.bind(this);
            this.hints_msg_received = IframeBoss.prototype.hints_msg_received.bind(this);
            this.hint_animation_ended = IframeBoss.prototype.hint_animation_ended.bind(this);
        }});
        IframeBoss.prototype.__init__ = function __init__() {
            var self = this;
            var handlers;
            window.navigator.epubReadingSystem = new EPUBReadingSystem;
            self.last_cfi = null;
            self.last_search_at = -1001;
            self.reference_mode_enabled = false;
            self.replace_history_on_next_cfi_update = true;
            self.blob_url_map = Object.create(null);
            self.content_ready = false;
            self.last_window_width = self.last_window_height = -1;
            self.forward_keypresses = false;
            self.full_book_search_in_progress = null;
            set_boss(self);
            handlers = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["change_color_scheme"] = self.change_color_scheme;
                ρσ_d["change_font_size"] = self.change_font_size;
                ρσ_d["viewer_font_size_changed"] = self.viewer_font_size_changed;
                ρσ_d["change_number_of_columns"] = self.change_number_of_columns;
                ρσ_d["number_of_columns_changed"] = self.number_of_columns_changed;
                ρσ_d["change_scroll_speed"] = self.change_scroll_speed;
                ρσ_d["display"] = self.display;
                ρσ_d["gesture_from_margin"] = self.gesture_from_margin;
                ρσ_d["native_gesture"] = self.native_gesture;
                ρσ_d["get_current_cfi"] = self.get_current_cfi;
                ρσ_d["initialize"] = self.initialize;
                ρσ_d["modify_selection"] = self.modify_selection;
                ρσ_d["next_screen"] = self.on_next_screen;
                ρσ_d["scroll_to_anchor"] = self.on_scroll_to_anchor;
                ρσ_d["scroll_to_frac"] = self.on_scroll_to_frac;
                ρσ_d["scroll_to_ref"] = self.on_scroll_to_ref;
                ρσ_d["fake_popup_activation"] = self.on_fake_popup_activation;
                ρσ_d["set_reference_mode"] = self.set_reference_mode;
                ρσ_d["toggle_autoscroll"] = self.toggle_autoscroll;
                ρσ_d["fake_wheel_event"] = self.fake_wheel_event;
                ρσ_d["window_size"] = self.received_window_size;
                ρσ_d["overlay_visibility_changed"] = self.on_overlay_visibility_changed;
                ρσ_d["show_search_result"] = self.show_search_result;
                ρσ_d["handle_navigation_shortcut"] = self.on_handle_navigation_shortcut;
                ρσ_d["annotations"] = self.annotations_msg_received;
                ρσ_d["tts"] = self.tts_msg_received;
                ρσ_d["audio-ebook"] = self.audio_ebook_msg_received;
                ρσ_d["hints"] = self.hints_msg_received;
                ρσ_d["copy_selection"] = self.copy_selection;
                ρσ_d["replace_highlights"] = self.replace_highlights;
                ρσ_d["clear_selection"] = (function() {
                    var ρσ_anonfunc = function () {
                        window.getSelection().removeAllRanges();
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.iframe"}
                    });
                    return ρσ_anonfunc;
                })();
                return ρσ_d;
            }).call(this);
            self.comm = new IframeClient(handlers, "main-iframe");
            self.last_window_ypos = 0;
            self.length_before = null;
        };
        if (!IframeBoss.prototype.__init__.__module__) Object.defineProperties(IframeBoss.prototype.__init__, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.__argnames__ = IframeBoss.prototype.__init__.__argnames__;
        IframeBoss.__handles_kwarg_interpolation__ = IframeBoss.prototype.__init__.__handles_kwarg_interpolation__;
        IframeBoss.prototype.on_overlay_visibility_changed = function on_overlay_visibility_changed(data) {
            var self = this;
            cancel_drag_scroll();
            if (data.visible) {
                self.forward_keypresses = true;
                if (self.auto_scroll_action) {
                    self.auto_scroll_active_before_overlay = self.auto_scroll_action("is_active");
                    self.auto_scroll_action("stop");
                }
            } else {
                self.forward_keypresses = false;
                if (self.auto_scroll_active_before_overlay) {
                    self.auto_scroll_active_before_overlay = undefined;
                    self.auto_scroll_action("start");
                }
            }
        };
        if (!IframeBoss.prototype.on_overlay_visibility_changed.__argnames__) Object.defineProperties(IframeBoss.prototype.on_overlay_visibility_changed, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.modify_selection = function modify_selection(data) {
            var self = this;
            var sel, use_end, r;
            sel = window.getSelection();
            use_end = false;
            if (data.granularity === "all") {
                r = document.createRange();
                r.selectNode(document.body);
                sel.removeAllRanges();
                sel.addRange(r);
            } else {
                use_end = data.direction === "forward" || data.direction === "right";
                try {
                    sel.modify("extend", data.direction, data.granularity);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        if (data.granularity === "paragraph") {
                            sel.modify("extend", data.direction, "line");
                        }
                    } 
                }
            }
            self.ensure_selection_boundary_visible(use_end);
        };
        if (!IframeBoss.prototype.modify_selection.__argnames__) Object.defineProperties(IframeBoss.prototype.modify_selection, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.initialize = function initialize(data) {
            var self = this;
            scroll_viewport.update_window_size(data.width, data.height);
            window.addEventListener("error", self.onerror);
            window.addEventListener("scroll", debounce(self.onscroll, ONSCROLL_DEBOUNCE_TIME));
            window.addEventListener("scroll", self.no_latency_onscroll);
            window.addEventListener("resize", debounce(self.onresize, 500));
            window.addEventListener("wheel", self.onwheel, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            window.addEventListener("keydown", self.onkeydown, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            window.addEventListener("mousemove", self.onmousemove, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = true;
                return ρσ_d;
            }).call(this));
            window.addEventListener("mouseup", self.onmouseup, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = true;
                return ρσ_d;
            }).call(this));
            window.addEventListener("dblclick", self.ondoubleclick, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = true;
                return ρσ_d;
            }).call(this));
            document.documentElement.addEventListener("contextmenu", self.oncontextmenu, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            document.addEventListener("selectionchange", self.onselectionchange);
            self.color_scheme = data.color_scheme;
            create_touch_handlers();
        };
        if (!IframeBoss.prototype.initialize.__argnames__) Object.defineProperties(IframeBoss.prototype.initialize, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.onerror = function onerror(evt) {
            var self = this;
            var msg, script_url, line_number, column_number, error_object, is_internal_error, fname, details;
            msg = evt.message;
            script_url = evt.filename;
            line_number = evt.lineno;
            column_number = evt.colno;
            error_object = evt.error;
            [evt.stopPropagation(), evt.preventDefault()];
            if (error_object === null) {
                console.log("Unhandled error from external javascript, ignoring: " + ρσ_str.format("{}", msg) + " " + ρσ_str.format("{}", script_url) + " " + ρσ_str.format("{}", line_number) + "");
                return;
            }
            is_internal_error = ρσ_in(script_url, ["about:srcdoc", "userscript:viewer.js"]);
            if (is_internal_error) {
                console.log("" + ρσ_str.format("{}", script_url) + ": " + ρσ_str.format("{}", error_object) + "");
                try {
                    fname = (ρσ_expr_temp = script_url.rpartition("/"))[ρσ_expr_temp.length-1] || script_url;
                    msg = msg + "<br><span style=\"font-size:smaller\">" + "Error at {}:{}:{}".format(fname, line_number, column_number || "") + "</span>";
                    details = (error_object) ? traceback.format_exception(error_object).join("") : "";
                    if (details) {
                        console.log(details);
                    }
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["error"].concat([ρσ_desugar_kwargs({errkey: "unhandled-error", details: details, msg: msg})]));
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        console.log("There was an error in the iframe unhandled exception handler");
                    } 
                }
            } else {
                (console.error || console.log)("There was an error in the JavaScript from within the book");
            }
        };
        if (!IframeBoss.prototype.onerror.__argnames__) Object.defineProperties(IframeBoss.prototype.onerror, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.display = function display(data) {
            var self = this;
            var ρσ_unpack, spine, index, name, root_data;
            cancel_drag_scroll();
            drag_mouse_position.x = drag_mouse_position.y = null;
            self.length_before = null;
            self.content_ready = false;
            clear_annot_id_uuid_map();
            reset_highlight_counter();
            set_toc_anchor_map();
            self.replace_history_on_next_cfi_update = true;
            self.book = current_book.book = data.book;
            self.smil_map = data.smil_map;
            ρσ_unpack = flatten_smil_map(self.smil_map);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            self.smil_anchor_map = ρσ_unpack[0];
            self.smil_par_list = ρσ_unpack[1];
            self.link_attr = "data-" + self.book.manifest.link_uid;
            self.reference_mode_enabled = data.reference_mode_enabled;
            self.is_titlepage = data.is_titlepage;
            spine = self.book.manifest.spine;
            index = spine.indexOf(data.name);
            reset_paged_mode_globals();
            set_layout_mode((FORCE_FLOW_MODE) ? "flow" : data.settings.read_mode);
            if (current_layout_mode() === "flow") {
                self.do_layout = flow_layout;
                self.handle_wheel = flow_onwheel;
                self.handle_navigation_shortcut = flow_handle_shortcut;
                self._handle_gesture = flow_handle_gesture;
                self.to_scroll_fraction = flow_to_scroll_fraction;
                self.jump_to_cfi = flow_jump_to_cfi;
                self.anchor_funcs = flow_anchor_funcs;
                self.auto_scroll_action = flow_auto_scroll_action;
                self.scroll_to_extend_annotation = flow_annotation_scroll;
                self.ensure_selection_visible = ensure_selection_visible;
                self.ensure_selection_boundary_visible = ensure_selection_boundary_visible_flow;
                self.start_drag_scroll = start_drag_scroll_flow;
                paged_auto_scroll_action("stop");
            } else {
                self.do_layout = paged_layout;
                self.handle_wheel = paged_onwheel;
                self.handle_navigation_shortcut = paged_handle_shortcut;
                self.to_scroll_fraction = paged_scroll_to_fraction;
                self.jump_to_cfi = paged_jump_to_cfi;
                self._handle_gesture = paged_handle_gesture;
                self.anchor_funcs = paged_anchor_funcs;
                self.auto_scroll_action = paged_auto_scroll_action;
                self.scroll_to_extend_annotation = paged_annotation_scroll;
                self.ensure_selection_visible = snap_to_selection;
                self.ensure_selection_boundary_visible = ensure_selection_boundary_visible_paged;
                self.start_drag_scroll = start_drag_scroll_paged;
                flow_auto_scroll_action("stop");
            }
            update_settings(data.settings);
            self.keyboard_shortcut_map = create_shortcut_map(data.settings.keyboard_shortcuts);
            set_current_spine_item((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["name"] = data.name;
                ρσ_d["is_first"] = index === 0;
                ρσ_d["is_last"] = index === spine.length - 1;
                ρσ_d["index"] = index;
                ρσ_d["initial_position"] = data.initial_position;
                return ρσ_d;
            }).call(this));
            self.last_cfi = null;
            var ρσ_Iter0 = ρσ_Iterable(self.blob_url_map);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                name = ρσ_Iter0[ρσ_Index0];
                window.URL.revokeObjectURL((ρσ_expr_temp = self.blob_url_map)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]);
            }
            document.body.style.removeProperty("font-family");
            ρσ_unpack = finalize_resources(self.book, data.name, data.resource_data);
ρσ_unpack = ρσ_unpack_asarray(3, ρσ_unpack);
            root_data = ρσ_unpack[0];
            self.mathjax = ρσ_unpack[1];
            self.blob_url_map = ρσ_unpack[2];
            self.highlights_to_apply = data.highlights;
            unserialize_html(root_data, self.content_loaded, null, data.name);
        };
        if (!IframeBoss.prototype.display.__argnames__) Object.defineProperties(IframeBoss.prototype.display, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.on_scroll_to_frac = function on_scroll_to_frac(data) {
            var self = this;
            self.to_scroll_fraction(data.frac, false);
        };
        if (!IframeBoss.prototype.on_scroll_to_frac.__argnames__) Object.defineProperties(IframeBoss.prototype.on_scroll_to_frac, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.toggle_autoscroll = function toggle_autoscroll() {
            var self = this;
            self.auto_scroll_action("toggle");
        };
        if (!IframeBoss.prototype.toggle_autoscroll.__module__) Object.defineProperties(IframeBoss.prototype.toggle_autoscroll, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.handle_gesture = function handle_gesture(gesture) {
            var self = this;
            gesture.resolved_action = action_for_gesture(gesture, current_layout_mode() === "flow");
            if (gesture.resolved_action === "show_chrome") {
                self.send_message("show_chrome");
            } else if (gesture.resolved_action === "decrease_font_size") {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["bump_font_size"].concat([ρσ_desugar_kwargs({increase: false})]));
            } else if (gesture.resolved_action === "increase_font_size") {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["bump_font_size"].concat([ρσ_desugar_kwargs({increase: true})]));
            } else if (gesture.resolved_action === "highlight_or_inspect") {
                self.handle_long_tap(gesture);
            } else {
                self._handle_gesture(gesture);
            }
        };
        if (!IframeBoss.prototype.handle_gesture.__argnames__) Object.defineProperties(IframeBoss.prototype.handle_gesture, {
            __argnames__ : {value: ["gesture"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.handle_long_tap = function handle_long_tap(gesture) {
            var self = this;
            var elements, r, s;
            elements = get_elements(gesture.viewport_x, gesture.viewport_y);
            if (elements.img) {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["view_image"].concat([ρσ_desugar_kwargs({calibre_src: elements.img})]));
                return;
            }
            if (elements.highlight) {
                select_crw(elements.crw);
                return;
            }
            r = word_at_point(gesture.viewport_x, gesture.viewport_y);
            if (r) {
                s = document.getSelection();
                s.removeAllRanges();
                s.addRange(r);
            }
        };
        if (!IframeBoss.prototype.handle_long_tap.__argnames__) Object.defineProperties(IframeBoss.prototype.handle_long_tap, {
            __argnames__ : {value: ["gesture"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.gesture_from_margin = function gesture_from_margin(data) {
            var self = this;
            self.handle_gesture(data.gesture);
        };
        if (!IframeBoss.prototype.gesture_from_margin.__argnames__) Object.defineProperties(IframeBoss.prototype.gesture_from_margin, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.native_gesture = function native_gesture(data) {
            var self = this;
            self.handle_gesture(data.gesture);
        };
        if (!IframeBoss.prototype.native_gesture.__argnames__) Object.defineProperties(IframeBoss.prototype.native_gesture, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.fake_wheel_event = function fake_wheel_event(data) {
            var self = this;
            self.onwheel(data.evt);
        };
        if (!IframeBoss.prototype.fake_wheel_event.__argnames__) Object.defineProperties(IframeBoss.prototype.fake_wheel_event, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.report_human_scroll = function report_human_scroll(scrolled_by_frac) {
            var self = this;
            ρσ_interpolate_kwargs.call(self, self.send_message, ["human_scroll"].concat([ρσ_desugar_kwargs({scrolled_by_frac: scrolled_by_frac || null})]));
        };
        if (!IframeBoss.prototype.report_human_scroll.__argnames__) Object.defineProperties(IframeBoss.prototype.report_human_scroll, {
            __argnames__ : {value: ["scrolled_by_frac"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.on_scroll_to_anchor = function on_scroll_to_anchor(data) {
            var self = this;
            var frag;
            frag = data.frag;
            if (frag) {
                self.replace_history_on_next_cfi_update = false;
                self.scroll_to_anchor(frag);
            } else {
                self.to_scroll_fraction(0, false);
            }
        };
        if (!IframeBoss.prototype.on_scroll_to_anchor.__argnames__) Object.defineProperties(IframeBoss.prototype.on_scroll_to_anchor, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.on_next_screen = function on_next_screen(data) {
            var self = this;
            var backwards;
            backwards = data.backwards;
            if (current_layout_mode() === "flow") {
                flow_scroll_by_page((backwards) ? -1 : 1, data.flip_if_rtl_page_progression);
            } else {
                paged_scroll_by_page(backwards, data.all_pages_on_screen, data.flip_if_rtl_page_progression);
            }
        };
        if (!IframeBoss.prototype.on_next_screen.__argnames__) Object.defineProperties(IframeBoss.prototype.on_next_screen, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.change_font_size = function change_font_size(data) {
            var self = this;
            if (ρσ_exists.n(data.base_font_size) && (data.base_font_size !== opts.base_font_size && (typeof data.base_font_size !== "object" || ρσ_not_equals(data.base_font_size, opts.base_font_size)))) {
                opts.base_font_size = data.base_font_size;
                apply_font_size();
                if (!runtime.is_standalone_viewer) {
                    self.relayout_on_font_size_change();
                }
            }
        };
        if (!IframeBoss.prototype.change_font_size.__argnames__) Object.defineProperties(IframeBoss.prototype.change_font_size, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.viewer_font_size_changed = function viewer_font_size_changed(data) {
            var self = this;
            self.relayout_on_font_size_change();
        };
        if (!IframeBoss.prototype.viewer_font_size_changed.__argnames__) Object.defineProperties(IframeBoss.prototype.viewer_font_size_changed, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.change_number_of_columns = function change_number_of_columns(data) {
            var self = this;
            var cdata, delta, new_val;
            if (current_layout_mode() === "flow") {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["error"].concat([ρσ_desugar_kwargs({errkey: "changing-columns-in-flow-mode"})]));
                return;
            }
            cdata = get_columns_per_screen_data();
            delta = int(data.delta);
            if (delta === 0) {
                new_val = 0;
            } else {
                new_val = max(1, cdata.cps + delta);
            }
            (ρσ_expr_temp = opts.columns_per_screen)[ρσ_bound_index(cdata.which, ρσ_expr_temp)] = new_val;
            self.relayout_on_font_size_change();
            ρσ_interpolate_kwargs.call(self, self.send_message, ["columns_per_screen_changed"].concat([ρσ_desugar_kwargs({which: cdata.which, cps: new_val})]));
        };
        if (!IframeBoss.prototype.change_number_of_columns.__argnames__) Object.defineProperties(IframeBoss.prototype.change_number_of_columns, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.relayout_on_font_size_change = function relayout_on_font_size_change() {
            var self = this;
            var cfi;
            if (current_layout_mode() !== "flow" && will_columns_per_screen_change()) {
                self.do_layout(self.is_titlepage);
                if (self.last_cfi) {
                    cfi = self.last_cfi.slice(len("epubcfi(/"), -1).partition("/")[2];
                    if (cfi) {
                        self.jump_to_cfi("/" + cfi);
                    }
                }
                self.update_cfi();
            }
            invalidate_anchor_position_cache();
            self.update_toc_position(true);
        };
        if (!IframeBoss.prototype.relayout_on_font_size_change.__module__) Object.defineProperties(IframeBoss.prototype.relayout_on_font_size_change, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.number_of_columns_changed = function number_of_columns_changed(data) {
            var self = this;
            opts.columns_per_screen = data.columns_per_screen;
            self.relayout_on_font_size_change();
        };
        if (!IframeBoss.prototype.number_of_columns_changed.__argnames__) Object.defineProperties(IframeBoss.prototype.number_of_columns_changed, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.change_scroll_speed = function change_scroll_speed(data) {
            var self = this;
            if (ρσ_exists.n(data.lines_per_sec_auto)) {
                opts.lines_per_sec_auto = data.lines_per_sec_auto;
            }
        };
        if (!IframeBoss.prototype.change_scroll_speed.__argnames__) Object.defineProperties(IframeBoss.prototype.change_scroll_speed, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.change_stylesheet = function change_stylesheet(data) {
            var self = this;
            opts.user_stylesheet = data.sheet || "";
            apply_stylesheet();
        };
        if (!IframeBoss.prototype.change_stylesheet.__argnames__) Object.defineProperties(IframeBoss.prototype.change_stylesheet, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.change_color_scheme = function change_color_scheme(data) {
            var self = this;
            if (data.color_scheme && data.color_scheme.foreground && data.color_scheme.background) {
                opts.color_scheme = data.color_scheme;
                opts.is_dark_theme = !!data.color_scheme.is_dark_theme;
                apply_colors();
                set_color_scheme_class();
            }
        };
        if (!IframeBoss.prototype.change_color_scheme.__argnames__) Object.defineProperties(IframeBoss.prototype.change_color_scheme, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.content_loaded = function content_loaded() {
            var self = this;
            var ρσ_unpack;
            document.documentElement.style.overflow = "hidden";
            if (self.is_titlepage && !opts.cover_preserve_aspect_ratio) {
                document.body.classList.add("cover-fill");
            }
            document.body.classList.add("calibre-viewer-" + ρσ_str.format("{}", layout_style()) + "");
            set_color_scheme_class();
            if (self.reference_mode_enabled) {
                start_reference_mode();
            }
            ρσ_unpack = [scroll_viewport.width(), scroll_viewport.height()];
            self.last_window_width = ρσ_unpack[0];
            self.last_window_height = ρσ_unpack[1];
            if (self.highlights_to_apply) {
                self.apply_highlights_on_load(self.highlights_to_apply);
                self.highlights_to_apply = null;
            }
            apply_settings();
            invalidate_anchor_position_cache();
            fix_fullscreen_svg_images();
            self.do_layout(self.is_titlepage);
            if (self.mathjax) {
                return apply_mathjax(self.mathjax, self.book.manifest.link_uid, self.content_loaded_stage2);
            }
            self.content_loaded_stage2();
        };
        if (!IframeBoss.prototype.content_loaded.__module__) Object.defineProperties(IframeBoss.prototype.content_loaded, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.content_loaded_stage2 = function content_loaded_stage2() {
            var self = this;
            var csi, ipos, spine, files, spine_index, si, i, load_event;
            reset_find_caches();
            self.connect_links();
            if (runtime.is_standalone_viewer) {
                self.listen_for_image_double_clicks();
            }
            self.content_ready = true;
            if (ρσ_exists.d(document.head).firstChild) {
                document.head.removeChild(document.head.firstChild);
            }
            csi = current_spine_item();
            if (csi.initial_position) {
                ipos = csi.initial_position;
                self.replace_history_on_next_cfi_update = ipos.replace_history || false;
                if (ipos.type === "frac") {
                    self.to_scroll_fraction(ipos.frac, true);
                } else if (ipos.type === "anchor") {
                    self.scroll_to_anchor(ipos.anchor);
                } else if (ipos.type === "ref") {
                    self.scroll_to_ref(ipos.refnum);
                } else if (ipos.type === "cfi") {
                    self.jump_to_cfi(ipos.cfi);
                } else if (ipos.type === "search_result") {
                    self.show_search_result(ipos, true);
                } else if (ipos.type === "edit_annotation") {
                    window.setTimeout((function() {
                        var ρσ_anonfunc = function () {
                            self.annotations_msg_received((function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["type"] = "edit-highlight";
                                ρσ_d["uuid"] = ipos.uuid;
                                return ρσ_d;
                            }).call(this));
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.iframe"}
                        });
                        return ρσ_anonfunc;
                    })(), 5);
                } else if (ipos.type === "smil_id") {
                    self.audio_ebook_msg_received((function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["type"] = "play";
                        ρσ_d["anchor"] = ipos.anchor;
                        return ρσ_d;
                    }).call(this));
                } else if (ipos.type === "pagelist_ref") {
                    self.scroll_to_pagelist_ref(ipos.anchor);
                }
            }
            spine = self.book.manifest.spine;
            files = self.book.manifest.files;
            spine_index = csi.index;
            self.length_before = 0;
            if (spine_index > -1) {
                for (var ρσ_Index1 = 0; ρσ_Index1 < spine_index; ρσ_Index1++) {
                    i = ρσ_Index1;
                    si = spine[(typeof i === "number" && i < 0) ? spine.length + i : i];
                    if (si) {
                        self.length_before += ρσ_exists.d(files[(typeof si === "number" && si < 0) ? files.length + si : si]).length || 0;
                    }
                }
            }
            ρσ_interpolate_kwargs.call(self, self.send_message, ["content_loaded"].concat([ρσ_desugar_kwargs({progress_frac: self.calculate_progress_frac(), file_progress_frac: progress_frac(), page_counts: page_counts()})]));
            self.last_cfi = null;
            self.auto_scroll_action("resume");
            reset_touch_handlers();
            window.setTimeout(self.update_cfi, ONSCROLL_DEBOUNCE_TIME);
            window.setTimeout(self.update_toc_position, 0);
            load_event = document.createEvent("Event");
            load_event.initEvent("load", false, false);
            window.dispatchEvent(load_event);
        };
        if (!IframeBoss.prototype.content_loaded_stage2.__module__) Object.defineProperties(IframeBoss.prototype.content_loaded_stage2, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.calculate_progress_frac = function calculate_progress_frac() {
            var self = this;
            var current_name, files, file_length, frac, ans;
            current_name = current_spine_item().name;
            files = self.book.manifest.files;
            file_length = ρσ_exists.d(files[(typeof current_name === "number" && current_name < 0) ? files.length + current_name : current_name]).length || 0;
            if (self.length_before === null) {
                return 0;
            }
            frac = progress_frac();
            ans = (self.length_before + file_length * frac) / self.book.manifest.spine_length;
            return ans;
        };
        if (!IframeBoss.prototype.calculate_progress_frac.__module__) Object.defineProperties(IframeBoss.prototype.calculate_progress_frac, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.get_current_cfi = function get_current_cfi(data) {
            var self = this;
            var cfi, csi, index, selection, selcfi, seltext;
            cfi = current_cfi();
            csi = current_spine_item();
            function epubcfi(cfi) {
                return (cfi) ? "epubcfi(/{}{})".format(2 * (index + 1), cfi) : null;
            };
            if (!epubcfi.__argnames__) Object.defineProperties(epubcfi, {
                __argnames__ : {value: ["cfi"]},
                __module__ : {value: "read_book.iframe"}
            });

            if (cfi && csi) {
                index = csi.index;
                if (index > -1) {
                    selection = window.getSelection();
                    selcfi = seltext = null;
                    if (selection && !selection.isCollapsed) {
                        seltext = selection.toString();
                        selcfi = cfi_for_selection();
                        selcfi.start = epubcfi(selcfi.start);
                        selcfi.end = epubcfi(selcfi.end);
                    }
                    cfi = epubcfi(cfi);
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["report_cfi"].concat([ρσ_desugar_kwargs({cfi: cfi, progress_frac: self.calculate_progress_frac(), file_progress_frac: progress_frac(), request_id: data.request_id, selected_text: seltext, selection_bounds: selcfi, page_counts: page_counts()})]));
                    return;
                }
            }
            ρσ_interpolate_kwargs.call(self, self.send_message, ["report_cfi"].concat([ρσ_desugar_kwargs({cfi: null, progress_frac: 0, file_progress_frac: 0, page_counts: page_counts(), request_id: data.request_id})]));
        };
        if (!IframeBoss.prototype.get_current_cfi.__argnames__) Object.defineProperties(IframeBoss.prototype.get_current_cfi, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.update_cfi = function update_cfi(force_update) {
            var self = this;
            var cfi, index, pf, fpf;
            cfi = current_cfi();
            if (cfi) {
                index = current_spine_item().index;
                if (index > -1) {
                    cfi = "epubcfi(/{}{})".format(2 * (index + 1), cfi);
                    pf = self.calculate_progress_frac();
                    fpf = progress_frac();
                    if (cfi !== self.last_cfi || force_update) {
                        self.last_cfi = cfi;
                        ρσ_interpolate_kwargs.call(self, self.send_message, ["update_cfi"].concat([ρσ_desugar_kwargs({cfi: cfi, replace_history: self.replace_history_on_next_cfi_update, progress_frac: pf, file_progress_frac: fpf, page_counts: page_counts()})]));
                        self.replace_history_on_next_cfi_update = true;
                    } else {
                        ρσ_interpolate_kwargs.call(self, self.send_message, ["update_progress_frac"].concat([ρσ_desugar_kwargs({progress_frac: pf, file_progress_frac: fpf, page_counts: page_counts()})]));
                    }
                }
            }
        };
        if (!IframeBoss.prototype.update_cfi.__argnames__) Object.defineProperties(IframeBoss.prototype.update_cfi, {
            __argnames__ : {value: ["force_update"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.update_toc_position = function update_toc_position(recalculate_toc_anchor_positions) {
            var self = this;
            var visible_anchors;
            visible_anchors = update_visible_toc_anchors(self.book.manifest.toc_anchor_map, self.book.manifest.page_list_anchor_map, bool(recalculate_toc_anchor_positions));
            ρσ_interpolate_kwargs.call(self, self.send_message, ["update_toc_position"].concat([ρσ_desugar_kwargs({visible_anchors: visible_anchors})]));
        };
        if (!IframeBoss.prototype.update_toc_position.__argnames__) Object.defineProperties(IframeBoss.prototype.update_toc_position, {
            __argnames__ : {value: ["recalculate_toc_anchor_positions"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.onscroll = function onscroll() {
            var self = this;
            if (self.content_ready) {
                self.update_cfi();
                self.update_toc_position();
            }
        };
        if (!IframeBoss.prototype.onscroll.__module__) Object.defineProperties(IframeBoss.prototype.onscroll, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.no_latency_onscroll = function no_latency_onscroll() {
            var self = this;
            var pf, fpf, sel;
            pf = self.calculate_progress_frac();
            fpf = progress_frac();
            ρσ_interpolate_kwargs.call(self, self.send_message, ["update_progress_frac"].concat([ρσ_desugar_kwargs({progress_frac: pf, file_progress_frac: fpf, page_counts: page_counts()})]));
            sel = window.getSelection();
            if (sel && !sel.isCollapsed) {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["update_selection_position"].concat([ρσ_desugar_kwargs({selection_extents: selection_extents(current_layout_mode() === "flow", true)})]));
            }
        };
        if (!IframeBoss.prototype.no_latency_onscroll.__module__) Object.defineProperties(IframeBoss.prototype.no_latency_onscroll, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.onresize = function onresize() {
            var self = this;
            self.send_message("request_size");
            if (self.content_ready) {
                if (is_ios) {
                    return;
                }
                self.onresize_stage2();
            }
        };
        if (!IframeBoss.prototype.onresize.__module__) Object.defineProperties(IframeBoss.prototype.onresize, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.onselectionchange = function onselectionchange() {
            var self = this;
            var sel, text, annot_id, collapsed, start_is_anchor, r, now, by_search;
            if (!self.content_ready) {
                return;
            }
            sel = window.getSelection();
            text = "";
            annot_id = null;
            collapsed = !sel || sel.isCollapsed;
            start_is_anchor = true;
            if (!collapsed) {
                text = sel.toString();
                annot_id = highlight_associated_with_selection(sel, annot_id_uuid_map);
                r = sel.getRangeAt(0);
                start_is_anchor = r.startContainer === sel.anchorNode && r.startOffset === sel.anchorOffset;
            }
            now = window.performance.now();
            by_search = now - self.last_search_at < 1e3;
            ρσ_interpolate_kwargs.call(self, self.send_message, ["selectionchange"].concat([ρσ_desugar_kwargs({text: text, empty: !!collapsed, annot_id: annot_id, drag_mouse_position: drag_mouse_position, selection_change_caused_by_search: by_search, selection_extents: selection_extents(current_layout_mode() === "flow"), rtl: scroll_viewport.rtl, vertical: scroll_viewport.vertical_writing_mode, start_is_anchor: start_is_anchor})]));
        };
        if (!IframeBoss.prototype.onselectionchange.__module__) Object.defineProperties(IframeBoss.prototype.onselectionchange, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.onresize_stage2 = function onresize_stage2() {
            var self = this;
            var ρσ_unpack, cfi, sel;
            if (scroll_viewport.width() === self.last_window_width && scroll_viewport.height() === self.last_window_height) {
                return;
            }
            if (current_layout_mode() !== "flow") {
                paged_prepare_for_resize(self.last_window_width, self.last_window_height);
                self.do_layout(self.is_titlepage);
            }
            ρσ_unpack = [scroll_viewport.width(), scroll_viewport.height()];
            self.last_window_width = ρσ_unpack[0];
            self.last_window_height = ρσ_unpack[1];
            if (self.last_cfi) {
                cfi = self.last_cfi.slice(len("epubcfi(/"), -1).partition("/")[2];
                if (cfi) {
                    self.jump_to_cfi("/" + cfi);
                }
            }
            if (current_layout_mode() !== "flow") {
                paged_resize_done();
            }
            self.update_cfi();
            self.update_toc_position();
            sel = window.getSelection();
            if (sel && !sel.isCollapsed) {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["update_selection_position"].concat([ρσ_desugar_kwargs({selection_extents: selection_extents(current_layout_mode() === "flow")})]));
            }
        };
        if (!IframeBoss.prototype.onresize_stage2.__module__) Object.defineProperties(IframeBoss.prototype.onresize_stage2, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.received_window_size = function received_window_size(data) {
            var self = this;
            scroll_viewport.update_window_size(data.width, data.height);
            if (self.content_ready) {
                self.onresize_stage2();
            }
        };
        if (!IframeBoss.prototype.received_window_size.__argnames__) Object.defineProperties(IframeBoss.prototype.received_window_size, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.onwheel = function onwheel(evt) {
            var self = this;
            if (self.content_ready) {
                if (evt.preventDefault) {
                    evt.preventDefault();
                }
                if (evt.deltaY && evt.ctrlKey && !evt.shiftKey && !evt.altKey && !evt.metaKey) {
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["handle_shortcut"].concat([ρσ_desugar_kwargs({name: (evt.deltaY < 0) ? "increase_font_size" : "decrease_font_size"})]));
                } else {
                    self.handle_wheel(evt);
                }
            }
        };
        if (!IframeBoss.prototype.onwheel.__argnames__) Object.defineProperties(IframeBoss.prototype.onwheel, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.onmousemove = function onmousemove(evt) {
            var self = this;
            var sel, delta;
            if (evt.buttons !== 1) {
                return;
            }
            drag_mouse_position.x = evt.clientX;
            drag_mouse_position.y = evt.clientY;
            if (0 <= (ρσ_cond_temp = evt.clientY) && ρσ_cond_temp <= window.innerHeight) {
                cancel_drag_scroll();
                return;
            }
            sel = window.getSelection();
            if (!sel) {
                cancel_drag_scroll();
                return;
            }
            delta = (evt.clientY < 0) ? evt.clientY : evt.clientY - window.innerHeight;
            self.start_drag_scroll(delta);
        };
        if (!IframeBoss.prototype.onmousemove.__argnames__) Object.defineProperties(IframeBoss.prototype.onmousemove, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.onmouseup = function onmouseup(evt) {
            var self = this;
            cancel_drag_scroll();
            drag_mouse_position.x = drag_mouse_position.y = null;
            self.onselectionchange();
            if (evt.button === 3 || evt.button === 4) {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["handle_shortcut"].concat([ρσ_desugar_kwargs({name: (evt.button === 3) ? "back" : "forward"})]));
            }
        };
        if (!IframeBoss.prototype.onmouseup.__argnames__) Object.defineProperties(IframeBoss.prototype.onmouseup, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.ondoubleclick = function ondoubleclick(evt) {
            var self = this;
            ρσ_interpolate_kwargs.call(self, self.send_message, ["annotations"].concat([ρσ_desugar_kwargs({type: "double-click"})]));
        };
        if (!IframeBoss.prototype.ondoubleclick.__argnames__) Object.defineProperties(IframeBoss.prototype.ondoubleclick, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.onkeydown = function onkeydown(evt) {
            var self = this;
            var sc_name;
            if (current_layout_mode() !== "flow" && evt.key === "Tab") {
                evt.preventDefault();
            }
            if (self.forward_keypresses) {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["handle_keypress"].concat([ρσ_desugar_kwargs({evt: keyevent_as_shortcut(evt)})]));
                [evt.preventDefault(), evt.stopPropagation()];
                return;
            }
            if (self.content_ready) {
                sc_name = shortcut_for_key_event(evt, self.keyboard_shortcut_map);
                if (sc_name) {
                    evt.preventDefault();
                    if (!self.handle_navigation_shortcut(sc_name, evt)) {
                        ρσ_interpolate_kwargs.call(self, self.send_message, ["handle_shortcut"].concat([ρσ_desugar_kwargs({name: sc_name})]));
                    }
                }
            }
        };
        if (!IframeBoss.prototype.onkeydown.__argnames__) Object.defineProperties(IframeBoss.prototype.onkeydown, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.on_handle_navigation_shortcut = function on_handle_navigation_shortcut(data) {
            var self = this;
            self.handle_navigation_shortcut(data.name, data.key || (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["key"] = "";
                ρσ_d["altKey"] = false;
                ρσ_d["ctrlKey"] = false;
                ρσ_d["shiftKey"] = false;
                ρσ_d["metaKey"] = false;
                return ρσ_d;
            }).call(this));
        };
        if (!IframeBoss.prototype.on_handle_navigation_shortcut.__argnames__) Object.defineProperties(IframeBoss.prototype.on_handle_navigation_shortcut, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.oncontextmenu = function oncontextmenu(evt) {
            var self = this;
            if (self.content_ready) {
                evt.preventDefault();
                ρσ_interpolate_kwargs.call(self, self.send_message, ["show_chrome"].concat([ρσ_desugar_kwargs({elements: get_elements(evt.clientX, evt.clientY)})]));
            }
        };
        if (!IframeBoss.prototype.oncontextmenu.__argnames__) Object.defineProperties(IframeBoss.prototype.oncontextmenu, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.send_message = function send_message() {
            var self = this;
            var action = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var data = arguments[arguments.length-1];
            if (data === null || typeof data !== "object" || data [ρσ_kwargs_symbol] !== true) data = {};
            self.comm.send_message(action, data);
        };
        if (!IframeBoss.prototype.send_message.__handles_kwarg_interpolation__) Object.defineProperties(IframeBoss.prototype.send_message, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["action"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.connect_links = function connect_links() {
            var self = this;
            var a;
            var ρσ_Iter2 = ρσ_Iterable(document.body.querySelectorAll("a[" + ρσ_str.format("{}", self.link_attr) + "],area[" + ρσ_str.format("{}", self.link_attr) + "]"));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                a = ρσ_Iter2[ρσ_Index2];
                a.addEventListener("click", self.link_activated);
            }
            if (runtime.is_standalone_viewer) {
                var ρσ_Iter3 = ρσ_Iterable(document.body.querySelectorAll("a[target]"));
                for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                    a = ρσ_Iter3[ρσ_Index3];
                    a.removeAttribute("target");
                }
            }
        };
        if (!IframeBoss.prototype.connect_links.__module__) Object.defineProperties(IframeBoss.prototype.connect_links, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.listen_for_image_double_clicks = function listen_for_image_double_clicks() {
            var self = this;
            var img;
            var ρσ_Iter4 = ρσ_Iterable(document.querySelectorAll("img, image"));
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                img = ρσ_Iter4[ρσ_Index4];
                img.addEventListener("dblclick", self.image_double_clicked, (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["passive"] = true;
                    return ρσ_d;
                }).call(this));
            }
        };
        if (!IframeBoss.prototype.listen_for_image_double_clicks.__module__) Object.defineProperties(IframeBoss.prototype.listen_for_image_double_clicks, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.image_double_clicked = function image_double_clicked(ev) {
            var self = this;
            var img;
            img = ev.currentTarget;
            if (img.dataset.calibreSrc) {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["view_image"].concat([ρσ_desugar_kwargs({calibre_src: img.dataset.calibreSrc})]));
            }
        };
        if (!IframeBoss.prototype.image_double_clicked.__argnames__) Object.defineProperties(IframeBoss.prototype.image_double_clicked, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.link_activated = function link_activated(evt) {
            var self = this;
            var data;
            try {
                data = JSON.parse(evt.currentTarget.getAttribute(self.link_attr));
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    print("WARNING: Failed to parse link data {}, ignoring".format(ρσ_exists.c(ρσ_exists.d(evt.currentTarget).getAttribute)(self.link_attr)));
                    return;
                } 
            }
            if (data.missing) {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["link_to_missing_activated"].concat([ρσ_desugar_kwargs({name: data.name})]));
            } else {
                self.activate_link(data.name, data.frag, evt.currentTarget);
            }
        };
        if (!IframeBoss.prototype.link_activated.__argnames__) Object.defineProperties(IframeBoss.prototype.link_activated, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.activate_link = function activate_link(name, frag, target_elem) {
            var self = this;
            var is_popup;
            if (!name) {
                name = current_spine_item().name;
            }
            try {
                is_popup = is_footnote_link(target_elem, name, frag, current_spine_item().name, self.book.manifest.link_to_map || Object.create(null));
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    var traceback = ρσ_modules.traceback;

                    traceback.print_exc();
                    is_popup = false;
                } 
            }
            if (is_popup) {
                self.on_fake_popup_activation((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["name"] = name;
                    ρσ_d["frag"] = frag;
                    ρσ_d["title"] = target_elem.textContent;
                    return ρσ_d;
                }).call(this));
                return;
            }
            if (name === current_spine_item().name) {
                self.replace_history_on_next_cfi_update = false;
                self.scroll_to_anchor(frag);
            } else {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["scroll_to_anchor"].concat([ρσ_desugar_kwargs({name: name, frag: frag})]));
            }
        };
        if (!IframeBoss.prototype.activate_link.__argnames__) Object.defineProperties(IframeBoss.prototype.activate_link, {
            __argnames__ : {value: ["name", "frag", "target_elem"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.on_fake_popup_activation = function on_fake_popup_activation(data) {
            var self = this;
            ρσ_interpolate_kwargs.call(self, self.send_message, ["show_footnote"].concat([ρσ_desugar_kwargs({name: data.name, frag: data.frag, title: data.title, cols_per_screen: calc_columns_per_screen(), rtl: scroll_viewport.rtl, vertical_writing_mode: scroll_viewport.vertical_writing_mode})]));
        };
        if (!IframeBoss.prototype.on_fake_popup_activation.__argnames__) Object.defineProperties(IframeBoss.prototype.on_fake_popup_activation, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.scroll_to_anchor = function scroll_to_anchor(frag) {
            var self = this;
            var elem, c;
            if (frag) {
                elem = document.getElementById(frag);
                if (!elem) {
                    c = document.getElementsByName(frag);
                    if (c && c.length) {
                        elem = c[0];
                    }
                }
                if (elem) {
                    scroll_to_elem(elem);
                }
            } else {
                scroll_viewport.scroll_to(0, 0);
            }
        };
        if (!IframeBoss.prototype.scroll_to_anchor.__argnames__) Object.defineProperties(IframeBoss.prototype.scroll_to_anchor, {
            __argnames__ : {value: ["frag"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.scroll_to_pagelist_ref = function scroll_to_pagelist_ref(frag) {
            var self = this;
            var elem, c;
            elem = document.getElementById(frag);
            if (!elem) {
                c = document.getElementsByName(frag);
                if (c && c.length) {
                    elem = c[0];
                }
            }
            if (elem) {
                ensure_page_list_target_is_displayed(elem);
                scroll_to_elem(elem);
            }
        };
        if (!IframeBoss.prototype.scroll_to_pagelist_ref.__argnames__) Object.defineProperties(IframeBoss.prototype.scroll_to_pagelist_ref, {
            __argnames__ : {value: ["frag"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.scroll_to_ref = function scroll_to_ref(refnum) {
            var self = this;
            var elem;
            refnum = int(refnum);
            elem = elem_for_ref(refnum);
            if (elem) {
                scroll_to_elem(elem);
            }
        };
        if (!IframeBoss.prototype.scroll_to_ref.__argnames__) Object.defineProperties(IframeBoss.prototype.scroll_to_ref, {
            __argnames__ : {value: ["refnum"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.on_scroll_to_ref = function on_scroll_to_ref(data) {
            var self = this;
            var refnum;
            refnum = data.refnum;
            if ((typeof refnum !== "undefined" && refnum !== null)) {
                self.scroll_to_ref(refnum);
            }
        };
        if (!IframeBoss.prototype.on_scroll_to_ref.__argnames__) Object.defineProperties(IframeBoss.prototype.on_scroll_to_ref, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.show_search_result = function show_search_result(data, from_load) {
            var self = this;
            var sr, before_select_pos, need_workaround, discovered;
            if (self.load_search_result_timer) {
                window.clearTimeout(self.load_search_result_timer);
                self.load_search_result_timer = null;
            }
            sr = data.search_result;
            if (sr.on_discovery) {
                if (sr.result_num === 1) {
                    self.full_book_search_in_progress = new FullBookSearch;
                } else if (ρσ_exists.d(self.full_book_search_in_progress).first_result_shown) {
                    return;
                }
            }
            self.last_search_at = window.performance.now();
            before_select_pos = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["x"] = scroll_viewport.x();
                ρσ_d["y"] = scroll_viewport.y();
                return ρσ_d;
            }).call(this);
            if (select_search_result(sr)) {
                self.ensure_selection_boundary_visible();
                need_workaround = from_load && current_layout_mode() === "paged";
                if (need_workaround) {
                    self.load_search_result_timer = window.setTimeout(self.ensure_search_result_visible.bind(null, before_select_pos), int(3 * ONSCROLL_DEBOUNCE_TIME / 4));
                }
                if (self.full_book_search_in_progress && !self.full_book_search_in_progress.first_result_shown && sr.on_discovery) {
                    discovered = false;
                    if (sr.force_jump_to || progress_frac() >= self.full_book_search_in_progress.progress_frac_at_start || current_spine_item().index !== self.full_book_search_in_progress.start_spine_index) {
                        self.full_book_search_in_progress.first_result_shown = true;
                        discovered = true;
                    } else {
                        scroll_viewport.scroll_to(before_select_pos.x, before_select_pos.y);
                    }
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["search_result_discovered"].concat([ρσ_desugar_kwargs({search_result: data.search_result, discovered: discovered})]));
                }
                if (!need_workaround) {
                    self.add_search_result_to_history_stack(before_select_pos);
                }
            } else {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["search_result_not_found"].concat([ρσ_desugar_kwargs({search_result: data.search_result})]));
            }
        };
        if (!IframeBoss.prototype.show_search_result.__argnames__) Object.defineProperties(IframeBoss.prototype.show_search_result, {
            __argnames__ : {value: ["data", "from_load"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.add_search_result_to_history_stack = function add_search_result_to_history_stack(before_select_pos) {
            var self = this;
            self.replace_history_on_next_cfi_update = false;
            self.update_cfi(true);
        };
        if (!IframeBoss.prototype.add_search_result_to_history_stack.__argnames__) Object.defineProperties(IframeBoss.prototype.add_search_result_to_history_stack, {
            __argnames__ : {value: ["before_select_pos"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.ensure_search_result_visible = function ensure_search_result_visible(before_select_pos) {
            var self = this;
            var sel;
            self.load_search_result_timer = null;
            sel = window.getSelection();
            if (sel.isCollapsed || sel.rangeCount === 0) {
                return;
            }
            self.ensure_selection_boundary_visible();
            self.add_search_result_to_history_stack(before_select_pos);
        };
        if (!IframeBoss.prototype.ensure_search_result_visible.__argnames__) Object.defineProperties(IframeBoss.prototype.ensure_search_result_visible, {
            __argnames__ : {value: ["before_select_pos"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.set_reference_mode = function set_reference_mode(data) {
            var self = this;
            self.reference_mode_enabled = data.enabled;
            if (data.enabled) {
                start_reference_mode();
            } else {
                end_reference_mode();
            }
        };
        if (!IframeBoss.prototype.set_reference_mode.__argnames__) Object.defineProperties(IframeBoss.prototype.set_reference_mode, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.apply_highlight = function apply_highlight(uuid, existing, has_notes, style_defn) {
            var self = this;
            var sel, anchor_before, text, bounds, style, cls, ρσ_unpack, annot_id, intersecting_wrappers, removed_highlights, intersecting_uuids, x, crw;
            sel = window.getSelection();
            if (!sel.rangeCount) {
                return;
            }
            anchor_before = find_anchor_before_range(sel.getRangeAt(0), self.book.manifest.toc_anchor_map, self.book.manifest.page_list_anchor_map);
            text = sel.toString();
            bounds = cfi_for_selection();
            style = highlight_style_as_css(style_defn, opts.is_dark_theme, opts.color_scheme.foreground);
            cls = (has_notes) ? "crw-has-dot" : null;
            ρσ_unpack = wrap_text_in_range(style, null, cls, self.add_highlight_listeners);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            annot_id = ρσ_unpack[0];
            intersecting_wrappers = ρσ_unpack[1];
            removed_highlights = [];
            if (annot_id !== null) {
                intersecting_uuids = (function() {
                    var ρσ_Iter = ρσ_Iterable(intersecting_wrappers), ρσ_Result = Object.create(null), x;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        x = ρσ_Iter[ρσ_Index];
                        ρσ_Result[annot_id_uuid_map[(typeof x === "number" && x < 0) ? annot_id_uuid_map.length + x : x]] = (true);
                    }
                    return ρσ_Result;
                })();
                if (existing && intersecting_uuids[(typeof existing === "number" && existing < 0) ? intersecting_uuids.length + existing : existing]) {
                    uuid = existing;
                } else if (intersecting_wrappers.length === 1 && annot_id_uuid_map[ρσ_bound_index(intersecting_wrappers[0], annot_id_uuid_map)]) {
                    uuid = annot_id_uuid_map[ρσ_bound_index(intersecting_wrappers[0], annot_id_uuid_map)];
                    intersecting_wrappers = [];
                }
                removed_highlights = Object.create(null);
                var ρσ_Iter5 = ρσ_Iterable(intersecting_wrappers);
                for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                    crw = ρσ_Iter5[ρσ_Index5];
                    unwrap_crw(crw);
                    if (annot_id_uuid_map[(typeof crw === "number" && crw < 0) ? annot_id_uuid_map.length + crw : crw]) {
                        if (annot_id_uuid_map[(typeof crw === "number" && crw < 0) ? annot_id_uuid_map.length + crw : crw] !== uuid) {
                            removed_highlights[ρσ_bound_index(annot_id_uuid_map[(typeof crw === "number" && crw < 0) ? annot_id_uuid_map.length + crw : crw], removed_highlights)] = true;
                        }
                        delete annot_id_uuid_map[crw];
                    }
                }
                removed_highlights = Object.keys(removed_highlights);
                sel.removeAllRanges();
                annot_id_uuid_map[(typeof annot_id === "number" && annot_id < 0) ? annot_id_uuid_map.length + annot_id : annot_id] = uuid;
            }
            ρσ_interpolate_kwargs.call(self, self.send_message, ["annotations"].concat([ρσ_desugar_kwargs({type: "highlight-applied", uuid: uuid, ok: annot_id !== null, bounds: bounds, style: style_defn, removed_highlights: removed_highlights, highlighted_text: text, anchor_before: anchor_before})]));
            reset_find_caches();
        };
        if (!IframeBoss.prototype.apply_highlight.__argnames__) Object.defineProperties(IframeBoss.prototype.apply_highlight, {
            __argnames__ : {value: ["uuid", "existing", "has_notes", "style_defn"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.annotations_msg_received = function annotations_msg_received(data) {
            var self = this;
            var dtype, sel, ρσ_unpack, end_node, end_offset, found_highlight_to_edit, qcrw, quuid, cls, node, found_highlight_to_remove, existing, bounds, text;
            dtype = (typeof data !== "undefined" && data !== null ? data : Object.create(null)).type;
            if (dtype === "move-end-of-selection") {
                move_end_of_selection(data.pos, data.start);
            } else if (dtype === "set-highlight-style") {
                set_selection_style(data.style);
            } else if (dtype === "trigger-shortcut") {
                self.on_handle_navigation_shortcut(data);
            } else if (dtype === "extend-to-paragraph") {
                sel = window.getSelection();
                try {
                    try {
                        sel.modify("extend", "forward", "paragraphboundary");
                    } catch (ρσ_Exception) {
                        ρσ_last_exception = ρσ_Exception;
                        {
                            sel.modify("extend", "forward", "lineboundary");
                        } 
                    }
                    ρσ_unpack = [sel.focusNode, sel.focusOffset];
                    end_node = ρσ_unpack[0];
                    end_offset = ρσ_unpack[1];
                    try {
                        sel.modify("extend", "backward", "paragraphboundary");
                    } catch (ρσ_Exception) {
                        ρσ_last_exception = ρσ_Exception;
                        {
                            sel.modify("extend", "backward", "lineboundary");
                        } 
                    }
                    sel.setBaseAndExtent(sel.focusNode, sel.focusOffset, end_node, end_offset);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        (console.error || console.log)("Failed to extend selection to paragraph");
                    } 
                }
            } else if (dtype === "extend-to-point") {
                move_end_of_selection(data.pos, is_start_closer_to_point(data.pos));
            } else if (dtype === "drag-scroll") {
                self.scroll_to_extend_annotation(data.backwards);
            } else if (dtype === "edit-highlight") {
                found_highlight_to_edit = false;
                var ρσ_Iter6 = ρσ_Iterable(Object.entries(annot_id_uuid_map));
                for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                    ρσ_unpack = ρσ_Iter6[ρσ_Index6];
                    qcrw = ρσ_unpack[0];
                    quuid = ρσ_unpack[1];
                    if (quuid === data.uuid && select_crw(qcrw)) {
                        found_highlight_to_edit = true;
                        break;
                    }
                }
                if (found_highlight_to_edit) {
                    self.ensure_selection_visible();
                    window.setTimeout((function() {
                        var ρσ_anonfunc = function () {
                            ρσ_interpolate_kwargs.call(self, self.send_message, ["annotations"].concat([ρσ_desugar_kwargs({type: "edit-highlight"})]));
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.iframe"}
                        });
                        return ρσ_anonfunc;
                    })(), 50);
                } else {
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["annotations"].concat([ρσ_desugar_kwargs({type: "edit-highlight-failed", uuid: data.uuid})]));
                }
            } else if (dtype === "notes-edited") {
                cls = "crw-has-dot";
                var ρσ_Iter7 = ρσ_Iterable(Object.entries(annot_id_uuid_map));
                for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                    ρσ_unpack = ρσ_Iter7[ρσ_Index7];
                    qcrw = ρσ_unpack[0];
                    quuid = ρσ_unpack[1];
                    if (quuid === data.uuid) {
                        node = last_span_for_crw(qcrw);
                        if (node) {
                            if (data.has_notes) {
                                node.classList.add(cls);
                            } else {
                                node.classList.remove(cls);
                            }
                        }
                    }
                }
            } else if (dtype === "remove-highlight") {
                found_highlight_to_remove = false;
                var ρσ_Iter8 = ρσ_Iterable(Object.entries(annot_id_uuid_map));
                for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                    ρσ_unpack = ρσ_Iter8[ρσ_Index8];
                    qcrw = ρσ_unpack[0];
                    quuid = ρσ_unpack[1];
                    if (quuid === data.uuid) {
                        found_highlight_to_remove = true;
                        unwrap_crw(qcrw);
                        delete annot_id_uuid_map[qcrw];
                    }
                }
                if (found_highlight_to_remove) {
                    window.getSelection().removeAllRanges();
                }
            } else if (dtype === "apply-highlight") {
                existing = all_annots_in_selection(window.getSelection(), annot_id_uuid_map);
                if (existing.length === 0 || existing.length === 1 && existing[0] === data.existing) {
                    self.apply_highlight(data.uuid, data.existing, data.has_notes, data.style);
                } else {
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["annotations"].concat([ρσ_desugar_kwargs({type: "highlight-overlapped", uuid: data.uuid, existing: data.existing, has_notes: data.has_notes, style: data.style})]));
                }
            } else if (dtype === "apply-highlight-overwrite") {
                self.apply_highlight(data.uuid, data.existing, data.has_notes, data.style);
            } else if (dtype === "cite-current-selection") {
                sel = window.getSelection();
                if (!sel.rangeCount) {
                    return;
                }
                bounds = cfi_for_selection();
                text = sel.toString();
                ρσ_interpolate_kwargs.call(self, self.send_message, ["annotations"].concat([ρσ_desugar_kwargs({type: "cite-data", bounds: bounds, highlighted_text: text})]));
            } else {
                console.log("Ignoring annotations message to iframe with unknown type: " + dtype);
            }
        };
        if (!IframeBoss.prototype.annotations_msg_received.__argnames__) Object.defineProperties(IframeBoss.prototype.annotations_msg_received, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.apply_highlights_on_load = function apply_highlights_on_load(highlights) {
            var self = this;
            var strcmp, r, style, cls, ρσ_unpack, annot_id, intersecting_wrappers, crw, h;
            clear_annot_id_uuid_map();
            reset_highlight_counter();
            strcmp = new Intl.Collator().compare;
            highlights.sort((function() {
                var ρσ_anonfunc = function (a, b) {
                    return strcmp(a.timestamp, b.timestamp);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["a", "b"]},
                    __module__ : {value: "read_book.iframe"}
                });
                return ρσ_anonfunc;
            })());
            var ρσ_Iter9 = ρσ_Iterable(highlights);
            for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                h = ρσ_Iter9[ρσ_Index9];
                r = range_from_cfi(h.start_cfi, h.end_cfi);
                if (!r) {
                    continue;
                }
                style = highlight_style_as_css(h.style, opts.is_dark_theme, opts.color_scheme.foreground);
                cls = (h.notes) ? "crw-has-dot" : null;
                ρσ_unpack = wrap_text_in_range(style, r, cls, self.add_highlight_listeners);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                annot_id = ρσ_unpack[0];
                intersecting_wrappers = ρσ_unpack[1];
                if (annot_id !== null) {
                    annot_id_uuid_map[(typeof annot_id === "number" && annot_id < 0) ? annot_id_uuid_map.length + annot_id : annot_id] = h.uuid;
                    var ρσ_Iter10 = ρσ_Iterable(intersecting_wrappers);
                    for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                        crw = ρσ_Iter10[ρσ_Index10];
                        unwrap_crw(crw);
                        delete annot_id_uuid_map[crw];
                    }
                }
            }
        };
        if (!IframeBoss.prototype.apply_highlights_on_load.__argnames__) Object.defineProperties(IframeBoss.prototype.apply_highlights_on_load, {
            __argnames__ : {value: ["highlights"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.replace_highlights = function replace_highlights(data) {
            var self = this;
            var highlights;
            highlights = data.highlights;
            unwrap_all_crw();
            self.apply_highlights_on_load(highlights || []);
        };
        if (!IframeBoss.prototype.replace_highlights.__argnames__) Object.defineProperties(IframeBoss.prototype.replace_highlights, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.add_highlight_listeners = function add_highlight_listeners(wrapper) {
            var self = this;
            wrapper.addEventListener("dblclick", self.highlight_wrapper_dblclicked);
        };
        if (!IframeBoss.prototype.add_highlight_listeners.__argnames__) Object.defineProperties(IframeBoss.prototype.add_highlight_listeners, {
            __argnames__ : {value: ["wrapper"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.highlight_wrapper_dblclicked = function highlight_wrapper_dblclicked(ev) {
            var self = this;
            var crw;
            crw = ev.currentTarget.dataset.calibreRangeWrapper;
            if (crw) {
                [ev.preventDefault(), ev.stopPropagation()];
                select_crw(crw);
            }
        };
        if (!IframeBoss.prototype.highlight_wrapper_dblclicked.__argnames__) Object.defineProperties(IframeBoss.prototype.highlight_wrapper_dblclicked, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.copy_selection = function copy_selection() {
            var self = this;
            var s, text, container, i;
            try {
                if (document.execCommand("copy")) {
                    return;
                }
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                } 
            }
            s = window.getSelection();
            text = s.toString();
            if (text) {
                container = document.createElement("div");
                for (var ρσ_Index11 = 0; ρσ_Index11 < s.rangeCount; ρσ_Index11++) {
                    i = ρσ_Index11;
                    container.appendChild(s.getRangeAt(i).cloneContents());
                }
                ρσ_interpolate_kwargs.call(self, self.send_message, ["copy_text_to_clipboard"].concat([ρσ_desugar_kwargs({text: text, html: container.innerHTML})]));
            }
        };
        if (!IframeBoss.prototype.copy_selection.__module__) Object.defineProperties(IframeBoss.prototype.copy_selection, {
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.tts_msg_received = function tts_msg_received(data) {
            var self = this;
            var ρσ_unpack, text_node, offset, r, marked_text, sel;
            if (data.type === "mark") {
                self.mark_word_being_spoken(data.num);
            } else if (data.type === "play") {
                ρσ_unpack = [null, 0];
                text_node = ρσ_unpack[0];
                offset = ρσ_unpack[1];
                if (data.pos) {
                    r = word_at_point(data.pos.x, data.pos.y);
                    if (!r) {
                        return;
                    }
                } else {
                    r = first_visible_word();
                }
                if (r && ρσ_exists.d(r.startContainer).nodeType === Node.TEXT_NODE) {
                    ρσ_unpack = [r.startContainer, r.startOffset];
                    text_node = ρσ_unpack[0];
                    offset = ρσ_unpack[1];
                }
                marked_text = tts_data(text_node, offset);
                sel = window.getSelection();
                sel.removeAllRanges();
                ρσ_interpolate_kwargs.call(self, self.send_message, ["tts"].concat([ρσ_desugar_kwargs({type: "text-extracted", marked_text: marked_text, pos: data.pos})]));
            }
        };
        if (!IframeBoss.prototype.tts_msg_received.__argnames__) Object.defineProperties(IframeBoss.prototype.tts_msg_received, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.mark_word_being_spoken = function mark_word_being_spoken(x) {
            var self = this;
            if (typeof x === "number") {
                x = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["first"] = x;
                    ρσ_d["last"] = x;
                    return ρσ_d;
                }).call(this);
            }
            self.last_search_at = window.performance.now();
            if (select_tts_mark(x.first, x.last)) {
                self.ensure_selection_boundary_visible();
            }
        };
        if (!IframeBoss.prototype.mark_word_being_spoken.__argnames__) Object.defineProperties(IframeBoss.prototype.mark_word_being_spoken, {
            __argnames__ : {value: ["x"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.audio_ebook_msg_received = function audio_ebook_msg_received(data) {
            var self = this;
            var pos, par;
            if (data.type === "mark") {
                if (data.anchor) {
                    self.last_search_at = window.performance.now();
                    if (mark_smil_element(data.anchor)) {
                        self.ensure_selection_boundary_visible();
                        ρσ_interpolate_kwargs.call(self, self.send_message, ["audio_ebook_message"].concat([ρσ_desugar_kwargs({type: "marked", anchor: data.anchor, idx: data.idx})]));
                    } else {
                        ρσ_interpolate_kwargs.call(self, self.send_message, ["audio_ebook_message"].concat([ρσ_desugar_kwargs({type: "marked"})]));
                    }
                } else {
                    window.getSelection().removeAllRanges();
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["audio_ebook_message"].concat([ρσ_desugar_kwargs({type: "marked"})]));
                }
            } else if (data.type === "play") {
                if (data.anchor) {
                    pos = (ρσ_expr_temp = self.smil_anchor_map)[ρσ_bound_index(data.anchor, ρσ_expr_temp)];
                    if ((typeof pos !== "undefined" && pos !== null)) {
                        par = (ρσ_expr_temp = self.smil_par_list)[(typeof pos === "number" && pos < 0) ? ρσ_expr_temp.length + pos : pos];
                    } else {
                        par = null;
                    }
                } else {
                    par = smil_element_at(data.pos, self.smil_anchor_map, self.smil_par_list);
                }
                ρσ_interpolate_kwargs.call(self, self.send_message, ["audio_ebook_message"].concat([ρσ_desugar_kwargs({type: "start_play_at", par: par || null, anchor: data.anchor || null, pos: data.pos || null})]));
            } else {
                console.error("Unknown audio ebook message type from main: " + ρσ_str.format("{}", data.type) + "");
            }
        };
        if (!IframeBoss.prototype.audio_ebook_msg_received.__argnames__) Object.defineProperties(IframeBoss.prototype.audio_ebook_msg_received, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.hints_msg_received = function hints_msg_received(data) {
            var self = this;
            var hints_map, hint, a;
            if (data.type === "show") {
                window.getSelection().removeAllRanges();
                hints_map = hint_visible_links();
                ρσ_interpolate_kwargs.call(self, self.send_message, ["hints"].concat([ρσ_desugar_kwargs({type: "shown", hints_map: hints_map})]));
            } else if (data.type === "hide") {
                unhint_links();
            } else if (data.type === "activate") {
                hint = data.hint;
                if (hint.type === "link") {
                    a = document.body.querySelector("[data-calibre-hint-value=\"" + ρσ_str.format("{}", hint.value) + "\"]");
                    a.removeEventListener("animationend", self.hint_animation_ended);
                    a.addEventListener("animationend", self.hint_animation_ended, false);
                    a.classList.add("calibre-animated-hint");
                }
            } else if (data.type === "apply_prefix") {
                apply_prefix_to_hints(data.prefix);
            }
        };
        if (!IframeBoss.prototype.hints_msg_received.__argnames__) Object.defineProperties(IframeBoss.prototype.hints_msg_received, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.hint_animation_ended = function hint_animation_ended(ev) {
            var self = this;
            var a;
            a = ev.currentTarget;
            a.classList.remove("calibre-animated-hint");
            a.click();
        };
        if (!IframeBoss.prototype.hint_animation_ended.__argnames__) Object.defineProperties(IframeBoss.prototype.hint_animation_ended, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.iframe"}
        });
        IframeBoss.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        IframeBoss.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(IframeBoss.prototype, "__bases__", {value: []});

        function main() {
            if (!main.boss) {
                main.boss = new IframeBoss;
            }
        };
        if (!main.__module__) Object.defineProperties(main, {
            __module__ : {value: "read_book.iframe"}
        });

        ρσ_modules["read_book.iframe"].FORCE_FLOW_MODE = FORCE_FLOW_MODE;
        ρσ_modules["read_book.iframe"].CALIBRE_VERSION = CALIBRE_VERSION;
        ρσ_modules["read_book.iframe"].ONSCROLL_DEBOUNCE_TIME = ONSCROLL_DEBOUNCE_TIME;
        ρσ_modules["read_book.iframe"].ERS_SUPPORTED_FEATURES = ERS_SUPPORTED_FEATURES;
        ρσ_modules["read_book.iframe"].drag_mouse_position = drag_mouse_position;
        ρσ_modules["read_book.iframe"].layout_style = layout_style;
        ρσ_modules["read_book.iframe"].cancel_drag_scroll = cancel_drag_scroll;
        ρσ_modules["read_book.iframe"].EPUBReadingSystem = EPUBReadingSystem;
        ρσ_modules["read_book.iframe"].FullBookSearch = FullBookSearch;
        ρσ_modules["read_book.iframe"].IframeBoss = IframeBoss;
        ρσ_modules["read_book.iframe"].main = main;
    })();

    (function(){
        var __name__ = "book_list.item_list";
        var CLASS_NAME;
        var build_rule = ρσ_modules.dom.build_rule;
        var svgicon = ρσ_modules.dom.svgicon;
        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var clear = ρσ_modules.dom.clear;

        var E = ρσ_modules.elementmaker.E;

        var get_font_size = ρσ_modules["book_list.theme"].get_font_size;
        var get_color = ρσ_modules["book_list.theme"].get_color;

        CLASS_NAME = "generic-items-list";
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, style;
                sel = "." + CLASS_NAME + " ";
                style = "";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({padding: "0.75rem 1rem"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " > p"].concat([ρσ_desugar_kwargs({margin: "0 0 0.75rem 0", padding: "0.6rem 0.75rem", border: "var(--calibre-border-style-subtle)", border_radius: "12px", background_color: "rgba(0,0,0,0.02)", font_style: "normal", opacity: "0.8"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " ul"].concat([ρσ_desugar_kwargs({list_style: "none", margin: "0", padding: "0", display: "flex", flex_direction: "column", gap: "0.5rem"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "li"].concat([ρσ_desugar_kwargs({padding: "0", border: "var(--calibre-border-style-subtle)", border_radius: "14px", background_color: get_color("window-background"), box_shadow: "0 1px 2px rgba(0,0,0,0.06)", cursor: "pointer", overflow: "hidden"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "li:hover"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light)", box_shadow: "0 8px 20px rgba(0,0,0,0.10)", transform: "translateY(-1px)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "li:active"].concat([ρσ_desugar_kwargs({transform: "translateY(0px)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .item-title-body .item-title"].concat([ρσ_desugar_kwargs({font_size: get_font_size("item-list-title"), font_weight: "700"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .item-subtitle"].concat([ρσ_desugar_kwargs({font_size: get_font_size("item-list-subtitle"), font_style: "normal", opacity: "0.78"})]));
                sel += " li > div:nth-child(1)";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({padding: "0.85rem 0.95rem", position: "relative", display: "flex", align_items: "flex-start", flex_wrap: "wrap", gap: "0.5rem", box_sizing: "border-box"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .item-title-body"].concat([ρσ_desugar_kwargs({display: "flex", align_items: "center", gap: "0.5rem", min_width: "0", flex: "1 1 auto"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .item-title-body > span:not(.item-title)"].concat([ρσ_desugar_kwargs({opacity: "0.8"})]));
                style += "\n@media (max-width: 420px) {\n  .generic-items-list { padding: 0.6rem 0.75rem; }\n  .generic-items-list ul { gap: 0.45rem; }\n  .generic-items-list li > div:nth-child(1) { padding: 0.75rem 0.75rem; }\n}\n";
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "book_list.item_list"}
            });
            return ρσ_anonfunc;
        })());
        function side_action(action, ev) {
            var li;
            [ev.stopPropagation(), ev.preventDefault()];
            if (action) {
                li = ev.currentTarget.closest("li");
                action(li);
            }
        };
        if (!side_action.__argnames__) Object.defineProperties(side_action, {
            __argnames__ : {value: ["action", "ev"]},
            __module__ : {value: "book_list.item_list"}
        });

        function add_classes(elem, class_names) {
            var cls;
            var ρσ_Iter0 = ρσ_Iterable((class_names || "").toString().split(/\s+/));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                cls = ρσ_Iter0[ρσ_Index0];
                if (cls) {
                    elem.classList.add(cls);
                }
            }
        };
        if (!add_classes.__argnames__) Object.defineProperties(add_classes, {
            __argnames__ : {value: ["elem", "class_names"]},
            __module__ : {value: "book_list.item_list"}
        });

        function build_list(container, items, subtitle) {
            var c, ul, has_icons, item, title_body, ic, tit, row, nm, stack, li, s, x;
            c = container;
            clear(c);
            c.classList.add(CLASS_NAME);
            if (subtitle) {
                c.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [subtitle].concat([ρσ_desugar_kwargs({style: "font-style:normal; font-weight:700; padding: 1em 1ex; border-bottom: solid 1px currentColor"})])));
            }
            ul = E.ul();
            c.appendChild(ul);
            has_icons = false;
            var ρσ_Iter1 = ρσ_Iterable(items);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                item = ρσ_Iter1[ρσ_Index1];
                if (item.icon) {
                    has_icons = true;
                    break;
                }
            }
            var ρσ_Iter2 = ρσ_Iterable(items);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                item = ρσ_Iter2[ρσ_Index2];
                title_body = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "item-title-body"})]);
                if (has_icons) {
                    ic = "";
                    if (item.icon) {
                        ic = svgicon(item.icon);
                    }
                    title_body.appendChild(E.span(ic, " "));
                }
                tit = item.title;
                if (typeof tit === "string") {
                    title_body.appendChild(ρσ_interpolate_kwargs.call(E, E.span, [(tit || "") + ""].concat([ρσ_desugar_kwargs({class_: "item-title"})])));
                } else {
                    title_body.appendChild(tit);
                }
                row = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "item-first-row"})]);
                add_classes(row, item.row_class);
                row.appendChild(title_body);
                nm = item.nav_list_meta;
                if (nm && (nm.rating || nm.count)) {
                    stack = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "item-subtitle item-subtitle-nav"})]);
                    if (nm.rating) {
                        stack.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [nm.rating].concat([ρσ_desugar_kwargs({class_: "item-subtitle-rating"})])));
                    }
                    if (nm.count) {
                        stack.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [nm.count].concat([ρσ_desugar_kwargs({class_: "item-subtitle-count"})])));
                    }
                    row.appendChild(stack);
                } else if (item.subtitle) {
                    row.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [item.subtitle].concat([ρσ_desugar_kwargs({class_: "item-subtitle", style: "padding-top:1ex"})])));
                }
                li = E.li(row);
                add_classes(li, item.li_class);
                ul.appendChild(li);
                if (item.action) {
                    li.addEventListener("click", item.action);
                }
                if (item.data) {
                    li.dataset.userData = item.data;
                }
                if (ρσ_exists.d(item.side_actions).length) {
                    s = li.style;
                    s.display = "flex";
                    s.alignItems = "center";
                    li.firstChild.style.flexGrow = "10";
                    li.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display: flex; align-items: center; margin-left: 0.5rem"})]));
                    var ρσ_Iter3 = ρσ_Iterable(item.side_actions);
                    for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                        x = ρσ_Iter3[ρσ_Index3];
                        li.lastChild.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [svgicon(x.icon)].concat([ρσ_desugar_kwargs({class_: "simple-link", style: "padding: 0.5rem", title: x.tooltip || "", onclick: side_action.bind(null, x.action)})])));
                    }
                }
            }
        };
        if (!build_list.__argnames__) Object.defineProperties(build_list, {
            __argnames__ : {value: ["container", "items", "subtitle"]},
            __module__ : {value: "book_list.item_list"}
        });

        function create_side_action() {
            var icon = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var action = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_side_action.__defaults__.action : arguments[1];
            var tooltip = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_side_action.__defaults__.tooltip : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "action")){
                action = ρσ_kwargs_obj.action;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "tooltip")){
                tooltip = ρσ_kwargs_obj.tooltip;
            }
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["icon"] = icon;
                ρσ_d["action"] = action;
                ρσ_d["tooltip"] = tooltip;
                return ρσ_d;
            }).call(this);
        };
        if (!create_side_action.__defaults__) Object.defineProperties(create_side_action, {
            __defaults__ : {value: {action:null, tooltip:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["icon", "action", "tooltip"]},
            __module__ : {value: "book_list.item_list"}
        });

        function create_item() {
            var title = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var action = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_item.__defaults__.action : arguments[1];
            var subtitle = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_item.__defaults__.subtitle : arguments[2];
            var icon = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_item.__defaults__.icon : arguments[3];
            var data = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_item.__defaults__.data : arguments[4];
            var side_actions = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_item.__defaults__.side_actions : arguments[5];
            var nav_list_meta = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_item.__defaults__.nav_list_meta : arguments[6];
            var li_class = (arguments[7] === undefined || ( 7 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_item.__defaults__.li_class : arguments[7];
            var row_class = (arguments[8] === undefined || ( 8 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_item.__defaults__.row_class : arguments[8];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "action")){
                action = ρσ_kwargs_obj.action;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "subtitle")){
                subtitle = ρσ_kwargs_obj.subtitle;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "icon")){
                icon = ρσ_kwargs_obj.icon;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "data")){
                data = ρσ_kwargs_obj.data;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "side_actions")){
                side_actions = ρσ_kwargs_obj.side_actions;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "nav_list_meta")){
                nav_list_meta = ρσ_kwargs_obj.nav_list_meta;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "li_class")){
                li_class = ρσ_kwargs_obj.li_class;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "row_class")){
                row_class = ρσ_kwargs_obj.row_class;
            }
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["title"] = title;
                ρσ_d["action"] = action;
                ρσ_d["subtitle"] = subtitle;
                ρσ_d["icon"] = icon;
                ρσ_d["data"] = data;
                ρσ_d["side_actions"] = side_actions || [];
                ρσ_d["nav_list_meta"] = nav_list_meta;
                ρσ_d["li_class"] = li_class;
                ρσ_d["row_class"] = row_class;
                return ρσ_d;
            }).call(this);
        };
        if (!create_item.__defaults__) Object.defineProperties(create_item, {
            __defaults__ : {value: {action:null, subtitle:null, icon:null, data:null, side_actions:null, nav_list_meta:null, li_class:null, row_class:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title", "action", "subtitle", "icon", "data", "side_actions", "nav_list_meta", "li_class", "row_class"]},
            __module__ : {value: "book_list.item_list"}
        });

        function create_item_list() {
            var container = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var items = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var subtitle = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_item_list.__defaults__.subtitle : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "subtitle")){
                subtitle = ρσ_kwargs_obj.subtitle;
            }
            build_list(container, items, subtitle);
        };
        if (!create_item_list.__defaults__) Object.defineProperties(create_item_list, {
            __defaults__ : {value: {subtitle:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["container", "items", "subtitle"]},
            __module__ : {value: "book_list.item_list"}
        });

        ρσ_modules["book_list.item_list"].CLASS_NAME = CLASS_NAME;
        ρσ_modules["book_list.item_list"].side_action = side_action;
        ρσ_modules["book_list.item_list"].add_classes = add_classes;
        ρσ_modules["book_list.item_list"].build_list = build_list;
        ρσ_modules["book_list.item_list"].create_side_action = create_side_action;
        ρσ_modules["book_list.item_list"].create_item = create_item;
        ρσ_modules["book_list.item_list"].create_item_list = create_item_list;
    })();

    (function(){
        var __name__ = "read_book.open_book";
        var current_container_id, current_opened_book_path;
        var E = ρσ_modules.elementmaker.E;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var create_item = ρσ_modules["book_list.item_list"].create_item;
        var create_item_list = ρσ_modules["book_list.item_list"].create_item_list;

        var clear = ρσ_modules.dom.clear;
        var unique_id = ρσ_modules.dom.unique_id;

        var _ = ρσ_modules.gettext.gettext;

        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var create_button = ρσ_modules.widgets.create_button;

        current_container_id = null;
        current_opened_book_path = null;
        function create_open_book(container, book) {
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin: 1rem", id: unique_id()})]));
            container = container.lastChild;
            current_container_id = container.id;
            current_opened_book_path = null;
            if (book) {
                current_opened_book_path = book.manifest.pathtoebook;
            }
            rebuild_open_list(container);
        };
        if (!create_open_book.__argnames__) Object.defineProperties(create_open_book, {
            __argnames__ : {value: ["container", "book"]},
            __module__ : {value: "read_book.open_book"}
        });

        function rebuild_open_list(container) {
            var sd, rl, c, items, fname, entry;
            clear(container);
            container.appendChild(ρσ_interpolate_kwargs.call(this, create_button, [_("Open a book from your computer")].concat([ρσ_desugar_kwargs({action: ui_operations.ask_for_open.bind(null, null)})])));
            sd = get_session_data();
            rl = sd.get("standalone_recently_opened");
            if ((typeof rl !== "undefined" && rl !== null ? rl : Object.create(null)).length) {
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: unique_id()})]));
                c = container.lastChild;
                items = ρσ_list_decorate([]);
                c.appendChild(ρσ_interpolate_kwargs.call(E, E.h2, [_("Recently viewed books")].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem"})])));
                c.appendChild(E.div());
                var ρσ_Iter0 = ρσ_Iterable(rl);
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    entry = ρσ_Iter0[ρσ_Index0];
                    if (current_opened_book_path && current_opened_book_path === entry.pathtoebook) {
                        continue;
                    }
                    if (typeof entry.pathtoebook !== "string") {
                        continue;
                    }
                    fname = entry.pathtoebook.replace(/\\/g, "/");
                    if (ρσ_in("/", fname)) {
                        fname = (ρσ_expr_temp = fname.rpartition("/"))[ρσ_expr_temp.length-1];
                    }
                    items.push(create_item(entry.title || _("Unknown"), ui_operations.ask_for_open.bind(null, entry.pathtoebook), fname));
                }
                create_item_list(c.lastChild, items);
                c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin: 1rem"})]));
                c.lastChild.appendChild(ρσ_interpolate_kwargs.call(this, create_button, [_("Clear recent list")].concat([ρσ_desugar_kwargs({action: clear_recent_list.bind(null, c.id)})])));
            }
        };
        if (!rebuild_open_list.__argnames__) Object.defineProperties(rebuild_open_list, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.open_book"}
        });

        function clear_recent_list(container_id) {
            var sd;
            sd = get_session_data();
            sd.set("standalone_recently_opened", []);
            document.getElementById(container_id).style.display = "none";
        };
        if (!clear_recent_list.__argnames__) Object.defineProperties(clear_recent_list, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "read_book.open_book"}
        });

        function add_book_to_recently_viewed(book) {
            var sd, rl, key, new_entry, ans, entry;
            sd = get_session_data();
            rl = sd.get("standalone_recently_opened");
            key = book.manifest.pathtoebook;
            new_entry = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["key"] = key;
                ρσ_d["pathtoebook"] = book.manifest.pathtoebook;
                ρσ_d["title"] = book.metadata.title;
                ρσ_d["authors"] = book.metadata.authors;
                ρσ_d["timestamp"] = (new Date).toISOString();
                return ρσ_d;
            }).call(this);
            ans = [];
            ans.push(new_entry);
            var ρσ_Iter1 = ρσ_Iterable(rl);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                entry = ρσ_Iter1[ρσ_Index1];
                if (entry.key !== key) {
                    ans.push(entry);
                }
            }
            sd.set("standalone_recently_opened", ans.slice(0, 25));
            return ans;
        };
        if (!add_book_to_recently_viewed.__argnames__) Object.defineProperties(add_book_to_recently_viewed, {
            __argnames__ : {value: ["book"]},
            __module__ : {value: "read_book.open_book"}
        });

        function remove_recently_opened(path) {
            var sd, rl, newl, entry, container;
            sd = get_session_data();
            rl = sd.get("standalone_recently_opened");
            newl = [];
            if (path) {
                var ρσ_Iter2 = ρσ_Iterable(rl);
                for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                    entry = ρσ_Iter2[ρσ_Index2];
                    if (entry.key !== path) {
                        newl.push(entry);
                    }
                }
            }
            sd.set("standalone_recently_opened", newl);
            if (current_container_id) {
                container = document.getElementById(current_container_id);
                if (container) {
                    rebuild_open_list(container);
                }
            }
        };
        if (!remove_recently_opened.__argnames__) Object.defineProperties(remove_recently_opened, {
            __argnames__ : {value: ["path"]},
            __module__ : {value: "read_book.open_book"}
        });

        ρσ_modules["read_book.open_book"].current_container_id = current_container_id;
        ρσ_modules["read_book.open_book"].current_opened_book_path = current_opened_book_path;
        ρσ_modules["read_book.open_book"].create_open_book = create_open_book;
        ρσ_modules["read_book.open_book"].rebuild_open_list = rebuild_open_list;
        ρσ_modules["read_book.open_book"].clear_recent_list = clear_recent_list;
        ρσ_modules["read_book.open_book"].add_book_to_recently_viewed = add_book_to_recently_viewed;
        ρσ_modules["read_book.open_book"].remove_recently_opened = remove_recently_opened;
    })();

    (function(){
        var __name__ = "read_book.prefs";

    })();

    (function(){
        var __name__ = "read_book.prefs.utils";
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var create_button = ρσ_modules.widgets.create_button;

        function create_button_box(restore_defaults_func, apply_func, cancel_func) {
            var cbutton, rbutton, obutton, b;
            cbutton = ρσ_interpolate_kwargs.call(this, create_button, [_("Cancel")].concat([ρσ_desugar_kwargs({action: cancel_func})]));
            if (restore_defaults_func) {
                rbutton = ρσ_interpolate_kwargs.call(this, create_button, [_("Restore defaults")].concat([ρσ_desugar_kwargs({action: restore_defaults_func})]));
            } else {
                rbutton = E.div(" ");
            }
            obutton = ρσ_interpolate_kwargs.call(this, create_button, [_("OK")].concat([ρσ_desugar_kwargs({action: apply_func})]));
            var ρσ_Iter0 = ρσ_Iterable(ρσ_list_decorate([ rbutton, obutton, cbutton ]));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                b = ρσ_Iter0[ρσ_Index0];
                b.style.marginTop = "1ex";
            }
            return ρσ_interpolate_kwargs.call(E, E.div, [rbutton, ρσ_interpolate_kwargs.call(E, E.div, [obutton, E.div(" "), cbutton].concat([ρσ_desugar_kwargs({style: "margin-left: 1rem; display: flex; align-items: flex-start; flex-wrap: wrap"})]))].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem; display: flex; justify-content: space-between; align-items: flex-start"})]));
        };
        if (!create_button_box.__argnames__) Object.defineProperties(create_button_box, {
            __argnames__ : {value: ["restore_defaults_func", "apply_func", "cancel_func"]},
            __module__ : {value: "read_book.prefs.utils"}
        });

        ρσ_modules["read_book.prefs.utils"].create_button_box = create_button_box;
    })();

    (function(){
        var __name__ = "viewer";

    })();

    (function(){
        var __name__ = "viewer.constants";
        var FAKE_PROTOCOL, FAKE_HOST, CHARS_PER_PAGE;
        FAKE_PROTOCOL = "clbr";
        FAKE_HOST = "internal.invalid";
        CHARS_PER_PAGE = 2520;
        ρσ_modules["viewer.constants"].FAKE_PROTOCOL = FAKE_PROTOCOL;
        ρσ_modules["viewer.constants"].FAKE_HOST = FAKE_HOST;
        ρσ_modules["viewer.constants"].CHARS_PER_PAGE = CHARS_PER_PAGE;
    })();

    (function(){
        var __name__ = "read_book.prefs.head_foot";
        var CONTAINER, time_formatter;
        var svgicon = ρσ_modules.dom.svgicon;

        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var ngettext = ρσ_modules.gettext.ngettext;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var clear = ρσ_modules.dom.clear;
        var unique_id = ρσ_modules.dom.unique_id;

        var create_button_box = ρσ_modules["read_book.prefs.utils"].create_button_box;

        var current_book = ρσ_modules["read_book.globals"].current_book;

        var get_interface_data = ρσ_modules.session.get_interface_data;
        var session_defaults = ρσ_modules.session.session_defaults;

        var fmt_sidx = ρσ_modules.utils.fmt_sidx;

        var CHARS_PER_PAGE = ρσ_modules["viewer.constants"].CHARS_PER_PAGE;

        CONTAINER = unique_id("reader-hf-prefs");
        function create_item(region, label, style) {
            var s;
            function sep() {
                return ρσ_interpolate_kwargs.call(E, E.option, [" "].concat([ρσ_desugar_kwargs({disabled: true})]));
            };
            if (!sep.__module__) Object.defineProperties(sep, {
                __module__ : {value: "read_book.prefs.head_foot"}
            });

            function opt(label, name, selected) {
                return ρσ_interpolate_kwargs.call(E, E.option, [label].concat([ρσ_desugar_kwargs({id: name, value: name, selected: bool(selected)})]));
            };
            if (!opt.__argnames__) Object.defineProperties(opt, {
                __argnames__ : {value: ["label", "name", "selected"]},
                __module__ : {value: "read_book.prefs.head_foot"}
            });

            s = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.select, [opt(_("Empty"), "empty", true), sep(), opt(_("Book title"), "title"), opt(_("Authors"), "authors"), opt(_("Series"), "series"), sep(), opt(_("Top level section"), "top-section"), opt(_("Current section"), "section"), opt(_("View mode"), "view-mode"), opt(_("View mode as icon"), "view-mode-icon"), sep(), opt(_("Clock"), "clock"), opt(_("Controls button on hover"), "menu-icon-on-hover"), sep(), opt(_("Progress"), "progress"), opt(_("Time to read book"), "time-book"), opt(_("Time to read chapter"), "time-chapter"), opt(_("Time to read chapter and book"), "time-chapter-book"), opt(_("Position in book"), "pos-book"), opt(_("Position in chapter"), "pos-chapter"), opt(_("Pages in chapter"), "pages-progress"), opt(_("Pages from paper edition"), "page-list"), opt(_("Pages from paper edition with total"), "page-list-with-total")].concat([ρσ_desugar_kwargs({data_region: region})])), E.span(svgicon("angle-down"))].concat([ρσ_desugar_kwargs({data_component: "select"})]));
            return ρσ_interpolate_kwargs.call(E, E.tr, [ρσ_interpolate_kwargs.call(E, E.td, [label + ":"].concat([ρσ_desugar_kwargs({style: "padding: 1ex 1rem"})])), E.td(s)].concat([ρσ_desugar_kwargs({style: style || ""})]));
        };
        if (!create_item.__argnames__) Object.defineProperties(create_item, {
            __argnames__ : {value: ["region", "label", "style"]},
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        function create_items(which) {
            var ans;
            if (which === "header" || which === "footer") {
                ans = ρσ_interpolate_kwargs.call(E, E.table, [create_item("left", _("Left")), create_item("middle", _("Middle")), create_item("right", _("Right"))].concat([ρσ_desugar_kwargs({data_which: which})]));
            } else if (which === "controls_footer") {
                ans = ρσ_interpolate_kwargs.call(E, E.table, [create_item("left", _("Left"), "display: none"), create_item("middle", _("Middle")), create_item("right", _("Right"))].concat([ρσ_desugar_kwargs({data_which: which})]));
            } else {
                ans = ρσ_interpolate_kwargs.call(E, E.table, [create_item("left", _("Top")), create_item("middle", _("Middle")), create_item("right", _("Bottom"))].concat([ρσ_desugar_kwargs({data_which: which})]));
            }
            return ans;
        };
        if (!create_items.__argnames__) Object.defineProperties(create_items, {
            __argnames__ : {value: ["which"]},
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        function apply_setting(table, val) {
            var sel, opt, x, region;
            var ρσ_Iter0 = ρσ_Iterable("left middle right".split(" "));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                region = ρσ_Iter0[ρσ_Index0];
                sel = table.querySelector("select[data-region=" + ρσ_str.format("{}", region) + "]");
                var ρσ_Iter1 = ρσ_Iterable(sel.selectedOptions);
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    opt = ρσ_Iter1[ρσ_Index1];
                    opt.selected = false;
                }
                x = val[(typeof region === "number" && region < 0) ? val.length + region : region] || "empty";
                opt = sel.namedItem(x);
                if (opt) {
                    opt.selected = true;
                } else {
                    sel.selectedIndex = 0;
                }
            }
        };
        if (!apply_setting.__argnames__) Object.defineProperties(apply_setting, {
            __argnames__ : {value: ["table", "val"]},
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        function get_setting(table) {
            var ans, sel, region;
            ans = Object.create(null);
            var ρσ_Iter2 = ρσ_Iterable("left middle right".split(" "));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                region = ρσ_Iter2[ρσ_Index2];
                sel = table.querySelector("select[data-region=" + ρσ_str.format("{}", region) + "]");
                if (sel.selectedIndex > -1) {
                    ans[(typeof region === "number" && region < 0) ? ans.length + region : region] = (ρσ_expr_temp = sel.options)[ρσ_bound_index(sel.selectedIndex, ρσ_expr_temp)].value;
                }
            }
            return ans;
        };
        if (!get_setting.__argnames__) Object.defineProperties(get_setting, {
            __argnames__ : {value: ["table"]},
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        function groups() {
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["header"] = _("Header");
                ρσ_d["footer"] = _("Footer");
                ρσ_d["left-margin"] = _("Left margin");
                ρσ_d["right-margin"] = _("Right margin");
                ρσ_d["controls_footer"] = _("Controls footer");
                return ρσ_d;
            }).call(this);
        };
        if (!groups.__module__) Object.defineProperties(groups, {
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        function restore_defaults() {
            var container, table, which;
            container = document.getElementById(CONTAINER);
            var ρσ_Iter3 = ρσ_Iterable(Object.keys(groups()));
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                which = ρσ_Iter3[ρσ_Index3];
                table = container.querySelector("table[data-which=" + ρσ_str.format("{}", which) + "]");
                apply_setting(table, (ρσ_expr_temp = session_defaults())[(typeof which === "number" && which < 0) ? ρσ_expr_temp.length + which : which] || Object.create(null));
            }
        };
        if (!restore_defaults.__module__) Object.defineProperties(restore_defaults, {
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        function create_head_foot_panel(container, apply_func, cancel_func) {
            var gr, s, key, sd, table, which;
            gr = groups();
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: CONTAINER})]));
            container = container.lastChild;
            var ρσ_Iter4 = ρσ_Iterable(gr);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                key = ρσ_Iter4[ρσ_Index4];
                s = "margin: 1rem;";
                if (container.childNodes.length > 0) {
                    s += "margin-top: 0;";
                }
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.h4, [gr[(typeof key === "number" && key < 0) ? gr.length + key : key]].concat([ρσ_desugar_kwargs({style: s})])));
                container.appendChild(create_items(key));
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.hr, [ρσ_desugar_kwargs({style: "margin-top: 1ex; margin-bottom: 1ex"})]));
            }
            container.removeChild(container.lastChild);
            sd = get_session_data();
            var ρσ_Iter5 = ρσ_Iterable(Object.keys(gr));
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                which = ρσ_Iter5[ρσ_Index5];
                table = container.querySelector("table[data-which=" + ρσ_str.format("{}", which) + "]");
                apply_setting(table, sd.get(which) || Object.create(null));
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_button_box(restore_defaults, apply_func, cancel_func)].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
        };
        if (!create_head_foot_panel.__argnames__) Object.defineProperties(create_head_foot_panel, {
            __argnames__ : {value: ["container", "apply_func", "cancel_func"]},
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        function commit_head_foot(onchange, container) {
            var sd, changed, prev, table, current, region, which;
            sd = get_session_data();
            changed = false;
            var ρσ_Iter6 = ρσ_Iterable(Object.keys(groups()));
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                which = ρσ_Iter6[ρσ_Index6];
                prev = sd.get(which) || Object.create(null);
                table = container.querySelector("table[data-which=" + ρσ_str.format("{}", which) + "]");
                current = get_setting(table);
                var ρσ_Iter7 = ρσ_Iterable("left middle right".split(" "));
                for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                    region = ρσ_Iter7[ρσ_Index7];
                    if (prev[(typeof region === "number" && region < 0) ? prev.length + region : region] !== current[(typeof region === "number" && region < 0) ? current.length + region : region]) {
                        changed = true;
                    }
                }
                sd.set(which, get_setting(table));
            }
            if (changed) {
                onchange();
            }
        };
        if (!commit_head_foot.__argnames__) Object.defineProperties(commit_head_foot, {
            __argnames__ : {value: ["onchange", "container"]},
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        if (ρσ_exists.d((typeof window !== "undefined" && window !== null ? window : Object.create(null)).Intl).DateTimeFormat) {
            time_formatter = window.Intl.DateTimeFormat(undefined, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["hour"] = "numeric";
                ρσ_d["minute"] = "numeric";
                return ρσ_d;
            }).call(this));
        } else {
            time_formatter = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["format"] = (function() {
                    var ρσ_anonfunc = function (date) {
                        return "{}:{}".format(date.getHours(), date.getMinutes());
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["date"]},
                        __module__ : {value: "read_book.prefs.head_foot"}
                    });
                    return ρσ_anonfunc;
                })();
                return ρσ_d;
            }).call(this);
        }
        function set_time_formatter(func) {
            time_formatter = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["format"] = func;
                return ρσ_d;
            }).call(this);
        };
        if (!set_time_formatter.__argnames__) Object.defineProperties(set_time_formatter, {
            __argnames__ : {value: ["func"]},
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        function format_time_left(seconds) {
            var ρσ_unpack, hours, minutes;
            ρσ_unpack = divmod(int(seconds / 60), 60);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            hours = ρσ_unpack[0];
            minutes = ρσ_unpack[1];
            if (hours <= 0) {
                if (minutes < 1) {
                    return _("almost done");
                }
                minutes = minutes;
                return ngettext("{} min", "{} mins", minutes).format(minutes);
            }
            if (!minutes) {
                return ngettext("{} hour", "{} hours", hours).format(hours);
            }
            return _("{} h {} mins").format(hours, minutes);
        };
        if (!format_time_left.__argnames__) Object.defineProperties(format_time_left, {
            __argnames__ : {value: ["seconds"]},
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        function format_pos(progress_frac, length) {
            var pages, pos;
            if (length < 1) {
                return "";
            }
            pages = Math.ceil(length / CHARS_PER_PAGE);
            pos = progress_frac * pages;
            return "" + ρσ_str.format("{:.1f}", pos) + " / " + ρσ_str.format("{}", pages) + "";
        };
        if (!format_pos.__argnames__) Object.defineProperties(format_pos, {
            __argnames__ : {value: ["progress_frac", "length"]},
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        function render_head_foot(div, which, region, metadata, current_toc_node, current_toc_toplevel_node, page_list, book_time, chapter_time, pos, override, view_mode) {
            var template, field, interface_data, text, has_clock, force_display_even_if_overflowed, percent, ival, full_page_list;
            template = get_session_data().get(which) || Object.create(null);
            field = template[(typeof region === "number" && region < 0) ? template.length + region : region] || "empty";
            interface_data = get_interface_data();
            text = "";
            has_clock = false;
            div.style.textOverflow = "ellipsis";
            div.style.overflow = "hidden";
            force_display_even_if_overflowed = false;
            if (override) {
                text = override;
            } else if (field === "menu-icon-on-hover") {
                clear(div);
                div.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.span(_("Show controls"))].concat([ρσ_desugar_kwargs({class_: "visible-on-hover", title: _("Show viewer controls"), style: "cursor: pointer"})])));
                return has_clock;
            } else if (field === "progress") {
                percent = min(100, max(Math.round(pos.progress_frac * 100), 0));
                text = percent + "%";
                force_display_even_if_overflowed = true;
            } else if (field === "title") {
                text = metadata.title || _("Untitled");
            } else if (field === "authors") {
                text = " & ".join(metadata.authors || []);
            } else if (field === "series") {
                if (metadata.series) {
                    ival = ρσ_interpolate_kwargs.call(this, fmt_sidx, [metadata.series_index].concat([ρσ_desugar_kwargs({use_roman: interface_data.use_roman_numerals_for_series_number})]));
                    text = _("{0} of {1}").format(ival, metadata.series);
                }
            } else if (field === "clock") {
                force_display_even_if_overflowed = true;
                text = time_formatter.format(new Date);
                has_clock = true;
            } else if (field === "section") {
                text = (current_toc_node) ? current_toc_node.title : "";
            } else if (field === "top-section") {
                text = (current_toc_toplevel_node) ? current_toc_toplevel_node.title : "";
                if (!text) {
                    text = (current_toc_node) ? current_toc_node.title : "";
                }
            } else if (field === "view-mode") {
                text = (view_mode === "paged") ? _("Paged") : _("Flow");
            } else if (field === "view-mode-icon") {
                text = (view_mode === "paged") ? "📄" : "📜";
            } else if (field.startswith("time-")) {
                if (book_time === null || chapter_time === null) {
                    text = _("Calculating...");
                } else {
                    if (field === "time-book") {
                        text = format_time_left(book_time);
                    } else if (field === "time-chapter") {
                        text = format_time_left(chapter_time);
                    } else {
                        text = "{} ({})".format(format_time_left(chapter_time), format_time_left(book_time));
                    }
                }
            } else if (field.startswith("pos-")) {
                if (field === "pos-book") {
                    text = format_pos(pos.progress_frac, pos.book_length);
                } else {
                    text = format_pos(pos.file_progress_frac, pos.chapter_length);
                }
            } else if (field === "pages-progress") {
                if (pos.page_counts) {
                    text = "" + ρσ_str.format("{}", pos.page_counts.current + 1) + " / " + ρσ_str.format("{}", pos.page_counts.total) + "";
                } else {
                    text = _("Unknown");
                }
            } else if (field === "page-list") {
                if (page_list && page_list.length > 0) {
                    if (page_list.length === 1) {
                        text = page_list[0].pagenum;
                    } else {
                        text = "" + ρσ_str.format("{}", page_list[0].pagenum) + " - " + ρσ_str.format("{}", page_list[page_list.length-1].pagenum) + "";
                    }
                }
            } else if (field === "page-list-with-total") {
                if (page_list && page_list.length > 0) {
                    if (page_list.length === 1) {
                        text = page_list[0].pagenum;
                    } else {
                        text = "" + ρσ_str.format("{}", page_list[0].pagenum) + " - " + ρσ_str.format("{}", page_list[page_list.length-1].pagenum) + "";
                    }
                    full_page_list = current_book().manifest.page_list;
                    if (full_page_list) {
                        text = "" + ρσ_str.format("{}", text) + " / " + ρσ_str.format("{}", full_page_list[full_page_list.length-1].pagenum) + "";
                    }
                }
            }
            if (!text) {
                text = " ";
            }
            if (text !== div.textContent) {
                div.textContent = text;
            }
            if (force_display_even_if_overflowed) {
                div.style.textOverflow = "clip";
                div.style.overflow = "visible";
            }
            return has_clock;
        };
        if (!render_head_foot.__argnames__) Object.defineProperties(render_head_foot, {
            __argnames__ : {value: ["div", "which", "region", "metadata", "current_toc_node", "current_toc_toplevel_node", "page_list", "book_time", "chapter_time", "pos", "override", "view_mode"]},
            __module__ : {value: "read_book.prefs.head_foot"}
        });

        ρσ_modules["read_book.prefs.head_foot"].CONTAINER = CONTAINER;
        ρσ_modules["read_book.prefs.head_foot"].time_formatter = time_formatter;
        ρσ_modules["read_book.prefs.head_foot"].create_item = create_item;
        ρσ_modules["read_book.prefs.head_foot"].create_items = create_items;
        ρσ_modules["read_book.prefs.head_foot"].apply_setting = apply_setting;
        ρσ_modules["read_book.prefs.head_foot"].get_setting = get_setting;
        ρσ_modules["read_book.prefs.head_foot"].groups = groups;
        ρσ_modules["read_book.prefs.head_foot"].restore_defaults = restore_defaults;
        ρσ_modules["read_book.prefs.head_foot"].create_head_foot_panel = create_head_foot_panel;
        ρσ_modules["read_book.prefs.head_foot"].commit_head_foot = commit_head_foot;
        ρσ_modules["read_book.prefs.head_foot"].set_time_formatter = set_time_formatter;
        ρσ_modules["read_book.prefs.head_foot"].format_time_left = format_time_left;
        ρσ_modules["read_book.prefs.head_foot"].format_pos = format_pos;
        ρσ_modules["read_book.prefs.head_foot"].render_head_foot = render_head_foot;
    })();

    (function(){
        var __name__ = "book_list.cover_grid";
        var COVER_GRID_CLASS, COVER_GRID_VIEWPORT_FRAC, COVER_GRID_PCT_DEFAULT, COVER_GRID_PCT_MIN, COVER_GRID_PCT_MAX, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, THUMBNAIL_MIN_WIDTH, THUMBNAIL_MIN_HEIGHT, BORDER_RADIUS, COVER_GRID_ROW_GAP;
        var clear = ρσ_modules.dom.clear;
        var set_css = ρσ_modules.dom.set_css;
        var build_rule = ρσ_modules.dom.build_rule;

        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        COVER_GRID_CLASS = "book-list-cover-grid";
        COVER_GRID_VIEWPORT_FRAC = .165;
        COVER_GRID_PCT_DEFAULT = Math.round(100 * COVER_GRID_VIEWPORT_FRAC);
        COVER_GRID_PCT_MIN = 8;
        COVER_GRID_PCT_MAX = 45;
        THUMBNAIL_MAX_WIDTH = 3 * 85;
        THUMBNAIL_MAX_HEIGHT = int(THUMBNAIL_MAX_WIDTH * 3 / 2);
        THUMBNAIL_MIN_WIDTH = 3 * 16;
        THUMBNAIL_MIN_HEIGHT = int(THUMBNAIL_MIN_WIDTH * 3 / 2);
        BORDER_RADIUS = 10;
        COVER_GRID_ROW_GAP = 10;
        function cover_grid_column_layout(container_w, tile_px, row_gap) {
            var W, T, R, n_hi, n_cap, n, g, cand, g_try;
            W = float(container_w);
            T = float(tile_px);
            R = float(row_gap);
            if (W < 32 || T < 1) {
                return [1, 0];
            }
            n_hi = int(Math.floor((W + R) / (T + R)));
            n_cap = int(Math.floor(W / T));
            if (n_hi > n_cap) {
                n_hi = n_cap;
            }
            if (n_hi < 1) {
                n_hi = 1;
            }
            n = 1;
            g = 0;
            if (n_hi >= 2) {
                cand = n_hi;
                while (cand >= 2) {
                    g_try = (W - cand * T) / (cand - 1);
                    if (g_try + 1e-6 >= R && g_try <= T + 1e-6) {
                        n = cand;
                        g = g_try;
                        break;
                    }
                    cand -= 1;
                }
            }
            return [n, g];
        };
        if (!cover_grid_column_layout.__argnames__) Object.defineProperties(cover_grid_column_layout, {
            __argnames__ : {value: ["container_w", "tile_px", "row_gap"]},
            __module__ : {value: "book_list.cover_grid"}
        });

        function get_cover_grid_pct() {
            var raw, n;
            raw = get_session_data().get("cover_grid_tile_pct", COVER_GRID_PCT_DEFAULT);
            if (typeof raw === "number") {
                n = raw;
            } else {
                n = parseFloat(str(raw));
            }
            if ((n !== n && (typeof n !== "object" || ρσ_not_equals(n, n)))) {
                n = COVER_GRID_PCT_DEFAULT;
            }
            return Math.max(COVER_GRID_PCT_MIN, Math.min(COVER_GRID_PCT_MAX, n));
        };
        if (!get_cover_grid_pct.__module__) Object.defineProperties(get_cover_grid_pct, {
            __module__ : {value: "book_list.cover_grid"}
        });

        function sync_cover_grid_tile_px() {
            var grid, cw, pct, px, ρσ_unpack, n_cols, col_gap;
            grid = document.querySelector("." + COVER_GRID_CLASS);
            if (!grid) {
                return;
            }
            cw = grid.clientWidth;
            if (cw < 32) {
                return;
            }
            pct = get_cover_grid_pct();
            px = Math.round(cw * pct / 100);
            px = Math.max(THUMBNAIL_MIN_WIDTH, Math.min(THUMBNAIL_MAX_WIDTH, px));
            grid.style.setProperty("--cs-cover-tile-px", str(px) + "px");
            ρσ_unpack = cover_grid_column_layout(cw, px, COVER_GRID_ROW_GAP);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            n_cols = ρσ_unpack[0];
            col_gap = ρσ_unpack[1];
            grid.style.gridTemplateColumns = "repeat(" + str(n_cols) + ", " + str(px) + "px)";
            grid.style.rowGap = str(COVER_GRID_ROW_GAP) + "px";
            if (n_cols > 1) {
                grid.style.columnGap = str(col_gap) + "px";
            } else {
                grid.style.columnGap = "0px";
            }
        };
        if (!sync_cover_grid_tile_px.__module__) Object.defineProperties(sync_cover_grid_tile_px, {
            __module__ : {value: "book_list.cover_grid"}
        });

        function apply_cover_grid_pct_css() {
            var raf;
            document.documentElement.style.setProperty("--cs-cover-grid-pct", str(get_cover_grid_pct()));
            sync_cover_grid_tile_px();
            raf = window.requestAnimationFrame;
            if (raf) {
                raf(sync_cover_grid_tile_px);
            } else {
                window.setTimeout(sync_cover_grid_tile_px, 0);
            }
        };
        if (!apply_cover_grid_pct_css.__module__) Object.defineProperties(apply_cover_grid_pct_css, {
            __module__ : {value: "book_list.cover_grid"}
        });

        function ensure_cover_grid_resize_listener() {
            if (window.cs_cover_grid_resize_bound) {
                return;
            }
            window.cs_cover_grid_resize_bound = true;
            function on_resize(ev) {
                apply_cover_grid_pct_css();
            };
            if (!on_resize.__argnames__) Object.defineProperties(on_resize, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.cover_grid"}
            });

            window.addEventListener("resize", on_resize, false);
        };
        if (!ensure_cover_grid_resize_listener.__module__) Object.defineProperties(ensure_cover_grid_resize_listener, {
            __module__ : {value: "book_list.cover_grid"}
        });

        function attach_cover_grid_resize_observer(grid) {
            var obs;
            if (window.cs_cover_grid_resize_observer) {
                window.cs_cover_grid_resize_observer.disconnect();
                window.cs_cover_grid_resize_observer = null;
            }
            if (!window.ResizeObserver) {
                return;
            }
            function on_observed(entries) {
                var raf;
                if (window.cs_cover_grid_tile_sync_scheduled) {
                    return;
                }
                window.cs_cover_grid_tile_sync_scheduled = true;
                function flush() {
                    window.cs_cover_grid_tile_sync_scheduled = false;
                    sync_cover_grid_tile_px();
                };
                if (!flush.__module__) Object.defineProperties(flush, {
                    __module__ : {value: "book_list.cover_grid"}
                });

                raf = window.requestAnimationFrame;
                if (raf) {
                    raf(flush);
                } else {
                    window.setTimeout(flush, 0);
                }
            };
            if (!on_observed.__argnames__) Object.defineProperties(on_observed, {
                __argnames__ : {value: ["entries"]},
                __module__ : {value: "book_list.cover_grid"}
            });

            obs = new window.ResizeObserver(on_observed);
            obs.observe(grid);
            window.cs_cover_grid_resize_observer = obs;
        };
        if (!attach_cover_grid_resize_observer.__argnames__) Object.defineProperties(attach_cover_grid_resize_observer, {
            __argnames__ : {value: ["grid"]},
            __module__ : {value: "book_list.cover_grid"}
        });

        function on_cover_grid_size_input(ev) {
            var v;
            v = parseFloat(ev.target.value);
            if ((v !== v && (typeof v !== "object" || ρσ_not_equals(v, v)))) {
                return;
            }
            v = Math.max(COVER_GRID_PCT_MIN, Math.min(COVER_GRID_PCT_MAX, v));
            v = Math.round(v * 40) / 40;
            get_session_data().set("cover_grid_tile_pct", v);
            apply_cover_grid_pct_css();
        };
        if (!on_cover_grid_size_input.__argnames__) Object.defineProperties(on_cover_grid_size_input, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "book_list.cover_grid"}
        });

        function sync_cover_grid_size_control(control, mode) {
            var r;
            if (!control) {
                return;
            }
            r = control.querySelector(".cs-cover-grid-size-range");
            if (r) {
                r.value = str(get_cover_grid_pct());
            }
            if (mode === "cover_grid") {
                ensure_cover_grid_resize_listener();
                apply_cover_grid_pct_css();
                ρσ_interpolate_kwargs.call(this, set_css, [control].concat([ρσ_desugar_kwargs({display: "inline-flex"})]));
            } else {
                ρσ_interpolate_kwargs.call(this, set_css, [control].concat([ρσ_desugar_kwargs({display: "none"})]));
            }
        };
        if (!sync_cover_grid_size_control.__argnames__) Object.defineProperties(sync_cover_grid_size_control, {
            __argnames__ : {value: ["control", "mode"]},
            __module__ : {value: "book_list.cover_grid"}
        });

        function create_cover_grid_size_control(mode) {
            var lab, r, control;
            lab = ρσ_interpolate_kwargs.call(E, E.span, [ρσ_desugar_kwargs({class_: "cs-cover-grid-size-label"})]);
            lab.textContent = _("Cover size");
            r = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "range", class_: "cs-cover-grid-size-range", min: str(COVER_GRID_PCT_MIN), max: str(COVER_GRID_PCT_MAX), step: "0.025"})]);
            r.value = str(get_cover_grid_pct());
            r.title = _("Adjust cover grid tile size");
            r.addEventListener("input", on_cover_grid_size_input);
            control = ρσ_interpolate_kwargs.call(E, E.div, [lab, r].concat([ρσ_desugar_kwargs({class_: "cs-cover-grid-size-control"})]));
            control.setAttribute("role", "group");
            control.setAttribute("aria-label", _("Cover grid size"));
            sync_cover_grid_size_control(control, mode);
            return control;
        };
        if (!create_cover_grid_size_control.__argnames__) Object.defineProperties(create_cover_grid_size_control, {
            __argnames__ : {value: ["mode"]},
            __module__ : {value: "book_list.cover_grid"}
        });

        function cover_grid_thumb_size() {
            var frac, grid, base, w, h;
            frac = get_cover_grid_pct() / 100;
            grid = document.querySelector("." + COVER_GRID_CLASS);
            base = (grid && grid.clientWidth > 40) ? grid.clientWidth : 0;
            if (!base) {
                base = window.innerWidth;
            }
            w = Math.round(base * frac);
            h = Math.round(w * 3 / 2);
            w = Math.max(THUMBNAIL_MIN_WIDTH, Math.min(w, THUMBNAIL_MAX_WIDTH));
            h = Math.max(THUMBNAIL_MIN_HEIGHT, Math.min(h, THUMBNAIL_MAX_HEIGHT));
            return [w, h];
        };
        if (!cover_grid_thumb_size.__module__) Object.defineProperties(cover_grid_thumb_size, {
            __module__ : {value: "book_list.cover_grid"}
        });

        function description() {
            return _("A grid of book covers");
        };
        if (!description.__module__) Object.defineProperties(description, {
            __module__ : {value: "book_list.cover_grid"}
        });

        function cover_grid_css() {
            var grid_root, sel, item_sel, margin_unit, ans;
            grid_root = "." + COVER_GRID_CLASS;
            sel = grid_root;
            item_sel = sel + " > a";
            margin_unit = "px";
            ans = ":root { --cs-cover-grid-pct: %s; }\n" % COVER_GRID_PCT_DEFAULT;
            ans += ".book-list-cover-grid { --cs-cover-tile-px: 120px; }\n";
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({display: "grid", justify_items: "stretch", align_items: "end", justify_content: "start", user_select: "none", overflow: "visible", position: "relative", margin_top: "5" + margin_unit, row_gap: str(COVER_GRID_ROW_GAP) + margin_unit, column_gap: "0" + margin_unit, width: "100%", min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [".book-list-container .cs-book-list-wrap, .local-books-list .cs-book-list-wrap"].concat([ρσ_desugar_kwargs({width: "100%", min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [".book-list-container [data-component=\"book_list\"], .local-books-list [data-component=\"book_list\"]"].concat([ρσ_desugar_kwargs({display: "block", width: "100%", min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
            sel = item_sel;
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({margin: "0", display: "block", width: "100%", min_width: "0", max_width: "100%", height: "auto", aspect_ratio: "2 / 3", cursor: "pointer", position: "relative", overflow: "visible", box_sizing: "border-box", transition: "background-color 160ms ease, width 0.2s ease", container_type: "inline-size"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", sel) + ":hover"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light)"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", sel) + ":active"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light-2)"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", item_sel) + " > .cs-cover-frame"].concat([ρσ_desugar_kwargs({position: "relative", width: "100%", height: "100%", overflow: "hidden", border_radius: BORDER_RADIUS + "px", box_shadow: "0 clamp(10px, 1.8vh, 14px) clamp(26px, 4.2vh, 48px) rgba(0,0,0,0.18)", border: "var(--calibre-border-style-subtle)", background_color: "rgba(0,0,0,0.02)", transition: "box-shadow 160ms ease, background-color 160ms ease, border-color 160ms ease"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", item_sel) + ":hover > .cs-cover-frame"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light)", border_color: "var(--calibre-color-border)", box_shadow: "0 clamp(14px, 2.6vh, 18px) clamp(34px, 5.2vh, 62px) rgba(0,0,0,0.24), 0 0 0 4px var(--calibre-color-primary-light)"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", item_sel) + " .cs-cover-frame > .cs-cover-mask"].concat([ρσ_desugar_kwargs({position: "absolute", left: "0", right: "0", bottom: "0", padding: "0.85rem 0.75rem 0.6rem 0.75rem", display: "flex", flex_direction: "column", gap: "0.25rem", justify_content: "flex-end", align_items: "stretch", text_align: "right", background: "linear-gradient(to top, rgba(0,0,0,0.97) 0%, rgba(0,0,0,0.88) 18%, rgba(0,0,0,0.62) 48%, rgba(0,0,0,0.20) 78%, rgba(0,0,0,0.0) 100%)", color: "rgba(255,255,255,0.97)", text_shadow: "0 2px 10px rgba(0,0,0,0.65)", pointer_events: "none"})]));
            ans += "\n@container (max-width: 10ch) {\n                .cs-cover-mask { display: none !important; }\n            }\n            ";
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", item_sel) + " .cs-cover-frame > .cs-cover-mask .cs-cover-mask-title"].concat([ρσ_desugar_kwargs({font_size: "0.95rem", font_weight: "800", width: "100%", white_space: "nowrap", overflow: "hidden", text_overflow: "ellipsis"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", item_sel) + " .cs-cover-frame > .cs-cover-mask .cs-cover-mask-authors"].concat([ρσ_desugar_kwargs({font_size: "0.82rem", font_weight: "600", opacity: "0.92", width: "100%", white_space: "nowrap", overflow: "hidden", text_overflow: "ellipsis"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [grid_root + " > .cover-grid-filler"].concat([ρσ_desugar_kwargs({position: "absolute", left: "0", top: "0", width: "1px", height: "1px", margin: "0", padding: "0", overflow: "hidden", visibility: "hidden", pointer_events: "none", z_index: "-1"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " > div"].concat([ρσ_desugar_kwargs({position: "relative", top: "-50%", transform: "translateY(50%)", margin: "0"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", item_sel) + " .cs-cover-frame > img"].concat([ρσ_desugar_kwargs({width: "100%", height: "100%", display: "block", object_fit: "cover"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [".cs-cover-grid-size-control"].concat([ρσ_desugar_kwargs({display: "inline-flex", align_items: "center", gap: "0.65rem", flex: "1 1 15rem", min_width: "min(100%, 13rem)", max_width: "24rem", box_sizing: "border-box"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [".cs-cover-grid-size-control .cs-cover-grid-size-label"].concat([ρσ_desugar_kwargs({font_size: "0.88rem", font_weight: "600", opacity: "0.88", white_space: "nowrap", flex_shrink: "0"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [".cs-cover-grid-size-control .cs-cover-grid-size-range"].concat([ρσ_desugar_kwargs({flex: "1 1 auto", min_width: "3rem", margin: "0"})]));
            return ans;
        };
        if (!cover_grid_css.__module__) Object.defineProperties(cover_grid_css, {
            __module__ : {value: "book_list.cover_grid"}
        });

        function init(container) {
            var i;
            clear(container);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: COVER_GRID_CLASS})]));
            for (var ρσ_Index0 = 0; ρσ_Index0 < 12; ρσ_Index0++) {
                i = ρσ_Index0;
                container.lastChild.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cover-grid-filler"})]));
            }
            ensure_cover_grid_resize_listener();
            attach_cover_grid_resize_observer(container.lastChild);
            apply_cover_grid_pct_css();
        };
        if (!init.__argnames__) Object.defineProperties(init, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.cover_grid"}
        });

        function on_img_load(img, load_type) {
            var div;
            div = img.parentNode;
            if (!div) {
                return;
            }
            if (load_type !== "load") {
                clear(div);
                div.appendChild(E.div(ρσ_interpolate_kwargs.call(E, E.h2, [img.dataset.title].concat([ρσ_desugar_kwargs({style: "text-align:center; font-size:larger; font-weight: bold"})])), ρσ_interpolate_kwargs.call(E, E.div, [_("by")].concat([ρσ_desugar_kwargs({style: "text-align: center"})])), ρσ_interpolate_kwargs.call(E, E.h2, [img.dataset.authors].concat([ρσ_desugar_kwargs({style: "text-align:center; font-size:larger; font-weight: bold"})]))));
                ρσ_interpolate_kwargs.call(this, set_css, [div].concat([ρσ_desugar_kwargs({border: "dashed 1px currentColor", border_radius: BORDER_RADIUS + "px"})]));
            }
        };
        if (!on_img_load.__argnames__) Object.defineProperties(on_img_load, {
            __argnames__ : {value: ["img", "load_type"]},
            __module__ : {value: "book_list.cover_grid"}
        });

        function create_item(book_id, metadata, create_image, show_book_details, href) {
            var authors, ρσ_unpack, w, h, img, tooltip, mask, frame, ans;
            authors = (metadata.authors) ? metadata.authors.join(" & ") : _("Unknown");
            ρσ_unpack = cover_grid_thumb_size();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            w = ρσ_unpack[0];
            h = ρσ_unpack[1];
            img = create_image(book_id, w, h, on_img_load);
            tooltip = _("{} by {}").format(metadata.title, authors);
            img.setAttribute("alt", tooltip);
            ρσ_unpack = [metadata.title, authors];
            img.dataset.title = ρσ_unpack[0];
            img.dataset.authors = ρσ_unpack[1];
            mask = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [metadata.title || ""].concat([ρσ_desugar_kwargs({class_: "cs-cover-mask-title"})])), ρσ_interpolate_kwargs.call(E, E.div, [authors || ""].concat([ρσ_desugar_kwargs({class_: "cs-cover-mask-authors"})]))].concat([ρσ_desugar_kwargs({class_: "cs-cover-mask"})]));
            frame = ρσ_interpolate_kwargs.call(E, E.div, [img, mask].concat([ρσ_desugar_kwargs({class_: "cs-cover-frame"})]));
            ans = ρσ_interpolate_kwargs.call(E, E.a, [frame].concat([ρσ_desugar_kwargs({onclick: show_book_details, title: tooltip, href: href})]));
            return ans;
        };
        if (!create_item.__argnames__) Object.defineProperties(create_item, {
            __argnames__ : {value: ["book_id", "metadata", "create_image", "show_book_details", "href"]},
            __module__ : {value: "book_list.cover_grid"}
        });

        function append_item(container, item) {
            var first_filler, raf;
            first_filler = container.lastChild.querySelector(".cover-grid-filler");
            container.lastChild.insertBefore(item, first_filler);
            if (window.cs_cover_grid_tile_sync_scheduled) {
                return;
            }
            window.cs_cover_grid_tile_sync_scheduled = true;
            function flush() {
                window.cs_cover_grid_tile_sync_scheduled = false;
                apply_cover_grid_pct_css();
            };
            if (!flush.__module__) Object.defineProperties(flush, {
                __module__ : {value: "book_list.cover_grid"}
            });

            raf = window.requestAnimationFrame;
            if (raf) {
                raf(flush);
            } else {
                window.setTimeout(flush, 0);
            }
        };
        if (!append_item.__argnames__) Object.defineProperties(append_item, {
            __argnames__ : {value: ["container", "item"]},
            __module__ : {value: "book_list.cover_grid"}
        });

        ρσ_modules["book_list.cover_grid"].COVER_GRID_CLASS = COVER_GRID_CLASS;
        ρσ_modules["book_list.cover_grid"].COVER_GRID_VIEWPORT_FRAC = COVER_GRID_VIEWPORT_FRAC;
        ρσ_modules["book_list.cover_grid"].COVER_GRID_PCT_DEFAULT = COVER_GRID_PCT_DEFAULT;
        ρσ_modules["book_list.cover_grid"].COVER_GRID_PCT_MIN = COVER_GRID_PCT_MIN;
        ρσ_modules["book_list.cover_grid"].COVER_GRID_PCT_MAX = COVER_GRID_PCT_MAX;
        ρσ_modules["book_list.cover_grid"].THUMBNAIL_MAX_WIDTH = THUMBNAIL_MAX_WIDTH;
        ρσ_modules["book_list.cover_grid"].THUMBNAIL_MAX_HEIGHT = THUMBNAIL_MAX_HEIGHT;
        ρσ_modules["book_list.cover_grid"].THUMBNAIL_MIN_WIDTH = THUMBNAIL_MIN_WIDTH;
        ρσ_modules["book_list.cover_grid"].THUMBNAIL_MIN_HEIGHT = THUMBNAIL_MIN_HEIGHT;
        ρσ_modules["book_list.cover_grid"].BORDER_RADIUS = BORDER_RADIUS;
        ρσ_modules["book_list.cover_grid"].COVER_GRID_ROW_GAP = COVER_GRID_ROW_GAP;
        ρσ_modules["book_list.cover_grid"].cover_grid_column_layout = cover_grid_column_layout;
        ρσ_modules["book_list.cover_grid"].get_cover_grid_pct = get_cover_grid_pct;
        ρσ_modules["book_list.cover_grid"].sync_cover_grid_tile_px = sync_cover_grid_tile_px;
        ρσ_modules["book_list.cover_grid"].apply_cover_grid_pct_css = apply_cover_grid_pct_css;
        ρσ_modules["book_list.cover_grid"].ensure_cover_grid_resize_listener = ensure_cover_grid_resize_listener;
        ρσ_modules["book_list.cover_grid"].attach_cover_grid_resize_observer = attach_cover_grid_resize_observer;
        ρσ_modules["book_list.cover_grid"].on_cover_grid_size_input = on_cover_grid_size_input;
        ρσ_modules["book_list.cover_grid"].sync_cover_grid_size_control = sync_cover_grid_size_control;
        ρσ_modules["book_list.cover_grid"].create_cover_grid_size_control = create_cover_grid_size_control;
        ρσ_modules["book_list.cover_grid"].cover_grid_thumb_size = cover_grid_thumb_size;
        ρσ_modules["book_list.cover_grid"].description = description;
        ρσ_modules["book_list.cover_grid"].cover_grid_css = cover_grid_css;
        ρσ_modules["book_list.cover_grid"].init = init;
        ρσ_modules["book_list.cover_grid"].on_img_load = on_img_load;
        ρσ_modules["book_list.cover_grid"].create_item = create_item;
        ρσ_modules["book_list.cover_grid"].append_item = append_item;
    })();

    (function(){
        var __name__ = "book_list.top_bar";
        var CLASS_NAME, SPACING, VSPACING, THROBBER_NAME;
        var get_color = ρσ_modules["book_list.theme"].get_color;
        var get_font_size = ρσ_modules["book_list.theme"].get_font_size;

        var book_list_container_id = ρσ_modules["book_list.constants"].book_list_container_id;
        var cs_top_bar_host_id = ρσ_modules["book_list.constants"].cs_top_bar_host_id;

        var set_css = ρσ_modules.dom.set_css;
        var clear = ρσ_modules.dom.clear;
        var create_keyframes = ρσ_modules.dom.create_keyframes;
        var build_rule = ρσ_modules.dom.build_rule;
        var svgicon = ρσ_modules.dom.svgicon;
        var add_extra_css = ρσ_modules.dom.add_extra_css;

        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var get_interface_data = ρσ_modules.session.get_interface_data;

        var home = ρσ_modules["book_list.router"].home;

        var back = ρσ_modules["book_list.router"].back;

        var parse_url_params = ρσ_modules.utils.parse_url_params;

        CLASS_NAME = "main-top-bar";
        SPACING = "0.5em";
        VSPACING = "0.55ex";
        THROBBER_NAME = "top-bar-throbber";
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, style;
                sel = "." + CLASS_NAME + " ";
                style = "";
                style += create_keyframes(THROBBER_NAME, "from { transform: scale(1); } 50% { transform: scale(0.5); } to { transform: scale(1); }");
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "a"].concat([ρσ_desugar_kwargs({display: "inline-flex", align_items: "center", gap: "0.35rem", line_height: "1.0", overflow: "hidden", flex_shrink: "0", cursor: "pointer", color: get_color("window-foreground"), background: "none", padding_top: VSPACING, padding_bottom: VSPACING, border_radius: "999px", padding_left: "0.35em", padding_right: "0.35em"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "a svg"].concat([ρσ_desugar_kwargs({display: "block", height: "max(1.125rem, 1.35ex)", width: "max(1.125rem, 1.35ex)", vertical_align: "middle", opacity: "0.92", flex_shrink: "0"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "a span"].concat([ρσ_desugar_kwargs({line_height: "1.0"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "a.top-bar-title"].concat([ρσ_desugar_kwargs({flex_shrink: "1", min_width: "0", max_width: "100%", overflow: "hidden", text_overflow: "ellipsis", white_space: "nowrap"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "span.top-bar-title"].concat([ρσ_desugar_kwargs({flex_shrink: "1", min_width: "0", max_width: "100%", overflow: "hidden", text_overflow: "ellipsis", white_space: "nowrap", display: "block"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "a:hover"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "a:active"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light-2)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "a:focus"].concat([ρσ_desugar_kwargs({outline: "none"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "a.top-bar-title:hover"].concat([ρσ_desugar_kwargs({transform: "scale(1)", color: get_color("link-foreground"), font_style: "normal"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "a.top-bar-title:active"].concat([ρσ_desugar_kwargs({transform: "scale(1)", color: get_color("link-foreground"), font_style: "normal"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + CLASS_NAME + " > .main-top-bar-left"].concat([ρσ_desugar_kwargs({display: "flex", flex_wrap: "nowrap", align_items: "center", gap: "0.45em", min_width: "0", max_width: "100%", flex: "1 1 0%", box_sizing: "border-box", padding_left: "0.45em", overflow: "hidden"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + CLASS_NAME + " > .main-top-bar-right"].concat([ρσ_desugar_kwargs({display: "flex", flex_wrap: "nowrap", align_items: "center", justify_content: "flex-end", gap: "0.45em", flex: "0 0 auto", margin_left: "auto", box_sizing: "border-box", padding_right: "0.45em"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + CLASS_NAME + " > .main-top-bar-right:empty"].concat([ρσ_desugar_kwargs({display: "none", margin_left: "0", padding_right: "0"})]));
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "book_list.top_bar"}
            });
            return ρσ_anonfunc;
        })());
        function top_bar_target_container(container) {
            var bl, host;
            if (!container) {
                return container;
            }
            bl = document.getElementById(book_list_container_id);
            host = document.getElementById(cs_top_bar_host_id);
            if (bl && host && bl.contains(container)) {
                return host;
            }
            return container;
        };
        if (!top_bar_target_container.__argnames__) Object.defineProperties(top_bar_target_container, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function create_markup(container) {
            var target, bar;
            target = top_bar_target_container(container);
            if (target && target.id === cs_top_bar_host_id) {
                clear(target);
            }
            if (!target) {
                return;
            }
            bar = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "main-top-bar-left"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "main-top-bar-right"})])].concat([ρσ_desugar_kwargs({class_: CLASS_NAME})]));
            ρσ_interpolate_kwargs.call(this, set_css, [bar].concat([ρσ_desugar_kwargs({width: "100%", display: "flex", flex_direction: "row", flex_wrap: "nowrap", justify_content: "flex-start", align_items: "center", gap: "0.45rem", overflow: "hidden", font_size: get_font_size("title"), user_select: "none", color: get_color("window-foreground"), background_color: get_color("window-background"), border_bottom: "var(--calibre-border-style-subtle)", box_shadow: "0 1px 0 rgba(0,0,0,0.03)"})]));
            target.appendChild(bar);
        };
        if (!create_markup.__argnames__) Object.defineProperties(create_markup, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function _has_visible_right_child(right) {
            var kids, cs, kid;
            if (!right) {
                return false;
            }
            kids = right.children || [];
            var ρσ_Iter0 = ρσ_Iterable(kids);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                kid = ρσ_Iter0[ρσ_Index0];
                if (!kid || kid.nodeType !== Node.ELEMENT_NODE) {
                    continue;
                }
                if (kid.hidden || ρσ_exists.d(kid.style).display === "none") {
                    continue;
                }
                try {
                    cs = window.getComputedStyle(kid);
                    if (cs && cs.display === "none") {
                        continue;
                    }
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                    } else {
                        throw ρσ_Exception;
                    }
                }
                return true;
            }
            return false;
        };
        if (!_has_visible_right_child.__argnames__) Object.defineProperties(_has_visible_right_child, {
            __argnames__ : {value: ["right"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function sync_right_slot_visibility(container) {
            var right, has_visible, bar;
            var ρσ_Iter1 = ρσ_Iterable(get_bars(container));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                bar = ρσ_Iter1[ρσ_Index1];
                right = ((typeof bar !== "undefined" && bar !== null ? bar : Object.create(null)).firstChild) ? bar.firstChild.nextSibling : null;
                if (!right) {
                    continue;
                }
                has_visible = _has_visible_right_child(right);
                if (has_visible) {
                    right.style.display = "flex";
                    right.style.marginLeft = "auto";
                    right.style.paddingRight = "0.45em";
                } else {
                    right.style.display = "none";
                    right.style.marginLeft = "0";
                    right.style.paddingRight = "0";
                }
            }
        };
        if (!sync_right_slot_visibility.__argnames__) Object.defineProperties(sync_right_slot_visibility, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function get_bars(container) {
            var target;
            target = top_bar_target_container(container);
            if (!target) {
                if (container) {
                    return container.getElementsByClassName(CLASS_NAME);
                }
                return document.createElement("div").getElementsByClassName(CLASS_NAME);
            }
            return target.getElementsByClassName(CLASS_NAME);
        };
        if (!get_bars.__argnames__) Object.defineProperties(get_bars, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function set_left_data() {
            var container = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var title = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? set_left_data.__defaults__.title : arguments[1];
            var icon = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? set_left_data.__defaults__.icon : arguments[2];
            var action = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? set_left_data.__defaults__.action : arguments[3];
            var tooltip = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? set_left_data.__defaults__.tooltip : arguments[4];
            var run_animation = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? set_left_data.__defaults__.run_animation : arguments[5];
            var title_action = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? set_left_data.__defaults__.title_action : arguments[6];
            var title_tooltip = (arguments[7] === undefined || ( 7 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? set_left_data.__defaults__.title_tooltip : arguments[7];
            var back_action = (arguments[8] === undefined || ( 8 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? set_left_data.__defaults__.back_action : arguments[8];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "title")){
                title = ρσ_kwargs_obj.title;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "icon")){
                icon = ρσ_kwargs_obj.icon;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "action")){
                action = ρσ_kwargs_obj.action;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "tooltip")){
                tooltip = ρσ_kwargs_obj.tooltip;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "run_animation")){
                run_animation = ρσ_kwargs_obj.run_animation;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "title_action")){
                title_action = ρσ_kwargs_obj.title_action;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "title_tooltip")){
                title_tooltip = ρσ_kwargs_obj.title_tooltip;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "back_action")){
                back_action = ρσ_kwargs_obj.back_action;
            }
            var bars, interface_data, is_home, left, title_elem, a, btns, idx, ρσ_unpack, i, bar;
            bars = get_bars(container);
            function on_back_click(event) {
                event.preventDefault();
                if (callable(back_action)) {
                    back_action(event);
                } else {
                    back.bind(event)();
                }
            };
            if (!on_back_click.__argnames__) Object.defineProperties(on_back_click, {
                __argnames__ : {value: ["event"]},
                __module__ : {value: "book_list.top_bar"}
            });

            if (icon === "heart") {
                if (!tooltip) {
                    tooltip = _("Donate to support calibre development");
                }
            } else if (icon === "back") {
                if (action === null) {
                    action = on_back_click;
                }
            }
            interface_data = get_interface_data();
            try {
                is_home = !((parse_url_params().panel || ""));
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    is_home = false;
                } else {
                    throw ρσ_Exception;
                }
            }
            var ρσ_Iter2 = ρσ_Iterable(enumerate(bars));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                ρσ_unpack = ρσ_Iter2[ρσ_Index2];
                i = ρσ_unpack[0];
                bar = ρσ_unpack[1];
                left = bar.firstChild;
                clear(left);
                title_elem = (callable(title_action)) ? "a" : "span";
                if (icon === "heart") {
                    left.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [svgicon(icon)].concat([ρσ_desugar_kwargs({title: tooltip})])));
                } else if (icon === "close") {
                    left.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [svgicon("close")].concat([ρσ_desugar_kwargs({title: tooltip || _("Close")})])));
                } else {
                    if (!is_home) {
                        left.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [svgicon("arrow-left")].concat([ρσ_desugar_kwargs({title: _("Back")})])));
                    }
                    left.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [svgicon("home")].concat([ρσ_desugar_kwargs({title: _("Go to the home page")})])));
                }
                left.appendChild(ρσ_interpolate_kwargs.call(this, E, [title_elem, title].concat([ρσ_desugar_kwargs({title: title_tooltip, class_: "top-bar-title", style: "margin-left: {0}; font-weight: bold; padding-top: {1}; padding-bottom: {1}; vertical-align: middle".format(SPACING, VSPACING)})])));
                if (i === 0) {
                    a = left.firstChild;
                    if (icon === "heart") {
                        ρσ_interpolate_kwargs.call(this, set_css, [a].concat([ρσ_desugar_kwargs({animation_name: THROBBER_NAME, animation_duration: "1s", animation_timing_function: "ease-in-out", animation_iteration_count: "5", animation_play_state: (run_animation) ? "running" : "paused"})]));
                        ρσ_interpolate_kwargs.call(this, set_css, [a.firstChild].concat([ρσ_desugar_kwargs({color: get_color("heart")})]));
                        a.setAttribute("href", interface_data.donate_link);
                        a.setAttribute("target", "donate-to-calibre");
                        if (action !== null) {
                            a.addEventListener("click", (function() {
                                var ρσ_anonfunc = function (event) {
                                    event.preventDefault();
                                    action.bind(event)();
                                };
                                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                    __argnames__ : {value: ["event"]},
                                    __module__ : {value: "book_list.top_bar"}
                                });
                                return ρσ_anonfunc;
                            })());
                        }
                    } else if (icon === "close") {
                        if (action !== null) {
                            a.addEventListener("click", (function() {
                                var ρσ_anonfunc = function (event) {
                                    event.preventDefault();
                                    action.bind(event)();
                                };
                                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                    __argnames__ : {value: ["event"]},
                                    __module__ : {value: "book_list.top_bar"}
                                });
                                return ρσ_anonfunc;
                            })());
                        }
                    } else {
                        btns = left.getElementsByTagName("a");
                        idx = 0;
                        if (!is_home) {
                            btns[(typeof idx === "number" && idx < 0) ? btns.length + idx : idx].addEventListener("click", on_back_click);
                            idx += 1;
                        }
                        btns[(typeof idx === "number" && idx < 0) ? btns.length + idx : idx].addEventListener("click", (function() {
                            var ρσ_anonfunc = function (event) {
                                event.preventDefault();
                                home.bind(event)();
                            };
                            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                __argnames__ : {value: ["event"]},
                                __module__ : {value: "book_list.top_bar"}
                            });
                            return ρσ_anonfunc;
                        })());
                    }
                    if (callable(title_action)) {
                        a = left.querySelector(".top-bar-title");
                        a.addEventListener("click", (function() {
                            var ρσ_anonfunc = function (event) {
                                event.preventDefault();
                                title_action.bind(event)();
                            };
                            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                __argnames__ : {value: ["event"]},
                                __module__ : {value: "book_list.top_bar"}
                            });
                            return ρσ_anonfunc;
                        })());
                    }
                }
            }
        };
        if (!set_left_data.__defaults__) Object.defineProperties(set_left_data, {
            __defaults__ : {value: {title:"calibre", icon:"heart", action:null, tooltip:"", run_animation:false, title_action:null, title_tooltip:null, back_action:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["container", "title", "icon", "action", "tooltip", "run_animation", "title_action", "title_tooltip", "back_action"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function set_title(container, text) {
            var bars, left, el, bar;
            bars = get_bars(container);
            var ρσ_Iter3 = ρσ_Iterable(bars);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                bar = ρσ_Iter3[ρσ_Index3];
                left = bar.firstChild;
                el = (left) ? left.querySelector(".top-bar-title") : null;
                if (el) {
                    el.textContent = text;
                }
            }
        };
        if (!set_title.__argnames__) Object.defineProperties(set_title, {
            __argnames__ : {value: ["container", "text"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function set_title_tooltip(container, text) {
            var bars, left, el, bar;
            bars = get_bars(container);
            var ρσ_Iter4 = ρσ_Iterable(bars);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                bar = ρσ_Iter4[ρσ_Index4];
                left = bar.firstChild;
                el = (left) ? left.querySelector(".top-bar-title") : null;
                if (el) {
                    el.title = text;
                }
            }
        };
        if (!set_title_tooltip.__argnames__) Object.defineProperties(set_title_tooltip, {
            __argnames__ : {value: ["container", "text"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function create_top_bar() {
            var container = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            create_markup(container);
            ρσ_interpolate_kwargs.call(this, set_left_data, [container].concat([ρσ_desugar_kwargs(kw)]));
        };
        if (!create_top_bar.__handles_kwarg_interpolation__) Object.defineProperties(create_top_bar, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function add_button() {
            var container = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var icon = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var action = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_button.__defaults__.action : arguments[2];
            var tooltip = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_button.__defaults__.tooltip : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "action")){
                action = ρσ_kwargs_obj.action;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "tooltip")){
                tooltip = ρσ_kwargs_obj.tooltip;
            }
            var bars, right, ρσ_unpack, i, bar;
            if (!icon) {
                throw new ValueError("An icon must be specified");
            }
            bars = get_bars(container);
            var ρσ_Iter5 = ρσ_Iterable(enumerate(bars));
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                ρσ_unpack = ρσ_Iter5[ρσ_Index5];
                i = ρσ_unpack[0];
                bar = ρσ_unpack[1];
                right = bar.firstChild.nextSibling;
                right.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [svgicon(icon)].concat([ρσ_desugar_kwargs({style: "margin-left: " + SPACING, title: tooltip})])));
                right.lastChild.dataset.buttonIcon = icon;
                if (i === 0) {
                    if (action !== null) {
                        right.lastChild.addEventListener("click", (function() {
                            var ρσ_anonfunc = function (event) {
                                [event.preventDefault(), action()];
                            };
                            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                __argnames__ : {value: ["event"]},
                                __module__ : {value: "book_list.top_bar"}
                            });
                            return ρσ_anonfunc;
                        })());
                    }
                }
            }
            sync_right_slot_visibility(container);
        };
        if (!add_button.__defaults__) Object.defineProperties(add_button, {
            __defaults__ : {value: {action:null, tooltip:""}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["container", "icon", "action", "tooltip"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function clear_buttons(container) {
            var bars, right, ρσ_unpack, i, bar;
            bars = get_bars(container);
            var ρσ_Iter6 = ρσ_Iterable(enumerate(bars));
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                ρσ_unpack = ρσ_Iter6[ρσ_Index6];
                i = ρσ_unpack[0];
                bar = ρσ_unpack[1];
                right = bar.firstChild.nextSibling;
                clear(right);
            }
            sync_right_slot_visibility(container);
        };
        if (!clear_buttons.__argnames__) Object.defineProperties(clear_buttons, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.top_bar"}
        });

        function set_button_visibility(container, icon, visible) {
            var right, elem, bar;
            var ρσ_Iter7 = ρσ_Iterable(get_bars(container));
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                bar = ρσ_Iter7[ρσ_Index7];
                right = bar.firstChild.nextSibling;
                elem = right.querySelector("[data-button-icon=\"" + ρσ_str.format("{}", icon) + "\"]");
                if (elem) {
                    elem.style.display = (visible) ? "inline-block" : "none";
                }
            }
            sync_right_slot_visibility(container);
        };
        if (!set_button_visibility.__argnames__) Object.defineProperties(set_button_visibility, {
            __argnames__ : {value: ["container", "icon", "visible"]},
            __module__ : {value: "book_list.top_bar"}
        });

        ρσ_modules["book_list.top_bar"].CLASS_NAME = CLASS_NAME;
        ρσ_modules["book_list.top_bar"].SPACING = SPACING;
        ρσ_modules["book_list.top_bar"].VSPACING = VSPACING;
        ρσ_modules["book_list.top_bar"].THROBBER_NAME = THROBBER_NAME;
        ρσ_modules["book_list.top_bar"].top_bar_target_container = top_bar_target_container;
        ρσ_modules["book_list.top_bar"].create_markup = create_markup;
        ρσ_modules["book_list.top_bar"]._has_visible_right_child = _has_visible_right_child;
        ρσ_modules["book_list.top_bar"].sync_right_slot_visibility = sync_right_slot_visibility;
        ρσ_modules["book_list.top_bar"].get_bars = get_bars;
        ρσ_modules["book_list.top_bar"].set_left_data = set_left_data;
        ρσ_modules["book_list.top_bar"].set_title = set_title;
        ρσ_modules["book_list.top_bar"].set_title_tooltip = set_title_tooltip;
        ρσ_modules["book_list.top_bar"].create_top_bar = create_top_bar;
        ρσ_modules["book_list.top_bar"].add_button = add_button;
        ρσ_modules["book_list.top_bar"].clear_buttons = clear_buttons;
        ρσ_modules["book_list.top_bar"].set_button_visibility = set_button_visibility;
    })();

    (function(){
        var __name__ = "book_list.ui";
        var panel_handlers, default_panel_handler;
        var ensure_id = ρσ_modules.dom.ensure_id;
        var clear = ρσ_modules.dom.clear;

        var E = ρσ_modules.elementmaker.E;

        var book_list_container_id = ρσ_modules["book_list.constants"].book_list_container_id;

        var get_current_query = ρσ_modules["book_list.globals"].get_current_query;

        var push_state = ρσ_modules["book_list.router"].push_state;

        var current_library_id = ρσ_modules["book_list.library_data"].current_library_id;
        var current_virtual_library = ρσ_modules["book_list.library_data"].current_virtual_library;

        var encode_query_with_path = ρσ_modules.utils.encode_query_with_path;

        panel_handlers = Object.create(null);
        default_panel_handler = null;
        function set_panel_handler(panel, handler) {
            panel_handlers[(typeof panel === "number" && panel < 0) ? panel_handlers.length + panel : panel] = handler;
        };
        if (!set_panel_handler.__argnames__) Object.defineProperties(set_panel_handler, {
            __argnames__ : {value: ["panel", "handler"]},
            __module__ : {value: "book_list.ui"}
        });

        function set_default_panel_handler(handler) {
            default_panel_handler = handler;
        };
        if (!set_default_panel_handler.__argnames__) Object.defineProperties(set_default_panel_handler, {
            __argnames__ : {value: ["handler"]},
            __module__ : {value: "book_list.ui"}
        });

        function develop_panel(container_id) {
            var container, q, m;
            container = document.getElementById(container_id);
            q = get_current_query();
            m = q.widget_module;
            if (m) {
                m = get_module(m);
                if ((typeof m !== "undefined" && m !== null ? m : Object.create(null)).develop) {
                    m.develop(container);
                } else {
                    container.textContent = "The module {} either does not exist or has no develop method.".format(q.widget_module);
                }
            }
        };
        if (!develop_panel.__argnames__) Object.defineProperties(develop_panel, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.ui"}
        });

        set_panel_handler("develop-widgets", develop_panel);
        function currently_showing_panel() {
            var c;
            c = document.getElementById(book_list_container_id);
            return c.dataset.panel;
        };
        if (!currently_showing_panel.__module__) Object.defineProperties(currently_showing_panel, {
            __module__ : {value: "book_list.ui"}
        });

        function add_library_info(query) {
            var vlid;
            if (!query.library_id) {
                query.library_id = current_library_id();
            }
            if (!query.vl) {
                if (query.vl === null) {
                    delete query.vl;
                } else {
                    vlid = current_virtual_library();
                    if (vlid) {
                        query.vl = vlid;
                    }
                }
            }
        };
        if (!add_library_info.__argnames__) Object.defineProperties(add_library_info, {
            __argnames__ : {value: ["query"]},
            __module__ : {value: "book_list.ui"}
        });

        function prepare_query(query, panel) {
            var q, k;
            q = (function() {
                var ρσ_Iter = ρσ_Iterable(query || Object.create(null)), ρσ_Result = Object.create(null), k;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    k = ρσ_Iter[ρσ_Index];
                    if (k !== "panel") {
                        ρσ_Result[k] = (query[(typeof k === "number" && k < 0) ? query.length + k : k]);
                    }
                }
                return ρσ_Result;
            })();
            if (panel !== "home") {
                q.panel = panel;
                add_library_info(q);
            }
            return q;
        };
        if (!prepare_query.__argnames__) Object.defineProperties(prepare_query, {
            __argnames__ : {value: ["query", "panel"]},
            __module__ : {value: "book_list.ui"}
        });

        function query_as_href(query, panel) {
            var q;
            q = prepare_query(query, panel || "book_list");
            return encode_query_with_path(q);
        };
        if (!query_as_href.__argnames__) Object.defineProperties(query_as_href, {
            __argnames__ : {value: ["query", "panel"]},
            __module__ : {value: "book_list.ui"}
        });

        function show_panel() {
            var panel = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var query = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_panel.__defaults__.query : arguments[1];
            var replace = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_panel.__defaults__.replace : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "query")){
                query = ρσ_kwargs_obj.query;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "replace")){
                replace = ρσ_kwargs_obj.replace;
            }
            ρσ_interpolate_kwargs.call(this, push_state, [prepare_query(query, panel)].concat([ρσ_desugar_kwargs({replace: replace})]));
        };
        if (!show_panel.__defaults__) Object.defineProperties(show_panel, {
            __defaults__ : {value: {query:null, replace:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["panel", "query", "replace"]},
            __module__ : {value: "book_list.ui"}
        });

        function apply_url_state(state) {
            var panel, c, handler;
            panel = state.panel || "home";
            c = document.getElementById(book_list_container_id);
            clear(c);
            c.appendChild(E.div());
            c.dataset.panel = panel;
            handler = panel_handlers[(typeof panel === "number" && panel < 0) ? panel_handlers.length + panel : panel] || default_panel_handler;
            handler(ensure_id(c.firstChild, "panel"));
        };
        if (!apply_url_state.__argnames__) Object.defineProperties(apply_url_state, {
            __argnames__ : {value: ["state"]},
            __module__ : {value: "book_list.ui"}
        });

        apply_url_state.back_from_current = (function() {
            var ρσ_anonfunc = function back_from_current(current_query) {
                var q, k;
                q = current_query;
                if (q.panel) {
                    if (ρσ_in("^", q.panel)) {
                        q = (function() {
                            var ρσ_Iter = ρσ_Iterable(q), ρσ_Result = Object.create(null), k;
                            for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                                k = ρσ_Iter[ρσ_Index];
                                ρσ_Result[k] = (q[(typeof k === "number" && k < 0) ? q.length + k : k]);
                            }
                            return ρσ_Result;
                        })();
                        q.panel = q.panel.rpartition("^")[0];
                    } else if (q.panel === "book_list") {
                        q = Object.create(null);
                    } else {
                        q = (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["panel"] = "book_list";
                            return ρσ_d;
                        }).call(this);
                        add_library_info(q);
                    }
                }
                return q;
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["current_query"]},
                __module__ : {value: "book_list.ui"}
            });
            return ρσ_anonfunc;
        })();
        ρσ_modules["book_list.ui"].panel_handlers = panel_handlers;
        ρσ_modules["book_list.ui"].default_panel_handler = default_panel_handler;
        ρσ_modules["book_list.ui"].set_panel_handler = set_panel_handler;
        ρσ_modules["book_list.ui"].set_default_panel_handler = set_default_panel_handler;
        ρσ_modules["book_list.ui"].develop_panel = develop_panel;
        ρσ_modules["book_list.ui"].currently_showing_panel = currently_showing_panel;
        ρσ_modules["book_list.ui"].add_library_info = add_library_info;
        ρσ_modules["book_list.ui"].prepare_query = prepare_query;
        ρσ_modules["book_list.ui"].query_as_href = query_as_href;
        ρσ_modules["book_list.ui"].show_panel = show_panel;
        ρσ_modules["book_list.ui"].apply_url_state = apply_url_state;
    })();

    (function(){
        var __name__ = "book_list.home";
        var CLASS_NAME, recently_read_by_user;
        var E = ρσ_modules.elementmaker.E;

        var absolute_path = ρσ_modules.ajax.absolute_path;
        var ajax_send = ρσ_modules.ajax.ajax_send;
        var ajax = ρσ_modules.ajax.ajax;

        var BORDER_RADIUS = ρσ_modules["book_list.cover_grid"].BORDER_RADIUS;

        var get_db = ρσ_modules["book_list.globals"].get_db;

        var all_libraries = ρσ_modules["book_list.library_data"].all_libraries;
        var last_virtual_library_for = ρσ_modules["book_list.library_data"].last_virtual_library_for;
        var sync_library_books = ρσ_modules["book_list.library_data"].sync_library_books;

        var open_book = ρσ_modules["book_list.router"].open_book;
        var update_window_title = ρσ_modules["book_list.router"].update_window_title;

        var add_button = ρσ_modules["book_list.top_bar"].add_button;
        var create_top_bar = ρσ_modules["book_list.top_bar"].create_top_bar;

        var set_default_panel_handler = ρσ_modules["book_list.ui"].set_default_panel_handler;
        var show_panel = ρσ_modules["book_list.ui"].show_panel;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var ensure_id = ρσ_modules.dom.ensure_id;
        var set_css = ρσ_modules.dom.set_css;
        var unique_id = ρσ_modules.dom.unique_id;

        var _ = ρσ_modules.gettext.gettext;

        var create_custom_dialog = ρσ_modules.modals.create_custom_dialog;

        var get_device_uuid = ρσ_modules.session.get_device_uuid;
        var get_interface_data = ρσ_modules.session.get_interface_data;

        var conditional_timeout = ρσ_modules.utils.conditional_timeout;
        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;
        var username_key = ρσ_modules.utils.username_key;

        var create_button = ρσ_modules.widgets.create_button;

        CLASS_NAME = "home-page";
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var ans, sel, img_sel;
                ans = "";
                sel = "." + ρσ_str.format("{}", CLASS_NAME) + " ";
                ans += ρσ_interpolate_kwargs.call(this, build_rule, ["." + CLASS_NAME].concat([ρσ_desugar_kwargs({min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-home-content"].concat([ρσ_desugar_kwargs({padding: "0.75rem 1rem 1rem 1rem", max_width: "980px", width: "100%", min_width: "0", box_sizing: "border-box", margin_left: "auto", margin_right: "auto"})]));
                ans += "\n@media (max-width: 720px) {\n  .home-page .cs-home-content { padding-left: 0.75rem; padding-right: 0.75rem; }\n}\n@media (max-width: 380px) {\n  .home-page .cs-home-content { padding-left: 0.5rem; padding-right: 0.5rem; }\n}\n";
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-home-section"].concat([ρσ_desugar_kwargs({margin_top: "0.95rem", padding: "1rem", border_radius: "18px", border: "var(--calibre-border-style-subtle)", background: "var(--calibre-color-surface-1)", box_shadow: "0 16px 44px rgba(0,0,0,0.10)", min_width: "0", max_width: "100%", box_sizing: "border-box", overflow_x: "hidden"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-home-section:first-child"].concat([ρσ_desugar_kwargs({margin_top: "0"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-home-section h2"].concat([ρσ_desugar_kwargs({margin: "0 0 0.85rem 0", padding: "0", font_size: "1.1em", font_weight: "800", opacity: "0.92"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-home-actions"].concat([ρσ_desugar_kwargs({display: "flex", flex_wrap: "wrap", gap: "0.65rem", min_width: "0", max_width: "100%"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-home-download-actions"].concat([ρσ_desugar_kwargs({margin_top: "0.55rem"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-home-actions a.calibre-push-button"].concat([ρσ_desugar_kwargs({margin: "0"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-home-covers"].concat([ρσ_desugar_kwargs({display: "flex", flex_wrap: "wrap", align_items: "flex-start", align_content: "flex-start", gap: "10px", row_gap: "10px", column_gap: "10px", width: "100%", min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-home-covers > div"].concat([ρσ_desugar_kwargs({margin: "0", flex_grow: "0", flex_shrink: "1", flex_basis: "auto", min_width: "0", width: "min(118px, max(72px, calc((100% - 20px) / 3.15)))", max_width: "100%", box_sizing: "border-box"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-home-covers > div > a"].concat([ρσ_desugar_kwargs({display: "block", width: "100%", min_width: "0", box_sizing: "border-box"})]));
                img_sel = sel + ".recently-read img";
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [img_sel].concat([ρσ_desugar_kwargs({width: "100%", height: "auto", aspect_ratio: "2 / 3", border_radius: "" + ρσ_str.format("{}", BORDER_RADIUS) + "px", display: "block", object_fit: "cover", border: "var(--calibre-border-style)", box_shadow: "0 10px 26px rgba(0,0,0,0.14)", transition: "box-shadow 160ms ease, filter 160ms ease"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", img_sel) + ":hover"].concat([ρσ_desugar_kwargs({box_shadow: "0 16px 44px rgba(0,0,0,0.18), 0 0 0 4px var(--calibre-color-primary-light)", filter: "brightness(1.03)"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", img_sel) + ":active"].concat([ρσ_desugar_kwargs({box_shadow: "0 12px 34px rgba(0,0,0,0.18), 0 0 0 4px var(--calibre-color-primary-light-2)", filter: "brightness(1.01)"})]));
                return ans;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "book_list.home"}
            });
            return ρσ_anonfunc;
        })());
        recently_read_by_user = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["updated"] = false;
            return ρσ_d;
        }).call(this);
        function update_recently_read_by_user(items) {
            if (items) {
                recently_read_by_user.items = items;
            }
            recently_read_by_user.updated = true;
        };
        if (!update_recently_read_by_user.__argnames__) Object.defineProperties(update_recently_read_by_user, {
            __argnames__ : {value: ["items"]},
            __module__ : {value: "book_list.home"}
        });

        function update_book_in_recently_read_by_user_on_home_page(library_id, book_id, book_format, cfi) {
            var item;
            if (recently_read_by_user.items) {
                var ρσ_Iter0 = ρσ_Iterable(recently_read_by_user.items);
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    item = ρσ_Iter0[ρσ_Index0];
                    if (item.library_id === library_id && item.book_id === book_id && item.format === book_format) {
                        item.cfi = cfi;
                    }
                }
            }
        };
        if (!update_book_in_recently_read_by_user_on_home_page.__argnames__) Object.defineProperties(update_book_in_recently_read_by_user_on_home_page, {
            __argnames__ : {value: ["library_id", "book_id", "book_format", "cfi"]},
            __module__ : {value: "book_list.home"}
        });

        function show_cover(blob, name, mt, book) {
            var img;
            img = document.getElementById(this);
            if (!img) {
                return;
            }
            img.onload = (function() {
                var ρσ_anonfunc = function () {
                    window.URL.revokeObjectURL(this.src);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.home"}
                });
                return ρσ_anonfunc;
            })();
            img.src = window.URL.createObjectURL(blob);
        };
        if (!show_cover.__argnames__) Object.defineProperties(show_cover, {
            __argnames__ : {value: ["blob", "name", "mt", "book"]},
            __module__ : {value: "book_list.home"}
        });

        function read_book(library_id, book_id, fmt, extra_query) {
            ρσ_interpolate_kwargs.call(this, open_book, [book_id, fmt, library_id].concat([ρσ_desugar_kwargs({extra_query: extra_query})]));
        };
        if (!read_book.__argnames__) Object.defineProperties(read_book, {
            __argnames__ : {value: ["library_id", "book_id", "fmt", "extra_query"]},
            __module__ : {value: "book_list.home"}
        });

        function view_book_page(library_id, book_id) {
            ρσ_interpolate_kwargs.call(this, show_panel, ["book_details", (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["library_id"] = library_id;
                ρσ_d["book_id"] = book_id + "";
                return ρσ_d;
            }).call(this)].concat([ρσ_desugar_kwargs({replace: false})]));
        };
        if (!view_book_page.__argnames__) Object.defineProperties(view_book_page, {
            __argnames__ : {value: ["library_id", "book_id"]},
            __module__ : {value: "book_list.home"}
        });

        function get_last_read_position(last_read_positions, prev_last_read) {
            var prev_epoch, dev, newest_epoch, ans, data;
            prev_epoch = prev_last_read.getTime();
            dev = get_device_uuid();
            newest_epoch = ans = null;
            var ρσ_Iter1 = ρσ_Iterable(last_read_positions);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                data = ρσ_Iter1[ρσ_Index1];
                if (data.device !== dev && data.epoch > prev_epoch) {
                    if (ans === null || data.epoch > newest_epoch) {
                        newest_epoch = data.epoch;
                        ans = data;
                    }
                }
            }
            return ans;
        };
        if (!get_last_read_position.__argnames__) Object.defineProperties(get_last_read_position, {
            __argnames__ : {value: ["last_read_positions", "prev_last_read"]},
            __module__ : {value: "book_list.home"}
        });

        function sync_data_received(library_id, lrmap, load_type, xhr, ev) {
            var data, db, new_vals, entry, prev_last_read, last_read_positions, new_last_read, last_read, cfi, new_amap, is_empty, ρσ_unpack, book_id, fmt, key;
            if (load_type !== "load") {
                print("Failed to get book sync data");
                return;
            }
            data = JSON.parse(xhr.responseText);
            db = get_db();
            var ρσ_Iter2 = ρσ_Iterable(data);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                key = ρσ_Iter2[ρσ_Index2];
                new_vals = data[(typeof key === "number" && key < 0) ? data.length + key : key];
                entry = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["last_read"] = null;
                    ρσ_d["last_read_position"] = null;
                    ρσ_d["annotations_map"] = null;
                    return ρσ_d;
                }).call(this);
                prev_last_read = lrmap[(typeof key === "number" && key < 0) ? lrmap.length + key : key];
                if (prev_last_read) {
                    last_read_positions = new_vals.last_read_positions;
                    new_last_read = get_last_read_position(last_read_positions, prev_last_read);
                    if (new_last_read) {
                        last_read = new Date(new_last_read.epoch * 1e3);
                        cfi = new_last_read.cfi;
                        if (cfi) {
                            entry.last_read = last_read;
                            entry.last_read_position = cfi;
                        }
                    }
                }
                new_amap = new_vals.annotations_map || Object.create(null);
                is_empty = true;
                for(var ikey in new_amap) { is_empty = false; break; };
                if (!is_empty) {
                    entry.annotations_map = new_amap;
                }
                if (entry.last_read_position || entry.annotations_map) {
                    ρσ_unpack = ρσ_eslice(key.partition(":"), 2);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                    book_id = ρσ_unpack[0];
                    fmt = ρσ_unpack[1];
                    db.update_annotations_data_from_key(library_id, int(book_id), fmt, entry);
                }
            }
        };
        if (!sync_data_received.__argnames__) Object.defineProperties(sync_data_received, {
            __argnames__ : {value: ["library_id", "lrmap", "load_type", "xhr", "ev"]},
            __module__ : {value: "book_list.home"}
        });

        function start_sync(to_sync) {
            var libraries, library_id, ρσ_unpack, key, last_read, lid;
            libraries = Object.create(null);
            var ρσ_Iter3 = ρσ_Iterable(to_sync);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                ρσ_unpack = ρσ_Iter3[ρσ_Index3];
                key = ρσ_unpack[0];
                last_read = ρσ_unpack[1];
                library_id = key[0];
                if (!libraries[(typeof library_id === "number" && library_id < 0) ? libraries.length + library_id : library_id]) {
                    libraries[(typeof library_id === "number" && library_id < 0) ? libraries.length + library_id : library_id] = [];
                }
                libraries[(typeof library_id === "number" && library_id < 0) ? libraries.length + library_id : library_id].push([key, last_read]);
            }
            var ρσ_Iter4 = ρσ_Iterable(libraries);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                lid = ρσ_Iter4[ρσ_Index4];
                sync_library_books(lid, libraries[(typeof lid === "number" && lid < 0) ? libraries.length + lid : lid], sync_data_received);
            }
        };
        if (!start_sync.__argnames__) Object.defineProperties(start_sync, {
            __argnames__ : {value: ["to_sync"]},
            __module__ : {value: "book_list.home"}
        });

        function prepare_recent_container(container) {
            var cover_container;
            container.style.display = "block";
            container.appendChild(E.h2(_("Continue reading…")));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-home-covers"})]));
            cover_container = container.lastChild;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(this, create_button, [_("Browse all downloaded books…")].concat([ρσ_desugar_kwargs({icon: "cloud-download", action: (function() {
                var ρσ_anonfunc = function () {
                    show_panel("local_books");
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.home"}
                });
                return ρσ_anonfunc;
            })()})]))].concat([ρσ_desugar_kwargs({class_: "cs-home-actions cs-home-download-actions"})])));
            return cover_container;
        };
        if (!prepare_recent_container.__argnames__) Object.defineProperties(prepare_recent_container, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.home"}
        });

        function show_recent_for_user(container_id) {
            var container, images, q, rb, img, item;
            container = document.getElementById(container_id);
            images = prepare_recent_container(container);
            var ρσ_Iter5 = ρσ_Iterable(recently_read_by_user.items.slice(0, 3));
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                item = ρσ_Iter5[ρσ_Index5];
                q = Object.create(null);
                if (item.cfi) {
                    q.bookpos = item.cfi;
                }
                rb = read_book.bind(null, item.library_id, item.book_id, item.format, q);
                img = ρσ_interpolate_kwargs.call(E, E.img, [ρσ_desugar_kwargs({alt: item.tooltip, src: absolute_path("get/cover/" + ρσ_str.format("{}", item.book_id) + "/" + ρσ_str.format("{}", item.library_id) + "")})]);
                images.appendChild(E.div(ρσ_interpolate_kwargs.call(E, E.a, [img].concat([ρσ_desugar_kwargs({title: item.tooltip, href: "javascript:void(0)", onclick: rb})]))));
                img.onerror = (function() {
                    var ρσ_anonfunc = function (err) {
                        var failed;
                        failed = err.target;
                        failed.parentNode.parentNode.style.display = "none";
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["err"]},
                        __module__ : {value: "book_list.home"}
                    });
                    return ρσ_anonfunc;
                })();
            }
        };
        if (!show_recent_for_user.__argnames__) Object.defineProperties(show_recent_for_user, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.home"}
        });

        function show_recent_stage2(books) {
            var container, images, db, to_sync, username, lr, authors, img, img_id, book;
            container = document.getElementById(this);
            if (!container || !books.length) {
                return;
            }
            images = prepare_recent_container(container);
            db = get_db();
            to_sync = [];
            username = get_interface_data().username;
            var ρσ_Iter6 = ρσ_Iterable(books);
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                book = ρσ_Iter6[ρσ_Index6];
                if (to_sync.length < 10) {
                    lr = (ρσ_expr_temp = book.last_read)[ρσ_bound_index(username_key(username), ρσ_expr_temp)] || new Date(0);
                    to_sync.push([book.key, lr]);
                }
                authors = (book.metadata.authors) ? book.metadata.authors.join(" & ") : _("Unknown");
                img = ρσ_interpolate_kwargs.call(E, E.img, [ρσ_desugar_kwargs({alt: _("{} by {}").format(book.metadata.title, authors)})]);
                img_id = ensure_id(img);
                images.appendChild(E.div(ρσ_interpolate_kwargs.call(E, E.a, [img].concat([ρσ_desugar_kwargs({href: "javascript: void(0)", title: img.alt, onclick: read_book.bind(null, book.key[0], book.key[1], book.key[2], null)})]))));
                if (book.cover_name) {
                    db.get_file(book, book.cover_name, show_cover.bind(img_id));
                }
            }
            start_sync(to_sync);
        };
        if (!show_recent_stage2.__argnames__) Object.defineProperties(show_recent_stage2, {
            __argnames__ : {value: ["books"]},
            __module__ : {value: "book_list.home"}
        });

        function show_recent_for_user_if_fetched() {
            var container;
            container = this;
            if (!recently_read_by_user.updated) {
                return conditional_timeout(container.id, 5, show_recent_for_user_if_fetched);
            }
            if (recently_read_by_user.items && recently_read_by_user.items.length > 0) {
                return show_recent_for_user(container.id);
            }
            return show_recent.call(container);
        };
        if (!show_recent_for_user_if_fetched.__module__) Object.defineProperties(show_recent_for_user_if_fetched, {
            __module__ : {value: "book_list.home"}
        });

        function show_recent() {
            var container, db;
            container = this;
            db = get_db();
            if (!db.initialized) {
                conditional_timeout(container.id, 5, show_recent);
                return;
            }
            if (db.is_ok) {
                db.get_recently_read_books(show_recent_stage2.bind(container.id));
            } else {
                print(db.initialize_error_msg);
            }
        };
        if (!show_recent.__module__) Object.defineProperties(show_recent, {
            __module__ : {value: "book_list.home"}
        });

        function newly_added_received(newly_container_id, end_type, xhr, ev) {
            var container, data, images, authors, alt, img, book_id;
            container = document.getElementById(newly_container_id);
            if (!container || end_type !== "load") {
                return;
            }
            data = JSON.parse(xhr.responseText);
            if (!data.books || !data.books.length) {
                return;
            }
            container.style.display = "block";
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-home-covers"})]));
            images = container.lastChild;
            var ρσ_Iter7 = ρσ_Iterable(data.books);
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                book_id = ρσ_Iter7[ρσ_Index7];
                authors = (ρσ_expr_temp = data.authors)[(typeof book_id === "number" && book_id < 0) ? ρσ_expr_temp.length + book_id : book_id].join(" & ");
                alt = _("{} by {}").format((ρσ_expr_temp = data.titles)[(typeof book_id === "number" && book_id < 0) ? ρσ_expr_temp.length + book_id : book_id], authors);
                img = ρσ_interpolate_kwargs.call(E, E.img, [ρσ_desugar_kwargs({alt: alt, src: absolute_path("get/cover/" + ρσ_str.format("{}", book_id) + "/" + ρσ_str.format("{}", data.library_id) + "")})]);
                images.appendChild(E.div(ρσ_interpolate_kwargs.call(E, E.a, [img].concat([ρσ_desugar_kwargs({href: "javascript: void(0)", title: img.alt, onclick: view_book_page.bind(null, data.library_id, book_id)})]))));
            }
        };
        if (!newly_added_received.__argnames__) Object.defineProperties(newly_added_received, {
            __argnames__ : {value: ["newly_container_id", "end_type", "xhr", "ev"]},
            __module__ : {value: "book_list.home"}
        });

        function change_password() {
            var interface_data;
            interface_data = get_interface_data();
            create_custom_dialog(_("Change password for: {}").format(interface_data.username), (function() {
                var ρσ_anonfunc = function (parent, close_modal) {
                    var ids;
                    ids = [unique_id(), unique_id(), unique_id()];
                    parent.appendChild(E.table(E.tr(E.td(ρσ_interpolate_kwargs.call(E, E.label, [_("Current password:") + " "].concat([ρσ_desugar_kwargs({for_: ids[0]})]))), ρσ_interpolate_kwargs.call(this, set_css, [ρσ_interpolate_kwargs.call(E, E.td, [ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "password"})])].concat([ρσ_desugar_kwargs({id: ids[0]})]))].concat([ρσ_desugar_kwargs({padding_bottom: "1.5ex"})]))), E.tr(E.td(ρσ_interpolate_kwargs.call(E, E.label, [_("New password:") + " "].concat([ρσ_desugar_kwargs({for_: ids[1]})]))), ρσ_interpolate_kwargs.call(this, set_css, [ρσ_interpolate_kwargs.call(E, E.td, [ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "password"})])].concat([ρσ_desugar_kwargs({id: ids[1]})]))].concat([ρσ_desugar_kwargs({padding_bottom: "1.5ex"})]))), E.tr(E.td(ρσ_interpolate_kwargs.call(E, E.label, [_("New password again:") + " "].concat([ρσ_desugar_kwargs({for_: ids[2]})]))), ρσ_interpolate_kwargs.call(this, set_css, [ρσ_interpolate_kwargs.call(E, E.td, [ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "password"})])].concat([ρσ_desugar_kwargs({id: ids[2]})]))].concat([ρσ_desugar_kwargs({padding_bottom: "1.5ex"})])))));
                    parent.appendChild(E.div());
                    function show_msg(html, is_info) {
                        var msg;
                        msg = parent.firstChild.nextSibling;
                        safe_set_inner_html(msg, html);
                        msg.style.color = (!is_info) ? "red" : "currentColor";
                    };
                    if (!show_msg.__argnames__) Object.defineProperties(show_msg, {
                        __argnames__ : {value: ["html", "is_info"]},
                        __module__ : {value: "book_list.home"}
                    });

                    function on_complete(end_type, xhr, ev) {
                        if (end_type === "load") {
                            clear(parent);
                            parent.appendChild(E.div(_("Password successfully changed, you will be asked for the new password the next time the browser has to contact the calibre server.")));
                            parent.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("OK"), null, close_modal)].concat([ρσ_desugar_kwargs({class_: "button-box"})])));
                            return;
                        }
                        show_msg(_("Failed to change password, with error: {}").format(xhr.error_html));
                    };
                    if (!on_complete.__argnames__) Object.defineProperties(on_complete, {
                        __argnames__ : {value: ["end_type", "xhr", "ev"]},
                        __module__ : {value: "book_list.home"}
                    });

                    function ok() {
                        var pws, ρσ_unpack, oldpw, pw1, pw2;
                        pws = parent.firstChild.getElementsByTagName("input");
                        ρσ_unpack = [pws[0].value, pws[1].value, pws[2].value];
                        oldpw = ρσ_unpack[0];
                        pw1 = ρσ_unpack[1];
                        pw2 = ρσ_unpack[2];
                        if (pw1 !== pw2) {
                            show_msg(_("The two new passwords do not match"));
                            return;
                        }
                        if (!pw1 || !oldpw) {
                            show_msg(_("Empty passwords are not allowed"));
                            return;
                        }
                        ajax_send("users/change-pw", (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["oldpw"] = oldpw;
                            ρσ_d["newpw"] = pw1;
                            return ρσ_d;
                        }).call(this), on_complete);
                        show_msg(_("Contacting server, please wait..."), true);
                        parent.lastChild.display = "none";
                    };
                    if (!ok.__module__) Object.defineProperties(ok, {
                        __module__ : {value: "book_list.home"}
                    });

                    parent.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Cancel"), null, close_modal), ρσ_interpolate_kwargs.call(this, create_button, [_("OK"), null, ok].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: "button-box"})])));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["parent", "close_modal"]},
                    __module__ : {value: "book_list.home"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!change_password.__module__) Object.defineProperties(change_password, {
            __module__ : {value: "book_list.home"}
        });

        function show_user_details() {
            var interface_data;
            interface_data = get_interface_data();
            create_custom_dialog(_("Logged in as {}").format(interface_data.username), (function() {
                var ρσ_anonfunc = function (parent, close_modal) {
                    var msg;
                    msg = E.div();
                    safe_set_inner_html(msg, _("You are logged in as the user <b>{}</b>. To log in as a different user, you will have to restart the browser.").format(interface_data.username));
                    parent.appendChild(msg);
                    parent.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Close"), null, close_modal), ρσ_interpolate_kwargs.call(this, create_button, [_("Change password"), null, (function() {
                        var ρσ_anonfunc = function () {
                            setTimeout(change_password, 0);
                            close_modal();
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "book_list.home"}
                        });
                        return ρσ_anonfunc;
                    })()].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: "button-box"})])));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["parent", "close_modal"]},
                    __module__ : {value: "book_list.home"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!show_user_details.__module__) Object.defineProperties(show_user_details, {
            __module__ : {value: "book_list.home"}
        });

        function init(container_id) {
            var container, interface_data, content, recent, recent_container_id, choose, cl, library_name, ρσ_unpack, library_id, newly, newly_container_id, offline_mode, nav;
            update_window_title();
            container = document.getElementById(container_id);
            container.classList.add(CLASS_NAME);
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({run_animation: true})]));
            interface_data = get_interface_data();
            if (interface_data.username) {
                add_button(container, "user", show_user_details, _("Logged in as {}").format(interface_data.username));
            }
            content = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-home-content"})]);
            container.appendChild(content);
            recent = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display:none", class_: "cs-home-section recently-read"})]);
            recent_container_id = ensure_id(recent);
            content.appendChild(recent);
            if (interface_data.username) {
                conditional_timeout(recent_container_id, 5, show_recent_for_user_if_fetched);
            } else {
                conditional_timeout(recent_container_id, 5, show_recent);
            }
            choose = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-home-section"})]);
            content.appendChild(choose);
            choose.appendChild(E.h2(_("Choose the calibre library to browse…")));
            choose.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-home-actions"})]));
            cl = choose.lastChild;
            var ρσ_Iter8 = ρσ_Iterable(all_libraries());
            for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                ρσ_unpack = ρσ_Iter8[ρσ_Index8];
                library_id = ρσ_unpack[0];
                library_name = ρσ_unpack[1];
                library_name = (ρσ_expr_temp = interface_data.library_map)[(typeof library_id === "number" && library_id < 0) ? ρσ_expr_temp.length + library_id : library_id];
                if (library_name) {
                    cl.appendChild(ρσ_interpolate_kwargs.call(this, create_button, [library_name].concat([ρσ_desugar_kwargs({icon: "library", action: (function() {
                        var ρσ_anonfunc = function (ev) {
                            var lib_id, q, vlid;
                            lib_id = ev.currentTarget.dataset.lid;
                            q = (function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["library_id"] = lib_id;
                                return ρσ_d;
                            }).call(this);
                            vlid = last_virtual_library_for(lib_id);
                            if (vlid) {
                                q.vl = vlid;
                            }
                            show_panel("book_list", q);
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["ev"]},
                            __module__ : {value: "book_list.home"}
                        });
                        return ρσ_anonfunc;
                    })()})])));
                    cl.lastChild.dataset.lid = library_id;
                }
            }
            newly = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display: none", class_: "cs-home-section recently-read"})]);
            newly.appendChild(E.h2(_("Newly added…")));
            newly_container_id = ensure_id(newly);
            content.appendChild(newly);
            ajax("interface-data/newly-added", newly_added_received.bind(null, newly_container_id)).send();
            offline_mode = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "font-size:smaller", class_: "cs-home-section recently-read"})]);
            offline_mode.textContent = _("Offline mode is not supported");
            content.appendChild(offline_mode);
            if (ρσ_exists.d(window.performance).getEntriesByType) {
                nav = window.performance.getEntriesByType("navigation");
                if (nav && nav.length > 0) {
                    nav = nav[0];
                    if (nav.workerStart > 0) {
                        if (nav.transferSize === 0 && nav.decodedBodySize > 0) {
                            offline_mode.textContent = _("Loaded from cache in offline mode");
                        } else {
                            offline_mode.textContent = _("Offline mode is available");
                        }
                    } else {
                        if (window.isSecureContext) {
                            offline_mode.textContent = _("Offline mode is possible, reload the page to enable it");
                        } else {
                            offline_mode.textContent = _("Offline mode is not available, you need to setup HTTPS support in the calibre Content server");
                        }
                    }
                }
            }
        };
        if (!init.__argnames__) Object.defineProperties(init, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.home"}
        });

        set_default_panel_handler(init);
        ρσ_modules["book_list.home"].CLASS_NAME = CLASS_NAME;
        ρσ_modules["book_list.home"].recently_read_by_user = recently_read_by_user;
        ρσ_modules["book_list.home"].update_recently_read_by_user = update_recently_read_by_user;
        ρσ_modules["book_list.home"].update_book_in_recently_read_by_user_on_home_page = update_book_in_recently_read_by_user_on_home_page;
        ρσ_modules["book_list.home"].show_cover = show_cover;
        ρσ_modules["book_list.home"].read_book = read_book;
        ρσ_modules["book_list.home"].view_book_page = view_book_page;
        ρσ_modules["book_list.home"].get_last_read_position = get_last_read_position;
        ρσ_modules["book_list.home"].sync_data_received = sync_data_received;
        ρσ_modules["book_list.home"].start_sync = start_sync;
        ρσ_modules["book_list.home"].prepare_recent_container = prepare_recent_container;
        ρσ_modules["book_list.home"].show_recent_for_user = show_recent_for_user;
        ρσ_modules["book_list.home"].show_recent_stage2 = show_recent_stage2;
        ρσ_modules["book_list.home"].show_recent_for_user_if_fetched = show_recent_for_user_if_fetched;
        ρσ_modules["book_list.home"].show_recent = show_recent;
        ρσ_modules["book_list.home"].newly_added_received = newly_added_received;
        ρσ_modules["book_list.home"].change_password = change_password;
        ρσ_modules["book_list.home"].show_user_details = show_user_details;
        ρσ_modules["book_list.home"].init = init;
    })();

    (function(){
        var __name__ = "read_book.bookmarks";
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var build_list = ρσ_modules["book_list.item_list"].build_list;
        var create_item = ρσ_modules["book_list.item_list"].create_item;
        var create_side_action = ρσ_modules["book_list.item_list"].create_side_action;

        var ensure_id = ρσ_modules.dom.ensure_id;
        var set_css = ρσ_modules.dom.set_css;

        var question_dialog = ρσ_modules.modals.question_dialog;

        var create_button = ρσ_modules.widgets.create_button;

        var get_book_mark_title = ρσ_modules["read_book.toc"].get_book_mark_title;

        function goto_cfi(cfi, view) {
            view.goto_cfi(cfi, true);
        };
        if (!goto_cfi.__argnames__) Object.defineProperties(goto_cfi, {
            __argnames__ : {value: ["cfi", "view"]},
            __module__ : {value: "read_book.bookmarks"}
        });

        function remove_bookmark(annotations_manager, title, list_dom_node) {
            question_dialog(_("Are you sure?"), _("Do you want to permanently delete this bookmark?"), (function() {
                var ρσ_anonfunc = function (yes) {
                    if (yes) {
                        annotations_manager.remove_bookmark(title);
                        list_dom_node.style.display = "none";
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["yes"]},
                    __module__ : {value: "read_book.bookmarks"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!remove_bookmark.__argnames__) Object.defineProperties(remove_bookmark, {
            __argnames__ : {value: ["annotations_manager", "title", "list_dom_node"]},
            __module__ : {value: "read_book.bookmarks"}
        });

        function edit_bookmark(annotations_manager, title, list_dom_node) {
            var new_title;
            new_title = window.prompt(_("Enter new title for bookmark:"), title);
            if (new_title) {
                if (annotations_manager.edit_bookmark(title, new_title)) {
                    console.log(list_dom_node);
                    list_dom_node.querySelector(".item-title").textContent = new_title;
                }
            }
        };
        if (!edit_bookmark.__argnames__) Object.defineProperties(edit_bookmark, {
            __argnames__ : {value: ["annotations_manager", "title", "list_dom_node"]},
            __module__ : {value: "read_book.bookmarks"}
        });

        function create_bookmarks_list(annotations_manager, onclick) {
            var bookmarks, items, sa, ea, bookmark, c;
            bookmarks = ρσ_interpolate_kwargs.call(this, sorted, [annotations_manager.all_bookmarks()].concat([ρσ_desugar_kwargs({key: (function() {
                var ρσ_anonfunc = function (x) {
                    return x.title.toLowerCase();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["x"]},
                    __module__ : {value: "read_book.bookmarks"}
                });
                return ρσ_anonfunc;
            })()})]));
            items = ρσ_list_decorate([]);
            var ρσ_Iter0 = ρσ_Iterable(bookmarks);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                bookmark = ρσ_Iter0[ρσ_Index0];
                if (!bookmark.removed) {
                    sa = create_side_action("trash", remove_bookmark.bind(null, annotations_manager, bookmark.title), _("Remove this bookmark"));
                    ea = create_side_action("edit", edit_bookmark.bind(null, annotations_manager, bookmark.title), _("Edit this bookmark"));
                    items.push(ρσ_interpolate_kwargs.call(this, create_item, [bookmark.title].concat([ρσ_desugar_kwargs({data: bookmark.pos, action: onclick.bind(null, goto_cfi.bind(null, bookmark.pos)), side_actions: ρσ_list_decorate([ sa, ea ])})])));
                }
            }
            c = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-top: 1ex"})]);
            build_list(c, items);
            return c;
        };
        if (!create_bookmarks_list.__argnames__) Object.defineProperties(create_bookmarks_list, {
            __argnames__ : {value: ["annotations_manager", "onclick"]},
            __module__ : {value: "read_book.bookmarks"}
        });

        function create_new_bookmark(annotations_manager, data) {
            var base_default_title, title, cfi;
            base_default_title = get_book_mark_title() || _("Bookmark");
            title = window.prompt(_("Enter title for bookmark:"), data.selected_text || annotations_manager.default_bookmark_title(base_default_title));
            if (!title) {
                return false;
            }
            cfi = data.cfi;
            if (ρσ_exists.d(data.selection_bounds).start) {
                cfi = data.selection_bounds.start;
            }
            annotations_manager.add_bookmark(title, cfi);
            return true;
        };
        if (!create_new_bookmark.__argnames__) Object.defineProperties(create_new_bookmark, {
            __argnames__ : {value: ["annotations_manager", "data"]},
            __module__ : {value: "read_book.bookmarks"}
        });

        function new_bookmark(container_id, annotations_manager, data, onclick, ev) {
            if (create_new_bookmark(annotations_manager, data)) {
                onclick((function() {
                    var ρσ_anonfunc = function () {
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.bookmarks"}
                    });
                    return ρσ_anonfunc;
                })());
            }
        };
        if (!new_bookmark.__argnames__) Object.defineProperties(new_bookmark, {
            __argnames__ : {value: ["container_id", "annotations_manager", "data", "onclick", "ev"]},
            __module__ : {value: "read_book.bookmarks"}
        });

        function create_bookmarks_panel(annotations_manager, data, book, container, onclick) {
            var container_id, button;
            ρσ_interpolate_kwargs.call(this, set_css, [container].concat([ρσ_desugar_kwargs({display: "flex", flex_direction: "column"})]));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "padding: 1rem"})]));
            container = container.lastChild;
            container_id = ensure_id(container);
            button = create_button(_("New bookmark"), "plus", new_bookmark.bind(null, container_id, annotations_manager, data, onclick));
            container.appendChild(E.div(button));
            container.appendChild(E.div(create_bookmarks_list(annotations_manager, onclick)));
        };
        if (!create_bookmarks_panel.__argnames__) Object.defineProperties(create_bookmarks_panel, {
            __argnames__ : {value: ["annotations_manager", "data", "book", "container", "onclick"]},
            __module__ : {value: "read_book.bookmarks"}
        });

        ρσ_modules["read_book.bookmarks"].goto_cfi = goto_cfi;
        ρσ_modules["read_book.bookmarks"].remove_bookmark = remove_bookmark;
        ρσ_modules["read_book.bookmarks"].edit_bookmark = edit_bookmark;
        ρσ_modules["read_book.bookmarks"].create_bookmarks_list = create_bookmarks_list;
        ρσ_modules["read_book.bookmarks"].create_new_bookmark = create_new_bookmark;
        ρσ_modules["read_book.bookmarks"].new_bookmark = new_bookmark;
        ρσ_modules["read_book.bookmarks"].create_bookmarks_panel = create_bookmarks_panel;
    })();

    (function(){
        var __name__ = "read_book.content_popup";
        var CLASS_NAME, TOP_LEVEL_DISPLAY;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var svgicon = ρσ_modules.dom.svgicon;

        var create_wrapped_iframe = ρσ_modules.iframe_comm.create_wrapped_iframe;

        var runtime = ρσ_modules["read_book.globals"].runtime;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;
        var is_dark_theme = ρσ_modules["read_book.globals"].is_dark_theme;

        var load_resources = ρσ_modules["read_book.resources"].load_resources;

        CLASS_NAME = "book-content-popup-container";
        TOP_LEVEL_DISPLAY = "flex";
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, style;
                sel = "." + CLASS_NAME;
                style = "";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({justify_content: "center", align_items: "center", height: "100%"})]));
                sel += " > div";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({border_radius: "8px", border: "solid currentColor 2px", margin: "1rem", padding: "0.5rem", box_shadow: "2px 2px 4px currentColor"})]));
                sel += " > div";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({display: "flex", justify_content: "space-between", align_items: "center"})]));
                sel += " > div";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({display: "flex", justify_content: "space-between", align_items: "center"})]));
                sel += " > a";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({margin_left: "1ex", cursor: "pointer", display: "inline-block"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ":hover"].concat([ρσ_desugar_kwargs({transform: "scale(1.5)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ":active"].concat([ρσ_desugar_kwargs({transform: "scale(2)"})]));
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "read_book.content_popup"}
            });
            return ρσ_anonfunc;
        })());
        function ContentPopupOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ContentPopupOverlay.prototype.__bind_methods__.call(this);
            ContentPopupOverlay.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ContentPopupOverlay.prototype, "__bind_methods__", {value: function () {
            this.reset = ContentPopupOverlay.prototype.reset.bind(this);
            this.create_iframe = ContentPopupOverlay.prototype.create_iframe.bind(this);
            this.on_print = ContentPopupOverlay.prototype.on_print.bind(this);
            this.on_link_activated = ContentPopupOverlay.prototype.on_link_activated.bind(this);
            this.on_close_requested = ContentPopupOverlay.prototype.on_close_requested.bind(this);
            this.hide = ContentPopupOverlay.prototype.hide.bind(this);
            this.show = ContentPopupOverlay.prototype.show.bind(this);
            this.on_iframe_ready = ContentPopupOverlay.prototype.on_iframe_ready.bind(this);
            this.apply_color_scheme = ContentPopupOverlay.prototype.apply_color_scheme.bind(this);
            this.create_footnote_header = ContentPopupOverlay.prototype.create_footnote_header.bind(this);
            this.load_doc = ContentPopupOverlay.prototype.load_doc.bind(this);
            this.show_footnote = ContentPopupOverlay.prototype.show_footnote.bind(this);
            this.show_footnote_item = ContentPopupOverlay.prototype.show_footnote_item.bind(this);
            this.do_pending_load = ContentPopupOverlay.prototype.do_pending_load.bind(this);
            this.show_footnote_item_stage2 = ContentPopupOverlay.prototype.show_footnote_item_stage2.bind(this);
            this.on_content_loaded = ContentPopupOverlay.prototype.on_content_loaded.bind(this);
        }});
        Object.defineProperties(ContentPopupOverlay.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById("book-content-popup-overlay");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "iframe": {
                "enumerable": true, 
                "get": function iframe() {
                    var self = this;
                    return self.iframe_wrapper.iframe;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "is_visible": {
                "enumerable": true, 
                "get": function is_visible() {
                    var self = this;
                    return self.container.style.display !== "none";
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        ContentPopupOverlay.prototype.__init__ = function __init__(view) {
            var self = this;
            var c;
            self.view = view;
            self.loaded_resources = Object.create(null);
            c = self.container;
            c.classList.add(CLASS_NAME);
            c.appendChild(E.div(E.div()));
            c.addEventListener("click", self.hide);
            c.firstChild.addEventListener("click", (function() {
                var ρσ_anonfunc = function (ev) {
                    [ev.stopPropagation(), ev.preventDefault()];
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.content_popup"}
                });
                return ρσ_anonfunc;
            })());
            self.pending_load = null;
        };
        if (!ContentPopupOverlay.prototype.__init__.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.__init__, {
            __argnames__ : {value: ["view"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.__argnames__ = ContentPopupOverlay.prototype.__init__.__argnames__;
        ContentPopupOverlay.__handles_kwarg_interpolation__ = ContentPopupOverlay.prototype.__init__.__handles_kwarg_interpolation__;
        ContentPopupOverlay.prototype.reset = function reset() {
            var self = this;
            if (self.iframe_wrapper) {
                self.iframe_wrapper.reset();
            }
        };
        if (!ContentPopupOverlay.prototype.reset.__module__) Object.defineProperties(ContentPopupOverlay.prototype.reset, {
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.create_iframe = function create_iframe() {
            var self = this;
            var handlers, iframe_kw, entry_point, ρσ_unpack, iframe, c;
            handlers = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["ready"] = self.on_iframe_ready;
                ρσ_d["error"] = self.view.on_iframe_error;
                ρσ_d["content_loaded"] = self.on_content_loaded;
                ρσ_d["print"] = self.on_print;
                ρσ_d["link_activated"] = self.on_link_activated;
                ρσ_d["close_requested"] = self.on_close_requested;
                return ρσ_d;
            }).call(this);
            iframe_kw = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["seamless"] = true;
                ρσ_d["sandbox"] = "allow-scripts";
                ρσ_d["style"] = "width: 100%; max-height: 70vh";
                return ρσ_d;
            }).call(this);
            if (runtime.is_standalone_viewer) {
                entry_point = "" + ρσ_str.format("{}", runtime.FAKE_PROTOCOL) + "://" + ρσ_str.format("{}", runtime.SANDBOX_HOST) + "/book/__popup__";
            } else {
                entry_point = "read_book.footnotes";
            }
            ρσ_unpack = create_wrapped_iframe(handlers, _("Loading data, please wait..."), entry_point, iframe_kw);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            iframe = ρσ_unpack[0];
            self.iframe_wrapper = ρσ_unpack[1];
            iframe.style.colorScheme = (is_dark_theme()) ? "dark" : "light";
            c = self.container;
            c.firstChild.appendChild(iframe);
        };
        if (!ContentPopupOverlay.prototype.create_iframe.__module__) Object.defineProperties(ContentPopupOverlay.prototype.create_iframe, {
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.on_print = function on_print(data) {
            var self = this;
            print(data.string);
        };
        if (!ContentPopupOverlay.prototype.on_print.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.on_print, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.on_link_activated = function on_link_activated(data) {
            var self = this;
            self.view.link_in_content_popup_activated(data.name, data.frag, data.is_popup, data.title);
        };
        if (!ContentPopupOverlay.prototype.on_link_activated.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.on_link_activated, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.on_close_requested = function on_close_requested(data) {
            var self = this;
            self.hide();
        };
        if (!ContentPopupOverlay.prototype.on_close_requested.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.on_close_requested, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.hide = function hide() {
            var self = this;
            self.container.style.display = "none";
            ui_operations.focus_iframe();
        };
        if (!ContentPopupOverlay.prototype.hide.__module__) Object.defineProperties(ContentPopupOverlay.prototype.hide, {
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.show = function show() {
            var self = this;
            var c;
            c = self.container;
            c.style.display = TOP_LEVEL_DISPLAY;
        };
        if (!ContentPopupOverlay.prototype.show.__module__) Object.defineProperties(ContentPopupOverlay.prototype.show, {
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.on_iframe_ready = function on_iframe_ready(msg) {
            var self = this;
            return self.do_pending_load();
        };
        if (!ContentPopupOverlay.prototype.on_iframe_ready.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.on_iframe_ready, {
            __argnames__ : {value: ["msg"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.apply_color_scheme = function apply_color_scheme(bg, fg) {
            var self = this;
            var c;
            c = self.container.firstChild;
            c.style.backgroundColor = bg;
            c.style.color = fg;
            try {
                self.iframe.style.colorScheme = (is_dark_theme()) ? "dark" : "light";
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                } 
            }
        };
        if (!ContentPopupOverlay.prototype.apply_color_scheme.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.apply_color_scheme, {
            __argnames__ : {value: ["bg", "fg"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.create_footnote_header = function create_footnote_header(header) {
            var self = this;
            var bc;
            clear(header);
            header.appendChild(E.h3(self.current_footnote_data.title || _("Footnote")));
            bc = E.div(ρσ_interpolate_kwargs.call(E, E.a, [svgicon("arrow-right")].concat([ρσ_desugar_kwargs({title: _("Go to this footnote in the main view"), href: "javascript:void(0)"})])), ρσ_interpolate_kwargs.call(E, E.a, [svgicon("close")].concat([ρσ_desugar_kwargs({title: _("Close the footnotes window"), href: "javascript:void(0)"})])));
            bc.firstChild.addEventListener("click", (function() {
                var ρσ_anonfunc = function () {
                    self.hide();
                    self.view.goto_named_destination(self.current_footnote_data.name, self.current_footnote_data.frag);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.content_popup"}
                });
                return ρσ_anonfunc;
            })());
            bc.lastChild.addEventListener("click", self.hide);
            header.appendChild(bc);
        };
        if (!ContentPopupOverlay.prototype.create_footnote_header.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.create_footnote_header, {
            __argnames__ : {value: ["header"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.load_doc = function load_doc(name, done_callback) {
            var self = this;
            function cb(resource_data) {
                self.loaded_resources = resource_data;
                done_callback(resource_data);
            };
            if (!cb.__argnames__) Object.defineProperties(cb, {
                __argnames__ : {value: ["resource_data"]},
                __module__ : {value: "read_book.content_popup"}
            });

            load_resources(self.view.book, name, self.loaded_resources, cb);
        };
        if (!ContentPopupOverlay.prototype.load_doc.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.load_doc, {
            __argnames__ : {value: ["name", "done_callback"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.show_footnote = function show_footnote(data) {
            var self = this;
            var c, header, s, bs;
            if (!self.iframe_wrapper) {
                self.create_iframe();
            }
            self.current_footnote_data = data;
            c = self.container.firstChild;
            header = c.firstChild;
            s = header.style;
            s.paddingLeft = s.paddingRight = s.paddingBottom = s.paddingTop = "0";
            s.marginLeft = s.marginRight = s.marginBottom = s.marginTop = "0";
            s.borderBottom = s.borderTop = s.borderLeft = s.borderRight = "solid currentColor 0";
            bs = "solid currentColor 2px";
            if (self.current_footnote_data.vertical_writing_mode) {
                c.style.width = str(Math.floor(50 / data.cols_per_screen)) + "vw";
                self.iframe.style.height = "80vh";
                c.style.writingMode = (self.current_footnote_data.rtl) ? "vertical-rl" : "vertical-lr";
                if (self.current_footnote_data.rtl) {
                    s.paddingLeft = s.marginLeft = "1ex";
                    s.borderLeft = bs;
                } else {
                    s.paddingRight = s.marginRight = "1ex";
                    s.borderRight = bs;
                }
            } else {
                c.style.width = str(Math.floor(100 / data.cols_per_screen)) + "vw";
                self.iframe.style.height = "12ex";
                c.style.writingMode = (self.current_footnote_data.rtl) ? "horizontal-rl" : "horizontal-lr";
                s.paddingBottom = s.marginBottom = "1ex";
                s.borderBottom = bs;
            }
            self.create_footnote_header(header);
            self.load_doc(data.name, self.show_footnote_item);
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["clear"].concat([ρσ_desugar_kwargs({text: _("Loading note, please wait...")})]));
        };
        if (!ContentPopupOverlay.prototype.show_footnote.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.show_footnote, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.show_footnote_item = function show_footnote_item(resource_data) {
            var self = this;
            self.pending_load = [resource_data, self.show_footnote_item_stage2];
            if (self.iframe_wrapper.ready) {
                self.do_pending_load();
            } else {
                self.iframe_wrapper.init();
            }
        };
        if (!ContentPopupOverlay.prototype.show_footnote_item.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.show_footnote_item, {
            __argnames__ : {value: ["resource_data"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.do_pending_load = function do_pending_load() {
            var self = this;
            var ρσ_unpack, data, func;
            if (self.pending_load) {
                ρσ_unpack = self.pending_load;
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                data = ρσ_unpack[0];
                func = ρσ_unpack[1];
                self.pending_load = null;
                func(data);
            }
        };
        if (!ContentPopupOverlay.prototype.do_pending_load.__module__) Object.defineProperties(ContentPopupOverlay.prototype.do_pending_load, {
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.show_footnote_item_stage2 = function show_footnote_item_stage2(resource_data) {
            var self = this;
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_unencrypted_message, ["display"].concat([ρσ_desugar_kwargs({resource_data: resource_data, book: self.view.book, name: self.current_footnote_data.name, frag: self.current_footnote_data.frag, settings: self.view.currently_showing.settings})]));
        };
        if (!ContentPopupOverlay.prototype.show_footnote_item_stage2.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.show_footnote_item_stage2, {
            __argnames__ : {value: ["resource_data"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.on_content_loaded = function on_content_loaded(data) {
            var self = this;
            self.iframe.style.height = "" + ρσ_str.format("{}", data.height) + "px";
        };
        if (!ContentPopupOverlay.prototype.on_content_loaded.__argnames__) Object.defineProperties(ContentPopupOverlay.prototype.on_content_loaded, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.content_popup"}
        });
        ContentPopupOverlay.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ContentPopupOverlay.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ContentPopupOverlay.prototype, "__bases__", {value: []});
        
        
        

        ρσ_modules["read_book.content_popup"].CLASS_NAME = CLASS_NAME;
        ρσ_modules["read_book.content_popup"].TOP_LEVEL_DISPLAY = TOP_LEVEL_DISPLAY;
        ρσ_modules["read_book.content_popup"].ContentPopupOverlay = ContentPopupOverlay;
    })();

    (function(){
        var __name__ = "read_book.goto";
        var traceback = ρσ_modules.traceback;

        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var encode_query_component = ρσ_modules.ajax.encode_query_component;

        var build_list = ρσ_modules["book_list.item_list"].build_list;
        var create_item = ρσ_modules["book_list.item_list"].create_item;

        var ensure_id = ρσ_modules.dom.ensure_id;
        var set_css = ρσ_modules.dom.set_css;

        var error_dialog = ρσ_modules.modals.error_dialog;

        var current_book = ρσ_modules["read_book.globals"].current_book;
        var runtime = ρσ_modules["read_book.globals"].runtime;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var format_pos = ρσ_modules["read_book.prefs.head_foot"].format_pos;

        var get_border_nodes = ρσ_modules["read_book.toc"].get_border_nodes;
        var get_toc_maps = ρσ_modules["read_book.toc"].get_toc_maps;

        var create_button = ρσ_modules.widgets.create_button;

        function create_goto_list() {
            var onclick = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var current_position_data = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var page_list = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var show_sub_panel = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_goto_list.__defaults__.show_sub_panel : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "show_sub_panel")){
                show_sub_panel = ρσ_kwargs_obj.show_sub_panel;
            }
            var ans, items, location_text, landmarks, toc, id_map, ρσ_unpack, before, after, l;
            ans = E.div();
            items = [];
            location_text = format_pos(current_position_data.progress_frac, current_position_data.book_length) + " :: ";
            if (current_position_data.cfi) {
                location_text += current_position_data.cfi;
            }
            landmarks = current_book().manifest.landmarks;
            toc = current_book().manifest.toc;
            id_map = get_toc_maps(toc)[1];
            ρσ_unpack = get_border_nodes(toc, id_map);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            before = ρσ_unpack[0];
            after = ρσ_unpack[1];
            if (after) {
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [_("Next section")].concat([ρσ_desugar_kwargs({icon: "caret-right", subtitle: after.title, action: onclick.bind(null, after.dest, after.frag)})])));
            }
            if (before) {
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [_("Previous section")].concat([ρσ_desugar_kwargs({icon: "caret-left", subtitle: before.title, action: onclick.bind(null, before.dest, before.frag)})])));
            }
            items.push(ρσ_interpolate_kwargs.call(this, create_item, [_("Book start")].concat([ρσ_desugar_kwargs({action: onclick.bind(null, (function() {
                var ρσ_anonfunc = function (view) {
                    view.goto_doc_boundary(true);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["view"]},
                    __module__ : {value: "read_book.goto"}
                });
                return ρσ_anonfunc;
            })())})])));
            items.push(ρσ_interpolate_kwargs.call(this, create_item, [_("Book end")].concat([ρσ_desugar_kwargs({action: onclick.bind(null, (function() {
                var ρσ_anonfunc = function (view) {
                    view.goto_doc_boundary(false);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["view"]},
                    __module__ : {value: "read_book.goto"}
                });
                return ρσ_anonfunc;
            })())})])));
            function panel_action(name, fallback_fn) {
                if (show_sub_panel) {
                    return (function() {
                        var ρσ_anonfunc = function () {
                            show_sub_panel(name);
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.goto"}
                        });
                        return ρσ_anonfunc;
                    })();
                }
                return onclick.bind(null, fallback_fn);
            };
            if (!panel_action.__argnames__) Object.defineProperties(panel_action, {
                __argnames__ : {value: ["name", "fallback_fn"]},
                __module__ : {value: "read_book.goto"}
            });

            items.push(ρσ_interpolate_kwargs.call(this, create_item, [_("Metadata")].concat([ρσ_desugar_kwargs({subtitle: _("Details about this book"), action: panel_action("metadata", (function() {
                var ρσ_anonfunc = function (view) {
                    view.overlay.show_metadata();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["view"]},
                    __module__ : {value: "read_book.goto"}
                });
                return ρσ_anonfunc;
            })())})])));
            if (!runtime.is_standalone_viewer) {
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [_("Book page in library")].concat([ρσ_desugar_kwargs({subtitle: _("The page for this book in the calibre library"), action: onclick.bind(null, (function() {
                    var ρσ_anonfunc = function (view) {
                        view.open_book_page();
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["view"]},
                        __module__ : {value: "read_book.goto"}
                    });
                    return ρσ_anonfunc;
                })())})])));
            }
            items.push(ρσ_interpolate_kwargs.call(this, create_item, [_("Location")].concat([ρσ_desugar_kwargs({subtitle: location_text, action: panel_action("location", (function() {
                var ρσ_anonfunc = function (view) {
                    view.overlay.show_ask_for_location();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["view"]},
                    __module__ : {value: "read_book.goto"}
                });
                return ρσ_anonfunc;
            })())})])));
            if (page_list && page_list.length > 0) {
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [_("Page number")].concat([ρσ_desugar_kwargs({subtitle: _("Typically the page number from a paper edition of this book"), action: panel_action("page_list", (function() {
                    var ρσ_anonfunc = function (view) {
                        view.overlay.show_page_list(page_list);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["view"]},
                        __module__ : {value: "read_book.goto"}
                    });
                    return ρσ_anonfunc;
                })())})])));
            }
            var ρσ_Iter0 = ρσ_Iterable(landmarks);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                l = ρσ_Iter0[ρσ_Index0];
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [l.title].concat([ρσ_desugar_kwargs({action: onclick.bind(null, l.dest, l.frag)})])));
            }
            build_list(ans, items);
            return ans;
        };
        if (!create_goto_list.__defaults__) Object.defineProperties(create_goto_list, {
            __defaults__ : {value: {show_sub_panel:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["onclick", "current_position_data", "page_list", "show_sub_panel"]},
            __module__ : {value: "read_book.goto"}
        });

        function get_next_section(forward) {
            var toc, id_map, ρσ_unpack, before, after;
            toc = current_book().manifest.toc;
            id_map = get_toc_maps(toc)[1];
            ρσ_unpack = get_border_nodes(toc, id_map);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            before = ρσ_unpack[0];
            after = ρσ_unpack[1];
            return (forward) ? after : before;
        };
        if (!get_next_section.__argnames__) Object.defineProperties(get_next_section, {
            __argnames__ : {value: ["forward"]},
            __module__ : {value: "read_book.goto"}
        });

        function create_goto_panel() {
            var current_position_data = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var book = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var container = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var onclick = ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[3];
            var show_sub_panel = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_goto_panel.__defaults__.show_sub_panel : arguments[4];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "show_sub_panel")){
                show_sub_panel = ρσ_kwargs_obj.show_sub_panel;
            }
            var panel;
            panel = create_goto_list(onclick, current_position_data, book.manifest.page_list, show_sub_panel);
            ρσ_interpolate_kwargs.call(this, set_css, [container].concat([ρσ_desugar_kwargs({display: "flex", flex_direction: "column"})]));
            ρσ_interpolate_kwargs.call(this, set_css, [panel].concat([ρσ_desugar_kwargs({flex_grow: "10"})]));
            container.appendChild(panel);
        };
        if (!create_goto_panel.__defaults__) Object.defineProperties(create_goto_panel, {
            __defaults__ : {value: {show_sub_panel:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["current_position_data", "book", "container", "onclick", "show_sub_panel"]},
            __module__ : {value: "read_book.goto"}
        });

        function create_page_list_overlay(book, overlay, container) {
            var list_container, pl, text, search_input, page_list, items, x;
            list_container = E.div();
            pl = overlay.view.current_pagelist_items;
            function goto(x) {
                overlay.view.goto_pagelist_item(x);
                overlay.hide();
            };
            if (!goto.__argnames__) Object.defineProperties(goto, {
                __argnames__ : {value: ["x"]},
                __module__ : {value: "read_book.goto"}
            });

            function goto_matching_page(text) {
                var x, q;
                var ρσ_Iter1 = ρσ_Iterable(page_list);
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    x = ρσ_Iter1[ρσ_Index1];
                    if (x.pagenum === text) {
                        goto(x);
                        return;
                    }
                }
                q = text.toLowerCase();
                var ρσ_Iter2 = ρσ_Iterable(page_list);
                for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                    x = ρσ_Iter2[ρσ_Index2];
                    if (x.pagenum.toLowerCase() === q) {
                        goto(x);
                        return;
                    }
                }
                error_dialog(_("No such page"), _("No page {!r} exists").format(text));
            };
            if (!goto_matching_page.__argnames__) Object.defineProperties(goto_matching_page, {
                __argnames__ : {value: ["text"]},
                __module__ : {value: "read_book.goto"}
            });

            if (pl && pl.length > 0) {
                if (pl.length === 1) {
                    text = _("Currently on page: {}").format(pl[0].pagenum);
                } else {
                    text = _("Currently on pages: {}").format(pl[0].pagenum + " - " + pl[1].pagenum);
                }
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [text].concat([ρσ_desugar_kwargs({style: "margin: 1em"})])));
            }
            search_input = ρσ_interpolate_kwargs.call(E, E.div, [E.div(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "text", placeholder: _("Enter a page number"), onkeydown: (function() {
                var ρσ_anonfunc = function (ev) {
                    var text;
                    if (ev.key === "Enter") {
                        text = ev.target.value;
                        if (text) {
                            goto_matching_page(text);
                        }
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.goto"}
                });
                return ρσ_anonfunc;
            })()})]))].concat([ρσ_desugar_kwargs({style: "margin: 1em"})]));
            container.appendChild(search_input);
            container.appendChild(list_container);
            page_list = book.manifest.page_list || [];
            items = [];
            var ρσ_Iter3 = ρσ_Iterable(page_list);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                x = ρσ_Iter3[ρσ_Index3];
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [x.pagenum].concat([ρσ_desugar_kwargs({action: goto.bind(null, x)})])));
            }
            build_list(list_container, items);
        };
        if (!create_page_list_overlay.__argnames__) Object.defineProperties(create_page_list_overlay, {
            __argnames__ : {value: ["book", "overlay", "container"]},
            __module__ : {value: "read_book.goto"}
        });

        function create_location_overlay(current_position_data, book, overlay, container) {
            var container_id, current_cfi, calibre_book_url;
            container_id = ensure_id(container);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin: 0 1rem"})]));
            container = container.lastChild;
            current_cfi = current_position_data.cfi;
            calibre_book_url = (typeof book !== "undefined" && book !== null ? book : Object.create(null)).calibre_book_url;
            function copy_button(text_to_copy) {
                return ρσ_interpolate_kwargs.call(this, create_button, [_("Copy")].concat([ρσ_desugar_kwargs({action: (function() {
                    var ρσ_anonfunc = function () {
                        var src, orig;
                        src = document.querySelector("#" + ρσ_str.format("{}", container_id) + " input");
                        orig = src.value;
                        src.value = text_to_copy;
                        src.focus();
                        src.select();
                        try {
                            document.execCommand("copy");
                        } finally {
                            src.value = orig;
                        }
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.goto"}
                    });
                    return ρσ_anonfunc;
                })()})]));
            };
            if (!copy_button.__argnames__) Object.defineProperties(copy_button, {
                __argnames__ : {value: ["text_to_copy"]},
                __module__ : {value: "read_book.goto"}
            });

            function display_and_copy(label, text) {
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [label, " ", ρσ_interpolate_kwargs.call(E, E.span, [text].concat([ρσ_desugar_kwargs({style: "font-size: smaller; font-family: monospace; overflow-wrap: anywhere"})]))].concat([ρσ_desugar_kwargs({style: "flex-grow: 10; text-overflow: ellipsis; margin-bottom: 1ex"})])), copy_button(text)].concat([ρσ_desugar_kwargs({style: "margin: 1rem; margin-bottom: calc(1rem - 1ex); display: flex; align-items: baseline; flex-wrap: wrap"})])));
            };
            if (!display_and_copy.__argnames__) Object.defineProperties(display_and_copy, {
                __argnames__ : {value: ["label", "text"]},
                __module__ : {value: "read_book.goto"}
            });

            if (current_cfi) {
                display_and_copy(_("Current location:"), current_cfi);
            }
            function goto_cfi(cfi) {
                if (ui_operations.goto_cfi(cfi)) {
                    overlay.hide();
                } else {
                    error_dialog(_("No such location"), _("No location {} found").format(cfi));
                }
            };
            if (!goto_cfi.__argnames__) Object.defineProperties(goto_cfi, {
                __argnames__ : {value: ["cfi"]},
                __module__ : {value: "read_book.goto"}
            });

            function goto_ref(ref) {
                ref = ref.replace(/,/g, ".");
                if (ui_operations.goto_reference(ref)) {
                    overlay.hide();
                } else {
                    error_dialog(_("No such reference"), _("No reference {} found").format(ref));
                }
            };
            if (!goto_ref.__argnames__) Object.defineProperties(goto_ref, {
                __argnames__ : {value: ["ref"]},
                __module__ : {value: "read_book.goto"}
            });

            if (current_position_data.book_length > 0) {
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Current position: {}").format(format_pos(current_position_data.progress_frac, current_position_data.book_length))].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Type the position, location or reference below. For a reference type ref: followed by the reference:")].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
            function goto_pos() {
                var src;
                src = document.querySelector("#" + ρσ_str.format("{}", container_id) + " [name=newpos]").value;
                if (!src) {
                    return;
                }
                if (src.indexOf("epubcfi(") === 0) {
                    return goto_cfi(src);
                }
                if (src.indexOf("ref:") === 0) {
                    return goto_ref(src.slice(len("ref:")));
                }
                var ρσ_try_else_1 = false;
                try {
                    ui_operations.goto_book_position(float(src));
                    ρσ_try_else_1 = true;
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        error_dialog(_("Not a valid book position"), _("{} is not a valid book position").format(src), traceback.format_exc());
                    } 
                }
                if (ρσ_try_else_1) {
                    overlay.hide();
                }
            };
            if (!goto_pos.__module__) Object.defineProperties(goto_pos, {
                __module__ : {value: "read_book.goto"}
            });

            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.label, [_("Go to:")].concat([ρσ_desugar_kwargs({style: "margin-right: 1rem"})])), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "newpos", type: "text", style: "flex-grow: 10; margin-right: 1rem", onkeydown: (function() {
                var ρσ_anonfunc = function (ev) {
                    if (ev.key === "Enter") {
                        goto_pos();
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.goto"}
                });
                return ρσ_anonfunc;
            })()})]), E.span(" "), ρσ_interpolate_kwargs.call(this, create_button, [_("Go")].concat([ρσ_desugar_kwargs({action: goto_pos})]))].concat([ρσ_desugar_kwargs({style: "display: flex; align-items: baseline; flex-wrap: wrap"})]))].concat([ρσ_desugar_kwargs({style: "margin: 1rem;"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Note that using a position is not very robust, it is best to use either the location or reference.")].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
            if (calibre_book_url) {
                if (current_cfi) {
                    calibre_book_url += "?open_at=" + encode_query_component(current_cfi);
                }
                display_and_copy(_("URL for this position:"), calibre_book_url);
            } else if (!runtime.is_standalone_viewer) {
                display_and_copy(_("URL for this position:"), window.top.location.toString());
            }
            window.setTimeout((function() {
                var ρσ_anonfunc = function () {
                    var container;
                    container = document.getElementById(container_id);
                    if (container) {
                        container.querySelector("[name=newpos]").focus();
                    }
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.goto"}
                });
                return ρσ_anonfunc;
            })(), 10);
        };
        if (!create_location_overlay.__argnames__) Object.defineProperties(create_location_overlay, {
            __argnames__ : {value: ["current_position_data", "book", "overlay", "container"]},
            __module__ : {value: "read_book.goto"}
        });

        ρσ_modules["read_book.goto"].create_goto_list = create_goto_list;
        ρσ_modules["read_book.goto"].get_next_section = get_next_section;
        ρσ_modules["read_book.goto"].create_goto_panel = create_goto_panel;
        ρσ_modules["read_book.goto"].create_page_list_overlay = create_page_list_overlay;
        ρσ_modules["read_book.goto"].create_location_overlay = create_location_overlay;
    })();

    (function(){
        var __name__ = "file_uploads";
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var ensure_id = ρσ_modules.dom.ensure_id;

        var human_readable = ρσ_modules.utils.human_readable;
        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;

        function upload_files_widget() {
            var container = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var proceed = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var msg = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var single_file = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? upload_files_widget.__defaults__.single_file : arguments[3];
            var accept_extensions = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? upload_files_widget.__defaults__.accept_extensions : arguments[4];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "single_file")){
                single_file = ρσ_kwargs_obj.single_file;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "accept_extensions")){
                accept_extensions = ρσ_kwargs_obj.accept_extensions;
            }
            var container_id, c, a;
            container_id = ensure_id(container, "upload-files");
            function files_selected() {
                var files;
                files = this.files;
                if (c.parentNode) {
                    c.parentNode.removeChild(c);
                }
                if (callable(proceed) && files.length) {
                    proceed(container_id, files);
                }
            };
            if (!files_selected.__module__) Object.defineProperties(files_selected, {
                __module__ : {value: "file_uploads"}
            });

            msg = msg || _("Upload books by either <a>selecting the book files</a> or drag and drop the files here");
            c = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.span, [ρσ_desugar_kwargs({class_: "cs-upload-dropzone-msg"})]), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "file", class_: "cs-upload-file-input", style: "display:none", onchange: files_selected})])].concat([ρσ_desugar_kwargs({class_: "cs-upload-dropzone"})]));
            if (!single_file) {
                c.lastChild.setAttribute("multiple", "multiple");
            }
            if (accept_extensions) {
                c.lastChild.setAttribute("accept", ", ".join((function() {
                    var ρσ_Iter = ρσ_Iterable(accept_extensions.split(" ")), ρσ_Result = [], x;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        x = ρσ_Iter[ρσ_Index];
                        ρσ_Result.push("." + x);
                    }
                    ρσ_Result = ρσ_list_constructor(ρσ_Result);
                    return ρσ_Result;
                })()));
            }
            safe_set_inner_html(c.firstChild, msg);
            a = c.getElementsByTagName("a")[0];
            a.setAttribute("href", "javascript: void(0)");
            a.classList.add("blue-link");
            a.addEventListener("click", (function() {
                var ρσ_anonfunc = function () {
                    document.getElementById(container_id).querySelector("input[type=file]").click();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "file_uploads"}
                });
                return ρσ_anonfunc;
            })(), false);
            function pick_if_not_link(ev) {
                var t, inp;
                t = ev.target;
                if (t && t.tagName.toLowerCase() === "a") {
                    return;
                }
                inp = document.getElementById(container_id).querySelector(".cs-upload-file-input");
                if (inp) {
                    inp.click();
                }
            };
            if (!pick_if_not_link.__argnames__) Object.defineProperties(pick_if_not_link, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "file_uploads"}
            });

            c.addEventListener("click", pick_if_not_link, false);
            container.appendChild(c);
            function stop(e) {
                [e.stopPropagation(), e.preventDefault()];
            };
            if (!stop.__argnames__) Object.defineProperties(stop, {
                __argnames__ : {value: ["e"]},
                __module__ : {value: "file_uploads"}
            });

            function drop(e) {
                var dt;
                stop(e);
                dt = e.dataTransfer;
                files_selected.call(dt);
            };
            if (!drop.__argnames__) Object.defineProperties(drop, {
                __argnames__ : {value: ["e"]},
                __module__ : {value: "file_uploads"}
            });

            c.addEventListener("dragenter", stop, false);
            c.addEventListener("dragover", stop, false);
            c.addEventListener("drop", drop, false);
            return c;
        };
        if (!upload_files_widget.__defaults__) Object.defineProperties(upload_files_widget, {
            __defaults__ : {value: {single_file:false, accept_extensions:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["container", "proceed", "msg", "single_file", "accept_extensions"]},
            __module__ : {value: "file_uploads"}
        });

        function update_status_widget(w, sent, total) {
            var p;
            if (total) {
                p = w.getElementsByTagName("progress")[0];
                p.setAttribute("value", "" + sent);
                p.setAttribute("max", "" + total);
                w.lastChild.textContent = (ρσ_expr_temp = _(" {percent:.0%} of {total}"), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.format, [ρσ_desugar_kwargs({percent: sent / total, total: human_readable(total)})]));
            }
        };
        if (!update_status_widget.__argnames__) Object.defineProperties(update_status_widget, {
            __argnames__ : {value: ["w", "sent", "total"]},
            __module__ : {value: "file_uploads"}
        });

        function upload_status_widget(name, job_id) {
            var ans;
            ans = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-upload-job", data_job: "" + job_id})]);
            if (name) {
                ans.appendChild(ρσ_interpolate_kwargs.call(E, E.h3, [E.b(name)].concat([ρσ_desugar_kwargs({class_: "cs-upload-job-title"})])));
            }
            ans.appendChild(ρσ_interpolate_kwargs.call(E, E.progress, [ρσ_desugar_kwargs({class_: "cs-upload-progress"})]));
            ans.appendChild(ρσ_interpolate_kwargs.call(E, E.span, [ρσ_desugar_kwargs({class_: "cs-upload-progress-label"})]));
            return ans;
        };
        if (!upload_status_widget.__argnames__) Object.defineProperties(upload_status_widget, {
            __argnames__ : {value: ["name", "job_id"]},
            __module__ : {value: "file_uploads"}
        });

        ρσ_modules.file_uploads.upload_files_widget = upload_files_widget;
        ρσ_modules.file_uploads.update_status_widget = update_status_widget;
        ρσ_modules.file_uploads.upload_status_widget = upload_status_widget;
    })();

    (function(){
        var __name__ = "book_list.add";
        var state;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var ajax_send_file = ρσ_modules.ajax.ajax_send_file;

        var force_refresh_on_next_load = ρσ_modules["book_list.library_data"].force_refresh_on_next_load;
        var loaded_books_query = ρσ_modules["book_list.library_data"].loaded_books_query;

        var back = ρσ_modules["book_list.router"].back;

        var create_top_bar = ρσ_modules["book_list.top_bar"].create_top_bar;

        var query_as_href = ρσ_modules["book_list.ui"].query_as_href;
        var show_panel = ρσ_modules["book_list.ui"].show_panel;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var ensure_id = ρσ_modules.dom.ensure_id;

        var update_status_widget = ρσ_modules.file_uploads.update_status_widget;
        var upload_files_widget = ρσ_modules.file_uploads.upload_files_widget;
        var upload_status_widget = ρσ_modules.file_uploads.upload_status_widget;

        var get_interface_data = ρσ_modules.session.get_interface_data;

        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;

        var create_button = ρσ_modules.widgets.create_button;
        var enable_escape_key = ρσ_modules.widgets.enable_escape_key;

        state = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["in_progress"] = false;
            ρσ_d["container_id"] = null;
            ρσ_d["counter"] = 0;
            ρσ_d["number"] = 0;
            ρσ_d["fake_send"] = false;
            ρσ_d["transfers"] = [];
            return ρσ_d;
        }).call(this);
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var panel, sel, s;
                panel = ".cs-add-books";
                sel = panel + " ";
                s = "";
                s += ρσ_interpolate_kwargs.call(this, build_rule, [panel].concat([ρσ_desugar_kwargs({display: "flex", flex_direction: "column", min_height: "0", flex: "1 1 auto"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [".cs-upload-dropzone"].concat([ρσ_desugar_kwargs({box_sizing: "border-box", min_height: "10rem", padding: "1.1rem 1rem", border: "var(--calibre-border-style-subtle)", border_radius: "14px", background_color: "var(--calibre-color-primary-light)", color: "inherit", transition: "background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-upload-dropzone"].concat([ρσ_desugar_kwargs({min_height: "min(72vh, 520px)", padding: "2rem 1.5rem", margin: "0.75rem 1rem 0.5rem 1rem", border: "2px dashed var(--calibre-color-border)", border_radius: "18px", display: "flex", flex_direction: "column", align_items: "center", justify_content: "center", cursor: "pointer", box_shadow: "0 1px 2px rgba(0,0,0,0.04)"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-upload-dropzone:hover"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light-2)", border_color: "var(--calibre-color-primary)", box_shadow: "0 4px 18px rgba(0,0,0,0.08)"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [".cs-upload-dropzone-msg"].concat([ρσ_desugar_kwargs({display: "block", max_width: "28rem", margin: "0", text_align: "center", font_size: "1.02rem", line_height: "1.55", opacity: "0.92"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-upload-dropzone-msg"].concat([ρσ_desugar_kwargs({font_size: "1.06rem", line_height: "1.6"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [".cs-upload-dropzone-msg a.blue-link"].concat([ρσ_desugar_kwargs({font_weight: "600", text_decoration: "underline", text_underline_offset: "3px"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [".cs-upload-job"].concat([ρσ_desugar_kwargs({margin: "0 0 0.65rem 0", padding: "1.1rem 1.2rem", box_sizing: "border-box", border: "var(--calibre-border-style-subtle)", border_radius: "14px", background_color: get_color("window-background"), box_shadow: "0 2px 8px rgba(0,0,0,0.06)"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-upload-job"].concat([ρσ_desugar_kwargs({margin_left: "1rem", margin_right: "1rem"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [".cs-upload-job-title"].concat([ρσ_desugar_kwargs({margin: "0 0 0.75rem 0", font_size: "1.02rem", font_weight: "700", line_height: "1.35", word_break: "break-word"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [".cs-upload-progress"].concat([ρσ_desugar_kwargs({width: "100%", height: "0.5rem", border_radius: "999px", overflow: "hidden", border: "none", background_color: "rgba(0,0,0,0.08)", accent_color: "var(--calibre-color-primary)"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [".cs-upload-progress-label"].concat([ρσ_desugar_kwargs({display: "block", margin_top: "0.55rem", font_size: "0.88rem", opacity: "0.8"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-add-books-done-msg"].concat([ρσ_desugar_kwargs({display: "inline", margin_right: "0.35rem", font_size: "0.95rem", opacity: "0.88"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-add-books-dup-list"].concat([ρσ_desugar_kwargs({margin_top: "0.45rem"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-add-books-dup-hint"].concat([ρσ_desugar_kwargs({padding: "0.35rem 0", line_height: "1.5", opacity: "0.9"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-add-books-dup-detail"].concat([ρσ_desugar_kwargs({margin_top: "0.85rem", padding_top: "0.85rem", border_top: "var(--calibre-border-style-subtle)", font_size: "0.95rem", line_height: "1.5", opacity: "0.88"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-add-books-dup-detail ol"].concat([ρσ_desugar_kwargs({margin: "0.5rem 0 0 0", padding_left: "1.25rem"})]));
                s += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-add-books-error"].concat([ρσ_desugar_kwargs({padding: "0.5rem 0 0 0", font_size: "0.95rem", line_height: "1.55", color: "inherit"})]));
                s += "\n@media (max-width: 520px) {\n  .cs-add-books .cs-upload-dropzone { min-height: 56vh; padding: 1.35rem 1rem; margin-left: 0.65rem; margin-right: 0.65rem; }\n  .cs-add-books .cs-upload-job { margin-left: 0.65rem; margin-right: 0.65rem; }\n}\n";
                return s;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "book_list.add"}
            });
            return ρσ_anonfunc;
        })());
        function cancel_in_progress() {
            var xhr;
            var ρσ_Iter0 = ρσ_Iterable(state.transfers);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                xhr = ρσ_Iter0[ρσ_Index0];
                xhr.abort();
            }
            state.transfers = [];
            state.in_progress = false;
        };
        if (!cancel_in_progress.__module__) Object.defineProperties(cancel_in_progress, {
            __module__ : {value: "book_list.add"}
        });

        function on_close() {
            cancel_in_progress();
            back();
        };
        if (!on_close.__module__) Object.defineProperties(on_close, {
            __module__ : {value: "book_list.add"}
        });

        function get_job_container(container_id, job_id) {
            var container;
            container = document.getElementById(container_id);
            if (!container) {
                return;
            }
            return container.querySelector("[data-job=\"" + ρσ_str.format("{}", job_id) + "\"]");
        };
        if (!get_job_container.__argnames__) Object.defineProperties(get_job_container, {
            __argnames__ : {value: ["container_id", "job_id"]},
            __module__ : {value: "book_list.add"}
        });

        function on_progress(container_id, job_id, loaded, total, xhr) {
            var container;
            container = get_job_container(container_id, job_id);
            if (!container) {
                return;
            }
            if (total) {
                update_status_widget(container, loaded, total);
            }
        };
        if (!on_progress.__argnames__) Object.defineProperties(on_progress, {
            __argnames__ : {value: ["container_id", "job_id", "loaded", "total", "xhr"]},
            __module__ : {value: "book_list.add"}
        });

        function list_added_book(container, data) {
            var done_msg, q, a;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.h3, [E.b(data.title), E.span(" " + _("by") + " "), E.i(" & ".join(data.authors))].concat([ρσ_desugar_kwargs({class_: "cs-upload-job-title"})])));
            done_msg = _("Added successfully") + " ";
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.span, [done_msg].concat([ρσ_desugar_kwargs({class_: "cs-add-books-done-msg"})])));
            q = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["book_id"] = data.book_id + "";
                return ρσ_d;
            }).call(this);
            a = ρσ_interpolate_kwargs.call(this, create_button, [_("Open")].concat([ρσ_desugar_kwargs({action: query_as_href(q, "book_details")})]));
            if (state.number > 1) {
                a.setAttribute("target", "_blank");
            } else {
                a.addEventListener("click", (function() {
                    var ρσ_anonfunc = function (e) {
                        e.preventDefault();
                        show_panel("book_details", (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["book_id"] = data.book_id + "";
                            return ρσ_d;
                        }).call(this), true);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["e"]},
                        __module__ : {value: "book_list.add"}
                    });
                    return ρσ_anonfunc;
                })());
            }
            container.appendChild(a);
        };
        if (!list_added_book.__argnames__) Object.defineProperties(list_added_book, {
            __argnames__ : {value: ["container", "data"]},
            __module__ : {value: "book_list.add"}
        });

        function list_duplicate_book(container, container_id, job_id, data, file) {
            var b;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("A book with the title \"{0}\" already exists in the library.").format(data.title)].concat([ρσ_desugar_kwargs({class_: "cs-add-books-dup-hint"})])));
            b = ρσ_interpolate_kwargs.call(this, create_button, [_("Add anyway")].concat([ρσ_desugar_kwargs({action: (function() {
                var ρσ_anonfunc = function () {
                    var c, w;
                    c = get_job_container(container_id, job_id);
                    clear(c);
                    w = upload_status_widget(file.name, job_id);
                    c.appendChild(w);
                    send_file(file, container_id, job_id, true);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.add"}
                });
                return ρσ_anonfunc;
            })()})]));
            function list_duplicates() {
                var ans, item;
                ans = ρσ_interpolate_kwargs.call(E, E.ol, [ρσ_desugar_kwargs({class_: "cs-add-books-dup-ol"})]);
                var ρσ_Iter1 = ρσ_Iterable(data.duplicates);
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    item = ρσ_Iter1[ρσ_Index1];
                    ans.appendChild(E.li(_("{0} by {1}").format(item.title, " & ".join(item.authors))));
                }
                return ans;
            };
            if (!list_duplicates.__module__) Object.defineProperties(list_duplicates, {
                __module__ : {value: "book_list.add"}
            });

            container.appendChild(b);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("The book you are trying to add is:"), E.span(" ", E.b(data.title), " ", _("by"), " ", E.i(" & ".join(data.authors))), _(". Books already in the library with that title are:"), ρσ_interpolate_kwargs.call(E, E.div, [list_duplicates()].concat([ρσ_desugar_kwargs({class_: "cs-add-books-dup-list"})]))].concat([ρσ_desugar_kwargs({class_: "cs-add-books-dup-detail"})])));
        };
        if (!list_duplicate_book.__argnames__) Object.defineProperties(list_duplicate_book, {
            __argnames__ : {value: ["container", "container_id", "job_id", "data", "file"]},
            __module__ : {value: "book_list.add"}
        });

        function write_access_error(msg, xhr) {
            var html, un;
            html = msg + "<br>";
            if (xhr.status === 403) {
                un = get_interface_data().username;
                if (un) {
                    html += _("You are not allowed to make changes to the library") + "<hr>";
                } else {
                    html += _("You must be logged in to make changes to the library") + "<hr>";
                }
            }
            return html + "<br>" + xhr.error_html;
        };
        if (!write_access_error.__argnames__) Object.defineProperties(write_access_error, {
            __argnames__ : {value: ["msg", "xhr"]},
            __module__ : {value: "book_list.add"}
        });

        function on_complete(container_id, job_id, end_type, xhr, ev) {
            var idx, container, data, html;
            idx = state.transfers.indexOf(xhr);
            if (idx > -1) {
                state.transfers.splice(idx, 1);
            }
            container = get_job_container(container_id, job_id);
            if (!container) {
                return;
            }
            clear(container);
            if (end_type === "load") {
                data = JSON.parse(xhr.responseText);
                if (data.book_id) {
                    list_added_book(container, data);
                    force_refresh_on_next_load();
                } else {
                    list_duplicate_book(container, container_id, job_id, data, this);
                }
            } else if (end_type === "abort") {
                return;
            } else {
                html = write_access_error(_("Failed to upload the file: {}").format(this.name), xhr);
                safe_set_inner_html(container, "<div class=\"cs-add-books-error\">" + html + "</div>");
            }
        };
        if (!on_complete.__argnames__) Object.defineProperties(on_complete, {
            __argnames__ : {value: ["container_id", "job_id", "end_type", "xhr", "ev"]},
            __module__ : {value: "book_list.add"}
        });

        function fake_send(container_id, job_id) {
            var container, prev;
            container = get_job_container(container_id, job_id);
            prev = parseInt(container.dataset.fake || "0");
            container.dataset.fake = prev + 10;
            update_status_widget(container, container.dataset.fake, 100);
            if (parseInt(container.dataset.fake || "0") < 100) {
                setTimeout(fake_send.bind(null, container_id, job_id), 1e3);
            }
        };
        if (!fake_send.__argnames__) Object.defineProperties(fake_send, {
            __argnames__ : {value: ["container_id", "job_id"]},
            __module__ : {value: "book_list.add"}
        });

        function send_file(file, container_id, job_id, add_duplicates) {
            var lid, ad, xhr;
            lid = loaded_books_query().library_id;
            ad = (add_duplicates) ? "y" : "n";
            xhr = ajax_send_file("cdb/add-book/" + ρσ_str.format("{}", job_id) + "/" + ρσ_str.format("{}", ad) + "/" + ρσ_str.format("{}", encodeURIComponent(file.name)) + "/" + ρσ_str.format("{}", lid) + "", file, on_complete.bind(file, container_id, job_id), on_progress.bind(null, container_id, job_id));
            state.transfers.push(xhr);
            return xhr;
        };
        if (!send_file.__argnames__) Object.defineProperties(send_file, {
            __argnames__ : {value: ["file", "container_id", "job_id", "add_duplicates"]},
            __module__ : {value: "book_list.add"}
        });

        function files_chosen(container_id, files) {
            var container, job_id, w, file;
            container = document.getElementById(container_id);
            if (!container) {
                return;
            }
            state.number = 0;
            var ρσ_Iter2 = ρσ_Iterable(files);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                file = ρσ_Iter2[ρσ_Index2];
                state.counter += 1;
                state.number += 1;
                job_id = state.counter;
                w = upload_status_widget(file.name, job_id);
                container.appendChild(w);
                if (state.fake_send) {
                    setTimeout(fake_send.bind(null, container_id, job_id), 100);
                } else {
                    send_file(file, container_id, job_id);
                }
            }
        };
        if (!files_chosen.__argnames__) Object.defineProperties(files_chosen, {
            __argnames__ : {value: ["container_id", "files"]},
            __module__ : {value: "book_list.add"}
        });

        function add_books_panel(container_id) {
            var container;
            container = document.getElementById(container_id);
            container.classList.add("cs-add-books");
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("Add books"), action: on_close, icon: "close"})]));
            cancel_in_progress();
            state.in_progress = true;
            state.container_id = container_id;
            state.fake_send = false;
            enable_escape_key(container, on_close);
            return upload_files_widget(container, files_chosen);
        };
        if (!add_books_panel.__argnames__) Object.defineProperties(add_books_panel, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.add"}
        });

        function develop(container) {
            add_books_panel(ensure_id(container));
        };
        if (!develop.__argnames__) Object.defineProperties(develop, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.add"}
        });

        ρσ_modules["book_list.add"].state = state;
        ρσ_modules["book_list.add"].cancel_in_progress = cancel_in_progress;
        ρσ_modules["book_list.add"].on_close = on_close;
        ρσ_modules["book_list.add"].get_job_container = get_job_container;
        ρσ_modules["book_list.add"].on_progress = on_progress;
        ρσ_modules["book_list.add"].list_added_book = list_added_book;
        ρσ_modules["book_list.add"].list_duplicate_book = list_duplicate_book;
        ρσ_modules["book_list.add"].write_access_error = write_access_error;
        ρσ_modules["book_list.add"].on_complete = on_complete;
        ρσ_modules["book_list.add"].fake_send = fake_send;
        ρσ_modules["book_list.add"].send_file = send_file;
        ρσ_modules["book_list.add"].files_chosen = files_chosen;
        ρσ_modules["book_list.add"].add_books_panel = add_books_panel;
        ρσ_modules["book_list.add"].develop = develop;
    })();

    (function(){
        var __name__ = "book_list.delete_book";
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var ajax = ρσ_modules.ajax.ajax;

        var write_access_error = ρσ_modules["book_list.add"].write_access_error;

        var book_after = ρσ_modules["book_list.library_data"].book_after;
        var force_refresh_on_next_load = ρσ_modules["book_list.library_data"].force_refresh_on_next_load;
        var remove_book = ρσ_modules["book_list.library_data"].remove_book;

        var back = ρσ_modules["book_list.router"].back;

        var show_panel = ρσ_modules["book_list.ui"].show_panel;

        var clear = ρσ_modules.dom.clear;

        var create_custom_dialog = ρσ_modules.modals.create_custom_dialog;

        var get_db = ρσ_modules["read_book.db"].get_db;

        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;

        var create_button = ρσ_modules.widgets.create_button;

        function delete_from_cache(library_id, book_id, title) {
            var db;
            db = get_db();
            db.delete_books_matching(library_id, book_id);
        };
        if (!delete_from_cache.__argnames__) Object.defineProperties(delete_from_cache, {
            __argnames__ : {value: ["library_id", "book_id", "title"]},
            __module__ : {value: "book_list.delete_book"}
        });

        function refresh_after_delete(book_id, library_id) {
            var next_book_id;
            force_refresh_on_next_load();
            next_book_id = book_after(book_id);
            remove_book(book_id);
            if (next_book_id) {
                show_panel("book_details", (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["book_id"] = str(next_book_id);
                    ρσ_d["library_id"] = library_id;
                    return ρσ_d;
                }).call(this), true);
            } else {
                back();
            }
        };
        if (!refresh_after_delete.__argnames__) Object.defineProperties(refresh_after_delete, {
            __argnames__ : {value: ["book_id", "library_id"]},
            __module__ : {value: "book_list.delete_book"}
        });

        function do_delete_from_library(parent, close_modal, library_id, book_id, title) {
            parent.appendChild(E.div(_("Deleting {0} from library, please wait...").format(title)));
            function oncomplete(end_type, xhr, ev) {
                var msg;
                if (end_type === "load" || end_type === "abort") {
                    close_modal();
                    if (end_type === "load") {
                        refresh_after_delete(book_id, library_id);
                    }
                    return;
                }
                clear(parent);
                msg = E.div();
                safe_set_inner_html(msg, write_access_error(_("Failed to delete {0}, with error:").format(title), xhr));
                parent.appendChild(E.div(msg, ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Close"), null, close_modal, true)].concat([ρσ_desugar_kwargs({class_: "button-box"})]))));
            };
            if (!oncomplete.__argnames__) Object.defineProperties(oncomplete, {
                __argnames__ : {value: ["end_type", "xhr", "ev"]},
                __module__ : {value: "book_list.delete_book"}
            });

            ρσ_interpolate_kwargs.call(this, ajax, ["cdb/delete-books/" + ρσ_str.format("{}", book_id) + "/" + ρσ_str.format("{}", library_id) + "", oncomplete].concat([ρσ_desugar_kwargs({method: "POST"})])).send();
        };
        if (!do_delete_from_library.__argnames__) Object.defineProperties(do_delete_from_library, {
            __argnames__ : {value: ["parent", "close_modal", "library_id", "book_id", "title"]},
            __module__ : {value: "book_list.delete_book"}
        });

        function confirm_delete_from_library(library_id, book_id, title) {
            create_custom_dialog(_("Are you sure?"), (function() {
                var ρσ_anonfunc = function (parent, close_modal) {
                    var msg, m;
                    function action(doit) {
                        if (doit) {
                            clear(parent);
                            do_delete_from_library(parent, close_modal, library_id, book_id, title);
                        } else {
                            close_modal();
                        }
                    };
                    if (!action.__argnames__) Object.defineProperties(action, {
                        __argnames__ : {value: ["doit"]},
                        __module__ : {value: "book_list.delete_book"}
                    });

                    msg = _("This will <b>permanently delete</b> <i>{0}</i> from your calibre library. Are you sure?").format(title);
                    m = E.div();
                    safe_set_inner_html(m, msg);
                    parent.appendChild(E.div(m, ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Cancel"), null, action.bind(null, false)), ρσ_interpolate_kwargs.call(this, create_button, [_("OK"), null, action.bind(null, true)].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: "button-box"})]))));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["parent", "close_modal"]},
                    __module__ : {value: "book_list.delete_book"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!confirm_delete_from_library.__argnames__) Object.defineProperties(confirm_delete_from_library, {
            __argnames__ : {value: ["library_id", "book_id", "title"]},
            __module__ : {value: "book_list.delete_book"}
        });

        function choose_which_delete(library_id, book_id, title) {
            create_custom_dialog(_("Delete from?"), (function() {
                var ρσ_anonfunc = function (parent, close_modal) {
                    function action(from_cache, from_library) {
                        close_modal();
                        if (from_cache) {
                            delete_from_cache(library_id, book_id, title);
                        }
                        if (from_library) {
                            confirm_delete_from_library(library_id, book_id, title);
                        }
                    };
                    if (!action.__argnames__) Object.defineProperties(action, {
                        __argnames__ : {value: ["from_cache", "from_library"]},
                        __module__ : {value: "book_list.delete_book"}
                    });

                    parent.appendChild(E.div(E.div(_("{0} is available both in the browser cache for offline reading and in your calibre library. Where do you want to delete it from?").format(title)), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Cache"), null, action.bind(null, true, false)), create_button(_("Library and cache"), null, action.bind(null, true, true))].concat([ρσ_desugar_kwargs({class_: "button-box"})]))));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["parent", "close_modal"]},
                    __module__ : {value: "book_list.delete_book"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!choose_which_delete.__argnames__) Object.defineProperties(choose_which_delete, {
            __argnames__ : {value: ["library_id", "book_id", "title"]},
            __module__ : {value: "book_list.delete_book"}
        });

        function delete_book_stage2(library_id, book_id, title, has_offline_copies) {
            if (has_offline_copies) {
                choose_which_delete(library_id, book_id, title);
            } else {
                confirm_delete_from_library(library_id, book_id, title);
            }
        };
        if (!delete_book_stage2.__argnames__) Object.defineProperties(delete_book_stage2, {
            __argnames__ : {value: ["library_id", "book_id", "title", "has_offline_copies"]},
            __module__ : {value: "book_list.delete_book"}
        });

        function start_delete_book(library_id, book_id, title) {
            var db;
            book_id = int(book_id);
            db = get_db();
            db.has_book_matching(library_id, book_id, delete_book_stage2.bind(null, library_id, book_id, title));
        };
        if (!start_delete_book.__argnames__) Object.defineProperties(start_delete_book, {
            __argnames__ : {value: ["library_id", "book_id", "title"]},
            __module__ : {value: "book_list.delete_book"}
        });

        ρσ_modules["book_list.delete_book"].delete_from_cache = delete_from_cache;
        ρσ_modules["book_list.delete_book"].refresh_after_delete = refresh_after_delete;
        ρσ_modules["book_list.delete_book"].do_delete_from_library = do_delete_from_library;
        ρσ_modules["book_list.delete_book"].confirm_delete_from_library = confirm_delete_from_library;
        ρσ_modules["book_list.delete_book"].choose_which_delete = choose_which_delete;
        ρσ_modules["book_list.delete_book"].delete_book_stage2 = delete_book_stage2;
        ρσ_modules["book_list.delete_book"].start_delete_book = start_delete_book;
    })();

    (function(){
        var __name__ = "book_list.details_list";
        var DETAILS_LIST_CLASS, ITEM_CLASS, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, BORDER_RADIUS;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var effective_book_list_is_dark = ρσ_modules["book_list.theme"].effective_book_list_is_dark;
        var css_for_variables = ρσ_modules["book_list.theme"].css_for_variables;
        var get_color = ρσ_modules["book_list.theme"].get_color;

        var format_date = ρσ_modules.date.format_date;

        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var set_css = ρσ_modules.dom.set_css;
        var svgicon = ρσ_modules.dom.svgicon;

        var get_interface_data = ρσ_modules.session.get_interface_data;

        var fmt_sidx = ρσ_modules.utils.fmt_sidx;
        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;
        var sandboxed_html = ρσ_modules.utils.sandboxed_html;

        DETAILS_LIST_CLASS = "book-list-details-list";
        ITEM_CLASS = DETAILS_LIST_CLASS + "-item";
        function description() {
            return _("A list with thumbnails and some book details");
        };
        if (!description.__module__) Object.defineProperties(description, {
            __module__ : {value: "book_list.details_list"}
        });

        THUMBNAIL_MAX_WIDTH = 35 * 3;
        THUMBNAIL_MAX_HEIGHT = int(THUMBNAIL_MAX_WIDTH * 3 / 2);
        BORDER_RADIUS = 6;
        function details_list_css() {
            var ans, sel, s, top, extra_data, primary;
            ans = "";
            sel = "." + DETAILS_LIST_CLASS;
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({cursor: "pointer", user_select: "none", display: "flex", flex_direction: "column", gap: "0.75rem", padding_top: "0.75rem", padding_bottom: "0.75rem", min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", sel) + " > .book-list-item"].concat([ρσ_desugar_kwargs({min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " a:hover"].concat([ρσ_desugar_kwargs({text_decoration: "none"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " > div"].concat([ρσ_desugar_kwargs({margin: "0", padding: "0", border: "none"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", sel) + " ." + ρσ_str.format("{}", ITEM_CLASS) + ""].concat([ρσ_desugar_kwargs({display: "flex", align_items: "stretch", gap: "1rem", padding: "0.85rem 1rem", border_radius: "18px", border: "var(--calibre-border-style-subtle)", background: "var(--calibre-surface-1)", box_shadow: "0 16px 44px rgba(0,0,0,0.10)", text_decoration: "none", min_width: "0", max_width: "100%", width: "100%", box_sizing: "border-box", overflow: "hidden"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", sel) + " ." + ρσ_str.format("{}", ITEM_CLASS) + ":hover"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light)", border_color: "var(--calibre-color-border)", box_shadow: "0 20px 56px rgba(0,0,0,0.12), 0 0 0 4px var(--calibre-color-primary-light)"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", sel) + " ." + ρσ_str.format("{}", ITEM_CLASS) + ":active"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light-2)", transform: "translateY(0.5px)"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", sel) + " ." + ρσ_str.format("{}", ITEM_CLASS) + ":hover .details-list-left > img"].concat([ρσ_desugar_kwargs({box_shadow: "0 10px 24px rgba(0,0,0,0.14)"})]));
            s = sel + " .details-list-left";
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [s].concat([ρσ_desugar_kwargs({margin_right: "1em", min_width: "" + ρσ_str.format("{}", THUMBNAIL_MAX_WIDTH) + "px", height: "" + ρσ_str.format("{}", THUMBNAIL_MAX_HEIGHT) + "px", display: "flex", align_items: "stretch"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [s + " > img"].concat([ρσ_desugar_kwargs({border_radius: BORDER_RADIUS + "px", width: "" + ρσ_str.format("{}", THUMBNAIL_MAX_WIDTH) + "px", height: "" + ρσ_str.format("{}", THUMBNAIL_MAX_HEIGHT) + "px", display: "block", object_fit: "cover", border: "var(--calibre-border-style-subtle)", transition: "box-shadow 160ms ease"})]));
            s = sel + " .details-list-right";
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [s].concat([ρσ_desugar_kwargs({flex_grow: "10", flex_shrink: "1", flex_basis: "0", min_width: "0", max_width: "100%", overflow_x: "hidden", overflow_y: "visible", display: "flex", flex_direction: "column", min_height: "0", box_sizing: "border-box"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .details-main-head"].concat([ρσ_desugar_kwargs({display: "flex", justify_content: "space-between", gap: "0.75rem", overflow_x: "hidden", overflow_y: "hidden", flex_shrink: "0", min_height: "0", min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .details-head-primary"].concat([ρσ_desugar_kwargs({display: "flex", flex_direction: "column", flex: "1 1 0", min_width: "0", max_width: "100%", min_height: "0", overflow: "hidden"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .details-title-authors"].concat([ρσ_desugar_kwargs({flex: "0 0 auto", min_width: "0", max_width: "100%", overflow: "hidden"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .details-title"].concat([ρσ_desugar_kwargs({display: "block", white_space: "nowrap", overflow: "hidden", text_overflow: "ellipsis"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .details-authors"].concat([ρσ_desugar_kwargs({display: "block", margin_top: "0.1rem", opacity: "0.88", white_space: "nowrap", overflow: "hidden", text_overflow: "ellipsis"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .details-comments"].concat([ρσ_desugar_kwargs({min_height: "4ex", margin_top: "0.65ex", height: "0", border: "none", flex_grow: "1"})]));
            ans += sel + " .details-meta {\n  margin-top: 0.35ex;\n  display: flex;\n  flex-wrap: wrap;\n  align-content: flex-start;\n  gap: 0.35rem 0.6rem;\n  opacity: 0.78;\n  font-size: 0.92em;\n  line-height: 1.25;\n  overflow: hidden;\n  flex: 0 0 auto;\n  min-width: 0;\n  max-width: 100%;\n  max-height: calc(2 * (1.25em + 0.32rem) + 0.35rem);\n}\n";
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .details-meta:empty"].concat([ρσ_desugar_kwargs({display: "none", margin_top: "0"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .details-badge"].concat([ρσ_desugar_kwargs({display: "inline-flex", align_items: "center", gap: "0.25rem", padding: "0.15rem 0.45rem", border_radius: "999px", border: "var(--calibre-border-style-subtle)", background: "var(--calibre-color-surface-3)", max_width: "100%", white_space: "nowrap", overflow: "hidden", text_overflow: "ellipsis"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .details-series"].concat([ρσ_desugar_kwargs({display: "block", white_space: "nowrap", overflow: "hidden", text_overflow: "ellipsis", max_width: "100%"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .details-rating"].concat([ρσ_desugar_kwargs({display: "block", white_space: "nowrap", overflow: "hidden", text_overflow: "ellipsis", max_width: "100%"})]));
            top = sel + " .details-main-head";
            extra_data = top + " > div:last-child";
            primary = sel + " .details-head-primary";
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [extra_data].concat([ρσ_desugar_kwargs({text_align: "right", flex: "0 3 auto", min_width: "0", max_width: "min(18rem, 48%)", overflow_x: "hidden", overflow_y: "visible", box_sizing: "border-box"})]));
            ans += "\n@media (max-width: 640px) {\n  __TOP__ {\n    flex-direction: column;\n    align-items: stretch;\n    gap: 0.5rem;\n  }\n  __EXTRA__ {\n    text-align: left;\n    margin-top: 0.15rem;\n    align-self: stretch;\n    max-width: 100%;\n    flex: 0 3 auto;\n  }\n  __PRIMARY__ {\n    max-width: 100%;\n    flex: 0 1 auto;\n    min-height: 0;\n  }\n  __TA__ {\n    max-width: 100%;\n  }\n}\n".replace("__TOP__", top).replace("__EXTRA__", extra_data).replace("__PRIMARY__", primary).replace("__TA__", sel + " .details-title-authors");
            return ans;
        };
        if (!details_list_css.__module__) Object.defineProperties(details_list_css, {
            __module__ : {value: "book_list.details_list"}
        });

        function init(container) {
            clear(container);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: DETAILS_LIST_CLASS})]));
        };
        if (!init.__argnames__) Object.defineProperties(init, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.details_list"}
        });

        function on_img_load(img, load_type) {
            var div;
            div = img.parentNode;
            if (!div) {
                return;
            }
            if (load_type !== "load") {
                clear(div);
                div.appendChild(E.div(ρσ_interpolate_kwargs.call(E, E.h2, [img.dataset.title].concat([ρσ_desugar_kwargs({style: "text-align:center; font-size:larger; font-weight: bold"})])), ρσ_interpolate_kwargs.call(E, E.div, [_("by")].concat([ρσ_desugar_kwargs({style: "text-align: center"})])), ρσ_interpolate_kwargs.call(E, E.h2, [img.dataset.authors].concat([ρσ_desugar_kwargs({style: "text-align:center; font-size:larger; font-weight: bold"})]))));
                ρσ_interpolate_kwargs.call(this, set_css, [div].concat([ρσ_desugar_kwargs({border: "dashed 1px currentColor", border_radius: BORDER_RADIUS + "px"})]));
            }
        };
        if (!on_img_load.__argnames__) Object.defineProperties(on_img_load, {
            __argnames__ : {value: ["img", "load_type"]},
            __module__ : {value: "book_list.details_list"}
        });

        function sandbox_css() {
            var is_dark_theme;
            is_dark_theme = effective_book_list_is_dark();
            if (!sandbox_css.ans || sandbox_css.is_dark_theme !== is_dark_theme) {
                sandbox_css.ans = css_for_variables() + "\n\n";
                sandbox_css.ans += "html {{ overflow: hidden; color: {} }}".format(get_color("window-foreground"));
                sandbox_css.is_dark_theme = is_dark_theme;
            }
            return sandbox_css.ans;
        };
        if (!sandbox_css.__module__) Object.defineProperties(sandbox_css, {
            __module__ : {value: "book_list.details_list"}
        });

        function create_item(book_id, metadata, create_image, show_book_details, href) {
            var authors, img, ρσ_unpack, img_div, extra_data, comments, interface_data, stars, i, ival, meta, fmts, langs, tgs, tg, right, ans;
            authors = (metadata.authors) ? metadata.authors.join(" & ") : _("Unknown");
            img = create_image(book_id, THUMBNAIL_MAX_WIDTH, THUMBNAIL_MAX_HEIGHT, on_img_load);
            img.setAttribute("alt", _("{} by {}").format(metadata.title, authors));
            ρσ_unpack = [metadata.title, authors];
            img.dataset.title = ρσ_unpack[0];
            img.dataset.authors = ρσ_unpack[1];
            img_div = ρσ_interpolate_kwargs.call(E, E.div, [img].concat([ρσ_desugar_kwargs({class_: "details-list-left"})]));
            extra_data = E.div();
            comments = sandboxed_html(metadata.comments, sandbox_css());
            comments.classList.add("details-comments");
            if (!metadata.comments) {
                comments.style.display = "none";
            }
            interface_data = get_interface_data();
            if (metadata.rating) {
                stars = ρσ_interpolate_kwargs.call(E, E.span, [ρσ_desugar_kwargs({class_: "details-rating"})]);
                var ρσ_Iter0 = ρσ_Iterable(range(Math.floor(int(metadata.rating) / 2)));
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    i = ρσ_Iter0[ρσ_Index0];
                    stars.appendChild(svgicon("star"));
                }
                [extra_data.appendChild(stars), extra_data.appendChild(E.br())];
            }
            if (metadata.series) {
                try {
                    ival = float(metadata.series_index);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        ival = 1;
                    } else {
                        throw ρσ_Exception;
                    }
                }
                ival = ρσ_interpolate_kwargs.call(this, fmt_sidx, [ival].concat([ρσ_desugar_kwargs({use_roman: interface_data.use_roman_numerals_for_series_number})]));
                extra_data.appendChild(safe_set_inner_html(ρσ_interpolate_kwargs.call(E, E.span, [ρσ_desugar_kwargs({class_: "details-series"})]), _("{0} of <i>{1}</i>").format(ival, metadata.series)));
            }
            meta = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "details-meta"})]);
            function add_badge() {
                var icon = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
                var text = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
                var title = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_badge.__defaults__.title : arguments[2];
                var ρσ_kwargs_obj = arguments[arguments.length-1];
                if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "title")){
                    title = ρσ_kwargs_obj.title;
                }
                var b;
                if (!text) {
                    return;
                }
                b = ρσ_interpolate_kwargs.call(E, E.span, [ρσ_desugar_kwargs({class_: "details-badge"})]);
                if (icon) {
                    b.appendChild(svgicon(icon));
                }
                b.appendChild(E.span(text));
                if (title) {
                    b.title = title;
                }
                meta.appendChild(b);
            };
            if (!add_badge.__defaults__) Object.defineProperties(add_badge, {
                __defaults__ : {value: {title:null}},
                __handles_kwarg_interpolation__ : {value: true},
                __argnames__ : {value: ["icon", "text", "title"]},
                __module__ : {value: "book_list.details_list"}
            });

            if (metadata.pubdate) {
                try {
                    add_badge("date", format_date(metadata.pubdate, "yyyy-MM-dd"), _("Published"));
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                    } else {
                        throw ρσ_Exception;
                    }
                }
            }
            fmts = metadata.formats || [];
            if (fmts && fmts.length) {
                add_badge("book", fmts.slice(0, 4).join(" · "), _("Formats"));
            }
            langs = metadata.lang_names || metadata.languages || [];
            if (langs && langs.length) {
                add_badge("global-search", langs.slice(0, 3).join(" · "), _("Languages"));
            }
            tgs = metadata.tags || [];
            if (tgs && tgs.length) {
                var ρσ_Iter1 = ρσ_Iterable(tgs.slice(0, 4));
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    tg = ρσ_Iter1[ρσ_Index1];
                    add_badge("tags", tg, _("Tag"));
                }
            }
            if (metadata.publisher) {
                add_badge("library", metadata.publisher, _("Publisher"));
            }
            right = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.b, [metadata.title || _("Unknown")].concat([ρσ_desugar_kwargs({class_: "details-title"})])), ρσ_interpolate_kwargs.call(E, E.span, [authors].concat([ρσ_desugar_kwargs({class_: "details-authors"})]))].concat([ρσ_desugar_kwargs({class_: "details-title-authors"})])), meta].concat([ρσ_desugar_kwargs({class_: "details-head-primary"})])), extra_data].concat([ρσ_desugar_kwargs({class_: "details-main-head"})])), comments].concat([ρσ_desugar_kwargs({class_: "details-list-right"})]));
            ans = E.div(ρσ_interpolate_kwargs.call(E, E.a, [img_div, right].concat([ρσ_desugar_kwargs({href: href, style: "min-height:" + ρσ_str.format("{}", THUMBNAIL_MAX_HEIGHT) + "px; display: flex", class_: ITEM_CLASS})])));
            ans.addEventListener("click", show_book_details, true);
            return ans;
        };
        if (!create_item.__argnames__) Object.defineProperties(create_item, {
            __argnames__ : {value: ["book_id", "metadata", "create_image", "show_book_details", "href"]},
            __module__ : {value: "book_list.details_list"}
        });

        function append_item(container, item) {
            container.lastChild.appendChild(item);
        };
        if (!append_item.__argnames__) Object.defineProperties(append_item, {
            __argnames__ : {value: ["container", "item"]},
            __module__ : {value: "book_list.details_list"}
        });

        ρσ_modules["book_list.details_list"].DETAILS_LIST_CLASS = DETAILS_LIST_CLASS;
        ρσ_modules["book_list.details_list"].ITEM_CLASS = ITEM_CLASS;
        ρσ_modules["book_list.details_list"].THUMBNAIL_MAX_WIDTH = THUMBNAIL_MAX_WIDTH;
        ρσ_modules["book_list.details_list"].THUMBNAIL_MAX_HEIGHT = THUMBNAIL_MAX_HEIGHT;
        ρσ_modules["book_list.details_list"].BORDER_RADIUS = BORDER_RADIUS;
        ρσ_modules["book_list.details_list"].description = description;
        ρσ_modules["book_list.details_list"].details_list_css = details_list_css;
        ρσ_modules["book_list.details_list"].init = init;
        ρσ_modules["book_list.details_list"].on_img_load = on_img_load;
        ρσ_modules["book_list.details_list"].sandbox_css = sandbox_css;
        ρσ_modules["book_list.details_list"].create_item = create_item;
        ρσ_modules["book_list.details_list"].append_item = append_item;
    })();

    (function(){
        var __name__ = "book_list.custom_list";
        var CUSTOM_LIST_CLASS, ITEM_CLASS;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var sandbox_css = ρσ_modules["book_list.details_list"].sandbox_css;
        var BORDER_RADIUS = ρσ_modules["book_list.details_list"].BORDER_RADIUS;

        var library_data = ρσ_modules["book_list.library_data"].library_data;

        var format_date = ρσ_modules.date.format_date;

        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var set_css = ρσ_modules.dom.set_css;
        var svgicon = ρσ_modules.dom.svgicon;

        var get_interface_data = ρσ_modules.session.get_interface_data;

        var fmt_sidx = ρσ_modules.utils.fmt_sidx;
        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;
        var sandboxed_html = ρσ_modules.utils.sandboxed_html;

        CUSTOM_LIST_CLASS = "book-list-custom-list";
        ITEM_CLASS = CUSTOM_LIST_CLASS + "-item";
        function description() {
            return _("A customizable list (see Preferences->Sharing over the net->Book list template)");
        };
        if (!description.__module__) Object.defineProperties(description, {
            __module__ : {value: "book_list.custom_list"}
        });

        function custom_list_css() {
            var ans, sel, s;
            ans = "";
            sel = "." + CUSTOM_LIST_CLASS;
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({cursor: "pointer", user_select: "none"})]));
            sel += " ." + ITEM_CLASS;
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({margin: "1ex 1em", padding_bottom: "1ex", border_bottom: "solid 1px currentColor", min_width: "0", max_width: "100%", box_sizing: "border-box", overflow: "hidden"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ":hover"].concat([ρσ_desugar_kwargs({text_decoration: "none"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", sel) + ":hover"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light)", border_radius: "14px"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", sel) + ":active"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light-2)"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, ["" + ρσ_str.format("{}", sel) + ":hover .custom-list-left > img"].concat([ρσ_desugar_kwargs({box_shadow: "0 10px 24px rgba(0,0,0,0.14)"})]));
            s = sel + " .custom-list-left";
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [s].concat([ρσ_desugar_kwargs({margin_right: "1em"})]));
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [s + " > img"].concat([ρσ_desugar_kwargs({border_radius: BORDER_RADIUS + "px", transition: "box-shadow 160ms ease"})]));
            sel += " iframe";
            ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({flex_grow: "10", cursor: "pointer", pointer_events: "none"})]));
            return ans;
        };
        if (!custom_list_css.__module__) Object.defineProperties(custom_list_css, {
            __module__ : {value: "book_list.custom_list"}
        });

        function default_template() {
            if (!default_template.ans) {
                default_template.ans = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["thumbnail"] = true;
                    ρσ_d["thumbnail_height"] = 140;
                    ρσ_d["height"] = "auto";
                    ρσ_d["comments_fields"] = ['comments'];
                    ρσ_d["lines"] = ρσ_list_decorate([ _("<b>{title}</b> by {authors}"), _("{series_index} of <i>{series}</i>") + "|||{rating}", "{tags}", _("Date: {timestamp}") + "|||" + _("Published: {pubdate}") + "|||" + _("Publisher: {publisher}"), "" ]);
                    return ρσ_d;
                }).call(this);
            }
            return default_template.ans;
        };
        if (!default_template.__module__) Object.defineProperties(default_template, {
            __module__ : {value: "book_list.custom_list"}
        });

        function render_field(field, mi, book_id) {
            var field_metadata, fm, val, interface_data, name, datatype, func, ans, join, fmt;
            if (field === "id") {
                return book_id + "";
            }
            field_metadata = library_data.field_metadata;
            if (!field_metadata) {
                return;
            }
            fm = field_metadata[(typeof field === "number" && field < 0) ? field_metadata.length + field : field];
            if (!fm || !mi) {
                return;
            }
            val = mi[(typeof field === "number" && field < 0) ? mi.length + field : field];
            if (val === undefined || val === null) {
                return;
            }
            interface_data = get_interface_data();
            function add_val() {
                var val = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
                var is_html = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_val.__defaults__.is_html : arguments[1];
                var join = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_val.__defaults__.join : arguments[2];
                var ρσ_kwargs_obj = arguments[arguments.length-1];
                if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "is_html")){
                    is_html = ρσ_kwargs_obj.is_html;
                }
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "join")){
                    join = ρσ_kwargs_obj.join;
                }
                if (is_html && /[<>]/.test(val + "")) {
                    return safe_set_inner_html(E.span(), val);
                }
                if (join) {
                    val = val.join(join);
                } else {
                    val += "";
                }
                return val;
            };
            if (!add_val.__defaults__) Object.defineProperties(add_val, {
                __defaults__ : {value: {is_html:false, join:null}},
                __handles_kwarg_interpolation__ : {value: true},
                __argnames__ : {value: ["val", "is_html", "join"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_composite(field, fm, name, val) {
                var all_vals;
                if (fm.display && fm.display.contains_html) {
                    return ρσ_interpolate_kwargs.call(this, add_val, [val].concat([ρσ_desugar_kwargs({is_html: true})]));
                }
                if (fm.is_multiple && fm.is_multiple.list_to_ui) {
                    all_vals = filter(null, map(str.strip, val.split(fm.is_multiple.list_to_ui)));
                    return ρσ_interpolate_kwargs.call(this, add_val, [all_vals].concat([ρσ_desugar_kwargs({join: fm.is_multiple.list_to_ui})]));
                }
                return add_val(val);
            };
            if (!process_composite.__argnames__) Object.defineProperties(process_composite, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_authors(field, fm, name, val) {
                return ρσ_interpolate_kwargs.call(this, add_val, [val].concat([ρσ_desugar_kwargs({join: " & "})]));
            };
            if (!process_authors.__argnames__) Object.defineProperties(process_authors, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_publisher(field, fm, name, val) {
                return add_val(val);
            };
            if (!process_publisher.__argnames__) Object.defineProperties(process_publisher, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_formats(field, fm, name, val) {
                return ρσ_interpolate_kwargs.call(this, add_val, [val].concat([ρσ_desugar_kwargs({join: ", "})]));
            };
            if (!process_formats.__argnames__) Object.defineProperties(process_formats, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_rating(field, fm, name, val) {
                var stars, i;
                stars = E.span();
                val = int(val || 0);
                if (val > 0) {
                    for (var ρσ_Index0 = 0; ρσ_Index0 < Math.floor(val / 2); ρσ_Index0++) {
                        i = ρσ_Index0;
                        stars.appendChild(svgicon("star"));
                    }
                    if (fm.display.allow_half_stars && val % 2) {
                        stars.appendChild(svgicon("star-half"));
                    }
                    return stars;
                }
            };
            if (!process_rating.__argnames__) Object.defineProperties(process_rating, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_identifiers(field, fm, name, val) {
                var keys, ans, key;
                if (val) {
                    keys = Object.keys(val);
                    if (keys.length) {
                        ans = [];
                        var ρσ_Iter1 = ρσ_Iterable(keys);
                        for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                            key = ρσ_Iter1[ρσ_Index1];
                            ans.push(key + ":" + val[(typeof key === "number" && key < 0) ? val.length + key : key]);
                        }
                        return ρσ_interpolate_kwargs.call(this, add_val, [ans].concat([ρσ_desugar_kwargs({join: ", "})]));
                    }
                }
            };
            if (!process_identifiers.__argnames__) Object.defineProperties(process_identifiers, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_languages(field, fm, name, val) {
                var langs, k;
                if (val && val.length) {
                    langs = (function() {
                        var ρσ_Iter = ρσ_Iterable(val), ρσ_Result = [], k;
                        for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                            k = ρσ_Iter[ρσ_Index];
                            ρσ_Result.push((ρσ_expr_temp = mi.lang_names)[(typeof k === "number" && k < 0) ? ρσ_expr_temp.length + k : k]);
                        }
                        ρσ_Result = ρσ_list_constructor(ρσ_Result);
                        return ρσ_Result;
                    })();
                    return ρσ_interpolate_kwargs.call(this, add_val, [langs].concat([ρσ_desugar_kwargs({join: ", "})]));
                }
            };
            if (!process_languages.__argnames__) Object.defineProperties(process_languages, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_datetime(field, fm, name, val) {
                var fmt;
                if (val) {
                    fmt = interface_data[ρσ_bound_index("gui_" + field + "_display_format", interface_data)] || (fm["display"] || Object.create(null)).date_format;
                    return add_val(format_date(val, fmt));
                }
            };
            if (!process_datetime.__argnames__) Object.defineProperties(process_datetime, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_series(field, fm, name, val) {
                if (val) {
                    return add_val(val);
                }
            };
            if (!process_series.__argnames__) Object.defineProperties(process_series, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_series_index(field, fm, name, val) {
                var sval;
                sval = mi[ρσ_bound_index(field.slice(0, -6), mi)];
                if (sval) {
                    if (val === null || val === undefined) {
                        val = 1;
                    }
                    return ρσ_interpolate_kwargs.call(this, fmt_sidx, [val].concat([ρσ_desugar_kwargs({use_roman: interface_data.use_roman_numerals_for_series_number})]));
                }
            };
            if (!process_series_index.__argnames__) Object.defineProperties(process_series_index, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            function process_size(field, fm, name, val) {
                var mb;
                val = val || 0;
                mb = 1024 * 1024;
                function fmt(val, suffix) {
                    var ans;
                    ans = "" + ρσ_str.format("{:.1f}", val) + "";
                    if (ans.endsWith(".0")) {
                        ans = ans.slice(0, -2);
                    }
                    return ans + suffix;
                };
                if (!fmt.__argnames__) Object.defineProperties(fmt, {
                    __argnames__ : {value: ["val", "suffix"]},
                    __module__ : {value: "book_list.custom_list"}
                });

                if (val < mb) {
                    return fmt(val / 1024, "KB");
                }
                return fmt(val / mb, "MB");
            };
            if (!process_size.__argnames__) Object.defineProperties(process_size, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.custom_list"}
            });

            name = fm.name || field;
            datatype = fm.datatype;
            if (field === "comments") {
                return;
            }
            if (datatype === "composite") {
                func = process_composite;
            } else if (field === "formats") {
                func = process_formats;
            } else if (datatype === "rating") {
                func = process_rating;
            } else if (field === "identifiers") {
                func = process_identifiers;
            } else if (field === "authors") {
                func = process_authors;
            } else if (field === "publisher") {
                func = process_publisher;
            } else if (field === "languages") {
                func = process_languages;
            } else if (datatype === "datetime") {
                func = process_datetime;
            } else if (datatype === "series") {
                func = process_series;
            } else if (datatype === "comments") {
                if (ρσ_exists.d(fm.display).interpret_as === "short-text") {
                    return add_val(val);
                } else {
                    return;
                }
            } else if (field.endswith("_index")) {
                func = process_series_index;
            } else if (field === "size") {
                func = process_size;
            }
            ans = null;
            if (func) {
                ans = func(field, fm, name, val);
            } else {
                if (datatype === "text" || datatype === "enumeration") {
                    if (val !== undefined && val !== null) {
                        join = (fm.is_multiple) ? fm.is_multiple.list_to_ui : null;
                        ans = ρσ_interpolate_kwargs.call(this, add_val, [val].concat([ρσ_desugar_kwargs({join: join})]));
                    }
                } else if (datatype === "bool") {
                    ans = add_val((val) ? _("Yes") : _("No"));
                } else if (datatype === "int" || datatype === "float") {
                    if (val !== undefined && val !== null) {
                        fmt = (fm.display || Object.create(null)).number_format;
                        if (fmt) {
                            val = fmt.format(val);
                        } else {
                            val += "";
                        }
                        ans = add_val(val);
                    }
                }
            }
            return ans;
        };
        if (!render_field.__argnames__) Object.defineProperties(render_field, {
            __argnames__ : {value: ["field", "mi", "book_id"]},
            __module__ : {value: "book_list.custom_list"}
        });

        function render_part(part, template, book_id, metadata) {
            var count, rendered_count, ans, iterator, replacements, n, rendered, val, field, ρσ_unpack, new_child, old_child;
            count = rendered_count = 0;
            ans = E.div();
            ans.innerHTML = part;
            iterator = document.createNodeIterator(ans, NodeFilter.SHOW_TEXT);
            replacements = [];
            while (true) {
                n = iterator.nextNode();
                if (!n) {
                    break;
                }
                rendered = E.span();
                var ρσ_Iter2 = ρσ_Iterable(n.nodeValue.split(/({#?[_a-z0-9]+})/));
                for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                    field = ρσ_Iter2[ρσ_Index2];
                    if (field[0] === "{" && field[field.length-1] === "}") {
                        count += 1;
                        val = render_field(field.slice(1, -1), metadata, book_id);
                        if (val) {
                            rendered_count += 1;
                            if (typeof val === "string") {
                                val = document.createTextNode(val);
                            }
                            rendered.appendChild(val);
                        }
                    } else {
                        rendered.appendChild(document.createTextNode(field));
                    }
                }
                replacements.push([rendered, n]);
            }
            var ρσ_Iter3 = ρσ_Iterable(replacements);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                ρσ_unpack = ρσ_Iter3[ρσ_Index3];
                new_child = ρσ_unpack[0];
                old_child = ρσ_unpack[1];
                old_child.parentNode.replaceChild(new_child, old_child);
            }
            if (count && !rendered_count) {
                return;
            }
            return ans;
        };
        if (!render_part.__argnames__) Object.defineProperties(render_part, {
            __argnames__ : {value: ["part", "template", "book_id", "metadata"]},
            __module__ : {value: "book_list.custom_list"}
        });

        function render_line(line, template, book_id, metadata) {
            var parts, part, p, ans;
            parts = [];
            line = line || " ";
            var ρσ_Iter4 = ρσ_Iterable(line.split(/\|\|\|/));
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                p = ρσ_Iter4[ρσ_Index4];
                part = render_part(p, template, book_id, metadata);
                if (part) {
                    parts.push(part);
                }
            }
            if (!parts.length) {
                return;
            }
            ans = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "custom-line"})]);
            var ρσ_Iter5 = ρσ_Iterable(parts);
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                p = ρσ_Iter5[ρσ_Index5];
                ans.appendChild(p);
            }
            if (parts.length > 1) {
                ρσ_interpolate_kwargs.call(this, set_css, [ans].concat([ρσ_desugar_kwargs({display: "flex", justify_content: "space-between"})]));
            }
            return ans;
        };
        if (!render_line.__argnames__) Object.defineProperties(render_line, {
            __argnames__ : {value: ["line", "template", "book_id", "metadata"]},
            __module__ : {value: "book_list.custom_list"}
        });

        function render_template_text(template, book_id, metadata) {
            var ans, ldiv, line, html, val, f, comments;
            ans = E.div();
            var ρσ_Iter6 = ρσ_Iterable(template.lines);
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                line = ρσ_Iter6[ρσ_Index6];
                ldiv = render_line(line, template, book_id, metadata);
                if (ldiv) {
                    ans.appendChild(ldiv);
                }
            }
            if (template.comments_fields.length) {
                html = "";
                var ρσ_Iter7 = ρσ_Iterable(template.comments_fields);
                for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                    f = ρσ_Iter7[ρσ_Index7];
                    val = metadata[(typeof f === "number" && f < 0) ? metadata.length + f : f];
                    if (val) {
                        html += "<div style=\"margin-bottom:1.5ex\">" + ρσ_str.format("{}", val) + "</div>";
                    }
                }
                if (html) {
                    comments = sandboxed_html(html, sandbox_css());
                    ans.appendChild(comments);
                }
            }
            return ans;
        };
        if (!render_template_text.__argnames__) Object.defineProperties(render_template_text, {
            __argnames__ : {value: ["template", "book_id", "metadata"]},
            __module__ : {value: "book_list.custom_list"}
        });

        function init(container) {
            clear(container);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: CUSTOM_LIST_CLASS})]));
        };
        if (!init.__argnames__) Object.defineProperties(init, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.custom_list"}
        });

        function on_img_load(img, load_type) {
            var div;
            div = img.parentNode;
            if (!div) {
                return;
            }
            if (load_type !== "load") {
                clear(div);
                div.appendChild(E.div(ρσ_interpolate_kwargs.call(E, E.h2, [img.dataset.title].concat([ρσ_desugar_kwargs({style: "text-align:center; font-size:larger; font-weight: bold"})])), ρσ_interpolate_kwargs.call(E, E.div, [_("by")].concat([ρσ_desugar_kwargs({style: "text-align: center"})])), ρσ_interpolate_kwargs.call(E, E.h2, [img.dataset.authors].concat([ρσ_desugar_kwargs({style: "text-align:center; font-size:larger; font-weight: bold"})]))));
                ρσ_interpolate_kwargs.call(this, set_css, [div].concat([ρσ_desugar_kwargs({border: "dashed 1px currentColor", border_radius: BORDER_RADIUS + "px"})]));
            }
        };
        if (!on_img_load.__argnames__) Object.defineProperties(on_img_load, {
            __argnames__ : {value: ["img", "load_type"]},
            __module__ : {value: "book_list.custom_list"}
        });

        function create_item(book_id, metadata, create_image, show_book_details, href) {
            var template, text_data, height, extra, ans, h, w, img, authors, ρσ_unpack, img_div;
            template = get_interface_data().custom_list_template || default_template();
            text_data = render_template_text(template, book_id, metadata);
            text_data.style.flexGrow = "10";
            text_data.style.overflow = "hidden";
            if (template.thumbnail) {
                height = "" + ρσ_str.format("{}", template.thumbnail_height) + "px";
            } else {
                if (template.height === "auto") {
                    extra = (template.comments_fields.length) ? 5 : 1;
                    height = template.lines.length * 2.5 + extra + "ex";
                } else {
                    height = template.height;
                    if (typeof height === "number") {
                        height += "px";
                    }
                }
            }
            ans = ρσ_interpolate_kwargs.call(E, E.a, [ρσ_desugar_kwargs({style: "height:" + ρσ_str.format("{}", height) + "; display: flex", class_: ITEM_CLASS, href: href})]);
            if (template.thumbnail) {
                h = template.thumbnail_height;
                w = int(.75 * h);
                img = create_image(book_id, w, h, on_img_load);
                authors = (metadata.authors) ? metadata.authors.join(" & ") : _("Unknown");
                img.setAttribute("alt", _("{} by {}").format(metadata.title, authors));
                ρσ_unpack = [metadata.title, authors];
                img.dataset.title = ρσ_unpack[0];
                img.dataset.authors = ρσ_unpack[1];
                img.style.maxWidth = w + "px";
                img.style.maxHeight = h + "px";
                img_div = ρσ_interpolate_kwargs.call(E, E.div, [img].concat([ρσ_desugar_kwargs({class_: "custom-list-left", style: "min-width: " + ρσ_str.format("{}", w) + "px"})]));
                ans.appendChild(img_div);
            }
            ans.appendChild(text_data);
            ans.addEventListener("click", show_book_details, true);
            return ans;
        };
        if (!create_item.__argnames__) Object.defineProperties(create_item, {
            __argnames__ : {value: ["book_id", "metadata", "create_image", "show_book_details", "href"]},
            __module__ : {value: "book_list.custom_list"}
        });

        function append_item(container, item) {
            container.lastChild.appendChild(item);
        };
        if (!append_item.__argnames__) Object.defineProperties(append_item, {
            __argnames__ : {value: ["container", "item"]},
            __module__ : {value: "book_list.custom_list"}
        });

        ρσ_modules["book_list.custom_list"].CUSTOM_LIST_CLASS = CUSTOM_LIST_CLASS;
        ρσ_modules["book_list.custom_list"].ITEM_CLASS = ITEM_CLASS;
        ρσ_modules["book_list.custom_list"].description = description;
        ρσ_modules["book_list.custom_list"].custom_list_css = custom_list_css;
        ρσ_modules["book_list.custom_list"].default_template = default_template;
        ρσ_modules["book_list.custom_list"].render_field = render_field;
        ρσ_modules["book_list.custom_list"].render_part = render_part;
        ρσ_modules["book_list.custom_list"].render_line = render_line;
        ρσ_modules["book_list.custom_list"].render_template_text = render_template_text;
        ρσ_modules["book_list.custom_list"].init = init;
        ρσ_modules["book_list.custom_list"].on_img_load = on_img_load;
        ρσ_modules["book_list.custom_list"].create_item = create_item;
        ρσ_modules["book_list.custom_list"].append_item = append_item;
    })();

    (function(){
        var __name__ = "book_list.saved_virtual_libraries";
        var SAVED_VIRTUAL_LIBRARIES_SETTING, DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON;
        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        SAVED_VIRTUAL_LIBRARIES_SETTING = "saved_virtual_libraries";
        DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON = "📁";
        function all_saved_virtual_libraries() {
            var virtual_libraries;
            virtual_libraries = get_session_data().get(SAVED_VIRTUAL_LIBRARIES_SETTING, []) || [];
            if (!Array.isArray(virtual_libraries)) {
                return [];
            }
            return virtual_libraries;
        };
        if (!all_saved_virtual_libraries.__module__) Object.defineProperties(all_saved_virtual_libraries, {
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        function get_saved_virtual_libraries(library_id) {
            var ans, item;
            library_id = (library_id || "") + "";
            ans = [];
            var ρσ_Iter0 = ρσ_Iterable(all_saved_virtual_libraries());
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                item = ρσ_Iter0[ρσ_Index0];
                if ((item.library_id || "") + "" === library_id) {
                    ans.push(item);
                }
            }
            return ans;
        };
        if (!get_saved_virtual_libraries.__argnames__) Object.defineProperties(get_saved_virtual_libraries, {
            __argnames__ : {value: ["library_id"]},
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        function set_saved_virtual_libraries(virtual_libraries) {
            get_session_data().set(SAVED_VIRTUAL_LIBRARIES_SETTING, virtual_libraries || []);
        };
        if (!set_saved_virtual_libraries.__argnames__) Object.defineProperties(set_saved_virtual_libraries, {
            __argnames__ : {value: ["virtual_libraries"]},
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        function normalize_saved_virtual_library_icon(stored) {
            var s;
            s = ((stored || "") + "").strip();
            if (!s) {
                return DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON;
            }
            return s;
        };
        if (!normalize_saved_virtual_library_icon.__argnames__) Object.defineProperties(normalize_saved_virtual_library_icon, {
            __argnames__ : {value: ["stored"]},
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        function saved_virtual_library_item() {
            var library_id = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var name = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var search_expr = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var virtual_library = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? saved_virtual_library_item.__defaults__.virtual_library : arguments[3];
            var icon = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? saved_virtual_library_item.__defaults__.icon : arguments[4];
            var use_icon = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? saved_virtual_library_item.__defaults__.use_icon : arguments[5];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "virtual_library")){
                virtual_library = ρσ_kwargs_obj.virtual_library;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "icon")){
                icon = ρσ_kwargs_obj.icon;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "use_icon")){
                use_icon = ρσ_kwargs_obj.use_icon;
            }
            library_id = ((library_id || "") + "").strip();
            name = ((name || "") + "").strip();
            search_expr = ((search_expr || "") + "").strip();
            virtual_library = ((virtual_library || "") + "").strip();
            if (!library_id || !name || !search_expr) {
                return null;
            }
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["library_id"] = library_id;
                ρσ_d["name"] = name;
                ρσ_d["search"] = search_expr;
                ρσ_d["vl"] = virtual_library;
                ρσ_d["icon"] = normalize_saved_virtual_library_icon(icon);
                ρσ_d["use_icon"] = use_icon !== false;
                return ρσ_d;
            }).call(this);
        };
        if (!saved_virtual_library_item.__defaults__) Object.defineProperties(saved_virtual_library_item, {
            __defaults__ : {value: {virtual_library:"", icon:DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON, use_icon:true}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["library_id", "name", "search_expr", "virtual_library", "icon", "use_icon"]},
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        function saved_virtual_library_query(item) {
            var q, vl;
            q = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["library_id"] = (item.library_id || "") + "";
                ρσ_d["search"] = (item.search || "") + "";
                return ρσ_d;
            }).call(this);
            vl = (item.vl || "") + "";
            q.vl = (vl) ? vl : null;
            return q;
        };
        if (!saved_virtual_library_query.__argnames__) Object.defineProperties(saved_virtual_library_query, {
            __argnames__ : {value: ["item"]},
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        function saved_virtual_library_nav_initial(name) {
            var s;
            s = ((name || "") + "").strip();
            if (!s) {
                return "·";
            }
            return s[0];
        };
        if (!saved_virtual_library_nav_initial.__argnames__) Object.defineProperties(saved_virtual_library_nav_initial, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        function saved_virtual_library_matches(left, right) {
            if (!left || !right) {
                return false;
            }
            return (left.library_id || "") + "" === (right.library_id || "") + "" && (left.name || "") + "" === (right.name || "") + "";
        };
        if (!saved_virtual_library_matches.__argnames__) Object.defineProperties(saved_virtual_library_matches, {
            __argnames__ : {value: ["left", "right"]},
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        function replace_saved_virtual_library(original, item) {
            var virtual_libraries, updated, found, existing;
            if (!item) {
                return false;
            }
            virtual_libraries = all_saved_virtual_libraries();
            updated = [];
            found = false;
            var ρσ_Iter1 = ρσ_Iterable(virtual_libraries);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                existing = ρσ_Iter1[ρσ_Index1];
                if (!found && saved_virtual_library_matches(existing, original)) {
                    updated.push(item);
                    found = true;
                } else if (!saved_virtual_library_matches(existing, item)) {
                    updated.push(existing);
                }
            }
            if (!found) {
                return false;
            }
            set_saved_virtual_libraries(updated);
            return true;
        };
        if (!replace_saved_virtual_library.__argnames__) Object.defineProperties(replace_saved_virtual_library, {
            __argnames__ : {value: ["original", "item"]},
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        function remove_saved_virtual_library(item) {
            var virtual_libraries, updated, x;
            if (!item) {
                return false;
            }
            virtual_libraries = all_saved_virtual_libraries();
            updated = (function() {
                var ρσ_Iter = ρσ_Iterable(virtual_libraries), ρσ_Result = [], x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    if (!saved_virtual_library_matches(x, item)) {
                        ρσ_Result.push(x);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
            if (updated.length === virtual_libraries.length) {
                return false;
            }
            set_saved_virtual_libraries(updated);
            return true;
        };
        if (!remove_saved_virtual_library.__argnames__) Object.defineProperties(remove_saved_virtual_library, {
            __argnames__ : {value: ["item"]},
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        function save_saved_virtual_library(item) {
            var virtual_libraries, x;
            if (!item) {
                return false;
            }
            virtual_libraries = (function() {
                var ρσ_Iter = ρσ_Iterable(all_saved_virtual_libraries()), ρσ_Result = [], x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    if (!saved_virtual_library_matches(x, item)) {
                        ρσ_Result.push(x);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
            virtual_libraries.unshift(item);
            set_saved_virtual_libraries(virtual_libraries);
            return true;
        };
        if (!save_saved_virtual_library.__argnames__) Object.defineProperties(save_saved_virtual_library, {
            __argnames__ : {value: ["item"]},
            __module__ : {value: "book_list.saved_virtual_libraries"}
        });

        ρσ_modules["book_list.saved_virtual_libraries"].SAVED_VIRTUAL_LIBRARIES_SETTING = SAVED_VIRTUAL_LIBRARIES_SETTING;
        ρσ_modules["book_list.saved_virtual_libraries"].DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON = DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON;
        ρσ_modules["book_list.saved_virtual_libraries"].all_saved_virtual_libraries = all_saved_virtual_libraries;
        ρσ_modules["book_list.saved_virtual_libraries"].get_saved_virtual_libraries = get_saved_virtual_libraries;
        ρσ_modules["book_list.saved_virtual_libraries"].set_saved_virtual_libraries = set_saved_virtual_libraries;
        ρσ_modules["book_list.saved_virtual_libraries"].normalize_saved_virtual_library_icon = normalize_saved_virtual_library_icon;
        ρσ_modules["book_list.saved_virtual_libraries"].saved_virtual_library_item = saved_virtual_library_item;
        ρσ_modules["book_list.saved_virtual_libraries"].saved_virtual_library_query = saved_virtual_library_query;
        ρσ_modules["book_list.saved_virtual_libraries"].saved_virtual_library_nav_initial = saved_virtual_library_nav_initial;
        ρσ_modules["book_list.saved_virtual_libraries"].saved_virtual_library_matches = saved_virtual_library_matches;
        ρσ_modules["book_list.saved_virtual_libraries"].replace_saved_virtual_library = replace_saved_virtual_library;
        ρσ_modules["book_list.saved_virtual_libraries"].remove_saved_virtual_library = remove_saved_virtual_library;
        ρσ_modules["book_list.saved_virtual_libraries"].save_saved_virtual_library = save_saved_virtual_library;
    })();

    (function(){
        var __name__ = "book_list.saved_virtual_library_icon_picker";
        var SAVED_VIRTUAL_LIBRARY_ICON_CHOICES;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON = ρσ_modules["book_list.saved_virtual_libraries"].DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON;
        var normalize_saved_virtual_library_icon = ρσ_modules["book_list.saved_virtual_libraries"].normalize_saved_virtual_library_icon;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var unique_id = ρσ_modules.dom.unique_id;

        SAVED_VIRTUAL_LIBRARY_ICON_CHOICES = ρσ_list_decorate([ ["📁", _("Folder")], ["📂", 
        _("Open folder")], ["🔖", _("Bookmark")], ["📖", _("Book")], ["📚", _("Library")], ["🏠", 
        _("Home")], ["⭐", _("Star")], ["🌟", _("Sparkle")], ["❤️", _("Heart")], ["🔍", _("Search")], ["➕", 
        _("Plus")], ["✏️", _("Pencil")], ["🖼️", _("Image")], ["🔗", _("Link")], ["🤖", 
        _("AI")], ["🎲", _("Random")], ["✅", _("Checkmark")], ["✨", _("Highlight")], ["⚠️", 
        _("Warning")], ["❓", _("Help")], ["🗑️", _("Trash")], ["⚙️", _("Settings")], ["👤", 
        _("User")], ["📣", _("Announcement")], ["🔄", _("Refresh")], ["⬆️", _("Sort up")], ["⬇️", 
        _("Sort down")], ["📋", _("Clipboard")], ["📤", _("Send")], ["🎯", _("Target")], ["💡", 
        _("Idea")], ["🏷️", _("Tag")], ["🌈", _("Rainbow")], ["🎵", _("Music")], ["🎬", 
        _("Film")], ["📌", _("Pin")], ["📝", _("Memo")] ]);
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, ans;
                sel = ".cs-vl-icon-picker ";
                ans = ρσ_interpolate_kwargs.call(this, build_rule, [".cs-vl-icon-picker"].concat([ρσ_desugar_kwargs({margin_top: "0.35rem"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-vl-icon-grid"].concat([ρσ_desugar_kwargs({display: "flex", flex_wrap: "wrap", gap: "0.45rem", align_items: "stretch", justify_content: "flex-start"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "button.cs-vl-icon-btn"].concat([ρσ_desugar_kwargs({display: "inline-flex", align_items: "center", justify_content: "center", width: "2.35rem", height: "2.35rem", padding: "0", margin: "0", box_sizing: "border-box", border: "var(--calibre-border-style-subtle)", border_radius: "10px", background_color: "rgba(0,0,0,0.02)", color: get_color("window-foreground"), cursor: "pointer", line_height: "1", transition: "background 120ms ease, border-color 120ms ease, box-shadow 120ms ease"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "button.cs-vl-icon-btn .cs-vl-emoji"].concat([ρσ_desugar_kwargs({font_size: "1.3rem", line_height: "1", user_select: "none", pointer_events: "none"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "button.cs-vl-icon-btn:hover"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light)", border_color: "var(--calibre-color-border)"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "button.cs-vl-icon-btn:focus"].concat([ρσ_desugar_kwargs({outline: "none", box_shadow: "var(--calibre-focus-ring)"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "button.cs-vl-icon-btn-selected"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light-2)", border_color: "var(--calibre-color-border)", font_weight: "600"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-vl-icon-custom-wrap"].concat([ρσ_desugar_kwargs({margin_top: "0.55rem", display: "flex", flex_direction: "column", gap: "0.35rem", width: "100%", max_width: "100%", box_sizing: "border-box"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-vl-icon-custom-wrap label"].concat([ρσ_desugar_kwargs({font_size: "0.88rem", font_weight: "600", opacity: "0.88"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "input.cs-vl-icon-custom-input"].concat([ρσ_desugar_kwargs({width: "100%", max_width: "100%", box_sizing: "border-box", padding: "0.5rem 0.65rem", border_radius: "10px", border: "var(--calibre-border-style-subtle)", background_color: "rgba(0,0,0,0.02)", color: get_color("window-foreground"), font_size: "1.1rem", line_height: "1.3"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-vl-icon-custom-hint"].concat([ρσ_desugar_kwargs({font_size: "0.82rem", font_weight: "600", opacity: "0.72", line_height: "1.35"})]));
                return ans;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "book_list.saved_virtual_library_icon_picker"}
            });
            return ρσ_anonfunc;
        })());
        function create_saved_virtual_library_icon_picker() {
            var initial_icon = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_saved_virtual_library_icon_picker.__defaults__.initial_icon : arguments[0];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "initial_icon")){
                initial_icon = ρσ_kwargs_obj.initial_icon;
            }
            var state, grid, inp_id, btn, ρσ_unpack, emoji_char, label, custom_inp, custom_wrap, help_span, root;
            state = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["icon"] = normalize_saved_virtual_library_icon(initial_icon) + "";
                return ρσ_d;
            }).call(this);
            grid = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-vl-icon-grid", role: "radiogroup", aria_label: _("Icon presets")})]);
            inp_id = unique_id("cs-vl-icon-custom");
            function sync_grid_only() {
                var found, nm, on, btn;
                found = false;
                var ρσ_Iter0 = ρσ_Iterable(grid.querySelectorAll("button.cs-vl-icon-btn"));
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    btn = ρσ_Iter0[ρσ_Index0];
                    nm = btn.dataset.vlIcon;
                    on = nm === state.icon;
                    if (on) {
                        found = true;
                        btn.classList.add("cs-vl-icon-btn-selected");
                    } else {
                        btn.classList.remove("cs-vl-icon-btn-selected");
                    }
                    btn.setAttribute("aria-checked", (on) ? "true" : "false");
                }
                return found;
            };
            if (!sync_grid_only.__module__) Object.defineProperties(sync_grid_only, {
                __module__ : {value: "book_list.saved_virtual_library_icon_picker"}
            });

            function sync_from_input() {
                var raw;
                raw = (custom_inp.value || "") + "";
                state.icon = normalize_saved_virtual_library_icon(raw);
                sync_grid_only();
            };
            if (!sync_from_input.__module__) Object.defineProperties(sync_from_input, {
                __module__ : {value: "book_list.saved_virtual_library_icon_picker"}
            });

            function make_handler(stored_emoji) {
                function on_click(evt) {
                    evt.preventDefault();
                    state.icon = stored_emoji;
                    custom_inp.value = stored_emoji;
                    sync_grid_only();
                };
                if (!on_click.__argnames__) Object.defineProperties(on_click, {
                    __argnames__ : {value: ["evt"]},
                    __module__ : {value: "book_list.saved_virtual_library_icon_picker"}
                });

                return on_click;
            };
            if (!make_handler.__argnames__) Object.defineProperties(make_handler, {
                __argnames__ : {value: ["stored_emoji"]},
                __module__ : {value: "book_list.saved_virtual_library_icon_picker"}
            });

            var ρσ_Iter1 = ρσ_Iterable(SAVED_VIRTUAL_LIBRARY_ICON_CHOICES);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                ρσ_unpack = ρσ_Iter1[ρσ_Index1];
                emoji_char = ρσ_unpack[0];
                label = ρσ_unpack[1];
                btn = ρσ_interpolate_kwargs.call(E, E.button, [ρσ_desugar_kwargs({type: "button", class_: "cs-vl-icon-btn", role: "radio", title: label})]);
                btn.dataset.vlIcon = emoji_char;
                btn.setAttribute("aria-label", label);
                btn.appendChild(ρσ_interpolate_kwargs.call(E, E.span, [emoji_char].concat([ρσ_desugar_kwargs({class_: "cs-vl-emoji"})])));
                btn.addEventListener("click", make_handler(emoji_char));
                grid.appendChild(btn);
            }
            custom_inp = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "text", id: inp_id, class_: "cs-vl-icon-custom-input", placeholder: _("e.g. emoji or a few characters"), aria_label: _("Custom icon")})]);
            custom_inp.addEventListener("input", (function() {
                var ρσ_anonfunc = function (ev) {
                    sync_from_input();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "book_list.saved_virtual_library_icon_picker"}
                });
                return ρσ_anonfunc;
            })());
            custom_inp.addEventListener("change", (function() {
                var ρσ_anonfunc = function (ev) {
                    sync_from_input();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "book_list.saved_virtual_library_icon_picker"}
                });
                return ρσ_anonfunc;
            })());
            custom_wrap = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.label, [_("Custom")].concat([ρσ_desugar_kwargs({class_: "cs-vl-custom-label", for_: inp_id})])), custom_inp].concat([ρσ_desugar_kwargs({class_: "cs-vl-icon-custom-wrap"})]));
            help_span = ρσ_interpolate_kwargs.call(E, E.span, [_("You can pick a preset above or type your own (emoji, letter, etc.).")].concat([ρσ_desugar_kwargs({class_: "cs-vl-icon-custom-hint"})]));
            custom_wrap.appendChild(help_span);
            if (!sync_grid_only()) {
                custom_inp.value = state.icon + "";
            }
            root = ρσ_interpolate_kwargs.call(E, E.div, [grid, custom_wrap].concat([ρσ_desugar_kwargs({class_: "cs-vl-icon-picker"})]));
            function get_value() {
                var raw, trimmed;
                raw = (custom_inp.value || "") + "";
                trimmed = raw.strip();
                if (trimmed) {
                    return normalize_saved_virtual_library_icon(trimmed);
                }
                return state.icon || DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON;
            };
            if (!get_value.__module__) Object.defineProperties(get_value, {
                __module__ : {value: "book_list.saved_virtual_library_icon_picker"}
            });

            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["root"] = root;
                ρσ_d["get_value"] = get_value;
                return ρσ_d;
            }).call(this);
        };
        if (!create_saved_virtual_library_icon_picker.__defaults__) Object.defineProperties(create_saved_virtual_library_icon_picker, {
            __defaults__ : {value: {initial_icon:DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["initial_icon"]},
            __module__ : {value: "book_list.saved_virtual_library_icon_picker"}
        });

        ρσ_modules["book_list.saved_virtual_library_icon_picker"].SAVED_VIRTUAL_LIBRARY_ICON_CHOICES = SAVED_VIRTUAL_LIBRARY_ICON_CHOICES;
        ρσ_modules["book_list.saved_virtual_library_icon_picker"].create_saved_virtual_library_icon_picker = create_saved_virtual_library_icon_picker;
    })();

    (function(){
        var __name__ = "book_list.saved_virtual_library_dialog";
        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var clear = ρσ_modules.dom.clear;

        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var all_virtual_libraries = ρσ_modules["book_list.library_data"].all_virtual_libraries;

        var DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON = ρσ_modules["book_list.saved_virtual_libraries"].DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON;
        var normalize_saved_virtual_library_icon = ρσ_modules["book_list.saved_virtual_libraries"].normalize_saved_virtual_library_icon;
        var saved_virtual_library_item = ρσ_modules["book_list.saved_virtual_libraries"].saved_virtual_library_item;

        var create_saved_virtual_library_icon_picker = ρσ_modules["book_list.saved_virtual_library_icon_picker"].create_saved_virtual_library_icon_picker;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var create_custom_dialog = ρσ_modules.modals.create_custom_dialog;

        var create_button = ρσ_modules.widgets.create_button;

        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                return "\n\n.cs-virtual-library-dialog {\n    width: 100%;\n    min-width: 0;\n    max-width: min(42rem, calc(100vw - 2rem));\n    box-sizing: border-box;\n\n    & .vl-row {\n        margin-bottom: 0.75rem;\n    }\n    & .vl-checkbox-row {\n        display: flex;\n        align-items: center;\n        margin-bottom: 0.35rem;\n    }\n    & .vl-label {\n        display: block;\n        margin: 0 0 0.45rem 0;\n        font-weight: 700;\n        opacity: 0.9;\n    }\n    & input[type=\"text\"] {\n        width: 100%;\n        box-sizing: border-box;\n        color: inherit;\n    }\n    & .vl-actions-save-cancel {\n        display: flex;\n        flex-wrap: wrap;\n        align-items: stretch;\n        justify-content: space-between;\n        gap: 0.5rem;\n        margin-top: 0.65rem;\n    }\n    & .vl-actions-save-cancel > a.calibre-push-button {\n        flex: 1 1 0;\n        min-width: 0;\n        justify-content: center;\n    }\n    & .vl-actions-save-cancel--toprule {\n        margin-top: 0.35rem;\n        padding-top: 0.6rem;\n        border-top: var(--calibre-border-style-subtle);\n    }\n}\n\n.cs-vl-import-dialog {\n    position: relative;\n    width: 100%;\n    min-width: 0;\n    max-width: min(42rem, calc(100vw - 2rem));\n    max-height: calc(min(60vh, 100vh - 6rem) - 5rem);\n    box-sizing: border-box;\n    display: flex;\n    flex-direction: column;\n    overflow: hidden;\n\n    & .vl-import-empty {\n        opacity: 0.7;\n        padding: 0.5rem 0;\n    }\n    & .vl-import-list {\n        min-height: 8ex;\n        overflow-y: auto;\n        margin-bottom: 0.5rem;\n        border: var(--calibre-border-style-subtle);\n        border-radius: 6px;\n        padding: 0.25rem 0;\n    }\n    & .vl-import-row {\n        display: flex;\n        align-items: center;\n        gap: 0.55rem;\n        padding: 0.45rem 0.65rem;\n    }\n    & .vl-import-row:not(:last-child) {\n        border-bottom: var(--calibre-border-style-subtle);\n    }\n    & .vl-import-row input[type=\"checkbox\"] {\n        flex-shrink: 0;\n        width: 1.1rem;\n        height: 1.1rem;\n        cursor: pointer;\n    }\n    & .vl-import-name {\n        flex: 1 1 0;\n        min-width: 0;\n        overflow: hidden;\n        text-overflow: ellipsis;\n        white-space: nowrap;\n    }\n    & .vl-import-icon-wrap {\n        display: flex;\n        align-items: center;\n        gap: 0.3rem;\n        flex-shrink: 0;\n    }\n    & .vl-import-icon-label {\n        font-size: 0.8rem;\n        opacity: 0.75;\n        white-space: nowrap;\n    }\n    & .vl-import-icon-btn {\n        display: inline-flex;\n        align-items: center;\n        justify-content: center;\n        width: 2.35rem;\n        height: 2.35rem;\n        padding: 0;\n        margin: 0;\n        font-size: 1.2rem;\n        line-height: 1;\n        border: var(--calibre-border-style-subtle);\n        border-radius: 8px;\n        background: rgba(0,0,0,0.02);\n        color: inherit;\n        cursor: pointer;\n        transition: background 120ms ease, border-color 120ms ease;\n    }\n    & .vl-import-icon-btn:hover {\n        background: var(--calibre-color-primary-light);\n        border-color: var(--calibre-color-border);\n    }\n    & .vl-import-icon-btn:focus {\n        outline: none;\n        box-shadow: var(--calibre-focus-ring);\n    }\n    & .vl-import-icon-overlay {\n        position: absolute;\n        inset: 0;\n        display: none;\n        flex-direction: column;\n        gap: 0.65rem;\n        padding: 0.75rem;\n        border-radius: 6px;\n        overflow-y: auto;\n        z-index: 10;\n    }\n    & .vl-import-overlay-title {\n        font-weight: 700;\n        font-size: 1rem;\n        flex-shrink: 0;\n    }\n    & .vl-import-overlay-actions {\n        display: flex;\n        flex-wrap: wrap;\n        gap: 0.5rem;\n        justify-content: space-between;\n        margin-top: 0.25rem;\n        flex-shrink: 0;\n    }\n    & .vl-import-overlay-actions > a.calibre-push-button {\n        flex: 1 1 0;\n        min-width: 0;\n        justify-content: center;\n    }\n    & .vl-actions-save-cancel {\n        display: flex;\n        flex-wrap: wrap;\n        align-items: stretch;\n        justify-content: space-between;\n        gap: 0.5rem;\n        margin-top: 0.65rem;\n        flex-shrink: 0;\n    }\n    & .vl-actions-save-cancel > a.calibre-push-button {\n        flex: 1 1 0;\n        min-width: 0;\n        justify-content: center;\n    }\n    & .vl-actions-save-cancel--toprule {\n        margin-top: 0.35rem;\n        padding-top: 0.6rem;\n        border-top: var(--calibre-border-style-subtle);\n    }\n}\n";
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "book_list.saved_virtual_library_dialog"}
            });
            return ρσ_anonfunc;
        })());
        function show_import_virtual_libraries_dialog(library_id, on_save) {
            create_custom_dialog(_("Import Virtual Libraries"), (function() {
                var ρσ_anonfunc = function (parent, close_modal) {
                    var vls, vl_names, overlay, rows, list_div, search, cb, icon_btn, row_state, vl_name;
                    vls = all_virtual_libraries();
                    vl_names = sorted(Object.keys(vls));
                    if (!vl_names.length) {
                        parent.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [_("No virtual libraries found in calibre settings.")].concat([ρσ_desugar_kwargs({class_: "vl-import-empty"})])), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Close"), "close", (function() {
                            var ρσ_anonfunc = function () {
                                var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ρσ_anonfunc.__defaults__.ev : arguments[0];
                                var ρσ_kwargs_obj = arguments[arguments.length-1];
                                if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                                    ev = ρσ_kwargs_obj.ev;
                                }
                                close_modal();
                            };
                            if (!ρσ_anonfunc.__defaults__) Object.defineProperties(ρσ_anonfunc, {
                                __defaults__ : {value: {ev:null}},
                                __handles_kwarg_interpolation__ : {value: true},
                                __argnames__ : {value: ["ev"]},
                                __module__ : {value: "book_list.saved_virtual_library_dialog"}
                            });
                            return ρσ_anonfunc;
                        })())].concat([ρσ_desugar_kwargs({class_: "vl-actions-save-cancel vl-actions-save-cancel--toprule"})]))].concat([ρσ_desugar_kwargs({class_: "cs-vl-import-dialog"})])));
                        return;
                    }
                    overlay = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "vl-import-icon-overlay"})]);
                    overlay.style.backgroundColor = get_color("dialog-background");
                    function hide_overlay() {
                        var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? hide_overlay.__defaults__.ev : arguments[0];
                        var ρσ_kwargs_obj = arguments[arguments.length-1];
                        if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                        if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                            ev = ρσ_kwargs_obj.ev;
                        }
                        overlay.style.display = "none";
                        clear(overlay);
                    };
                    if (!hide_overlay.__defaults__) Object.defineProperties(hide_overlay, {
                        __defaults__ : {value: {ev:null}},
                        __handles_kwarg_interpolation__ : {value: true},
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "book_list.saved_virtual_library_dialog"}
                    });

                    function show_icon_overlay(row) {
                        var picker;
                        picker = create_saved_virtual_library_icon_picker(row.icon);
                        function confirm_icon() {
                            var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? confirm_icon.__defaults__.ev : arguments[0];
                            var ρσ_kwargs_obj = arguments[arguments.length-1];
                            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                                ev = ρσ_kwargs_obj.ev;
                            }
                            row.icon = normalize_saved_virtual_library_icon(picker.get_value());
                            row.icon_btn.textContent = row.icon;
                            hide_overlay();
                        };
                        if (!confirm_icon.__defaults__) Object.defineProperties(confirm_icon, {
                            __defaults__ : {value: {ev:null}},
                            __handles_kwarg_interpolation__ : {value: true},
                            __argnames__ : {value: ["ev"]},
                            __module__ : {value: "book_list.saved_virtual_library_dialog"}
                        });

                        clear(overlay);
                        overlay.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Choose icon")].concat([ρσ_desugar_kwargs({class_: "vl-import-overlay-title"})])));
                        overlay.appendChild(picker.root);
                        overlay.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Cancel"), "close", hide_overlay), ρσ_interpolate_kwargs.call(this, create_button, [_("Select"), "check", confirm_icon].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: "vl-import-overlay-actions"})])));
                        overlay.style.display = "flex";
                    };
                    if (!show_icon_overlay.__argnames__) Object.defineProperties(show_icon_overlay, {
                        __argnames__ : {value: ["row"]},
                        __module__ : {value: "book_list.saved_virtual_library_dialog"}
                    });

                    rows = [];
                    list_div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "vl-import-list"})]);
                    var ρσ_Iter0 = ρσ_Iterable(vl_names);
                    for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                        vl_name = ρσ_Iter0[ρσ_Index0];
                        search = vls[(typeof vl_name === "number" && vl_name < 0) ? vls.length + vl_name : vl_name];
                        cb = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox"})]);
                        cb.checked = true;
                        icon_btn = ρσ_interpolate_kwargs.call(E, E.button, [ρσ_desugar_kwargs({type: "button", class_: "vl-import-icon-btn", title: _("Click to change icon")})]);
                        icon_btn.textContent = DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON;
                        row_state = (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["name"] = vl_name;
                            ρσ_d["search"] = search;
                            ρσ_d["checkbox"] = cb;
                            ρσ_d["icon"] = DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON;
                            ρσ_d["icon_btn"] = icon_btn;
                            return ρσ_d;
                        }).call(this);
                        function make_icon_handler(r) {
                            function handler(ev) {
                                ev.preventDefault();
                                show_icon_overlay(r);
                            };
                            if (!handler.__argnames__) Object.defineProperties(handler, {
                                __argnames__ : {value: ["ev"]},
                                __module__ : {value: "book_list.saved_virtual_library_dialog"}
                            });

                            return handler;
                        };
                        if (!make_icon_handler.__argnames__) Object.defineProperties(make_icon_handler, {
                            __argnames__ : {value: ["r"]},
                            __module__ : {value: "book_list.saved_virtual_library_dialog"}
                        });

                        icon_btn.addEventListener("click", make_icon_handler(row_state));
                        rows.push(row_state);
                        list_div.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [cb, ρσ_interpolate_kwargs.call(E, E.span, [vl_name].concat([ρσ_desugar_kwargs({class_: "vl-import-name", title: vl_name})])), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.span, [_("Icon:")].concat([ρσ_desugar_kwargs({class_: "vl-import-icon-label"})])), icon_btn].concat([ρσ_desugar_kwargs({class_: "vl-import-icon-wrap"})]))].concat([ρσ_desugar_kwargs({class_: "vl-import-row"})])));
                    }
                    function do_import() {
                        var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? do_import.__defaults__.ev : arguments[0];
                        var ρσ_kwargs_obj = arguments[arguments.length-1];
                        if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                        if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                            ev = ρσ_kwargs_obj.ev;
                        }
                        var item, row;
                        var ρσ_Iter1 = ρσ_Iterable(rows);
                        for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                            row = ρσ_Iter1[ρσ_Index1];
                            if (row.checkbox.checked) {
                                item = saved_virtual_library_item(library_id, row.name, row.search, "", row.icon || DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON, true);
                                if (item) {
                                    on_save(item);
                                }
                            }
                        }
                        close_modal();
                    };
                    if (!do_import.__defaults__) Object.defineProperties(do_import, {
                        __defaults__ : {value: {ev:null}},
                        __handles_kwarg_interpolation__ : {value: true},
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "book_list.saved_virtual_library_dialog"}
                    });

                    parent.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [list_div, overlay, ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Cancel"), "close", (function() {
                        var ρσ_anonfunc = function () {
                            var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ρσ_anonfunc.__defaults__.ev : arguments[0];
                            var ρσ_kwargs_obj = arguments[arguments.length-1];
                            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                                ev = ρσ_kwargs_obj.ev;
                            }
                            close_modal();
                        };
                        if (!ρσ_anonfunc.__defaults__) Object.defineProperties(ρσ_anonfunc, {
                            __defaults__ : {value: {ev:null}},
                            __handles_kwarg_interpolation__ : {value: true},
                            __argnames__ : {value: ["ev"]},
                            __module__ : {value: "book_list.saved_virtual_library_dialog"}
                        });
                        return ρσ_anonfunc;
                    })()), ρσ_interpolate_kwargs.call(this, create_button, [_("Import"), "plus", do_import].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: "vl-actions-save-cancel vl-actions-save-cancel--toprule"})]))].concat([ρσ_desugar_kwargs({class_: "cs-vl-import-dialog"})])));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["parent", "close_modal"]},
                    __module__ : {value: "book_list.saved_virtual_library_dialog"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!show_import_virtual_libraries_dialog.__argnames__) Object.defineProperties(show_import_virtual_libraries_dialog, {
            __argnames__ : {value: ["library_id", "on_save"]},
            __module__ : {value: "book_list.saved_virtual_library_dialog"}
        });

        function show_saved_virtual_library_dialog() {
            var title = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var save_label = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var on_save = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var library_id = ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[3];
            var virtual_library = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_saved_virtual_library_dialog.__defaults__.virtual_library : arguments[4];
            var initial_name = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_saved_virtual_library_dialog.__defaults__.initial_name : arguments[5];
            var initial_search = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_saved_virtual_library_dialog.__defaults__.initial_search : arguments[6];
            var initial_icon = (arguments[7] === undefined || ( 7 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_saved_virtual_library_dialog.__defaults__.initial_icon : arguments[7];
            var initial_use_icon = (arguments[8] === undefined || ( 8 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_saved_virtual_library_dialog.__defaults__.initial_use_icon : arguments[8];
            var on_delete = (arguments[9] === undefined || ( 9 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_saved_virtual_library_dialog.__defaults__.on_delete : arguments[9];
            var save_icon = (arguments[10] === undefined || ( 10 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_saved_virtual_library_dialog.__defaults__.save_icon : arguments[10];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "virtual_library")){
                virtual_library = ρσ_kwargs_obj.virtual_library;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "initial_name")){
                initial_name = ρσ_kwargs_obj.initial_name;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "initial_search")){
                initial_search = ρσ_kwargs_obj.initial_search;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "initial_icon")){
                initial_icon = ρσ_kwargs_obj.initial_icon;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "initial_use_icon")){
                initial_use_icon = ρσ_kwargs_obj.initial_use_icon;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_delete")){
                on_delete = ρσ_kwargs_obj.on_delete;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "save_icon")){
                save_icon = ρσ_kwargs_obj.save_icon;
            }
            create_custom_dialog(title, (function() {
                var ρσ_anonfunc = function (parent, close_modal) {
                    var name_input, search_input, icon_picker, use_icon_cb, icon_section, use_icon_help, dialog, actions_class;
                    name_input = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "text", value: (initial_name || "") + "", placeholder: _("Virtual library name")})]);
                    search_input = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "text", value: (initial_search || "") + "", placeholder: _("Search expression")})]);
                    icon_picker = create_saved_virtual_library_icon_picker((initial_icon || DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON) + "");
                    use_icon_cb = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox"})]);
                    use_icon_cb.checked = initial_use_icon !== false;
                    icon_section = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.label, [_("Icon")].concat([ρσ_desugar_kwargs({class_: "vl-label"})])), icon_picker.root].concat([ρσ_desugar_kwargs({class_: "vl-row"})]))].concat([ρσ_desugar_kwargs({class_: "vl-icon-section"})]));
                    use_icon_help = ρσ_interpolate_kwargs.call(E, E.div, [_("When disabled, only the first character of the name is shown while the navigation is collapsed.")].concat([ρσ_desugar_kwargs({class_: "help"})]));
                    function sync_icon_section_visibility() {
                        var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? sync_icon_section_visibility.__defaults__.ev : arguments[0];
                        var ρσ_kwargs_obj = arguments[arguments.length-1];
                        if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                        if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                            ev = ρσ_kwargs_obj.ev;
                        }
                        var on;
                        on = use_icon_cb.checked;
                        icon_section.style.display = (on) ? "block" : "none";
                        use_icon_help.style.display = (on) ? "none" : "block";
                    };
                    if (!sync_icon_section_visibility.__defaults__) Object.defineProperties(sync_icon_section_visibility, {
                        __defaults__ : {value: {ev:null}},
                        __handles_kwarg_interpolation__ : {value: true},
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "book_list.saved_virtual_library_dialog"}
                    });

                    function save_item() {
                        var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? save_item.__defaults__.ev : arguments[0];
                        var ρσ_kwargs_obj = arguments[arguments.length-1];
                        if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                        if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                            ev = ρσ_kwargs_obj.ev;
                        }
                        var item;
                        item = saved_virtual_library_item(library_id, name_input.value, search_input.value, virtual_library, icon_picker.get_value(), use_icon_cb.checked);
                        if (!item) {
                            return;
                        }
                        if (on_save(item) === false) {
                            return;
                        }
                        close_modal();
                    };
                    if (!save_item.__defaults__) Object.defineProperties(save_item, {
                        __defaults__ : {value: {ev:null}},
                        __handles_kwarg_interpolation__ : {value: true},
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "book_list.saved_virtual_library_dialog"}
                    });

                    function delete_item() {
                        var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? delete_item.__defaults__.ev : arguments[0];
                        var ρσ_kwargs_obj = arguments[arguments.length-1];
                        if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                        if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                            ev = ρσ_kwargs_obj.ev;
                        }
                        if (on_delete && on_delete() === false) {
                            return;
                        }
                        close_modal();
                    };
                    if (!delete_item.__defaults__) Object.defineProperties(delete_item, {
                        __defaults__ : {value: {ev:null}},
                        __handles_kwarg_interpolation__ : {value: true},
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "book_list.saved_virtual_library_dialog"}
                    });

                    function open_import() {
                        var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? open_import.__defaults__.ev : arguments[0];
                        var ρσ_kwargs_obj = arguments[arguments.length-1];
                        if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                        if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                            ev = ρσ_kwargs_obj.ev;
                        }
                        close_modal();
                        show_import_virtual_libraries_dialog(library_id, on_save);
                    };
                    if (!open_import.__defaults__) Object.defineProperties(open_import, {
                        __defaults__ : {value: {ev:null}},
                        __handles_kwarg_interpolation__ : {value: true},
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "book_list.saved_virtual_library_dialog"}
                    });

                    dialog = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.label, [_("Virtual library name")].concat([ρσ_desugar_kwargs({class_: "vl-label"})])), name_input].concat([ρσ_desugar_kwargs({class_: "vl-row"})])), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.label, [_("Search expression")].concat([ρσ_desugar_kwargs({class_: "vl-label"})])), search_input].concat([ρσ_desugar_kwargs({class_: "vl-row"})])), ρσ_interpolate_kwargs.call(E, E.div, [use_icon_cb, ρσ_interpolate_kwargs.call(E, E.span, [_("Show icon in sidebar")].concat([ρσ_desugar_kwargs({style: "margin-left:0.45rem"})]))].concat([ρσ_desugar_kwargs({class_: "vl-checkbox-row"})])), use_icon_help, icon_section].concat([ρσ_desugar_kwargs({class_: "cs-virtual-library-dialog"})]));
                    actions_class = "vl-actions-save-cancel";
                    if (!on_delete) {
                        actions_class += " vl-actions-save-cancel--toprule";
                    }
                    dialog.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Cancel"), "close", (function() {
                        var ρσ_anonfunc = function () {
                            var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? ρσ_anonfunc.__defaults__.ev : arguments[0];
                            var ρσ_kwargs_obj = arguments[arguments.length-1];
                            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                                ev = ρσ_kwargs_obj.ev;
                            }
                            close_modal();
                        };
                        if (!ρσ_anonfunc.__defaults__) Object.defineProperties(ρσ_anonfunc, {
                            __defaults__ : {value: {ev:null}},
                            __handles_kwarg_interpolation__ : {value: true},
                            __argnames__ : {value: ["ev"]},
                            __module__ : {value: "book_list.saved_virtual_library_dialog"}
                        });
                        return ρσ_anonfunc;
                    })()), ρσ_interpolate_kwargs.call(this, create_button, [save_label, save_icon, save_item].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: actions_class})])));
                    if (on_delete) {
                        dialog.lastChild.insertBefore(create_button(_("Delete"), "trash", delete_item, _("Delete this Virtual library")), dialog.lastChild.firstChild);
                    } else {
                        dialog.lastChild.insertBefore(create_button(_("Import"), "library", open_import, _("Import virtual libraries from calibre settings")), dialog.lastChild.firstChild);
                    }
                    parent.appendChild(dialog);
                    use_icon_cb.addEventListener("change", sync_icon_section_visibility);
                    sync_icon_section_visibility();
                    setTimeout((function() {
                        var ρσ_anonfunc = function () {
                            name_input.focus();
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "book_list.saved_virtual_library_dialog"}
                        });
                        return ρσ_anonfunc;
                    })(), 10);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["parent", "close_modal"]},
                    __module__ : {value: "book_list.saved_virtual_library_dialog"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!show_saved_virtual_library_dialog.__defaults__) Object.defineProperties(show_saved_virtual_library_dialog, {
            __defaults__ : {value: {virtual_library:"", initial_name:"", initial_search:"", initial_icon:DEFAULT_SAVED_VIRTUAL_LIBRARY_ICON, initial_use_icon:true, on_delete:null, save_icon:"check"}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title", "save_label", "on_save", "library_id", "virtual_library", "initial_name", "initial_search", "initial_icon", "initial_use_icon", "on_delete", "save_icon"]},
            __module__ : {value: "book_list.saved_virtual_library_dialog"}
        });

        ρσ_modules["book_list.saved_virtual_library_dialog"].show_import_virtual_libraries_dialog = show_import_virtual_libraries_dialog;
        ρσ_modules["book_list.saved_virtual_library_dialog"].show_saved_virtual_library_dialog = show_saved_virtual_library_dialog;
    })();

    (function(){
        var __name__ = "book_list.prefs";
        var pp_counter, widget_counter, CLASS_NAME;
        var clear = ρσ_modules.dom.clear;
        var ensure_id = ρσ_modules.dom.ensure_id;
        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;

        var E = ρσ_modules.elementmaker.E;

        var create_button = ρσ_modules.widgets.create_button;
        var create_select = ρσ_modules.widgets.create_select;

        var _ = ρσ_modules.gettext.gettext;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var create_top_bar = ρσ_modules["book_list.top_bar"].create_top_bar;

        var back = ρσ_modules["book_list.router"].back;

        pp_counter = 0;
        widget_counter = 0;
        CLASS_NAME = "cs-prefs";
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, style;
                sel = "." + CLASS_NAME + " ";
                style = "";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({padding: "0.75rem 1rem 1rem 1rem", max_width: "980px", width: "100%", box_sizing: "border-box", min_width: "0", margin_left: "auto", margin_right: "auto"})]));
                style += "\n@media (max-width: 720px) {\n  .cs-prefs { padding-left: 0.75rem; padding-right: 0.75rem; }\n}\n@media (max-width: 520px) {\n  .cs-prefs .item-main {\n    flex-direction: column;\n    align-items: stretch;\n  }\n  .cs-prefs .control {\n    flex-direction: column;\n    align-items: stretch;\n    justify-content: flex-start;\n  }\n  .cs-prefs .control .label {\n    flex: 0 0 auto;\n  }\n}\n";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".list"].concat([ρσ_desugar_kwargs({display: "flex", flex_direction: "column", gap: "0.65rem", min_width: "0", width: "100%", box_sizing: "border-box"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".item"].concat([ρσ_desugar_kwargs({padding: "0.85rem 1rem", border_radius: "16px", border: "var(--calibre-border-style-subtle)", background: "linear-gradient(135deg, var(--calibre-color-surface-1) 0%, var(--calibre-color-surface-2) 100%)", box_shadow: "0 12px 32px rgba(0,0,0,0.08)", min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".item:hover"].concat([ρσ_desugar_kwargs({border: "var(--calibre-border-style)", box_shadow: "0 16px 44px rgba(0,0,0,0.10)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".item-main"].concat([ρσ_desugar_kwargs({display: "flex", align_items: "center", justify_content: "space-between", gap: "1rem", flex_wrap: "wrap", min_width: "0", width: "100%", box_sizing: "border-box"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".control"].concat([ρσ_desugar_kwargs({display: "flex", align_items: "center", justify_content: "space-between", gap: "0.75rem", flex: "1 1 auto", min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".label"].concat([ρσ_desugar_kwargs({font_weight: "800", white_space: "normal", opacity: "0.92", flex: "1 1 auto", min_width: "0", max_width: "100%", overflow_wrap: "anywhere", word_break: "break-word"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".control input[type=\"text\"]," + sel + ".control input[type=\"number\"]"].concat([ρσ_desugar_kwargs({min_width: "0", max_width: "100%", width: "100%", flex: "1 1 auto"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".help"].concat([ρσ_desugar_kwargs({margin_top: "0.65rem", padding_top: "0.65rem", border_top: "var(--calibre-border-style-subtle)", font_size: "0.85rem", font_weight: "700", opacity: "0.75", display: "none", max_width: "100%", overflow_wrap: "anywhere", word_break: "break-word"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".footer"].concat([ρσ_desugar_kwargs({margin_top: "1rem", display: "flex", justify_content: "flex-end"})]));
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "book_list.prefs"}
            });
            return ρσ_anonfunc;
        })());
        function ConfigItem() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ConfigItem.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperties(ConfigItem.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById(self.widget_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "control": {
                "enumerable": true, 
                "get": function control() {
                    var self = this;
                    return self.container.lastChild;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        ConfigItem.prototype.__init__ = function __init__(item_data) {
            var self = this;
            widget_counter += 1;
            self.widget_id = "pref-widget-" + widget_counter;
            self.item_data = item_data;
            self.ignore_ui_value_changed = false;
        };
        if (!ConfigItem.prototype.__init__.__argnames__) Object.defineProperties(ConfigItem.prototype.__init__, {
            __argnames__ : {value: ["item_data"]},
            __module__ : {value: "book_list.prefs"}
        });
        ConfigItem.__argnames__ = ConfigItem.prototype.__init__.__argnames__;
        ConfigItem.__handles_kwarg_interpolation__ = ConfigItem.prototype.__init__.__handles_kwarg_interpolation__;
        ConfigItem.prototype.initialize = function initialize() {
            var self = this;
            self.ignore_ui_value_changed = true;
            try {
                self.to_ui(self.from_storage());
            } finally {
                self.ignore_ui_value_changed = false;
            }
            return self;
        };
        if (!ConfigItem.prototype.initialize.__module__) Object.defineProperties(ConfigItem.prototype.initialize, {
            __module__ : {value: "book_list.prefs"}
        });
        ConfigItem.prototype.from_storage = function from_storage() {
            var self = this;
            var val;
            val = get_session_data().get(self.item_data.name);
            if (self.item_data.from_storage) {
                val = self.item_data.from_storage(val);
            }
            return val;
        };
        if (!ConfigItem.prototype.from_storage.__module__) Object.defineProperties(ConfigItem.prototype.from_storage, {
            __module__ : {value: "book_list.prefs"}
        });
        ConfigItem.prototype.to_storage = function to_storage(val) {
            var self = this;
            if (self.item_data.to_storage) {
                val = self.item_data.to_storage(val);
            }
            get_session_data().set(self.item_data.name, val);
        };
        if (!ConfigItem.prototype.to_storage.__argnames__) Object.defineProperties(ConfigItem.prototype.to_storage, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "book_list.prefs"}
        });
        ConfigItem.prototype.defval = function defval() {
            var self = this;
            var val;
            val = get_session_data().defval(self.item_data.name);
            if (self.item_data.from_storage) {
                val = self.item_data.from_storage(val);
            }
            return val;
        };
        if (!ConfigItem.prototype.defval.__module__) Object.defineProperties(ConfigItem.prototype.defval, {
            __module__ : {value: "book_list.prefs"}
        });
        ConfigItem.prototype.ui_value_changed = function ui_value_changed() {
            var self = this;
            var val;
            if (self.ignore_ui_value_changed) {
                return;
            }
            val = self.from_ui();
            self.to_storage(val);
            if (self.item_data.onchange) {
                self.item_data.onchange(val);
            }
        };
        if (!ConfigItem.prototype.ui_value_changed.__module__) Object.defineProperties(ConfigItem.prototype.ui_value_changed, {
            __module__ : {value: "book_list.prefs"}
        });
        ConfigItem.prototype.reset_to_default = function reset_to_default() {
            var self = this;
            self.to_ui(self.defval());
            self.ui_value_changed();
        };
        if (!ConfigItem.prototype.reset_to_default.__module__) Object.defineProperties(ConfigItem.prototype.reset_to_default, {
            __module__ : {value: "book_list.prefs"}
        });
        ConfigItem.prototype.to_ui = function to_ui(val) {
            var self = this;
        };
        if (!ConfigItem.prototype.to_ui.__argnames__) Object.defineProperties(ConfigItem.prototype.to_ui, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "book_list.prefs"}
        });
        ConfigItem.prototype.from_ui = function from_ui() {
            var self = this;
        };
        if (!ConfigItem.prototype.from_ui.__module__) Object.defineProperties(ConfigItem.prototype.from_ui, {
            __module__ : {value: "book_list.prefs"}
        });
        ConfigItem.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ConfigItem.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ConfigItem.prototype, "__bases__", {value: []});
        
        

        function Choices() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            Choices.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(Choices, ConfigItem);
        Object.defineProperties(Choices.prototype,  {
            "control": {
                "enumerable": true, 
                "get": function control() {
                    var self = this;
                    return self.container.getElementsByTagName("select")[0];
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        Choices.prototype.__init__ = function __init__(item_data, container, onfocus) {
            var self = this;
            var options, ρσ_unpack, choice, text, c, select, div;
            ConfigItem.prototype.__init__.call(self, item_data);
            options = Object.create(null);
            var ρσ_Iter0 = ρσ_Iterable(item_data.choices);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                ρσ_unpack = ρσ_Iter0[ρσ_Index0];
                choice = ρσ_unpack[0];
                text = ρσ_unpack[1];
                options[(typeof choice === "number" && choice < 0) ? options.length + choice : choice] = text;
            }
            ρσ_unpack = ρσ_interpolate_kwargs.call(this, create_select, [item_data.text, ""].concat([ρσ_desugar_kwargs(options)]));
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            c = ρσ_unpack[0];
            select = ρσ_unpack[1];
            div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.span, [item_data.text].concat([ρσ_desugar_kwargs({class_: "label"})])), c].concat([ρσ_desugar_kwargs({id: self.widget_id})]));
            div.classList.add("control");
            container.appendChild(div);
            select.addEventListener("change", self.ui_value_changed.bind(self));
            select.addEventListener("focus", onfocus);
            div.addEventListener("click", onfocus);
        };
        if (!Choices.prototype.__init__.__argnames__) Object.defineProperties(Choices.prototype.__init__, {
            __argnames__ : {value: ["item_data", "container", "onfocus"]},
            __module__ : {value: "book_list.prefs"}
        });
        Choices.__argnames__ = Choices.prototype.__init__.__argnames__;
        Choices.__handles_kwarg_interpolation__ = Choices.prototype.__init__.__handles_kwarg_interpolation__;
        Choices.prototype.to_ui = function to_ui(val) {
            var self = this;
            self.control.value = val;
        };
        if (!Choices.prototype.to_ui.__argnames__) Object.defineProperties(Choices.prototype.to_ui, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "book_list.prefs"}
        });
        Choices.prototype.from_ui = function from_ui() {
            var self = this;
            return self.control.value;
        };
        if (!Choices.prototype.from_ui.__module__) Object.defineProperties(Choices.prototype.from_ui, {
            __module__ : {value: "book_list.prefs"}
        });
        Choices.prototype.__repr__ = function __repr__ () {
            if(ConfigItem.prototype.__repr__) return ConfigItem.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        Choices.prototype.__str__ = function __str__ () {
            if(ConfigItem.prototype.__str__) return ConfigItem.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(Choices.prototype, "__bases__", {value: [ConfigItem]});
        

        function CheckBox() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            CheckBox.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(CheckBox, ConfigItem);
        Object.defineProperties(CheckBox.prototype,  {
            "control": {
                "enumerable": true, 
                "get": function control() {
                    var self = this;
                    return self.container.firstChild;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        CheckBox.prototype.__init__ = function __init__(item_data, container, onfocus) {
            var self = this;
            var div, control;
            ConfigItem.prototype.__init__.call(self, item_data);
            div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox"})]), ρσ_interpolate_kwargs.call(E, E.span, [item_data.text].concat([ρσ_desugar_kwargs({class_: "label"})]))].concat([ρσ_desugar_kwargs({id: self.widget_id, style: "cursor: pointer"})]));
            div.classList.add("control");
            container.appendChild(div);
            control = div.firstChild;
            control.addEventListener("change", self.ui_value_changed.bind(self));
            control.addEventListener("focus", onfocus);
            div.addEventListener("click", onfocus);
            div.lastChild.addEventListener("click", self.toggle.bind(self));
        };
        if (!CheckBox.prototype.__init__.__argnames__) Object.defineProperties(CheckBox.prototype.__init__, {
            __argnames__ : {value: ["item_data", "container", "onfocus"]},
            __module__ : {value: "book_list.prefs"}
        });
        CheckBox.__argnames__ = CheckBox.prototype.__init__.__argnames__;
        CheckBox.__handles_kwarg_interpolation__ = CheckBox.prototype.__init__.__handles_kwarg_interpolation__;
        CheckBox.prototype.to_ui = function to_ui(val) {
            var self = this;
            self.control.checked = bool(val);
        };
        if (!CheckBox.prototype.to_ui.__argnames__) Object.defineProperties(CheckBox.prototype.to_ui, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "book_list.prefs"}
        });
        CheckBox.prototype.from_ui = function from_ui() {
            var self = this;
            return bool(self.control.checked);
        };
        if (!CheckBox.prototype.from_ui.__module__) Object.defineProperties(CheckBox.prototype.from_ui, {
            __module__ : {value: "book_list.prefs"}
        });
        CheckBox.prototype.toggle = function toggle() {
            var self = this;
            self.to_ui(!self.from_ui());
            self.ui_value_changed();
        };
        if (!CheckBox.prototype.toggle.__module__) Object.defineProperties(CheckBox.prototype.toggle, {
            __module__ : {value: "book_list.prefs"}
        });
        CheckBox.prototype.__repr__ = function __repr__ () {
            if(ConfigItem.prototype.__repr__) return ConfigItem.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        CheckBox.prototype.__str__ = function __str__ () {
            if(ConfigItem.prototype.__str__) return ConfigItem.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(CheckBox.prototype, "__bases__", {value: [ConfigItem]});
        

        function SpinBox() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            SpinBox.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(SpinBox, ConfigItem);
        SpinBox.prototype.__init__ = function __init__(item_data, container, onfocus) {
            var self = this;
            var div, control, val, attr;
            ConfigItem.prototype.__init__.call(self, item_data);
            div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.span, [item_data.text].concat([ρσ_desugar_kwargs({class_: "label"})])), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "number", step: "any", min: "1", max: "100"})])].concat([ρσ_desugar_kwargs({id: self.widget_id})]));
            div.classList.add("control");
            container.appendChild(div);
            control = div.lastChild;
            var ρσ_Iter1 = ρσ_Iterable("min max step".split(" "));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                attr = ρσ_Iter1[ρσ_Index1];
                val = item_data[(typeof attr === "number" && attr < 0) ? item_data.length + attr : attr];
                if (val !== undefined && val !== null) {
                    control.setAttribute(attr, "" + val);
                }
            }
            control.addEventListener("change", self.ui_value_changed.bind(self));
            control.addEventListener("focus", onfocus);
            div.addEventListener("click", onfocus);
        };
        if (!SpinBox.prototype.__init__.__argnames__) Object.defineProperties(SpinBox.prototype.__init__, {
            __argnames__ : {value: ["item_data", "container", "onfocus"]},
            __module__ : {value: "book_list.prefs"}
        });
        SpinBox.__argnames__ = SpinBox.prototype.__init__.__argnames__;
        SpinBox.__handles_kwarg_interpolation__ = SpinBox.prototype.__init__.__handles_kwarg_interpolation__;
        SpinBox.prototype.to_ui = function to_ui(val) {
            var self = this;
            self.control.value = val;
        };
        if (!SpinBox.prototype.to_ui.__argnames__) Object.defineProperties(SpinBox.prototype.to_ui, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "book_list.prefs"}
        });
        SpinBox.prototype.from_ui = function from_ui() {
            var self = this;
            return self.control.value;
        };
        if (!SpinBox.prototype.from_ui.__module__) Object.defineProperties(SpinBox.prototype.from_ui, {
            __module__ : {value: "book_list.prefs"}
        });
        SpinBox.prototype.__repr__ = function __repr__ () {
            if(ConfigItem.prototype.__repr__) return ConfigItem.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        SpinBox.prototype.__str__ = function __str__ () {
            if(ConfigItem.prototype.__str__) return ConfigItem.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(SpinBox.prototype, "__bases__", {value: [ConfigItem]});

        function LineEdit() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            LineEdit.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(LineEdit, ConfigItem);
        LineEdit.prototype.__init__ = function __init__(item_data, container, onfocus) {
            var self = this;
            var div, control;
            ConfigItem.prototype.__init__.call(self, item_data);
            div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.span, [item_data.text].concat([ρσ_desugar_kwargs({class_: "label"})])), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "text"})])].concat([ρσ_desugar_kwargs({id: self.widget_id})]));
            div.classList.add("control");
            container.appendChild(div);
            control = div.lastChild;
            control.addEventListener("change", self.ui_value_changed.bind(self));
            control.addEventListener("focus", onfocus);
            div.addEventListener("click", onfocus);
        };
        if (!LineEdit.prototype.__init__.__argnames__) Object.defineProperties(LineEdit.prototype.__init__, {
            __argnames__ : {value: ["item_data", "container", "onfocus"]},
            __module__ : {value: "book_list.prefs"}
        });
        LineEdit.__argnames__ = LineEdit.prototype.__init__.__argnames__;
        LineEdit.__handles_kwarg_interpolation__ = LineEdit.prototype.__init__.__handles_kwarg_interpolation__;
        LineEdit.prototype.to_ui = function to_ui(val) {
            var self = this;
            self.control.value = val || "";
        };
        if (!LineEdit.prototype.to_ui.__argnames__) Object.defineProperties(LineEdit.prototype.to_ui, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "book_list.prefs"}
        });
        LineEdit.prototype.from_ui = function from_ui() {
            var self = this;
            return self.control.value || "";
        };
        if (!LineEdit.prototype.from_ui.__module__) Object.defineProperties(LineEdit.prototype.from_ui, {
            __module__ : {value: "book_list.prefs"}
        });
        LineEdit.prototype.__repr__ = function __repr__ () {
            if(ConfigItem.prototype.__repr__) return ConfigItem.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        LineEdit.prototype.__str__ = function __str__ () {
            if(ConfigItem.prototype.__str__) return ConfigItem.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(LineEdit.prototype, "__bases__", {value: [ConfigItem]});

        function ColorEdit() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ColorEdit.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(ColorEdit, ConfigItem);
        ColorEdit.prototype.__init__ = function __init__(item_data, container, onfocus) {
            var self = this;
            var div, control;
            ConfigItem.prototype.__init__.call(self, item_data);
            div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.span, [item_data.text].concat([ρσ_desugar_kwargs({class_: "label"})])), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "color"})])].concat([ρσ_desugar_kwargs({id: self.widget_id})]));
            div.classList.add("control");
            container.appendChild(div);
            control = div.lastChild;
            control.addEventListener("change", self.ui_value_changed.bind(self));
            control.addEventListener("input", self.ui_value_changed.bind(self));
            control.addEventListener("focus", onfocus);
            div.addEventListener("click", onfocus);
        };
        if (!ColorEdit.prototype.__init__.__argnames__) Object.defineProperties(ColorEdit.prototype.__init__, {
            __argnames__ : {value: ["item_data", "container", "onfocus"]},
            __module__ : {value: "book_list.prefs"}
        });
        ColorEdit.__argnames__ = ColorEdit.prototype.__init__.__argnames__;
        ColorEdit.__handles_kwarg_interpolation__ = ColorEdit.prototype.__init__.__handles_kwarg_interpolation__;
        ColorEdit.prototype.to_ui = function to_ui(val) {
            var self = this;
            self.control.value = val || "";
        };
        if (!ColorEdit.prototype.to_ui.__argnames__) Object.defineProperties(ColorEdit.prototype.to_ui, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "book_list.prefs"}
        });
        ColorEdit.prototype.from_ui = function from_ui() {
            var self = this;
            return self.control.value || "";
        };
        if (!ColorEdit.prototype.from_ui.__module__) Object.defineProperties(ColorEdit.prototype.from_ui, {
            __module__ : {value: "book_list.prefs"}
        });
        ColorEdit.prototype.__repr__ = function __repr__ () {
            if(ConfigItem.prototype.__repr__) return ConfigItem.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ColorEdit.prototype.__str__ = function __str__ () {
            if(ConfigItem.prototype.__str__) return ConfigItem.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(ColorEdit.prototype, "__bases__", {value: [ConfigItem]});

        function onfocus(state, name) {
            return (function() {
                var ρσ_anonfunc = function (ev) {
                    var c, div;
                    c = document.getElementById(state.container_id);
                    div = c.querySelector("div[data-name=\"{}\"]".format(name));
                    if ((typeof div !== "undefined" && div !== null ? div : Object.create(null)).lastChild) {
                        div.lastChild.style.display = "block";
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "book_list.prefs"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!onfocus.__argnames__) Object.defineProperties(onfocus, {
            __argnames__ : {value: ["state", "name"]},
            __module__ : {value: "book_list.prefs"}
        });

        function create_prefs_widget(container, prefs_data) {
            var state, outer, div, val, cls, item;
            state = Object.create(null);
            state.container_id = ensure_id(container);
            state.widgets = ρσ_list_decorate([]);
            clear(container);
            try {
                container.classList.add(CLASS_NAME);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                } else {
                    throw ρσ_Exception;
                }
            }
            outer = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "list"})]);
            container.appendChild(outer);
            var ρσ_Iter2 = ρσ_Iterable(prefs_data);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                item = ρσ_Iter2[ρσ_Index2];
                div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "item-main"})]), ρσ_interpolate_kwargs.call(E, E.div, [item.tooltip || ""].concat([ρσ_desugar_kwargs({class_: "help"})]))].concat([ρσ_desugar_kwargs({title: item.tooltip, data_name: item.name, class_: "item"})]));
                outer.appendChild(div);
                val = get_session_data().get(item.name);
                if (item.from_storage) {
                    val = item.from_storage(val);
                }
                if (item.choices) {
                    cls = Choices;
                } else if (item.type === "color") {
                    cls = ColorEdit;
                } else if (val === true || val === false) {
                    cls = CheckBox;
                } else if (typeof val === "number") {
                    cls = SpinBox;
                } else {
                    cls = LineEdit;
                }
                state.widgets.push(new cls(item, div.firstChild, onfocus(state, item.name)).initialize());
            }
            if (state.widgets.length) {
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Restore default settings"), "refresh", reset_to_defaults.bind(null, state))].concat([ρσ_desugar_kwargs({class_: "footer"})])));
            }
        };
        if (!create_prefs_widget.__argnames__) Object.defineProperties(create_prefs_widget, {
            __argnames__ : {value: ["container", "prefs_data"]},
            __module__ : {value: "book_list.prefs"}
        });

        function reset_to_defaults(state) {
            var w;
            var ρσ_Iter3 = ρσ_Iterable(state.widgets);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                w = ρσ_Iter3[ρσ_Index3];
                w.reset_to_default();
            }
        };
        if (!reset_to_defaults.__argnames__) Object.defineProperties(reset_to_defaults, {
            __argnames__ : {value: ["state"]},
            __module__ : {value: "book_list.prefs"}
        });

        function prefs_panel_handler() {
            var title_func = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var get_prefs_data = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var on_close = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? prefs_panel_handler.__defaults__.on_close : arguments[2];
            var icon = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? prefs_panel_handler.__defaults__.icon : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_close")){
                on_close = ρσ_kwargs_obj.on_close;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "icon")){
                icon = ρσ_kwargs_obj.icon;
            }
            function onkeydown(container_id, close_action, ev) {
                if (ev.key === "Escape") {
                    [ev.preventDefault(), ev.stopPropagation()];
                    close_action();
                }
            };
            if (!onkeydown.__argnames__) Object.defineProperties(onkeydown, {
                __argnames__ : {value: ["container_id", "close_action", "ev"]},
                __module__ : {value: "book_list.prefs"}
            });

            function close_action() {
                if (on_close !== null) {
                    on_close();
                }
                back();
            };
            if (!close_action.__module__) Object.defineProperties(close_action, {
                __module__ : {value: "book_list.prefs"}
            });

            function init_prefs_panel(container_id) {
                var container;
                container = document.getElementById(container_id);
                container.addEventListener("keydown", onkeydown.bind(null, container_id, close_action), (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["passive"] = false;
                    ρσ_d["capture"] = true;
                    return ρσ_d;
                }).call(this));
                container.setAttribute("tabindex", "0");
                ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: title_func(), action: close_action, icon: icon})]));
                container.appendChild(E.div());
                create_prefs_widget(container.lastChild, get_prefs_data());
                container.focus();
            };
            if (!init_prefs_panel.__argnames__) Object.defineProperties(init_prefs_panel, {
                __argnames__ : {value: ["container_id"]},
                __module__ : {value: "book_list.prefs"}
            });

            return init_prefs_panel;
        };
        if (!prefs_panel_handler.__defaults__) Object.defineProperties(prefs_panel_handler, {
            __defaults__ : {value: {on_close:null, icon:"close"}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["title_func", "get_prefs_data", "on_close", "icon"]},
            __module__ : {value: "book_list.prefs"}
        });

        ρσ_modules["book_list.prefs"].pp_counter = pp_counter;
        ρσ_modules["book_list.prefs"].widget_counter = widget_counter;
        ρσ_modules["book_list.prefs"].CLASS_NAME = CLASS_NAME;
        ρσ_modules["book_list.prefs"].ConfigItem = ConfigItem;
        ρσ_modules["book_list.prefs"].Choices = Choices;
        ρσ_modules["book_list.prefs"].CheckBox = CheckBox;
        ρσ_modules["book_list.prefs"].SpinBox = SpinBox;
        ρσ_modules["book_list.prefs"].LineEdit = LineEdit;
        ρσ_modules["book_list.prefs"].ColorEdit = ColorEdit;
        ρσ_modules["book_list.prefs"].onfocus = onfocus;
        ρσ_modules["book_list.prefs"].create_prefs_widget = create_prefs_widget;
        ρσ_modules["book_list.prefs"].reset_to_defaults = reset_to_defaults;
        ρσ_modules["book_list.prefs"].prefs_panel_handler = prefs_panel_handler;
    })();

    (function(){
        var __name__ = "book_list.search";
        var apply_search, sp_counter, CLASS_NAME, state, last_accepted_search;
        var ajax = ρσ_modules.ajax.ajax;
        var absolute_path = ρσ_modules.ajax.absolute_path;

        var create_search_bar = ρσ_modules.complete.create_search_bar;

        var clear = ρσ_modules.dom.clear;
        var set_css = ρσ_modules.dom.set_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var svgicon = ρσ_modules.dom.svgicon;
        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var ensure_id = ρσ_modules.dom.ensure_id;

        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var create_button = ρσ_modules.widgets.create_button;
        var create_spinner = ρσ_modules.widgets.create_spinner;
        var Breadcrumbs = ρσ_modules.widgets.Breadcrumbs;

        var show_modal = ρσ_modules.modals.show_modal;
        var create_custom_dialog = ρσ_modules.modals.create_custom_dialog;

        var rating_to_stars = ρσ_modules.utils.rating_to_stars;
        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;
        var is_ios = ρσ_modules.utils.is_ios;

        var get_interface_data = ρσ_modules.session.get_interface_data;

        var library_data = ρσ_modules["book_list.library_data"].library_data;
        var current_library_id = ρσ_modules["book_list.library_data"].current_library_id;
        var current_virtual_library = ρσ_modules["book_list.library_data"].current_virtual_library;

        var show_panel = ρσ_modules["book_list.ui"].show_panel;

        var back = ρσ_modules["book_list.router"].back;
        var show_note = ρσ_modules["book_list.router"].show_note;

        var create_top_bar = ρσ_modules["book_list.top_bar"].create_top_bar;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var get_color = ρσ_modules["book_list.theme"].get_color;
        var get_font_size = ρσ_modules["book_list.theme"].get_font_size;

        var prefs_panel_handler = ρσ_modules["book_list.prefs"].prefs_panel_handler;

        apply_search = null;
        function set_apply_search(func) {
            apply_search = func;
        };
        if (!set_apply_search.__argnames__) Object.defineProperties(set_apply_search, {
            __argnames__ : {value: ["func"]},
            __module__ : {value: "book_list.search"}
        });

        sp_counter = 0;
        CLASS_NAME = "book-search-panel";
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, card_bg, card_border, style;
                sel = "." + CLASS_NAME + " ";
                card_bg = "var(--calibre-surface-1)";
                card_border = "var(--calibre-border-style-subtle)";
                style = ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({padding: "0.75rem 1rem 1rem 1rem", max_width: "980px", margin_top: "0.75rem", margin_bottom: "0.75rem", margin_left: "auto", margin_right: "auto", box_sizing: "border-box", display: "flex", flex_direction: "column", gap: "1rem"})]));
                style += "\n@media (max-width: 720px) {\n  ." + CLASS_NAME + " { padding-left: 0.75rem; padding-right: 0.75rem; }\n}\n";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-body"].concat([ρσ_desugar_kwargs({margin_top: "0", display: "flex", flex_direction: "column", gap: "0.95rem"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " div.tag-name > span"].concat([ρσ_desugar_kwargs({word_break: "break-all", hyphens: "auto", padding_left: "1ex"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " div.tag-name:hover"].concat([ρσ_desugar_kwargs({color: "inherit", background_color: "var(--calibre-color-primary-light)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " div.tag-menu:hover"].concat([ρσ_desugar_kwargs({color: "inherit", background_color: "var(--calibre-color-primary-light)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " div.tag-name:active"].concat([ρσ_desugar_kwargs({transform: "none", opacity: "0.92"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " div.tag-menu:active"].concat([ρσ_desugar_kwargs({transform: "none", opacity: "0.92"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " ul.search-items"].concat([ρσ_desugar_kwargs({margin_top: "0.65rem", margin_bottom: "0", list_style_type: "none", text_align: "left", display: "flex", flex_wrap: "wrap", gap: "0.35rem", padding: "0"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " ul.search-items > li"].concat([ρσ_desugar_kwargs({display: "inline-flex", align_items: "center", gap: "0.25rem", cursor: "pointer", padding: "0.15rem 0.5rem", border_radius: "999px", border: "var(--calibre-border-style-subtle)", background: "var(--calibre-color-surface-3)", font_size: "0.92em"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " ul.search-items > li:hover"].concat([ρσ_desugar_kwargs({background: "var(--calibre-color-primary-light)", border_color: "var(--calibre-color-border)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " ul.search-items > li:active"].concat([ρσ_desugar_kwargs({background: "var(--calibre-color-primary-light-2)", transform: "none"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-tag-card"].concat([ρσ_desugar_kwargs({padding: "1rem", border_radius: "18px", border: card_border, background: card_bg, box_shadow: "none"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-breadcrumbs.calibre-breadcrumbs"].concat([ρσ_desugar_kwargs({background: "var(--calibre-color-surface-2)", border: "var(--calibre-border-style-subtle)", border_radius: "14px", margin: "0 0 0.85rem 0", padding: "0.25rem 0", z_index: "auto"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-breadcrumbs.calibre-breadcrumbs > li:hover"].concat([ρσ_desugar_kwargs({color: "inherit"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-tags"].concat([ρσ_desugar_kwargs({padding: "0", display: "flex", flex_direction: "column", gap: "0.65rem", margin: "0", width: "100%"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-tag-row"].concat([ρσ_desugar_kwargs({display: "flex", align_items: "stretch", max_width: "100%", border: "var(--calibre-border-style-subtle)", border_radius: "14px", background: "var(--calibre-color-surface-2)", box_shadow: "none", cursor: "pointer", overflow: "hidden", user_select: "none", transition: "background-color 160ms ease, border-color 160ms ease"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-tag-row:hover"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light)", border_color: "var(--calibre-color-border)", box_shadow: "none"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-tag-row:active"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light-2)", transform: "translateY(0.5px)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-tag-row .tag-name"].concat([ρσ_desugar_kwargs({border_right: "var(--calibre-border-style-subtle)", padding: "0.65rem 0.85rem", display: "flex", align_items: "center", flex: "1 1 auto", min_width: "0"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-tag-row .tag-menu"].concat([ρσ_desugar_kwargs({padding: "0.65rem 0.75rem", display: "flex", align_items: "center", flex: "0 0 auto", background: "var(--calibre-color-surface-3)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .cs-search-loading"].concat([ρσ_desugar_kwargs({padding: "2.5rem 1rem", text_align: "center", border_radius: "18px", border: card_border, background: card_bg, box_shadow: "none"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container ul.tb-action-list > li:hover"].concat([ρσ_desugar_kwargs({color: get_color("list-hover-foreground"), background_color: get_color("list-hover-background")})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#modal-container ul.tb-action-list > li:active"].concat([ρσ_desugar_kwargs({color: get_color("window-hover-foreground"), color: get_color("list-hover-foreground"), background_color: get_color("list-hover-background")})]));
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "book_list.search"}
            });
            return ρσ_anonfunc;
        })());
        state = Object.create(null);
        last_accepted_search = null;
        function component(container, name) {
            return container.querySelector("[data-component=\"" + ρσ_str.format("{}", name) + "\"]");
        };
        if (!component.__argnames__) Object.defineProperties(component, {
            __argnames__ : {value: ["container", "name"]},
            __module__ : {value: "book_list.search"}
        });

        function icon_for_node(node) {
            var interface_data, fallback, fmt, ans;
            interface_data = get_interface_data();
            fallback = "";
            if (node.data.category === "formats" && !node.data.is_category) {
                fmt = node.data.name.lower();
                if (fmt.startswith("original_")) {
                    fmt = fmt.partition("_")[2];
                }
                ans = "mimetypes/" + ρσ_str.format("{}", fmt) + ".png";
                fallback = (ρσ_expr_temp = interface_data.icon_map)[ρσ_bound_index(node.data.category, ρσ_expr_temp)];
            } else {
                ans = (ρσ_expr_temp = interface_data.icon_map)[ρσ_bound_index(node.data.category, ρσ_expr_temp)] || "column.png";
                if (node.data.value_icon) {
                    fallback = ans;
                    ans = "_" + node.data.value_icon;
                }
            }
            if (fallback) {
                fallback = absolute_path(interface_data.icon_path + "/" + fallback);
            }
            return [absolute_path(interface_data.icon_path + "/" + ans), fallback];
        };
        if (!icon_for_node.__argnames__) Object.defineProperties(icon_for_node, {
            __argnames__ : {value: ["node"]},
            __module__ : {value: "book_list.search"}
        });

        function node_for_path(path) {
            var ans, child_index;
            path = path || state.tag_path;
            ans = state.tag_browser_data;
            var ρσ_Iter0 = ρσ_Iterable(path);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                child_index = ρσ_Iter0[ρσ_Index0];
                ans = (ρσ_expr_temp = ans.children)[(typeof child_index === "number" && child_index < 0) ? ρσ_expr_temp.length + child_index : child_index];
            }
            return ans;
        };
        if (!node_for_path.__argnames__) Object.defineProperties(node_for_path, {
            __argnames__ : {value: ["path"]},
            __module__ : {value: "book_list.search"}
        });

        function execute_search(text) {
            if (state.tag_path && state.tag_path.length) {
                last_accepted_search = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["library_id"] = current_library_id();
                    ρσ_d["vl"] = current_virtual_library();
                    ρσ_d["tag_path"] = list(state.tag_path);
                    return ρσ_d;
                }).call(this);
            }
            apply_search(text);
        };
        if (!execute_search.__argnames__) Object.defineProperties(execute_search, {
            __argnames__ : {value: ["text"]},
            __module__ : {value: "book_list.search"}
        });

        function ask_about_smart_quotes(text) {
            create_custom_dialog(_("Search contains smart quotes"), (function() {
                var ρσ_anonfunc = function (parent, close_modal) {
                    function action(replace) {
                        close_modal();
                        if (replace) {
                            text = text.replace(/[“”«»„]/g, "\"");
                        }
                        execute_search(text);
                    };
                    if (!action.__argnames__) Object.defineProperties(action, {
                        __argnames__ : {value: ["replace"]},
                        __module__ : {value: "book_list.search"}
                    });

                    parent.appendChild(E.div(E.div(_("The search expression {} contains smart quotes. By default, Apple inserts smart quotes instead of normal quotes when tapping the quote button. This will prevent the search from working, if you intended to use normal quotes. You can type normal quotes by long-tapping the quotes button. Do you want to keep the smart quotes or replace them with normal quotes?").format(text)), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Keep"), null, action.bind(null, false)), ρσ_interpolate_kwargs.call(this, create_button, [_("Replace"), null, action.bind(null, true)].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: "button-box"})]))));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["parent", "close_modal"]},
                    __module__ : {value: "book_list.search"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!ask_about_smart_quotes.__argnames__) Object.defineProperties(ask_about_smart_quotes, {
            __argnames__ : {value: ["text"]},
            __module__ : {value: "book_list.search"}
        });

        function execute_search_interactive(text) {
            var container, search_control;
            if (!text) {
                container = document.getElementById(state.container_id);
                search_control = container.querySelector("input[name=\"search-books\"]");
                text = search_control.value || "";
            }
            if (is_ios && /[“”«»„]/.test(text)) {
                ask_about_smart_quotes(text);
            } else {
                execute_search(text);
            }
        };
        if (!execute_search_interactive.__argnames__) Object.defineProperties(execute_search_interactive, {
            __argnames__ : {value: ["text"]},
            __module__ : {value: "book_list.search"}
        });

        function search_expression_for_item(node, node_state) {
            var item, search_state, stars, category, letters_seen, child, charclass, expr, rnum, fm, suffix, name;
            item = node.data;
            if (item.is_searchable === false || !node_state || node_state === "clear") {
                return "";
            }
            search_state = (ρσ_expr_temp = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["plus"] = "true";
                ρσ_d["plusplus"] = ".true";
                ρσ_d["minus"] = "false";
                ρσ_d["minusminus"] = ".false";
                return ρσ_d;
            }).call(this))[(typeof node_state === "number" && node_state < 0) ? ρσ_expr_temp.length + node_state : node_state];
            stars = rating_to_stars(3, true);
            if (item.is_category) {
                category = item.category;
                if (item.is_first_letter) {
                    letters_seen = Object.create(null);
                    var ρσ_Iter1 = ρσ_Iterable(node.children);
                    for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                        child = ρσ_Iter1[ρσ_Index1];
                        if (child.data.sort) {
                            letters_seen[ρσ_bound_index(child.data.sort[0], letters_seen)] = true;
                        }
                    }
                    letters_seen = Object.keys(letters_seen);
                    if (letters_seen.length) {
                        charclass = letters_seen.join("");
                        if (category === "authors") {
                            expr = "author_sort:\"~(^[{0}])|(&\\s*[{0}])\"".format(charclass);
                        } else if (category === "series") {
                            expr = "series_sort:\"~^[{0}]\"".format(charclass);
                        } else {
                            expr = "{0}:\"~^[{1}]\"".format(category, charclass);
                        }
                    } else {
                        expr = "{}:false".format(category);
                    }
                } else if (category === "news") {
                    expr = "tags:\"={}\"".format(item.name);
                } else {
                    return "{}:{}".format(category, search_state);
                }
                if (ρσ_in("false", search_state)) {
                    expr = "(not " + expr + ")";
                }
                return expr;
            }
            category = (item.category === "news") ? "tags" : item.category;
            if (item.name && ρσ_in(item.name[0], stars)) {
                rnum = item.name.length;
                if (item.name.endswith(stars[stars.length-1])) {
                    rnum = "{}.5".format(rnum - 1);
                }
                expr = "{}:{}".format(category, rnum);
            } else {
                fm = (ρσ_expr_temp = library_data.field_metadata)[ρσ_bound_index(item.category, ρσ_expr_temp)];
                suffix = (fm && fm.is_csp) ? ":" : "";
                name = item.original_name || item.name || item.sort;
                if (!name) {
                    return "";
                }
                name = str.replace(name, "\"", "\\\"");
                if (name[0] === ".") {
                    name = "." + name;
                }
                if (search_state === ".true" || search_state === ".false") {
                    name = "." + name;
                }
                expr = "{}:\"={}{}\"".format(category, name, suffix);
            }
            if (ρσ_in("false", search_state)) {
                expr = "(not " + expr + ")";
            }
            return expr;
        };
        if (!search_expression_for_item.__argnames__) Object.defineProperties(search_expression_for_item, {
            __argnames__ : {value: ["node", "node_state"]},
            __module__ : {value: "book_list.search"}
        });

        function node_clicked(i) {
            var node, expr;
            node = (ρσ_expr_temp = node_for_path().children)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
            if (node.children && node.children.length) {
                state.tag_path.append(i);
                render_tag_browser();
            } else {
                expr = search_expression_for_item(node, "plus");
                execute_search(expr);
            }
        };
        if (!node_clicked.__argnames__) Object.defineProperties(node_clicked, {
            __argnames__ : {value: ["i"]},
            __module__ : {value: "book_list.search"}
        });

        function add_to_search(node, search_type) {
            var anded;
            anded = get_session_data().get("and_search_terms");
            (ρσ_expr_temp = state.active_nodes)[ρσ_bound_index(node.id, ρσ_expr_temp)] = ρσ_list_decorate([ search_type, anded ]);
            render_search_expression();
        };
        if (!add_to_search.__argnames__) Object.defineProperties(add_to_search, {
            __argnames__ : {value: ["node", "search_type"]},
            __module__ : {value: "book_list.search"}
        });

        function remove_expression(node_id) {
            delete state.active_nodes[node_id];
            render_search_expression();
        };
        if (!remove_expression.__argnames__) Object.defineProperties(remove_expression, {
            __argnames__ : {value: ["node_id"]},
            __module__ : {value: "book_list.search"}
        });

        function render_search_expression() {
            var parts, container, sic, ρσ_unpack, search_type, anded, node, expr, name, c, node_id, search_control;
            parts = [];
            container = document.getElementById(state.container_id);
            sic = component(container, "search_expression");
            clear(sic);
            var ρσ_Iter2 = ρσ_Iterable(Object.keys(state.active_nodes));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                node_id = ρσ_Iter2[ρσ_Index2];
                ρσ_unpack = (ρσ_expr_temp = state.active_nodes)[(typeof node_id === "number" && node_id < 0) ? ρσ_expr_temp.length + node_id : node_id];
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                search_type = ρσ_unpack[0];
                anded = ρσ_unpack[1];
                node = (ρσ_expr_temp = state.node_id_map)[(typeof node_id === "number" && node_id < 0) ? ρσ_expr_temp.length + node_id : node_id];
                expr = search_expression_for_item(node, search_type);
                name = node.data.original_name || node.data.name || node.data.sort || "";
                if (expr) {
                    c = E.li(svgicon("remove"), " " + name);
                    sic.appendChild(c);
                    c.addEventListener("click", remove_expression.bind(null, node_id));
                    if (parts.length) {
                        expr = ((anded) ? "and" : "or") + " " + expr;
                    }
                    parts.push(expr);
                }
            }
            search_control = container.querySelector("input[name=\"search-books\"]");
            search_control.value = parts.join(" ");
        };
        if (!render_search_expression.__module__) Object.defineProperties(render_search_expression, {
            __module__ : {value: "book_list.search"}
        });

        function show_fallback(fallback, ev) {
            if (fallback) {
                if (ev.target.src !== fallback) {
                    ev.target.src = fallback;
                }
            }
        };
        if (!show_fallback.__argnames__) Object.defineProperties(show_fallback, {
            __argnames__ : {value: ["fallback", "ev"]},
            __module__ : {value: "book_list.search"}
        });

        function menu_clicked(i) {
            function create_details(container, hide_modal) {
                var node, data, name, ρσ_unpack, icon, fallback, title, ul, items, interface_data, li, text, search_type, f, and_control, about_items, footer;
                node = (ρσ_expr_temp = node_for_path().children)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
                data = node.data;
                name = data.original_name || data.name || data.sort;
                ρσ_unpack = icon_for_node(node);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                icon = ρσ_unpack[0];
                fallback = ρσ_unpack[1];
                title = ρσ_interpolate_kwargs.call(E, E.h2, [ρσ_interpolate_kwargs.call(E, E.img, [ρσ_desugar_kwargs({src: icon, onerror: show_fallback.bind(null, fallback), style: "height:2ex; margin-right: 0.5rem"})]), E.span(name)].concat([ρσ_desugar_kwargs({style: "display:flex; align-items: center; border-bottom: solid 1px currentColor; font-weight:bold; font-size:" + get_font_size("title")})]));
                function edit_note(field, item_name) {
                    hide_modal();
                    ρσ_interpolate_kwargs.call(this, show_note, [field, 0, item_name].concat([ρσ_desugar_kwargs({panel: "edit_note"})]));
                };
                if (!edit_note.__argnames__) Object.defineProperties(edit_note, {
                    __argnames__ : {value: ["field", "item_name"]},
                    __module__ : {value: "book_list.search"}
                });

                if (data.category && data.name && library_data.fields_that_support_notes.indexOf(data.category)) {
                    title.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [svgicon("pencil")].concat([ρσ_desugar_kwargs({class_: "blue-link", style: "margin-left: 0.5em", href: "javascript:void(0)", onclick: edit_note.bind(null, data.category, data.name), title: _("Edit or add notes for {}").format(data.name)})])));
                }
                container.appendChild(title);
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Search for books based on this category (a search term will be added to the search field)")].concat([ρσ_desugar_kwargs({style: "margin-top:1ex; margin-bottom: 1ex"})])));
                ul = ρσ_interpolate_kwargs.call(E, E.ul, [ρσ_desugar_kwargs({style: "list-style:none; overflow-x:auto; overflow-y:visible", class_: "tb-action-list"})]);
                container.appendChild(ul);
                items = ρσ_list_decorate([ [_("Books matching this category"), "plus"], [_("Books that do not match this category"), 
                "minus"] ]);
                if (node.data.is_hierarchical === 5) {
                    items.extend(ρσ_list_decorate([ [_("Books that match this category and all sub-categories"), 
                    "plusplus"], [_("Books that do not match this category or any of its sub-categories"), 
                    "minusminus"] ]));
                }
                interface_data = get_interface_data();
                var ρσ_Iter3 = ρσ_Iterable(items);
                for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                    ρσ_unpack = ρσ_Iter3[ρσ_Index3];
                    text = ρσ_unpack[0];
                    search_type = ρσ_unpack[1];
                    li = ρσ_interpolate_kwargs.call(E, E.li, [ρσ_interpolate_kwargs.call(E, E.img, [ρσ_desugar_kwargs({src: absolute_path("{}/{}.png".format(interface_data.icon_path, search_type)), style: "max-height: 2.5ex; margin-right:0.5rem"})]), E.span(text)].concat([ρσ_desugar_kwargs({style: "display:flex; align-items: center; margin-bottom:0.5ex; padding: 0.5ex; cursor:pointer"})]));
                    li.addEventListener("click", add_to_search.bind(null, node, search_type));
                    li.addEventListener("click", hide_modal);
                    ul.appendChild(li);
                }
                f = ρσ_interpolate_kwargs.call(E, E.form, [E.span(_("Add to the search expression with:")), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "expr_join", value: "OR", checked: ""})]), E.span(" OR "), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "expr_join", value: "AND"})]), E.span(" AND")].concat([ρσ_desugar_kwargs({style: "text-align:left; border-top: solid 1px currentColor; padding-top:1ex; margin-top:0.5ex; display:flex; align-items:center"})]));
                and_control = f.lastChild.previousSibling;
                and_control.checked = get_session_data().get("and_search_terms");
                container.appendChild(f);
                and_control.addEventListener("change", (function() {
                    var ρσ_anonfunc = function (ev) {
                        get_session_data().set("and_search_terms", bool(ev.target.checked));
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "book_list.search"}
                    });
                    return ρσ_anonfunc;
                })());
                f.firstChild.nextSibling.addEventListener("change", (function() {
                    var ρσ_anonfunc = function (ev) {
                        get_session_data().set("and_search_terms", !ev.target.checked);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "book_list.search"}
                    });
                    return ρσ_anonfunc;
                })());
                about_items = [];
                if (data.count !== undefined) {
                    about_items.push(_("Number of books: {}").format(data.count));
                }
                if (data.avg_rating !== undefined) {
                    about_items.push(_("Average rating of books: {:.1f}").format(data.avg_rating));
                }
                footer = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "text-align:left; border-top: solid 1px currentColor; padding-top:1ex; margin-top:0.5ex;"})]);
                if (about_items.length) {
                    footer.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [" ".join(about_items)].concat([ρσ_desugar_kwargs({style: "font-size: smaller"})])));
                }
                if (footer.firstChild) {
                    container.appendChild(footer);
                }
            };
            if (!create_details.__argnames__) Object.defineProperties(create_details, {
                __argnames__ : {value: ["container", "hide_modal"]},
                __module__ : {value: "book_list.search"}
            });

            show_modal(create_details);
        };
        if (!menu_clicked.__argnames__) Object.defineProperties(menu_clicked, {
            __argnames__ : {value: ["i"]},
            __module__ : {value: "book_list.search"}
        });

        function render_children(container, children) {
            var data, tooltip, ρσ_unpack, icon, fallback, div, i, node;
            var ρσ_Iter4 = ρσ_Iterable(enumerate(children));
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                ρσ_unpack = ρσ_Iter4[ρσ_Index4];
                i = ρσ_unpack[0];
                node = ρσ_unpack[1];
                data = node.data;
                tooltip = "";
                if (data.count !== undefined) {
                    tooltip += "\n" + _("Number of books in this category: {}").format(data.count);
                }
                if (data.avg_rating !== undefined) {
                    tooltip += "\n" + _("Average rating for books in this category: {:.1f}").format(data.avg_rating);
                }
                ρσ_unpack = icon_for_node(node);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                icon = ρσ_unpack[0];
                fallback = ρσ_unpack[1];
                div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.img, [ρσ_desugar_kwargs({src: icon, onerror: show_fallback.bind(null, fallback), style: "display:inline-block; max-height:2.5ex; margin-right:0.5rem; flex-shrink:0"})]), E.span(data.name)].concat([ρσ_desugar_kwargs({class_: "tag-name"})])), ρσ_interpolate_kwargs.call(E, E.div, [E.div(svgicon("angle-down"))].concat([ρσ_desugar_kwargs({class_: "tag-menu"})]))].concat([ρσ_desugar_kwargs({title: tooltip.lstrip(), class_: "cs-search-tag-row"})]));
                div.firstChild.addEventListener("click", node_clicked.bind(null, i));
                div.lastChild.addEventListener("click", menu_clicked.bind(null, i));
                container.appendChild(div);
            }
        };
        if (!render_children.__argnames__) Object.defineProperties(render_children, {
            __argnames__ : {value: ["container", "children"]},
            __module__ : {value: "book_list.search"}
        });

        function render_breadcrumbs() {
            var container, parent, ρσ_unpack, i, index;
            container = state.breadcrumbs.container;
            if (!state.tag_path.length) {
                container.style.display = "none";
                return;
            }
            container.style.display = "inline-block";
            state.breadcrumbs.reset();
            function onclick(i) {
                return (function() {
                    var ρσ_anonfunc = function (ev) {
                        state.tag_path = state.tag_path.slice(0, i + 1);
                        render_tag_browser();
                        ev.preventDefault();
                        return true;
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "book_list.search"}
                    });
                    return ρσ_anonfunc;
                })();
            };
            if (!onclick.__argnames__) Object.defineProperties(onclick, {
                __argnames__ : {value: ["i"]},
                __module__ : {value: "book_list.search"}
            });

            function create_breadcrumb() {
                var index = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_breadcrumb.__defaults__.index : arguments[0];
                var item = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_breadcrumb.__defaults__.item : arguments[1];
                var ρσ_kwargs_obj = arguments[arguments.length-1];
                if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "index")){
                    index = ρσ_kwargs_obj.index;
                }
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "item")){
                    item = ρσ_kwargs_obj.item;
                }
                var li;
                li = state.breadcrumbs.add_crumb(onclick(index));
                if (item) {
                    li.appendChild(E.span(item.name));
                } else {
                    li.appendChild(svgicon("home", "2.2ex", "2.2ex"));
                }
            };
            if (!create_breadcrumb.__defaults__) Object.defineProperties(create_breadcrumb, {
                __defaults__ : {value: {index:-1, item:null}},
                __handles_kwarg_interpolation__ : {value: true},
                __argnames__ : {value: ["index", "item"]},
                __module__ : {value: "book_list.search"}
            });

            create_breadcrumb();
            parent = state.tag_browser_data;
            var ρσ_Iter5 = ρσ_Iterable(enumerate(state.tag_path));
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                ρσ_unpack = ρσ_Iter5[ρσ_Index5];
                i = ρσ_unpack[0];
                index = ρσ_unpack[1];
                parent = (ρσ_expr_temp = parent.children)[(typeof index === "number" && index < 0) ? ρσ_expr_temp.length + index : index];
                create_breadcrumb(i, parent.data);
            }
        };
        if (!render_breadcrumbs.__module__) Object.defineProperties(render_breadcrumbs, {
            __module__ : {value: "book_list.search"}
        });

        function render_tag_browser() {
            var container, node;
            container = component(document.getElementById(state.container_id), "tag_browser");
            clear(container);
            ρσ_interpolate_kwargs.call(this, set_css, [container].concat([ρσ_desugar_kwargs({padding: "0", display: "flex", flex_direction: "column", gap: "0.65rem", width: "100%"})]));
            try {
                node = node_for_path();
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    state.tag_path = ρσ_list_decorate([]);
                    node = node_for_path();
                } 
            }
            render_children(container, node.children);
            render_breadcrumbs();
        };
        if (!render_tag_browser.__module__) Object.defineProperties(render_tag_browser, {
            __module__ : {value: "book_list.search"}
        });

        function on_data_fetched(end_type, xhr, ev) {
            var container, loading_panel, tc, tag_browser_data;
            state.currently_loading = null;
            if (end_type === "abort") {
                return;
            }
            container = document.getElementById(state.container_id);
            if (!container) {
                return;
            }
            loading_panel = component(container, "loading");
            loading_panel.style.display = "none";
            tc = component(container, "tag_card");
            if (tc) {
                tc.style.display = "block";
            }
            container = component(container, "tag_browser");
            container.style.display = "flex";
            clear(container);
            function show_error(error_html) {
                var ediv;
                ediv = E.div();
                container.appendChild(ediv);
                safe_set_inner_html(ediv, "<h3>" + _("Failed to load Tag browser data") + "</h3>" + error_html);
            };
            if (!show_error.__argnames__) Object.defineProperties(show_error, {
                __argnames__ : {value: ["error_html"]},
                __module__ : {value: "book_list.search"}
            });

            function process_node(node, item_map) {
                var child;
                (ρσ_expr_temp = state.node_id_map)[ρσ_bound_index(node.id, ρσ_expr_temp)] = node;
                node.data = item_map[ρσ_bound_index(node.id, item_map)];
                var ρσ_Iter6 = ρσ_Iterable(node.children);
                for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                    child = ρσ_Iter6[ρσ_Index6];
                    child.parent = node;
                    process_node(child, item_map);
                }
            };
            if (!process_node.__argnames__) Object.defineProperties(process_node, {
                __argnames__ : {value: ["node", "item_map"]},
                __module__ : {value: "book_list.search"}
            });

            if (end_type === "load") {
                try {
                    tag_browser_data = JSON.parse(xhr.responseText);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        var err = ρσ_Exception;
                        show_error(err + "");
                        return;
                    } else {
                        throw ρσ_Exception;
                    }
                }
                state.tag_browser_data = tag_browser_data.root;
                state.node_id_map = Object.create(null);
                state.active_nodes = Object.create(null);
                process_node(state.tag_browser_data, tag_browser_data.item_map);
                if (last_accepted_search && last_accepted_search.library_id === current_library_id() && last_accepted_search.vl === current_virtual_library()) {
                    if (last_accepted_search.tag_path.length) {
                        state.tag_path = list(last_accepted_search.tag_path);
                    }
                }
                render_tag_browser();
            } else {
                show_error(xhr.error_html);
            }
        };
        if (!on_data_fetched.__argnames__) Object.defineProperties(on_data_fetched, {
            __argnames__ : {value: ["end_type", "xhr", "ev"]},
            __module__ : {value: "book_list.search"}
        });

        function refresh() {
            var root, lp, tc, sd, query, k, xhr;
            root = document.getElementById(state.container_id);
            if (root) {
                lp = component(root, "loading");
                if (lp) {
                    lp.style.display = "block";
                }
                tc = component(root, "tag_card");
                if (tc) {
                    tc.style.display = "none";
                }
            }
            if (state.currently_loading !== null) {
                state.currently_loading.abort();
                state.currently_loading = null;
            }
            sd = get_session_data();
            query = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["library_id"] = current_library_id();
                ρσ_d["vl"] = current_virtual_library();
                return ρσ_d;
            }).call(this);
            var ρσ_Iter7 = ρσ_Iterable("sort_tags_by partition_method collapse_at dont_collapse hide_empty_categories".split(" "));
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                k = ρσ_Iter7[ρσ_Index7];
                query[(typeof k === "number" && k < 0) ? query.length + k : k] = sd.get(k) + "";
            }
            xhr = ρσ_interpolate_kwargs.call(this, ajax, ["interface-data/tag-browser", on_data_fetched].concat([ρσ_desugar_kwargs({query: query, bypass_cache: false})]));
            xhr.send();
            state.currently_loading = xhr;
        };
        if (!refresh.__module__) Object.defineProperties(refresh, {
            __module__ : {value: "book_list.search"}
        });

        function create_search_panel(container) {
            var search_container, search_bar, loading_panel;
            state = Object.create(null);
            container.classList.add(CLASS_NAME);
            search_container = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "calibre-group-box", data_component: "search"})]);
            container.appendChild(search_container);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({data_component: "loading", class_: "cs-search-loading"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.ol, [ρσ_desugar_kwargs({style: "display:none", data_component: "breadcrumbs", class_: "cs-search-breadcrumbs"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display:none", data_component: "tag_browser", class_: "cs-search-tags"})])].concat([ρσ_desugar_kwargs({data_component: "tag_card", class_: "cs-search-tag-card", style: "display:none"})]))].concat([ρσ_desugar_kwargs({class_: "cs-search-body"})])));
            search_bar = ρσ_interpolate_kwargs.call(this, create_search_bar, [execute_search_interactive, "search-books"].concat([ρσ_desugar_kwargs({tooltip: _("Search for books"), placeholder: _("Enter the search query"), button: "icon-button"})]));
            search_container.appendChild(search_bar);
            search_container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.a, [svgicon("fts"), " ", _("Search the full text of books instead")].concat([ρσ_desugar_kwargs({class_: "blue-link", href: "javascript: void(0)", onclick: show_panel.bind(null, "fts")})]))].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem"})])));
            search_container.appendChild(ρσ_interpolate_kwargs.call(E, E.ul, [ρσ_desugar_kwargs({class_: "search-items", data_component: "search_expression"})]));
            loading_panel = component(container, "loading");
            loading_panel.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_spinner(), " " + _("Fetching data for the Tag browser, please wait") + "…"].concat([ρσ_desugar_kwargs({style: "font-size: 1.15rem; font-weight: 700; opacity: 0.9"})])));
            state.breadcrumbs = new Breadcrumbs(component(container, "breadcrumbs"));
            state.currently_loading = null;
            state.tag_browser_data = null;
            state.node_id_map = Object.create(null);
            state.active_nodes = Object.create(null);
            state.tag_path = ρσ_list_decorate([]);
            state.container_id = ensure_id(container);
            refresh();
        };
        if (!create_search_panel.__argnames__) Object.defineProperties(create_search_panel, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.search"}
        });

        function get_prefs() {
            return ρσ_list_decorate([ (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["name"] = "sort_tags_by";
                ρσ_d["text"] = _("Sort tags by");
                ρσ_d["choices"] = ρσ_list_decorate([ ["name", _("Name")], ["popularity", _("Popularity (number of books)")], ["rating", 
                _("Average rating")] ]);
                ρσ_d["tooltip"] = _("Change how the tags/authors/etc. are sorted in the \"Tag browser\"");
                return ρσ_d;
            }).call(this), (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["name"] = "partition_method";
                ρσ_d["text"] = _("Category partitioning method");
                ρσ_d["choices"] = ρσ_list_decorate([ ["first letter", _("First Letter")], ["disable", 
                _("Disable")], ["partition", _("Partition")] ]);
                ρσ_d["tooltip"] = _("Choose how Tag browser subcategories are displayed when there are more items than the limit. Select by first letter to see an A, B, C list. Choose partitioned to have a list of fixed-sized groups. Set to disabled if you never want subcategories.");
                return ρσ_d;
            }).call(this), (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["name"] = "collapse_at";
                ρσ_d["text"] = _("Collapse when more items than");
                ρσ_d["min"] = 5;
                ρσ_d["max"] = 1e4;
                ρσ_d["step"] = 5;
                ρσ_d["from_storage"] = int;
                ρσ_d["to_storage"] = int;
                ρσ_d["tooltip"] = _("If a \"Tag browser\" category has more than this number of items, it is divided up into subcategories. If the partition method is set to disable, this value is ignored.");
                return ρσ_d;
            }).call(this), (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["name"] = "dont_collapse";
                ρσ_d["text"] = _("Categories not to partition");
                ρσ_d["tooltip"] = _("A comma-separated list of categories in which items containing periods are displayed in the Tag browser trees. For example, if this box contains 'tags' then tags of the form 'Mystery.English' and 'Mystery.Thriller' will be displayed with English and Thriller both under 'Mystery'. If 'tags' is not in this box, then the tags will be displayed each on their own line.");
                return ρσ_d;
            }).call(this), (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["name"] = "hide_empty_categories";
                ρσ_d["text"] = _("Hide empty categories (columns)");
                ρσ_d["from_storage"] = (function() {
                    var ρσ_anonfunc = function (x) {
                        return x.toLowerCase() === "yes";
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["x"]},
                        __module__ : {value: "book_list.search"}
                    });
                    return ρσ_anonfunc;
                })();
                ρσ_d["to_storage"] = (function() {
                    var ρσ_anonfunc = function (x) {
                        return (x) ? "yes" : "no";
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["x"]},
                        __module__ : {value: "book_list.search"}
                    });
                    return ρσ_anonfunc;
                })();
                ρσ_d["tooltip"] = _("When checked, calibre will automatically hide any category (a column, custom or standard) that has no items to show. For example, some categories might not have values when using Virtual libraries. Checking this box will cause these empty categories to be hidden.");
                return ρσ_d;
            }).call(this) ]);
        };
        if (!get_prefs.__module__) Object.defineProperties(get_prefs, {
            __module__ : {value: "book_list.search"}
        });

        function tb_config_panel_handler() {
            return prefs_panel_handler((function() {
                var ρσ_anonfunc = function () {
                    return _("Configure Tag browser");
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.search"}
                });
                return ρσ_anonfunc;
            })(), get_prefs);
        };
        if (!tb_config_panel_handler.__module__) Object.defineProperties(tb_config_panel_handler, {
            __module__ : {value: "book_list.search"}
        });

        function onkeydown(container_id, close_action, ev) {
            if (ev.key === "Escape") {
                [ev.preventDefault(), ev.stopPropagation()];
                close_action();
            }
        };
        if (!onkeydown.__argnames__) Object.defineProperties(onkeydown, {
            __argnames__ : {value: ["container_id", "close_action", "ev"]},
            __module__ : {value: "book_list.search"}
        });

        function init(container_id) {
            var container;
            if (!library_data.sortable_fields) {
                ρσ_interpolate_kwargs.call(this, show_panel, ["book_list"].concat([ρσ_desugar_kwargs({replace: true})]));
                return;
            }
            container = document.getElementById(container_id);
            container.setAttribute("tabindex", "0");
            container.addEventListener("keydown", onkeydown.bind(null, container_id, back), (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                ρσ_d["capture"] = true;
                return ρσ_d;
            }).call(this));
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("Search for books"), icon: "back"})]));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: CLASS_NAME})]));
            create_search_panel(container.lastChild);
            container.focus();
        };
        if (!init.__argnames__) Object.defineProperties(init, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.search"}
        });

        ρσ_modules["book_list.search"].apply_search = apply_search;
        ρσ_modules["book_list.search"].sp_counter = sp_counter;
        ρσ_modules["book_list.search"].CLASS_NAME = CLASS_NAME;
        ρσ_modules["book_list.search"].state = state;
        ρσ_modules["book_list.search"].last_accepted_search = last_accepted_search;
        ρσ_modules["book_list.search"].set_apply_search = set_apply_search;
        ρσ_modules["book_list.search"].component = component;
        ρσ_modules["book_list.search"].icon_for_node = icon_for_node;
        ρσ_modules["book_list.search"].node_for_path = node_for_path;
        ρσ_modules["book_list.search"].execute_search = execute_search;
        ρσ_modules["book_list.search"].ask_about_smart_quotes = ask_about_smart_quotes;
        ρσ_modules["book_list.search"].execute_search_interactive = execute_search_interactive;
        ρσ_modules["book_list.search"].search_expression_for_item = search_expression_for_item;
        ρσ_modules["book_list.search"].node_clicked = node_clicked;
        ρσ_modules["book_list.search"].add_to_search = add_to_search;
        ρσ_modules["book_list.search"].remove_expression = remove_expression;
        ρσ_modules["book_list.search"].render_search_expression = render_search_expression;
        ρσ_modules["book_list.search"].show_fallback = show_fallback;
        ρσ_modules["book_list.search"].menu_clicked = menu_clicked;
        ρσ_modules["book_list.search"].render_children = render_children;
        ρσ_modules["book_list.search"].render_breadcrumbs = render_breadcrumbs;
        ρσ_modules["book_list.search"].render_tag_browser = render_tag_browser;
        ρσ_modules["book_list.search"].on_data_fetched = on_data_fetched;
        ρσ_modules["book_list.search"].refresh = refresh;
        ρσ_modules["book_list.search"].create_search_panel = create_search_panel;
        ρσ_modules["book_list.search"].get_prefs = get_prefs;
        ρσ_modules["book_list.search"].tb_config_panel_handler = tb_config_panel_handler;
        ρσ_modules["book_list.search"].onkeydown = onkeydown;
        ρσ_modules["book_list.search"].init = init;
    })();

    (function(){
        var __name__ = "book_list.views";
        var CLASS_NAME, ITEM_CLASS_NAME, ALLOWED_MODES, DEFAULT_MODE, book_list_data;
        var traceback = ρσ_modules.traceback;

        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;
        var ngettext = ρσ_modules.gettext.ngettext;

        var ajax_send = ρσ_modules.ajax.ajax_send;

        var add_books_panel = ρσ_modules["book_list.add"].add_books_panel;

        var cover_grid_append_item = ρσ_modules["book_list.cover_grid"].append_item;
        var cover_grid_css = ρσ_modules["book_list.cover_grid"].cover_grid_css;
        var create_cover_grid_item = ρσ_modules["book_list.cover_grid"].create_item;
        var COVER_GRID_DESCRIPTION = ρσ_modules["book_list.cover_grid"].description;
        var init_cover_grid = ρσ_modules["book_list.cover_grid"].init;
        var create_cover_grid_size_control = ρσ_modules["book_list.cover_grid"].create_cover_grid_size_control;
        var sync_cover_grid_size_control = ρσ_modules["book_list.cover_grid"].sync_cover_grid_size_control;

        var custom_list_append_item = ρσ_modules["book_list.custom_list"].append_item;
        var create_custom_list_item = ρσ_modules["book_list.custom_list"].create_item;
        var custom_list_css = ρσ_modules["book_list.custom_list"].custom_list_css;
        var CUSTOM_LIST_DESCRIPTION = ρσ_modules["book_list.custom_list"].description;
        var init_custom_list = ρσ_modules["book_list.custom_list"].init;

        var save_saved_virtual_library = ρσ_modules["book_list.saved_virtual_libraries"].save_saved_virtual_library;

        var show_saved_virtual_library_dialog = ρσ_modules["book_list.saved_virtual_library_dialog"].show_saved_virtual_library_dialog;

        var details_list_append_item = ρσ_modules["book_list.details_list"].append_item;
        var create_details_list_item = ρσ_modules["book_list.details_list"].create_item;
        var DETAILS_LIST_DESCRIPTION = ρσ_modules["book_list.details_list"].description;
        var details_list_css = ρσ_modules["book_list.details_list"].details_list_css;
        var init_details_list = ρσ_modules["book_list.details_list"].init;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var create_item = ρσ_modules["book_list.item_list"].create_item;
        var create_item_list = ρσ_modules["book_list.item_list"].create_item_list;

        var add_more_books = ρσ_modules["book_list.library_data"].add_more_books;
        var all_virtual_libraries = ρσ_modules["book_list.library_data"].all_virtual_libraries;
        var book_metadata = ρσ_modules["book_list.library_data"].book_metadata;
        var current_book_ids = ρσ_modules["book_list.library_data"].current_book_ids;
        var current_library_id = ρσ_modules["book_list.library_data"].current_library_id;
        var current_sorted_field = ρσ_modules["book_list.library_data"].current_sorted_field;
        var ensure_current_library_data = ρσ_modules["book_list.library_data"].ensure_current_library_data;
        var library_data = ρσ_modules["book_list.library_data"].library_data;
        var load_status = ρσ_modules["book_list.library_data"].load_status;
        var loaded_books_query = ρσ_modules["book_list.library_data"].loaded_books_query;
        var refresh_sidebar_navigation = ρσ_modules["book_list.library_data"].refresh_sidebar_navigation;
        var thumbnail_cache = ρσ_modules["book_list.library_data"].thumbnail_cache;
        var url_books_query = ρσ_modules["book_list.library_data"].url_books_query;

        var back = ρσ_modules["book_list.router"].back;
        var home = ρσ_modules["book_list.router"].home;
        var push_state = ρσ_modules["book_list.router"].push_state;
        var update_window_title = ρσ_modules["book_list.router"].update_window_title;

        var init_search_panel = ρσ_modules["book_list.search"].init;
        var set_apply_search = ρσ_modules["book_list.search"].set_apply_search;
        var tb_config_panel_handler = ρσ_modules["book_list.search"].tb_config_panel_handler;

        var add_button = ρσ_modules["book_list.top_bar"].add_button;
        var create_top_bar = ρσ_modules["book_list.top_bar"].create_top_bar;
        var set_title_tooltip = ρσ_modules["book_list.top_bar"].set_title_tooltip;

        var query_as_href = ρσ_modules["book_list.ui"].query_as_href;
        var set_panel_handler = ρσ_modules["book_list.ui"].set_panel_handler;
        var show_panel = ρσ_modules["book_list.ui"].show_panel;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var ensure_id = ρσ_modules.dom.ensure_id;
        var set_css = ρσ_modules.dom.set_css;
        var svgicon = ρσ_modules.dom.svgicon;

        var error_dialog = ρσ_modules.modals.error_dialog;

        var get_interface_data = ρσ_modules.session.get_interface_data;

        var conditional_timeout = ρσ_modules.utils.conditional_timeout;
        var parse_url_params = ρσ_modules.utils.parse_url_params;
        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;

        var create_button = ρσ_modules.widgets.create_button;
        var create_pager_widget = ρσ_modules.widgets.create_pager_widget;
        var create_spinner = ρσ_modules.widgets.create_spinner;
        var enable_escape_key = ρσ_modules.widgets.enable_escape_key;
        var create_select = ρσ_modules.widgets.create_select;

        CLASS_NAME = "book-list-container";
        ITEM_CLASS_NAME = "book-list-item";
        ALLOWED_MODES = (function(){
            var s = ρσ_set();
            s.jsset.add("cover_grid");
            s.jsset.add("details_list");
            s.jsset.add("custom_list");
            return s;
        })();
        DEFAULT_MODE = "cover_grid";
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, ans;
                sel = "." + CLASS_NAME + " ";
                ans = sel + "{\n        padding-left: 1rem; padding-right: 1rem;\n        @media (max-width: 720px) {\n            padding-left: 0.75rem; padding-right: 0.75rem;\n        }\n    }\n    .calibre-showing-label {\n        & > span:last-of-type { display: none; }\n        @media (max-width: 420px) {\n            & > span:last-of-type { display: inline; }\n            & > span:first-of-type { display: none; }\n        }\n    }\n    [data-component=\"book_list\"] a { color: currentColor; }\n    [data-component=\"book_list\"] a:visited { color: currentColor; }\n    ";
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "." + ITEM_CLASS_NAME].concat([ρσ_desugar_kwargs({min_width: "0", max_width: "100%", box_sizing: "border-box"})]));
                ans += cover_grid_css();
                ans += details_list_css();
                ans += custom_list_css();
                return ans;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "book_list.views"}
            });
            return ρσ_anonfunc;
        })());
        book_list_data = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["container_id"] = null;
            ρσ_d["shown_book_ids"] = set();
            ρσ_d["mode"] = null;
            ρσ_d["fetching_more_books"] = null;
            return ρσ_d;
        }).call(this);
        function parse_int(x, default_value) {
            try {
                x = int(x);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    x = default_value;
                } else {
                    throw ρσ_Exception;
                }
            }
            return x;
        };
        if (!parse_int.__argnames__) Object.defineProperties(parse_int, {
            __argnames__ : {value: ["x", "default_value"]},
            __module__ : {value: "book_list.views"}
        });

        function clamp(n, lo, hi) {
            return max(lo, min(hi, n));
        };
        if (!clamp.__argnames__) Object.defineProperties(clamp, {
            __argnames__ : {value: ["n", "lo", "hi"]},
            __module__ : {value: "book_list.views"}
        });

        function component(name) {
            return document.getElementById(book_list_data.container_id).querySelector("[data-component=\"" + ρσ_str.format("{}", name) + "\"]");
        };
        if (!component.__argnames__) Object.defineProperties(component, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "book_list.views"}
        });

        function clear_grid() {
            var e, parent, bl;
            e = component("book_list");
            if (!e) {
                return;
            }
            parent = e.parentNode;
            if (!parent) {
                return;
            }
            bl = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({data_component: "book_list"})]);
            parent.insertBefore(bl, e);
            parent.removeChild(e);
            book_list_data.init_grid(bl);
        };
        if (!clear_grid.__module__) Object.defineProperties(clear_grid, {
            __module__ : {value: "book_list.views"}
        });

        function has_parent_with_class(elem, cls) {
            while (elem) {
                if (elem.classList && elem.classList.contains(cls)) {
                    return elem;
                }
                elem = elem.parentNode;
            }
        };
        if (!has_parent_with_class.__argnames__) Object.defineProperties(has_parent_with_class, {
            __argnames__ : {value: ["elem", "cls"]},
            __module__ : {value: "book_list.views"}
        });

        function save_scroll_position() {
            var container, ρσ_unpack, left, top, elem, p, q, x, y;
            container = document.getElementById(book_list_data.container_id);
            if (container) {
                ρσ_unpack = [container.offsetLeft, container.offsetTop];
                left = ρσ_unpack[0];
                top = ρσ_unpack[1];
                for (var ρσ_Index0 = 5; ρσ_Index0 < 100; ρσ_Index0+=5) {
                    y = ρσ_Index0;
                    for (var ρσ_Index1 = 25; ρσ_Index1 < 125; ρσ_Index1+=5) {
                        x = ρσ_Index1;
                        elem = document.elementFromPoint(left + x, top + y);
                        p = has_parent_with_class(elem, ITEM_CLASS_NAME);
                        if (p) {
                            q = parse_url_params();
                            q.book_id = p.dataset.bookId;
                            ρσ_interpolate_kwargs.call(this, push_state, [q].concat([ρσ_desugar_kwargs({replace: true, call_handler: false})]));
                            return;
                        }
                    }
                }
            }
        };
        if (!save_scroll_position.__module__) Object.defineProperties(save_scroll_position, {
            __module__ : {value: "book_list.views"}
        });

        function show_subsequent_panel() {
            var name = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var query = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_subsequent_panel.__defaults__.query : arguments[1];
            var replace = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_subsequent_panel.__defaults__.replace : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "query")){
                query = ρσ_kwargs_obj.query;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "replace")){
                replace = ρσ_kwargs_obj.replace;
            }
            save_scroll_position();
            show_panel(name, query, replace);
        };
        if (!show_subsequent_panel.__defaults__) Object.defineProperties(show_subsequent_panel, {
            __defaults__ : {value: {query:null, replace:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["name", "query", "replace"]},
            __module__ : {value: "book_list.views"}
        });

        function show_add_books() {
            show_subsequent_panel("book_list^add");
        };
        if (!show_add_books.__module__) Object.defineProperties(show_add_books, {
            __module__ : {value: "book_list.views"}
        });

        function show_random_book() {
            show_subsequent_panel("book_details", (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["book_id"] = "0";
                return ρσ_d;
            }).call(this));
        };
        if (!show_random_book.__module__) Object.defineProperties(show_random_book, {
            __module__ : {value: "book_list.views"}
        });

        function add_book_list_top_bar_buttons(container) {
            add_button(container, "plus", show_add_books, _("Add books to the library"));
            add_button(container, "random", show_random_book, _("Choose a random book from the library"));
        };
        if (!add_book_list_top_bar_buttons.__argnames__) Object.defineProperties(add_book_list_top_bar_buttons, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.views"}
        });

        function on_book_click(book_id, evt) {
            evt.preventDefault();
            show_subsequent_panel("book_details", (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["book_id"] = book_id;
                return ρσ_d;
            }).call(this));
        };
        if (!on_book_click.__argnames__) Object.defineProperties(on_book_click, {
            __argnames__ : {value: ["book_id", "evt"]},
            __module__ : {value: "book_list.views"}
        });

        function create_image(book_id, max_width, max_height, on_load) {
            return thumbnail_cache.get(book_id, max_width, max_height, on_load);
        };
        if (!create_image.__argnames__) Object.defineProperties(create_image, {
            __argnames__ : {value: ["book_id", "max_width", "max_height", "on_load"]},
            __module__ : {value: "book_list.views"}
        });

        function render_id(book_id) {
            var l, metadata, ans;
            l = book_list_data.shown_book_ids.length;
            book_list_data.shown_book_ids.add(book_id);
            if (l < book_list_data.shown_book_ids.length) {
                metadata = book_metadata(book_id);
                ans = book_list_data.render_book(book_id, metadata, create_image, on_book_click.bind(null, book_id), query_as_href((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["book_id"] = book_id + "";
                    return ρσ_d;
                }).call(this), "book_details"));
                ans.classList.add(ITEM_CLASS_NAME);
                ans.dataset.bookId = str(book_id);
                return ans;
            }
        };
        if (!render_id.__argnames__) Object.defineProperties(render_id, {
            __argnames__ : {value: ["book_id"]},
            __module__ : {value: "book_list.views"}
        });

        function render_ids(book_ids) {
            var div, child, book_id;
            book_ids = book_ids || current_book_ids();
            div = component("book_list");
            if (div) {
                var ρσ_Iter2 = ρσ_Iterable(book_ids);
                for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                    book_id = ρσ_Iter2[ρσ_Index2];
                    child = render_id(book_id);
                    if (child) {
                        book_list_data.append_item(div, child);
                    }
                }
            }
        };
        if (!render_ids.__argnames__) Object.defineProperties(render_ids, {
            __argnames__ : {value: ["book_ids"]},
            __module__ : {value: "book_list.views"}
        });

        function get_view_mode() {
            var idata, mode;
            idata = get_interface_data();
            mode = get_session_data().get("view_mode", idata.default_book_list_mode);
            if (!ρσ_in(mode, ["cover_grid", "details_list", "custom_list"])) {
                mode = DEFAULT_MODE;
            }
            return mode;
        };
        if (!get_view_mode.__module__) Object.defineProperties(get_view_mode, {
            __module__ : {value: "book_list.views"}
        });

        function setup_view_mode(mode, book_list_data) {
            if (!ρσ_in(mode, ALLOWED_MODES)) {
                mode = DEFAULT_MODE;
            }
            book_list_data.mode = mode;
            if (mode === "cover_grid") {
                book_list_data.render_book = create_cover_grid_item;
                book_list_data.init_grid = init_cover_grid;
                book_list_data.append_item = cover_grid_append_item;
            } else if (mode === "details_list") {
                book_list_data.render_book = create_details_list_item;
                book_list_data.init_grid = init_details_list;
                book_list_data.append_item = details_list_append_item;
            } else if (mode === "custom_list") {
                book_list_data.render_book = create_custom_list_item;
                book_list_data.init_grid = init_custom_list;
                book_list_data.append_item = custom_list_append_item;
            }
            return mode;
        };
        if (!setup_view_mode.__argnames__) Object.defineProperties(setup_view_mode, {
            __argnames__ : {value: ["mode", "book_list_data"]},
            __module__ : {value: "book_list.views"}
        });

        function apply_view_mode() {
            var mode = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? apply_view_mode.__defaults__.mode : arguments[0];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "mode")){
                mode = ρσ_kwargs_obj.mode;
            }
            if (book_list_data.mode !== mode) {
                setup_view_mode(mode, book_list_data);
                book_list_data.shown_book_ids = set();
                clear_grid();
                render_ids();
            }
            return mode;
        };
        if (!apply_view_mode.__defaults__) Object.defineProperties(apply_view_mode, {
            __defaults__ : {value: {mode:DEFAULT_MODE}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["mode"]},
            __module__ : {value: "book_list.views"}
        });

        function update_fetching_status() {
            var more;
            more = component("more_button");
            if (!more) {
                return;
            }
            if (book_list_data.fetching_more_books) {
                more.firstChild.style.display = "none";
                more.lastChild.style.display = "block";
            } else if (library_data.search_result.total_num > book_list_data.shown_book_ids.length) {
                more.firstChild.style.display = "block";
                more.lastChild.style.display = "none";
            } else {
                more.firstChild.style.display = "none";
                more.lastChild.style.display = "none";
            }
        };
        if (!update_fetching_status.__module__) Object.defineProperties(update_fetching_status, {
            __module__ : {value: "book_list.views"}
        });

        function abort_get_more_books(no_update) {
            if (book_list_data.fetching_more_books) {
                book_list_data.fetching_more_books.abort();
                book_list_data.fetching_more_books = null;
                if (!no_update) {
                    update_fetching_status();
                }
            }
        };
        if (!abort_get_more_books.__argnames__) Object.defineProperties(abort_get_more_books, {
            __argnames__ : {value: ["no_update"]},
            __module__ : {value: "book_list.views"}
        });

        function got_more_books(end_type, xhr, event) {
            var data;
            if (book_list_data.fetching_more_books !== xhr) {
                return;
            }
            book_list_data.fetching_more_books = null;
            update_fetching_status();
            if (end_type === "load") {
                try {
                    data = JSON.parse(xhr.responseText);
                    if (!data.search_result.book_ids) {
                        throw new Exception("No books ids object in search result from server");
                    }
                    add_more_books(data);
                    render_ids(data.search_result.book_ids);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        error_dialog(_("Could not get more books"), _("Server returned an invalid response"), traceback.format_exc());
                    } else {
                        throw ρσ_Exception;
                    }
                }
            } else if (end_type !== "abort") {
                error_dialog(_("Could not get more books"), xhr.error_html);
            }
        };
        if (!got_more_books.__argnames__) Object.defineProperties(got_more_books, {
            __argnames__ : {value: ["end_type", "xhr", "event"]},
            __module__ : {value: "book_list.views"}
        });

        function get_more_books() {
            var data, key;
            data = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["offset"] = book_list_data.shown_book_ids.length;
                return ρσ_d;
            }).call(this);
            var ρσ_Iter3 = ρσ_Iterable(ρσ_list_decorate([ "query", "sort", "sort_order", "vl" ]));
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                key = ρσ_Iter3[ρσ_Index3];
                data[(typeof key === "number" && key < 0) ? data.length + key : key] = (ρσ_expr_temp = library_data.search_result)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
            }
            book_list_data.fetching_more_books = ρσ_interpolate_kwargs.call(this, ajax_send, ["interface-data/more-books", data, got_more_books].concat([ρσ_desugar_kwargs({query: (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["library_id"] = loaded_books_query().library_id;
                return ρσ_d;
            }).call(this)})]));
            update_fetching_status();
        };
        if (!get_more_books.__module__) Object.defineProperties(get_more_books, {
            __module__ : {value: "book_list.views"}
        });

        function create_more_button(more) {
            more.appendChild(create_button(_("Show more books"), "cloud-download", get_more_books));
            more.lastChild.setAttribute("rel", "next");
            ρσ_interpolate_kwargs.call(this, set_css, [more.firstChild].concat([ρσ_desugar_kwargs({display: "block", margin_left: "auto", margin_right: "auto", margin_top: "1rem"})]));
            ρσ_interpolate_kwargs.call(this, set_css, [more].concat([ρσ_desugar_kwargs({font_size: "1.5rem", padding_top: "1.5rem", margin_bottom: "1.5rem", text_align: "center", display: "flex"})]));
            more.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_spinner(), " " + _("Fetching metadata for more books, please wait") + "…"].concat([ρσ_desugar_kwargs({style: "margin-left:auto; margin-right:auto; display:none"})])));
            update_fetching_status();
        };
        if (!create_more_button.__argnames__) Object.defineProperties(create_more_button, {
            __argnames__ : {value: ["more"]},
            __module__ : {value: "book_list.views"}
        });

        function replace_books_page(data) {
            var key;
            var ρσ_Iter4 = ρσ_Iterable(data.metadata);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                key = ρσ_Iter4[ρσ_Index4];
                (ρσ_expr_temp = library_data.metadata)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = (ρσ_expr_temp = data.metadata)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
            }
            library_data.previous_book_ids = [];
            library_data.search_result = data.search_result;
            book_list_data.shown_book_ids = set();
            clear_grid();
            render_ids(data.search_result.book_ids);
        };
        if (!replace_books_page.__argnames__) Object.defineProperties(replace_books_page, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "book_list.views"}
        });

        function fetch_books_page(new_offset, page_size, on_done) {
            var sr, payload, key;
            sr = library_data.search_result;
            if (!sr) {
                if (on_done) {
                    on_done(false);
                }
                return;
            }
            abort_get_more_books(true);
            payload = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["offset"] = new_offset;
                return ρσ_d;
            }).call(this);
            var ρσ_Iter5 = ρσ_Iterable(ρσ_list_decorate([ "query", "sort", "sort_order", "vl" ]));
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                key = ρσ_Iter5[ρσ_Index5];
                payload[(typeof key === "number" && key < 0) ? payload.length + key : key] = sr[(typeof key === "number" && key < 0) ? sr.length + key : key];
            }
            book_list_data.fetching_more_books = ρσ_interpolate_kwargs.call(this, ajax_send, ["interface-data/more-books", payload, (function() {
                var ρσ_anonfunc = function (end_type, xhr, event) {
                    var data;
                    book_list_data.fetching_more_books = null;
                    if (end_type === "load") {
                        try {
                            data = JSON.parse(xhr.responseText);
                            if (!data.search_result.book_ids) {
                                throw new Exception("No books ids object in search result from server");
                            }
                            replace_books_page(data);
                            if (on_done) {
                                on_done(true);
                            }
                        } catch (ρσ_Exception) {
                            ρσ_last_exception = ρσ_Exception;
                            if (ρσ_Exception instanceof Error) {
                                if (on_done) {
                                    on_done(false);
                                }
                            } else {
                                throw ρσ_Exception;
                            }
                        }
                    } else if (end_type !== "abort") {
                        if (on_done) {
                            on_done(false);
                        }
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["end_type", "xhr", "event"]},
                    __module__ : {value: "book_list.views"}
                });
                return ρσ_anonfunc;
            })()].concat([ρσ_desugar_kwargs({query: (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["library_id"] = loaded_books_query().library_id;
                ρσ_d["num"] = str(page_size);
                return ρσ_d;
            }).call(this)})]));
        };
        if (!fetch_books_page.__argnames__) Object.defineProperties(fetch_books_page, {
            __argnames__ : {value: ["new_offset", "page_size", "on_done"]},
            __module__ : {value: "book_list.views"}
        });

        function fts() {
            var q;
            q = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["restricted"] = "y";
                ρσ_d["restriction"] = library_data.search_result.query;
                return ρσ_d;
            }).call(this);
            show_panel("fts", q);
        };
        if (!fts.__module__) Object.defineProperties(fts, {
            __module__ : {value: "book_list.views"}
        });

        function save_to_saved_virtual_library() {
            var current_query, current_search, library_id, virtual_library;
            current_query = loaded_books_query();
            current_search = (current_query.search || "") + "";
            library_id = current_query.library_id || current_library_id();
            virtual_library = (current_query.vl || "") + "";
            function do_save(item) {
                if (!save_saved_virtual_library(item)) {
                    return false;
                }
                refresh_sidebar_navigation();
                return true;
            };
            if (!do_save.__argnames__) Object.defineProperties(do_save, {
                __argnames__ : {value: ["item"]},
                __module__ : {value: "book_list.views"}
            });

            ρσ_interpolate_kwargs.call(this, show_saved_virtual_library_dialog, [_("Save as virtual library"), _("Save"), do_save, library_id, virtual_library].concat([ρσ_desugar_kwargs({initial_search: current_search})]));
        };
        if (!save_to_saved_virtual_library.__module__) Object.defineProperties(save_to_saved_virtual_library, {
            __module__ : {value: "book_list.views"}
        });

        function icon_action(icon_name, tooltip, action) {
            return ρσ_interpolate_kwargs.call(E, E.a, [svgicon(icon_name)].concat([ρσ_desugar_kwargs({class_: "calibre-icon-button", style: "margin-left: 0.4em", href: "javascript:void(0)", title: tooltip, onclick: (function() {
                var ρσ_anonfunc = function (evt) {
                    evt.preventDefault();
                    action();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["evt"]},
                    __module__ : {value: "book_list.views"}
                });
                return ρσ_anonfunc;
            })()})]));
        };
        if (!icon_action.__argnames__) Object.defineProperties(icon_action, {
            __argnames__ : {value: ["icon_name", "tooltip", "action"]},
            __module__ : {value: "book_list.views"}
        });

        function show_top_message(container) {
            var q, c, buttons;
            q = loaded_books_query();
            if (!q.search && !q.vl) {
                return false;
            }
            if (q.vl) {
                container.appendChild(E.span(ρσ_interpolate_kwargs.call(E, E.span, [E.span(_("Showing Virtual library: {}").format(q.vl)), E.span(_("Virt. lib: {}").format(q.vl)), create_button(_("Close"), "close", (function() {
                    var ρσ_anonfunc = function () {
                        show_vl();
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "book_list.views"}
                    });
                    return ρσ_anonfunc;
                })(), _("Show all books in library"))].concat([ρσ_desugar_kwargs({class_: "calibre-showing-label"})]))));
                if (q.search) {
                    container.appendChild(E.br());
                }
            }
            if (q.search) {
                c = E.span();
                if (library_data.search_result.total_num) {
                    c.style.display = "inline-flex";
                    c.style.flexWrap = "wrap";
                    c.style.alignItems = "center";
                    c.style.justifyContent = "space-between";
                    c.style.width = "100%";
                    c.appendChild(ρσ_interpolate_kwargs.call(E, E.span, [E.span(_("Showing books matching:")), E.span(_("Matching:")), " ", E.i(library_data.search_result.query)].concat([ρσ_desugar_kwargs({class_: "calibre-showing-label"})])));
                    buttons = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-left: auto; display: inline-flex"})]);
                    buttons.appendChild(E.span(" ", icon_action("close", _("Clear search"), (function() {
                        var ρσ_anonfunc = function () {
                            search();
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "book_list.views"}
                        });
                        return ρσ_anonfunc;
                    })())));
                    buttons.appendChild(E.span(" ", icon_action("plus", _("Save as virtual library"), save_to_saved_virtual_library)));
                    c.appendChild(buttons);
                    if (library_data.fts_enabled) {
                        buttons.appendChild(E.span(" ", icon_action("search", _("Search the text of these books"), fts)));
                    }
                } else {
                    c.appendChild(E.span(_("No books matching:"), " ", E.i(library_data.search_result.query)));
                }
                container.appendChild(c);
            }
            return true;
        };
        if (!show_top_message.__argnames__) Object.defineProperties(show_top_message, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.views"}
        });

        function clear_book_list_inner(inner) {
            if (inner) {
                clear(inner);
            }
        };
        if (!clear_book_list_inner.__argnames__) Object.defineProperties(clear_book_list_inner, {
            __argnames__ : {value: ["inner"]},
            __module__ : {value: "book_list.views"}
        });

        function create_optional_cover_grid_size_control(mode) {
            try {
                return create_cover_grid_size_control(mode);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    var err = ρσ_Exception;
                    console.warn("Failed to create cover grid size toolbar control");
                    console.warn(err);
                } else {
                    throw ρσ_Exception;
                }
            }
        };
        if (!create_optional_cover_grid_size_control.__argnames__) Object.defineProperties(create_optional_cover_grid_size_control, {
            __argnames__ : {value: ["mode"]},
            __module__ : {value: "book_list.views"}
        });

        function populate_book_list_toolbar() {
            var toolbar_el = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var include_sort = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var on_view_mode_change = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? populate_book_list_toolbar.__defaults__.on_view_mode_change : arguments[2];
            var initial_mode = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? populate_book_list_toolbar.__defaults__.initial_mode : arguments[3];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "on_view_mode_change")){
                on_view_mode_change = ρσ_kwargs_obj.on_view_mode_change;
            }
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "initial_mode")){
                initial_mode = ρσ_kwargs_obj.initial_mode;
            }
            var cover_grid_size_control, current_mode, ρσ_unpack, mode_wrap, mode_sel, csf, csfo, found, options, field, name, value, sort_wrap, sort_field_sel, icon_name;
            if (!toolbar_el) {
                return;
            }
            clear(toolbar_el);
            cover_grid_size_control = null;
            current_mode = initial_mode || get_view_mode();
            ρσ_unpack = ρσ_interpolate_kwargs.call(this, create_select, [_("Change book list mode"), current_mode].concat([ρσ_desugar_kwargs({cover_grid: _("Cover grid"), details_list: _("Detailed list"), custom_list: _("Custom list")})]));
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            mode_wrap = ρσ_unpack[0];
            mode_sel = ρσ_unpack[1];
            mode_sel.dataset.currentMode = current_mode;
            mode_sel.addEventListener("change", (function() {
                var ρσ_anonfunc = function (ev) {
                    var requested_mode, current_mode;
                    requested_mode = mode_sel.value;
                    current_mode = mode_sel.dataset.currentMode;
                    if (requested_mode && requested_mode !== current_mode) {
                        get_session_data().set("view_mode", requested_mode);
                        if (on_view_mode_change) {
                            current_mode = on_view_mode_change(requested_mode) || requested_mode;
                        } else {
                            current_mode = apply_view_mode(requested_mode) || requested_mode;
                        }
                        mode_sel.dataset.currentMode = current_mode;
                        mode_sel.value = current_mode;
                        if (cover_grid_size_control) {
                            sync_cover_grid_size_control(cover_grid_size_control, current_mode);
                        }
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "book_list.views"}
                });
                return ρσ_anonfunc;
            })());
            toolbar_el.appendChild(mode_wrap);
            cover_grid_size_control = create_optional_cover_grid_size_control(current_mode);
            if (cover_grid_size_control) {
                toolbar_el.appendChild(cover_grid_size_control);
            }
            if (!include_sort) {
                return;
            }
            function toggle_sort_order() {
                var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? toggle_sort_order.__defaults__.ev : arguments[0];
                var ρσ_kwargs_obj = arguments[arguments.length-1];
                if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                    ev = ρσ_kwargs_obj.ev;
                }
                var ρσ_unpack, _csf, _csfo, new_order;
                ρσ_unpack = current_sorted_field();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                _csf = ρσ_unpack[0];
                _csfo = ρσ_unpack[1];
                if (_csf === "date") {
                    _csf = "timestamp";
                }
                new_order = (_csfo === "asc") ? "desc" : "asc";
                if (_csf) {
                    change_sort(_csf, new_order);
                }
            };
            if (!toggle_sort_order.__defaults__) Object.defineProperties(toggle_sort_order, {
                __defaults__ : {value: {ev:null}},
                __handles_kwarg_interpolation__ : {value: true},
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.views"}
            });

            try {
                if (!library_data.sortable_fields) {
                    return;
                }
                ρσ_unpack = current_sorted_field();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                csf = ρσ_unpack[0];
                csfo = ρσ_unpack[1];
                if (csf === "date") {
                    csf = "timestamp";
                }
                found = false;
                options = Object.create(null);
                var ρσ_Iter6 = ρσ_Iterable(library_data.sortable_fields);
                for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                    ρσ_unpack = ρσ_Iter6[ρσ_Index6];
                    field = ρσ_unpack[0];
                    name = ρσ_unpack[1];
                    options[(typeof field === "number" && field < 0) ? options.length + field : field] = name;
                    if (field === csf) {
                        found = true;
                    }
                }
                if (!found && ρσ_exists.d(library_data.sortable_fields).length) {
                    value = library_data.sortable_fields[0][0];
                } else {
                    value = csf;
                }
                ρσ_unpack = ρσ_interpolate_kwargs.call(this, create_select, [_("Change how the list is sorted"), value].concat([ρσ_desugar_kwargs(options)]));
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                sort_wrap = ρσ_unpack[0];
                sort_field_sel = ρσ_unpack[1];
                sort_field_sel.addEventListener("change", (function() {
                    var ρσ_anonfunc = function (ev) {
                        var f;
                        f = sort_field_sel.value || "";
                        if (f) {
                            change_sort(f, null);
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "book_list.views"}
                    });
                    return ρσ_anonfunc;
                })());
                toolbar_el.appendChild(sort_wrap);
                icon_name = ((csfo || "asc") === "asc") ? "sort-amount-asc" : "sort-amount-desc";
                toolbar_el.appendChild(ρσ_interpolate_kwargs.call(this, create_button, [""].concat([ρσ_desugar_kwargs({icon: icon_name, action: toggle_sort_order, tooltip: _("Toggle sort order"), class_: "cs-sort-order-btn"})])));
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                } else {
                    throw ρσ_Exception;
                }
            }
        };
        if (!populate_book_list_toolbar.__defaults__) Object.defineProperties(populate_book_list_toolbar, {
            __defaults__ : {value: {on_view_mode_change:null, initial_mode:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["toolbar_el", "include_sort", "on_view_mode_change", "initial_mode"]},
            __module__ : {value: "book_list.views"}
        });

        function create_books_list(container) {
            var pager, book_list_div, bottom_pager_el, single_page_count_el, top_widget, bottom_widget, q, page_size, scrolled, e;
            book_list_data.container_id = ensure_id(container);
            book_list_data.shown_book_ids = set();
            book_list_data.mode = null;
            abort_get_more_books(true);
            pager = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({data_component: "pager"})]);
            book_list_div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({data_component: "book_list"})]);
            bottom_pager_el = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-bottom:1.5rem"})]);
            single_page_count_el = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin: 0.5ex 0"})]);
            container.appendChild(pager);
            container.appendChild(single_page_count_el);
            container.appendChild(book_list_div);
            container.appendChild(bottom_pager_el);
            top_widget = create_pager_widget((function() {
                var ρσ_anonfunc = function () {
                    go_to_offset((library_data.search_result.offset || 0) - page_size);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.views"}
                });
                return ρσ_anonfunc;
            })(), (function() {
                var ρσ_anonfunc = function () {
                    go_to_offset((library_data.search_result.offset || 0) + page_size);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.views"}
                });
                return ρσ_anonfunc;
            })());
            bottom_widget = create_pager_widget((function() {
                var ρσ_anonfunc = function () {
                    go_to_offset((library_data.search_result.offset || 0) - page_size);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.views"}
                });
                return ρσ_anonfunc;
            })(), (function() {
                var ρσ_anonfunc = function () {
                    go_to_offset((library_data.search_result.offset || 0) + page_size);
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.views"}
                });
                return ρσ_anonfunc;
            })());
            bottom_pager_el.appendChild(bottom_widget.container);
            top_widget.set_top_row_visibility(show_top_message(top_widget.top_row));
            apply_view_mode(get_view_mode());
            q = parse_url_params();
            page_size = clamp(parse_int(q.num, ρσ_exists.d(library_data.search_result).num || 50), 10, 200);
            function go_to_offset(new_offset) {
                var qq;
                new_offset = max(0, new_offset);
                qq = parse_url_params();
                qq.offset = str(new_offset);
                qq.num = str(page_size);
                ρσ_interpolate_kwargs.call(this, push_state, [qq].concat([ρσ_desugar_kwargs({replace: true, call_handler: false})]));
                fetch_books_page(new_offset, page_size, (function() {
                    var ρσ_anonfunc = function (ok) {
                        if (!ok) {
                            error_dialog(_("Could not load books"), _("Failed to load the requested page"));
                        }
                        update_pager();
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ok"]},
                        __module__ : {value: "book_list.views"}
                    });
                    return ρσ_anonfunc;
                })());
            };
            if (!go_to_offset.__argnames__) Object.defineProperties(go_to_offset, {
                __argnames__ : {value: ["new_offset"]},
                __module__ : {value: "book_list.views"}
            });

            function update_pager() {
                var sr, total, offset, end, has_prev, has_next;
                sr = library_data.search_result;
                total = sr.total_num || 0;
                offset = sr.offset || 0;
                end = min(total, offset + page_size);
                top_widget.count_msg.textContent = _("{0}–{1} of {2}").format((total) ? offset + 1 : 0, end, total);
                has_prev = offset > 0;
                has_next = end < total;
                top_widget.set_enabled(has_prev, has_next);
                bottom_widget.set_enabled(has_prev, has_next);
                if (!has_prev && !has_next && total && loaded_books_query().search) {
                    single_page_count_el.textContent = ngettext("{} book found", "{} books found", total).format(total);
                } else {
                    single_page_count_el.textContent = "";
                }
            };
            if (!update_pager.__module__) Object.defineProperties(update_pager, {
                __module__ : {value: "book_list.views"}
            });

            update_pager();
            pager.appendChild(top_widget.container);
            populate_book_list_toolbar(top_widget.middle_row, true);
            top_widget.set_middle_row_visibility(top_widget.middle_row.children.length > 0);
            q = parse_url_params();
            scrolled = false;
            if (q.book_id) {
                e = container.querySelector("." + ρσ_str.format("{}", ITEM_CLASS_NAME) + "[data-book-id=\"" + ρσ_str.format("{}", q.book_id) + "\"]");
                if (e && e.scrollIntoView) {
                    e.scrollIntoView(true);
                    window.scrollBy(0, -container.offsetTop);
                    scrolled = true;
                }
            }
            if (!scrolled) {
                window.scrollTo(0, 0);
            }
            q = loaded_books_query();
            if (!q.search && library_data.search_result.total_num < 1) {
                book_list_div.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("No books found")].concat([ρσ_desugar_kwargs({style: "margin: 1ex 0"})])));
            }
        };
        if (!create_books_list.__argnames__) Object.defineProperties(create_books_list, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.views"}
        });

        function check_for_books_loaded() {
            var container, container_id, err, q, desired_offset, page_size;
            container = this;
            container_id = container.id;
            if (load_status.loading) {
                conditional_timeout(container_id, 5, check_for_books_loaded);
                return;
            }
            container = container.lastChild;
            if (!load_status.ok) {
                clear(container);
                if (load_status.http_error_code === 401) {
                    container.appendChild(E.div(_("Username/password required, retrying...")));
                    ensure_current_library_data();
                    conditional_timeout(container_id, 100, check_for_books_loaded);
                    return;
                }
                err = E.div();
                safe_set_inner_html(err, load_status.error_html);
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.div(_("Failed to load books from calibre library, with error:")), err, ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.a, [_("Go back to the home page")].concat([ρσ_desugar_kwargs({onclick: (function() {
                    var ρσ_anonfunc = function () {
                        ρσ_interpolate_kwargs.call(this, home, [ρσ_desugar_kwargs({replace: true})]);
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "book_list.views"}
                    });
                    return ρσ_anonfunc;
                })(), href: "javascript: void(0)", class_: "blue-link"})]))].concat([ρσ_desugar_kwargs({style: "margin-top: 1em; border-top: solid 1px currentColor; padding-top: 1ex;"})]))].concat([ρσ_desugar_kwargs({style: "margin: 1ex 1em"})])));
                return;
            }
            clear_book_list_inner(container);
            create_books_list(container);
            q = parse_url_params();
            desired_offset = max(0, parse_int(q.offset, 0));
            if (desired_offset) {
                page_size = clamp(parse_int(q.num, ρσ_exists.d(library_data.search_result).num || 50), 10, 200);
                fetch_books_page(desired_offset, page_size, (function() {
                    var ρσ_anonfunc = function (ok) {
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ok"]},
                        __module__ : {value: "book_list.views"}
                    });
                    return ρσ_anonfunc;
                })());
            }
            if (library_data.search_result && typeof library_data.search_result.num_books_without_search === "number") {
                set_title_tooltip(this, _("Total number of books: {}").format(library_data.search_result.num_books_without_search));
            }
        };
        if (!check_for_books_loaded.__module__) Object.defineProperties(check_for_books_loaded, {
            __module__ : {value: "book_list.views"}
        });

        function init(container_id) {
            var interface_data, container, lid, title, inner;
            interface_data = get_interface_data();
            ensure_current_library_data();
            container = document.getElementById(container_id);
            lid = container.dataset.library_id = url_books_query().library_id;
            title = (ρσ_expr_temp = interface_data.library_map)[(typeof lid === "number" && lid < 0) ? ρσ_expr_temp.length + lid : lid];
            update_window_title(title);
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: title, action: (function() {
                var ρσ_anonfunc = function () {
                    [save_scroll_position(), home()];
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.views"}
                });
                return ρσ_anonfunc;
            })(), icon: "home"})]));
            add_book_list_top_bar_buttons(container);
            inner = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: CLASS_NAME})]);
            container.appendChild(inner);
            inner.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Loading books from the {} calibre library, please wait...").format(title)].concat([ρσ_desugar_kwargs({style: "margin: 1ex 1em"})])));
            conditional_timeout(container_id, 5, check_for_books_loaded);
        };
        if (!init.__argnames__) Object.defineProperties(init, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.views"}
        });

        function change_sort(field, order) {
            var sd, so, q;
            abort_get_more_books();
            sd = get_session_data();
            so = sd.get("last_sort_order");
            order = order || so[(typeof field === "number" && field < 0) ? so.length + field : field] || "asc";
            order = (order === "asc") ? "asc" : "desc";
            q = loaded_books_query();
            q.sort = field + "." + order;
            so[(typeof field === "number" && field < 0) ? so.length + field : field] = order;
            sd.set("last_sort_order", so);
            sd.set_library_option(q.library_id, "sort", q.sort);
            ρσ_interpolate_kwargs.call(this, show_panel, ["book_list"].concat([ρσ_desugar_kwargs({query: q, replace: true})]));
        };
        if (!change_sort.__argnames__) Object.defineProperties(change_sort, {
            __argnames__ : {value: ["field", "order"]},
            __module__ : {value: "book_list.views"}
        });

        function create_sort_panel(container_id) {
            var container, ρσ_unpack, close_action, close_icon, items, csf, csf_order, new_sort_order, subtitle, icon_name, action, field, name;
            if (!library_data.sortable_fields) {
                ρσ_interpolate_kwargs.call(this, show_panel, ["book_list"].concat([ρσ_desugar_kwargs({replace: true})]));
                return;
            }
            container = document.getElementById(container_id);
            ρσ_unpack = [back, "close"];
            close_action = ρσ_unpack[0];
            close_icon = ρσ_unpack[1];
            if (parse_url_params().close_action === "home") {
                ρσ_unpack = [(function() {
                    var ρσ_anonfunc = function () {
                        home();
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "book_list.views"}
                    });
                    return ρσ_anonfunc;
                })(), "home"];
                close_action = ρσ_unpack[0];
                close_icon = ρσ_unpack[1];
            }
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("Sort books by…"), action: close_action, icon: close_icon})]));
            items = ρσ_list_decorate([]);
            ρσ_unpack = current_sorted_field();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            csf = ρσ_unpack[0];
            csf_order = ρσ_unpack[1];
            new_sort_order = (csf_order === "asc") ? "desc" : "asc";
            if (csf === "date") {
                csf = "timestamp";
            }
            var ρσ_Iter7 = ρσ_Iterable(library_data.sortable_fields);
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                ρσ_unpack = ρσ_Iter7[ρσ_Index7];
                field = ρσ_unpack[0];
                name = ρσ_unpack[1];
                subtitle = icon_name = null;
                if (field === csf) {
                    subtitle = _("Reverse current sort order");
                    icon_name = (csf_order === "asc") ? "sort-amount-asc" : "sort-amount-desc";
                    action = change_sort.bind(null, field, new_sort_order);
                } else {
                    action = change_sort.bind(null, field, null);
                }
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [name].concat([ρσ_desugar_kwargs({subtitle: subtitle, icon: icon_name, action: action})])));
            }
            container.appendChild(E.div());
            create_item_list(container.lastChild, items, _("Change how the list of books is sorted"));
            enable_escape_key(container, close_action);
        };
        if (!create_sort_panel.__argnames__) Object.defineProperties(create_sort_panel, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.views"}
        });

        function search_query_for(query) {
            var q;
            q = loaded_books_query();
            if (query) {
                q.search = query;
            } else {
                delete q.search;
            }
            return q;
        };
        if (!search_query_for.__argnames__) Object.defineProperties(search_query_for, {
            __argnames__ : {value: ["query"]},
            __module__ : {value: "book_list.views"}
        });

        function search() {
            var query = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var replace = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? search.__defaults__.replace : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "replace")){
                replace = ρσ_kwargs_obj.replace;
            }
            ρσ_interpolate_kwargs.call(this, show_panel, ["book_list"].concat([ρσ_desugar_kwargs({query: search_query_for(query), replace: replace})]));
        };
        if (!search.__defaults__) Object.defineProperties(search, {
            __defaults__ : {value: {replace:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["query", "replace"]},
            __module__ : {value: "book_list.views"}
        });

        set_apply_search((function() {
            var ρσ_anonfunc = function (query) {
                search(query, true);
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["query"]},
                __module__ : {value: "book_list.views"}
            });
            return ρσ_anonfunc;
        })());
        function create_vl_panel(container_id) {
            var container, items, vls, vl_names, name;
            if (!library_data.sortable_fields) {
                ρσ_interpolate_kwargs.call(this, show_panel, ["book_list"].concat([ρσ_desugar_kwargs({replace: true})]));
                return;
            }
            container = document.getElementById(container_id);
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("Choose Virtual library…"), icon: "back"})]));
            items = ρσ_list_decorate([]);
            vls = all_virtual_libraries();
            vl_names = Object.keys(vls).sort((function() {
                var ρσ_anonfunc = function (a, b) {
                    return a.toLowerCase().localeCompare(b.toLowerCase());
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["a", "b"]},
                    __module__ : {value: "book_list.views"}
                });
                return ρσ_anonfunc;
            })());
            var ρσ_Iter8 = ρσ_Iterable(vl_names);
            for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                name = ρσ_Iter8[ρσ_Index8];
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [name].concat([ρσ_desugar_kwargs({subtitle: vls[(typeof name === "number" && name < 0) ? vls.length + name : name], action: show_vl.bind(null, name, true)})])));
            }
            container.appendChild(E.div());
            create_item_list(container.lastChild, items, _("Choose a Virtual library to browse from the list below"));
            enable_escape_key(container, back);
        };
        if (!create_vl_panel.__argnames__) Object.defineProperties(create_vl_panel, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.views"}
        });

        function show_vl(vl_name, replace) {
            var q;
            q = loaded_books_query();
            q.vl = vl_name || null;
            ρσ_interpolate_kwargs.call(this, show_panel, ["book_list"].concat([ρσ_desugar_kwargs({query: q, replace: replace || false})]));
        };
        if (!show_vl.__argnames__) Object.defineProperties(show_vl, {
            __argnames__ : {value: ["vl_name", "replace"]},
            __module__ : {value: "book_list.views"}
        });

        function create_mode_panel(container_id) {
            var container, items, current_mode;
            if (!library_data.sortable_fields) {
                ρσ_interpolate_kwargs.call(this, show_panel, ["book_list"].concat([ρσ_desugar_kwargs({replace: true})]));
                return;
            }
            container = document.getElementById(container_id);
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("Choose book list mode…"), icon: "back"})]));
            items = ρσ_list_decorate([]);
            current_mode = get_view_mode();
            function ci(title, desc, name) {
                var ic;
                ic = (name === current_mode) ? "check" : null;
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [title].concat([ρσ_desugar_kwargs({subtitle: desc, icon: ic, action: (function() {
                    var ρσ_anonfunc = function () {
                        if (name !== current_mode) {
                            get_session_data().set("view_mode", name);
                        }
                        back();
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "book_list.views"}
                    });
                    return ρσ_anonfunc;
                })()})])));
            };
            if (!ci.__argnames__) Object.defineProperties(ci, {
                __argnames__ : {value: ["title", "desc", "name"]},
                __module__ : {value: "book_list.views"}
            });

            ci(_("Cover grid"), COVER_GRID_DESCRIPTION(), "cover_grid");
            ci(_("Detailed list"), DETAILS_LIST_DESCRIPTION(), "details_list");
            ci(_("Custom list"), CUSTOM_LIST_DESCRIPTION(), "custom_list");
            container.appendChild(E.div());
            create_item_list(container.lastChild, items, _("Choose a display mode for the list of books from below"));
            enable_escape_key(container, back);
        };
        if (!create_mode_panel.__argnames__) Object.defineProperties(create_mode_panel, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.views"}
        });

        function create_add_panel(container_id) {
            if (!library_data.sortable_fields) {
                ρσ_interpolate_kwargs.call(this, show_panel, ["book_list"].concat([ρσ_desugar_kwargs({replace: true})]));
                return;
            }
            add_books_panel(container_id);
        };
        if (!create_add_panel.__argnames__) Object.defineProperties(create_add_panel, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.views"}
        });

        set_panel_handler("book_list", init);
        set_panel_handler("book_list^add", create_add_panel);
        set_panel_handler("book_list^sort", create_sort_panel);
        set_panel_handler("book_list^vl", create_vl_panel);
        set_panel_handler("book_list^search", init_search_panel);
        set_panel_handler("book_list^choose_mode", create_mode_panel);
        set_panel_handler("book_list^search^prefs", tb_config_panel_handler());
        ρσ_modules["book_list.views"].CLASS_NAME = CLASS_NAME;
        ρσ_modules["book_list.views"].ITEM_CLASS_NAME = ITEM_CLASS_NAME;
        ρσ_modules["book_list.views"].ALLOWED_MODES = ALLOWED_MODES;
        ρσ_modules["book_list.views"].DEFAULT_MODE = DEFAULT_MODE;
        ρσ_modules["book_list.views"].book_list_data = book_list_data;
        ρσ_modules["book_list.views"].parse_int = parse_int;
        ρσ_modules["book_list.views"].clamp = clamp;
        ρσ_modules["book_list.views"].component = component;
        ρσ_modules["book_list.views"].clear_grid = clear_grid;
        ρσ_modules["book_list.views"].has_parent_with_class = has_parent_with_class;
        ρσ_modules["book_list.views"].save_scroll_position = save_scroll_position;
        ρσ_modules["book_list.views"].show_subsequent_panel = show_subsequent_panel;
        ρσ_modules["book_list.views"].show_add_books = show_add_books;
        ρσ_modules["book_list.views"].show_random_book = show_random_book;
        ρσ_modules["book_list.views"].add_book_list_top_bar_buttons = add_book_list_top_bar_buttons;
        ρσ_modules["book_list.views"].on_book_click = on_book_click;
        ρσ_modules["book_list.views"].create_image = create_image;
        ρσ_modules["book_list.views"].render_id = render_id;
        ρσ_modules["book_list.views"].render_ids = render_ids;
        ρσ_modules["book_list.views"].get_view_mode = get_view_mode;
        ρσ_modules["book_list.views"].setup_view_mode = setup_view_mode;
        ρσ_modules["book_list.views"].apply_view_mode = apply_view_mode;
        ρσ_modules["book_list.views"].update_fetching_status = update_fetching_status;
        ρσ_modules["book_list.views"].abort_get_more_books = abort_get_more_books;
        ρσ_modules["book_list.views"].got_more_books = got_more_books;
        ρσ_modules["book_list.views"].get_more_books = get_more_books;
        ρσ_modules["book_list.views"].create_more_button = create_more_button;
        ρσ_modules["book_list.views"].replace_books_page = replace_books_page;
        ρσ_modules["book_list.views"].fetch_books_page = fetch_books_page;
        ρσ_modules["book_list.views"].fts = fts;
        ρσ_modules["book_list.views"].save_to_saved_virtual_library = save_to_saved_virtual_library;
        ρσ_modules["book_list.views"].icon_action = icon_action;
        ρσ_modules["book_list.views"].show_top_message = show_top_message;
        ρσ_modules["book_list.views"].clear_book_list_inner = clear_book_list_inner;
        ρσ_modules["book_list.views"].create_optional_cover_grid_size_control = create_optional_cover_grid_size_control;
        ρσ_modules["book_list.views"].populate_book_list_toolbar = populate_book_list_toolbar;
        ρσ_modules["book_list.views"].create_books_list = create_books_list;
        ρσ_modules["book_list.views"].check_for_books_loaded = check_for_books_loaded;
        ρσ_modules["book_list.views"].init = init;
        ρσ_modules["book_list.views"].change_sort = change_sort;
        ρσ_modules["book_list.views"].create_sort_panel = create_sort_panel;
        ρσ_modules["book_list.views"].search_query_for = search_query_for;
        ρσ_modules["book_list.views"].search = search;
        ρσ_modules["book_list.views"].create_vl_panel = create_vl_panel;
        ρσ_modules["book_list.views"].show_vl = show_vl;
        ρσ_modules["book_list.views"].create_mode_panel = create_mode_panel;
        ρσ_modules["book_list.views"].create_add_panel = create_add_panel;
    })();

    (function(){
        var __name__ = "book_list.book_details";
        var bd_counter, CLASS_NAME, SEARCH_INTERNET_CLASS, COPY_TO_LIBRARY_CLASS, DATA_FILES_CLASS, FORMAT_PRIORITIES, IGNORED_FIELDS, default_sort, ρσ_unpack, i, f, current_fetch, EXTENSIONS_TO_OPEN_IN_BROWSER;
        var E = ρσ_modules.elementmaker.E;

        var traceback = ρσ_modules.traceback;

        var ajax = ρσ_modules.ajax.ajax;
        var ajax_send = ρσ_modules.ajax.ajax_send;
        var encode_query_component = ρσ_modules.ajax.encode_query_component;

        var refresh_after_delete = ρσ_modules["book_list.delete_book"].refresh_after_delete;
        var start_delete_book = ρσ_modules["book_list.delete_book"].start_delete_book;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var create_item = ρσ_modules["book_list.item_list"].create_item;
        var create_item_list = ρσ_modules["book_list.item_list"].create_item_list;
        var create_side_action = ρσ_modules["book_list.item_list"].create_side_action;

        var all_libraries = ρσ_modules["book_list.library_data"].all_libraries;
        var book_after = ρσ_modules["book_list.library_data"].book_after;
        var book_metadata = ρσ_modules["book_list.library_data"].book_metadata;
        var cover_url = ρσ_modules["book_list.library_data"].cover_url;
        var current_library_id = ρσ_modules["book_list.library_data"].current_library_id;
        var current_virtual_library = ρσ_modules["book_list.library_data"].current_virtual_library;
        var download_url = ρσ_modules["book_list.library_data"].download_url;
        var library_data = ρσ_modules["book_list.library_data"].library_data;
        var load_status = ρσ_modules["book_list.library_data"].load_status;
        var set_book_metadata = ρσ_modules["book_list.library_data"].set_book_metadata;
        var download_data_file_url = ρσ_modules["book_list.library_data"].download_data_file_url;
        var web_search_url = ρσ_modules["book_list.library_data"].web_search_url;

        var back = ρσ_modules["book_list.router"].back;
        var home = ρσ_modules["book_list.router"].home;
        var open_book = ρσ_modules["book_list.router"].open_book;
        var report_a_load_failure = ρσ_modules["book_list.router"].report_a_load_failure;
        var show_note = ρσ_modules["book_list.router"].show_note;
        var open_book_url_in_library = ρσ_modules["book_list.router"].open_book_url_in_library;
        var search_url_in_library = ρσ_modules["book_list.router"].search_url_in_library;

        var color_scheme = ρσ_modules["book_list.theme"].color_scheme;
        var get_color = ρσ_modules["book_list.theme"].get_color;
        var get_color_as_rgba = ρσ_modules["book_list.theme"].get_color_as_rgba;

        var clear_buttons = ρσ_modules["book_list.top_bar"].clear_buttons;
        var create_top_bar = ρσ_modules["book_list.top_bar"].create_top_bar;
        var set_title = ρσ_modules["book_list.top_bar"].set_title;

        var query_as_href = ρσ_modules["book_list.ui"].query_as_href;
        var set_panel_handler = ρσ_modules["book_list.ui"].set_panel_handler;
        var show_panel = ρσ_modules["book_list.ui"].show_panel;

        var search_query_for = ρσ_modules["book_list.views"].search_query_for;

        var format_date = ρσ_modules.date.format_date;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var ensure_id = ρσ_modules.dom.ensure_id;
        var svgicon = ρσ_modules.dom.svgicon;
        var unique_id = ρσ_modules.dom.unique_id;

        var update_status_widget = ρσ_modules.file_uploads.update_status_widget;
        var upload_files_widget = ρσ_modules.file_uploads.upload_files_widget;
        var upload_status_widget = ρσ_modules.file_uploads.upload_status_widget;

        var _ = ρσ_modules.gettext.gettext;

        var create_custom_dialog = ρσ_modules.modals.create_custom_dialog;
        var error_dialog = ρσ_modules.modals.error_dialog;
        var warning_dialog = ρσ_modules.modals.warning_dialog;
        var question_dialog = ρσ_modules.modals.question_dialog;

        var copy_touch = ρσ_modules["read_book.touch"].copy_touch;
        var install_handlers = ρσ_modules["read_book.touch"].install_handlers;
        var interpret_single_gesture = ρσ_modules["read_book.touch"].interpret_single_gesture;
        var touch_id = ρσ_modules["read_book.touch"].touch_id;
        var update_touch = ρσ_modules["read_book.touch"].update_touch;

        var get_interface_data = ρσ_modules.session.get_interface_data;

        var conditional_timeout = ρσ_modules.utils.conditional_timeout;
        var debounce = ρσ_modules.utils.debounce;
        var fmt_sidx = ρσ_modules.utils.fmt_sidx;
        var human_readable = ρσ_modules.utils.human_readable;
        var parse_url_params = ρσ_modules.utils.parse_url_params;
        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;
        var sandboxed_html = ρσ_modules.utils.sandboxed_html;

        var create_button = ρσ_modules.widgets.create_button;
        var create_spinner = ρσ_modules.widgets.create_spinner;

        bd_counter = 0;
        CLASS_NAME = "book-details-panel";
        SEARCH_INTERNET_CLASS = "book-details-search-internet";
        COPY_TO_LIBRARY_CLASS = "book-details-copy-to-library";
        DATA_FILES_CLASS = "book-details-data-files";
        FORMAT_PRIORITIES = ρσ_list_decorate([ "EPUB", "AZW3", "DOCX", "LIT", "MOBI", "ODT", "RTF", "MD", "MARKDOWN", "TXT", "PDF" ]);
        function sort_formats_key(fmt) {
            var ans;
            ans = FORMAT_PRIORITIES.indexOf(fmt);
            if (ans < 0) {
                ans = FORMAT_PRIORITIES.length;
            }
            return ans;
        };
        if (!sort_formats_key.__argnames__) Object.defineProperties(sort_formats_key, {
            __argnames__ : {value: ["fmt"]},
            __module__ : {value: "book_list.book_details"}
        });

        function get_preferred_format(metadata, output_format, input_formats, for_download) {
            var formats, f, fmt, found, q;
            formats = metadata && metadata.formats || [];
            formats = (function() {
                var ρσ_Iter = ρσ_Iterable(formats), ρσ_Result = [], f;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    f = ρσ_Iter[ρσ_Index];
                    ρσ_Result.push(f.toUpperCase());
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
            fmt = (output_format === "PDF") ? "EPUB" : output_format;
            if (formats.length && formats.indexOf(fmt) === -1) {
                found = false;
                formats = ρσ_interpolate_kwargs.call(this, sorted, [formats].concat([ρσ_desugar_kwargs({key: sort_formats_key})]));
                var ρσ_Iter0 = ρσ_Iterable(formats);
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    q = ρσ_Iter0[ρσ_Index0];
                    if (input_formats[(typeof q === "number" && q < 0) ? input_formats.length + q : q]) {
                        fmt = q;
                        found = true;
                        break;
                    }
                }
                if (for_download && !found && formats.length) {
                    fmt = formats[0];
                }
            }
            return fmt.toUpperCase();
        };
        if (!get_preferred_format.__argnames__) Object.defineProperties(get_preferred_format, {
            __argnames__ : {value: ["metadata", "output_format", "input_formats", "for_download"]},
            __module__ : {value: "book_list.book_details"}
        });

        IGNORED_FIELDS = (function(){
            var s = ρσ_set();
            s.jsset.add("title");
            s.jsset.add("sort");
            s.jsset.add("uuid");
            s.jsset.add("id");
            s.jsset.add("urls_from_identifiers");
            s.jsset.add("lang_names");
            s.jsset.add("last_modified");
            s.jsset.add("path");
            return s;
        })();
        default_sort = (function() {
            var ρσ_Iter = ρσ_Iterable(enumerate(["title", "title_sort", "authors", "author_sort", 
            "series", "rating", "pubdate", "tags", "timestamp", "pubdate", "identifiers", "languages", 
            "publisher", "last_modified"])), ρσ_Result = Object.create(null), i, f;
            for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                ρσ_unpack = ρσ_Iter[ρσ_Index];
                i = ρσ_unpack[0];
                f = ρσ_unpack[1];
                ρσ_Result[f] = (i + 1);
            }
            return ρσ_Result;
        })();
        default_sort["formats"] = 999;
        function field_sorter(field_metadata) {
            return (function() {
                var ρσ_anonfunc = function (field) {
                    var lvl, fm;
                    lvl = "{:03d}".format(default_sort[(typeof field === "number" && field < 0) ? default_sort.length + field : field] || 998);
                    fm = (ρσ_expr_temp = (field_metadata[(typeof field === "number" && field < 0) ? field_metadata.length + field : field] || Object.create(null)))[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field] || Object.create(null);
                    return lvl + (fm.name || "zzzzz");
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["field"]},
                    __module__ : {value: "book_list.book_details"}
                });
                return ρσ_anonfunc;
            })();
        };
        if (!field_sorter.__argnames__) Object.defineProperties(field_sorter, {
            __argnames__ : {value: ["field_metadata"]},
            __module__ : {value: "book_list.book_details"}
        });

        function href_for_search() {
            var name = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var val = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var use_quotes = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? href_for_search.__defaults__.use_quotes : arguments[2];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "use_quotes")){
                use_quotes = ρσ_kwargs_obj.use_quotes;
            }
            var query, q;
            query = ((use_quotes) ? "{}:\"={}\"" : "{}:{}").format(name, str.replace(val, "\"", "\\\""));
            q = search_query_for(query);
            return query_as_href(q);
        };
        if (!href_for_search.__defaults__) Object.defineProperties(href_for_search, {
            __defaults__ : {value: {use_quotes:true}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["name", "val", "use_quotes"]},
            __module__ : {value: "book_list.book_details"}
        });

        function on_fmt_click(ev) {
            var fmt, book_id, ρσ_unpack, title, sz;
            fmt = ev.currentTarget.dataset.format;
            book_id = int(ev.currentTarget.dataset.bookId);
            ρσ_unpack = this;
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            title = ρσ_unpack[0];
            sz = ρσ_unpack[1];
            create_custom_dialog(title, (function() {
                var ρσ_anonfunc = function (parent, close_modal) {
                    var read_button;
                    function action(which) {
                        close_modal();
                        which(book_id, fmt);
                    };
                    if (!action.__argnames__) Object.defineProperties(action, {
                        __argnames__ : {value: ["which"]},
                        __module__ : {value: "book_list.book_details"}
                    });

                    if (fmt.lower() === "pdf") {
                        read_button = download_url(book_id, fmt, "inline");
                    } else {
                        read_button = action.bind(null, read_format);
                    }
                    parent.appendChild(E.div(E.div(_("What would you like to do with the {} format?").format(fmt)), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Read"), "book", read_button), ρσ_interpolate_kwargs.call(this, create_button, [_("Download"), "cloud-download", download_url(book_id, fmt), _("File size: {}").format(human_readable(sz))].concat([ρσ_desugar_kwargs({download_filename: "" + ρσ_str.format("{}", title) + "." + ρσ_str.format("{}", fmt.toLowerCase()) + ""})]))].concat([ρσ_desugar_kwargs({class_: "button-box"})]))));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["parent", "close_modal"]},
                    __module__ : {value: "book_list.book_details"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!on_fmt_click.__argnames__) Object.defineProperties(on_fmt_click, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "book_list.book_details"}
        });

        function adjust_iframe_height(iframe) {
            var de;
            de = iframe.contentWindow.document.documentElement;
            iframe.style.height = de.offsetHeight + 5 + "px";
            iframe.dataset.last_window_width = window.innerWidth + "";
            return de;
        };
        if (!adjust_iframe_height.__argnames__) Object.defineProperties(adjust_iframe_height, {
            __argnames__ : {value: ["iframe"]},
            __module__ : {value: "book_list.book_details"}
        });

        function setup_iframe(iframe) {
            var de, a, key;
            de = adjust_iframe_height(iframe);
            var ρσ_Iter1 = ρσ_Iterable(de.querySelectorAll("a[href]"));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                a = ρσ_Iter1[ρσ_Index1];
                a.setAttribute("target", "_parent");
            }
            function forward_touch_events(ev) {
                var container, dup;
                container = window.parent.document.getElementById(render_book.container_id);
                if (container) {
                    dup = new ev.constructor(ev.type, ev);
                    container.dispatchEvent(dup);
                }
            };
            if (!forward_touch_events.__argnames__) Object.defineProperties(forward_touch_events, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            var ρσ_Iter2 = ρσ_Iterable(ρσ_list_decorate([ "start", "move", "end", "cancel" ]));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                key = ρσ_Iter2[ρσ_Index2];
                iframe.contentWindow.addEventListener("touch" + ρσ_str.format("{}", key) + "", forward_touch_events);
            }
        };
        if (!setup_iframe.__argnames__) Object.defineProperties(setup_iframe, {
            __argnames__ : {value: ["iframe"]},
            __module__ : {value: "book_list.book_details"}
        });

        function adjust_all_iframes(ev) {
            var ww, iframe;
            var ρσ_Iter3 = ρσ_Iterable(document.querySelectorAll("." + ρσ_str.format("{}", CLASS_NAME) + " iframe"));
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                iframe = ρσ_Iter3[ρσ_Index3];
                ww = parseInt(iframe.dataset.last_window_width);
                if (ww !== window.innerWidth) {
                    adjust_iframe_height(iframe);
                }
            }
        };
        if (!adjust_all_iframes.__argnames__) Object.defineProperties(adjust_all_iframes, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "book_list.book_details"}
        });

        function add_stars_to(stars, val, allow_half_stars) {
            var i;
            for (var ρσ_Index4 = 0; ρσ_Index4 < Math.floor(val / 2); ρσ_Index4++) {
                i = ρσ_Index4;
                stars.appendChild(svgicon("star"));
            }
            if (allow_half_stars && val % 2) {
                stars.appendChild(svgicon("star-half"));
            }
        };
        if (!add_stars_to.__argnames__) Object.defineProperties(add_stars_to, {
            __argnames__ : {value: ["stars", "val", "allow_half_stars"]},
            __module__ : {value: "book_list.book_details"}
        });

        if ((typeof window !== "undefined" && window !== null)) {
            window.addEventListener("resize", debounce(adjust_all_iframes, 250));
        }
        function hex_decode(lib) {
            const uint8Array = new Uint8Array(lib.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));;
            lib = new TextDecoder("utf-8").decode(uint8Array);;
            return lib;
        };
        if (!hex_decode.__argnames__) Object.defineProperties(hex_decode, {
            __argnames__ : {value: ["lib"]},
            __module__ : {value: "book_list.book_details"}
        });

        function decode_calibre_url_library_id(lib) {
            if (lib.startswith("_hex_-")) {
                lib = hex_decode(lib.slice(6));
            } else if (lib === "_") {
                lib = current_library_id();
            }
            return lib;
        };
        if (!decode_calibre_url_library_id.__argnames__) Object.defineProperties(decode_calibre_url_library_id, {
            __argnames__ : {value: ["lib"]},
            __module__ : {value: "book_list.book_details"}
        });

        function replace_calibre_links_to_books(html) {
            var parser, dom, changed;
            parser = new DOMParser();
            dom = parser.parseFromString(html, "text/html");
            changed = false;
            dom.body.querySelectorAll("a[href]").forEach((function() {
                var ρσ_anonfunc = function (link) {
                    var url, path, parts, ρσ_unpack, lib, book_id, q, vl, new_href, fmt, extra_query;
                    if (!link.href || !link.href.startswith("calibre://")) {
                        return;
                    }
                    url = new URL(link.href, window.location.origin);
                    if (url.hostname !== "show-book" && url.hostname !== "view-book" && url.hostname !== "search") {
                        return;
                    }
                    path = url.pathname;
                    parts = str.split(path, "/");
                    ρσ_unpack = [parts[1], parts[2]];
                    lib = ρσ_unpack[0];
                    book_id = ρσ_unpack[1];
                    lib = decode_calibre_url_library_id(lib);
                    if (url.hostname === "search") {
                        q = vl = "";
                        if (url.searchParams.get("eq")) {
                            q = hex_decode(url.searchParams.get("eq"));
                        } else if (url.searchParams.get("q")) {
                            q = url.searchParams.get("q");
                        }
                        if (!q) {
                            return;
                        }
                        if (url.searchParams.get("encoded_virtual_library")) {
                            vl = hex_decode(url.searchParams.get("encoded_virtual_library"));
                        } else if (url.searchParams.get("virtual_library")) {
                            vl = url.searchParams.get("virtual_library");
                        }
                        if (vl === "_") {
                            vl = "";
                        }
                        link.href = search_url_in_library(lib, q, vl);
                        changed = true;
                    } else {
                        try {
                            book_id = int(book_id);
                        } catch (ρσ_Exception) {
                            ρσ_last_exception = ρσ_Exception;
                            {
                                return;
                            } 
                        }
                        if (url.hostname === "show-book") {
                            new_href = query_as_href((function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["book_id"] = book_id + "";
                                ρσ_d["library_id"] = lib;
                                return ρσ_d;
                            }).call(this), "book_details");
                        } else {
                            fmt = parts[3];
                            extra_query = Object.create(null);
                            url.searchParams.forEach((function() {
                                var ρσ_anonfunc = function (val, key) {
                                    if (key === "open_at") {
                                        key = "bookpos";
                                    }
                                    extra_query[(typeof key === "number" && key < 0) ? extra_query.length + key : key] = val;
                                };
                                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                    __argnames__ : {value: ["val", "key"]},
                                    __module__ : {value: "book_list.book_details"}
                                });
                                return ρσ_anonfunc;
                            })());
                            new_href = open_book_url_in_library(lib, book_id, fmt, extra_query);
                            if (url.search) {
                                new_href;
                            }
                        }
                        link.href = new_href;
                        changed = true;
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["link"]},
                    __module__ : {value: "book_list.book_details"}
                });
                return ρσ_anonfunc;
            })());
            if (changed) {
                return new XMLSerializer().serializeToString(dom);;
            }
            return html;
        };
        if (!replace_calibre_links_to_books.__argnames__) Object.defineProperties(replace_calibre_links_to_books, {
            __argnames__ : {value: ["html"]},
            __module__ : {value: "book_list.book_details"}
        });

        function adjusting_sandboxed_html(html, extra_css) {
            var color, css, ans;
            color = get_color_as_rgba("window-foreground");
            css = "\n\n:root { color-scheme: " + ρσ_str.format("{}", color_scheme()) + " }\n\nhtml, body { overflow: hidden; color: rgba(" + ρσ_str.format("{}", color[0]) + ", " + ρσ_str.format("{}", color[1]) + ", " + ρσ_str.format("{}", color[2]) + ", " + ρσ_str.format("{}", color[3]) + ") }";
            if (extra_css) {
                css += "\n\n" + extra_css;
            }
            ans = sandboxed_html(html, css, "allow-same-origin allow-top-navigation-by-user-activation");
            ans.addEventListener("load", (function() {
                var ρσ_anonfunc = function (ev) {
                    setup_iframe(ev.target);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "book_list.book_details"}
                });
                return ρσ_anonfunc;
            })());
            ans.style.height = "50vh";
            ans.dataset.last_window_width = "0";
            return ans;
        };
        if (!adjusting_sandboxed_html.__argnames__) Object.defineProperties(adjusting_sandboxed_html, {
            __argnames__ : {value: ["html", "extra_css"]},
            __module__ : {value: "book_list.book_details"}
        });

        function render_metadata(mi, table, book_id, iframe_css) {
            var field_metadata, interface_data, fields, vertical_categories, x, comments, link_maps, fm, field, all_html, name, ρσ_unpack, comment, iframe;
            field_metadata = library_data.field_metadata;
            interface_data = get_interface_data();
            function allowed_fields(field) {
                var fm;
                if (field.endswith("_index")) {
                    fm = field_metadata[ρσ_bound_index(field.slice(0, -len("_index")), field_metadata)];
                    if (fm && fm.datatype === "series") {
                        return false;
                    }
                }
                if (field.startswith("#")) {
                    return true;
                }
                if (ρσ_in(field, IGNORED_FIELDS) || field.endswith("_sort")) {
                    return false;
                }
                if (mi[(typeof field === "number" && field < 0) ? mi.length + field : field] === undefined) {
                    return false;
                }
                return true;
            };
            if (!allowed_fields.__argnames__) Object.defineProperties(allowed_fields, {
                __argnames__ : {value: ["field"]},
                __module__ : {value: "book_list.book_details"}
            });

            fields = library_data.book_display_fields;
            vertical_categories = (function() {
                var ρσ_Iter = ρσ_Iterable(library_data.book_details_vertical_categories || []), ρσ_Result = Object.create(null), x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    ρσ_Result[x] = (true);
                }
                return ρσ_Result;
            })();
            if (!fields || !fields.length || get_session_data().get("show_all_metadata")) {
                if (field_metadata) {
                    fields = ρσ_interpolate_kwargs.call(this, sorted, [filter(allowed_fields, mi)].concat([ρσ_desugar_kwargs({key: field_sorter(field_metadata)})]));
                } else {
                    fields = filter(allowed_fields, fields);
                }
            } else {
                fields = filter(allowed_fields, fields);
            }
            comments = [];
            link_maps = mi.link_maps || {};
            function show_note_action(field, item_id, item_val) {
                show_note(field, item_id, item_val);
            };
            if (!show_note_action.__argnames__) Object.defineProperties(show_note_action, {
                __argnames__ : {value: ["field", "item_id", "item_val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function add_note_link(field, name, val, parent) {
                if (mi.items_with_notes && (ρσ_expr_temp = mi.items_with_notes)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field] && (ρσ_expr_temp = (ρσ_expr_temp = mi.items_with_notes)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field])[(typeof val === "number" && val < 0) ? ρσ_expr_temp.length + val : val]) {
                    parent.appendChild(document.createTextNode(" "));
                    parent.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [svgicon("pencil")].concat([ρσ_desugar_kwargs({title: _("Show notes for: {}").format(val), href: "javascript:void(0)", onclick: show_note_action.bind(null, field, (ρσ_expr_temp = (ρσ_expr_temp = mi.items_with_notes)[(typeof field === "number" && field < 0) ? ρσ_expr_temp.length + field : field])[(typeof val === "number" && val < 0) ? ρσ_expr_temp.length + val : val], val), class_: "blue-link"})])));
                }
            };
            if (!add_note_link.__argnames__) Object.defineProperties(add_note_link, {
                __argnames__ : {value: ["field", "name", "val", "parent"]},
                __module__ : {value: "book_list.book_details"}
            });

            function add_row() {
                var field = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
                var name = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
                var val = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
                var is_searchable = (arguments[3] === undefined || ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_row.__defaults__.is_searchable : arguments[3];
                var is_html = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_row.__defaults__.is_html : arguments[4];
                var join = (arguments[5] === undefined || ( 5 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_row.__defaults__.join : arguments[5];
                var search_text = (arguments[6] === undefined || ( 6 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_row.__defaults__.search_text : arguments[6];
                var use_quotes = (arguments[7] === undefined || ( 7 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_row.__defaults__.use_quotes : arguments[7];
                var ρσ_kwargs_obj = arguments[arguments.length-1];
                if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "is_searchable")){
                    is_searchable = ρσ_kwargs_obj.is_searchable;
                }
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "is_html")){
                    is_html = ρσ_kwargs_obj.is_html;
                }
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "join")){
                    join = ρσ_kwargs_obj.join;
                }
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "search_text")){
                    search_text = ρσ_kwargs_obj.search_text;
                }
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "use_quotes")){
                    use_quotes = ρσ_kwargs_obj.use_quotes;
                }
                var is_vertical, v;
                if (val === undefined || val === null) {
                    return;
                }
                is_vertical = vertical_categories[(typeof field === "number" && field < 0) ? vertical_categories.length + field : field];
                function add_val(v) {
                    var parent, websearch_link, no_link, fm, text_rep, target, calibre_search_url, calibre_search_tooltip, url, tooltip;
                    if (!v.appendChild) {
                        v += "";
                    }
                    parent = table.lastChild.lastChild;
                    if (is_searchable) {
                        websearch_link = false;
                        no_link = false;
                        if (field === "authors") {
                            no_link = interface_data.default_author_link === "__no_link__";
                            websearch_link = bool(interface_data.default_author_link) && interface_data.default_author_link !== "search-calibre";
                        } else {
                            fm = field_metadata[(typeof field === "number" && field < 0) ? field_metadata.length + field : field];
                            if ((typeof fm !== "undefined" && fm !== null ? fm : Object.create(null)).display && fm.display.web_search_template && ρσ_in(fm.display.web_search_template.partition(":")[0], ["http", 
                            "https"])) {
                                websearch_link = true;
                            }
                        }
                        text_rep = search_text || v;
                        target = "_self";
                        if (websearch_link && typeof v !== "string") {
                            websearch_link = false;
                        }
                        calibre_search_url = ρσ_interpolate_kwargs.call(this, href_for_search, [is_searchable, text_rep].concat([ρσ_desugar_kwargs({use_quotes: use_quotes})]));
                        calibre_search_tooltip = _("Click to see books with {0}: {1}").format(name, text_rep);
                        if (websearch_link) {
                            url = web_search_url(book_id, field, v);
                            target = "_blank";
                            tooltip = _("Click to browse for {} on the web").format(text_rep);
                        } else {
                            url = calibre_search_url;
                            tooltip = calibre_search_tooltip;
                        }
                        if (no_link) {
                            parent.appendChild((v.appendChild) ? v : document.createTextNode(v));
                        } else {
                            parent.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [v].concat([ρσ_desugar_kwargs({target: target, title: tooltip, class_: "blue-link", href: url})])));
                        }
                        if (link_maps[(typeof field === "number" && field < 0) ? link_maps.length + field : field] && (ρσ_expr_temp = link_maps[(typeof field === "number" && field < 0) ? link_maps.length + field : field])[(typeof text_rep === "number" && text_rep < 0) ? ρσ_expr_temp.length + text_rep : text_rep]) {
                            url = (ρσ_expr_temp = link_maps[(typeof field === "number" && field < 0) ? link_maps.length + field : field])[(typeof text_rep === "number" && text_rep < 0) ? ρσ_expr_temp.length + text_rep : text_rep];
                            if (url.startswith("https://") || url.startswith("http://")) {
                                parent.appendChild(document.createTextNode(" "));
                                parent.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [svgicon("external-link")].concat([ρσ_desugar_kwargs({title: _("Click to open") + ": " + url, href: url, target: "_blank", class_: "blue-link"})])));
                            }
                        }
                        if (websearch_link || no_link) {
                            parent.appendChild(document.createTextNode(" "));
                            parent.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [svgicon("search")].concat([ρσ_desugar_kwargs({title: calibre_search_tooltip, href: calibre_search_url, class_: "blue-link"})])));
                        }
                    } else {
                        parent.appendChild((v.appendChild) ? v : document.createTextNode(v));
                    }
                    if (typeof v === "string" && !is_html) {
                        add_note_link(field, name, v, parent);
                    }
                };
                if (!add_val.__argnames__) Object.defineProperties(add_val, {
                    __argnames__ : {value: ["v"]},
                    __module__ : {value: "book_list.book_details"}
                });

                table.appendChild(E.tr(E.td(name), E.td()));
                if (is_html && /[<>]/.test(val + "")) {
                    table.lastChild.lastChild.appendChild(adjusting_sandboxed_html(val + "", iframe_css));
                } else {
                    if (!join) {
                        add_val(val);
                    } else {
                        var ρσ_Iter5 = ρσ_Iterable(val);
                        for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                            v = ρσ_Iter5[ρσ_Index5];
                            add_val(v);
                            if (v !== val[val.length-1]) {
                                if (is_vertical) {
                                    table.lastChild.lastChild.appendChild(E.br());
                                } else {
                                    table.lastChild.lastChild.appendChild(document.createTextNode(join));
                                }
                            }
                        }
                    }
                }
                return table.lastChild.lastChild;
            };
            if (!add_row.__defaults__) Object.defineProperties(add_row, {
                __defaults__ : {value: {is_searchable:false, is_html:false, join:null, search_text:null, use_quotes:true}},
                __handles_kwarg_interpolation__ : {value: true},
                __argnames__ : {value: ["field", "name", "val", "is_searchable", "is_html", "join", "search_text", "use_quotes"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_composite(field, fm, name, val) {
                var all_vals;
                if (fm.display && fm.display.contains_html) {
                    ρσ_interpolate_kwargs.call(this, add_row, [field, name, val].concat([ρσ_desugar_kwargs({is_html: true})]));
                    return;
                }
                if (fm.is_multiple && fm.is_multiple.list_to_ui) {
                    all_vals = filter(null, map(str.strip, val.split(fm.is_multiple.list_to_ui)));
                    ρσ_interpolate_kwargs.call(this, add_row, [field, name, all_vals].concat([ρσ_desugar_kwargs({is_searchable: field, join: fm.is_multiple.list_to_ui})]));
                } else {
                    ρσ_interpolate_kwargs.call(this, add_row, [field, name, val].concat([ρσ_desugar_kwargs({is_searchable: field})]));
                }
            };
            if (!process_composite.__argnames__) Object.defineProperties(process_composite, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_authors(field, fm, name, val) {
                ρσ_interpolate_kwargs.call(this, add_row, [field, name, val].concat([ρσ_desugar_kwargs({is_searchable: field, join: " & "})]));
            };
            if (!process_authors.__argnames__) Object.defineProperties(process_authors, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_publisher(field, fm, name, val) {
                ρσ_interpolate_kwargs.call(this, add_row, [field, name, val].concat([ρσ_desugar_kwargs({is_searchable: field})]));
            };
            if (!process_publisher.__argnames__) Object.defineProperties(process_publisher, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_formats(field, fm, name, val) {
                var td, fmt;
                if (val.length && (typeof book_id !== "undefined" && book_id !== null)) {
                    table.appendChild(E.tr(E.td(name), E.td()));
                    td = table.lastChild.lastChild;
                    var ρσ_Iter6 = ρσ_Iterable(val);
                    for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                        fmt = ρσ_Iter6[ρσ_Index6];
                        fmt = fmt.toUpperCase();
                        td.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [fmt].concat([ρσ_desugar_kwargs({class_: "blue-link", href: "javascript:void(0)", title: _("Read or download this book in the {} format").format(fmt), onclick: on_fmt_click.bind([mi.title, mi.format_sizes[fmt] || 0]), data_format: fmt, data_book_id: "" + book_id})])));
                        if (fmt !== val[val.length-1]) {
                            td.appendChild(document.createTextNode(", "));
                        }
                    }
                }
            };
            if (!process_formats.__argnames__) Object.defineProperties(process_formats, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_rating(field, fm, name, val) {
                var stars;
                stars = E.span();
                val = int(val || 0);
                if (val > 0) {
                    add_stars_to(stars, val, ρσ_exists.d(fm.display).allow_half_stars);
                    ρσ_interpolate_kwargs.call(this, add_row, [field, name, stars].concat([ρσ_desugar_kwargs({is_searchable: field, search_text: val / 2 + ""})]));
                }
            };
            if (!process_rating.__argnames__) Object.defineProperties(process_rating, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_identifiers(field, fm, name, val) {
                var td, label, ρσ_unpack, _, id_name, id_value, url;
                function ids_sorter(x) {
                    return (x[1] || "").toLowerCase();
                };
                if (!ids_sorter.__argnames__) Object.defineProperties(ids_sorter, {
                    __argnames__ : {value: ["x"]},
                    __module__ : {value: "book_list.book_details"}
                });

                if (val && mi.urls_from_identifiers && mi.urls_from_identifiers.length > 0) {
                    td = E.td();
                    var ρσ_Iter7 = ρσ_Iterable(ρσ_interpolate_kwargs.call(this, sorted, [mi.urls_from_identifiers || []].concat([ρσ_desugar_kwargs({key: ids_sorter})])));
                    for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                        ρσ_unpack = ρσ_flatten(ρσ_Iter7[ρσ_Index7]);
                        _ = ρσ_unpack[0];
                        id_name = ρσ_unpack[1];
                        id_value = ρσ_unpack[2];
                        url = ρσ_unpack[3];
                        if (td.childNodes.length) {
                            td.appendChild(document.createTextNode(", "));
                        }
                        label = "{}:{}".format(id_name || "", id_value || "");
                        td.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [label].concat([ρσ_desugar_kwargs({class_: "blue-link", title: label, target: "_new", href: url})])));
                    }
                    if (td.childNodes.length) {
                        table.appendChild(E.tr(E.td(name), td));
                    }
                }
            };
            if (!process_identifiers.__argnames__) Object.defineProperties(process_identifiers, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_size(field, fm, name, val) {
                if (val) {
                    try {
                        add_row(field, name, human_readable(int(val)));
                    } catch (ρσ_Exception) {
                        ρσ_last_exception = ρσ_Exception;
                        {
                            add_row(field, name, val + "");
                        } 
                    }
                }
            };
            if (!process_size.__argnames__) Object.defineProperties(process_size, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_languages(field, fm, name, val) {
                var td, lang, k;
                if (val && val.length) {
                    table.appendChild(E.tr(E.td(name), E.td()));
                    td = table.lastChild.lastChild;
                    var ρσ_Iter8 = ρσ_Iterable(val);
                    for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                        k = ρσ_Iter8[ρσ_Index8];
                        if (mi.lang_names) {
                            lang = (ρσ_expr_temp = mi.lang_names)[(typeof k === "number" && k < 0) ? ρσ_expr_temp.length + k : k] || k;
                        } else {
                            lang = k;
                        }
                        td.appendChild(ρσ_interpolate_kwargs.call(E, E.a, [lang].concat([ρσ_desugar_kwargs({class_: "blue-link", title: _("Click to see books with language: {}").format(lang), href: href_for_search(field, k)})])));
                        if (k !== val[val.length-1]) {
                            td.appendChild(document.createTextNode(", "));
                        }
                    }
                }
            };
            if (!process_languages.__argnames__) Object.defineProperties(process_languages, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_datetime(field, fm, name, val) {
                var fmt, formatted_val;
                if (val) {
                    fmt = interface_data[ρσ_bound_index("gui_" + field + "_display_format", interface_data)] || (fm["display"] || Object.create(null)).date_format;
                    formatted_val = format_date(val, fmt);
                    if (formatted_val) {
                        ρσ_interpolate_kwargs.call(this, add_row, [field, name, formatted_val].concat([ρσ_desugar_kwargs({is_searchable: field, search_text: val})]));
                    }
                }
            };
            if (!process_datetime.__argnames__) Object.defineProperties(process_datetime, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_series(field, fm, name, val) {
                var ifield, ival, s, a;
                if (val) {
                    ifield = field + "_index";
                    try {
                        ival = float(mi[(typeof ifield === "number" && ifield < 0) ? mi.length + ifield : ifield]);
                    } catch (ρσ_Exception) {
                        ρσ_last_exception = ρσ_Exception;
                        if (ρσ_Exception instanceof Error) {
                            ival = 1;
                        } else {
                            throw ρσ_Exception;
                        }
                    }
                    ival = ρσ_interpolate_kwargs.call(this, fmt_sidx, [ival].concat([ρσ_desugar_kwargs({use_roman: interface_data.use_roman_numerals_for_series_number})]));
                    table.appendChild(E.tr(E.td(name), E.td()));
                    s = safe_set_inner_html(E.span(), _("{0} of <a>{1}</a>").format(ival, val));
                    a = s.getElementsByTagName("a");
                    if (a && a.length) {
                        a = a[0];
                        a.setAttribute("href", href_for_search(field, val));
                        a.setAttribute("title", _("Click to see books with {0}: {1}").format(name, val));
                        a.setAttribute("class", "blue-link");
                    } else {
                        print("WARNING: Translation of series template is incorrect as it does not have an <a> tag");
                    }
                    table.lastChild.lastChild.appendChild(s);
                    add_note_link(field, name, val, table.lastChild.lastChild);
                }
            };
            if (!process_series.__argnames__) Object.defineProperties(process_series, {
                __argnames__ : {value: ["field", "fm", "name", "val"]},
                __module__ : {value: "book_list.book_details"}
            });

            function process_field(field, fm) {
                var name, datatype, val, ias, hp, func, join, v, fmt, formatted_val;
                name = fm.name || field;
                datatype = fm.datatype;
                val = mi[(typeof field === "number" && field < 0) ? mi.length + field : field];
                if (field === "comments" || datatype === "comments" || ρσ_exists.d(fm.display).composite_show_in_comments) {
                    if (!val) {
                        return;
                    }
                    ias = ρσ_exists.d(fm.display).interpret_as || "html";
                    hp = ρσ_exists.d(fm.display).heading_position || "hide";
                    if (ias === "long-text") {
                        if (hp === "side") {
                            add_row(field, name, val).style.whiteSpace = "pre-wrap";
                            return;
                        }
                        val = ρσ_interpolate_kwargs.call(E, E.pre, [val].concat([ρσ_desugar_kwargs({style: "white-space:pre-wrap"})])).outerHTML;
                    } else if (ias === "short-text") {
                        if (hp === "side") {
                            add_row(field, name, val);
                            return;
                        }
                        val = E.span(val).outerHTML;
                    } else {
                        if (field === "comments" && !ρσ_in("<", val)) {
                            val = "\n".join((function() {
                                var ρσ_Iter = ρσ_Iterable(val.split("\n\n")), ρσ_Result = [], x;
                                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                                    x = ρσ_Iter[ρσ_Index];
                                    ρσ_Result.push("<p class=\"description\">{}</p>".format(x.replace(/\n/g, "<br>")));
                                }
                                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                                return ρσ_Result;
                            })());
                        }
                    }
                    if (hp === "side") {
                        ρσ_interpolate_kwargs.call(this, add_row, [field, name, val].concat([ρσ_desugar_kwargs({is_html: true})]));
                        return;
                    }
                    comments.push([field, val]);
                    return;
                }
                func = null;
                if (datatype === "composite") {
                    func = process_composite;
                } else if (field === "formats") {
                    func = process_formats;
                } else if (datatype === "rating") {
                    func = process_rating;
                } else if (field === "identifiers") {
                    func = process_identifiers;
                } else if (field === "authors") {
                    func = process_authors;
                } else if (field === "publisher") {
                    func = process_publisher;
                } else if (field === "languages") {
                    func = process_languages;
                } else if (field === "size") {
                    func = process_size;
                } else if (datatype === "datetime") {
                    func = process_datetime;
                } else if (datatype === "series") {
                    func = process_series;
                }
                if (func) {
                    func(field, fm, name, val);
                } else {
                    if (datatype === "text" || datatype === "enumeration") {
                        if (val !== undefined && val !== null) {
                            join = (fm.is_multiple) ? fm.is_multiple.list_to_ui : null;
                            ρσ_interpolate_kwargs.call(this, add_row, [field, name, val].concat([ρσ_desugar_kwargs({join: join, is_searchable: field})]));
                        }
                    } else if (datatype === "bool") {
                        if (library_data.bools_are_tristate) {
                            v = (val) ? _("Yes") : (val === undefined || val === null) ? "" : _("No");
                        } else {
                            v = (val) ? _("Yes") : _("No");
                        }
                        if (v) {
                            ρσ_interpolate_kwargs.call(this, add_row, [field, name, v].concat([ρσ_desugar_kwargs({is_searchable: field, use_quotes: false})]));
                        }
                    } else if (datatype === "int" || datatype === "float") {
                        if (val !== undefined && val !== null) {
                            fmt = (fm.display || Object.create(null)).number_format;
                            if (fmt) {
                                formatted_val = fmt.format(val);
                                if (formatted_val) {
                                    val += "";
                                    ρσ_interpolate_kwargs.call(this, add_row, [field, name, formatted_val].concat([ρσ_desugar_kwargs({is_searchable: field, search_text: val})]));
                                }
                            } else {
                                val += "";
                                ρσ_interpolate_kwargs.call(this, add_row, [field, name, val].concat([ρσ_desugar_kwargs({is_searchable: field, search_text: val})]));
                            }
                        }
                    }
                }
            };
            if (!process_field.__argnames__) Object.defineProperties(process_field, {
                __argnames__ : {value: ["field", "fm"]},
                __module__ : {value: "book_list.book_details"}
            });

            var ρσ_Iter9 = ρσ_Iterable(fields);
            for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                field = ρσ_Iter9[ρσ_Index9];
                fm = field_metadata[(typeof field === "number" && field < 0) ? field_metadata.length + field : field];
                if (!fm) {
                    continue;
                }
                try {
                    process_field(field, fm);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        print("Failed to render metadata field: " + field);
                        traceback.print_exc();
                    } else {
                        throw ρσ_Exception;
                    }
                }
            }
            all_html = "";
            var ρσ_Iter10 = ρσ_Iterable(comments);
            for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                ρσ_unpack = ρσ_Iter10[ρσ_Index10];
                field = ρσ_unpack[0];
                comment = ρσ_unpack[1];
                if (comment) {
                    fm = field_metadata[(typeof field === "number" && field < 0) ? field_metadata.length + field : field];
                    if (ρσ_exists.d(fm.display).heading_position === "above") {
                        name = fm.name || field;
                        all_html += "<h3>" + ρσ_str.format("{}", name) + "</h3>";
                    }
                    all_html += comment;
                }
            }
            iframe = adjusting_sandboxed_html(replace_calibre_links_to_books(all_html), iframe_css);
            iframe.style.marginTop = "2ex";
            table.parentNode.appendChild(iframe);
        };
        if (!render_metadata.__argnames__) Object.defineProperties(render_metadata, {
            __argnames__ : {value: ["mi", "table", "book_id", "iframe_css"]},
            __module__ : {value: "book_list.book_details"}
        });

        function basic_table_rules(sel) {
            var style;
            style = "";
            style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "table.metadata td"].concat([ρσ_desugar_kwargs({vertical_align: "top"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "table.metadata td:first-of-type"].concat([ρσ_desugar_kwargs({font_style: "normal", font_weight: "700", color: "var(--calibre-color-faded-text)", padding_right: "0.5em", white_space: "nowrap", text_align: "right"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + "table.metadata td:last-of-type"].concat([ρσ_desugar_kwargs({overflow_wrap: "anywhere", word_break: "break-word"})]));
            return style;
        };
        if (!basic_table_rules.__argnames__) Object.defineProperties(basic_table_rules, {
            __argnames__ : {value: ["sel"]},
            __module__ : {value: "book_list.book_details"}
        });

        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, style;
                sel = "." + CLASS_NAME + " ";
                style = basic_table_rules(sel);
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " .next-book-button:hover"].concat([ρσ_desugar_kwargs({transform: "scale(1.5)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-wrap"].concat([ρσ_desugar_kwargs({padding: "1rem", max_width: "1100px", margin_left: "auto", margin_right: "auto"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-initial-loading"].concat([ρσ_desugar_kwargs({min_height: "min(70vh, 720px)", display: "flex", align_items: "center", justify_content: "center"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-initial-loading-card"].concat([ρσ_desugar_kwargs({width: "min(820px, 100%)", padding: "1.1rem 1.1rem", border: "var(--calibre-border-style-subtle)", border_radius: "18px", background_color: "rgba(0,0,0,0.02)", box_shadow: "0 10px 30px rgba(0,0,0,0.06)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-initial-loading-row"].concat([ρσ_desugar_kwargs({display: "flex", align_items: "center", justify_content: "center", gap: "0.6rem", opacity: "0.9", font_weight: "700"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-initial-loading-sub"].concat([ρσ_desugar_kwargs({margin_top: "0.55rem", text_align: "center", opacity: "0.65"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-hero"].concat([ρσ_desugar_kwargs({display: "grid", grid_template_columns: "220px 1fr", gap: "1.25rem", align_items: "start", padding: "1rem", border: "var(--calibre-border-style-subtle)", border_radius: "18px", background_color: "rgba(0,0,0,0.02)", box_shadow: "0 10px 30px rgba(0,0,0,0.06)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-cover"].concat([ρσ_desugar_kwargs({position: "relative", width: "220px"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-cover img"].concat([ρσ_desugar_kwargs({width: "100%", height: "auto", display: "block", border_radius: "18px", box_shadow: "0 18px 48px rgba(0,0,0,0.18)", border: "var(--calibre-border-style-subtle)"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-nav"].concat([ρσ_desugar_kwargs({margin_top: "1rem", display: "flex", justify_content: "space-between", gap: "0.75rem"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-nav a.calibre-push-button"].concat([ρσ_desugar_kwargs({flex: "1 1 0", display: "inline-flex", align_items: "center", justify_content: "center", gap: "0.4rem"})]));
                style += "\n@media (max-width: 720px) {\n  .book-details-panel .cs-bd-nav { gap: 0.6rem; }\n  .book-details-panel .cs-bd-nav a.calibre-push-button { justify-content: center; }\n}\n";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-info"].concat([ρσ_desugar_kwargs({min_width: "0"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-title"].concat([ρσ_desugar_kwargs({font_size: "1.45em", font_weight: "800", line_height: "1.2", margin_bottom: "0.35rem"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-authors"].concat([ρσ_desugar_kwargs({opacity: "0.85", font_size: "1.05em", margin_bottom: "0.75rem", overflow: "hidden", text_overflow: "ellipsis"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-meta"].concat([ρσ_desugar_kwargs({display: "flex", flex_wrap: "wrap", gap: "0.35rem 0.6rem", margin_bottom: "0.9rem", opacity: "0.9"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-badge"].concat([ρσ_desugar_kwargs({display: "inline-flex", align_items: "center", gap: "0.25rem", padding: "0.15rem 0.45rem", border_radius: "999px", border: "var(--calibre-border-style-subtle)", background: "rgba(0,0,0,0.02)", max_width: "100%", white_space: "nowrap", overflow: "hidden", text_overflow: "ellipsis"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-actions"].concat([ρσ_desugar_kwargs({display: "flex", flex_wrap: "wrap", gap: "0.5rem", margin_top: "0.2rem"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-details"].concat([ρσ_desugar_kwargs({margin_top: "1rem", padding: "1rem", border: "var(--calibre-border-style-subtle)", border_radius: "18px", background_color: get_color("window-background"), box_shadow: "0 1px 2px rgba(0,0,0,0.06)", min_width: "0", max_width: "100%", box_sizing: "border-box", overflow_x: "hidden", overflow_wrap: "break-word", word_break: "break-word", text_align: "left"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-details table.metadata"].concat([ρσ_desugar_kwargs({width: "100%", max_width: "100%", table_layout: "fixed", box_sizing: "border-box"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-details table.metadata td:first-of-type"].concat([ρσ_desugar_kwargs({text_align: "left"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-details pre"].concat([ρσ_desugar_kwargs({white_space: "pre-wrap", word_break: "break-word", max_width: "100%", overflow_x: "auto"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".cs-bd-details code"].concat([ρσ_desugar_kwargs({word_break: "break-word", overflow_wrap: "anywhere"})]));
                style += "\n@media (max-width: 720px) {\n  .book-details-panel .cs-bd-wrap { padding: 0.75rem; min-width: 0; }\n  .book-details-panel .cs-bd-hero { grid-template-columns: 1fr; min-width: 0; }\n  .book-details-panel .cs-bd-cover { width: min(320px, 100%); margin-left: auto; margin-right: auto; }\n  .book-details-panel .cs-bd-title { font-size: 1.25em; }\n  .book-details-panel .cs-bd-details { padding: 0.75rem; }\n  .book-details-panel .cs-bd-details table.metadata td {\n    white-space: normal;\n    word-break: break-word;\n    overflow-wrap: anywhere;\n  }\n  .book-details-panel .cs-bd-details table.metadata td:first-of-type {\n    white-space: normal;\n    text-align: left;\n    padding-right: 0.35rem;\n  }\n}\n";
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + CLASS_NAME + " .cs-bd-loading-wrap"].concat([ρσ_desugar_kwargs({position: "relative"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + CLASS_NAME + " .cs-bd-loading-overlay"].concat([ρσ_desugar_kwargs({position: "absolute", left: "0", top: "0", right: "0", bottom: "0", display: "flex", align_items: "center", justify_content: "center", background_color: "rgba(255,255,255,0.55)", opacity: "0", pointer_events: "none", transition: "opacity 160ms ease"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + CLASS_NAME + " .cs-bd-loading .cs-bd-loading-overlay"].concat([ρσ_desugar_kwargs({opacity: "1"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + CLASS_NAME + " .cs-bd-loading .cs-bd-loading-content"].concat([ρσ_desugar_kwargs({opacity: "0.45", transition: "opacity 160ms ease"})]));
                style += "\n@keyframes cs_spin_bd { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }\n.book-details-panel .cs-bd-loading-overlay svg { animation: cs_spin_bd 1.2s linear infinite; opacity: 0.85; }\n";
                sel = "." + SEARCH_INTERNET_CLASS;
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({margin: "1ex 1em"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " ul > li"].concat([ρσ_desugar_kwargs({list_style_type: "none"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " ul > li > a"].concat([ρσ_desugar_kwargs({padding: "2ex 1em", display: "block", width: "100%"})]));
                sel = "." + COPY_TO_LIBRARY_CLASS;
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({margin: "1ex 1em"})]));
                sel = "." + DATA_FILES_CLASS;
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({margin: "1ex 1em"})]));
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "book_list.book_details"}
            });
            return ρσ_anonfunc;
        })());
        current_fetch = null;
        function no_book(container) {
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("No book found")].concat([ρσ_desugar_kwargs({style: "margin: 1ex 1em"})])));
        };
        if (!no_book.__argnames__) Object.defineProperties(no_book, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.book_details"}
        });

        function on_img_err(err) {
            var img;
            img = err.target;
            if (img.parentNode) {
                img.parentNode.style.display = "none";
            }
        };
        if (!on_img_err.__argnames__) Object.defineProperties(on_img_err, {
            __argnames__ : {value: ["err"]},
            __module__ : {value: "book_list.book_details"}
        });

        function preferred_format(book_id, for_download) {
            var interface_data;
            interface_data = get_interface_data();
            return get_preferred_format(book_metadata(book_id), interface_data.output_format, interface_data.input_formats, for_download);
        };
        if (!preferred_format.__argnames__) Object.defineProperties(preferred_format, {
            __argnames__ : {value: ["book_id", "for_download"]},
            __module__ : {value: "book_list.book_details"}
        });

        function read_format(book_id, fmt) {
            open_book(book_id, fmt);
        };
        if (!read_format.__argnames__) Object.defineProperties(read_format, {
            __argnames__ : {value: ["book_id", "fmt"]},
            __module__ : {value: "book_list.book_details"}
        });

        function read_book(book_id) {
            var fmt;
            fmt = preferred_format(book_id);
            if (fmt && fmt.lower() === "pdf") {
                window.open(download_url(book_id, fmt, "inline"), "_blank");
            } else {
                read_format(book_id, fmt);
            }
        };
        if (!read_book.__argnames__) Object.defineProperties(read_book, {
            __argnames__ : {value: ["book_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function download_format(book_id, fmt) {
            window.location = download_url(book_id, fmt);
        };
        if (!download_format.__argnames__) Object.defineProperties(download_format, {
            __argnames__ : {value: ["book_id", "fmt"]},
            __module__ : {value: "book_list.book_details"}
        });

        function download_book(book_id) {
            var fmt;
            fmt = preferred_format(book_id, true);
            download_format(book_id, fmt);
        };
        if (!download_book.__argnames__) Object.defineProperties(download_book, {
            __argnames__ : {value: ["book_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function next_book(book_id, delta) {
            var next_book_id, q;
            next_book_id = book_after(book_id, delta);
            if (next_book_id) {
                q = parse_url_params();
                q.book_id = next_book_id + "";
                ρσ_interpolate_kwargs.call(this, show_panel, ["book_details"].concat([ρσ_desugar_kwargs({query: q, replace: true})]));
            }
        };
        if (!next_book.__argnames__) Object.defineProperties(next_book, {
            __argnames__ : {value: ["book_id", "delta"]},
            __module__ : {value: "book_list.book_details"}
        });

        function render_book(container_id, book_id) {
            var is_random, c, metadata, authors, alt, imgdiv, img, wrap, hero, info, meta, stars, ival, actions, read_button, fmt, download_button, row, row2, details, md, table, prev_btn, next_btn, nav;
            render_book.book_id = book_id;
            render_book.container_id = container_id;
            is_random = parse_url_params().book_id === "0";
            c = document.getElementById(container_id);
            if (!c) {
                return;
            }
            install_touch_handlers(c, book_id);
            metadata = book_metadata(book_id);
            render_book.title = metadata.title;
            set_title(c, metadata.title);
            authors = (metadata.authors) ? metadata.authors.join(" & ") : _("Unknown");
            alt = _("{} by {}\n\nClick to read").format(metadata.title, authors);
            if (is_random) {
            }
            imgdiv = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.img, [ρσ_desugar_kwargs({alt: alt, title: alt, data_title: metadata.title, data_authors: authors, onclick: read_book.bind(null, book_id), style: "cursor: pointer;"})])].concat([ρσ_desugar_kwargs({class_: "cs-bd-cover"})]));
            img = imgdiv.getElementsByTagName("img")[0];
            img.onerror = on_img_err;
            img.src = cover_url(book_id);
            c = c.lastChild;
            wrap = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-bd-wrap"})]);
            c.appendChild(wrap);
            hero = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-bd-hero"})]);
            wrap.appendChild(hero);
            hero.appendChild(imgdiv);
            info = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-bd-info", data_book_id: "" + book_id})]);
            hero.appendChild(info);
            info.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [metadata.title || _("Unknown")].concat([ρσ_desugar_kwargs({class_: "cs-bd-title"})])));
            info.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [authors].concat([ρσ_desugar_kwargs({class_: "cs-bd-authors"})])));
            meta = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-bd-meta"})]);
            info.appendChild(meta);
            function add_badge() {
                var icon = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
                var text = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
                var title = (arguments[2] === undefined || ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? add_badge.__defaults__.title : arguments[2];
                var ρσ_kwargs_obj = arguments[arguments.length-1];
                if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "title")){
                    title = ρσ_kwargs_obj.title;
                }
                var b;
                if (!text) {
                    return;
                }
                b = ρσ_interpolate_kwargs.call(E, E.span, [ρσ_desugar_kwargs({class_: "cs-bd-badge"})]);
                if (icon) {
                    b.appendChild(svgicon(icon));
                }
                b.appendChild(E.span(text));
                if (title) {
                    b.title = title;
                }
                meta.appendChild(b);
            };
            if (!add_badge.__defaults__) Object.defineProperties(add_badge, {
                __defaults__ : {value: {title:null}},
                __handles_kwarg_interpolation__ : {value: true},
                __argnames__ : {value: ["icon", "text", "title"]},
                __module__ : {value: "book_list.book_details"}
            });

            if (metadata.rating) {
                stars = ρσ_interpolate_kwargs.call(E, E.span, [ρσ_desugar_kwargs({style: "white-space:nowrap"})]);
                add_stars_to(stars, int(metadata.rating || 0), true);
                add_badge(null, stars, _("Rating"));
            }
            if (metadata.series) {
                try {
                    ival = float(metadata.series_index);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        ival = 1;
                    } else {
                        throw ρσ_Exception;
                    }
                }
                ival = ρσ_interpolate_kwargs.call(this, fmt_sidx, [ival].concat([ρσ_desugar_kwargs({use_roman: get_interface_data().use_roman_numerals_for_series_number})]));
                add_badge("bookmark", _("{0} of {1}").format(ival, metadata.series), _("Series"));
            }
            if (metadata.publisher) {
                add_badge("library", metadata.publisher, _("Publisher"));
            }
            if (metadata.pubdate) {
                try {
                    add_badge("date", format_date(metadata.pubdate, "yyyy-MM-dd"), _("Published"));
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                    } else {
                        throw ρσ_Exception;
                    }
                }
            }
            if (metadata.formats && metadata.formats.length) {
                add_badge("book", metadata.formats.slice(0, 4).join(" · "), _("Formats"));
            }
            actions = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-bd-actions"})]);
            info.appendChild(actions);
            read_button = create_button(_("Read"), "book", read_book.bind(null, book_id), _("Read this book [V]"));
            fmt = preferred_format(book_id, true);
            download_button = ρσ_interpolate_kwargs.call(this, create_button, [_("Download"), "cloud-download", download_url(book_id, fmt), _("Download this book in the {0} format ({1})").format(fmt, human_readable((ρσ_expr_temp = metadata.format_sizes)[(typeof fmt === "number" && fmt < 0) ? ρσ_expr_temp.length + fmt : fmt] || 0))].concat([ρσ_desugar_kwargs({download_filename: "" + ρσ_str.format("{}", metadata.title) + "." + ρσ_str.format("{}", fmt.toLowerCase()) + ""})]));
            row = E.div(read_button, download_button);
            row.classList.add("cs-bd-actions");
            if (!metadata.formats || !metadata.formats.length) {
                row.style.display = "none";
            }
            actions.appendChild(row);
            function show_more_actions_modal() {
                var ev = (arguments[0] === undefined || ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_more_actions_modal.__defaults__.ev : arguments[0];
                var ρσ_kwargs_obj = arguments[arguments.length-1];
                if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
                if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "ev")){
                    ev = ρσ_kwargs_obj.ev;
                }
                create_custom_dialog(_("More actions…"), (function() {
                    var ρσ_anonfunc = function (parent, close_modal) {
                        var ρσ_unpack, title, subtitle, items, wrapper;
                        if (get_session_data().get("show_all_metadata")) {
                            ρσ_unpack = [_("Show important metadata"), _("Show only the important metadata fields in the book details")];
                            title = ρσ_unpack[0];
                            subtitle = ρσ_unpack[1];
                        } else {
                            ρσ_unpack = [_("Show all metadata"), _("Show all metadata fields in the book details")];
                            title = ρσ_unpack[0];
                            subtitle = ρσ_unpack[1];
                        }
                        items = ρσ_list_decorate([ ρσ_interpolate_kwargs.call(this, create_item, [_("Search the internet")].concat([ρσ_desugar_kwargs({subtitle: _("Search for this author or book on various websites"), action: (function() {
                            var ρσ_anonfunc = function () {
                                close_modal();
                                ρσ_interpolate_kwargs.call(this, show_subsequent_panel, ["search_internet"].concat([ρσ_desugar_kwargs({replace: true})]));
                            };
                            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                __module__ : {value: "book_list.book_details"}
                            });
                            return ρσ_anonfunc;
                        })()})])), ρσ_interpolate_kwargs.call(this, create_item, [title].concat([ρσ_desugar_kwargs({subtitle: subtitle, action: (function() {
                            var ρσ_anonfunc = function () {
                                close_modal();
                                toggle_fields();
                            };
                            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                __module__ : {value: "book_list.book_details"}
                            });
                            return ρσ_anonfunc;
                        })()})])), ρσ_interpolate_kwargs.call(this, create_item, [_("Copy to library")].concat([ρσ_desugar_kwargs({subtitle: _("Copy or move this book to another calibre library"), action: (function() {
                            var ρσ_anonfunc = function () {
                                close_modal();
                                ρσ_interpolate_kwargs.call(this, show_subsequent_panel, ["copy_to_library"].concat([ρσ_desugar_kwargs({replace: true})]));
                            };
                            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                __module__ : {value: "book_list.book_details"}
                            });
                            return ρσ_anonfunc;
                        })()})])), ρσ_interpolate_kwargs.call(this, create_item, [_("Manage data files")].concat([ρσ_desugar_kwargs({subtitle: _("Upload or download additional data files to this book"), action: (function() {
                            var ρσ_anonfunc = function () {
                                close_modal();
                                ρσ_interpolate_kwargs.call(this, show_subsequent_panel, ["data_files"].concat([ρσ_desugar_kwargs({replace: true})]));
                            };
                            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                __module__ : {value: "book_list.book_details"}
                            });
                            return ρσ_anonfunc;
                        })()})])) ]);
                        wrapper = E.div();
                        parent.appendChild(wrapper);
                        create_item_list(wrapper, items);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["parent", "close_modal"]},
                        __module__ : {value: "book_list.book_details"}
                    });
                    return ρσ_anonfunc;
                })());
            };
            if (!show_more_actions_modal.__defaults__) Object.defineProperties(show_more_actions_modal, {
                __defaults__ : {value: {ev:null}},
                __handles_kwarg_interpolation__ : {value: true},
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            row2 = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "flex-basis: 100%; width: 100%;"})]);
            row2.classList.add("cs-bd-actions");
            function on_convert(ev) {
                convert_book();
            };
            if (!on_convert.__argnames__) Object.defineProperties(on_convert, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            function on_edit(ev) {
                edit_metadata();
            };
            if (!on_edit.__argnames__) Object.defineProperties(on_edit, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            function on_delete(ev) {
                delete_book();
            };
            if (!on_delete.__argnames__) Object.defineProperties(on_delete, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            function on_more(ev) {
                show_more_actions_modal(ev);
            };
            if (!on_more.__argnames__) Object.defineProperties(on_more, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            row2.appendChild(create_button(_("Convert"), "convert", on_convert, _("Convert this book to another format [C]")));
            row2.appendChild(create_button(_("Edit"), "edit", on_edit, _("Edit the metadata for this book [E]")));
            row2.appendChild(create_button(_("Delete"), "trash", on_delete, _("Delete this book")));
            row2.appendChild(create_button("", "ellipsis-v", on_more, _("More actions")));
            actions.appendChild(row2);
            details = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-bd-details"})]);
            wrap.appendChild(details);
            md = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-bottom: 0"})]);
            table = ρσ_interpolate_kwargs.call(E, E.table, [ρσ_desugar_kwargs({class_: "metadata"})]);
            details.appendChild(md);
            md.appendChild(table);
            render_metadata(metadata, table, book_id);
            function make_nav_button(is_prev) {
                var delta, nbid, ans;
                delta = (is_prev) ? -1 : 1;
                nbid = book_after(book_id, delta);
                if (!nbid || nbid === book_id || is_random) {
                    return null;
                }
                ans = create_button((is_prev) ? _("Previous") : _("Next"), (is_prev) ? "chevron-left" : "chevron-right", next_book.bind(null, book_id, delta), (is_prev) ? _("Previous book [Ctrl+Left]") : _("Next book [Ctrl+Right]"));
                if (!is_prev) {
                    ans.insertBefore(ans.firstChild.nextSibling, ans.firstChild);
                }
                ans.style.justifyContent = (is_prev) ? "start" : "end";
                return ans;
            };
            if (!make_nav_button.__argnames__) Object.defineProperties(make_nav_button, {
                __argnames__ : {value: ["is_prev"]},
                __module__ : {value: "book_list.book_details"}
            });

            prev_btn = make_nav_button(true);
            next_btn = make_nav_button(false);
            if (prev_btn || next_btn) {
                nav = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-bd-nav"})]);
                nav.appendChild(prev_btn || E.span());
                nav.appendChild(next_btn || E.span());
                wrap.appendChild(nav);
            }
        };
        if (!render_book.__argnames__) Object.defineProperties(render_book, {
            __argnames__ : {value: ["container_id", "book_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function add_top_bar_buttons(container_id) {
            var container;
            container = document.getElementById(container_id);
            if (container) {
                clear_buttons(container);
            }
        };
        if (!add_top_bar_buttons.__argnames__) Object.defineProperties(add_top_bar_buttons, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function proceed_after_succesful_fetch_metadata(container_id, book_id) {
            render_book(container_id, book_id);
            add_top_bar_buttons(container_id);
        };
        if (!proceed_after_succesful_fetch_metadata.__argnames__) Object.defineProperties(proceed_after_succesful_fetch_metadata, {
            __argnames__ : {value: ["container_id", "book_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function metadata_fetched(container_id, book_id, proceed, end_type, xhr, event) {
            var c, overlay, content, data;
            if (current_fetch === null || current_fetch !== xhr) {
                return;
            }
            current_fetch = null;
            c = document.getElementById(container_id);
            if (!c) {
                return;
            }
            c = c.lastChild;
            try {
                c.classList.remove("cs-bd-loading");
                c.classList.remove("cs-bd-loading-wrap");
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                } else {
                    throw ρσ_Exception;
                }
            }
            try {
                overlay = c.querySelector(".cs-bd-loading-overlay");
                if (overlay && overlay.parentNode) {
                    overlay.parentNode.removeChild(overlay);
                }
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                } else {
                    throw ρσ_Exception;
                }
            }
            try {
                content = c.querySelector(".cs-bd-loading-content");
                if (content && content.parentNode) {
                    while (content.firstChild) {
                        c.insertBefore(content.firstChild, content);
                    }
                    content.parentNode.removeChild(content);
                }
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                } else {
                    throw ρσ_Exception;
                }
            }
            if (end_type === "load") {
                try {
                    data = JSON.parse(xhr.responseText);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        var err = ρσ_Exception;
                        error_dialog(_("Could not fetch metadata for book"), _("Server returned an invalid response"), err.toString());
                        return;
                    } else {
                        throw ρσ_Exception;
                    }
                }
                clear(c);
                book_id = int(data["id"]);
                set_book_metadata(book_id, data);
                proceed(container_id, book_id);
            } else if (end_type !== "abort") {
                clear(c);
                c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Could not fetch metadata for book"), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin: 1ex 1em"})])].concat([ρσ_desugar_kwargs({style: "margin: 1ex 1em"})])));
                safe_set_inner_html(c.lastChild.lastChild, xhr.error_html);
            }
        };
        if (!metadata_fetched.__argnames__) Object.defineProperties(metadata_fetched, {
            __argnames__ : {value: ["container_id", "book_id", "proceed", "end_type", "xhr", "event"]},
            __module__ : {value: "book_list.book_details"}
        });

        function fetch_metadata(container_id, book_id, proceed) {
            var container, body, content, overlay, wrap, card;
            container = document.getElementById(container_id);
            if (!container) {
                return;
            }
            if (current_fetch) {
                current_fetch.abort();
            }
            current_fetch = ρσ_interpolate_kwargs.call(this, ajax, ["interface-data/book-metadata/" + book_id, metadata_fetched.bind(null, container_id, book_id, proceed)].concat([ρσ_desugar_kwargs({query: (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["library_id"] = current_library_id();
                ρσ_d["vl"] = current_virtual_library();
                return ρσ_d;
            }).call(this)})]));
            current_fetch.send();
            body = container.lastChild;
            if (body && body.firstChild) {
                body.classList.add("cs-bd-loading-wrap");
                body.classList.add("cs-bd-loading");
                content = body.querySelector(".cs-bd-loading-content");
                if (!content) {
                    content = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-bd-loading-content"})]);
                    while (body.firstChild) {
                        content.appendChild(body.firstChild);
                    }
                    body.appendChild(content);
                }
                overlay = body.querySelector(".cs-bd-loading-overlay");
                if (!overlay) {
                    overlay = ρσ_interpolate_kwargs.call(E, E.div, [svgicon("cog"), E.span(" " + _("Fetching metadata…"))].concat([ρσ_desugar_kwargs({class_: "cs-bd-loading-overlay"})]));
                    body.appendChild(overlay);
                }
            } else {
                clear(body);
                body.classList.add("cs-bd-loading-wrap");
                wrap = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-bd-wrap cs-bd-initial-loading"})]);
                card = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "cs-bd-initial-loading-card"})]);
                card.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_spinner(), E.span(_("Fetching metadata…"))].concat([ρσ_desugar_kwargs({class_: "cs-bd-initial-loading-row"})])));
                card.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Fetching metadata for the book, please wait") + "…"].concat([ρσ_desugar_kwargs({class_: "cs-bd-initial-loading-sub"})])));
                wrap.appendChild(card);
                body.appendChild(wrap);
            }
        };
        if (!fetch_metadata.__argnames__) Object.defineProperties(fetch_metadata, {
            __argnames__ : {value: ["container_id", "book_id", "proceed"]},
            __module__ : {value: "book_list.book_details"}
        });

        function install_touch_handlers(container, book_id) {
            var ongoing_touches, gesture_id, container_id;
            ongoing_touches = Object.create(null);
            gesture_id = 0;
            container_id = container.id;
            function has_active_touches() {
                var t, tid;
                var ρσ_Iter11 = ρσ_Iterable(ongoing_touches);
                for (var ρσ_Index11 = 0; ρσ_Index11 < ρσ_Iter11.length; ρσ_Index11++) {
                    tid = ρσ_Iter11[ρσ_Index11];
                    t = ongoing_touches[(typeof tid === "number" && tid < 0) ? ongoing_touches.length + tid : tid];
                    if (t.active) {
                        return true;
                    }
                }
                return false;
            };
            if (!has_active_touches.__module__) Object.defineProperties(has_active_touches, {
                __module__ : {value: "book_list.book_details"}
            });

            function handle_touch(ev) {
                var container, touch, t, touches, num, gesture, delta;
                container = document.getElementById(container_id);
                if (!container) {
                    return;
                }
                if (ev.type === "touchstart") {
                    var ρσ_Iter12 = ρσ_Iterable(ev.changedTouches);
                    for (var ρσ_Index12 = 0; ρσ_Index12 < ρσ_Iter12.length; ρσ_Index12++) {
                        touch = ρσ_Iter12[ρσ_Index12];
                        ongoing_touches[ρσ_bound_index(touch_id(touch), ongoing_touches)] = copy_touch(touch);
                        gesture_id += 1;
                    }
                } else if (ev.type === "touchmove") {
                    var ρσ_Iter13 = ρσ_Iterable(ev.changedTouches);
                    for (var ρσ_Index13 = 0; ρσ_Index13 < ρσ_Iter13.length; ρσ_Index13++) {
                        touch = ρσ_Iter13[ρσ_Index13];
                        t = ongoing_touches[ρσ_bound_index(touch_id(touch), ongoing_touches)];
                        if (t) {
                            update_touch(t, touch);
                        }
                    }
                } else if (ev.type === "touchcancel") {
                    var ρσ_Iter14 = ρσ_Iterable(ev.changedTouches);
                    for (var ρσ_Index14 = 0; ρσ_Index14 < ρσ_Iter14.length; ρσ_Index14++) {
                        touch = ρσ_Iter14[ρσ_Index14];
                        delete ongoing_touches[touch_id(touch)];
                    }
                } else if (ev.type === "touchend") {
                    var ρσ_Iter15 = ρσ_Iterable(ev.changedTouches);
                    for (var ρσ_Index15 = 0; ρσ_Index15 < ρσ_Iter15.length; ρσ_Index15++) {
                        touch = ρσ_Iter15[ρσ_Index15];
                        t = ongoing_touches[ρσ_bound_index(touch_id(touch), ongoing_touches)];
                        if (t) {
                            t.active = false;
                            update_touch(t, touch);
                            if (!has_active_touches()) {
                                touches = ongoing_touches;
                                ongoing_touches = Object.create(null);
                                num = len(touches);
                                if (num === 1) {
                                    gesture = interpret_single_gesture(touches[ρσ_bound_index(Object.keys(touches)[0], touches)], gesture_id);
                                    if (gesture.type === "swipe" && gesture.axis === "horizontal") {
                                        delta = (gesture.direction === "right") ? -1 : 1;
                                        next_book(book_id, delta);
                                    }
                                }
                            }
                        }
                    }
                }
            };
            if (!handle_touch.__argnames__) Object.defineProperties(handle_touch, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            install_handlers(container, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["handle_touchstart"] = handle_touch;
                ρσ_d["handle_touchmove"] = handle_touch;
                ρσ_d["handle_touchend"] = handle_touch;
                ρσ_d["handle_touchcancel"] = handle_touch;
                return ρσ_d;
            }).call(this), true);
        };
        if (!install_touch_handlers.__argnames__) Object.defineProperties(install_touch_handlers, {
            __argnames__ : {value: ["container", "book_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function create_book_details(container) {
            var q, current_book_id, container_id;
            q = parse_url_params();
            current_book_id = q.book_id;
            if (current_book_id === undefined || current_book_id === null) {
                no_book(container);
                return;
            }
            current_book_id = int(current_book_id);
            container_id = container.parentNode.id;
            if (current_book_id !== 0 && book_metadata(current_book_id)) {
                render_book(container_id, current_book_id);
                add_top_bar_buttons(container_id);
            } else {
                fetch_metadata(container_id, current_book_id, proceed_after_succesful_fetch_metadata);
            }
        };
        if (!create_book_details.__argnames__) Object.defineProperties(create_book_details, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.book_details"}
        });

        function report_load_failure(container) {
            report_a_load_failure(container, _("Failed to load books from calibre library, with error:"), load_status.error_html);
        };
        if (!report_load_failure.__argnames__) Object.defineProperties(report_load_failure, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "book_list.book_details"}
        });

        function check_for_books_loaded() {
            var container;
            container = this;
            if (load_status.loading) {
                conditional_timeout(container.id, 5, check_for_books_loaded);
                return;
            }
            container = container.lastChild;
            clear(container);
            if (!load_status.ok) {
                report_load_failure(container);
                return;
            }
            create_book_details(container);
        };
        if (!check_for_books_loaded.__module__) Object.defineProperties(check_for_books_loaded, {
            __module__ : {value: "book_list.book_details"}
        });

        function onkeydown(container_id, close_action, ev) {
            if (render_book.book_id) {
                if (ev.ctrlKey) {
                    if (ev.key === "ArrowLeft") {
                        next_book(render_book.book_id, -1);
                        [ev.preventDefault(), ev.stopPropagation()];
                    } else if (ev.key === "ArrowRight") {
                        next_book(render_book.book_id, 1);
                        [ev.preventDefault(), ev.stopPropagation()];
                    }
                } else if (!ev.ctrlKey && !ev.metaKey && !ev.shiftKey) {
                    if (ev.key === "Escape") {
                        [ev.preventDefault(), ev.stopPropagation()];
                        close_action();
                    } else if (ev.key === "Delete") {
                        [ev.preventDefault(), ev.stopPropagation()];
                        delete_book();
                    } else if (ev.key === "v" || ev.key === "V") {
                        read_book(render_book.book_id);
                    } else if (ev.key === "c" || ev.key === "C") {
                        convert_book();
                    } else if (ev.key === "e" || ev.key === "E") {
                        edit_metadata();
                    }
                }
            }
        };
        if (!onkeydown.__argnames__) Object.defineProperties(onkeydown, {
            __argnames__ : {value: ["container_id", "close_action", "ev"]},
            __module__ : {value: "book_list.book_details"}
        });

        function init(container_id) {
            var container, ρσ_unpack, close_action, close_icon, q, ca;
            container = document.getElementById(container_id);
            clear(container);
            ρσ_unpack = [back, "close"];
            close_action = ρσ_unpack[0];
            close_icon = ρσ_unpack[1];
            q = parse_url_params();
            ca = q.close_action;
            if (ca === "home") {
                ρσ_unpack = [(function() {
                    var ρσ_anonfunc = function () {
                        home();
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "book_list.book_details"}
                    });
                    return ρσ_anonfunc;
                })(), "home"];
                close_action = ρσ_unpack[0];
                close_icon = ρσ_unpack[1];
            } else if (ca === "book_list") {
                close_action = (function() {
                    var ρσ_anonfunc = function () {
                        show_panel("book_list", (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["book_id"] = q.book_id;
                            return ρσ_d;
                        }).call(this));
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "book_list.book_details"}
                    });
                    return ρσ_anonfunc;
                })();
            }
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: "", action: close_action, icon: close_icon})]));
            window.scrollTo(0, 0);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: CLASS_NAME, tabindex: "0"})]));
            container.lastChild.addEventListener("keydown", onkeydown.bind(null, container_id, close_action), (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                ρσ_d["capture"] = true;
                return ρσ_d;
            }).call(this));
            container.lastChild.focus();
            container.lastChild.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Loading books from the calibre library, please wait...")].concat([ρσ_desugar_kwargs({style: "margin: 1ex 1em"})])));
            conditional_timeout(container_id, 5, check_for_books_loaded);
        };
        if (!init.__argnames__) Object.defineProperties(init, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function show_subsequent_panel() {
            var name = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var replace = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_subsequent_panel.__defaults__.replace : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "replace")){
                replace = ρσ_kwargs_obj.replace;
            }
            var q;
            q = parse_url_params();
            q.book_id = (render_book.book_id || q.book_id) + "";
            ρσ_interpolate_kwargs.call(this, show_panel, ["book_details^" + name].concat([ρσ_desugar_kwargs({query: q, replace: replace})]));
        };
        if (!show_subsequent_panel.__defaults__) Object.defineProperties(show_subsequent_panel, {
            __defaults__ : {value: {replace:false}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["name", "replace"]},
            __module__ : {value: "book_list.book_details"}
        });

        function edit_metadata() {
            var q;
            q = parse_url_params();
            q.book_id = (render_book.book_id || q.book_id) + "";
            ρσ_interpolate_kwargs.call(this, show_panel, ["edit_metadata"].concat([ρσ_desugar_kwargs({query: q, replace: false})]));
        };
        if (!edit_metadata.__module__) Object.defineProperties(edit_metadata, {
            __module__ : {value: "book_list.book_details"}
        });

        function convert_book() {
            var q;
            q = parse_url_params();
            q.book_id = (render_book.book_id || q.book_id) + "";
            ρσ_interpolate_kwargs.call(this, show_panel, ["convert_book"].concat([ρσ_desugar_kwargs({query: q, replace: false})]));
        };
        if (!convert_book.__module__) Object.defineProperties(convert_book, {
            __module__ : {value: "book_list.book_details"}
        });

        function create_more_actions_panel(container_id) {
            var container, ρσ_unpack, title, subtitle, items;
            container = document.getElementById(container_id);
            clear(container);
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("More actions…"), icon: "back"})]));
            if (get_session_data().get("show_all_metadata")) {
                ρσ_unpack = [_("Show important metadata"), _("Show only the important metadata fields in the book details")];
                title = ρσ_unpack[0];
                subtitle = ρσ_unpack[1];
            } else {
                ρσ_unpack = [_("Show all metadata"), _("Show all metadata fields in the book details")];
                title = ρσ_unpack[0];
                subtitle = ρσ_unpack[1];
            }
            items = ρσ_list_decorate([ ρσ_interpolate_kwargs.call(this, create_item, [_("Search the internet")].concat([ρσ_desugar_kwargs({subtitle: _("Search for this author or book on various websites"), action: (function() {
                var ρσ_anonfunc = function () {
                    ρσ_interpolate_kwargs.call(this, show_subsequent_panel, ["search_internet"].concat([ρσ_desugar_kwargs({replace: true})]));
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.book_details"}
                });
                return ρσ_anonfunc;
            })()})])), ρσ_interpolate_kwargs.call(this, create_item, [title].concat([ρσ_desugar_kwargs({subtitle: subtitle, action: toggle_fields})])), ρσ_interpolate_kwargs.call(this, create_item, [_("Copy to library")].concat([ρσ_desugar_kwargs({subtitle: _("Copy or move this book to another calibre library"), action: (function() {
                var ρσ_anonfunc = function () {
                    ρσ_interpolate_kwargs.call(this, show_subsequent_panel, ["copy_to_library"].concat([ρσ_desugar_kwargs({replace: true})]));
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.book_details"}
                });
                return ρσ_anonfunc;
            })()})])), ρσ_interpolate_kwargs.call(this, create_item, [_("Manage data files")].concat([ρσ_desugar_kwargs({subtitle: _("Upload or download additional data files to this book"), action: (function() {
                var ρσ_anonfunc = function () {
                    ρσ_interpolate_kwargs.call(this, show_subsequent_panel, ["data_files"].concat([ρσ_desugar_kwargs({replace: true})]));
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "book_list.book_details"}
                });
                return ρσ_anonfunc;
            })()})])) ]);
            container.appendChild(E.div());
            create_item_list(container.lastChild, items);
        };
        if (!create_more_actions_panel.__argnames__) Object.defineProperties(create_more_actions_panel, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function return_to_book_details() {
            var q;
            q = parse_url_params();
            ρσ_interpolate_kwargs.call(this, show_panel, ["book_details"].concat([ρσ_desugar_kwargs({query: q, replace: true})]));
        };
        if (!return_to_book_details.__module__) Object.defineProperties(return_to_book_details, {
            __module__ : {value: "book_list.book_details"}
        });

        function toggle_fields() {
            var sd;
            sd = get_session_data();
            sd.set("show_all_metadata", (sd.get("show_all_metadata")) ? false : true);
            return_to_book_details();
        };
        if (!toggle_fields.__module__) Object.defineProperties(toggle_fields, {
            __module__ : {value: "book_list.book_details"}
        });

        function url_for(template, data) {
            function eqc(x) {
                return encode_query_component(x).replace(/%20/g, "+");
            };
            if (!eqc.__argnames__) Object.defineProperties(eqc, {
                __argnames__ : {value: ["x"]},
                __module__ : {value: "book_list.book_details"}
            });

            return ρσ_interpolate_kwargs.call(template, template.format, [ρσ_desugar_kwargs({title: eqc(data.title), author: eqc(data.author)})]);
        };
        if (!url_for.__argnames__) Object.defineProperties(url_for, {
            __argnames__ : {value: ["template", "data"]},
            __module__ : {value: "book_list.book_details"}
        });

        EXTENSIONS_TO_OPEN_IN_BROWSER = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["pdf"] = true;
            ρσ_d["jpeg"] = true;
            ρσ_d["jpg"] = true;
            ρσ_d["png"] = true;
            ρσ_d["gif"] = true;
            ρσ_d["webp"] = true;
            ρσ_d["txt"] = true;
            ρσ_d["html"] = true;
            ρσ_d["htm"] = true;
            ρσ_d["xhtml"] = true;
            return ρσ_d;
        }).call(this);
        function download_data_file(book_id, relpath) {
            var ext, open_inline, cd, url;
            ext = relpath.toLowerCase().rpartition(".")[2];
            open_inline = bool(EXTENSIONS_TO_OPEN_IN_BROWSER[(typeof ext === "number" && ext < 0) ? EXTENSIONS_TO_OPEN_IN_BROWSER.length + ext : ext]);
            cd = (open_inline) ? "inline" : "attachment";
            url = download_data_file_url(book_id, relpath, cd);
            if (open_inline) {
                window.open(url);
            } else {
                window.location = url;
            }
        };
        if (!download_data_file.__argnames__) Object.defineProperties(download_data_file, {
            __argnames__ : {value: ["book_id", "relpath"]},
            __module__ : {value: "book_list.book_details"}
        });

        function on_progress(container_id, book_id, loaded, total, xhr) {
            var container;
            container = document.getElementById(container_id);
            if (container && total) {
                update_status_widget(container, loaded, total);
            }
        };
        if (!on_progress.__argnames__) Object.defineProperties(on_progress, {
            __argnames__ : {value: ["container_id", "book_id", "loaded", "total", "xhr"]},
            __module__ : {value: "book_list.book_details"}
        });

        function data_files_submitted(container_id, book_id, end_type, xhr, ev) {
            var res, mi;
            if (end_type === "abort") {
                back();
                return;
            }
            if (end_type !== "load") {
                error_dialog(_("Failed to upload files to server"), _("Uploading data files for book: {} failed.").format(book_id), xhr.error_html);
                return;
            }
            try {
                res = JSON.parse(xhr.responseText);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    var err = ρσ_Exception;
                    error_dialog(_("Could not upload data files for book"), _("Server returned an invalid response"), err.toString());
                    return;
                } else {
                    throw ρσ_Exception;
                }
            }
            mi = book_metadata(book_id);
            if (mi) {
                mi.data_files = res.data_files;
            }
            if (res.error) {
                error_dialog(_("Could not upload data files for book"), _("There was an error: ") + res.error);
            } else {
                back();
            }
        };
        if (!data_files_submitted.__argnames__) Object.defineProperties(data_files_submitted, {
            __argnames__ : {value: ["container_id", "book_id", "end_type", "xhr", "ev"]},
            __module__ : {value: "book_list.book_details"}
        });

        function submit_data_files(top_container_id, container_id, book_id, added) {
            var c, w;
            c = document.getElementById(container_id);
            clear(c);
            c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Uploading changes to server, please wait...")].concat([ρσ_desugar_kwargs({style: "margin: 1ex 1rem"})])));
            w = upload_status_widget();
            c.appendChild(w);
            ajax_send("data-files/upload/" + ρσ_str.format("{}", book_id) + "/" + ρσ_str.format("{}", current_library_id()) + "", added, data_files_submitted.bind(null, container_id, book_id), on_progress.bind(null, container_id, book_id));
        };
        if (!submit_data_files.__argnames__) Object.defineProperties(submit_data_files, {
            __argnames__ : {value: ["top_container_id", "container_id", "book_id", "added"]},
            __module__ : {value: "book_list.book_details"}
        });

        function files_added(check_existing, top_container_id, book_id, container_id, files) {
            var container, mi, added, existing, file, data, r;
            container = document.getElementById(container_id);
            mi = book_metadata(book_id);
            if (!container || !mi || !files[0]) {
                return;
            }
            added = [];
            function exists(fname) {
                var q, relpath;
                var ρσ_Iter16 = ρσ_Iterable(mi.data_files);
                for (var ρσ_Index16 = 0; ρσ_Index16 < ρσ_Iter16.length; ρσ_Index16++) {
                    relpath = ρσ_Iter16[ρσ_Index16];
                    q = relpath.partition("/")[2];
                    if (q === fname) {
                        return true;
                    }
                }
                return false;
            };
            if (!exists.__argnames__) Object.defineProperties(exists, {
                __argnames__ : {value: ["fname"]},
                __module__ : {value: "book_list.book_details"}
            });

            if (check_existing) {
                existing = (function() {
                    var ρσ_Iter = ρσ_Iterable(files), ρσ_Result = [], file;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        file = ρσ_Iter[ρσ_Index];
                        if (exists(file.name)) {
                            ρσ_Result.push(file.name);
                        }
                    }
                    ρσ_Result = ρσ_list_constructor(ρσ_Result);
                    return ρσ_Result;
                })();
                if (existing.length) {
                    return question_dialog(_("Replace existing data files?"), _("The following data files already exist, are you sure you want to replace them?") + " " + existing.join(", "), (function() {
                        var ρσ_anonfunc = function (yes) {
                            if (yes) {
                                files_added(false, top_container_id, book_id, container_id, files);
                            } else {
                                back();
                            }
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["yes"]},
                            __module__ : {value: "book_list.book_details"}
                        });
                        return ρσ_anonfunc;
                    })());
                }
            }
            var ρσ_Iter17 = ρσ_Iterable(files);
            for (var ρσ_Index17 = 0; ρσ_Index17 < ρσ_Iter17.length; ρσ_Index17++) {
                file = ρσ_Iter17[ρσ_Index17];
                data = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["name"] = file.name;
                    ρσ_d["size"] = file.size;
                    ρσ_d["type"] = file.type;
                    ρσ_d["data_url"] = null;
                    return ρσ_d;
                }).call(this);
                added.push(data);
                r = new FileReader;
                r.onload = (function() {
                    var ρσ_anonfunc = function (evt) {
                        var entry;
                        data.data_url = evt.target.result;
                        var ρσ_Iter18 = ρσ_Iterable(added);
                        for (var ρσ_Index18 = 0; ρσ_Index18 < ρσ_Iter18.length; ρσ_Index18++) {
                            entry = ρσ_Iter18[ρσ_Index18];
                            if (!entry.data_url) {
                                return;
                            }
                        }
                        submit_data_files(top_container_id, container_id, book_id, added);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["evt"]},
                        __module__ : {value: "book_list.book_details"}
                    });
                    return ρσ_anonfunc;
                })();
                r.readAsDataURL(file);
            }
        };
        if (!files_added.__argnames__) Object.defineProperties(files_added, {
            __argnames__ : {value: ["check_existing", "top_container_id", "book_id", "container_id", "files"]},
            __module__ : {value: "book_list.book_details"}
        });

        function upload_data_file(container_id) {
            var book_id, container, div;
            if (!render_book.book_id || !book_metadata(render_book.book_id)) {
                return return_to_book_details();
            }
            book_id = render_book.book_id;
            container = document.getElementById(container_id);
            clear(container);
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("Upload data files"), icon: "back"})]));
            div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: unique_id()})]);
            container.appendChild(div);
            ρσ_interpolate_kwargs.call(this, upload_files_widget, [div, files_added.bind(null, true, container_id, book_id), _("Upload files by <a>selecting the files</a> or drag and drop of the files here.")].concat([ρσ_desugar_kwargs({single_file: false})]));
        };
        if (!upload_data_file.__argnames__) Object.defineProperties(upload_data_file, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function rebuild_data_files_list(container_id, book_id, relpath_being_deleted) {
            var container, mi, items, fname_map, relpath, df, fname, being_deleted, subtitle, side_actions;
            function delete_data_file(relpath, fname, ev) {
                question_dialog(_("Are you sure?"), _("Do you want to permanently delete the data file {0} from the book {1}?").format(fname, mi.title), (function() {
                    var ρσ_anonfunc = function (yes) {
                        var data;
                        if (yes) {
                            data = [relpath];
                            ajax_send("data-files/remove/" + ρσ_str.format("{}", book_id) + "/" + ρσ_str.format("{}", current_library_id()) + "", data, data_file_deleted.bind(null, container_id, book_id, relpath));
                            rebuild_data_files_list(container_id, book_id, relpath_being_deleted);
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["yes"]},
                        __module__ : {value: "book_list.book_details"}
                    });
                    return ρσ_anonfunc;
                })());
            };
            if (!delete_data_file.__argnames__) Object.defineProperties(delete_data_file, {
                __argnames__ : {value: ["relpath", "fname", "ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            function ddf(relpath, fname, ev) {
                download_data_file(book_id, relpath);
            };
            if (!ddf.__argnames__) Object.defineProperties(ddf, {
                __argnames__ : {value: ["relpath", "fname", "ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            function upload_data_file(ev) {
                ρσ_interpolate_kwargs.call(this, show_subsequent_panel, ["upload_data_file"].concat([ρσ_desugar_kwargs({replace: false})]));
            };
            if (!upload_data_file.__argnames__) Object.defineProperties(upload_data_file, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            container = document.getElementById(container_id);
            mi = book_metadata(book_id);
            if (!container || !mi) {
                return;
            }
            container = container.querySelector("[data-component=data-files-list-container]");
            clear(container);
            items = ρσ_list_decorate([ ρσ_interpolate_kwargs.call(this, create_item, [_("Upload new data file")].concat([ρσ_desugar_kwargs({icon: "plus", action: upload_data_file})])) ]);
            if (mi.data_files) {
                fname_map = (function() {
                    var ρσ_Iter = ρσ_Iterable(mi.data_files), ρσ_Result = Object.create(null), relpath;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        relpath = ρσ_Iter[ρσ_Index];
                        ρσ_Result[relpath] = (relpath.partition("/")[2]);
                    }
                    return ρσ_Result;
                })();
                df = ρσ_interpolate_kwargs.call(this, sorted, [Object.keys(fname_map)].concat([ρσ_desugar_kwargs({key: (function() {
                    var ρσ_anonfunc = function (x) {
                        return fname_map[(typeof x === "number" && x < 0) ? fname_map.length + x : x].toLowerCase();
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["x"]},
                        __module__ : {value: "book_list.book_details"}
                    });
                    return ρσ_anonfunc;
                })()})]));
                var ρσ_Iter19 = ρσ_Iterable(df);
                for (var ρσ_Index19 = 0; ρσ_Index19 < ρσ_Iter19.length; ρσ_Index19++) {
                    relpath = ρσ_Iter19[ρσ_Index19];
                    fname = fname_map[(typeof relpath === "number" && relpath < 0) ? fname_map.length + relpath : relpath];
                    being_deleted = relpath === relpath_being_deleted;
                    subtitle = null;
                    side_actions = ρσ_list_decorate([]);
                    if (being_deleted) {
                        subtitle = _("This file is being deleted");
                    } else {
                        side_actions.push(ρσ_interpolate_kwargs.call(this, create_side_action, ["trash"].concat([ρσ_desugar_kwargs({tooltip: _("Delete the file: {}").format(fname), action: delete_data_file.bind(null, relpath, fname)})])));
                    }
                    items.push(ρσ_interpolate_kwargs.call(this, create_item, [fname].concat([ρσ_desugar_kwargs({icon: "cloud-download", subtitle: subtitle, side_actions: side_actions, action: ddf.bind(null, relpath, fname)})])));
                }
            }
            create_item_list(container, items);
        };
        if (!rebuild_data_files_list.__argnames__) Object.defineProperties(rebuild_data_files_list, {
            __argnames__ : {value: ["container_id", "book_id", "relpath_being_deleted"]},
            __module__ : {value: "book_list.book_details"}
        });

        function data_file_deleted(container_id, book_id, relpath, end_type, xhr, ev) {
            var res, mi;
            if (end_type === "abort") {
                back();
                return;
            }
            if (end_type !== "load") {
                error_dialog(_("Failed to delete data file from server"), _("Deleting data file for book: {} failed.").format(book_id), xhr.error_html);
                return;
            }
            try {
                res = JSON.parse(xhr.responseText);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    var err = ρσ_Exception;
                    error_dialog(_("Could not delete data file for book"), _("Server returned an invalid response"), err.toString());
                    return;
                } else {
                    throw ρσ_Exception;
                }
            }
            mi = book_metadata(book_id);
            if (mi) {
                mi.data_files = res.data_files;
            }
            if (res.errors) {
                error_dialog(_("Failed to delete data file"), _("Failed to delete data file: {}").format(relpath), (ρσ_expr_temp = res.errors)[(typeof relpath === "number" && relpath < 0) ? ρσ_expr_temp.length + relpath : relpath]);
            }
            rebuild_data_files_list(container_id, book_id);
        };
        if (!data_file_deleted.__argnames__) Object.defineProperties(data_file_deleted, {
            __argnames__ : {value: ["container_id", "book_id", "relpath", "end_type", "xhr", "ev"]},
            __module__ : {value: "book_list.book_details"}
        });

        function data_files(container_id) {
            var book_id, container;
            if (!render_book.book_id || !book_metadata(render_book.book_id)) {
                return return_to_book_details();
            }
            book_id = render_book.book_id;
            container = document.getElementById(container_id);
            clear(container);
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("Manage data files"), icon: "back"})]));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: DATA_FILES_CLASS})]));
            container = container.lastChild;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({data_component: "data-files-list-container"})]));
            rebuild_data_files_list(container_id, book_id);
        };
        if (!data_files.__argnames__) Object.defineProperties(data_files, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function search_internet(container_id) {
            var container, mi, data, interface_data, author_links, book_links, links, entry, ρσ_unpack, name, url;
            if (!render_book.book_id || !book_metadata(render_book.book_id)) {
                return return_to_book_details();
            }
            container = document.getElementById(container_id);
            clear(container);
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("Search the internet"), icon: "back"})]));
            mi = book_metadata(render_book.book_id);
            data = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["title"] = mi.title;
                ρσ_d["author"] = (mi.authors) ? mi.authors[0] : _("Unknown");
                return ρσ_d;
            }).call(this);
            interface_data = get_interface_data();
            function link_for(name, template) {
                return ρσ_interpolate_kwargs.call(E, E.a, [name].concat([ρσ_desugar_kwargs({class_: "simple-link", href: url_for(template, data), target: "_blank"})]));
            };
            if (!link_for.__argnames__) Object.defineProperties(link_for, {
                __argnames__ : {value: ["name", "template"]},
                __module__ : {value: "book_list.book_details"}
            });

            author_links = E.ul();
            book_links = E.ul();
            if (interface_data.search_the_net_urls) {
                var ρσ_Iter20 = ρσ_Iterable(interface_data.search_the_net_urls);
                for (var ρσ_Index20 = 0; ρσ_Index20 < ρσ_Iter20.length; ρσ_Index20++) {
                    entry = ρσ_Iter20[ρσ_Index20];
                    links = (entry.type === "book") ? book_links : author_links;
                    links.appendChild(E.li(link_for(entry.name, entry.url)));
                }
            }
            var ρσ_Iter21 = ρσ_Iterable(ρσ_list_decorate([ [_("Goodreads"), "https://www.goodreads.com/book/author/{author}"], [_("Wikipedia"), 
            "https://en.wikipedia.org/w/index.php?search={author}"], [_("Google Books"), "https://www.google.com/search?tbm=bks&q=inauthor:%22{author}%22"] ]));
            for (var ρσ_Index21 = 0; ρσ_Index21 < ρσ_Iter21.length; ρσ_Index21++) {
                ρσ_unpack = ρσ_Iter21[ρσ_Index21];
                name = ρσ_unpack[0];
                url = ρσ_unpack[1];
                author_links.appendChild(E.li(link_for(name, url)));
            }
            var ρσ_Iter22 = ρσ_Iterable(ρσ_list_decorate([ [_("Goodreads"), "https://www.goodreads.com/search?q={author}+{title}&search%5Bsource%5D=goodreads&search_type=books&tab=books"], [_("Google Books"), 
            "https://www.google.com/search?tbm=bks&q=inauthor:%22{author}%22+intitle:%22{title}%22"], [_("Amazon"), 
            "https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&field-keywords={author}+{title}"] ]));
            for (var ρσ_Index22 = 0; ρσ_Index22 < ρσ_Iter22.length; ρσ_Index22++) {
                ρσ_unpack = ρσ_Iter22[ρσ_Index22];
                name = ρσ_unpack[0];
                url = ρσ_unpack[1];
                book_links.appendChild(E.li(link_for(name, url)));
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [safe_set_inner_html(E.h2(), _("Search for the author <i>{}</i> at:").format(data.author)), author_links, E.hr(), safe_set_inner_html(E.h2(), _("Search for the book <i>{}</i> at:").format(data.title)), book_links].concat([ρσ_desugar_kwargs({class_: SEARCH_INTERNET_CLASS})])));
        };
        if (!search_internet.__argnames__) Object.defineProperties(search_internet, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function do_copy_to_library(book_id, target_library_id, target_library_name) {
            var title, dupes_id, sd, saved_value;
            function handle_result(move, close_func, end_type, xhr, ev) {
                var title, response, payload;
                close_func();
                title = book_metadata(book_id).title;
                return_to_book_details();
                if (end_type === "abort") {
                    return;
                }
                if (end_type !== "load") {
                    error_dialog(_("Failed to copy book"), _("Failed to copy the book \"{}\". Click \"Show details\" for more information.").format(title), xhr.error_html);
                    return;
                }
                try {
                    response = (ρσ_expr_temp = JSON.parse(xhr.responseText))[(typeof book_id === "number" && book_id < 0) ? ρσ_expr_temp.length + book_id : book_id];
                    if (!response) {
                        throw new Exception("bad");
                    }
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        error_dialog(_("Failed to copy book"), _("Failed to copy the book \"{}\" because of an invalid response from calibre").format(title));
                        return;
                    } 
                }
                if (!response.ok) {
                    error_dialog(_("Failed to copy book"), _("Failed to copy the book \"{}\". Click \"Show details\" for more information.").format(title), response.payload);
                    return;
                }
                payload = response.payload;
                if (payload.action === "duplicate") {
                    warning_dialog(_("Book already exists"), _("Could not copy as a book with the same title and authors already exists in the {} library").format(target_library_name));
                } else if (payload.action === "automerge") {
                    warning_dialog(_("Book merged"), _("The files from the book were merged into a book with the same title and authors in the {} library").format(target_library_name));
                }
                if (move && ρσ_in(payload.action, ["add", "automerge"])) {
                    refresh_after_delete(book_id, current_library_id());
                }
            };
            if (!handle_result.__argnames__) Object.defineProperties(handle_result, {
                __argnames__ : {value: ["move", "close_func", "end_type", "xhr", "ev"]},
                __module__ : {value: "book_list.book_details"}
            });

            function trigger_copy(container_id, move, close_func) {
                var choice, ρσ_unpack, duplicate_action, automerge_action, data, container;
                try {
                    choice = document.querySelector("#" + ρσ_str.format("{}", dupes_id) + " input[name=\"dupes\"]:checked").value;
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        choice = document.querySelector("#" + ρσ_str.format("{}", dupes_id) + " input[name=\"dupes\"]").value;
                    } 
                }
                sd.set("copy_to_library_dupes", choice);
                ρσ_unpack = choice.split(";", 2);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                duplicate_action = ρσ_unpack[0];
                automerge_action = ρσ_unpack[1];
                data = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["book_ids"] = [book_id];
                    ρσ_d["move"] = move;
                    ρσ_d["duplicate_action"] = duplicate_action;
                    ρσ_d["automerge_action"] = automerge_action;
                    return ρσ_d;
                }).call(this);
                container = document.getElementById(container_id);
                clear(container);
                container.appendChild(E.div(_("Contacting calibre to copy book, please wait...")));
                ajax_send("cdb/copy-to-library/" + ρσ_str.format("{}", target_library_id) + "/" + ρσ_str.format("{}", current_library_id()) + "", data, handle_result.bind(null, move, close_func));
            };
            if (!trigger_copy.__argnames__) Object.defineProperties(trigger_copy, {
                __argnames__ : {value: ["container_id", "move", "close_func"]},
                __module__ : {value: "book_list.book_details"}
            });

            function radio(value, text) {
                return ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "dupes", value: value, checked: value === saved_value})]), " ", E.span(text)].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem"})]));
            };
            if (!radio.__argnames__) Object.defineProperties(radio, {
                __argnames__ : {value: ["value", "text"]},
                __module__ : {value: "book_list.book_details"}
            });

            title = book_metadata(book_id).title;
            dupes_id = unique_id();
            sd = get_session_data();
            saved_value = sd.get("copy_to_library_dupes");
            create_custom_dialog((ρσ_expr_temp = _("Copy book to \"{target_library_name}\""), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.format, [ρσ_desugar_kwargs({target_library_name: target_library_name})])), (function() {
                var ρσ_anonfunc = function (container, close_func) {
                    var container_id;
                    container_id = ensure_id(container);
                    container.appendChild(E.div(E.div(_("Copying: {}").format(title)), ρσ_interpolate_kwargs.call(E, E.div, [E.p(_("If there are already existing books in \"{}\" with the same title and authors, how would you like to handle them?").format(target_library_name)), radio("add;overwrite", _("Copy anyway")), radio("ignore;overwrite", _("Do not copy")), radio("add_formats_to_existing;overwrite", _("Merge into existing books, overwriting existing files")), radio("add_formats_to_existing;ignore", _("Merge into existing books, keeping existing files")), radio("add_formats_to_existing;new record", _("Merge into existing books, putting conflicting files into a new book record"))].concat([ρσ_desugar_kwargs({id: dupes_id})])), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Cancel"), null, close_func), create_button(_("Move"), null, trigger_copy.bind(null, container_id, true, close_func)), ρσ_interpolate_kwargs.call(this, create_button, [_("Copy"), null, trigger_copy.bind(null, container_id, false, close_func)].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: "button-box"})]))));
                    if (!container.querySelector("#" + ρσ_str.format("{}", dupes_id) + " input[name=\"dupes\"]:checked")) {
                        container.querySelector("#" + ρσ_str.format("{}", dupes_id) + " input[name=\"dupes\"]").checked = true;
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["container", "close_func"]},
                    __module__ : {value: "book_list.book_details"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!do_copy_to_library.__argnames__) Object.defineProperties(do_copy_to_library, {
            __argnames__ : {value: ["book_id", "target_library_id", "target_library_name"]},
            __module__ : {value: "book_list.book_details"}
        });

        function copy_to_library(container_id) {
            var container, libraries, items, ρσ_unpack, library_id, library_name;
            if (!render_book.book_id || !book_metadata(render_book.book_id)) {
                return return_to_book_details();
            }
            container = document.getElementById(container_id);
            clear(container);
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("Copy to library"), icon: "back"})]));
            libraries = all_libraries();
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: COPY_TO_LIBRARY_CLASS})]));
            container = container.lastChild;
            if (libraries.length < 2) {
                container.appendChild(E.div(_("There are no other calibre libraries available to copy the book to")));
                return;
            }
            container.appendChild(E.h2(_("Choose the library to copy to below")));
            items = ρσ_list_decorate([]);
            var ρσ_Iter23 = ρσ_Iterable(libraries);
            for (var ρσ_Index23 = 0; ρσ_Index23 < ρσ_Iter23.length; ρσ_Index23++) {
                ρσ_unpack = ρσ_Iter23[ρσ_Index23];
                library_id = ρσ_unpack[0];
                library_name = ρσ_unpack[1];
                if (library_id === current_library_id()) {
                    continue;
                }
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [library_name].concat([ρσ_desugar_kwargs({action: do_copy_to_library.bind(null, render_book.book_id, library_id, library_name)})])));
            }
            container.appendChild(E.div());
            create_item_list(container.lastChild, items);
        };
        if (!copy_to_library.__argnames__) Object.defineProperties(copy_to_library, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "book_list.book_details"}
        });

        function delete_book() {
            start_delete_book(current_library_id(), render_book.book_id, render_book.title || _("Unknown"));
        };
        if (!delete_book.__module__) Object.defineProperties(delete_book, {
            __module__ : {value: "book_list.book_details"}
        });

        set_panel_handler("book_details", init);
        set_panel_handler("book_details^more_actions", create_more_actions_panel);
        set_panel_handler("book_details^search_internet", search_internet);
        set_panel_handler("book_details^copy_to_library", copy_to_library);
        set_panel_handler("book_details^data_files", data_files);
        set_panel_handler("book_details^upload_data_file", upload_data_file);
        ρσ_modules["book_list.book_details"].bd_counter = bd_counter;
        ρσ_modules["book_list.book_details"].CLASS_NAME = CLASS_NAME;
        ρσ_modules["book_list.book_details"].SEARCH_INTERNET_CLASS = SEARCH_INTERNET_CLASS;
        ρσ_modules["book_list.book_details"].COPY_TO_LIBRARY_CLASS = COPY_TO_LIBRARY_CLASS;
        ρσ_modules["book_list.book_details"].DATA_FILES_CLASS = DATA_FILES_CLASS;
        ρσ_modules["book_list.book_details"].FORMAT_PRIORITIES = FORMAT_PRIORITIES;
        ρσ_modules["book_list.book_details"].IGNORED_FIELDS = IGNORED_FIELDS;
        ρσ_modules["book_list.book_details"].default_sort = default_sort;
        ρσ_modules["book_list.book_details"].ρσ_unpack = ρσ_unpack;
        ρσ_modules["book_list.book_details"].i = i;
        ρσ_modules["book_list.book_details"].f = f;
        ρσ_modules["book_list.book_details"].current_fetch = current_fetch;
        ρσ_modules["book_list.book_details"].EXTENSIONS_TO_OPEN_IN_BROWSER = EXTENSIONS_TO_OPEN_IN_BROWSER;
        ρσ_modules["book_list.book_details"].sort_formats_key = sort_formats_key;
        ρσ_modules["book_list.book_details"].get_preferred_format = get_preferred_format;
        ρσ_modules["book_list.book_details"].field_sorter = field_sorter;
        ρσ_modules["book_list.book_details"].href_for_search = href_for_search;
        ρσ_modules["book_list.book_details"].on_fmt_click = on_fmt_click;
        ρσ_modules["book_list.book_details"].adjust_iframe_height = adjust_iframe_height;
        ρσ_modules["book_list.book_details"].setup_iframe = setup_iframe;
        ρσ_modules["book_list.book_details"].adjust_all_iframes = adjust_all_iframes;
        ρσ_modules["book_list.book_details"].add_stars_to = add_stars_to;
        ρσ_modules["book_list.book_details"].hex_decode = hex_decode;
        ρσ_modules["book_list.book_details"].decode_calibre_url_library_id = decode_calibre_url_library_id;
        ρσ_modules["book_list.book_details"].replace_calibre_links_to_books = replace_calibre_links_to_books;
        ρσ_modules["book_list.book_details"].adjusting_sandboxed_html = adjusting_sandboxed_html;
        ρσ_modules["book_list.book_details"].render_metadata = render_metadata;
        ρσ_modules["book_list.book_details"].basic_table_rules = basic_table_rules;
        ρσ_modules["book_list.book_details"].no_book = no_book;
        ρσ_modules["book_list.book_details"].on_img_err = on_img_err;
        ρσ_modules["book_list.book_details"].preferred_format = preferred_format;
        ρσ_modules["book_list.book_details"].read_format = read_format;
        ρσ_modules["book_list.book_details"].read_book = read_book;
        ρσ_modules["book_list.book_details"].download_format = download_format;
        ρσ_modules["book_list.book_details"].download_book = download_book;
        ρσ_modules["book_list.book_details"].next_book = next_book;
        ρσ_modules["book_list.book_details"].render_book = render_book;
        ρσ_modules["book_list.book_details"].add_top_bar_buttons = add_top_bar_buttons;
        ρσ_modules["book_list.book_details"].proceed_after_succesful_fetch_metadata = proceed_after_succesful_fetch_metadata;
        ρσ_modules["book_list.book_details"].metadata_fetched = metadata_fetched;
        ρσ_modules["book_list.book_details"].fetch_metadata = fetch_metadata;
        ρσ_modules["book_list.book_details"].install_touch_handlers = install_touch_handlers;
        ρσ_modules["book_list.book_details"].create_book_details = create_book_details;
        ρσ_modules["book_list.book_details"].report_load_failure = report_load_failure;
        ρσ_modules["book_list.book_details"].check_for_books_loaded = check_for_books_loaded;
        ρσ_modules["book_list.book_details"].onkeydown = onkeydown;
        ρσ_modules["book_list.book_details"].init = init;
        ρσ_modules["book_list.book_details"].show_subsequent_panel = show_subsequent_panel;
        ρσ_modules["book_list.book_details"].edit_metadata = edit_metadata;
        ρσ_modules["book_list.book_details"].convert_book = convert_book;
        ρσ_modules["book_list.book_details"].create_more_actions_panel = create_more_actions_panel;
        ρσ_modules["book_list.book_details"].return_to_book_details = return_to_book_details;
        ρσ_modules["book_list.book_details"].toggle_fields = toggle_fields;
        ρσ_modules["book_list.book_details"].url_for = url_for;
        ρσ_modules["book_list.book_details"].download_data_file = download_data_file;
        ρσ_modules["book_list.book_details"].on_progress = on_progress;
        ρσ_modules["book_list.book_details"].data_files_submitted = data_files_submitted;
        ρσ_modules["book_list.book_details"].submit_data_files = submit_data_files;
        ρσ_modules["book_list.book_details"].files_added = files_added;
        ρσ_modules["book_list.book_details"].upload_data_file = upload_data_file;
        ρσ_modules["book_list.book_details"].rebuild_data_files_list = rebuild_data_files_list;
        ρσ_modules["book_list.book_details"].data_file_deleted = data_file_deleted;
        ρσ_modules["book_list.book_details"].data_files = data_files;
        ρσ_modules["book_list.book_details"].search_internet = search_internet;
        ρσ_modules["book_list.book_details"].do_copy_to_library = do_copy_to_library;
        ρσ_modules["book_list.book_details"].copy_to_library = copy_to_library;
        ρσ_modules["book_list.book_details"].delete_book = delete_book;
    })();

    (function(){
        var __name__ = "read_book.chrome";
        var get_color = ρσ_modules["book_list.theme"].get_color;

        var set_css = ρσ_modules.dom.set_css;

        function viewer_chrome_colors() {
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["background"] = get_color("window-background");
                ρσ_d["foreground"] = get_color("window-foreground");
                return ρσ_d;
            }).call(this);
        };
        if (!viewer_chrome_colors.__module__) Object.defineProperties(viewer_chrome_colors, {
            __module__ : {value: "read_book.chrome"}
        });

        function apply_viewer_chrome_colors(elem) {
            var colors;
            colors = viewer_chrome_colors();
            ρσ_interpolate_kwargs.call(this, set_css, [elem].concat([ρσ_desugar_kwargs({background_color: colors.background, color: colors.foreground})]));
        };
        if (!apply_viewer_chrome_colors.__argnames__) Object.defineProperties(apply_viewer_chrome_colors, {
            __argnames__ : {value: ["elem"]},
            __module__ : {value: "read_book.chrome"}
        });

        ρσ_modules["read_book.chrome"].viewer_chrome_colors = viewer_chrome_colors;
        ρσ_modules["read_book.chrome"].apply_viewer_chrome_colors = apply_viewer_chrome_colors;
    })();

    (function(){
        var __name__ = "read_book.main_overlay_style";
        var MAIN_OVERLAY_TS_CLASS, MAIN_OVERLAY_ACTIONS_CLASS, MAIN_OVERLAY_ACTION_CONTROL_CLASS, MAIN_OVERLAY_ACTION_ICON_CLASS, MAIN_OVERLAY_TEXT_ICON_CLASS, MAIN_OVERLAY_TOP_ROW_CLASS, MAIN_OVERLAY_TITLE_CLASS, MAIN_OVERLAY_TIMER_CLASS, MAIN_OVERLAY_FOOTER_ACTION_CLASS, MAIN_OVERLAY_FOOTER_CLASS, MAIN_OVERLAY_FOOTER_ACTIONS_CLASS, MAIN_OVERLAY_FOOTER_SLOT_CLASS, MAIN_OVERLAY_FOOTER_MIDDLE_SLOT_CLASS, MAIN_OVERLAY_FOOTER_RIGHT_SLOT_CLASS, MAIN_OVERLAY_ICON_SIZE;
        var get_color = ρσ_modules["book_list.theme"].get_color;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var unique_id = ρσ_modules.dom.unique_id;

        var viewer_chrome_colors = ρσ_modules["read_book.chrome"].viewer_chrome_colors;

        MAIN_OVERLAY_TS_CLASS = "read-book-main-overlay-top-section";
        MAIN_OVERLAY_ACTIONS_CLASS = "read-book-main-overlay-actions";
        MAIN_OVERLAY_ACTION_CONTROL_CLASS = "read-book-main-overlay-action-control";
        MAIN_OVERLAY_ACTION_ICON_CLASS = "read-book-main-overlay-action-icon";
        MAIN_OVERLAY_TEXT_ICON_CLASS = "read-book-main-overlay-text-icon";
        MAIN_OVERLAY_TOP_ROW_CLASS = "read-book-main-overlay-top-row";
        MAIN_OVERLAY_TITLE_CLASS = "read-book-main-overlay-title";
        MAIN_OVERLAY_TIMER_CLASS = "read-book-main-overlay-timer";
        MAIN_OVERLAY_FOOTER_ACTION_CLASS = "read-book-main-overlay-footer-action";
        MAIN_OVERLAY_FOOTER_CLASS = "read-book-main-overlay-footer";
        MAIN_OVERLAY_FOOTER_ACTIONS_CLASS = "read-book-main-overlay-footer-actions";
        MAIN_OVERLAY_FOOTER_SLOT_CLASS = "read-book-main-overlay-footer-slot";
        MAIN_OVERLAY_FOOTER_MIDDLE_SLOT_CLASS = "read-book-main-overlay-footer-middle-slot";
        MAIN_OVERLAY_FOOTER_RIGHT_SLOT_CLASS = "read-book-main-overlay-footer-right-slot";
        MAIN_OVERLAY_ICON_SIZE = "3.5ex";
        function timer_id() {
            if (!timer_id.ans) {
                timer_id.ans = unique_id();
            }
            return timer_id.ans;
        };
        if (!timer_id.__module__) Object.defineProperties(timer_id, {
            __module__ : {value: "read_book.main_overlay_style"}
        });

        function main_overlay_css() {
            var style, colors, border, hover_background, active_background, focus_outline, sel, action_sel;
            style = "";
            colors = viewer_chrome_colors();
            border = "var(--calibre-border-style-subtle)";
            hover_background = "var(--calibre-color-primary-light)";
            active_background = "var(--calibre-color-primary-light-2)";
            focus_outline = "1px solid " + get_color("input-focus-outline-color");
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_TS_CLASS].concat([ρσ_desugar_kwargs({user_select: "none", background_color: colors.background, color: colors.foreground})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_TOP_ROW_CLASS].concat([ρσ_desugar_kwargs({display: "flex", justify_content: "space-between", align_items: "baseline", font_size: "smaller", padding: "0.5ex 1ex", border_bottom: border})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_TITLE_CLASS].concat([ρσ_desugar_kwargs({max_width: "90%", text_overflow: "ellipsis", font_weight: "bold", white_space: "nowrap", overflow: "hidden"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_TIMER_CLASS].concat([ρσ_desugar_kwargs({max_width: "9%", white_space: "nowrap", overflow: "hidden"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_FOOTER_CLASS].concat([ρσ_desugar_kwargs({position: "fixed", width: "100%", bottom: "0", display: "flex", justify_content: "space-between", align_items: "center", user_select: "none", background_color: colors.background, color: colors.foreground})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_FOOTER_ACTIONS_CLASS].concat([ρσ_desugar_kwargs({display: "flex", justify_content: "space-between", align_items: "center"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_FOOTER_ACTION_CLASS].concat([ρσ_desugar_kwargs({display: "flex", align_items: "center", cursor: "pointer", padding: "0.5ex 1rem", appearance: "none", margin: "0", border: "0", color: "inherit", background: "transparent", font: "inherit"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_FOOTER_ACTION_CLASS + ":focus"].concat([ρσ_desugar_kwargs({outline: focus_outline})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_FOOTER_ACTION_CLASS + " > svg:first-child"].concat([ρσ_desugar_kwargs({margin_right: "0.5ex"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_FOOTER_SLOT_CLASS].concat([ρσ_desugar_kwargs({padding: "0.5ex 1rem"})]));
            sel = "." + MAIN_OVERLAY_TS_CLASS + " > ." + MAIN_OVERLAY_ACTIONS_CLASS + " ";
            style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({overflow: "hidden"})]));
            sel += "> ul ";
            style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({display: "flex", list_style: "none", margin: "0", padding: "0", border_bottom: border})]));
            sel += "> li";
            style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({border_right: border, display: "flex"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ":last-child"].concat([ρσ_desugar_kwargs({border_right_style: "none"})]));
            action_sel = sel + " > ." + MAIN_OVERLAY_ACTION_CONTROL_CLASS;
            style += ρσ_interpolate_kwargs.call(this, build_rule, [action_sel].concat([ρσ_desugar_kwargs({display: "flex", flex_wrap: "wrap", align_items: "center", cursor: "pointer", appearance: "none", margin: "0", padding: "0.5em 1ex", border: "0", color: "inherit", background: "transparent", font: "inherit", text_align: "left"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, [action_sel + ":focus"].concat([ρσ_desugar_kwargs({outline: focus_outline})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, [action_sel + " > ." + MAIN_OVERLAY_ACTION_ICON_CLASS + ":first-child"].concat([ρσ_desugar_kwargs({margin_right: "0.5ex"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, ["." + MAIN_OVERLAY_TEXT_ICON_CLASS].concat([ρσ_desugar_kwargs({font_size: "175%", font_weight: "bold"})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, [action_sel + ":hover, ." + MAIN_OVERLAY_FOOTER_ACTION_CLASS + ":hover"].concat([ρσ_desugar_kwargs({background_color: hover_background})]));
            style += ρσ_interpolate_kwargs.call(this, build_rule, [action_sel + ":active, ." + MAIN_OVERLAY_FOOTER_ACTION_CLASS + ":active"].concat([ρσ_desugar_kwargs({background_color: active_background})]));
            style += "@media screen and (max-width: 350px) { #" + ρσ_str.format("{}", timer_id()) + " { display: none; } }";
            return style;
        };
        if (!main_overlay_css.__module__) Object.defineProperties(main_overlay_css, {
            __module__ : {value: "read_book.main_overlay_style"}
        });

        add_extra_css(main_overlay_css);
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_TS_CLASS = MAIN_OVERLAY_TS_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_ACTIONS_CLASS = MAIN_OVERLAY_ACTIONS_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_ACTION_CONTROL_CLASS = MAIN_OVERLAY_ACTION_CONTROL_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_ACTION_ICON_CLASS = MAIN_OVERLAY_ACTION_ICON_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_TEXT_ICON_CLASS = MAIN_OVERLAY_TEXT_ICON_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_TOP_ROW_CLASS = MAIN_OVERLAY_TOP_ROW_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_TITLE_CLASS = MAIN_OVERLAY_TITLE_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_TIMER_CLASS = MAIN_OVERLAY_TIMER_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_ACTION_CLASS = MAIN_OVERLAY_FOOTER_ACTION_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_CLASS = MAIN_OVERLAY_FOOTER_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_ACTIONS_CLASS = MAIN_OVERLAY_FOOTER_ACTIONS_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_SLOT_CLASS = MAIN_OVERLAY_FOOTER_SLOT_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_MIDDLE_SLOT_CLASS = MAIN_OVERLAY_FOOTER_MIDDLE_SLOT_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_RIGHT_SLOT_CLASS = MAIN_OVERLAY_FOOTER_RIGHT_SLOT_CLASS;
        ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_ICON_SIZE = MAIN_OVERLAY_ICON_SIZE;
        ρσ_modules["read_book.main_overlay_style"].timer_id = timer_id;
        ρσ_modules["read_book.main_overlay_style"].main_overlay_css = main_overlay_css;
    })();

    (function(){
        var __name__ = "read_book.profiles";
        var E = ρσ_modules.elementmaker.E;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var create_item = ρσ_modules["book_list.item_list"].create_item;
        var create_item_list = ρσ_modules["book_list.item_list"].create_item_list;
        var create_side_action = ρσ_modules["book_list.item_list"].create_side_action;

        var create_top_bar = ρσ_modules["book_list.top_bar"].create_top_bar;

        var clear = ρσ_modules.dom.clear;
        var unique_id = ρσ_modules.dom.unique_id;

        var _ = ρσ_modules.gettext.gettext;

        var question_dialog = ρσ_modules.modals.question_dialog;

        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var apply_reader_profile = ρσ_modules.session.apply_reader_profile;
        var settings_for_reader_profile = ρσ_modules.session.settings_for_reader_profile;

        var create_button = ρσ_modules.widgets.create_button;

        function save_profile(container_id, hide_panel) {
            var container, name, sd, settings;
            container = document.getElementById(container_id);
            if (!container) {
                return;
            }
            name = container.querySelector("[name=profile_name]").value;
            sd = get_session_data();
            settings = settings_for_reader_profile(sd);
            ui_operations.save_profile(name, settings, (function() {
                var ρσ_anonfunc = function () {
                    var container, r;
                    container = document.getElementById(container_id);
                    if (container) {
                        r = container.querySelector(".saved_msg");
                        if (r) {
                            clear(r);
                            r.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.i(_("Saved: ") + name)].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem; margin-bottom: 1rem"})])));
                            load_profiles(container_id);
                        }
                    }
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.profiles"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!save_profile.__argnames__) Object.defineProperties(save_profile, {
            __argnames__ : {value: ["container_id", "hide_panel"]},
            __module__ : {value: "read_book.profiles"}
        });

        function use_profile(container_id, profile_name, profile_data) {
            var container, sd;
            container = document.getElementById(container_id);
            if (!container) {
                return;
            }
            sd = get_session_data();
            apply_reader_profile(sd, profile_data);
            if (ui_operations.apply_profile) {
                ui_operations.apply_profile(profile_data);
            }
            container.dispatchEvent(new Event("settings_changed"));
            container.dispatchEvent(new Event("close_panel"));
        };
        if (!use_profile.__argnames__) Object.defineProperties(use_profile, {
            __argnames__ : {value: ["container_id", "profile_name", "profile_data"]},
            __module__ : {value: "read_book.profiles"}
        });

        function delete_profile(container_id, profile_name) {
            question_dialog(_("Are you sure?"), _("Are you sure you want to delete the saved profile named: {}?").format(profile_name), (function() {
                var ρσ_anonfunc = function (ok) {
                    if (ok) {
                        ui_operations.save_profile(profile_name, null, (function() {
                            var ρσ_anonfunc = function () {
                                load_profiles(container_id);
                            };
                            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                __module__ : {value: "read_book.profiles"}
                            });
                            return ρσ_anonfunc;
                        })());
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ok"]},
                    __module__ : {value: "read_book.profiles"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!delete_profile.__argnames__) Object.defineProperties(delete_profile, {
            __argnames__ : {value: ["container_id", "profile_name"]},
            __module__ : {value: "read_book.profiles"}
        });

        function got_all_profiles(container_id, all_profiles) {
            var container, names, pl, items, display_name, side_actions, name;
            container = document.getElementById(container_id);
            if (!container) {
                return;
            }
            all_profiles["__default__"] = Object.create(null);
            names = list_wrap(Object.keys(all_profiles));
            names.pysort((function() {
                var ρσ_anonfunc = function (x) {
                    return (x === "__default__") ? "" : x.toLowerCase();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["x"]},
                    __module__ : {value: "read_book.profiles"}
                });
                return ρσ_anonfunc;
            })());
            pl = container.querySelector(".profiles_list_container");
            clear(pl);
            pl.appendChild(E.div(_("Load settings from one of the previously saved profiles below…")));
            pl.appendChild(E.div());
            items = ρσ_list_decorate([]);
            var ρσ_Iter0 = ρσ_Iterable(names);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                name = ρσ_Iter0[ρσ_Index0];
                display_name = name;
                if (name === "__default__") {
                    display_name = _("Restore settings to default values");
                    side_actions = ρσ_list_decorate([]);
                } else {
                    side_actions = ρσ_list_decorate([ create_side_action("trash", delete_profile.bind(null, container_id, name), _("Delete this profile")) ]);
                }
                items.push(ρσ_interpolate_kwargs.call(this, create_item, [display_name].concat([ρσ_desugar_kwargs({action: use_profile.bind(null, container_id, name, all_profiles[(typeof name === "number" && name < 0) ? all_profiles.length + name : name]), side_actions: side_actions})])));
            }
            create_item_list(pl.lastChild, items);
        };
        if (!got_all_profiles.__argnames__) Object.defineProperties(got_all_profiles, {
            __argnames__ : {value: ["container_id", "all_profiles"]},
            __module__ : {value: "read_book.profiles"}
        });

        function load_profiles(container_id) {
            var container, pl;
            container = document.getElementById(container_id);
            if (!container) {
                return;
            }
            pl = container.querySelector(".profiles_list_container");
            clear(pl);
            pl.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Loading saved profiles, please wait…")].concat([ρσ_desugar_kwargs({style: "padding-bottom: 1rem"})])));
            ui_operations.get_all_profiles(got_all_profiles.bind(null, container_id));
        };
        if (!load_profiles.__argnames__) Object.defineProperties(load_profiles, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "read_book.profiles"}
        });

        function create_profiles_panel(container, hide_panel, on_change) {
            var c, container_id, a;
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: _("Profiles"), icon: "close", action: hide_panel})]));
            c = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin: 1rem", id: unique_id("placeholder-prefs")})]);
            c.addEventListener("close_panel", (function() {
                var ρσ_anonfunc = function () {
                    hide_panel();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.profiles"}
                });
                return ρσ_anonfunc;
            })(), false);
            c.addEventListener("settings_changed", (function() {
                var ρσ_anonfunc = function () {
                    on_change();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.profiles"}
                });
                return ρσ_anonfunc;
            })(), false);
            container_id = c.id;
            a = ρσ_interpolate_kwargs.call(E, E.div, [E.label(_("Save current settings as profile:") + " "), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "profile_name", type: "text", placeholder: _("Name of profile"), onkeydown: (function() {
                var ρσ_anonfunc = function (e) {
                    if (e.key === "Enter") {
                        save_profile(container_id, hide_panel);
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["e"]},
                    __module__ : {value: "read_book.profiles"}
                });
                return ρσ_anonfunc;
            })()})]), create_button(_("Save"), "bookmark", save_profile.bind(null, container_id, hide_panel))].concat([ρσ_desugar_kwargs({style: "display:flex; flex-wrap: wrap; align-items: center; gap: 0.65rem"})]));
            container.appendChild(c);
            c.appendChild(a);
            c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "saved_msg"})]));
            c.appendChild(ρσ_interpolate_kwargs.call(E, E.hr, [ρσ_desugar_kwargs({style: "margin-top: 1ex; margin-bottom: 1ex"})]));
            c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "profiles_list_container"})]));
            load_profiles(container_id);
        };
        if (!create_profiles_panel.__argnames__) Object.defineProperties(create_profiles_panel, {
            __argnames__ : {value: ["container", "hide_panel", "on_change"]},
            __module__ : {value: "read_book.profiles"}
        });

        ρσ_modules["read_book.profiles"].save_profile = save_profile;
        ρσ_modules["read_book.profiles"].use_profile = use_profile;
        ρσ_modules["read_book.profiles"].delete_profile = delete_profile;
        ρσ_modules["read_book.profiles"].got_all_profiles = got_all_profiles;
        ρσ_modules["read_book.profiles"].load_profiles = load_profiles;
        ρσ_modules["read_book.profiles"].create_profiles_panel = create_profiles_panel;
    })();

    (function(){
        var __name__ = "read_book.prefs.font_size";
        var CONTAINER, MIN_FONT_SIZE, MAX_FONT_SIZE;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var rule = ρσ_modules.dom.rule;
        var unique_id = ρσ_modules.dom.unique_id;

        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var create_button = ρσ_modules.widgets.create_button;

        var session_defaults = ρσ_modules.session.session_defaults;

        CONTAINER = unique_id("font-size-prefs");
        MIN_FONT_SIZE = 8;
        MAX_FONT_SIZE = 80;
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var style;
                style = ρσ_interpolate_kwargs.call(this, rule, [CONTAINER, "option.current"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light)"})]));
                style += ρσ_interpolate_kwargs.call(this, rule, [CONTAINER, "option:hover"].concat([ρσ_desugar_kwargs({background_color: "var(--calibre-color-primary-light)"})]));
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "read_book.prefs.font_size"}
            });
            return ρσ_anonfunc;
        })());
        function change_font_size(sz) {
            var sd;
            sd = get_session_data();
            if (sd.get("base_font_size") !== sz) {
                sd.set("base_font_size", sz);
                ui_operations.update_font_size();
            }
        };
        if (!change_font_size.__argnames__) Object.defineProperties(change_font_size, {
            __argnames__ : {value: ["sz"]},
            __module__ : {value: "read_book.prefs.font_size"}
        });

        function apply_font_size() {
            var fs;
            fs = int(document.getElementById(CONTAINER).dataset.cfs);
            change_font_size(fs);
        };
        if (!apply_font_size.__module__) Object.defineProperties(apply_font_size, {
            __module__ : {value: "read_book.prefs.font_size"}
        });

        function set_quick_size(ev) {
            var newval;
            newval = ev.currentTarget.value;
            try {
                int(newval);
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    return;
                } 
            }
            if (newval !== document.getElementById(CONTAINER).dataset.cfs) {
                display_changed_font_size(newval);
            }
        };
        if (!set_quick_size.__argnames__) Object.defineProperties(set_quick_size, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.prefs.font_size"}
        });

        function change_font_size_by(frac) {
            var sd, sz, amt, nsz;
            sd = get_session_data();
            sz = sd.get("base_font_size");
            amt = sz * frac;
            if (abs(amt) < 1) {
                amt = (amt < 0) ? -1 : 1;
            }
            nsz = Math.round(sz + amt);
            nsz = max(MIN_FONT_SIZE, min(nsz, MAX_FONT_SIZE));
            change_font_size(nsz);
        };
        if (!change_font_size_by.__argnames__) Object.defineProperties(change_font_size_by, {
            __argnames__ : {value: ["frac"]},
            __module__ : {value: "read_book.prefs.font_size"}
        });

        function restore_default_font_size() {
            change_font_size(session_defaults().base_font_size);
        };
        if (!restore_default_font_size.__module__) Object.defineProperties(restore_default_font_size, {
            __module__ : {value: "read_book.prefs.font_size"}
        });

        function display_changed_font_size(sz) {
            var c, option, input;
            sz = max(MIN_FONT_SIZE, min(int(sz), MAX_FONT_SIZE));
            sz += "";
            c = document.getElementById(CONTAINER);
            c.dataset.cfs = sz;
            var ρσ_Iter0 = ρσ_Iterable(c.querySelectorAll("option"));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                option = ρσ_Iter0[ρσ_Index0];
                if (option.value === sz) {
                    option.classList.add("current");
                } else {
                    option.classList.remove("current");
                }
            }
            var ρσ_Iter1 = ρσ_Iterable(c.querySelectorAll("input"));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                input = ρσ_Iter1[ρσ_Index1];
                input.value = sz;
            }
            c.querySelector(".cfs_preview").style.fontSize = "" + ρσ_str.format("{}", sz) + "px";
        };
        if (!display_changed_font_size.__argnames__) Object.defineProperties(display_changed_font_size, {
            __argnames__ : {value: ["sz"]},
            __module__ : {value: "read_book.prefs.font_size"}
        });

        function create_font_size_panel(container, close) {
            var sd, cfs, quick, sz;
            sd = get_session_data();
            cfs = sd.get("base_font_size");
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: CONTAINER, style: "max-width: 500px; width: 80vw; border-radius: 8px; border: solid 1px currentColor; padding:1ex 1rem;", onclick: (function() {
                var ρσ_anonfunc = function (ev) {
                    [ev.preventDefault(), ev.stopPropagation()];
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.prefs.font_size"}
                });
                return ρσ_anonfunc;
            })()})])].concat([ρσ_desugar_kwargs({style: "width: 100%; height: 100%; display: flex; justify-content: center; align-items: center"})])));
            container = container.lastChild.lastChild;
            container.style.backgroundColor = get_color("window-background");
            container.dataset.cfs = cfs + "";
            quick = ρσ_interpolate_kwargs.call(E, E.datalist, [ρσ_desugar_kwargs({style: "display:flex; justify-content:space-around; flex-wrap: wrap; align-items: baseline;"})]);
            container.appendChild(quick);
            var ρσ_Iter2 = ρσ_Iterable(ρσ_list_decorate([ 10, 12, 14, 16, 18, 20, 22 ]));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                sz = ρσ_Iter2[ρσ_Index2];
                quick.appendChild(ρσ_interpolate_kwargs.call(E, E.option, ["Aa"].concat([ρσ_desugar_kwargs({title: "{} px".format(sz), class_: (cfs === sz) ? "current" : "", value: sz + "", style: "display: inline-block; font-size:" + ρσ_str.format("{}", sz) + "px; padding: 5px; cursor: pointer; border-radius: 4px; margin: 0 0.5rem", onclick: (function() {
                    var ρσ_anonfunc = function (ev) {
                        set_quick_size(ev);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "read_book.prefs.font_size"}
                    });
                    return ρσ_anonfunc;
                })()})])));
            }
            function set_size(ev) {
                var newval, q;
                newval = ev.currentTarget.value;
                try {
                    q = int(newval);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        return;
                    } 
                }
                if (MIN_FONT_SIZE <= q && q <= MAX_FONT_SIZE) {
                    set_quick_size(ev);
                }
            };
            if (!set_size.__argnames__) Object.defineProperties(set_size, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "read_book.prefs.font_size"}
            });

            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "range", min: MIN_FONT_SIZE + "", max: MAX_FONT_SIZE + "", value: cfs + "", style: "flex-grow: 4", oninput: set_quick_size})]), E.span(" ", ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({value: "" + ρσ_str.format("{}", cfs) + "", oninput: set_size, type: "number", min: MIN_FONT_SIZE + "", max: MAX_FONT_SIZE + "", step: "1"})]), " px")].concat([ρσ_desugar_kwargs({style: "display: flex; margin-top: 1rem"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [_("Sample to preview font size")].concat([ρσ_desugar_kwargs({class_: "cfs_preview"})]))].concat([ρσ_desugar_kwargs({style: "font-size: " + ρσ_str.format("{}", cfs) + "px; margin-top: 1rem; min-height: 60px; max-height: 60px; overflow: hidden; display: flex;"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(this, create_button, [_("OK")].concat([ρσ_desugar_kwargs({highlight: true, action: (function() {
                var ρσ_anonfunc = function () {
                    apply_font_size();
                    close();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.prefs.font_size"}
                });
                return ρσ_anonfunc;
            })()})])), "  ", ρσ_interpolate_kwargs.call(this, create_button, [_("Cancel")].concat([ρσ_desugar_kwargs({action: close})]))].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem; text-align: right"})])));
        };
        if (!create_font_size_panel.__argnames__) Object.defineProperties(create_font_size_panel, {
            __argnames__ : {value: ["container", "close"]},
            __module__ : {value: "read_book.prefs.font_size"}
        });

        function develop(container) {
            create_font_size_panel(container, (function() {
                var ρσ_anonfunc = function () {
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.prefs.font_size"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!develop.__argnames__) Object.defineProperties(develop, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.font_size"}
        });

        ρσ_modules["read_book.prefs.font_size"].CONTAINER = CONTAINER;
        ρσ_modules["read_book.prefs.font_size"].MIN_FONT_SIZE = MIN_FONT_SIZE;
        ρσ_modules["read_book.prefs.font_size"].MAX_FONT_SIZE = MAX_FONT_SIZE;
        ρσ_modules["read_book.prefs.font_size"].change_font_size = change_font_size;
        ρσ_modules["read_book.prefs.font_size"].apply_font_size = apply_font_size;
        ρσ_modules["read_book.prefs.font_size"].set_quick_size = set_quick_size;
        ρσ_modules["read_book.prefs.font_size"].change_font_size_by = change_font_size_by;
        ρσ_modules["read_book.prefs.font_size"].restore_default_font_size = restore_default_font_size;
        ρσ_modules["read_book.prefs.font_size"].display_changed_font_size = display_changed_font_size;
        ρσ_modules["read_book.prefs.font_size"].create_font_size_panel = create_font_size_panel;
        ρσ_modules["read_book.prefs.font_size"].develop = develop;
    })();

    (function(){
        var __name__ = "read_book.prefs.colors";
        var CONTAINER, COLOR_LIST, ACTION_BUTTONS, EDIT_SCHEME, MARGINS, develop;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var cached_color_to_rgba = ρσ_modules["book_list.theme"].cached_color_to_rgba;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var set_css = ρσ_modules.dom.set_css;
        var set_radio_group_value = ρσ_modules.dom.set_radio_group_value;
        var svgicon = ρσ_modules.dom.svgicon;
        var unique_id = ρσ_modules.dom.unique_id;

        var error_dialog = ρσ_modules.modals.error_dialog;

        var default_color_schemes = ρσ_modules["read_book.globals"].default_color_schemes;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var create_button_box = ρσ_modules["read_book.prefs.utils"].create_button_box;

        var session_defaults = ρσ_modules.session.session_defaults;

        var create_button = ρσ_modules.widgets.create_button;

        CONTAINER = unique_id("reader-color-scheme");
        COLOR_LIST = unique_id();
        ACTION_BUTTONS = unique_id();
        EDIT_SCHEME = unique_id();
        MARGINS = ["left", "right", "top", "bottom"];
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, style;
                sel = "#" + COLOR_LIST;
                style = ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({list_style_type: "none", display: "flex", flex_wrap: "wrap"})]));
                sel += " > li";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({padding: "1ex 1rem", margin: "1ex 0.5rem", border_radius: "4px", cursor: "pointer", border: "solid 1px currentColor"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " svg"].concat([ρσ_desugar_kwargs({visibility: "hidden"})]));
                sel += ".current-color";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " svg"].concat([ρσ_desugar_kwargs({visibility: "visible"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#{} #{} td".format(CONTAINER, EDIT_SCHEME)].concat([ρσ_desugar_kwargs({padding: "1ex 1em"})]));
                sel = "#" + ACTION_BUTTONS;
                style += sel + "{margin-top:2ex; padding-top:1ex; border-top: solid 1px currentColor; margin-bottom: 2ex; padding-bottom: 1ex; border-bottom: solid 1px currentColor}";
                style += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " > span "].concat([ρσ_desugar_kwargs({margin: "1ex 0.5rem", display: "inline-block"})]));
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "read_book.prefs.colors"}
            });
            return ρσ_anonfunc;
        })());
        function get_container() {
            return document.getElementById(CONTAINER);
        };
        if (!get_container.__module__) Object.defineProperties(get_container, {
            __module__ : {value: "read_book.prefs.colors"}
        });

        function resolve_color_scheme(current_color_scheme) {
            var sd, cs, ucs, ans, sn, rgba;
            sd = get_session_data();
            cs = current_color_scheme || sd.get("current_color_scheme") || session_defaults().current_color_scheme;
            ucs = sd.get("user_color_schemes");
            if (default_color_schemes[(typeof cs === "number" && cs < 0) ? default_color_schemes.length + cs : cs]) {
                ans = default_color_schemes[(typeof cs === "number" && cs < 0) ? default_color_schemes.length + cs : cs];
            } else if (ucs[(typeof cs === "number" && cs < 0) ? ucs.length + cs : cs] && ucs[(typeof cs === "number" && cs < 0) ? ucs.length + cs : cs].foreground && ucs[(typeof cs === "number" && cs < 0) ? ucs.length + cs : cs].background) {
                ans = ucs[(typeof cs === "number" && cs < 0) ? ucs.length + cs : cs];
            } else {
                var ρσ_Iter0 = ρσ_Iterable(default_color_schemes);
                for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                    sn = ρσ_Iter0[ρσ_Index0];
                    ans = default_color_schemes[(typeof sn === "number" && sn < 0) ? default_color_schemes.length + sn : sn];
                    break;
                }
            }
            rgba = cached_color_to_rgba(ans.background);
            ans.is_dark_theme = max(rgba[0], rgba[1], rgba[2]) < 115;
            return ans;
        };
        if (!resolve_color_scheme.__argnames__) Object.defineProperties(resolve_color_scheme, {
            __argnames__ : {value: ["current_color_scheme"]},
            __module__ : {value: "read_book.prefs.colors"}
        });

        function change_current_color(ev) {
            var ul, li;
            ul = ev.currentTarget.parentNode;
            var ρσ_Iter1 = ρσ_Iterable(ul.childNodes);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                li = ρσ_Iter1[ρσ_Index1];
                li.setAttribute("class", (li === ev.currentTarget) ? "current-color" : "");
            }
            set_action_button_visibility(ul.parentNode);
        };
        if (!change_current_color.__argnames__) Object.defineProperties(change_current_color, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.prefs.colors"}
        });

        function new_color_scheme(ev) {
            var container, inp;
            container = document.getElementById(EDIT_SCHEME);
            container.style.display = "block";
            var ρσ_Iter2 = ρσ_Iterable(container.querySelectorAll("input"));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                inp = ρσ_Iter2[ρσ_Index2];
                if (inp.name.endswith("_color_type")) {
                    inp.checked = inp.value === "default";
                } else if (inp.name.startswith("margin_")) {
                } else {
                    inp.value = (ρσ_expr_temp = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["name"] = "";
                        ρσ_d["bg"] = "#ffffff";
                        ρσ_d["fg"] = "#000000";
                        ρσ_d["link"] = "#0000ee";
                        return ρσ_d;
                    }).call(this))[ρσ_bound_index(inp.name, ρσ_expr_temp)];
                }
            }
            container.querySelector("input").focus();
            return container;
        };
        if (!new_color_scheme.__argnames__) Object.defineProperties(new_color_scheme, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.prefs.colors"}
        });

        function edit_color_scheme(ev) {
            var container, ccs, all_schemes, scheme, attr, val, ρσ_unpack, bg, fg, which;
            container = new_color_scheme(ev);
            ccs = current_color_scheme(container);
            all_schemes = all_color_schemes();
            if (all_schemes[(typeof ccs === "number" && ccs < 0) ? all_schemes.length + ccs : ccs]) {
                scheme = all_schemes[(typeof ccs === "number" && ccs < 0) ? all_schemes.length + ccs : ccs];
                container = document.getElementById(EDIT_SCHEME);
                container.querySelector("input").value = scheme.name;
                container.querySelector("input[name=bg]").value = scheme.background;
                container.querySelector("input[name=fg]").value = scheme.foreground;
                set_radio_group_value(container, "link_color_type", (scheme.link) ? "custom" : "default");
                if (scheme.link) {
                    container.querySelector("input[name=link]").value = scheme.link;
                }
                var ρσ_Iter3 = ρσ_Iterable(MARGINS);
                for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                    which = ρσ_Iter3[ρσ_Index3];
                    attr = "margin_" + ρσ_str.format("{}", which) + "";
                    val = scheme[(typeof attr === "number" && attr < 0) ? scheme.length + attr : attr];
                    set_radio_group_value(container, "" + ρσ_str.format("{}", attr) + "_color_type", (val) ? "custom" : "default");
                    if (val) {
                        ρσ_unpack = val.split(":");
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                        bg = ρσ_unpack[0];
                        fg = ρσ_unpack[1];
                        container.querySelector("input[name=" + ρσ_str.format("{}", attr) + "_bg]").value = bg;
                        container.querySelector("input[name=" + ρσ_str.format("{}", attr) + "_fg]").value = fg;
                    }
                }
            }
        };
        if (!edit_color_scheme.__argnames__) Object.defineProperties(edit_color_scheme, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.prefs.colors"}
        });

        function remove_color_scheme(ev) {
            var ccs, sd, ucs;
            ccs = current_color_scheme();
            if (default_color_schemes[(typeof ccs === "number" && ccs < 0) ? default_color_schemes.length + ccs : ccs]) {
                return error_dialog(_("Cannot remove"), _("Cannot remove a builtin color scheme"));
            }
            sd = get_session_data();
            ucs = sd.get("user_color_schemes");
            delete ucs[ccs];
            sd.set("user_color_schemes", ucs);
            create_color_buttons();
            set_current_color_scheme();
        };
        if (!remove_color_scheme.__argnames__) Object.defineProperties(remove_color_scheme, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.prefs.colors"}
        });

        function current_color_scheme() {
            try {
                return get_container().querySelector("li.current-color").getAttribute("data-name");
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                if (ρσ_Exception instanceof Error) {
                    return session_defaults().current_color_scheme;
                } else {
                    throw ρσ_Exception;
                }
            }
        };
        if (!current_color_scheme.__module__) Object.defineProperties(current_color_scheme, {
            __module__ : {value: "read_book.prefs.colors"}
        });

        function set_current_color_scheme(value) {
            var ul, done, li;
            ul = document.getElementById(COLOR_LIST);
            done = false;
            var ρσ_Iter4 = ρσ_Iterable(ul.childNodes);
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                li = ρσ_Iter4[ρσ_Index4];
                li.classList.remove("current-color");
                if (li.getAttribute("data-name") === value) {
                    li.classList.add("current-color");
                    done = true;
                }
            }
            if (!done) {
                var ρσ_Iter5 = ρσ_Iterable(ul.childNodes);
                for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                    li = ρσ_Iter5[ρσ_Index5];
                    li.classList.add("current-color");
                    break;
                }
            }
            set_action_button_visibility();
        };
        if (!set_current_color_scheme.__argnames__) Object.defineProperties(set_current_color_scheme, {
            __argnames__ : {value: ["value"]},
            __module__ : {value: "read_book.prefs.colors"}
        });

        function add_color_scheme(ev) {
            var colors, div, name, col, which, margin, key, sd, ucs;
            colors = Object.create(null);
            function check_color(col) {
                colors[(typeof col === "number" && col < 0) ? colors.length + col : col] = div.querySelector("input[name=" + ρσ_str.format("{}", col) + "]").value;
                if (!/^#[0-9A-F]{6}$/i.test(colors[(typeof col === "number" && col < 0) ? colors.length + col : col])) {
                    error_dialog(_("Invalid color"), _("The color {} is not a valid color").format(colors[(typeof col === "number" && col < 0) ? colors.length + col : col]));
                    return false;
                }
                return true;
            };
            if (!check_color.__argnames__) Object.defineProperties(check_color, {
                __argnames__ : {value: ["col"]},
                __module__ : {value: "read_book.prefs.colors"}
            });

            div = document.getElementById(EDIT_SCHEME);
            if (this !== "cancel") {
                name = div.querySelector("input[name=name]").value;
                if (!name) {
                    error_dialog(_("Name not specified"), _("You must specify a name for the color scheme"));
                    return;
                }
                var ρσ_Iter6 = ρσ_Iterable(ρσ_list_decorate([ "bg", "fg", "link" ]));
                for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                    col = ρσ_Iter6[ρσ_Index6];
                    if (!check_color(col)) {
                        return;
                    }
                }
                var ρσ_Iter7 = ρσ_Iterable(MARGINS);
                for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                    margin = ρσ_Iter7[ρσ_Index7];
                    var ρσ_Iter8 = ρσ_Iterable(ρσ_list_decorate([ "fg", "bg" ]));
                    for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                        which = ρσ_Iter8[ρσ_Index8];
                        if (!check_color("margin_" + ρσ_str.format("{}", margin) + "_" + ρσ_str.format("{}", which) + "")) {
                            return;
                        }
                    }
                }
                key = "*" + name;
                sd = get_session_data();
                ucs = Object.assign(Object.create(null), sd.get("user_color_schemes"));
                ucs[(typeof key === "number" && key < 0) ? ucs.length + key : key] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["name"] = name;
                    ρσ_d["foreground"] = colors.fg;
                    ρσ_d["background"] = colors.bg;
                    return ρσ_d;
                }).call(this);
                if (div.querySelector("input[name=link_color_type]:checked").value === "custom") {
                    ucs[(typeof key === "number" && key < 0) ? ucs.length + key : key].link = colors.link;
                }
                var ρσ_Iter9 = ρσ_Iterable(MARGINS);
                for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                    margin = ρσ_Iter9[ρσ_Index9];
                    if (div.querySelector("input[name=margin_" + ρσ_str.format("{}", margin) + "_color_type]:checked").value === "custom") {
                        (ρσ_expr_temp = ucs[(typeof key === "number" && key < 0) ? ucs.length + key : key])[ρσ_bound_index("margin_" + ρσ_str.format("{}", margin) + "", ρσ_expr_temp)] = colors[ρσ_bound_index("margin_" + ρσ_str.format("{}", margin) + "_bg", colors)] + ":" + colors[ρσ_bound_index("margin_" + ρσ_str.format("{}", margin) + "_fg", colors)];
                    }
                }
                sd.set("user_color_schemes", ucs);
                create_color_buttons();
                set_current_color_scheme(key);
            }
            div.style.display = "none";
        };
        if (!add_color_scheme.__argnames__) Object.defineProperties(add_color_scheme, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.prefs.colors"}
        });

        function all_color_schemes() {
            var all_schemes, k, sd, ucs;
            all_schemes = Object.create(null);
            var ρσ_Iter10 = ρσ_Iterable(default_color_schemes);
            for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                k = ρσ_Iter10[ρσ_Index10];
                all_schemes[(typeof k === "number" && k < 0) ? all_schemes.length + k : k] = default_color_schemes[(typeof k === "number" && k < 0) ? default_color_schemes.length + k : k];
            }
            sd = get_session_data();
            ucs = sd.get("user_color_schemes");
            var ρσ_Iter11 = ρσ_Iterable(ucs);
            for (var ρσ_Index11 = 0; ρσ_Index11 < ρσ_Iter11.length; ρσ_Index11++) {
                k = ρσ_Iter11[ρσ_Index11];
                all_schemes[(typeof k === "number" && k < 0) ? all_schemes.length + k : k] = ucs[(typeof k === "number" && k < 0) ? ucs.length + k : k];
            }
            return all_schemes;
        };
        if (!all_color_schemes.__module__) Object.defineProperties(all_color_schemes, {
            __module__ : {value: "read_book.prefs.colors"}
        });

        function create_color_buttons() {
            var ul, sd, all_schemes, ccs, scheme, is_current, item, name;
            ul = document.getElementById(COLOR_LIST);
            sd = get_session_data();
            clear(ul);
            all_schemes = all_color_schemes();
            ccs = sd.get("current_color_scheme");
            if (!all_schemes[(typeof ccs === "number" && ccs < 0) ? all_schemes.length + ccs : ccs]) {
                ccs = session_defaults().current_color_scheme;
            }
            var ρσ_Iter12 = ρσ_Iterable(ρσ_interpolate_kwargs.call(this, sorted, [all_schemes].concat([ρσ_desugar_kwargs({key: (function() {
                var ρσ_anonfunc = function (k) {
                    return all_schemes[(typeof k === "number" && k < 0) ? all_schemes.length + k : k].name.toLowerCase();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["k"]},
                    __module__ : {value: "read_book.prefs.colors"}
                });
                return ρσ_anonfunc;
            })()})])));
            for (var ρσ_Index12 = 0; ρσ_Index12 < ρσ_Iter12.length; ρσ_Index12++) {
                name = ρσ_Iter12[ρσ_Index12];
                scheme = all_schemes[(typeof name === "number" && name < 0) ? all_schemes.length + name : name];
                is_current = name === ccs;
                item = ρσ_interpolate_kwargs.call(this, set_css, [ρσ_interpolate_kwargs.call(E, E.li, [svgicon("check"), " " + scheme.name].concat([ρσ_desugar_kwargs({data_name: name, onclick: change_current_color, class_: (is_current) ? "current-color" : ""})]))].concat([ρσ_desugar_kwargs({color: scheme.foreground, background_color: scheme.background})]));
                ul.appendChild(item);
            }
        };
        if (!create_color_buttons.__module__) Object.defineProperties(create_color_buttons, {
            __module__ : {value: "read_book.prefs.colors"}
        });

        function set_action_button_visibility() {
            var container, ccs, is_custom, is_first, button;
            container = get_container();
            ccs = current_color_scheme(container);
            is_custom = ccs.startswith("*");
            is_first = true;
            var ρσ_Iter13 = ρσ_Iterable(container.querySelectorAll("#" + ACTION_BUTTONS + " > span"));
            for (var ρσ_Index13 = 0; ρσ_Index13 < ρσ_Iter13.length; ρσ_Index13++) {
                button = ρσ_Iter13[ρσ_Index13];
                if (is_first) {
                    is_first = false;
                } else {
                    button.style.display = (is_custom) ? "inline-block" : "none";
                }
            }
        };
        if (!set_action_button_visibility.__module__) Object.defineProperties(set_action_button_visibility, {
            __module__ : {value: "read_book.prefs.colors"}
        });

        function create_colors_panel(container, apply_func, cancel_func) {
            var sd, cs, ul;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: CONTAINER})]));
            container = container.lastChild;
            sd = get_session_data();
            cs = resolve_color_scheme();
            container.dataset.bg = cs.background;
            container.dataset.fg = cs.foreground;
            container.dataset.link = cs.link || "";
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [_("Choose a color scheme below")].concat([ρσ_desugar_kwargs({style: "margin:1ex 1em; padding: 1ex 0"})])));
            ul = ρσ_interpolate_kwargs.call(E, E.ul, [ρσ_desugar_kwargs({id: COLOR_LIST})]);
            container.appendChild(ul);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.span(_("Override all book colors:") + " "), E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "override_book_colors", value: "never"})]), _("Never")), "  ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "override_book_colors", value: "dark"})]), _("In dark mode")), "  ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "override_book_colors", value: "always"})]), _("Always"))].concat([ρσ_desugar_kwargs({style: "margin:1ex 1em; padding: 1ex 0; white-space: pre-wrap"})])));
            try {
                container.lastChild.querySelector("[name=override_book_colors][value=" + ρσ_str.format("{}", sd.get("override_book_colors")) + "]").checked = true;
            } catch (ρσ_Exception) {
                ρσ_last_exception = ρσ_Exception;
                {
                    container.lastChild.querySelector("[name=override_book_colors][value=never]").checked = true;
                } 
            }
            create_color_buttons();
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.span(create_button(_("New scheme"), "plus", new_color_scheme)), E.span(create_button(_("Edit scheme"), "pencil", edit_color_scheme)), E.span(create_button(_("Remove scheme"), "trash", remove_color_scheme))].concat([ρσ_desugar_kwargs({id: ACTION_BUTTONS})])));
            function margin_row(title, which) {
                return E.tr(E.td(title), E.td(E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "margin_" + ρσ_str.format("{}", which) + "_color_type", value: "default"})]), _("Default")), "  ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "margin_" + ρσ_str.format("{}", which) + "_color_type", value: "custom"})]), _("Custom")), "  ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "margin_" + ρσ_str.format("{}", which) + "_bg", type: "color", value: "#ffffff", onclick: (function() {
                    var ρσ_anonfunc = function (ev) {
                        set_radio_group_value(ev.currentTarget.closest("td"), "margin_" + ρσ_str.format("{}", which) + "_color_type", "custom");
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "read_book.prefs.colors"}
                    });
                    return ρσ_anonfunc;
                })()})]), " " + _("Background")), "  ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "margin_" + ρσ_str.format("{}", which) + "_fg", type: "color", value: "#000000", onclick: (function() {
                    var ρσ_anonfunc = function (ev) {
                        set_radio_group_value(ev.currentTarget.closest("td"), "margin_" + ρσ_str.format("{}", which) + "_color_type", "custom");
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "read_book.prefs.colors"}
                    });
                    return ρσ_anonfunc;
                })()})]), " " + _("Foreground"))));
            };
            if (!margin_row.__argnames__) Object.defineProperties(margin_row, {
                __argnames__ : {value: ["title", "which"]},
                __module__ : {value: "read_book.prefs.colors"}
            });

            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.table(E.tr(E.td(_("Name:")), E.td(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "name"})]))), E.tr(E.td(_("Background:")), E.td(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "bg", type: "color", value: "#ffffff"})]))), E.tr(E.td(_("Foreground:")), E.td(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "fg", type: "color", value: "#000000"})]))), E.tr(E.td(_("Link:")), E.td(E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "link_color_type", value: "default"})]), _("Default")), "  ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "link_color_type", value: "custom"})]), _("Custom")), " ", ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "link", type: "color", value: "#000000", onclick: (function() {
                var ρσ_anonfunc = function (ev) {
                    set_radio_group_value(ev.currentTarget.closest("td"), "link_color_type", "custom");
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.prefs.colors"}
                });
                return ρσ_anonfunc;
            })()})]))), margin_row(_("Top margin:"), "top"), margin_row(_("Bottom margin:"), "bottom"), margin_row(_("Left margin:"), "left"), margin_row(_("Right margin:"), "right")), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("Apply"), "check", add_color_scheme), E.span(" "), create_button(_("Discard"), "close", add_color_scheme.bind("cancel"))].concat([ρσ_desugar_kwargs({style: "display:flex; justify-content: flex-end; margin: 1ex 1em"})]))].concat([ρσ_desugar_kwargs({id: EDIT_SCHEME, style: "display:none"})])));
            set_action_button_visibility();
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_button_box(null, apply_func, cancel_func)].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
        };
        if (!create_colors_panel.__argnames__) Object.defineProperties(create_colors_panel, {
            __argnames__ : {value: ["container", "apply_func", "cancel_func"]},
            __module__ : {value: "read_book.prefs.colors"}
        });

        develop = create_colors_panel;
        function commit_colors(onchange) {
            var ccs, rcs, c, sd, prev_obc, cur_obc;
            ccs = current_color_scheme();
            rcs = resolve_color_scheme(ccs);
            c = get_container();
            sd = get_session_data();
            prev_obc = sd.get("override_book_colors");
            cur_obc = c.querySelector("[name=override_book_colors]:checked").value;
            sd.set("current_color_scheme", ccs);
            if (cur_obc !== prev_obc) {
                sd.set("override_book_colors", cur_obc);
            }
            if (rcs.foreground !== c.dataset.fg || rcs.background !== c.dataset.bg || c.dataset.link !== rcs.link || cur_obc !== prev_obc) {
                ui_operations.update_color_scheme();
                onchange();
            }
        };
        if (!commit_colors.__argnames__) Object.defineProperties(commit_colors, {
            __argnames__ : {value: ["onchange"]},
            __module__ : {value: "read_book.prefs.colors"}
        });

        ρσ_modules["read_book.prefs.colors"].CONTAINER = CONTAINER;
        ρσ_modules["read_book.prefs.colors"].COLOR_LIST = COLOR_LIST;
        ρσ_modules["read_book.prefs.colors"].ACTION_BUTTONS = ACTION_BUTTONS;
        ρσ_modules["read_book.prefs.colors"].EDIT_SCHEME = EDIT_SCHEME;
        ρσ_modules["read_book.prefs.colors"].MARGINS = MARGINS;
        ρσ_modules["read_book.prefs.colors"].develop = develop;
        ρσ_modules["read_book.prefs.colors"].get_container = get_container;
        ρσ_modules["read_book.prefs.colors"].resolve_color_scheme = resolve_color_scheme;
        ρσ_modules["read_book.prefs.colors"].change_current_color = change_current_color;
        ρσ_modules["read_book.prefs.colors"].new_color_scheme = new_color_scheme;
        ρσ_modules["read_book.prefs.colors"].edit_color_scheme = edit_color_scheme;
        ρσ_modules["read_book.prefs.colors"].remove_color_scheme = remove_color_scheme;
        ρσ_modules["read_book.prefs.colors"].current_color_scheme = current_color_scheme;
        ρσ_modules["read_book.prefs.colors"].set_current_color_scheme = set_current_color_scheme;
        ρσ_modules["read_book.prefs.colors"].add_color_scheme = add_color_scheme;
        ρσ_modules["read_book.prefs.colors"].all_color_schemes = all_color_schemes;
        ρσ_modules["read_book.prefs.colors"].create_color_buttons = create_color_buttons;
        ρσ_modules["read_book.prefs.colors"].set_action_button_visibility = set_action_button_visibility;
        ρσ_modules["read_book.prefs.colors"].create_colors_panel = create_colors_panel;
        ρσ_modules["read_book.prefs.colors"].commit_colors = commit_colors;
    })();

    (function(){
        var __name__ = "read_book.prefs.fonts";
        var CONTAINER, DEFAULT_STANDARD_FONT, DEFAULT_MINIMUM_FONT_SIZE, DEFAULT_ZOOM_STEP_SIZE, MIN_ZOOM_STEP_SIZE, develop;
        var svgicon = ρσ_modules.dom.svgicon;

        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var unique_id = ρσ_modules.dom.unique_id;

        var runtime = ρσ_modules["read_book.globals"].runtime;

        var create_button_box = ρσ_modules["read_book.prefs.utils"].create_button_box;

        var MAX_FONT_SIZE = ρσ_modules["read_book.prefs.font_size"].MAX_FONT_SIZE;
        var MIN_FONT_SIZE = ρσ_modules["read_book.prefs.font_size"].MIN_FONT_SIZE;

        CONTAINER = unique_id("standalone-font-settings");
        DEFAULT_STANDARD_FONT = "serif";
        DEFAULT_MINIMUM_FONT_SIZE = 8;
        DEFAULT_ZOOM_STEP_SIZE = 20;
        MIN_ZOOM_STEP_SIZE = 10;
        function current_zoom_step_size() {
            var s;
            s = get_session_data().get("standalone_font_settings");
            return s.zoom_step_size || DEFAULT_ZOOM_STEP_SIZE;
        };
        if (!current_zoom_step_size.__module__) Object.defineProperties(current_zoom_step_size, {
            __module__ : {value: "read_book.prefs.fonts"}
        });

        function font_select(name, settings) {
            var ans, current_val, family;
            ans = ρσ_interpolate_kwargs.call(E, E.select, [ρσ_desugar_kwargs({name: name})]);
            ans.appendChild(ρσ_interpolate_kwargs.call(E, E.option, [_("— Choose a font —")].concat([ρσ_desugar_kwargs({value: ""})])));
            current_val = settings[(typeof name === "number" && name < 0) ? settings.length + name : name];
            if (!current_val) {
                ans.lastChild.setAttribute("selected", "selected");
            }
            var ρσ_Iter0 = ρσ_Iterable(runtime.all_font_families);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                family = ρσ_Iter0[ρσ_Index0];
                if (family) {
                    ans.appendChild(E.option(family));
                    if (family === current_val) {
                        ans.lastChild.setAttribute("selected", "selected");
                    }
                }
            }
            return ρσ_interpolate_kwargs.call(E, E.div, [ans, E.span(svgicon("angle-down"))].concat([ρσ_desugar_kwargs({data_component: "select"})]));
        };
        if (!font_select.__argnames__) Object.defineProperties(font_select, {
            __argnames__ : {value: ["name", "settings"]},
            __module__ : {value: "read_book.prefs.fonts"}
        });

        function standard_font(settings) {
            var ans, sf;
            ans = ρσ_interpolate_kwargs.call(E, E.select, [ρσ_desugar_kwargs({name: "standard_font"})]);
            ans.appendChild(ρσ_interpolate_kwargs.call(E, E.option, [_("Serif")].concat([ρσ_desugar_kwargs({value: "serif"})])));
            ans.appendChild(ρσ_interpolate_kwargs.call(E, E.option, [_("Sans-serif")].concat([ρσ_desugar_kwargs({value: "sans"})])));
            ans.appendChild(ρσ_interpolate_kwargs.call(E, E.option, [_("Monospace")].concat([ρσ_desugar_kwargs({value: "mono"})])));
            sf = settings.standard_font || DEFAULT_STANDARD_FONT;
            ans.querySelector("[value=" + ρσ_str.format("{}", sf) + "]").setAttribute("selected", "selected");
            return ρσ_interpolate_kwargs.call(E, E.div, [ans, E.span(svgicon("angle-down"))].concat([ρσ_desugar_kwargs({data_component: "select"})]));
        };
        if (!standard_font.__argnames__) Object.defineProperties(standard_font, {
            __argnames__ : {value: ["settings"]},
            __module__ : {value: "read_book.prefs.fonts"}
        });

        function minimum_font_size(settings) {
            var ans;
            ans = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({max: str(MAX_FONT_SIZE), min: str(MIN_FONT_SIZE), step: "1", type: "number", name: "minimum_font_size"})]);
            if (typeof settings.minimum_font_size === "number") {
                ans.value = settings.minimum_font_size + "";
            } else {
                ans.value = "" + DEFAULT_MINIMUM_FONT_SIZE;
            }
            return ans;
        };
        if (!minimum_font_size.__argnames__) Object.defineProperties(minimum_font_size, {
            __argnames__ : {value: ["settings"]},
            __module__ : {value: "read_book.prefs.fonts"}
        });

        function zoom_step_size(settings) {
            var ans;
            ans = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({max: "100", min: MIN_ZOOM_STEP_SIZE + "", step: "1", type: "number", name: "zoom_step_size"})]);
            if (typeof settings.zoom_step_size === "number") {
                ans.value = max(10, parseInt(settings.zoom_step_size)) + "";
            } else {
                ans.value = "" + DEFAULT_ZOOM_STEP_SIZE;
            }
            return ans;
        };
        if (!zoom_step_size.__argnames__) Object.defineProperties(zoom_step_size, {
            __argnames__ : {value: ["settings"]},
            __module__ : {value: "read_book.prefs.fonts"}
        });

        function restore_defaults() {
            var container, q;
            container = get_container();
            var ρσ_Iter1 = ρσ_Iterable(ρσ_list_decorate([ "serif_family", "sans_family", "mono_family" ]));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                q = ρσ_Iter1[ρσ_Index1];
                container.querySelector("[name=" + ρσ_str.format("{}", q) + "]").value = "";
            }
            container.querySelector("[name=zoom_step_size]").value = DEFAULT_ZOOM_STEP_SIZE + "";
            container.querySelector("[name=minimum_font_size]").value = DEFAULT_MINIMUM_FONT_SIZE + "";
            container.querySelector("[name=standard_font]").value = DEFAULT_STANDARD_FONT;
        };
        if (!restore_defaults.__module__) Object.defineProperties(restore_defaults, {
            __module__ : {value: "read_book.prefs.fonts"}
        });

        function get_container() {
            return document.getElementById(CONTAINER);
        };
        if (!get_container.__module__) Object.defineProperties(get_container, {
            __module__ : {value: "read_book.prefs.fonts"}
        });

        function create_fonts_panel(container, apply_func, cancel_func) {
            var sd, settings;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: CONTAINER, style: "margin: 1rem"})]));
            container = container.lastChild;
            container.append(ρσ_interpolate_kwargs.call(E, E.div, [_("Choose fonts to use for un-styled text:")].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem"})])));
            sd = get_session_data();
            settings = sd.get("standalone_font_settings");
            function row(label, widget) {
                return E.tr(ρσ_interpolate_kwargs.call(E, E.td, [label + ": "].concat([ρσ_desugar_kwargs({style: "padding-top: 1ex"})])), ρσ_interpolate_kwargs.call(E, E.td, [widget].concat([ρσ_desugar_kwargs({style: "padding-top: 1ex"})])));
            };
            if (!row.__argnames__) Object.defineProperties(row, {
                __argnames__ : {value: ["label", "widget"]},
                __module__ : {value: "read_book.prefs.fonts"}
            });

            container.append(ρσ_interpolate_kwargs.call(E, E.table, [row(_("Serif family"), font_select("serif_family", settings)), row(_("Sans-serif family"), font_select("sans_family", settings)), row(_("Monospace family"), font_select("mono_family", settings)), row(_("Standard font"), standard_font(settings))].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem"})])));
            container.append(ρσ_interpolate_kwargs.call(E, E.div, [_("Zoom related settings")].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem; padding-top: 1rem; width: 100%; border-top: solid 1px"})])));
            container.append(E.table(row(_("Zoom step size (%)"), zoom_step_size(settings)), row(_("Minimum font size (px)"), minimum_font_size(settings))));
            container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func));
        };
        if (!create_fonts_panel.__argnames__) Object.defineProperties(create_fonts_panel, {
            __argnames__ : {value: ["container", "apply_func", "cancel_func"]},
            __module__ : {value: "read_book.prefs.fonts"}
        });

        develop = create_fonts_panel;
        function commit_fonts(onchange) {
            var sd, container, vals, zss, mfs, sf, val, q;
            sd = get_session_data();
            container = get_container();
            vals = Object.create(null);
            zss = parseInt(container.querySelector("[name=zoom_step_size]").value);
            if (zss !== DEFAULT_ZOOM_STEP_SIZE) {
                vals.zoom_step_size = max(MIN_ZOOM_STEP_SIZE, zss);
            }
            mfs = parseInt(container.querySelector("[name=minimum_font_size]").value);
            if (mfs !== DEFAULT_MINIMUM_FONT_SIZE) {
                vals.minimum_font_size = mfs;
            }
            sf = container.querySelector("[name=standard_font]").value;
            if (sf !== DEFAULT_STANDARD_FONT) {
                vals.standard_font = sf;
            }
            var ρσ_Iter2 = ρσ_Iterable(ρσ_list_decorate([ "serif_family", "sans_family", "mono_family" ]));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                q = ρσ_Iter2[ρσ_Index2];
                val = container.querySelector("[name=" + ρσ_str.format("{}", q) + "]").value;
                if (val) {
                    vals[(typeof q === "number" && q < 0) ? vals.length + q : q] = val;
                }
            }
            sd.set("standalone_font_settings", vals);
        };
        if (!commit_fonts.__argnames__) Object.defineProperties(commit_fonts, {
            __argnames__ : {value: ["onchange"]},
            __module__ : {value: "read_book.prefs.fonts"}
        });

        ρσ_modules["read_book.prefs.fonts"].CONTAINER = CONTAINER;
        ρσ_modules["read_book.prefs.fonts"].DEFAULT_STANDARD_FONT = DEFAULT_STANDARD_FONT;
        ρσ_modules["read_book.prefs.fonts"].DEFAULT_MINIMUM_FONT_SIZE = DEFAULT_MINIMUM_FONT_SIZE;
        ρσ_modules["read_book.prefs.fonts"].DEFAULT_ZOOM_STEP_SIZE = DEFAULT_ZOOM_STEP_SIZE;
        ρσ_modules["read_book.prefs.fonts"].MIN_ZOOM_STEP_SIZE = MIN_ZOOM_STEP_SIZE;
        ρσ_modules["read_book.prefs.fonts"].develop = develop;
        ρσ_modules["read_book.prefs.fonts"].current_zoom_step_size = current_zoom_step_size;
        ρσ_modules["read_book.prefs.fonts"].font_select = font_select;
        ρσ_modules["read_book.prefs.fonts"].standard_font = standard_font;
        ρσ_modules["read_book.prefs.fonts"].minimum_font_size = minimum_font_size;
        ρσ_modules["read_book.prefs.fonts"].zoom_step_size = zoom_step_size;
        ρσ_modules["read_book.prefs.fonts"].restore_defaults = restore_defaults;
        ρσ_modules["read_book.prefs.fonts"].get_container = get_container;
        ρσ_modules["read_book.prefs.fonts"].create_fonts_panel = create_fonts_panel;
        ρσ_modules["read_book.prefs.fonts"].commit_fonts = commit_fonts;
    })();

    (function(){
        var __name__ = "read_book.prefs.keyboard";
        var develop;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var create_search_bar = ρσ_modules.complete.create_search_bar;

        var create_item = ρσ_modules["book_list.item_list"].create_item;
        var create_item_list = ρσ_modules["book_list.item_list"].create_item_list;

        var clear = ρσ_modules.dom.clear;
        var unique_id = ρσ_modules.dom.unique_id;

        var key_as_text = ρσ_modules["read_book.shortcuts"].key_as_text;
        var keyevent_as_shortcut = ρσ_modules["read_book.shortcuts"].keyevent_as_shortcut;
        var shortcut_differs = ρσ_modules["read_book.shortcuts"].shortcut_differs;
        var shortcuts_definition = ρσ_modules["read_book.shortcuts"].shortcuts_definition;
        var shortcuts_group_desc = ρσ_modules["read_book.shortcuts"].shortcuts_group_desc;

        var create_button = ρσ_modules.widgets.create_button;

        function get_container() {
            return document.getElementById(get_container.id);
        };
        if (!get_container.__module__) Object.defineProperties(get_container, {
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function restore_defaults(close_func) {
            var q, item;
            get_container().dataset.changed = "true";
            var ρσ_Iter0 = ρσ_Iterable(get_container().querySelectorAll("[data-user-data]"));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                item = ρσ_Iter0[ρσ_Index0];
                q = JSON.parse(item.dataset.userData);
                q.shortcuts = (ρσ_expr_temp = shortcuts_definition())[ρσ_bound_index(q.name, ρσ_expr_temp)].shortcuts;
                item.dataset.userData = JSON.stringify(q);
            }
            close_func();
        };
        if (!restore_defaults.__argnames__) Object.defineProperties(restore_defaults, {
            __argnames__ : {value: ["close_func"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function as_groups(shortcuts) {
            var ans, sc, sc_name;
            ans = Object.create(null);
            var ρσ_Iter1 = ρσ_Iterable(Object.keys(shortcuts));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                sc_name = ρσ_Iter1[ρσ_Index1];
                sc = shortcuts[(typeof sc_name === "number" && sc_name < 0) ? shortcuts.length + sc_name : sc_name];
                if (!ans[ρσ_bound_index(sc.group, ans)]) {
                    ans[ρσ_bound_index(sc.group, ans)] = Object.create(null);
                }
                (ρσ_expr_temp = ans[ρσ_bound_index(sc.group, ans)])[(typeof sc_name === "number" && sc_name < 0) ? ρσ_expr_temp.length + sc_name : sc_name] = sc;
            }
            return ans;
        };
        if (!as_groups.__argnames__) Object.defineProperties(as_groups, {
            __argnames__ : {value: ["shortcuts"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function sort_group_key(group, sc_name) {
            return group[(typeof sc_name === "number" && sc_name < 0) ? group.length + sc_name : sc_name].short.toLowerCase();
        };
        if (!sort_group_key.__argnames__) Object.defineProperties(sort_group_key, {
            __argnames__ : {value: ["group", "sc_name"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function sc_as_item(sc_name, sc, shortcuts) {
            var cuts;
            cuts = shortcuts || sc.shortcuts;
            return ρσ_interpolate_kwargs.call(this, create_item, [sc.short].concat([ρσ_desugar_kwargs({action: customize_shortcut.bind(null, sc_name), subtitle: sc.long, data: JSON.stringify((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["name"] = sc_name;
                ρσ_d["shortcuts"] = cuts;
                return ρσ_d;
            }).call(this))})]));
        };
        if (!sc_as_item.__argnames__) Object.defineProperties(sc_as_item, {
            __argnames__ : {value: ["sc_name", "sc", "shortcuts"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function remove_key(evt) {
            var key_container;
            key_container = evt.currentTarget.parentNode.parentNode;
            key_container.parentNode.removeChild(key_container);
        };
        if (!remove_key.__argnames__) Object.defineProperties(remove_key, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function key_widget(key) {
            return ρσ_interpolate_kwargs.call(E, E.tr, [ρσ_interpolate_kwargs.call(E, E.td, [key_as_text(key)].concat([ρσ_desugar_kwargs({style: "padding: 0.5rem; border-right: solid 1px; margin-right: 0.5rem; margin-top: 0.5rem; vertical-align: middle"})])), ρσ_interpolate_kwargs.call(E, E.td, [ρσ_interpolate_kwargs.call(this, create_button, [_("Remove"), "remove"].concat([ρσ_desugar_kwargs({action: remove_key})]))].concat([ρσ_desugar_kwargs({style: "padding: 0.5rem; margin-top: 0.5rem; vertical-align: bottom"})]))].concat([ρσ_desugar_kwargs({data_shortcut: JSON.stringify(keyevent_as_shortcut(key))})]));
        };
        if (!key_widget.__argnames__) Object.defineProperties(key_widget, {
            __argnames__ : {value: ["key"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function close_customize_shortcut(apply_changes) {
            var container, q, item, shortcuts, sc, x, sc_name;
            container = get_container();
            container.firstChild.style.display = "flex";
            container.firstChild.nextSibling.style.display = "block";
            container.lastChild.style.display = "none";
            if (close_customize_shortcut.shortcut_being_customized) {
                var ρσ_Iter2 = ρσ_Iterable(container.firstChild.querySelectorAll("[data-user-data]"));
                for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                    item = ρσ_Iter2[ρσ_Index2];
                    q = JSON.parse(item.dataset.userData);
                    if (q.name === close_customize_shortcut.shortcut_being_customized) {
                        item.scrollIntoView();
                        break;
                    }
                }
            }
            if (apply_changes) {
                shortcuts = [];
                var ρσ_Iter3 = ρσ_Iterable(container.lastChild.querySelectorAll("[data-shortcut]"));
                for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                    x = ρσ_Iter3[ρσ_Index3];
                    sc = JSON.parse(x.dataset.shortcut);
                    shortcuts.push(sc);
                }
                sc_name = container.lastChild.dataset.scName;
                var ρσ_Iter4 = ρσ_Iterable(container.querySelectorAll("[data-user-data]"));
                for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                    item = ρσ_Iter4[ρσ_Index4];
                    q = JSON.parse(item.dataset.userData);
                    if (q.name === sc_name) {
                        q.shortcuts = shortcuts;
                        item.dataset.userData = JSON.stringify(q);
                        break;
                    }
                }
                get_container().dataset.changed = "true";
                commit_keyboard(create_keyboard_panel.onchange, null);
            }
        };
        if (!close_customize_shortcut.__argnames__) Object.defineProperties(close_customize_shortcut, {
            __argnames__ : {value: ["apply_changes"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function add_key_widget() {
            var uid;
            uid = unique_id("add-new-shortcut");
            return ρσ_interpolate_kwargs.call(E, E.div, [E.div(ρσ_interpolate_kwargs.call(this, create_button, [_("Add a new shortcut")].concat([ρσ_desugar_kwargs({icon: "plus", action: (function() {
                var ρσ_anonfunc = function (evt) {
                    var div;
                    div = document.getElementById(uid);
                    div.firstChild.style.display = "none";
                    div.lastChild.style.display = "block";
                    div.lastChild.querySelector("input").focus();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["evt"]},
                    __module__ : {value: "read_book.prefs.keyboard"}
                });
                return ρσ_anonfunc;
            })()})]))), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({readonly: "readonly", value: _("Press the key combination to use as a shortcut"), style: "width: 90vw", onkeydown: (function() {
                var ρσ_anonfunc = function (evt) {
                    var key_con, div;
                    evt.preventDefault();
                    evt.stopPropagation();
                    if (!ρσ_in(evt.key, ['Control', 'Meta', 'Alt', 'Shift'])) {
                        key_con = get_container().querySelector(".key-container");
                        key_con.appendChild(key_widget(evt));
                        div = document.getElementById(uid);
                        div.firstChild.style.display = "block";
                        div.lastChild.style.display = "none";
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["evt"]},
                    __module__ : {value: "read_book.prefs.keyboard"}
                });
                return ρσ_anonfunc;
            })()})])].concat([ρσ_desugar_kwargs({style: "display:none"})]))].concat([ρσ_desugar_kwargs({style: "margin-top: 1ex; margin-bottom: 1ex", id: uid})]));
        };
        if (!add_key_widget.__module__) Object.defineProperties(add_key_widget, {
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function customize_shortcut(sc_name) {
            var container, shortcuts, q, item, sc, key_con, key;
            container = get_container();
            container.firstChild.style.display = "none";
            container.firstChild.nextSibling.style.display = "none";
            container.lastChild.style.display = "block";
            close_customize_shortcut.shortcut_being_customized = sc_name;
            shortcuts = [];
            var ρσ_Iter5 = ρσ_Iterable(container.querySelectorAll("[data-user-data]"));
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                item = ρσ_Iter5[ρσ_Index5];
                q = JSON.parse(item.dataset.userData);
                if (q.name === sc_name) {
                    shortcuts = q.shortcuts;
                    break;
                }
            }
            container = container.lastChild;
            clear(container);
            container.dataset.scName = sc_name;
            sc = (ρσ_expr_temp = shortcuts_definition())[(typeof sc_name === "number" && sc_name < 0) ? ρσ_expr_temp.length + sc_name : sc_name];
            container.appendChild(E.h4(sc.short));
            if (sc.long) {
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [sc.long].concat([ρσ_desugar_kwargs({style: "font-style: italic; font-size: smaller; margin-top: 1ex"})])));
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Existing shortcuts:")].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem"})])));
            key_con = container.appendChild(ρσ_interpolate_kwargs.call(E, E.table, [ρσ_desugar_kwargs({class_: "key-container"})]));
            var ρσ_Iter6 = ρσ_Iterable(shortcuts);
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                key = ρσ_Iter6[ρσ_Index6];
                key_con.appendChild(key_widget(key));
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [add_key_widget()].concat([ρσ_desugar_kwargs({style: "margin-top:1ex;"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(this, create_button, [_("OK")].concat([ρσ_desugar_kwargs({action: close_customize_shortcut.bind(null, true)})])), E.span(" "), ρσ_interpolate_kwargs.call(this, create_button, [_("Cancel")].concat([ρσ_desugar_kwargs({action: close_customize_shortcut.bind(null, false)})]))].concat([ρσ_desugar_kwargs({style: "margin-top:1ex; display:flex; justify-content: flex-end"})])));
        };
        if (!customize_shortcut.__argnames__) Object.defineProperties(customize_shortcut, {
            __argnames__ : {value: ["sc_name"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function run_search() {
            var container, query, q, matches, item;
            container = get_container();
            query = container.querySelector("[name=search-for-sc]").value || "";
            query = query.toLowerCase();
            var ρσ_Iter7 = ρσ_Iterable(get_container().querySelectorAll("[data-user-data]"));
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                item = ρσ_Iter7[ρσ_Index7];
                q = item.textContent.toLowerCase();
                matches = !query || q.indexOf(query) > -1;
                item.style.display = (matches) ? "list-item" : "none";
            }
        };
        if (!run_search.__module__) Object.defineProperties(run_search, {
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function create_keyboard_panel(container, apply_func, cancel_func, onchange) {
            var search_button, sb, sd, custom_shortcuts, groups, group, items, sc, sc_name, group_name;
            create_keyboard_panel.onchange = onchange;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: unique_id("keyboard-settings"), style: "margin: 1rem"})]));
            container = container.lastChild;
            container.dataset.changed = "false";
            get_container.id = container.id;
            search_button = ρσ_interpolate_kwargs.call(this, create_button, [_("Search")].concat([ρσ_desugar_kwargs({icon: "search"})]));
            sb = ρσ_interpolate_kwargs.call(this, create_search_bar, [run_search, "search-for-sc"].concat([ρσ_desugar_kwargs({placeholder: _("Search for shortcut"), button: search_button})]));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [sb, E.span("  "), search_button].concat([ρσ_desugar_kwargs({style: "margin-bottom: 1ex; display: flex; width: 100%; justify-content: space-between"})])));
            container.firstChild.firstChild.style.flexGrow = "100";
            container.appendChild(E.div());
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display: none"})]));
            container = container.firstChild.nextSibling;
            sd = get_session_data();
            custom_shortcuts = sd.get("keyboard_shortcuts");
            groups = as_groups(shortcuts_definition());
            var ρσ_Iter8 = ρσ_Iterable(Object.keys(groups));
            for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                group_name = ρσ_Iter8[ρσ_Index8];
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.h3, [(ρσ_expr_temp = shortcuts_group_desc())[(typeof group_name === "number" && group_name < 0) ? ρσ_expr_temp.length + group_name : group_name]].concat([ρσ_desugar_kwargs({style: "margin-top: 1ex"})])));
                group = groups[(typeof group_name === "number" && group_name < 0) ? groups.length + group_name : group_name];
                items = ρσ_list_decorate([]);
                var ρσ_Iter9 = ρσ_Iterable(ρσ_interpolate_kwargs.call(this, sorted, [Object.keys(group)].concat([ρσ_desugar_kwargs({key: sort_group_key.bind(null, group)})])));
                for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                    sc_name = ρσ_Iter9[ρσ_Index9];
                    sc = group[(typeof sc_name === "number" && sc_name < 0) ? group.length + sc_name : sc_name];
                    items.push(sc_as_item(sc_name, sc, custom_shortcuts[(typeof sc_name === "number" && sc_name < 0) ? custom_shortcuts.length + sc_name : sc_name]));
                }
                container.appendChild(E.div());
                create_item_list(container.lastChild, items);
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(this, create_button, [_("Restore defaults")].concat([ρσ_desugar_kwargs({action: restore_defaults.bind(null, apply_func)})]))].concat([ρσ_desugar_kwargs({style: "margin-top: 1rem"})])));
        };
        if (!create_keyboard_panel.__argnames__) Object.defineProperties(create_keyboard_panel, {
            __argnames__ : {value: ["container", "apply_func", "cancel_func", "onchange"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        develop = create_keyboard_panel;
        function shortcuts_differ(a, b) {
            var ρσ_unpack, x, y;
            if (a.length !== b.length) {
                return true;
            }
            var ρσ_Iter10 = ρσ_Iterable(zip(a, b));
            for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                ρσ_unpack = ρσ_Iter10[ρσ_Index10];
                x = ρσ_unpack[0];
                y = ρσ_unpack[1];
                if (shortcut_differs(x, y)) {
                    return true;
                }
            }
            return false;
        };
        if (!shortcuts_differ.__argnames__) Object.defineProperties(shortcuts_differ, {
            __argnames__ : {value: ["a", "b"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        function commit_keyboard(onchange, container) {
            var sd, vals, q, item;
            sd = get_session_data();
            vals = Object.create(null);
            var ρσ_Iter11 = ρσ_Iterable(get_container().querySelectorAll("[data-user-data]"));
            for (var ρσ_Index11 = 0; ρσ_Index11 < ρσ_Iter11.length; ρσ_Index11++) {
                item = ρσ_Iter11[ρσ_Index11];
                q = JSON.parse(item.dataset.userData);
                if (shortcuts_differ(q.shortcuts, (ρσ_expr_temp = shortcuts_definition())[ρσ_bound_index(q.name, ρσ_expr_temp)].shortcuts)) {
                    vals[ρσ_bound_index(q.name, vals)] = q.shortcuts;
                }
            }
            sd.set("keyboard_shortcuts", vals);
            if (container !== null) {
                create_keyboard_panel.onchange = null;
            }
            if (get_container().dataset.changed === "true") {
                onchange();
            }
        };
        if (!commit_keyboard.__argnames__) Object.defineProperties(commit_keyboard, {
            __argnames__ : {value: ["onchange", "container"]},
            __module__ : {value: "read_book.prefs.keyboard"}
        });

        ρσ_modules["read_book.prefs.keyboard"].develop = develop;
        ρσ_modules["read_book.prefs.keyboard"].get_container = get_container;
        ρσ_modules["read_book.prefs.keyboard"].restore_defaults = restore_defaults;
        ρσ_modules["read_book.prefs.keyboard"].as_groups = as_groups;
        ρσ_modules["read_book.prefs.keyboard"].sort_group_key = sort_group_key;
        ρσ_modules["read_book.prefs.keyboard"].sc_as_item = sc_as_item;
        ρσ_modules["read_book.prefs.keyboard"].remove_key = remove_key;
        ρσ_modules["read_book.prefs.keyboard"].key_widget = key_widget;
        ρσ_modules["read_book.prefs.keyboard"].close_customize_shortcut = close_customize_shortcut;
        ρσ_modules["read_book.prefs.keyboard"].add_key_widget = add_key_widget;
        ρσ_modules["read_book.prefs.keyboard"].customize_shortcut = customize_shortcut;
        ρσ_modules["read_book.prefs.keyboard"].run_search = run_search;
        ρσ_modules["read_book.prefs.keyboard"].create_keyboard_panel = create_keyboard_panel;
        ρσ_modules["read_book.prefs.keyboard"].shortcuts_differ = shortcuts_differ;
        ρσ_modules["read_book.prefs.keyboard"].commit_keyboard = commit_keyboard;
    })();

    (function(){
        var __name__ = "read_book.prefs.layout";
        var CONTAINER, MARGINS, READ_MODE, FS_MODE, COLS, TEXT_AREA, develop;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var element = ρσ_modules.dom.element;
        var unique_id = ρσ_modules.dom.unique_id;

        var runtime = ρσ_modules["read_book.globals"].runtime;

        var create_button_box = ρσ_modules["read_book.prefs.utils"].create_button_box;

        var session_defaults = ρσ_modules.session.session_defaults;

        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;

        CONTAINER = unique_id("reader-page-layout");
        MARGINS = unique_id("reader-page-margins");
        READ_MODE = unique_id("read-mode");
        FS_MODE = unique_id("fs-mode");
        COLS = unique_id("cols-per-screen");
        TEXT_AREA = unique_id("text-area");
        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, style;
                sel = "#" + MARGINS;
                style = ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({margin_left: "1rem", margin_top: "-1ex"})]));
                style += ρσ_interpolate_kwargs.call(this, build_rule, ["#{} td".format(CONTAINER)].concat([ρσ_desugar_kwargs({padding: "1ex"})]));
                return style;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "read_book.prefs.layout"}
            });
            return ρσ_anonfunc;
        })());
        function restore_defaults() {
            var defaults, container, which, name;
            defaults = session_defaults();
            container = document.getElementById(CONTAINER);
            var ρσ_Iter0 = ρσ_Iterable("top bottom left right".split(" "));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                which = ρσ_Iter0[ρσ_Index0];
                container.querySelector("input[name={}]".format(which)).value = str(defaults[ρσ_bound_index("margin_" + which, defaults)]);
            }
            var ρσ_Iter1 = ρσ_Iterable("paged flow".split(" "));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                name = ρσ_Iter1[ρσ_Index1];
                container.querySelector("#" + ρσ_str.format("{}", READ_MODE) + " input[data-name=" + ρσ_str.format("{}", name) + "]").checked = defaults.read_mode === name;
            }
            if (!runtime.is_standalone_viewer) {
                container.querySelector("#" + ρσ_str.format("{}", FS_MODE) + " input[value=" + ρσ_str.format("{}", defaults.fullscreen_when_opening) + "]").checked = true;
            }
            var ρσ_Iter2 = ρσ_Iterable("portrait landscape".split(" "));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                name = ρσ_Iter2[ρσ_Index2];
                container.querySelector("input[name={}]".format(name)).value = str((ρσ_expr_temp = defaults.columns_per_screen)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]);
            }
            var ρσ_Iter3 = ρσ_Iterable("width height".split(" "));
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                which = ρσ_Iter3[ρσ_Index3];
                container.querySelector("input[name={}]".format(which)).value = str(defaults[ρσ_bound_index("max_text_" + which, defaults)]);
            }
            container.querySelector("input[name=cover_preserve_aspect_ratio]").checked = defaults.cover_preserve_aspect_ratio;
        };
        if (!restore_defaults.__module__) Object.defineProperties(restore_defaults, {
            __module__ : {value: "read_book.prefs.layout"}
        });

        function create_layout_panel(container, apply_func, cancel_func) {
            var sd, labels, rm, cps, name, val;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: CONTAINER})]));
            container = container.lastChild;
            sd = get_session_data();
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [ρσ_desugar_kwargs({style: "margin:1ex 1rem; padding: 1ex 0"})]));
            safe_set_inner_html(container.lastChild, _("Current window size is: <b>{0}x{1}</b> pixels").format(window.innerWidth, window.innerHeight));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [_("Change the page margins (in pixels) below")].concat([ρσ_desugar_kwargs({style: "margin:1ex 1rem; padding: 1ex 0"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.table, [ρσ_desugar_kwargs({id: MARGINS})]));
            labels = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["top"] = _("Top:");
                ρσ_d["bottom"] = _("Bottom:");
                ρσ_d["left"] = _("Left:");
                ρσ_d["right"] = _("Right:");
                return ρσ_d;
            }).call(this);
            function item(which, tr) {
                tr.appendChild(E.td(labels[(typeof which === "number" && which < 0) ? labels.length + which : which]));
                tr.appendChild(E.td(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "number", max: "9999", min: "0", step: "1", name: which, value: str(sd.get("margin_" + which))})])));
            };
            if (!item.__argnames__) Object.defineProperties(item, {
                __argnames__ : {value: ["which", "tr"]},
                __module__ : {value: "read_book.prefs.layout"}
            });

            container.lastChild.appendChild(E.tr());
            item("left", container.lastChild.lastChild);
            item("right", container.lastChild.lastChild);
            container.lastChild.appendChild(E.tr());
            item("top", container.lastChild.lastChild);
            item("bottom", container.lastChild.lastChild);
            function sec(text) {
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [text].concat([ρσ_desugar_kwargs({style: "margin: 2ex 1rem; padding-top:2ex; border-top: solid 1px; max-width: 50em"})])));
            };
            if (!sec.__argnames__) Object.defineProperties(sec, {
                __argnames__ : {value: ["text"]},
                __module__ : {value: "read_book.prefs.layout"}
            });

            sec(_("Choose the page layout mode. In paged mode, the text is split up into individual pages, as in a paper book. In flow mode text is presented as one long scrolling page, as in web browsers."));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: READ_MODE, style: "margin: 1ex 2rem; display: flex;"})]));
            rm = sd.get("read_mode");
            rm = (rm === "flow") ? "flow" : "paged";
            function rb(name, text) {
                var d;
                d = container.lastChild;
                d.appendChild(E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: "page-layout-mode", data_name: name, checked: rm === name})]), text));
            };
            if (!rb.__argnames__) Object.defineProperties(rb, {
                __argnames__ : {value: ["name", "text"]},
                __module__ : {value: "read_book.prefs.layout"}
            });

            rb("paged", _("Paged mode"));
            container.lastChild.appendChild(ρσ_interpolate_kwargs.call(E, E.span, [" "].concat([ρσ_desugar_kwargs({style: "width:3em"})])));
            rb("flow", _("Flow mode"));
            sec(_("In paged mode, control the number of pages per screen. A setting of zero means the number of pages is set based on the screen size."));
            cps = sd.get("columns_per_screen");
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.table, [E.tr(E.td(_("Portrait:")), E.td(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "number", name: "portrait", min: "0", step: "1", max: "20", value: str(cps.portrait)})])), E.td(_("Landscape:")), E.td(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "number", name: "landscape", min: "0", step: "1", max: "20", value: str(cps.landscape)})])))].concat([ρσ_desugar_kwargs({style: "margin: 1ex 1rem", id: COLS})])));
            sec(_("Change the maximum screen area (in pixels) used to display text. A value of zero means that all available screen area is used."));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.table, [E.tr(E.td(_("Width:")), E.td(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "number", name: "width", min: "0", step: "10", max: "99999", value: str(sd.get("max_text_width"))})])), E.td(_("Height:")), E.td(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "number", name: "height", min: "0", step: "10", max: "99999", value: str(sd.get("max_text_height"))})])))].concat([ρσ_desugar_kwargs({style: "margin: 1ex 1rem", id: TEXT_AREA})])));
            sec(_("Miscellaneous"));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox", name: "cover_preserve_aspect_ratio", checked: sd.get("cover_preserve_aspect_ratio")})]), _("Preserve cover aspect ratio"))].concat([ρσ_desugar_kwargs({style: "margin: 1ex 2rem; display: flex;"})])));
            if (!runtime.is_standalone_viewer) {
                name = "fullscreen_when_opening";
                val = sd.get(name);
                if ("auto always never".split(" ").indexOf(val || "") < 0) {
                    val = session_defaults().fullscreen_when_opening;
                }
                container.appendChild(E.div(ρσ_interpolate_kwargs.call(E, E.div, [_("When opening a book enter fullscreen:"), " ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: name, value: "auto", checked: val === "auto"})]), _("Auto")), " ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: name, value: "always", checked: val === "always"})]), _("Always")), " ", E.label(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "radio", name: name, value: "never", checked: val === "never"})]), _("Never"))].concat([ρσ_desugar_kwargs({style: "margin: 1ex 2rem", id: FS_MODE})]))));
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_button_box(restore_defaults, apply_func, cancel_func)].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
        };
        if (!create_layout_panel.__argnames__) Object.defineProperties(create_layout_panel, {
            __argnames__ : {value: ["container", "apply_func", "cancel_func"]},
            __module__ : {value: "read_book.prefs.layout"}
        });

        develop = create_layout_panel;
        function commit_layout(onchange, container) {
            var was_changed, sd, i, val, which, rm, crm, fs, cfs, cps, inp, cover_preserve_aspect_ratio;
            was_changed = false;
            sd = get_session_data();
            var ρσ_Iter4 = ρσ_Iterable("top bottom left right".split(" "));
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                which = ρσ_Iter4[ρσ_Index4];
                i = element(MARGINS, "[name={}]".format(which));
                try {
                    val = int(i.value);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        continue;
                    } 
                }
                if (val !== sd.get("margin_" + which)) {
                    was_changed = true;
                    sd.set("margin_" + which, val);
                }
            }
            rm = sd.get("read_mode");
            rm = (rm === "flow") ? "flow" : "paged";
            crm = (element(READ_MODE, "input").checked) ? "paged" : "flow";
            if (rm !== crm) {
                was_changed = true;
                sd.set("read_mode", crm);
            }
            if (!runtime.is_standalone_viewer) {
                fs = sd.get("fullscreen_when_opening");
                cfs = document.querySelector("#" + ρσ_str.format("{}", FS_MODE) + " input[name=\"fullscreen_when_opening\"]:checked").value;
                if (cfs !== fs) {
                    was_changed = true;
                    sd.set("fullscreen_when_opening", cfs);
                }
            }
            cps = sd.get("columns_per_screen");
            cps = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["portrait"] = cps.portrait;
                ρσ_d["landscape"] = cps.landscape;
                return ρσ_d;
            }).call(this);
            var ρσ_Iter5 = ρσ_Iterable(ρσ_list_decorate([ "portrait", "landscape" ]));
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                which = ρσ_Iter5[ρσ_Index5];
                inp = element(COLS, "input[name={}]".format(which));
                try {
                    val = int(inp.value);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        continue;
                    } 
                }
                if (cps[(typeof which === "number" && which < 0) ? cps.length + which : which] !== val) {
                    cps[(typeof which === "number" && which < 0) ? cps.length + which : which] = val;
                    sd.set("columns_per_screen", cps);
                    was_changed = true;
                }
            }
            var ρσ_Iter6 = ρσ_Iterable(ρσ_list_decorate([ "width", "height" ]));
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                which = ρσ_Iter6[ρσ_Index6];
                try {
                    val = int(element(TEXT_AREA, "input[name={}]".format(which)).value);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    {
                        continue;
                    } 
                }
                if (val !== sd.get("max_text_" + which)) {
                    was_changed = true;
                    sd.set("max_text_" + which, val);
                }
            }
            cover_preserve_aspect_ratio = element(CONTAINER, "input[name=cover_preserve_aspect_ratio]").checked;
            if (cover_preserve_aspect_ratio !== sd.get("cover_preserve_aspect_ratio")) {
                was_changed = true;
                sd.set("cover_preserve_aspect_ratio", cover_preserve_aspect_ratio);
            }
            if (was_changed) {
                onchange();
            }
        };
        if (!commit_layout.__argnames__) Object.defineProperties(commit_layout, {
            __argnames__ : {value: ["onchange", "container"]},
            __module__ : {value: "read_book.prefs.layout"}
        });

        ρσ_modules["read_book.prefs.layout"].CONTAINER = CONTAINER;
        ρσ_modules["read_book.prefs.layout"].MARGINS = MARGINS;
        ρσ_modules["read_book.prefs.layout"].READ_MODE = READ_MODE;
        ρσ_modules["read_book.prefs.layout"].FS_MODE = FS_MODE;
        ρσ_modules["read_book.prefs.layout"].COLS = COLS;
        ρσ_modules["read_book.prefs.layout"].TEXT_AREA = TEXT_AREA;
        ρσ_modules["read_book.prefs.layout"].develop = develop;
        ρσ_modules["read_book.prefs.layout"].restore_defaults = restore_defaults;
        ρσ_modules["read_book.prefs.layout"].create_layout_panel = create_layout_panel;
        ρσ_modules["read_book.prefs.layout"].commit_layout = commit_layout;
    })();

    (function(){
        var __name__ = "read_book.prefs.misc";
        var CONTAINER, develop;
        var E = ρσ_modules.elementmaker.E;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var unique_id = ρσ_modules.dom.unique_id;

        var _ = ρσ_modules.gettext.gettext;

        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var create_button_box = ρσ_modules["read_book.prefs.utils"].create_button_box;

        var session_defaults = ρσ_modules.session.session_defaults;
        var DEFAULTS = ρσ_modules.session.standalone_reader_defaults;

        var create_button = ρσ_modules.widgets.create_button;

        CONTAINER = unique_id("standalone-misc-settings");
        function restore_defaults() {
            var container, control, q;
            container = get_container();
            var ρσ_Iter0 = ρσ_Iterable(Object.keys(DEFAULTS));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                q = ρσ_Iter0[ρσ_Index0];
                control = container.querySelector("[name=" + ρσ_str.format("{}", q) + "]");
                if (typeof DEFAULTS[(typeof q === "number" && q < 0) ? DEFAULTS.length + q : q] === "boolean") {
                    control.checked = DEFAULTS[(typeof q === "number" && q < 0) ? DEFAULTS.length + q : q];
                } else {
                    control.value = DEFAULTS[(typeof q === "number" && q < 0) ? DEFAULTS.length + q : q];
                }
            }
            container.querySelector("[name=hide_tooltips]").checked = session_defaults().hide_tooltips;
        };
        if (!restore_defaults.__module__) Object.defineProperties(restore_defaults, {
            __module__ : {value: "read_book.prefs.misc"}
        });

        function get_container() {
            return document.getElementById(CONTAINER);
        };
        if (!get_container.__module__) Object.defineProperties(get_container, {
            __module__ : {value: "read_book.prefs.misc"}
        });

        function create_misc_panel(container, apply_func, cancel_func) {
            var sd, settings, sai, sync_annots;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: CONTAINER, style: "margin: 1rem"})]));
            container = container.lastChild;
            sd = get_session_data();
            settings = sd.get("standalone_misc_settings");
            settings.hide_tooltips = sd.get("hide_tooltips");
            function cb(name, text) {
                var ans;
                ans = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox", name: name})]);
                ans.checked = (typeof settings[(typeof name === "number" && name < 0) ? settings.length + name : name] === "boolean") ? settings[(typeof name === "number" && name < 0) ? settings.length + name : name] : DEFAULTS[(typeof name === "number" && name < 0) ? DEFAULTS.length + name : name];
                return ρσ_interpolate_kwargs.call(E, E.div, [E.label(ans, " " + text)].concat([ρσ_desugar_kwargs({style: "margin-top:1ex"})]));
            };
            if (!cb.__argnames__) Object.defineProperties(cb, {
                __argnames__ : {value: ["name", "text"]},
                __module__ : {value: "read_book.prefs.misc"}
            });

            sai = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "sync_annots_user", type: "text", title: _("The username of a Content server user that you want all annotations synced with. Use the special value * to sync with anonymous users")})]);
            sai.value = (typeof settings.sync_annots_user === "string") ? settings.sync_annots_user : DEFAULTS.sync_annots_user;
            sync_annots = ρσ_interpolate_kwargs.call(E, E.div, [E.label(_("Sync bookmarks/highlights with Content server user:") + " ", sai)].concat([ρσ_desugar_kwargs({style: "margin-top: 1ex; margin-left: 3px"})]));
            container.append(cb("remember_window_geometry", _("Remember last used window size and position")));
            container.append(cb("show_actions_toolbar", _("Show a toolbar with the most useful actions")));
            container.lastChild.append(E.span(" "));
            container.lastChild.append(ρσ_interpolate_kwargs.call(this, create_button, [_("Customize toolbar")].concat([ρσ_desugar_kwargs({action: ui_operations.customize_toolbar})])));
            container.append(cb("show_actions_toolbar_in_fullscreen", _("Keep the toolbar in full screen mode (needs restart)")));
            container.append(cb("remember_last_read", _("Remember current page when quitting")));
            container.append(cb("restore_docks", _("Restore open panels such as Table of Contents, Search, etc. on restart")));
            container.append(cb("save_annotations_in_ebook", _("Keep a copy of annotations/bookmarks in the e-book file, for easy sharing")));
            container.append(sync_annots);
            container.append(cb("singleinstance", _("Allow only a single instance of the viewer (needs restart)")));
            container.append(cb("hide_tooltips", _("Hide mouse-over tooltips in the book text")));
            container.append(cb("auto_hide_mouse", _("Auto hide the mouse cursor when unused for a few seconds")));
            container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func));
        };
        if (!create_misc_panel.__argnames__) Object.defineProperties(create_misc_panel, {
            __argnames__ : {value: ["container", "apply_func", "cancel_func"]},
            __module__ : {value: "read_book.prefs.misc"}
        });

        develop = create_misc_panel;
        function commit_misc(onchange) {
            var sd, container, vals, control, val, q, hide_tooltips;
            sd = get_session_data();
            container = get_container();
            vals = Object.create(null);
            var ρσ_Iter1 = ρσ_Iterable(Object.keys(DEFAULTS));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                q = ρσ_Iter1[ρσ_Index1];
                control = container.querySelector("[name=" + ρσ_str.format("{}", q) + "]");
                if (typeof DEFAULTS[(typeof q === "number" && q < 0) ? DEFAULTS.length + q : q] === "boolean") {
                    val = control.checked;
                } else {
                    val = control.value.strip();
                }
                if (val !== DEFAULTS[(typeof q === "number" && q < 0) ? DEFAULTS.length + q : q]) {
                    vals[(typeof q === "number" && q < 0) ? vals.length + q : q] = val;
                }
            }
            sd.set("standalone_misc_settings", vals);
            hide_tooltips = container.querySelector("[name=hide_tooltips]").checked;
            sd.set("hide_tooltips", (hide_tooltips === session_defaults().hide_tooltips) ? null : hide_tooltips);
            onchange();
        };
        if (!commit_misc.__argnames__) Object.defineProperties(commit_misc, {
            __argnames__ : {value: ["onchange"]},
            __module__ : {value: "read_book.prefs.misc"}
        });

        ρσ_modules["read_book.prefs.misc"].CONTAINER = CONTAINER;
        ρσ_modules["read_book.prefs.misc"].develop = develop;
        ρσ_modules["read_book.prefs.misc"].restore_defaults = restore_defaults;
        ρσ_modules["read_book.prefs.misc"].get_container = get_container;
        ρσ_modules["read_book.prefs.misc"].create_misc_panel = create_misc_panel;
        ρσ_modules["read_book.prefs.misc"].commit_misc = commit_misc;
    })();

    (function(){
        var __name__ = "read_book.prefs.scrolling";
        var CONTAINER, MIN_SCROLL_SPEED_AUTO, MAX_SCROLL_SPEED_AUTO, MIN_SCROLL_AUTO_DELAY, MAX_SCROLL_AUTO_DELAY, MIN_SCROLL_SPEED_SMOOTH, MAX_SCROLL_SPEED_SMOOTH, MIN_SCROLL_MOUSE_DELAY, MAX_SCROLL_MOUSE_DELAY, develop;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var unique_id = ρσ_modules.dom.unique_id;

        var create_button_box = ρσ_modules["read_book.prefs.utils"].create_button_box;

        var session_defaults = ρσ_modules.session.session_defaults;

        CONTAINER = unique_id("standalone-scrolling-settings");
        MIN_SCROLL_SPEED_AUTO = .05;
        MAX_SCROLL_SPEED_AUTO = 5;
        MIN_SCROLL_AUTO_DELAY = -1;
        MAX_SCROLL_AUTO_DELAY = 50;
        MIN_SCROLL_SPEED_SMOOTH = 5;
        MAX_SCROLL_SPEED_SMOOTH = 80;
        MIN_SCROLL_MOUSE_DELAY = 0;
        MAX_SCROLL_MOUSE_DELAY = 5;
        function restore_defaults() {
            var container, val, control;
            container = get_container();
            var ρσ_Iter0 = ρσ_Iterable(container.querySelectorAll("input[name]"));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                control = ρσ_Iter0[ρσ_Index0];
                val = (ρσ_expr_temp = session_defaults())[ρσ_bound_index(control.getAttribute("name"), ρσ_expr_temp)];
                if (control.type === "checkbox") {
                    control.checked = val;
                } else {
                    control.valueAsNumber = val;
                }
            }
        };
        if (!restore_defaults.__module__) Object.defineProperties(restore_defaults, {
            __module__ : {value: "read_book.prefs.scrolling"}
        });

        function get_container() {
            return document.getElementById(CONTAINER);
        };
        if (!get_container.__module__) Object.defineProperties(get_container, {
            __module__ : {value: "read_book.prefs.scrolling"}
        });

        function change_scroll_speed(amt) {
            var sd, lps, nlps;
            sd = get_session_data();
            lps = sd.get("lines_per_sec_auto");
            nlps = max(MIN_SCROLL_SPEED_AUTO, min(lps + amt, MAX_SCROLL_SPEED_AUTO));
            if ((nlps !== lps && (typeof nlps !== "object" || ρσ_not_equals(nlps, lps)))) {
                sd.set("lines_per_sec_auto", nlps);
            }
            return nlps;
        };
        if (!change_scroll_speed.__argnames__) Object.defineProperties(change_scroll_speed, {
            __argnames__ : {value: ["amt"]},
            __module__ : {value: "read_book.prefs.scrolling"}
        });

        function create_scrolling_panel(container, apply_func, cancel_func) {
            var sd;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: CONTAINER, style: "margin: 1rem"})]));
            container = container.lastChild;
            sd = get_session_data();
            function cb(name, text, title) {
                var ans;
                ans = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox", name: name, style: "margin-left: 0"})]);
                if (sd.get(name)) {
                    ans.checked = true;
                }
                return ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.label, [ans, text].concat([ρσ_desugar_kwargs({title: title || ""})]))].concat([ρσ_desugar_kwargs({style: "margin-top:1ex"})]));
            };
            if (!cb.__argnames__) Object.defineProperties(cb, {
                __argnames__ : {value: ["name", "text", "title"]},
                __module__ : {value: "read_book.prefs.scrolling"}
            });

            function spinner() {
                var name = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
                var text = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
                var kwargs = arguments[arguments.length-1];
                if (kwargs === null || typeof kwargs !== "object" || kwargs [ρσ_kwargs_symbol] !== true) kwargs = {};
                var ans, ρσ_unpack, key, val;
                ans = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "number", name: name, id: name})]);
                var ρσ_Iter1 = ρσ_Iterable(Object.entries(kwargs));
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    ρσ_unpack = ρσ_Iter1[ρσ_Index1];
                    key = ρσ_unpack[0];
                    val = ρσ_unpack[1];
                    ans[(typeof key === "number" && key < 0) ? ans.length + key : key] = val;
                }
                ans.valueAsNumber = sd.get(name, (ρσ_expr_temp = session_defaults())[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]);
                return [ρσ_interpolate_kwargs.call(E, E.label, [text].concat([ρσ_desugar_kwargs({"for": name})])), 
                ans];
            };
            if (!spinner.__handles_kwarg_interpolation__) Object.defineProperties(spinner, {
                __handles_kwarg_interpolation__ : {value: true},
                __argnames__ : {value: ["name", "text"]},
                __module__ : {value: "read_book.prefs.scrolling"}
            });

            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Control how scrolling works in paged mode")].concat([ρσ_desugar_kwargs({style: "margin-top:1ex"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-left: 1rem"})]));
            container.lastChild.appendChild(cb("paged_wheel_scrolls_by_screen", _("Mouse wheel scrolls by screen fulls instead of pages")));
            container.lastChild.appendChild(cb("paged_wheel_section_jumps", _("Horizontal mouse wheel jumps to next/previous section")));
            container.lastChild.appendChild(cb("paged_margin_clicks_scroll_by_screen", _("Clicking on the margins scrolls by screen fulls instead of pages")));
            container.lastChild.appendChild(ρσ_interpolate_kwargs.call(E, E.div, ρσ_interpolate_kwargs.call(this, spinner, ["paged_pixel_scroll_threshold", " " + _("Pixel scroll threshold:")].concat([ρσ_desugar_kwargs({title: _("When using a touchpad or mouse wheel that produces scroll events in pixels, set the number of pixels before a page turn is triggered"), step: 5, min: 0, max: 1e4})])).concat([ρσ_desugar_kwargs({style: "display:grid;margin-top:1ex;align-items:center;grid-template-columns:auto min-content;grid-gap:1ex; max-width: 30em"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.hr, [ρσ_desugar_kwargs({style: "margin-top:1ex; margin-bottom: 1ex"})]));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Control how smooth scrolling works in flow mode")].concat([ρσ_desugar_kwargs({style: "margin-top:1ex"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-left: 1rem"})]));
            container.lastChild.appendChild(cb("scroll_stop_boundaries", _("Stop at internal file boundaries when smooth scrolling by holding down the scroll key")));
            container.lastChild.appendChild(ρσ_interpolate_kwargs.call(E, E.div, ρσ_interpolate_kwargs.call(this, spinner, ["lines_per_sec_smooth", _("Smooth scrolling speed in lines/sec:")].concat([ρσ_desugar_kwargs({step: 5, min: MIN_SCROLL_SPEED_SMOOTH, max: MAX_SCROLL_SPEED_SMOOTH})])).concat(ρσ_interpolate_kwargs.call(this, spinner, ["lines_per_sec_auto", _("Auto scrolling speed in lines/sec:")].concat([ρσ_desugar_kwargs({step: .05, min: MIN_SCROLL_SPEED_AUTO, max: MAX_SCROLL_SPEED_AUTO})]))).concat(ρσ_interpolate_kwargs.call(this, spinner, ["scroll_auto_boundary_delay", _("Seconds to pause before auto-scrolling past internal file boundaries:")].concat([ρσ_desugar_kwargs({title: _("Use negative values to not auto-scroll past internal file boundaries"), step: .25, min: MIN_SCROLL_AUTO_DELAY, max: MAX_SCROLL_AUTO_DELAY})]))).concat(ρσ_interpolate_kwargs.call(this, spinner, ["scroll_mouse_boundary_delay", _("Seconds to pause when mouse-scrolling past internal file boundaries:")].concat([ρσ_desugar_kwargs({title: _("Set to zero to scroll past internal file boundaries without delay"), step: .25, min: MIN_SCROLL_MOUSE_DELAY, max: MAX_SCROLL_MOUSE_DELAY})]))).concat([ρσ_desugar_kwargs({style: "display:grid;margin-top:1ex;align-items:center;grid-template-columns:auto min-content;grid-gap:1ex; max-width: 30em"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.hr, [ρσ_desugar_kwargs({style: "margin-top:1ex; margin-bottom: 1ex"})]));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Miscellaneous")].concat([ρσ_desugar_kwargs({style: "margin-top:1ex"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-left: 1rem"})]));
            container.lastChild.appendChild(cb("book_scrollbar", _("Show a scrollbar")));
            container.lastChild.appendChild(cb("reverse_page_turn_zones", _("Invert the page turn tap areas"), _("Have tapping on the left side turn the page forward and the right side backwards")));
            container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func));
        };
        if (!create_scrolling_panel.__argnames__) Object.defineProperties(create_scrolling_panel, {
            __argnames__ : {value: ["container", "apply_func", "cancel_func"]},
            __module__ : {value: "read_book.prefs.scrolling"}
        });

        develop = create_scrolling_panel;
        function commit_scrolling(onchange) {
            var sd, container, changed, name, val, control;
            sd = get_session_data();
            container = get_container();
            changed = false;
            var ρσ_Iter2 = ρσ_Iterable(container.querySelectorAll("input[name]"));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                control = ρσ_Iter2[ρσ_Index2];
                name = control.getAttribute("name");
                val = (control.type === "checkbox") ? control.checked : control.valueAsNumber;
                if (val !== sd.get(name) && control.validity.valid) {
                    sd.set(name, val);
                    changed = true;
                }
            }
            if (changed) {
                onchange();
            }
        };
        if (!commit_scrolling.__argnames__) Object.defineProperties(commit_scrolling, {
            __argnames__ : {value: ["onchange"]},
            __module__ : {value: "read_book.prefs.scrolling"}
        });

        ρσ_modules["read_book.prefs.scrolling"].CONTAINER = CONTAINER;
        ρσ_modules["read_book.prefs.scrolling"].MIN_SCROLL_SPEED_AUTO = MIN_SCROLL_SPEED_AUTO;
        ρσ_modules["read_book.prefs.scrolling"].MAX_SCROLL_SPEED_AUTO = MAX_SCROLL_SPEED_AUTO;
        ρσ_modules["read_book.prefs.scrolling"].MIN_SCROLL_AUTO_DELAY = MIN_SCROLL_AUTO_DELAY;
        ρσ_modules["read_book.prefs.scrolling"].MAX_SCROLL_AUTO_DELAY = MAX_SCROLL_AUTO_DELAY;
        ρσ_modules["read_book.prefs.scrolling"].MIN_SCROLL_SPEED_SMOOTH = MIN_SCROLL_SPEED_SMOOTH;
        ρσ_modules["read_book.prefs.scrolling"].MAX_SCROLL_SPEED_SMOOTH = MAX_SCROLL_SPEED_SMOOTH;
        ρσ_modules["read_book.prefs.scrolling"].MIN_SCROLL_MOUSE_DELAY = MIN_SCROLL_MOUSE_DELAY;
        ρσ_modules["read_book.prefs.scrolling"].MAX_SCROLL_MOUSE_DELAY = MAX_SCROLL_MOUSE_DELAY;
        ρσ_modules["read_book.prefs.scrolling"].develop = develop;
        ρσ_modules["read_book.prefs.scrolling"].restore_defaults = restore_defaults;
        ρσ_modules["read_book.prefs.scrolling"].get_container = get_container;
        ρσ_modules["read_book.prefs.scrolling"].change_scroll_speed = change_scroll_speed;
        ρσ_modules["read_book.prefs.scrolling"].create_scrolling_panel = create_scrolling_panel;
        ρσ_modules["read_book.prefs.scrolling"].commit_scrolling = commit_scrolling;
    })();

    (function(){
        var __name__ = "read_book.selection_bar";
        var DRAG_SCROLL_ZONE_MIN_HEIGHT, BUTTON_MARGIN, HIDDEN, WAITING, DRAGGING, EDITING;
        var E = ρσ_modules.elementmaker.E;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var change_icon_image = ρσ_modules.dom.change_icon_image;
        var clear = ρσ_modules.dom.clear;
        var svgicon = ρσ_modules.dom.svgicon;
        var unique_id = ρσ_modules.dom.unique_id;

        var _ = ρσ_modules.gettext.gettext;

        var create_custom_dialog = ρσ_modules.modals.create_custom_dialog;
        var error_dialog = ρσ_modules.modals.error_dialog;
        var question_dialog = ρσ_modules.modals.question_dialog;

        var runtime = ρσ_modules["read_book.globals"].runtime;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var ICON_SIZE = ρσ_modules["read_book.highlights"].ICON_SIZE;
        var EditNotesAndColors = ρσ_modules["read_book.highlights"].EditNotesAndColors;
        var HighlightStyle = ρσ_modules["read_book.highlights"].HighlightStyle;
        var all_styles = ρσ_modules["read_book.highlights"].all_styles;
        var get_current_link_prefix = ρσ_modules["read_book.highlights"].get_current_link_prefix;
        var link_to_epubcfi = ρσ_modules["read_book.highlights"].link_to_epubcfi;
        var render_notes = ρσ_modules["read_book.highlights"].render_notes;

        var shortcut_for_key_event = ρσ_modules["read_book.shortcuts"].shortcut_for_key_event;

        var family_for_toc_node = ρσ_modules["read_book.toc"].family_for_toc_node;
        var get_toc_nodes_bordering_spine_item = ρσ_modules["read_book.toc"].get_toc_nodes_bordering_spine_item;

        var short_uuid = ρσ_modules.uuid.short_uuid;

        var create_button = ρσ_modules.widgets.create_button;

        var parse_url_params = ρσ_modules.utils.parse_url_params;

        DRAG_SCROLL_ZONE_MIN_HEIGHT = 10;
        BUTTON_MARGIN = "0.5rem";
        function get_margins() {
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["top"] = document.getElementById("book-top-margin").offsetHeight;
                ρσ_d["left"] = document.getElementById("book-left-margin").offsetWidth;
                return ρσ_d;
            }).call(this);
        };
        if (!get_margins.__module__) Object.defineProperties(get_margins, {
            __module__ : {value: "read_book.selection_bar"}
        });

        function get_overlay_origin() {
            var c, r;
            c = document.getElementById("book-selection-bar-overlay");
            if (!c) {
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["left"] = 0;
                    ρσ_d["top"] = 0;
                    return ρσ_d;
                }).call(this);
            }
            r = c.getBoundingClientRect();
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["left"] = r.left || 0;
                ρσ_d["top"] = r.top || 0;
                return ρσ_d;
            }).call(this);
        };
        if (!get_overlay_origin.__module__) Object.defineProperties(get_overlay_origin, {
            __module__ : {value: "read_book.selection_bar"}
        });

        function map_boundaries(cs, vertical, rtl) {
            var margins;
            margins = get_margins();
            function map_boundary(b) {
                var x_offset, y_offset;
                x_offset = y_offset = 0;
                if (vertical) {
                    if (b.selected_prev) {
                        y_offset = b.height;
                    }
                } else {
                    if (rtl) {
                        if (!b.selected_prev) {
                            x_offset = b.width;
                        }
                    } else {
                        if (b.selected_prev) {
                            x_offset = b.width;
                        }
                    }
                }
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["x"] = (b.x || 0) + x_offset + margins.left;
                    ρσ_d["y"] = (b.y || 0) + y_offset + margins.top;
                    ρσ_d["height"] = b.height || 0;
                    ρσ_d["width"] = b.width || 0;
                    ρσ_d["onscreen"] = b.onscreen;
                    return ρσ_d;
                }).call(this);
            };
            if (!map_boundary.__argnames__) Object.defineProperties(map_boundary, {
                __argnames__ : {value: ["b"]},
                __module__ : {value: "read_book.selection_bar"}
            });

            return [map_boundary(cs.start), map_boundary(cs.end)];
        };
        if (!map_boundaries.__argnames__) Object.defineProperties(map_boundaries, {
            __argnames__ : {value: ["cs", "vertical", "rtl"]},
            __module__ : {value: "read_book.selection_bar"}
        });

        function map_to_iframe_coords(point, margins) {
            var origin;
            origin = get_overlay_origin();
            point.x -= margins.left + origin.left;
            point.y -= margins.top + origin.top;
            return point;
        };
        if (!map_to_iframe_coords.__argnames__) Object.defineProperties(map_to_iframe_coords, {
            __argnames__ : {value: ["point", "margins"]},
            __module__ : {value: "read_book.selection_bar"}
        });

        function near_element(elem, x, y) {
            var r, extend_by, left, top, right, bottom;
            r = elem.getBoundingClientRect();
            extend_by = 15;
            left = r.left - extend_by;
            top = r.top - extend_by;
            right = r.right + extend_by;
            bottom = r.bottom + extend_by;
            return left <= x && x <= right && top <= y && y <= bottom;
        };
        if (!near_element.__argnames__) Object.defineProperties(near_element, {
            __argnames__ : {value: ["elem", "x", "y"]},
            __module__ : {value: "read_book.selection_bar"}
        });

        function position_bar_avoiding_handles(lh, rh, left, top, bar_width, bar_height, available_width, available_height, buffer) {
            var bottom, has_space_below, b, ρσ_unpack, left_overlaps, right_overlaps, h, d1, d2, q1, q2, d, d3, q3, th, bh;
            function bar_rect(left, top) {
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["left"] = left;
                    ρσ_d["top"] = top;
                    ρσ_d["right"] = left + bar_width;
                    ρσ_d["bottom"] = top + bar_height;
                    return ρσ_d;
                }).call(this);
            };
            if (!bar_rect.__argnames__) Object.defineProperties(bar_rect, {
                __argnames__ : {value: ["left", "top"]},
                __module__ : {value: "read_book.selection_bar"}
            });

            function overlaps_a_handle(left, top) {
                var b;
                b = bar_rect(left, top);
                if (elements_overlap(lh, b)) {
                    return lh;
                }
                if (elements_overlap(rh, b)) {
                    return rh;
                }
            };
            if (!overlaps_a_handle.__argnames__) Object.defineProperties(overlaps_a_handle, {
                __argnames__ : {value: ["left", "top"]},
                __module__ : {value: "read_book.selection_bar"}
            });

            if (!overlaps_a_handle(left, top)) {
                return;
            }
            if (Math.abs(lh.top - rh.top) < lh.height + buffer) {
                bottom = max(lh.bottom, rh.bottom);
                has_space_below = bottom + bar_height < available_height - buffer;
                if (has_space_below) {
                    return (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["top"] = bottom;
                        ρσ_d["put_below"] = true;
                        return ρσ_d;
                    }).call(this);
                }
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["top"] = min(lh.top, rh.top);
                    ρσ_d["put_below"] = false;
                    return ρσ_d;
                }).call(this);
            }
            b = bar_rect(left, top);
            if (lh.left > rh.left) {
                ρσ_unpack = [rh, lh];
                lh = ρσ_unpack[0];
                rh = ρσ_unpack[1];
            }
            left_overlaps = elements_overlap(lh, b);
            right_overlaps = elements_overlap(rh, b);
            if (!left_overlaps || !right_overlaps) {
                h = (left_overlaps) ? lh : rh;
                d1 = d2 = 2 * available_width;
                q1 = h.left - bar_width - 1;
                if (q1 > -buffer && !overlaps_a_handle(q1, top)) {
                    d1 = abs(left - q1);
                }
                q2 = h.right + 1;
                if (q2 + bar_width < available_width + buffer && !overlaps_a_handle(q2, top)) {
                    d2 = abs(left - q2);
                }
                d = min(d1, d2);
                if (d < available_width) {
                    return (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["left"] = (d === d1) ? q1 : q2;
                        return ρσ_d;
                    }).call(this);
                }
            }
            d1 = d2 = d3 = 2 * available_width;
            q1 = lh.left - bar_width - 1;
            if (q1 > -buffer && !overlaps_a_handle(q1, top)) {
                d1 = abs(left - q1);
            }
            q2 = lh.right + 1;
            if (q2 + bar_width < rh.left + buffer && !overlaps_a_handle(q2, top)) {
                d2 = abs(left - q2);
            }
            q3 = rh.right + 1;
            if (q3 + bar_width < available_width + buffer && !overlaps_a_handle(q3, top)) {
                d3 = abs(left - q3);
            }
            d = min(d1, d2, d3);
            if (d < available_width) {
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["left"] = (d === d1) ? q1 : (d === d2) ? q2 : q3;
                    return ρσ_d;
                }).call(this);
            }
            ρσ_unpack = (lh.top <= rh.top) ? [lh, rh] : [rh, lh];
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            th = ρσ_unpack[0];
            bh = ρσ_unpack[1];
            d1 = d2 = d3 = 2 * available_height;
            q1 = th.top - bar_height - 1;
            if (q1 > -buffer && !overlaps_a_handle(left, q1)) {
                d1 = abs(top - q1);
            }
            q2 = th.bottom + 1;
            if (q2 + bar_height < bh.top + buffer && !overlaps_a_handle(left, q2)) {
                d2 = abs(top - q2);
            }
            q3 = bh.bottom + 1;
            if (q3 + bar_height < available_height + buffer && !overlaps_a_handle(left, q3)) {
                d3 = abs(top - q3);
            }
            d = min(d1, d2, d3);
            if (d < available_height) {
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["top"] = (d === d1) ? q1 + bar_height : (d === d2) ? q2 : q3;
                    ρσ_d["put_below"] = d !== d1;
                    return ρσ_d;
                }).call(this);
            }
            if (!overlaps_a_handle(buffer, buffer)) {
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["left"] = buffer;
                    ρσ_d["top"] = buffer + bar_height;
                    ρσ_d["put_below"] = false;
                    return ρσ_d;
                }).call(this);
            }
            if (!overlaps_a_handle(available_width - bar_width, buffer)) {
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["left"] = available_width - bar_width;
                    ρσ_d["top"] = buffer + bar_height;
                    ρσ_d["put_below"] = false;
                    return ρσ_d;
                }).call(this);
            }
            if (!overlaps_a_handle(buffer, available_height - bar_height)) {
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["left"] = buffer;
                    ρσ_d["top"] = available_height - bar_height;
                    ρσ_d["put_below"] = true;
                    return ρσ_d;
                }).call(this);
            }
            if (!overlaps_a_handle(available_width - bar_width, available_height - bar_height)) {
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["left"] = available_width - bar_width;
                    ρσ_d["top"] = available_height - bar_height;
                    ρσ_d["put_below"] = true;
                    return ρσ_d;
                }).call(this);
            }
        };
        if (!position_bar_avoiding_handles.__argnames__) Object.defineProperties(position_bar_avoiding_handles, {
            __argnames__ : {value: ["lh", "rh", "left", "top", "bar_width", "bar_height", "available_width", "available_height", "buffer"]},
            __module__ : {value: "read_book.selection_bar"}
        });

        function quick_highlight_icon(name, tooltip, hcolor) {
            var svg, u, ans;
            svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
            svg.setAttribute("style", "fill: currentColor; height: 2ex; width: 2ex; vertical-align: text-top; margin: 0");
            u = document.createElementNS("http://www.w3.org/2000/svg", "use");
            svg.appendChild(u);
            svg.firstChild.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "#icon-" + name);
            ans = ρσ_interpolate_kwargs.call(E, E.div, [svg, ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "width: " + ρσ_str.format("{}", ICON_SIZE) + "; height: 1ex; background-color: " + ρσ_str.format("{}", hcolor) + "; color: " + ρσ_str.format("{}", hcolor) + "; margin: 0"})])].concat([ρσ_desugar_kwargs({style: "width: " + ρσ_str.format("{}", ICON_SIZE) + "; height: " + ρσ_str.format("{}", ICON_SIZE) + "; display: flex; flex-direction: column", title: tooltip || ""})]));
            return ans;
        };
        if (!quick_highlight_icon.__argnames__) Object.defineProperties(quick_highlight_icon, {
            __argnames__ : {value: ["name", "tooltip", "hcolor"]},
            __module__ : {value: "read_book.selection_bar"}
        });

        function all_actions() {
            var qh;
            function a(icon, text, func, needs_highlight) {
                return (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["icon"] = icon;
                    ρσ_d["text"] = text;
                    ρσ_d["function_name"] = func;
                    ρσ_d["needs_highlight"] = !!needs_highlight;
                    ρσ_d["icon_function"] = (function() {
                        var ρσ_anonfunc = function (hcolor) {
                            return svgicon(icon, ICON_SIZE, ICON_SIZE, text);
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["hcolor"]},
                            __module__ : {value: "read_book.selection_bar"}
                        });
                        return ρσ_anonfunc;
                    })();
                    return ρσ_d;
                }).call(this);
            };
            if (!a.__argnames__) Object.defineProperties(a, {
                __argnames__ : {value: ["icon", "text", "func", "needs_highlight"]},
                __module__ : {value: "read_book.selection_bar"}
            });

            if (!all_actions.ans) {
                all_actions.ans = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["copy"] = a("copy", _("Copy to clipboard") + " [Ctrl+C]", "copy_to_clipboard");
                    ρσ_d["lookup"] = a("library", _("Lookup/search selected word") + " [L]", "lookup");
                    ρσ_d["quick_highlight"] = a("highlight", _("Quick highlight in current style") + " [Q]", "quick_highlight");
                    ρσ_d["highlight"] = a("highlight", _("Highlight selection") + " [H]", "create_highlight");
                    ρσ_d["search"] = a("search", _("Search for selection in the book") + " [F]", "book_search");
                    ρσ_d["bookmark"] = a("bookmark", _("Create a bookmark") + " [Ctrl+Alt+B]", "new_bookmark");
                    ρσ_d["search_net"] = a("global-search", _("Search for selection on the net") + " [S]", "internet_search");
                    ρσ_d["remove_highlight"] = a("trash", _("Remove this highlight") + _(" [Delete or D]"), "remove_highlight", true);
                    ρσ_d["clear"] = a("close", _("Clear selection") + " [Esc]", "clear_selection");
                    ρσ_d["speak"] = a("bullhorn", _("Read aloud") + " [T]", "speak_aloud");
                    ρσ_d["cite"] = a("reference-mode", _("Copy a citation to this text") + " [X]", "cite");
                    return ρσ_d;
                }).call(this);
                qh = all_actions.ans.quick_highlight;
                qh.icon_function = quick_highlight_icon.bind(null, qh.icon, qh.text);
            }
            return all_actions.ans;
        };
        if (!all_actions.__module__) Object.defineProperties(all_actions, {
            __module__ : {value: "read_book.selection_bar"}
        });

        function selection_handle() {
            var ans, s;
            ans = svgicon("selection-handle");
            s = ans.style;
            s.position = "absolute";
            s.boxSizing = "border-box";
            s.touchAction = "none";
            return ans;
        };
        if (!selection_handle.__module__) Object.defineProperties(selection_handle, {
            __module__ : {value: "read_book.selection_bar"}
        });

        function set_handle_color(handle, bg, fg) {
            var use;
            use = handle.querySelector("use");
            use.style.stroke = fg;
            use.style.fill = bg;
        };
        if (!set_handle_color.__argnames__) Object.defineProperties(set_handle_color, {
            __argnames__ : {value: ["handle", "bg", "fg"]},
            __module__ : {value: "read_book.selection_bar"}
        });

        function elements_overlap(a, b) {
            return a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
        };
        if (!elements_overlap.__argnames__) Object.defineProperties(elements_overlap, {
            __argnames__ : {value: ["a", "b"]},
            __module__ : {value: "read_book.selection_bar"}
        });

        HIDDEN = 0;
        WAITING = 1;
        DRAGGING = 2;
        EDITING = 3;
        function SelectionBar() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            SelectionBar.prototype.__bind_methods__.call(this);
            SelectionBar.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(SelectionBar.prototype, "__bind_methods__", {value: function () {
            this.set_handle_colors = SelectionBar.prototype.set_handle_colors.bind(this);
            this.build_bar = SelectionBar.prototype.build_bar.bind(this);
            this.show_quick_highlight_buttons = SelectionBar.prototype.show_quick_highlight_buttons.bind(this);
            this.show_notes = SelectionBar.prototype.show_notes.bind(this);
            this.mousedown_on_handle = SelectionBar.prototype.mousedown_on_handle.bind(this);
            this.touchstart_on_handle = SelectionBar.prototype.touchstart_on_handle.bind(this);
            this.start_handle_drag = SelectionBar.prototype.start_handle_drag.bind(this);
            this.container_context_menu_requested = SelectionBar.prototype.container_context_menu_requested.bind(this);
            this.container_clicked = SelectionBar.prototype.container_clicked.bind(this);
            this.mousemove_on_container = SelectionBar.prototype.mousemove_on_container.bind(this);
            this.touchmove_on_container = SelectionBar.prototype.touchmove_on_container.bind(this);
            this.move_handle = SelectionBar.prototype.move_handle.bind(this);
            this.end_handle_drag = SelectionBar.prototype.end_handle_drag.bind(this);
            this.mouseup_on_container = SelectionBar.prototype.mouseup_on_container.bind(this);
            this.touchend_on_container = SelectionBar.prototype.touchend_on_container.bind(this);
            this.on_wheel = SelectionBar.prototype.on_wheel.bind(this);
            this.on_keydown = SelectionBar.prototype.on_keydown.bind(this);
            this.report_failed_edit_highlight = SelectionBar.prototype.report_failed_edit_highlight.bind(this);
            this.run_drag_scroll = SelectionBar.prototype.run_drag_scroll.bind(this);
            this.do_one_drag_scroll = SelectionBar.prototype.do_one_drag_scroll.bind(this);
            this.send_drag_scroll_message = SelectionBar.prototype.send_drag_scroll_message.bind(this);
            this.end_drag_scroll = SelectionBar.prototype.end_drag_scroll.bind(this);
            this.hide = SelectionBar.prototype.hide.bind(this);
            this.show = SelectionBar.prototype.show.bind(this);
            this.focus = SelectionBar.prototype.focus.bind(this);
            this.update_position = SelectionBar.prototype.update_position.bind(this);
            this.place_single_handle = SelectionBar.prototype.place_single_handle.bind(this);
            this.position_handles = SelectionBar.prototype.position_handles.bind(this);
            this.position_undragged_handle = SelectionBar.prototype.position_undragged_handle.bind(this);
            this.show_editor = SelectionBar.prototype.show_editor.bind(this);
            this.place_editor = SelectionBar.prototype.place_editor.bind(this);
            this.hide_editor = SelectionBar.prototype.hide_editor.bind(this);
            this.add_notes_or_create_highlight = SelectionBar.prototype.add_notes_or_create_highlight.bind(this);
            this.editor_container_clicked = SelectionBar.prototype.editor_container_clicked.bind(this);
            this.copy_to_clipboard = SelectionBar.prototype.copy_to_clipboard.bind(this);
            this.lookup = SelectionBar.prototype.lookup.bind(this);
            this.book_search = SelectionBar.prototype.book_search.bind(this);
            this.new_bookmark = SelectionBar.prototype.new_bookmark.bind(this);
            this.internet_search = SelectionBar.prototype.internet_search.bind(this);
            this.clear_selection = SelectionBar.prototype.clear_selection.bind(this);
            this.speak_aloud = SelectionBar.prototype.speak_aloud.bind(this);
            this.cite = SelectionBar.prototype.cite.bind(this);
            this.create_highlight = SelectionBar.prototype.create_highlight.bind(this);
            this.quick_highlight = SelectionBar.prototype.quick_highlight.bind(this);
            this.quick_highlight_with_style = SelectionBar.prototype.quick_highlight_with_style.bind(this);
            this.remove_highlight = SelectionBar.prototype.remove_highlight.bind(this);
            this.remove_highlight_with_id = SelectionBar.prototype.remove_highlight_with_id.bind(this);
            this.edit_highlight = SelectionBar.prototype.edit_highlight.bind(this);
            this.send_message = SelectionBar.prototype.send_message.bind(this);
            this.notes_edited = SelectionBar.prototype.notes_edited.bind(this);
            this.handle_message = SelectionBar.prototype.handle_message.bind(this);
        }});
        Object.defineProperties(SelectionBar.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById("book-selection-bar-overlay");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "bar": {
                "enumerable": true, 
                "get": function bar() {
                    var self = this;
                    return document.getElementById(self.bar_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "start_handle": {
                "enumerable": true, 
                "get": function start_handle() {
                    var self = this;
                    return document.getElementById(self.start_handle_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "end_handle": {
                "enumerable": true, 
                "get": function end_handle() {
                    var self = this;
                    return document.getElementById(self.end_handle_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "editor": {
                "enumerable": true, 
                "get": function editor() {
                    var self = this;
                    return document.getElementById(self.editor_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "annotations_manager": {
                "enumerable": true, 
                "get": function annotations_manager() {
                    var self = this;
                    return self.view.annotations_manager;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "current_handle_position": {
                "enumerable": true, 
                "get": function current_handle_position() {
                    var self = this;
                    var ρσ_unpack, sh, eh, sbr, ebr;
                    ρσ_unpack = [self.start_handle, self.end_handle];
                    sh = ρσ_unpack[0];
                    eh = ρσ_unpack[1];
                    ρσ_unpack = [sh.getBoundingClientRect(), eh.getBoundingClientRect()];
                    sbr = ρσ_unpack[0];
                    ebr = ρσ_unpack[1];
                    if (!self.vertical) {
                        if (!self.rtl) {
                            return (function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["start"] = (function(){
                                    var ρσ_d = Object.create(null);
                                    ρσ_d["onscreen"] = sh.style.display !== "none";
                                    ρσ_d["x"] = Math.round(sbr.right);
                                    ρσ_d["y"] = Math.round(sbr.bottom - Math.floor(self.start_line_length / 2));
                                    return ρσ_d;
                                }).call(this);
                                ρσ_d["end"] = (function(){
                                    var ρσ_d = Object.create(null);
                                    ρσ_d["onscreen"] = eh.style.display !== "none";
                                    ρσ_d["x"] = Math.round(ebr.left);
                                    ρσ_d["y"] = Math.round(ebr.bottom - Math.floor(self.end_line_length / 2));
                                    return ρσ_d;
                                }).call(this);
                                return ρσ_d;
                            }).call(this);
                        } else {
                            return (function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["start"] = (function(){
                                    var ρσ_d = Object.create(null);
                                    ρσ_d["onscreen"] = sh.style.display !== "none";
                                    ρσ_d["x"] = Math.round(sbr.left);
                                    ρσ_d["y"] = Math.round(sbr.bottom - Math.floor(self.start_line_length / 2));
                                    return ρσ_d;
                                }).call(this);
                                ρσ_d["end"] = (function(){
                                    var ρσ_d = Object.create(null);
                                    ρσ_d["onscreen"] = eh.style.display !== "none";
                                    ρσ_d["x"] = Math.round(ebr.right);
                                    ρσ_d["y"] = Math.round(ebr.bottom - Math.floor(self.end_line_length / 2));
                                    return ρσ_d;
                                }).call(this);
                                return ρσ_d;
                            }).call(this);
                        }
                    } else if (self.rtl) {
                        return (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["start"] = (function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["onscreen"] = sh.style.display !== "none";
                                ρσ_d["x"] = Math.round(sbr.left + Math.floor(self.start_line_length / 2));
                                ρσ_d["y"] = Math.round(sbr.bottom);
                                return ρσ_d;
                            }).call(this);
                            ρσ_d["end"] = (function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["onscreen"] = eh.style.display !== "none";
                                ρσ_d["x"] = Math.round(ebr.right - Math.floor(self.end_line_length / 2));
                                ρσ_d["y"] = Math.round(ebr.top);
                                return ρσ_d;
                            }).call(this);
                            return ρσ_d;
                        }).call(this);
                    } else {
                        return (function(){
                            var ρσ_d = Object.create(null);
                            ρσ_d["start"] = (function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["onscreen"] = sh.style.display !== "none";
                                ρσ_d["x"] = Math.round(sbr.right - Math.floor(self.end_line_length / 2));
                                ρσ_d["y"] = Math.round(sbr.bottom);
                                return ρσ_d;
                            }).call(this);
                            ρσ_d["end"] = (function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["onscreen"] = eh.style.display !== "none";
                                ρσ_d["x"] = Math.round(ebr.left + Math.floor(self.start_line_length / 2));
                                ρσ_d["y"] = Math.round(ebr.top);
                                return ρσ_d;
                            }).call(this);
                            return ρσ_d;
                        }).call(this);
                    }
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "is_visible": {
                "enumerable": true, 
                "get": function is_visible() {
                    var self = this;
                    return self.container.style.display !== "none";
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        SelectionBar.prototype.__init__ = function __init__(view) {
            var self = this;
            var container, start_handle, end_handle, h, editor_div;
            self.view = view;
            self.current_highlight_style = new HighlightStyle(get_session_data().get("highlight_style"));
            self.current_notes = "";
            self.state = HIDDEN;
            self.start_handle_id = unique_id("handle");
            self.end_handle_id = unique_id("handle");
            self.bar_id = unique_id("bar");
            self.editor_id = unique_id("editor");
            self.quick_highlight_styles = [];
            self.ltr = true;
            self.rtl = false;
            self.vertical = false;
            container = self.container;
            container.style.overflow = "hidden";
            container.addEventListener("click", self.container_clicked, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("contextmenu", self.container_context_menu_requested, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("mouseup", self.mouseup_on_container, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("mousemove", self.mousemove_on_container, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("touchmove", self.touchmove_on_container, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("touchend", self.touchend_on_container, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("touchcancel", self.touchend_on_container, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("keydown", self.on_keydown, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("wheel", self.on_wheel, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.setAttribute("tabindex", "0");
            self.dragging_handle = null;
            self.position_in_handle = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["x"] = 0;
                ρσ_d["y"] = 0;
                return ρσ_d;
            }).call(this);
            self.active_touch = null;
            self.drag_scroll_timer = null;
            self.last_drag_scroll_at = null;
            self.start_line_length = self.end_line_length = 0;
            self.current_editor = null;
            start_handle = selection_handle();
            start_handle.id = self.start_handle_id;
            end_handle = selection_handle();
            end_handle.id = self.end_handle_id;
            var ρσ_Iter0 = ρσ_Iterable(ρσ_list_decorate([ start_handle, end_handle ]));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                h = ρσ_Iter0[ρσ_Index0];
                h.addEventListener("mousedown", self.mousedown_on_handle, (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["passive"] = false;
                    return ρσ_d;
                }).call(this));
                h.addEventListener("touchstart", self.touchstart_on_handle, (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["passive"] = false;
                    return ρσ_d;
                }).call(this));
                container.appendChild(h);
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: self.bar_id, style: "position: absolute; border: solid 1px currentColor; border-radius: 5px;left: 0; top: 0; display: flex; flex-direction: column;"})]));
            editor_div = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: self.editor_id, style: "position: absolute"})]);
            container.appendChild(editor_div);
            editor_div.addEventListener("click", self.editor_container_clicked, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            editor_div.addEventListener("wheel", (function() {
                var ρσ_anonfunc = function (ev) {
                    ev.stopPropagation();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.selection_bar"}
                });
                return ρσ_anonfunc;
            })(), (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = true;
                return ρσ_d;
            }).call(this));
        };
        if (!SelectionBar.prototype.__init__.__argnames__) Object.defineProperties(SelectionBar.prototype.__init__, {
            __argnames__ : {value: ["view"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.__argnames__ = SelectionBar.prototype.__init__.__argnames__;
        SelectionBar.__handles_kwarg_interpolation__ = SelectionBar.prototype.__init__.__handles_kwarg_interpolation__;
        SelectionBar.prototype.set_handle_colors = function set_handle_colors() {
            var self = this;
            var handle_fill, fg, h;
            handle_fill = get_color("window-background");
            fg = self.view.current_color_scheme.foreground;
            var ρσ_Iter1 = ρσ_Iterable(ρσ_list_decorate([ self.start_handle, self.end_handle ]));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                h = ρσ_Iter1[ρσ_Index1];
                set_handle_color(h, handle_fill, fg);
            }
        };
        if (!SelectionBar.prototype.set_handle_colors.__module__) Object.defineProperties(SelectionBar.prototype.set_handle_colors, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.build_bar = function build_bar(annot_id) {
            var self = this;
            var notes, bar_container, notes_container, x, bar, hs, actions, sd, ac, acname, selection_bar_quick_highlights;
            notes = self.annotations_manager.notes_for_highlight(annot_id);
            bar_container = self.bar;
            clear(bar_container);
            bar_container.style.maxWidth = "min(50rem, 90vw)";
            bar_container.style.backgroundColor = get_color("window-background");
            notes_container = E.div();
            notes_container.addEventListener("wheel", (function() {
                var ρσ_anonfunc = function (evt) {
                    evt.stopPropagation();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["evt"]},
                    __module__ : {value: "read_book.selection_bar"}
                });
                return ρσ_anonfunc;
            })(), (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            var ρσ_Iter2 = ρσ_Iterable(ρσ_list_decorate([ ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "height: 4ex; display: flex; align-items: center; padding: 5px; justify-content: center"})]), ρσ_interpolate_kwargs.call(E, E.hr, [ρσ_desugar_kwargs({style: "border-top: solid 1px; margin: 0; padding: 0; display: none"})]), ρσ_interpolate_kwargs.call(E, E.div, [notes_container].concat([ρσ_desugar_kwargs({style: "display: none; padding: 5px;"})])) ]));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                x = ρσ_Iter2[ρσ_Index2];
                bar_container.appendChild(x);
            }
            bar = bar_container.firstChild;
            hs = self.current_highlight_style.highlight_shade(self.view.current_color_scheme.is_dark_theme);
            function cb(ac, callback) {
                var ans;
                ans = ac.icon_function(hs);
                ans.addEventListener("click", (function() {
                    var ρσ_anonfunc = function (ev) {
                        [ev.stopPropagation(), ev.preventDefault()];
                        callback(ev);
                        self.view.focus_iframe();
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "read_book.selection_bar"}
                    });
                    return ρσ_anonfunc;
                })());
                ans.classList.add("simple-link");
                ans.style.marginLeft = ans.style.marginRight = BUTTON_MARGIN;
                return ans;
            };
            if (!cb.__argnames__) Object.defineProperties(cb, {
                __argnames__ : {value: ["ac", "callback"]},
                __module__ : {value: "read_book.selection_bar"}
            });

            actions = all_actions();
            sd = get_session_data();
            var ρσ_Iter3 = ρσ_Iterable(sd.get("selection_bar_actions"));
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                acname = ρσ_Iter3[ρσ_Index3];
                ac = actions[(typeof acname === "number" && acname < 0) ? actions.length + acname : acname];
                if (ac && (!ac.needs_highlight || !!annot_id)) {
                    bar.appendChild(cb(ac, self[ρσ_bound_index(ac.function_name, self)]));
                }
            }
            selection_bar_quick_highlights = sd.get("selection_bar_quick_highlights");
            self.quick_highlight_styles = [];
            if ((typeof selection_bar_quick_highlights !== "undefined" && selection_bar_quick_highlights !== null ? selection_bar_quick_highlights : Object.create(null)).length) {
                self.show_quick_highlight_buttons(bar, selection_bar_quick_highlights);
            }
            self.show_notes(bar_container, notes);
            return bar_container;
        };
        if (!SelectionBar.prototype.build_bar.__argnames__) Object.defineProperties(SelectionBar.prototype.build_bar, {
            __argnames__ : {value: ["annot_id"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.show_quick_highlight_buttons = function show_quick_highlight_buttons(bar, actions) {
            var self = this;
            var all, x, a, dark, hs, sc, sw, ρσ_unpack, i, key;
            all = (function() {
                var ρσ_Iter = ρσ_Iterable(all_styles()), ρσ_Result = Object.create(null), x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    ρσ_Result[x.key] = (x);
                }
                return ρσ_Result;
            })();
            actions = (function() {
                var ρσ_Iter = ρσ_Iterable(actions), ρσ_Result = [], a;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    a = ρσ_Iter[ρσ_Index];
                    if (all[(typeof a === "number" && a < 0) ? all.length + a : a]) {
                        ρσ_Result.push(a);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
            if (!actions.length) {
                return;
            }
            ρσ_interpolate_kwargs.call(actions, actions.pysort, [ρσ_desugar_kwargs({key: (function() {
                var ρσ_anonfunc = function (a) {
                    return (all[(typeof a === "number" && a < 0) ? all.length + a : a].friendly_name || "").toLowerCase();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["a"]},
                    __module__ : {value: "read_book.selection_bar"}
                });
                return ρσ_anonfunc;
            })()})]);
            self.quick_highlight_styles = actions;
            bar.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "background: currentColor; width: 1px; height: " + ρσ_str.format("{}", ICON_SIZE) + "; margin-left: " + ρσ_str.format("{}", BUTTON_MARGIN) + "; margin-right: " + ρσ_str.format("{}", BUTTON_MARGIN) + ""})]));
            dark = self.view.current_color_scheme.is_dark_theme;
            var ρσ_Iter4 = ρσ_Iterable(enumerate(actions));
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                ρσ_unpack = ρσ_Iter4[ρσ_Index4];
                i = ρσ_unpack[0];
                key = ρσ_unpack[1];
                hs = all[(typeof key === "number" && key < 0) ? all.length + key : key];
                if (i < 9) {
                    sc = i + 1;
                } else if ((i === 10 || typeof i === "object" && ρσ_equals(i, 10))) {
                    sc = 0;
                } else {
                    sc = null;
                }
                sw = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "simple-link", style: "margin-left: " + ρσ_str.format("{}", BUTTON_MARGIN) + "; margin-right: " + ρσ_str.format("{}", BUTTON_MARGIN) + "", title: (ρσ_expr_temp = _("Highlight using: {name}{sc}"), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.format, [ρσ_desugar_kwargs({name: hs.friendly_name, sc: (sc !== null) ? " [" + ρσ_str.format("{}", sc) + "]" : ""})])), onclick: self.quick_highlight_with_style.bind(null, hs)})]);
                hs.make_swatch(sw, dark);
                bar.appendChild(sw);
            }
        };
        if (!SelectionBar.prototype.show_quick_highlight_buttons.__argnames__) Object.defineProperties(SelectionBar.prototype.show_quick_highlight_buttons, {
            __argnames__ : {value: ["bar", "actions"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.show_notes = function show_notes(bar, notes) {
            var self = this;
            var notes_container, c;
            notes = (notes || "").strip();
            if (!notes) {
                return;
            }
            notes_container = bar.lastChild;
            c = notes_container.lastChild;
            notes_container.style.display = notes_container.previousSibling.style.display = "block";
            c.style.overflow = "auto";
            c.style.maxHeight = "min(20ex, 40vh)";
            render_notes(notes, c, true);
        };
        if (!SelectionBar.prototype.show_notes.__argnames__) Object.defineProperties(SelectionBar.prototype.show_notes, {
            __argnames__ : {value: ["bar", "notes"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.mousedown_on_handle = function mousedown_on_handle(ev) {
            var self = this;
            [ev.stopPropagation(), ev.preventDefault()];
            if (self.state === WAITING) {
                self.start_handle_drag(ev, ev.currentTarget);
            }
        };
        if (!SelectionBar.prototype.mousedown_on_handle.__argnames__) Object.defineProperties(SelectionBar.prototype.mousedown_on_handle, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.touchstart_on_handle = function touchstart_on_handle(ev) {
            var self = this;
            var touch;
            [ev.stopPropagation(), ev.preventDefault()];
            if (self.state === WAITING) {
                var ρσ_Iter5 = ρσ_Iterable(ev.changedTouches);
                for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                    touch = ρσ_Iter5[ρσ_Index5];
                    self.active_touch = touch.identifier;
                    self.start_handle_drag(touch, ev.currentTarget);
                    break;
                }
            }
        };
        if (!SelectionBar.prototype.touchstart_on_handle.__argnames__) Object.defineProperties(SelectionBar.prototype.touchstart_on_handle, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.start_handle_drag = function start_handle_drag(ev, handle) {
            var self = this;
            var r;
            self.state = DRAGGING;
            self.dragging_handle = handle.id;
            r = handle.getBoundingClientRect();
            self.position_in_handle.x = Math.round(ev.clientX - r.left);
            self.position_in_handle.y = Math.round(ev.clientY - r.top);
        };
        if (!SelectionBar.prototype.start_handle_drag.__argnames__) Object.defineProperties(SelectionBar.prototype.start_handle_drag, {
            __argnames__ : {value: ["ev", "handle"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.container_context_menu_requested = function container_context_menu_requested(ev) {
            var self = this;
            var pos;
            pos = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["x"] = ev.clientX;
                ρσ_d["y"] = ev.clientY;
                return ρσ_d;
            }).call(this);
            map_to_iframe_coords(pos, get_margins());
            ρσ_interpolate_kwargs.call(self, self.send_message, ["extend-to-point"].concat([ρσ_desugar_kwargs({pos: pos})]));
        };
        if (!SelectionBar.prototype.container_context_menu_requested.__argnames__) Object.defineProperties(SelectionBar.prototype.container_context_menu_requested, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.container_clicked = function container_clicked(ev) {
            var self = this;
            var now, pos, x;
            [ev.stopPropagation(), ev.preventDefault()];
            if (self.state === EDITING) {
                self.hide_editor(true);
            }
            if (self.state === WAITING) {
                now = window.performance.now();
                if (ev.shiftKey) {
                    pos = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["x"] = ev.clientX;
                        ρσ_d["y"] = ev.clientY;
                        return ρσ_d;
                    }).call(this);
                    map_to_iframe_coords(pos, get_margins());
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["extend-to-point"].concat([ρσ_desugar_kwargs({pos: pos})]));
                    return;
                }
                if (self.last_double_click_at && now - self.last_double_click_at < 500) {
                    self.send_message("extend-to-paragraph");
                    return;
                }
                var ρσ_Iter6 = ρσ_Iterable(ρσ_list_decorate([ self.bar, self.start_handle, self.end_handle ]));
                for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                    x = ρσ_Iter6[ρσ_Index6];
                    if (near_element(x, ev.clientX, ev.clientY)) {
                        return;
                    }
                }
            }
            self.clear_selection();
        };
        if (!SelectionBar.prototype.container_clicked.__argnames__) Object.defineProperties(SelectionBar.prototype.container_clicked, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.mousemove_on_container = function mousemove_on_container(ev) {
            var self = this;
            if (self.state !== DRAGGING) {
                return;
            }
            [ev.stopPropagation(), ev.preventDefault()];
            self.move_handle(ev);
        };
        if (!SelectionBar.prototype.mousemove_on_container.__argnames__) Object.defineProperties(SelectionBar.prototype.mousemove_on_container, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.touchmove_on_container = function touchmove_on_container(ev) {
            var self = this;
            var touch;
            if (self.state !== DRAGGING) {
                return;
            }
            [ev.stopPropagation(), ev.preventDefault()];
            var ρσ_Iter7 = ρσ_Iterable(ev.changedTouches);
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                touch = ρσ_Iter7[ρσ_Index7];
                if (touch.identifier === self.active_touch) {
                    self.move_handle(touch);
                    return;
                }
            }
        };
        if (!SelectionBar.prototype.touchmove_on_container.__argnames__) Object.defineProperties(SelectionBar.prototype.touchmove_on_container, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.move_handle = function move_handle(ev) {
            var self = this;
            var handle, s, rect, margins, pos, start, position, c, t, top, bottom;
            handle = document.getElementById(self.dragging_handle);
            s = handle.style;
            rect = self.container.getBoundingClientRect();
            s.left = ev.clientX - rect.left - self.position_in_handle.x + "px";
            s.top = ev.clientY - rect.top - self.position_in_handle.y + "px";
            margins = get_margins();
            pos = self.current_handle_position;
            if (self.dragging_handle === self.start_handle_id) {
                start = true;
                position = map_to_iframe_coords(pos.start, margins);
            } else {
                start = false;
                position = map_to_iframe_coords(pos.end, margins);
            }
            ρσ_interpolate_kwargs.call(self, self.send_message, ["move-end-of-selection"].concat([ρσ_desugar_kwargs({start: start, pos: position})]));
            c = self.container;
            rect = c.getBoundingClientRect();
            t = document.getElementById("book-top-margin").offsetHeight;
            top = rect.top + max(t, DRAG_SCROLL_ZONE_MIN_HEIGHT);
            t = document.getElementById("book-bottom-margin").offsetHeight;
            bottom = rect.bottom - max(t, DRAG_SCROLL_ZONE_MIN_HEIGHT);
            if (ev.clientY < top || ev.clientY > bottom) {
                self.run_drag_scroll(ev.clientY, top, bottom);
            } else {
                self.end_drag_scroll();
            }
        };
        if (!SelectionBar.prototype.move_handle.__argnames__) Object.defineProperties(SelectionBar.prototype.move_handle, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.end_handle_drag = function end_handle_drag() {
            var self = this;
            var handle;
            self.end_drag_scroll();
            handle = self.dragging_handle;
            self.dragging_handle = null;
            self.state = WAITING;
            window.setTimeout(self.update_position.bind(null, handle), 0);
        };
        if (!SelectionBar.prototype.end_handle_drag.__module__) Object.defineProperties(SelectionBar.prototype.end_handle_drag, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.mouseup_on_container = function mouseup_on_container(ev) {
            var self = this;
            if (self.state === DRAGGING) {
                [ev.preventDefault(), ev.stopPropagation()];
                self.end_handle_drag();
            }
        };
        if (!SelectionBar.prototype.mouseup_on_container.__argnames__) Object.defineProperties(SelectionBar.prototype.mouseup_on_container, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.touchend_on_container = function touchend_on_container(ev) {
            var self = this;
            var touch;
            if (self.state === DRAGGING) {
                [ev.preventDefault(), ev.stopPropagation()];
                var ρσ_Iter8 = ρσ_Iterable(ev.changedTouches);
                for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                    touch = ρσ_Iter8[ρσ_Index8];
                    if (touch.identifier === self.active_touch) {
                        self.active_touch = null;
                        self.end_handle_drag();
                        return;
                    }
                }
            }
        };
        if (!SelectionBar.prototype.touchend_on_container.__argnames__) Object.defineProperties(SelectionBar.prototype.touchend_on_container, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.on_wheel = function on_wheel(ev) {
            var self = this;
            [ev.stopPropagation(), ev.preventDefault()];
            if (self.state !== EDITING) {
                self.view.send_wheel_event_to_iframe(ev, "selection-mode");
            }
        };
        if (!SelectionBar.prototype.on_wheel.__argnames__) Object.defineProperties(SelectionBar.prototype.on_wheel, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.on_keydown = function on_keydown(ev) {
            var self = this;
            var k, all, x, key, hs, sc_name, forwarded;
            [ev.stopPropagation(), ev.preventDefault()];
            if (ev.key === "Escape") {
                if (self.state === EDITING) {
                    self.hide_editor();
                } else {
                    self.clear_selection();
                }
                return;
            }
            if (self.state === WAITING && !ev.ctrlKey && !ev.altKey && !ev.metaKey) {
                k = ev.key.toLowerCase();
                if (k === "l") {
                    self.lookup();
                    return;
                }
                if (k === "q") {
                    self.quick_highlight();
                    return;
                }
                if (k === "h") {
                    self.create_highlight();
                    return;
                }
                if (k === "f") {
                    self.book_search();
                    return;
                }
                if (k === "s") {
                    self.internet_search();
                    return;
                }
                if (k === "t") {
                    self.speak_aloud();
                    return;
                }
                if (k === "x") {
                    self.cite();
                    return;
                }
                if (k === "delete" || k === "d") {
                    self.remove_highlight();
                    return;
                }
                if (ρσ_in(k, "0123456789")) {
                    all = (function() {
                        var ρσ_Iter = ρσ_Iterable(all_styles()), ρσ_Result = Object.create(null), x;
                        for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                            x = ρσ_Iter[ρσ_Index];
                            ρσ_Result[x.key] = (x);
                        }
                        return ρσ_Result;
                    })();
                    k = int(k);
                    if (k === 0) {
                        k = 9;
                    } else {
                        k -= 1;
                    }
                    key = (ρσ_expr_temp = self.quick_highlight_styles)[(typeof k === "number" && k < 0) ? ρσ_expr_temp.length + k : k];
                    if (key) {
                        hs = all[(typeof key === "number" && key < 0) ? all.length + key : key];
                        if (hs) {
                            self.quick_highlight_with_style(hs);
                        }
                    }
                    return;
                }
            }
            sc_name = shortcut_for_key_event(ev, self.view.keyboard_shortcut_map);
            if (!sc_name) {
                return;
            }
            forwarded = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["toggle_highlights"] = true;
                ρσ_d["edit_book"] = true;
                ρσ_d["select_all"] = true;
                ρσ_d["extend_selection_to_end_of_line"] = true;
                ρσ_d["extend_selection_to_start_of_line"] = true;
                return ρσ_d;
            }).call(this);
            if (sc_name === "show_chrome") {
                self.clear_selection();
            } else if (sc_name === "copy_to_clipboard") {
                self.copy_to_clipboard();
            } else if (sc_name === "toggle_lookup") {
                self.lookup();
            } else if (ρσ_in(sc_name, ["up", "down", "pageup", "pagedown", "left", "right"])) {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["trigger-shortcut"].concat([ρσ_desugar_kwargs({name: sc_name})]));
            } else if (sc_name === "start_search") {
                self.book_search();
            } else if (sc_name === "new_bookmark") {
                self.new_bookmark();
            } else if (sc_name.startsWith("shrink_selection_by_") || sc_name.startsWith("extend_selection_by_") || forwarded[(typeof sc_name === "number" && sc_name < 0) ? forwarded.length + sc_name : sc_name]) {
                self.view.on_handle_shortcut((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["name"] = sc_name;
                    return ρσ_d;
                }).call(this));
            }
        };
        if (!SelectionBar.prototype.on_keydown.__argnames__) Object.defineProperties(SelectionBar.prototype.on_keydown, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.report_failed_edit_highlight = function report_failed_edit_highlight(annot_id) {
            var self = this;
            var notes, has_notes, title, text;
            notes = self.annotations_manager.notes_for_highlight(annot_id);
            has_notes = bool(notes);
            title = _("Highlight text missing");
            text = _("The text associated with this highlight could not be found in the book. This can happen if the book was modified. This highlight will be automatically removed.");
            if (runtime.is_standalone_viewer || !has_notes) {
                if (has_notes) {
                    ui_operations.copy_selection(notes);
                    text += " " + _("The notes for this highlight have been copied to the clipboard.");
                }
                error_dialog(title, text);
            } else {
                create_custom_dialog(title, (function() {
                    var ρσ_anonfunc = function (parent, close_modal) {
                        parent.appendChild(E.div(E.div(text), ρσ_interpolate_kwargs.call(E, E.div, [create_button(_("OK"), null, close_modal), ρσ_interpolate_kwargs.call(this, create_button, [_("Copy notes to clipboard"), null, (function() {
                            var ρσ_anonfunc = function () {
                                ui_operations.copy_selection(notes);
                                close_modal();
                            };
                            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                __module__ : {value: "read_book.selection_bar"}
                            });
                            return ρσ_anonfunc;
                        })()].concat([ρσ_desugar_kwargs({highlight: true})]))].concat([ρσ_desugar_kwargs({class_: "button-box"})]))));
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["parent", "close_modal"]},
                        __module__ : {value: "read_book.selection_bar"}
                    });
                    return ρσ_anonfunc;
                })());
            }
            self.remove_highlight_with_id(annot_id);
        };
        if (!SelectionBar.prototype.report_failed_edit_highlight.__argnames__) Object.defineProperties(SelectionBar.prototype.report_failed_edit_highlight, {
            __argnames__ : {value: ["annot_id"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.run_drag_scroll = function run_drag_scroll(mouse_y, top, bottom) {
            var self = this;
            var backwards;
            backwards = mouse_y <= top;
            self.do_one_drag_scroll(backwards, (backwards) ? top - mouse_y : mouse_y - bottom);
        };
        if (!SelectionBar.prototype.run_drag_scroll.__argnames__) Object.defineProperties(SelectionBar.prototype.run_drag_scroll, {
            __argnames__ : {value: ["mouse_y", "top", "bottom"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.do_one_drag_scroll = function do_one_drag_scroll(backwards, distance_from_boundary) {
            var self = this;
            var sd, in_flow_mode, interval, now;
            window.clearTimeout(self.drag_scroll_timer);
            self.drag_scroll_timer = null;
            if (self.state !== DRAGGING) {
                return;
            }
            sd = get_session_data();
            in_flow_mode = sd.get("read_mode") === "flow";
            interval = (in_flow_mode) ? 1e3 / sd.get("lines_per_sec_smooth") : 1200;
            self.drag_scroll_timer = window.setTimeout(self.do_one_drag_scroll.bind(null, backwards, distance_from_boundary), interval);
            now = window.performance.now();
            if (self.last_drag_scroll_at === null) {
                if (in_flow_mode) {
                    self.send_drag_scroll_message(backwards, (self.dragging_handle === self.start_handle_id) ? "left" : "right", true);
                }
                self.last_drag_scroll_at = now;
            } else if (now - self.last_drag_scroll_at > interval) {
                self.send_drag_scroll_message(backwards, (self.dragging_handle === self.start_handle_id) ? "left" : "right", true);
                self.last_drag_scroll_at = now;
            }
        };
        if (!SelectionBar.prototype.do_one_drag_scroll.__argnames__) Object.defineProperties(SelectionBar.prototype.do_one_drag_scroll, {
            __argnames__ : {value: ["backwards", "distance_from_boundary"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.send_drag_scroll_message = function send_drag_scroll_message(backwards, handle, extend_selection) {
            var self = this;
            ρσ_interpolate_kwargs.call(self, self.send_message, ["drag-scroll"].concat([ρσ_desugar_kwargs({backwards: backwards, handle: handle, extents: self.current_handle_position, extend_selection: extend_selection})]));
        };
        if (!SelectionBar.prototype.send_drag_scroll_message.__argnames__) Object.defineProperties(SelectionBar.prototype.send_drag_scroll_message, {
            __argnames__ : {value: ["backwards", "handle", "extend_selection"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.end_drag_scroll = function end_drag_scroll() {
            var self = this;
            if (self.drag_scroll_timer !== null) {
                window.clearTimeout(self.drag_scroll_timer);
                self.drag_scroll_timer = null;
                self.last_drag_scroll_at = null;
            }
        };
        if (!SelectionBar.prototype.end_drag_scroll.__module__) Object.defineProperties(SelectionBar.prototype.end_drag_scroll, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.hide = function hide() {
            var self = this;
            var was_shown;
            was_shown = self.state !== HIDDEN;
            self.state = HIDDEN;
            self.container.style.display = "none";
            self.view.focus_iframe();
            if (!was_shown && self.spoken_aloud_at_least_once) {
                ui_operations.speak_simple_text("");
                self.spoken_aloud_at_least_once = false;
            }
        };
        if (!SelectionBar.prototype.hide.__module__) Object.defineProperties(SelectionBar.prototype.hide, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.show = function show() {
            var self = this;
            var sd;
            sd = get_session_data();
            if (self.state === HIDDEN) {
                if (sd.get("show_selection_bar")) {
                    self.container.style.display = "block";
                    self.state = WAITING;
                    self.focus();
                }
            }
        };
        if (!SelectionBar.prototype.show.__module__) Object.defineProperties(SelectionBar.prototype.show, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.focus = function focus() {
            var self = this;
            self.container.focus();
        };
        if (!SelectionBar.prototype.focus.__module__) Object.defineProperties(SelectionBar.prototype.focus, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.update_position = function update_position(dragged_handle) {
            var self = this;
            var container, cs, h, ρσ_unpack, start, end, bar, bar_height, bar_width, buffer, limits, start_handle, end_handle, end_after_start, has_space_below, put_below, has_space_above, top, left, sh, eh, changed;
            container = self.container;
            cs = self.view.currently_showing.selection;
            self.bar.style.display = "none";
            self.set_handle_colors();
            if (self.state === DRAGGING) {
                self.show();
                self.position_undragged_handle();
                return;
            }
            if (self.state === EDITING) {
                self.start_handle.style.display = "none";
                self.end_handle.style.display = "none";
                self.show();
                self.place_editor();
                return;
            }
            self.start_handle.style.display = "none";
            self.end_handle.style.display = "none";
            self.editor.style.display = "none";
            if (!cs || cs.empty || typeof ρσ_exists.d(cs.drag_mouse_position).x === "number" || cs.selection_change_caused_by_search) {
                return self.hide();
            }
            if (!cs.start.onscreen && !cs.end.onscreen) {
                return self.hide();
            }
            self.rtl = cs.rtl;
            self.ltr = !self.rtl;
            self.vertical = cs.vertical;
            var ρσ_Iter9 = ρσ_Iterable(ρσ_list_decorate([ self.start_handle, self.end_handle ]));
            for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                h = ρσ_Iter9[ρσ_Index9];
                if (h.vertical !== self.vertical) {
                    h.vertical = self.vertical;
                    change_icon_image(h, (h.vertical) ? "selection-handle-vertical" : "selection-handle");
                }
            }
            self.show();
            self.bar.style.display = self.start_handle.style.display = self.end_handle.style.display = "block";
            ρσ_unpack = map_boundaries(cs, self.vertical, self.rtl);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            start = ρσ_unpack[0];
            end = ρσ_unpack[1];
            bar = self.build_bar(cs.annot_id);
            bar_height = bar.offsetHeight;
            bar_width = bar.offsetWidth;
            buffer = 2;
            limits = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["top"] = buffer;
                ρσ_d["bottom"] = container.offsetHeight - bar_height - buffer;
                ρσ_d["left"] = buffer;
                ρσ_d["right"] = container.offsetWidth - bar_width - buffer - 10;
                return ρσ_d;
            }).call(this);
            ρσ_unpack = [self.start_handle, self.end_handle];
            start_handle = ρσ_unpack[0];
            end_handle = ρσ_unpack[1];
            self.position_handles(start_handle, end_handle, start, end);
            function place_vertically(pos, put_below) {
                var top;
                if (put_below) {
                    top = pos;
                    bar.style.flexDirection = "column";
                } else {
                    top = pos - bar_height - buffer;
                    bar.style.flexDirection = "column-reverse";
                }
                bar.style.top = top + "px";
                return top;
            };
            if (!place_vertically.__argnames__) Object.defineProperties(place_vertically, {
                __argnames__ : {value: ["pos", "put_below"]},
                __module__ : {value: "read_book.selection_bar"}
            });

            if (dragged_handle) {
                if (dragged_handle !== self.end_handle_id) {
                    ρσ_unpack = [end, start];
                    start = ρσ_unpack[0];
                    end = ρσ_unpack[1];
                }
            } else {
                if (!cs.start_is_anchor) {
                    ρσ_unpack = [end, start];
                    start = ρσ_unpack[0];
                    end = ρσ_unpack[1];
                }
            }
            if (!end.onscreen && start.onscreen) {
                ρσ_unpack = [end, start];
                start = ρσ_unpack[0];
                end = ρσ_unpack[1];
            }
            end_after_start = start.y < end.y || start.y === end.y && start.x < end.x;
            if (end_after_start) {
                has_space_below = end.y + end.height < container.offsetHeight - bar_height - buffer;
                put_below = has_space_below;
            } else {
                has_space_above = end.y - bar_height - buffer > 0;
                put_below = !has_space_above;
            }
            top = place_vertically((put_below) ? end.y + end.height : end.y, put_below);
            left = end.x - Math.floor(bar_width / 2);
            left = max(limits.left, min(left, limits.right));
            bar.style.left = left + "px";
            ρσ_unpack = [start_handle.getBoundingClientRect(), end_handle.getBoundingClientRect()];
            sh = ρσ_unpack[0];
            eh = ρσ_unpack[1];
            changed = position_bar_avoiding_handles(sh, eh, left, top, bar_width, bar_height, container.offsetWidth - 10, container.offsetHeight, buffer);
            if (changed) {
                if (ρσ_exists.n(changed.top)) {
                    place_vertically(changed.top, changed.put_below);
                }
                if (ρσ_exists.n(changed.left)) {
                    bar.style.left = changed.left + "px";
                }
            }
        };
        if (!SelectionBar.prototype.update_position.__argnames__) Object.defineProperties(SelectionBar.prototype.update_position, {
            __argnames__ : {value: ["dragged_handle"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.place_single_handle = function place_single_handle(selection_size, handle, boundary, is_start) {
            var self = this;
            var s, width, height, bottom, top;
            s = handle.style;
            s.display = (boundary.onscreen) ? "block" : "none";
            selection_size = max(10, min(selection_size, 60));
            if (self.vertical) {
                width = selection_size * 2;
                height = int(width * 2 / 3);
            } else {
                height = selection_size * 2;
                width = int(height * 2 / 3);
            }
            s.width = "" + ρσ_str.format("{}", width) + "px";
            s.height = "" + ρσ_str.format("{}", height) + "px";
            s.transform = "none";
            if (!self.vertical) {
                bottom = boundary.y + boundary.height;
                top = bottom - height;
                s.top = "" + ρσ_str.format("{}", top) + "px";
                if (is_start) {
                    if (self.ltr) {
                        s.left = boundary.x - width + "px";
                        self.start_line_length = selection_size;
                    } else {
                        s.left = boundary.x + "px";
                        self.start_line_length = selection_size;
                        s.transform = "scaleX(-1)";
                    }
                } else {
                    if (self.ltr) {
                        s.left = boundary.x + "px";
                        self.end_line_length = selection_size;
                        s.transform = "scaleX(-1)";
                    } else {
                        s.left = boundary.x - width + "px";
                        self.end_line_length = selection_size;
                    }
                }
            } else {
                if (is_start) {
                    if (self.rtl) {
                        s.top = boundary.y - height + "px";
                        s.left = boundary.x + "px";
                        self.start_line_length = selection_size;
                        s.transform = "scaleX(-1) scaleY(-1)";
                    } else {
                        s.top = boundary.y - height + "px";
                        s.left = boundary.x - width + boundary.width + "px";
                        self.start_line_length = selection_size;
                        s.transform = "scaleY(-1)";
                    }
                } else {
                    if (self.rtl) {
                        s.top = boundary.y + "px";
                        s.left = boundary.x - width + boundary.width + "px";
                        self.end_line_length = selection_size;
                    } else {
                        s.top = boundary.y + "px";
                        s.left = boundary.x + "px";
                        self.end_line_length = selection_size;
                        s.transform = "scaleX(-1)";
                    }
                }
            }
        };
        if (!SelectionBar.prototype.place_single_handle.__argnames__) Object.defineProperties(SelectionBar.prototype.place_single_handle, {
            __argnames__ : {value: ["selection_size", "handle", "boundary", "is_start"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.position_handles = function position_handles(start_handle, end_handle, start, end) {
            var self = this;
            var selection_size;
            if (self.vertical) {
                selection_size = max(start.width, end.width);
            } else {
                selection_size = max(start.height, end.height);
            }
            self.place_single_handle(selection_size, start_handle, start, true);
            self.place_single_handle(selection_size, end_handle, end, false);
        };
        if (!SelectionBar.prototype.position_handles.__argnames__) Object.defineProperties(SelectionBar.prototype.position_handles, {
            __argnames__ : {value: ["start_handle", "end_handle", "start", "end"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.position_undragged_handle = function position_undragged_handle() {
            var self = this;
            var cs, ρσ_unpack, start, end, selection_size, handle, boundary, is_start;
            cs = self.view.currently_showing.selection;
            ρσ_unpack = map_boundaries(cs, self.vertical, self.rtl);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            start = ρσ_unpack[0];
            end = ρσ_unpack[1];
            if (!self.vertical) {
                selection_size = max(start.height, end.height);
            } else {
                selection_size = max(start.width, end.width);
            }
            if (self.dragging_handle === self.start_handle_id) {
                handle = self.end_handle;
                boundary = end;
                is_start = false;
            } else {
                handle = self.start_handle;
                boundary = start;
                is_start = true;
            }
            self.place_single_handle(selection_size, handle, boundary, is_start);
        };
        if (!SelectionBar.prototype.position_undragged_handle.__module__) Object.defineProperties(SelectionBar.prototype.position_undragged_handle, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.show_editor = function show_editor(highlight_style, notes) {
            var self = this;
            var x, container, cs;
            var ρσ_Iter10 = ρσ_Iterable(ρσ_list_decorate([ self.bar, self.start_handle, self.end_handle ]));
            for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                x = ρσ_Iter10[ρσ_Index10];
                x.style.display = "none";
            }
            container = self.editor;
            clear(container);
            container.style.display = "block";
            self.state = EDITING;
            cs = self.view.currently_showing.selection;
            self.current_editor = new EditNotesAndColors(container, self.view.current_color_scheme.is_dark_theme, notes, highlight_style, cs.annot_id, self.hide_editor);
            self.place_editor();
        };
        if (!SelectionBar.prototype.show_editor.__argnames__) Object.defineProperties(SelectionBar.prototype.show_editor, {
            __argnames__ : {value: ["highlight_style", "notes"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.place_editor = function place_editor() {
            var self = this;
            var ed, cs, ρσ_unpack, start, end, width, height, top, bottom, container, space_above, space_below, put_above, y, x;
            if (self.current_editor === null) {
                return;
            }
            ed = self.editor;
            cs = self.view.currently_showing.selection;
            ρσ_unpack = map_boundaries(cs, self.vertical, self.rtl);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            start = ρσ_unpack[0];
            end = ρσ_unpack[1];
            if (!start.onscreen && !end.onscreen) {
                return;
            }
            ρσ_unpack = [ed.offsetWidth, ed.offsetHeight];
            width = ρσ_unpack[0];
            height = ρσ_unpack[1];
            if (!start.onscreen) {
                start = end;
            }
            if (!end.onscreen) {
                end = start;
            }
            ρσ_unpack = (start.y <= end.y) ? [start, end] : [end, start];
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            top = ρσ_unpack[0];
            bottom = ρσ_unpack[1];
            container = self.container;
            ρσ_unpack = [top.y, container.offsetHeight - (bottom.y + bottom.height)];
            space_above = ρσ_unpack[0];
            space_below = ρσ_unpack[1];
            if (height <= min(space_above, space_below)) {
                put_above = space_above < space_below;
            } else {
                put_above = space_above > space_below;
            }
            if (put_above) {
                y = max(0, top.y - height);
            } else {
                y = bottom.y + bottom.height;
                if (y + height > container.offsetHeight) {
                    y = container.offsetHeight - height;
                }
            }
            x = max(0, end.x - Math.floor(width / 2));
            if (x + width > container.offsetWidth) {
                x = container.offsetWidth - width;
            }
            ed.style.left = x + "px";
            ed.style.top = y + "px";
        };
        if (!SelectionBar.prototype.place_editor.__module__) Object.defineProperties(SelectionBar.prototype.place_editor, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.hide_editor = function hide_editor(apply_changes) {
            var self = this;
            var ed;
            if (!apply_changes) {
                self.state = WAITING;
                self.update_position();
                self.focus();
                return;
            }
            ed = self.current_editor;
            self.current_editor = null;
            self.current_highlight_style = ed.current_style;
            self.current_notes = ed.current_notes;
            ρσ_interpolate_kwargs.call(self, self.send_message, ["apply-highlight"].concat([ρσ_desugar_kwargs({style: self.current_highlight_style.style, uuid: short_uuid(), existing: ed.annot_id, has_notes: !!self.current_notes})]));
            self.state = WAITING;
            self.update_position();
            get_session_data().set("highlight_style", self.current_highlight_style.style);
            self.focus();
        };
        if (!SelectionBar.prototype.hide_editor.__argnames__) Object.defineProperties(SelectionBar.prototype.hide_editor, {
            __argnames__ : {value: ["apply_changes"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.add_notes_or_create_highlight = function add_notes_or_create_highlight(notes, style) {
            var self = this;
            var annot_id, am, existing_notes, q;
            if (self.state === EDITING) {
                self.hide_editor();
            }
            annot_id = self.view.currently_showing.selection.annot_id;
            if (annot_id) {
                am = self.annotations_manager;
                existing_notes = am.notes_for_highlight(annot_id);
                if (existing_notes) {
                    notes = existing_notes + "\n\n------------------------------------\n\n" + notes;
                }
                q = am.style_for_highlight(annot_id);
                if (q) {
                    style = q;
                }
            }
            self.current_notes = notes;
            ρσ_interpolate_kwargs.call(self, self.send_message, ["apply-highlight"].concat([ρσ_desugar_kwargs({style: style, uuid: short_uuid(), has_notes: !!self.current_notes, existing: annot_id})]));
            self.state = WAITING;
            self.update_position();
            self.focus();
        };
        if (!SelectionBar.prototype.add_notes_or_create_highlight.__argnames__) Object.defineProperties(SelectionBar.prototype.add_notes_or_create_highlight, {
            __argnames__ : {value: ["notes", "style"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.editor_container_clicked = function editor_container_clicked(ev) {
            var self = this;
            [ev.stopPropagation(), ev.preventDefault()];
        };
        if (!SelectionBar.prototype.editor_container_clicked.__argnames__) Object.defineProperties(SelectionBar.prototype.editor_container_clicked, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.copy_to_clipboard = function copy_to_clipboard() {
            var self = this;
            self.view.copy_to_clipboard();
        };
        if (!SelectionBar.prototype.copy_to_clipboard.__module__) Object.defineProperties(SelectionBar.prototype.copy_to_clipboard, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.lookup = function lookup() {
            var self = this;
            if (ui_operations.toggle_lookup) {
                ui_operations.toggle_lookup(true);
            } else {
                self.view.overlay.show_word_actions(self.view.currently_showing.selection.text);
            }
        };
        if (!SelectionBar.prototype.lookup.__module__) Object.defineProperties(SelectionBar.prototype.lookup, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.book_search = function book_search() {
            var self = this;
            var cs;
            cs = ρσ_exists.d(ρσ_exists.d(self.view.currently_showing).selection).text;
            if (!cs || len(str.strip(cs)) < 2) {
                return error_dialog(_("Too little text"), _("Cannot search as too little text is selected. You must select at least two characters."));
            }
            self.view.show_search(true);
            self.clear_selection();
        };
        if (!SelectionBar.prototype.book_search.__module__) Object.defineProperties(SelectionBar.prototype.book_search, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.new_bookmark = function new_bookmark() {
            var self = this;
            self.view.new_bookmark();
        };
        if (!SelectionBar.prototype.new_bookmark.__module__) Object.defineProperties(SelectionBar.prototype.new_bookmark, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.internet_search = function internet_search() {
            var self = this;
            var text, q, url;
            text = self.view.currently_showing.selection.text;
            if (text) {
                q = encodeURIComponent(text);
                url = (ρσ_expr_temp = get_session_data().get("net_search_url"), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.format, [ρσ_desugar_kwargs({q: q})]));
                ui_operations.open_url(url);
            }
        };
        if (!SelectionBar.prototype.internet_search.__module__) Object.defineProperties(SelectionBar.prototype.internet_search, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.clear_selection = function clear_selection() {
            var self = this;
            self.view.on_handle_shortcut((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["name"] = "clear_selection";
                return ρσ_d;
            }).call(this));
            self.hide();
        };
        if (!SelectionBar.prototype.clear_selection.__module__) Object.defineProperties(SelectionBar.prototype.clear_selection, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.speak_aloud = function speak_aloud() {
            var self = this;
            var text;
            text = self.view.currently_showing.selection.text;
            if (text) {
                ui_operations.speak_simple_text(text);
                self.spoken_aloud_at_least_once = true;
            }
        };
        if (!SelectionBar.prototype.speak_aloud.__module__) Object.defineProperties(SelectionBar.prototype.speak_aloud, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.cite = function cite() {
            var self = this;
            self.send_message("cite-current-selection");
        };
        if (!SelectionBar.prototype.cite.__module__) Object.defineProperties(SelectionBar.prototype.cite, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.create_highlight = function create_highlight() {
            var self = this;
            var cs, hs, notes, am, q;
            cs = self.view.currently_showing.selection;
            hs = self.current_highlight_style;
            notes = "";
            if (cs.annot_id) {
                am = self.annotations_manager;
                q = am.style_for_highlight(cs.annot_id);
                if (q) {
                    hs = new HighlightStyle(q);
                }
                notes = am.notes_for_highlight(cs.annot_id) || notes;
                self.show();
            }
            self.show_editor(hs, notes);
        };
        if (!SelectionBar.prototype.create_highlight.__module__) Object.defineProperties(SelectionBar.prototype.create_highlight, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.quick_highlight = function quick_highlight() {
            var self = this;
            var cs, am;
            cs = self.view.currently_showing.selection;
            if (cs.text) {
                if (cs.annot_id) {
                    am = self.annotations_manager;
                    self.current_notes = am.notes_for_highlight(cs.annot_id) || "";
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["apply-highlight"].concat([ρσ_desugar_kwargs({style: self.current_highlight_style.style, uuid: short_uuid(), existing: cs.annot_id, has_notes: !!self.current_notes})]));
                } else {
                    self.current_notes = "";
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["apply-highlight"].concat([ρσ_desugar_kwargs({style: self.current_highlight_style.style, uuid: short_uuid(), has_notes: false})]));
                }
                self.state = WAITING;
                self.update_position();
            }
        };
        if (!SelectionBar.prototype.quick_highlight.__module__) Object.defineProperties(SelectionBar.prototype.quick_highlight, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.quick_highlight_with_style = function quick_highlight_with_style(hs) {
            var self = this;
            self.current_highlight_style = hs;
            self.quick_highlight();
        };
        if (!SelectionBar.prototype.quick_highlight_with_style.__argnames__) Object.defineProperties(SelectionBar.prototype.quick_highlight_with_style, {
            __argnames__ : {value: ["hs"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.remove_highlight = function remove_highlight() {
            var self = this;
            var annot_id, q, text, notes;
            annot_id = self.view.currently_showing.selection.annot_id;
            if (annot_id) {
                q = _("Are you sure you want to delete this highlight permanently?");
                text = self.annotations_manager.text_for_highlight(annot_id);
                if (text && text.length) {
                    if (text.length > 20) {
                        text = text.slice(0, 20) + "…";
                    }
                    notes = self.annotations_manager.notes_for_highlight(annot_id);
                    if (notes && notes.length) {
                        q = _("Are you sure you want to delete the highlighting of \"{}\" and the associated notes permanently?").format(text);
                    } else {
                        q = _("Are you sure you want to delete the highlighting of \"{}\" permanently?").format(text);
                    }
                }
                ρσ_interpolate_kwargs.call(this, question_dialog, [_("Are you sure?"), q, (function() {
                    var ρσ_anonfunc = function (yes) {
                        if (yes) {
                            self.remove_highlight_with_id(annot_id);
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["yes"]},
                        __module__ : {value: "read_book.selection_bar"}
                    });
                    return ρσ_anonfunc;
                })()].concat([ρσ_desugar_kwargs({skip_dialog_name: "confirm_remove_highlight"})]));
            }
        };
        if (!SelectionBar.prototype.remove_highlight.__module__) Object.defineProperties(SelectionBar.prototype.remove_highlight, {
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.remove_highlight_with_id = function remove_highlight_with_id(annot_id) {
            var self = this;
            ρσ_interpolate_kwargs.call(self, self.send_message, ["remove-highlight"].concat([ρσ_desugar_kwargs({uuid: annot_id})]));
            self.annotations_manager.delete_highlight(annot_id);
        };
        if (!SelectionBar.prototype.remove_highlight_with_id.__argnames__) Object.defineProperties(SelectionBar.prototype.remove_highlight_with_id, {
            __argnames__ : {value: ["annot_id"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.edit_highlight = function edit_highlight(annot_id) {
            var self = this;
            ρσ_interpolate_kwargs.call(self, self.send_message, ["edit-highlight"].concat([ρσ_desugar_kwargs({uuid: annot_id})]));
        };
        if (!SelectionBar.prototype.edit_highlight.__argnames__) Object.defineProperties(SelectionBar.prototype.edit_highlight, {
            __argnames__ : {value: ["annot_id"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.send_message = function send_message() {
            var self = this;
            var type = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            ρσ_interpolate_kwargs.call(self.view.iframe_wrapper, self.view.iframe_wrapper.send_message, ["annotations"].concat([ρσ_desugar_kwargs(kw, {type: type})]));
        };
        if (!SelectionBar.prototype.send_message.__handles_kwarg_interpolation__) Object.defineProperties(SelectionBar.prototype.send_message, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["type"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.notes_edited = function notes_edited(annot_id) {
            var self = this;
            var notes;
            notes = self.annotations_manager.notes_for_highlight(annot_id);
            ρσ_interpolate_kwargs.call(self, self.send_message, ["notes-edited"].concat([ρσ_desugar_kwargs({uuid: annot_id, has_notes: bool(notes)})]));
        };
        if (!SelectionBar.prototype.notes_edited.__argnames__) Object.defineProperties(SelectionBar.prototype.notes_edited, {
            __argnames__ : {value: ["annot_id"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.handle_message = function handle_message(msg) {
            var self = this;
            var notes, toc_family, before, annot_id, data, spine_index, cfi, url, ρσ_unpack, key, value, info, copy_info, link_prefix, text;
            if (msg.type === "highlight-applied") {
                notes = self.current_notes;
                self.current_notes = "";
                if (!msg.ok) {
                    return error_dialog(_("Highlighting failed"), _("Failed to apply highlighting, try adjusting extent of highlight"));
                }
                toc_family = [];
                if (msg.anchor_before) {
                    toc_family = family_for_toc_node(msg.anchor_before.id);
                } else {
                    before = get_toc_nodes_bordering_spine_item()[0];
                    if (before) {
                        toc_family = family_for_toc_node(before.id);
                    }
                }
                self.annotations_manager.add_highlight(msg, msg.style, notes, toc_family);
            } else if (msg.type === "highlight-overlapped") {
                question_dialog(_("Are you sure?"), _("This highlight overlaps existing highlights. Creating it will cause notes in the existing highlights to be lost. Create it anyway?"), (function() {
                    var ρσ_anonfunc = function (yes) {
                        if (yes) {
                            ρσ_interpolate_kwargs.call(self, self.send_message, ["apply-highlight-overwrite"].concat([ρσ_desugar_kwargs({style: msg.style, uuid: msg.uuid, existing: msg.existing, has_notes: msg.has_notes})]));
                        } else {
                            if (self.current_notes) {
                                self.show_editor(self.current_highlight_style, self.current_notes);
                            }
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["yes"]},
                        __module__ : {value: "read_book.selection_bar"}
                    });
                    return ρσ_anonfunc;
                })());
            } else if (msg.type === "edit-highlight") {
                if (self.state === WAITING) {
                    self.create_highlight();
                }
            } else if (msg.type === "edit-highlight-failed") {
                self.report_failed_edit_highlight(msg.uuid);
            } else if (msg.type === "double-click") {
                self.last_double_click_at = window.performance.now();
            } else if (msg.type === "cite-data") {
                annot_id = self.view.currently_showing.selection.annot_id;
                if (annot_id) {
                    data = self.annotations_manager.data_for_highlight(annot_id);
                    spine_index = self.view.currently_showing.spine_index;
                    cfi = self.annotations_manager.cfi_for_highlight(annot_id, spine_index);
                    if (runtime.is_standalone_viewer) {
                        url = get_current_link_prefix() + "?open_at=" + cfi;
                    } else {
                        url = get_current_link_prefix() + ("bookpos=" + ρσ_str.format("{}", cfi) + "");
                        var ρσ_Iter11 = ρσ_Iterable(Object.entries(parse_url_params()));
                        for (var ρσ_Index11 = 0; ρσ_Index11 < ρσ_Iter11.length; ρσ_Index11++) {
                            ρσ_unpack = ρσ_Iter11[ρσ_Index11];
                            key = ρσ_unpack[0];
                            value = ρσ_unpack[1];
                            if ((key !== "bookpos" && (typeof key !== "object" || ρσ_not_equals(key, "bookpos")))) {
                                url = url + ("&" + ρσ_str.format("{}", key) + "=" + ρσ_str.format("{}", value) + "");
                            }
                        }
                    }
                    info = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["text"] = data.highlighted_text;
                        ρσ_d["url"] = url;
                        ρσ_d["timestamp"] = data.timestamp;
                        ρσ_d["style_type"] = data.style.type;
                        ρσ_d["style_kind"] = data.style.kind;
                        ρσ_d["style_which"] = data.style.which;
                        ρσ_d["chapter"] = (data.toc_family_titles[0]) ? data.toc_family_titles[0] : "";
                        ρσ_d["notes"] = (ρσ_in("notes", data)) ? data.notes : "";
                        return ρσ_d;
                    }).call(this);
                    copy_info = (ρσ_expr_temp = get_session_data().get("cite_hl_template"), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.format, [ρσ_desugar_kwargs(info)]));
                } else {
                    spine_index = self.view.currently_showing.spine_index;
                    spine_index = (1 + spine_index) * 2;
                    cfi = msg.bounds.start;
                    link_prefix = get_current_link_prefix();
                    if (!link_prefix) {
                        return self.view.show_not_a_library_book_error();
                    }
                    text = msg.highlighted_text.replace(/\[/g, "\\[").replace(/\]/g, "\\]");
                    url = link_to_epubcfi("epubcfi(/" + ρσ_str.format("{}", spine_index) + "" + ρσ_str.format("{}", cfi) + ")", link_prefix);
                    info = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["text"] = text;
                        ρσ_d["url"] = url;
                        return ρσ_d;
                    }).call(this);
                    copy_info = (ρσ_expr_temp = get_session_data().get("cite_text_template"), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.format, [ρσ_desugar_kwargs(info)]));
                }
                ui_operations.copy_selection(copy_info);
            } else {
                print("Ignoring annotations message with unknown type:", msg.type);
            }
        };
        if (!SelectionBar.prototype.handle_message.__argnames__) Object.defineProperties(SelectionBar.prototype.handle_message, {
            __argnames__ : {value: ["msg"]},
            __module__ : {value: "read_book.selection_bar"}
        });
        SelectionBar.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        SelectionBar.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(SelectionBar.prototype, "__bases__", {value: []});
        
        
        
        
        
        
        
        

        ρσ_modules["read_book.selection_bar"].DRAG_SCROLL_ZONE_MIN_HEIGHT = DRAG_SCROLL_ZONE_MIN_HEIGHT;
        ρσ_modules["read_book.selection_bar"].BUTTON_MARGIN = BUTTON_MARGIN;
        ρσ_modules["read_book.selection_bar"].HIDDEN = HIDDEN;
        ρσ_modules["read_book.selection_bar"].WAITING = WAITING;
        ρσ_modules["read_book.selection_bar"].DRAGGING = DRAGGING;
        ρσ_modules["read_book.selection_bar"].EDITING = EDITING;
        ρσ_modules["read_book.selection_bar"].get_margins = get_margins;
        ρσ_modules["read_book.selection_bar"].get_overlay_origin = get_overlay_origin;
        ρσ_modules["read_book.selection_bar"].map_boundaries = map_boundaries;
        ρσ_modules["read_book.selection_bar"].map_to_iframe_coords = map_to_iframe_coords;
        ρσ_modules["read_book.selection_bar"].near_element = near_element;
        ρσ_modules["read_book.selection_bar"].position_bar_avoiding_handles = position_bar_avoiding_handles;
        ρσ_modules["read_book.selection_bar"].quick_highlight_icon = quick_highlight_icon;
        ρσ_modules["read_book.selection_bar"].all_actions = all_actions;
        ρσ_modules["read_book.selection_bar"].selection_handle = selection_handle;
        ρσ_modules["read_book.selection_bar"].set_handle_color = set_handle_color;
        ρσ_modules["read_book.selection_bar"].elements_overlap = elements_overlap;
        ρσ_modules["read_book.selection_bar"].SelectionBar = SelectionBar;
    })();

    (function(){
        var __name__ = "read_book.prefs.selection";
        var CONTAINER, develop;
        var E = ρσ_modules.elementmaker.E;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var create_simple_input_with_history = ρσ_modules.complete.create_simple_input_with_history;

        var clear = ρσ_modules.dom.clear;
        var svgicon = ρσ_modules.dom.svgicon;
        var unique_id = ρσ_modules.dom.unique_id;

        var _ = ρσ_modules.gettext.gettext;

        var is_dark_theme = ρσ_modules["read_book.globals"].is_dark_theme;

        var all_styles = ρσ_modules["read_book.highlights"].all_styles;

        var create_button_box = ρσ_modules["read_book.prefs.utils"].create_button_box;

        var all_actions = ρσ_modules["read_book.selection_bar"].all_actions;

        var session_defaults = ρσ_modules.session.session_defaults;

        CONTAINER = unique_id("selection-settings");
        function set_actions(use_defaults) {
            var c, adef, sd, actions, current, x, available_actions, quick_actions;
            c = get_container();
            adef = all_actions();
            sd = get_session_data();
            actions = (use_defaults) ? session_defaults().selection_bar_actions : sd.get("selection_bar_actions");
            current = (function() {
                var ρσ_Iter = ρσ_Iterable(actions), ρσ_Result = [], x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    if (adef[(typeof x === "number" && x < 0) ? adef.length + x : x]) {
                        ρσ_Result.push(x);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
            c.querySelector(".current-actions").dataset.actions = JSON.stringify(current);
            available_actions = (function() {
                var ρσ_Iter = ρσ_Iterable(adef), ρσ_Result = [], x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    if (current.indexOf(x) === -1) {
                        ρσ_Result.push(x);
                    }
                }
                ρσ_Result = ρσ_list_constructor(ρσ_Result);
                return ρσ_Result;
            })();
            c.querySelector(".available-actions").dataset.actions = JSON.stringify(available_actions);
            update_action_tables();
            quick_actions = (use_defaults) ? session_defaults().selection_bar_quick_highlights : sd.get("selection_bar_quick_highlights");
            c.querySelector(".quick-actions").dataset.actions = JSON.stringify(quick_actions);
            update_quick_action_table();
        };
        if (!set_actions.__argnames__) Object.defineProperties(set_actions, {
            __argnames__ : {value: ["use_defaults"]},
            __module__ : {value: "read_book.prefs.selection"}
        });

        function restore_defaults() {
            var container, sd, val, control, ta;
            container = get_container();
            sd = session_defaults();
            var ρσ_Iter0 = ρσ_Iterable(container.querySelectorAll("input[name]"));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                control = ρσ_Iter0[ρσ_Index0];
                val = sd[ρσ_bound_index(control.getAttribute("name"), sd)];
                if (control.type === "checkbox") {
                    control.checked = val;
                } else if (control.type === "number") {
                    control.valueAsNumber = val;
                } else {
                    control.value = val;
                }
            }
            var ρσ_Iter1 = ρσ_Iterable(container.querySelectorAll("textarea[name]"));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                ta = ρσ_Iter1[ρσ_Index1];
                val = sd[ρσ_bound_index(ta.getAttribute("name"), sd)];
                ta.value = val;
            }
            set_actions(true);
        };
        if (!restore_defaults.__module__) Object.defineProperties(restore_defaults, {
            __module__ : {value: "read_book.prefs.selection"}
        });

        function get_container() {
            return document.getElementById(CONTAINER);
        };
        if (!get_container.__module__) Object.defineProperties(get_container, {
            __module__ : {value: "read_book.prefs.selection"}
        });

        function transfer(name, frm, to_) {
            var c, actions, idx;
            c = get_container().querySelector("." + frm);
            actions = JSON.parse(c.dataset.actions);
            idx = actions.indexOf(name);
            actions.splice(idx, 1);
            c.dataset.actions = JSON.stringify(actions);
            c = get_container().querySelector("." + to_);
            actions = JSON.parse(c.dataset.actions);
            if (to_ === "current-actions") {
                actions.unshift(name);
            } else {
                actions.push(name);
            }
            c.dataset.actions = JSON.stringify(actions);
            update_action_tables();
        };
        if (!transfer.__argnames__) Object.defineProperties(transfer, {
            __argnames__ : {value: ["name", "frm", "to_"]},
            __module__ : {value: "read_book.prefs.selection"}
        });

        function add_action(name) {
            transfer(name, "available-actions", "current-actions");
        };
        if (!add_action.__argnames__) Object.defineProperties(add_action, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "read_book.prefs.selection"}
        });

        function remove_action(name) {
            transfer(name, "current-actions", "available-actions");
        };
        if (!remove_action.__argnames__) Object.defineProperties(remove_action, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "read_book.prefs.selection"}
        });

        function move_action(name, up) {
            var c, actions, idx, delta, new_idx, ρσ_unpack, a, b;
            c = get_container().querySelector(".current-actions");
            actions = JSON.parse(c.dataset.actions);
            idx = actions.indexOf(name);
            delta = (up) ? -1 : 1;
            new_idx = (idx + delta + len(actions)) % len(actions);
            ρσ_unpack = [actions[(typeof idx === "number" && idx < 0) ? actions.length + idx : idx], 
            actions[(typeof new_idx === "number" && new_idx < 0) ? actions.length + new_idx : new_idx]];
            a = ρσ_unpack[0];
            b = ρσ_unpack[1];
            ρσ_unpack = [a, b];
            actions[(typeof new_idx === "number" && new_idx < 0) ? actions.length + new_idx : new_idx] = ρσ_unpack[0];
            actions[(typeof idx === "number" && idx < 0) ? actions.length + idx : idx] = ρσ_unpack[1];
            c.dataset.actions = JSON.stringify(actions);
            update_action_tables();
        };
        if (!move_action.__argnames__) Object.defineProperties(move_action, {
            __argnames__ : {value: ["name", "up"]},
            __module__ : {value: "read_book.prefs.selection"}
        });

        function build_action_table(container, is_current) {
            var adef, table, ac, buttons, icon, action_name;
            clear(container);
            adef = all_actions();
            table = ρσ_interpolate_kwargs.call(E, E.table, [ρσ_desugar_kwargs({style: "margin-left: 2rem"})]);
            container.appendChild(table);
            var ρσ_Iter2 = ρσ_Iterable(JSON.parse(container.dataset.actions));
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                action_name = ρσ_Iter2[ρσ_Index2];
                ac = adef[(typeof action_name === "number" && action_name < 0) ? adef.length + action_name : action_name];
                if (is_current) {
                    buttons = E.td(ρσ_interpolate_kwargs.call(E, E.span, [_("Remove")].concat([ρσ_desugar_kwargs({class_: "simple-link", onclick: remove_action.bind(null, action_name)})])), ρσ_interpolate_kwargs.call(E, E.span, [" "].concat([ρσ_desugar_kwargs({style: "min-width: 2rem; display: inline-block"})])), ρσ_interpolate_kwargs.call(E, E.span, [_("Up")].concat([ρσ_desugar_kwargs({class_: "simple-link", onclick: move_action.bind(null, action_name, true)})])), ρσ_interpolate_kwargs.call(E, E.span, [" "].concat([ρσ_desugar_kwargs({style: "min-width: 2rem; display: inline-block"})])), ρσ_interpolate_kwargs.call(E, E.span, [_("Down")].concat([ρσ_desugar_kwargs({class_: "simple-link", onclick: move_action.bind(null, action_name, false)})])));
                } else {
                    buttons = E.td(ρσ_interpolate_kwargs.call(E, E.span, [_("Add")].concat([ρσ_desugar_kwargs({class_: "simple-link", onclick: add_action.bind(null, action_name)})])));
                }
                buttons.style.paddingLeft = "2rem";
                if (ac.icon_function) {
                    icon = ac.icon_function("#add8ff");
                } else {
                    icon = svgicon(ac.icon);
                }
                table.appendChild(E.tr(ρσ_interpolate_kwargs.call(E, E.td, [icon].concat([ρσ_desugar_kwargs({style: "padding: 1ex"})])), E.td(ac.text), buttons));
            }
        };
        if (!build_action_table.__argnames__) Object.defineProperties(build_action_table, {
            __argnames__ : {value: ["container", "is_current"]},
            __module__ : {value: "read_book.prefs.selection"}
        });

        function update_action_tables() {
            var c, current;
            c = get_container();
            current = c.querySelector(".current-actions");
            build_action_table(current, true);
            current = c.querySelector(".available-actions");
            build_action_table(current, false);
        };
        if (!update_action_tables.__module__) Object.defineProperties(update_action_tables, {
            __module__ : {value: "read_book.prefs.selection"}
        });

        function update_quick_action_table() {
            var c, current, x, actions, hs;
            c = get_container().querySelector(".quick-actions");
            clear(c);
            c.style.display = "flex";
            c.style.flexWrap = "wrap";
            current = (function() {
                var ρσ_Iter = ρσ_Iterable(JSON.parse(c.dataset.actions)), ρσ_Result = Object.create(null), x;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    x = ρσ_Iter[ρσ_Index];
                    ρσ_Result[x] = (true);
                }
                return ρσ_Result;
            })();
            actions = list(all_styles());
            ρσ_interpolate_kwargs.call(actions, actions.pysort, [ρσ_desugar_kwargs({key: (function() {
                var ρσ_anonfunc = function (a) {
                    return (a.friendly_name || "").toLowerCase();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["a"]},
                    __module__ : {value: "read_book.prefs.selection"}
                });
                return ρσ_anonfunc;
            })()})]);
            var ρσ_Iter3 = ρσ_Iterable(actions);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                hs = ρσ_Iter3[ρσ_Index3];
                c.appendChild(ρσ_interpolate_kwargs.call(E, E.label, [hs.make_swatch(E.span(), is_dark_theme()), " ", ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox", value: hs.key, checked: current[ρσ_bound_index(hs.key, current)]})]), " ", hs.friendly_name].concat([ρσ_desugar_kwargs({style: "margin: 1ex; display: flex; align-contents: center"})])));
            }
        };
        if (!update_quick_action_table.__module__) Object.defineProperties(update_quick_action_table, {
            __module__ : {value: "read_book.prefs.selection"}
        });

        function selected_quick_actions() {
            var ans, c, inp;
            ans = [];
            c = get_container().querySelector(".quick-actions");
            var ρσ_Iter4 = ρσ_Iterable(c.querySelectorAll("input:checked"));
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                inp = ρσ_Iter4[ρσ_Index4];
                if (inp.value) {
                    ans.push(inp.value);
                }
            }
            return ans;
        };
        if (!selected_quick_actions.__module__) Object.defineProperties(selected_quick_actions, {
            __module__ : {value: "read_book.prefs.selection"}
        });

        function create_selection_panel(container, apply_func, cancel_func) {
            var sd;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: CONTAINER, style: "margin: 1rem"})]));
            container = container.lastChild;
            sd = get_session_data();
            function cb(name, text) {
                var ans;
                ans = ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox", name: name})]);
                if (sd.get(name)) {
                    ans.checked = true;
                }
                return ρσ_interpolate_kwargs.call(E, E.div, [E.label(ans, " " + text)].concat([ρσ_desugar_kwargs({style: "margin-top:1ex"})]));
            };
            if (!cb.__argnames__) Object.defineProperties(cb, {
                __argnames__ : {value: ["name", "text"]},
                __module__ : {value: "read_book.prefs.selection"}
            });

            function url(name, text, title) {
                var ans, inp;
                ans = ρσ_interpolate_kwargs.call(this, create_simple_input_with_history, [name].concat([ρσ_desugar_kwargs({input_type: "url"})]));
                inp = ans.querySelector("input[name=" + ρσ_str.format("{}", name) + "]");
                inp.value = sd.get(name) || "";
                inp.setAttribute("size", "50");
                inp.style.marginTop = "1ex";
                return ρσ_interpolate_kwargs.call(E, E.div, [E.label(text, E.br(), ans)].concat([ρσ_desugar_kwargs({style: "margin-top:1ex"})]));
            };
            if (!url.__argnames__) Object.defineProperties(url, {
                __argnames__ : {value: ["name", "text", "title"]},
                __module__ : {value: "read_book.prefs.selection"}
            });

            function cite_template_textarea(name, text, title) {
                var ans;
                ans = ρσ_interpolate_kwargs.call(E, E.textarea, [ρσ_desugar_kwargs({name: name, style: "width: 100%; margin-top: 1ex; box-sizing: border-box; flex-grow: 10"})]);
                ans.value = sd.get(name);
                return ρσ_interpolate_kwargs.call(E, E.div, [E.label(text, E.br(), ans)].concat([ρσ_desugar_kwargs({style: "margin-top:1ex"})]));
            };
            if (!cite_template_textarea.__argnames__) Object.defineProperties(cite_template_textarea, {
                __argnames__ : {value: ["name", "text", "title"]},
                __module__ : {value: "read_book.prefs.selection"}
            });

            container.appendChild(cb("show_selection_bar", _("Show a popup bar with common actions next to selected text")));
            container.appendChild(url("net_search_url", _("URL to query when searching the internet"), _("The {q} in the URL is replaced by the selected text")));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Customize which actions are shown in the selection popup bar")].concat([ρσ_desugar_kwargs({style: "margin-top: 2ex; border-top: solid 1px; padding-top: 1ex;"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.h3(_("Current actions")), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "current-actions"})]), E.h3(_("Available actions")), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "available-actions"})])].concat([ρσ_desugar_kwargs({style: "padding: 1ex; border-bottom: solid 1px; margin-bottom: 1ex"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.h3(_("Quick highlight actions")), E.div(_("Choose highlight styles that will have dedicated buttons in the selection bar to create highlights with a single click")), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: "quick-actions"})])].concat([ρσ_desugar_kwargs({style: "padding: 1ex; border-bottom: solid 1px; margin-bottom: 1ex"})])));
            container.appendChild(E.h3(_("Citing text")));
            container.appendChild(cite_template_textarea("cite_text_template", _("Template for citing plain text:")));
            container.appendChild(cite_template_textarea("cite_hl_template", _("Template for citing highlighted text:")));
            container.appendChild(E.div(ρσ_interpolate_kwargs.call(E, E.div, [(ρσ_expr_temp = _("{text} and {url} are available in both types of template. Additionally, {timestamp}, {chapter}, {notes}, {style_type}, {style_kind} and {style_which} are available when citing a highlight."), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.format, [ρσ_desugar_kwargs({text: "{text}", url: "{url}", chapter: "{chapter}", notes: "{notes}", style_type: "{style_type}", style_kind: "{style_kind}", style_which: "{style_which}", timestamp: "{timestamp}"})]))].concat([ρσ_desugar_kwargs({style: "margin-top: 2ex"})])), ρσ_interpolate_kwargs.call(E, E.div, [_("Use \"}}\" and \"{{\" to escape \"}\" and \"{\".")].concat([ρσ_desugar_kwargs({style: "margin-top: 2ex; margin-bottom: 2ex; border-bottom: solid 1px; padding-bottom: 1ex;"})]))));
            set_actions();
            container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func));
        };
        if (!create_selection_panel.__argnames__) Object.defineProperties(create_selection_panel, {
            __argnames__ : {value: ["container", "apply_func", "cancel_func"]},
            __module__ : {value: "read_book.prefs.selection"}
        });

        develop = create_selection_panel;
        function commit_selection(onchange) {
            var sd, container, changed, save_ev, x, name, val, control, actions, quick_highlights, old, ta;
            sd = get_session_data();
            container = get_container();
            changed = false;
            save_ev = new Event("save_history");
            var ρσ_Iter5 = ρσ_Iterable(container.querySelectorAll("[data-calibre-history-input]"));
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                x = ρσ_Iter5[ρσ_Index5];
                x.dispatchEvent(save_ev);
            }
            var ρσ_Iter6 = ρσ_Iterable(container.querySelectorAll("input[name]"));
            for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                control = ρσ_Iter6[ρσ_Index6];
                name = control.getAttribute("name");
                if (control.type === "checkbox") {
                    val = control.checked;
                } else if (control.type === "number") {
                    val = control.valueAsNumber;
                } else {
                    val = control.value;
                }
                if (val !== sd.get(name) && control.validity.valid) {
                    sd.set(name, val);
                    changed = true;
                }
            }
            actions = JSON.parse(container.querySelector(".current-actions").dataset.actions);
            if (ρσ_not_equals(list(actions), list(sd.get("selection_bar_actions")))) {
                changed = true;
                sd.set("selection_bar_actions", actions);
            }
            quick_highlights = selected_quick_actions();
            if (ρσ_not_equals(list(quick_highlights), list(sd.get("selection_bar_quick_highlights")))) {
                changed = true;
                sd.set("selection_bar_quick_highlights", quick_highlights);
            }
            var ρσ_Iter7 = ρσ_Iterable(container.querySelectorAll("textarea[name]"));
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                ta = ρσ_Iter7[ρσ_Index7];
                name = ta.getAttribute("name");
                val = (ta.value || "").strip() || (ρσ_expr_temp = session_defaults())[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name];
                old = sd.get(name);
                if (old !== val) {
                    sd.set(name, val);
                    changed = true;
                }
            }
            if (changed) {
                onchange();
            }
        };
        if (!commit_selection.__argnames__) Object.defineProperties(commit_selection, {
            __argnames__ : {value: ["onchange"]},
            __module__ : {value: "read_book.prefs.selection"}
        });

        ρσ_modules["read_book.prefs.selection"].CONTAINER = CONTAINER;
        ρσ_modules["read_book.prefs.selection"].develop = develop;
        ρσ_modules["read_book.prefs.selection"].set_actions = set_actions;
        ρσ_modules["read_book.prefs.selection"].restore_defaults = restore_defaults;
        ρσ_modules["read_book.prefs.selection"].get_container = get_container;
        ρσ_modules["read_book.prefs.selection"].transfer = transfer;
        ρσ_modules["read_book.prefs.selection"].add_action = add_action;
        ρσ_modules["read_book.prefs.selection"].remove_action = remove_action;
        ρσ_modules["read_book.prefs.selection"].move_action = move_action;
        ρσ_modules["read_book.prefs.selection"].build_action_table = build_action_table;
        ρσ_modules["read_book.prefs.selection"].update_action_tables = update_action_tables;
        ρσ_modules["read_book.prefs.selection"].update_quick_action_table = update_quick_action_table;
        ρσ_modules["read_book.prefs.selection"].selected_quick_actions = selected_quick_actions;
        ρσ_modules["read_book.prefs.selection"].create_selection_panel = create_selection_panel;
        ρσ_modules["read_book.prefs.selection"].commit_selection = commit_selection;
    })();

    (function(){
        var __name__ = "read_book.prefs.touch";
        var CONTAINER, develop;
        var svgicon = ρσ_modules.dom.svgicon;

        var E = ρσ_modules.elementmaker.E;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var unique_id = ρσ_modules.dom.unique_id;

        var _ = ρσ_modules.gettext.gettext;

        var allowed_actions_for_flow_mode_drag = ρσ_modules["read_book.gestures"].allowed_actions_for_flow_mode_drag;
        var allowed_actions_for_flow_mode_flick = ρσ_modules["read_book.gestures"].allowed_actions_for_flow_mode_flick;
        var allowed_actions_for_paged_mode_swipe = ρσ_modules["read_book.gestures"].allowed_actions_for_paged_mode_swipe;
        var allowed_actions_for_tap = ρσ_modules["read_book.gestures"].allowed_actions_for_tap;
        var allowed_actions_for_two_fingers = ρσ_modules["read_book.gestures"].allowed_actions_for_two_fingers;
        var current_action_for_gesture_type = ρσ_modules["read_book.gestures"].current_action_for_gesture_type;
        var get_action_descriptions = ρσ_modules["read_book.gestures"].get_action_descriptions;

        var create_button_box = ρσ_modules["read_book.prefs.utils"].create_button_box;

        var GESTURE = ρσ_modules["read_book.touch"].GESTURE;
        var GESTURE_NAMES = ρσ_modules["read_book.touch"].GESTURE_NAMES;

        CONTAINER = unique_id("touch-settings");
        function restore_defaults() {
            apply_settings_to_ui(Object.create(null));
        };
        if (!restore_defaults.__module__) Object.defineProperties(restore_defaults, {
            __module__ : {value: "read_book.prefs.touch"}
        });

        function get_container() {
            return document.getElementById(CONTAINER);
        };
        if (!get_container.__module__) Object.defineProperties(get_container, {
            __module__ : {value: "read_book.prefs.touch"}
        });

        function apply_settings_to_ui(overrides) {
            var group_name, in_flow_mode, allowed_actions, option, gesture_type, current_action, select, group;
            overrides = overrides || Object.create(null);
            var ρσ_Iter0 = ρσ_Iterable(get_container().querySelectorAll("[data-group]"));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                group = ρσ_Iter0[ρσ_Index0];
                group_name = group.dataset.group;
                in_flow_mode = group_name.indexOf("flow") >= 0;
                var ρσ_Iter1 = ρσ_Iterable(group.querySelectorAll("select"));
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    select = ρσ_Iter1[ρσ_Index1];
                    allowed_actions = [];
                    var ρσ_Iter2 = ρσ_Iterable(select.querySelectorAll("option"));
                    for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                        option = ρσ_Iter2[ρσ_Index2];
                        allowed_actions.push(option.value);
                    }
                    gesture_type = select.name;
                    current_action = current_action_for_gesture_type(overrides, gesture_type, in_flow_mode);
                    if (allowed_actions.indexOf(current_action) < 0) {
                        current_action = current_action_for_gesture_type(Object.create(null), gesture_type, in_flow_mode);
                    }
                    if (!current_action || allowed_actions.indexOf(current_action) < 0) {
                        current_action = "none";
                    }
                    select.value = current_action;
                    select.dispatchEvent(new Event("change", (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["view"] = window;
                        ρσ_d["bubbles"] = true;
                        return ρσ_d;
                    }).call(this)));
                }
            }
        };
        if (!apply_settings_to_ui.__argnames__) Object.defineProperties(apply_settings_to_ui, {
            __argnames__ : {value: ["overrides"]},
            __module__ : {value: "read_book.prefs.touch"}
        });

        function get_overrides_from_ui() {
            var ans, group_name, in_flow_mode, attr, val, defval, select, group, which;
            ans = Object.create(null);
            var ρσ_Iter3 = ρσ_Iterable(get_container().querySelectorAll("[data-group]"));
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                group = ρσ_Iter3[ρσ_Index3];
                group_name = group.dataset.group;
                in_flow_mode = group_name.indexOf("flow") >= 0;
                if (group_name === "paged_swipe") {
                    attr = "paged_mode";
                } else if (group_name === "flow_swipe") {
                    attr = "flow_mode";
                } else {
                    attr = "common";
                }
                if (!ans[(typeof attr === "number" && attr < 0) ? ans.length + attr : attr]) {
                    ans[(typeof attr === "number" && attr < 0) ? ans.length + attr : attr] = Object.create(null);
                }
                var ρσ_Iter4 = ρσ_Iterable(group.querySelectorAll("select"));
                for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                    select = ρσ_Iter4[ρσ_Index4];
                    val = select.value;
                    defval = current_action_for_gesture_type(Object.create(null), select.name, in_flow_mode);
                    if (val !== defval) {
                        (ρσ_expr_temp = ans[(typeof attr === "number" && attr < 0) ? ans.length + attr : attr])[ρσ_bound_index(select.name, ρσ_expr_temp)] = val;
                    }
                }
            }
            var ρσ_Iter5 = ρσ_Iterable(Object.keys(ans));
            for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                which = ρσ_Iter5[ρσ_Index5];
                if (Object.keys(ans[(typeof which === "number" && which < 0) ? ans.length + which : which]).length === 0) {
                    delete ans[which];
                }
            }
            return ans;
        };
        if (!get_overrides_from_ui.__module__) Object.defineProperties(get_overrides_from_ui, {
            __module__ : {value: "read_book.prefs.touch"}
        });

        function create_touch_panel(container, apply_func, cancel_func) {
            var sd, overrides, action_descriptions, in_flow_mode, c, aat, aap, aaf;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: CONTAINER, style: "margin: 1rem"})]));
            container = container.lastChild;
            sd = get_session_data();
            overrides = sd.get("gesture_overrides");
            action_descriptions = get_action_descriptions();
            in_flow_mode = false;
            function on_select_change(ev) {
                var select, ad, span;
                select = ev.target;
                ad = action_descriptions[ρσ_bound_index(select.value, action_descriptions)];
                span = select.parentNode.parentNode.querySelector(".help-text");
                span.textContent = ad.long;
            };
            if (!on_select_change.__argnames__) Object.defineProperties(on_select_change, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "read_book.prefs.touch"}
            });

            function make_setting(gesture_type, allowed_actions) {
                var ans, title, sid, select, ad, action, c;
                ans = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-top: 1ex; display: flex; flex-direction: column"})]);
                title = (ρσ_expr_temp = GESTURE_NAMES())[(typeof gesture_type === "number" && gesture_type < 0) ? ρσ_expr_temp.length + gesture_type : gesture_type];
                sid = unique_id(gesture_type);
                ans.appendChild(E.h4(ρσ_interpolate_kwargs.call(E, E.label, [title].concat([ρσ_desugar_kwargs({"for": sid})]))));
                select = ρσ_interpolate_kwargs.call(E, E.select, [ρσ_desugar_kwargs({name: gesture_type, id: sid})]);
                var ρσ_Iter6 = ρσ_Iterable(allowed_actions);
                for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                    action = ρσ_Iter6[ρσ_Index6];
                    ad = action_descriptions[(typeof action === "number" && action < 0) ? action_descriptions.length + action : action];
                    select.appendChild(ρσ_interpolate_kwargs.call(E, E.option, [ad.short].concat([ρσ_desugar_kwargs({value: action})])));
                }
                select.addEventListener("change", on_select_change);
                c = ρσ_interpolate_kwargs.call(E, E.div, [select, E.span(svgicon("angle-down"))].concat([ρσ_desugar_kwargs({data_component: "select"})]));
                ans.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [c, ρσ_interpolate_kwargs.call(E, E.span, [ρσ_desugar_kwargs({class_: "help-text", style: "font-size: smaller; font-style: italic"})])].concat([ρσ_desugar_kwargs({style: "display: flex; flex-wrap: wrap; gap: 1ex; align-items: center"})])));
                on_select_change((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["target"] = select;
                    return ρσ_d;
                }).call(this));
                return ans;
            };
            if (!make_setting.__argnames__) Object.defineProperties(make_setting, {
                __argnames__ : {value: ["gesture_type", "allowed_actions"]},
                __module__ : {value: "read_book.prefs.touch"}
            });

            container.appendChild(E.h2(_("Tapping")));
            container.appendChild(E.div(_("There are three tap zones, depending on where on the screen you tap. When the tap is on a link, the link is followed, otherwise a configurable action based on the zone is performed.")));
            c = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({"data-group": "tap"})]);
            container.appendChild(c);
            aat = allowed_actions_for_tap();
            c.appendChild(make_setting(GESTURE.control_zone_tap, aat));
            c.appendChild(make_setting(GESTURE.forward_zone_tap, aat));
            c.appendChild(make_setting(GESTURE.back_zone_tap, aat));
            c.appendChild(make_setting(GESTURE.long_tap, aat));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.hr, [ρσ_desugar_kwargs({style: "margin-top:1ex; margin-bottom: 1ex"})]));
            container.appendChild(E.h2(_("Two finger gestures")));
            c = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({"data-group": "two_finger"})]);
            container.appendChild(c);
            aat = allowed_actions_for_two_fingers();
            c.appendChild(make_setting(GESTURE.two_finger_tap, aat));
            c.appendChild(make_setting(GESTURE.pinch_in, aat));
            c.appendChild(make_setting(GESTURE.pinch_out, aat));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.hr, [ρσ_desugar_kwargs({style: "margin-top:1ex; margin-bottom: 1ex"})]));
            container.appendChild(E.h2(_("Swiping")));
            container.appendChild(E.div(_("Swiping works differently in paged and flow mode, with different actions. For an English like language, swiping in the writing direction means swiping horizontally. For languages written vertically, it means swiping vertically. For languages written left-to-right \"going forward\" means swiping right-to-left, like turning a page with your finger.")));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.h3, [_("Swiping in paged mode")].concat([ρσ_desugar_kwargs({style: "padding-top: 1ex"})])));
            c = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({"data-group": "paged_swipe"})]);
            container.appendChild(c);
            aap = allowed_actions_for_paged_mode_swipe();
            c.appendChild(make_setting(GESTURE.flick_block_forward, aap));
            c.appendChild(make_setting(GESTURE.flick_block_backward, aap));
            c.appendChild(make_setting(GESTURE.flick_inline_forward, aap));
            c.appendChild(make_setting(GESTURE.flick_inline_backward, aap));
            c.appendChild(make_setting(GESTURE.swipe_inline_forward_hold, aap));
            c.appendChild(make_setting(GESTURE.swipe_inline_backward_hold, aap));
            c.appendChild(make_setting(GESTURE.swipe_block_forward_hold, aap));
            c.appendChild(make_setting(GESTURE.swipe_block_backward_hold, aap));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.hr, [ρσ_desugar_kwargs({style: "margin-top:1ex; margin-bottom: 1ex"})]));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.h3, [_("Swiping in flow mode")].concat([ρσ_desugar_kwargs({style: "padding-top: 1ex"})])));
            c = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({"data-group": "flow_swipe"})]);
            container.appendChild(c);
            in_flow_mode = true;
            in_flow_mode;
            aaf = allowed_actions_for_flow_mode_flick();
            c.appendChild(make_setting(GESTURE.flick_block_forward, aaf));
            c.appendChild(make_setting(GESTURE.flick_block_backward, aaf));
            c.appendChild(make_setting(GESTURE.flick_inline_forward, aaf));
            c.appendChild(make_setting(GESTURE.flick_inline_backward, aaf));
            aaf = allowed_actions_for_flow_mode_drag();
            c.appendChild(make_setting(GESTURE.swipe_inline_backward_in_progress, aaf));
            c.appendChild(make_setting(GESTURE.swipe_inline_forward_in_progress, aaf));
            c.appendChild(make_setting(GESTURE.swipe_block_backward_in_progress, aaf));
            c.appendChild(make_setting(GESTURE.swipe_block_forward_in_progress, aaf));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.hr, [ρσ_desugar_kwargs({style: "margin-top:1ex; margin-bottom: 1ex"})]));
            container.appendChild(create_button_box(restore_defaults, apply_func, cancel_func));
            apply_settings_to_ui(overrides);
        };
        if (!create_touch_panel.__argnames__) Object.defineProperties(create_touch_panel, {
            __argnames__ : {value: ["container", "apply_func", "cancel_func"]},
            __module__ : {value: "read_book.prefs.touch"}
        });

        develop = create_touch_panel;
        function commit_touch(onchange) {
            var sd, current_overrides, overrides, changed;
            sd = get_session_data();
            current_overrides = sd.get("gesture_overrides");
            overrides = get_overrides_from_ui();
            changed = (overrides !== current_overrides && (typeof overrides !== "object" || ρσ_not_equals(overrides, current_overrides)));
            if (changed) {
                sd.set("gesture_overrides", overrides);
                onchange();
            }
        };
        if (!commit_touch.__argnames__) Object.defineProperties(commit_touch, {
            __argnames__ : {value: ["onchange"]},
            __module__ : {value: "read_book.prefs.touch"}
        });

        ρσ_modules["read_book.prefs.touch"].CONTAINER = CONTAINER;
        ρσ_modules["read_book.prefs.touch"].develop = develop;
        ρσ_modules["read_book.prefs.touch"].restore_defaults = restore_defaults;
        ρσ_modules["read_book.prefs.touch"].get_container = get_container;
        ρσ_modules["read_book.prefs.touch"].apply_settings_to_ui = apply_settings_to_ui;
        ρσ_modules["read_book.prefs.touch"].get_overrides_from_ui = get_overrides_from_ui;
        ρσ_modules["read_book.prefs.touch"].create_touch_panel = create_touch_panel;
        ρσ_modules["read_book.prefs.touch"].commit_touch = commit_touch;
    })();

    (function(){
        var __name__ = "read_book.prefs.user_stylesheet";
        var BLANK, develop;
        var E = ρσ_modules.elementmaker.E;

        var hexlify = ρσ_modules.encodings.hexlify;

        var _ = ρσ_modules.gettext.gettext;

        var absolute_path = ρσ_modules.ajax.absolute_path;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var ensure_id = ρσ_modules.dom.ensure_id;
        var unique_id = ρσ_modules.dom.unique_id;

        var runtime = ρσ_modules["read_book.globals"].runtime;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var create_button_box = ρσ_modules["read_book.prefs.utils"].create_button_box;

        var session_defaults = ρσ_modules.session.session_defaults;

        var FAKE_HOST = ρσ_modules["viewer.constants"].FAKE_HOST;
        var FAKE_PROTOCOL = ρσ_modules["viewer.constants"].FAKE_PROTOCOL;

        var create_button = ρσ_modules.widgets.create_button;
        var create_select = ρσ_modules.widgets.create_select;

        BLANK = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
        function change_background_image(img_id) {
            ui_operations.change_background_image(img_id);
        };
        if (!change_background_image.__argnames__) Object.defineProperties(change_background_image, {
            __argnames__ : {value: ["img_id"]},
            __module__ : {value: "read_book.prefs.user_stylesheet"}
        });

        function clear_image(img_id) {
            var i;
            i = document.getElementById(img_id);
            i.src = BLANK;
            i.dataset.url = "";
        };
        if (!clear_image.__argnames__) Object.defineProperties(clear_image, {
            __argnames__ : {value: ["img_id"]},
            __module__ : {value: "read_book.prefs.user_stylesheet"}
        });

        function modify_background_image_url_for_fetch(url) {
            var encoded, x;
            if (!url) {
                return BLANK;
            }
            if (runtime.is_standalone_viewer) {
                if (url.startswith("" + ρσ_str.format("{}", FAKE_PROTOCOL) + ":")) {
                    return url;
                }
                encoded = hexlify(url);
                return "" + ρσ_str.format("{}", FAKE_PROTOCOL) + "://" + ρσ_str.format("{}", FAKE_HOST) + "/reader-background-" + ρσ_str.format("{}", encoded) + "";
            }
            if (url.startswith("" + ρσ_str.format("{}", FAKE_PROTOCOL) + ":")) {
                x = (ρσ_expr_temp = str.split(url, "/"))[ρσ_expr_temp.length-1].partition("?")[0].partition("-")[2];
                return absolute_path("reader-background/" + ρσ_str.format("{}", x) + "");
            }
            return url;
        };
        if (!modify_background_image_url_for_fetch.__argnames__) Object.defineProperties(modify_background_image_url_for_fetch, {
            __argnames__ : {value: ["url"]},
            __module__ : {value: "read_book.prefs.user_stylesheet"}
        });

        function standalone_background_widget(sd) {
            var url, src, img_id;
            url = sd.get("background_image");
            src = modify_background_image_url_for_fetch(url);
            img_id = unique_id("bg-image");
            return ρσ_interpolate_kwargs.call(E, E.div, [E.div(ρσ_interpolate_kwargs.call(E, E.img, [ρσ_desugar_kwargs({src: src, data_url: url, id: img_id, class_: "bg-image-preview", style: "width: 75px; height: 75px; border: solid 1px"})])), ρσ_interpolate_kwargs.call(E, E.div, [" "].concat([ρσ_desugar_kwargs({style: "margin: 0.5rem"})])), ρσ_interpolate_kwargs.call(this, create_button, [_("Change image")].concat([ρσ_desugar_kwargs({action: change_background_image.bind(null, img_id)})])), ρσ_interpolate_kwargs.call(E, E.div, [" "].concat([ρσ_desugar_kwargs({style: "margin: 0.5rem"})])), ρσ_interpolate_kwargs.call(this, create_button, [_("Clear image")].concat([ρσ_desugar_kwargs({action: clear_image.bind(null, img_id)})]))].concat([ρσ_desugar_kwargs({style: "display: flex; align-items: center"})]));
        };
        if (!standalone_background_widget.__argnames__) Object.defineProperties(standalone_background_widget, {
            __argnames__ : {value: ["sd"]},
            __module__ : {value: "read_book.prefs.user_stylesheet"}
        });

        function background_widget(sd) {
            if (runtime.is_standalone_viewer) {
                return standalone_background_widget(sd);
            }
            return ρσ_interpolate_kwargs.call(E, E.div, [E.label(_("Image URL") + ": ", ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "url", name: "background_image", value: sd.get("background_image") || ""})]))].concat([ρσ_desugar_kwargs({style: "margin-bottom: 1ex"})]));
        };
        if (!background_widget.__argnames__) Object.defineProperties(background_widget, {
            __argnames__ : {value: ["sd"]},
            __module__ : {value: "read_book.prefs.user_stylesheet"}
        });

        function background_style_widget(sd) {
            var title, ρσ_unpack, c, s;
            title = _("Background image style");
            ρσ_unpack = ρσ_interpolate_kwargs.call(this, create_select, [title, sd.get("background_image_style")].concat([ρσ_desugar_kwargs({scaled: _("Scaled"), tiled: _("Tiled")})]));
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            c = ρσ_unpack[0];
            s = ρσ_unpack[1];
            s.setAttribute("name", "background_image_style");
            return ρσ_interpolate_kwargs.call(E, E.div, [E.label(title + ": ", c)].concat([ρσ_desugar_kwargs({style: "margin-bottom: 1ex"})]));
        };
        if (!background_style_widget.__argnames__) Object.defineProperties(background_style_widget, {
            __argnames__ : {value: ["sd"]},
            __module__ : {value: "read_book.prefs.user_stylesheet"}
        });

        function background_fade_widget(sd) {
            return E.div(E.label(_("Background image fade (%)") + ": ", ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({name: "background_image_fade", type: "number", max: "100", min: "0", step: "1", value: "" + sd.get("background_image_fade"), style: "min-width: 8ch", title: _("Fading of the background image is done by blending it with the background color")})])));
        };
        if (!background_fade_widget.__argnames__) Object.defineProperties(background_fade_widget, {
            __argnames__ : {value: ["sd"]},
            __module__ : {value: "read_book.prefs.user_stylesheet"}
        });

        function restore_defaults() {
            var container, i;
            container = document.getElementById(create_user_stylesheet_panel.container_id);
            container.querySelector("[name=user-stylesheet]").value = "";
            if (runtime.is_standalone_viewer) {
                i = container.querySelector("img");
                clear_image(i.id);
            } else {
                container.querySelector("[name=background_image]").value = "";
            }
            container.querySelector("select[name=background_image_style]").value = session_defaults().background_image_style;
            container.querySelector("input[name=background_image_fade]").value = str(session_defaults().background_image_fade);
        };
        if (!restore_defaults.__module__) Object.defineProperties(restore_defaults, {
            __module__ : {value: "read_book.prefs.user_stylesheet"}
        });

        function create_user_stylesheet_panel(container, apply_func, cancel_func) {
            var sd, val;
            sd = get_session_data();
            create_user_stylesheet_panel.container_id = ensure_id(container);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [_("Choose a background image to display behind the book text")].concat([ρσ_desugar_kwargs({style: "margin-bottom: 1.5ex"})])), background_widget(sd), background_style_widget(sd), background_fade_widget(sd)].concat([ρσ_desugar_kwargs({style: "border-bottom: solid 1px; margin-bottom: 1.5ex; padding-bottom: 1.5ex"})])), ρσ_interpolate_kwargs.call(E, E.div, [E.div(_("A CSS style sheet that can be used to control the look and feel of the text. For examples, click"), " ", ρσ_interpolate_kwargs.call(E, E.a, [_("here.")].concat([ρσ_desugar_kwargs({class_: "blue-link", title: _("Examples of user style sheets"), target: (runtime.is_standalone_viewer) ? "_self" : "_blank", href: "https://www.mobileread.com/forums/showthread.php?t=51500"})])), " ", _("Note that you can use the selectors body.calibre-viewer-paginated and body.calibre-viewer-scrolling to target the Paged and Flow modes. Similarly, use body.calibre-viewer-light-colors and body.calibre-viewer-dark-colors to target light and dark color schemes.")), ρσ_interpolate_kwargs.call(E, E.textarea, [ρσ_desugar_kwargs({name: "user-stylesheet", style: "width: 100%; margin-top: 1ex; box-sizing: border-box; flex-grow: 10"})])].concat([ρσ_desugar_kwargs({style: "flex-grow: 10; display: flex; flex-flow: column"})]))].concat([ρσ_desugar_kwargs({style: "min-height: 75vh; display: flex; flex-flow: column; margin: 1ex 1rem; padding: 1ex 0"})])));
            val = sd.get("user_stylesheet");
            if (val) {
                container.querySelector("[name=user-stylesheet]").value = val;
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [create_button_box(restore_defaults, apply_func, cancel_func)].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
        };
        if (!create_user_stylesheet_panel.__argnames__) Object.defineProperties(create_user_stylesheet_panel, {
            __argnames__ : {value: ["container", "apply_func", "cancel_func"]},
            __module__ : {value: "read_book.prefs.user_stylesheet"}
        });

        develop = create_user_stylesheet_panel;
        function commit_user_stylesheet(onchange, container) {
            var sd, ta, val, old, changed, bg_image, bis, bif;
            sd = get_session_data();
            ta = container.querySelector("[name=user-stylesheet]");
            val = ta.value || "";
            old = sd.get("user_stylesheet");
            changed = false;
            if (old !== val) {
                sd.set("user_stylesheet", val);
                changed = true;
            }
            if (runtime.is_standalone_viewer) {
                bg_image = container.querySelector("img.bg-image-preview").dataset.url;
                if (bg_image === BLANK || !bg_image) {
                    bg_image = null;
                }
            } else {
                bg_image = container.querySelector("input[name=background_image]").value;
            }
            old = sd.get("background_image");
            if (old !== bg_image) {
                sd.set("background_image", bg_image);
                changed = true;
            }
            old = sd.get("background_image_style");
            bis = container.querySelector("select[name=background_image_style]").value;
            if (bis !== old) {
                changed = true;
                sd.set("background_image_style", bis);
            }
            old = int(sd.get("background_image_fade"));
            bif = int(container.querySelector("input[name=background_image_fade]").value);
            if (old !== bif) {
                changed = true;
                sd.set("background_image_fade", bif);
            }
            if (changed) {
                onchange();
            }
        };
        if (!commit_user_stylesheet.__argnames__) Object.defineProperties(commit_user_stylesheet, {
            __argnames__ : {value: ["onchange", "container"]},
            __module__ : {value: "read_book.prefs.user_stylesheet"}
        });

        ρσ_modules["read_book.prefs.user_stylesheet"].BLANK = BLANK;
        ρσ_modules["read_book.prefs.user_stylesheet"].develop = develop;
        ρσ_modules["read_book.prefs.user_stylesheet"].change_background_image = change_background_image;
        ρσ_modules["read_book.prefs.user_stylesheet"].clear_image = clear_image;
        ρσ_modules["read_book.prefs.user_stylesheet"].modify_background_image_url_for_fetch = modify_background_image_url_for_fetch;
        ρσ_modules["read_book.prefs.user_stylesheet"].standalone_background_widget = standalone_background_widget;
        ρσ_modules["read_book.prefs.user_stylesheet"].background_widget = background_widget;
        ρσ_modules["read_book.prefs.user_stylesheet"].background_style_widget = background_style_widget;
        ρσ_modules["read_book.prefs.user_stylesheet"].background_fade_widget = background_fade_widget;
        ρσ_modules["read_book.prefs.user_stylesheet"].restore_defaults = restore_defaults;
        ρσ_modules["read_book.prefs.user_stylesheet"].create_user_stylesheet_panel = create_user_stylesheet_panel;
        ρσ_modules["read_book.prefs.user_stylesheet"].commit_user_stylesheet = commit_user_stylesheet;
    })();

    (function(){
        var __name__ = "read_book.prefs.main";
        var E = ρσ_modules.elementmaker.E;

        var build_list = ρσ_modules["book_list.item_list"].build_list;
        var create_item = ρσ_modules["book_list.item_list"].create_item;

        var create_top_bar = ρσ_modules["book_list.top_bar"].create_top_bar;
        var set_title = ρσ_modules["book_list.top_bar"].set_title;

        var clear = ρσ_modules.dom.clear;
        var ensure_id = ρσ_modules.dom.ensure_id;

        var _ = ρσ_modules.gettext.gettext;

        var runtime = ρσ_modules["read_book.globals"].runtime;

        var commit_colors = ρσ_modules["read_book.prefs.colors"].commit_colors;
        var create_colors_panel = ρσ_modules["read_book.prefs.colors"].create_colors_panel;

        var commit_fonts = ρσ_modules["read_book.prefs.fonts"].commit_fonts;
        var create_fonts_panel = ρσ_modules["read_book.prefs.fonts"].create_fonts_panel;

        var commit_head_foot = ρσ_modules["read_book.prefs.head_foot"].commit_head_foot;
        var create_head_foot_panel = ρσ_modules["read_book.prefs.head_foot"].create_head_foot_panel;

        var commit_keyboard = ρσ_modules["read_book.prefs.keyboard"].commit_keyboard;
        var create_keyboard_panel = ρσ_modules["read_book.prefs.keyboard"].create_keyboard_panel;

        var commit_layout = ρσ_modules["read_book.prefs.layout"].commit_layout;
        var create_layout_panel = ρσ_modules["read_book.prefs.layout"].create_layout_panel;

        var commit_misc = ρσ_modules["read_book.prefs.misc"].commit_misc;
        var create_misc_panel = ρσ_modules["read_book.prefs.misc"].create_misc_panel;

        var commit_scrolling = ρσ_modules["read_book.prefs.scrolling"].commit_scrolling;
        var create_scrolling_panel = ρσ_modules["read_book.prefs.scrolling"].create_scrolling_panel;

        var commit_selection = ρσ_modules["read_book.prefs.selection"].commit_selection;
        var create_selection_panel = ρσ_modules["read_book.prefs.selection"].create_selection_panel;

        var commit_touch = ρσ_modules["read_book.prefs.touch"].commit_touch;
        var create_touch_panel = ρσ_modules["read_book.prefs.touch"].create_touch_panel;

        var commit_user_stylesheet = ρσ_modules["read_book.prefs.user_stylesheet"].commit_user_stylesheet;
        var create_user_stylesheet_panel = ρσ_modules["read_book.prefs.user_stylesheet"].create_user_stylesheet_panel;

        function Prefs() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            Prefs.prototype.__bind_methods__.call(this);
            Prefs.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(Prefs.prototype, "__bind_methods__", {value: function () {
            this.set_top_title = Prefs.prototype.set_top_title.bind(this);
            this.onchange = Prefs.prototype.onchange.bind(this);
            this.cancel = Prefs.prototype.cancel.bind(this);
            this.onclose = Prefs.prototype.onclose.bind(this);
            this.create_panel = Prefs.prototype.create_panel.bind(this);
            this.display_panel = Prefs.prototype.display_panel.bind(this);
            this.show_panel = Prefs.prototype.show_panel.bind(this);
            this.display_top = Prefs.prototype.display_top.bind(this);
            this.display_fonts = Prefs.prototype.display_fonts.bind(this);
            this.close_fonts = Prefs.prototype.close_fonts.bind(this);
            this.display_misc = Prefs.prototype.display_misc.bind(this);
            this.close_misc = Prefs.prototype.close_misc.bind(this);
            this.display_colors = Prefs.prototype.display_colors.bind(this);
            this.close_colors = Prefs.prototype.close_colors.bind(this);
            this.display_layout = Prefs.prototype.display_layout.bind(this);
            this.close_layout = Prefs.prototype.close_layout.bind(this);
            this.display_user_stylesheet = Prefs.prototype.display_user_stylesheet.bind(this);
            this.close_user_stylesheet = Prefs.prototype.close_user_stylesheet.bind(this);
            this.display_head_foot = Prefs.prototype.display_head_foot.bind(this);
            this.close_head_foot = Prefs.prototype.close_head_foot.bind(this);
            this.display_keyboard = Prefs.prototype.display_keyboard.bind(this);
            this.close_keyboard = Prefs.prototype.close_keyboard.bind(this);
            this.display_scrolling = Prefs.prototype.display_scrolling.bind(this);
            this.close_scrolling = Prefs.prototype.close_scrolling.bind(this);
            this.display_selection = Prefs.prototype.display_selection.bind(this);
            this.close_selection = Prefs.prototype.close_selection.bind(this);
            this.display_touch = Prefs.prototype.display_touch.bind(this);
            this.close_touch = Prefs.prototype.close_touch.bind(this);
        }});
        Object.defineProperties(Prefs.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById(self.container_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        Prefs.prototype.__init__ = function __init__(container, close_func, on_change) {
            var self = this;
            self.close_func = close_func;
            self.on_change = on_change;
            self.main_title = _("Configure book reader");
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.div(), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "flex-grow: 100; overflow: auto"})])].concat([ρσ_desugar_kwargs({style: "contain: paint; width: 100%; height: 100%; display: flex; flex-direction: column", tabindex: "-1", onkeydown: (function() {
                var ρσ_anonfunc = function (ev) {
                    if (ev.key === "Escape") {
                        [ev.stopPropagation(), ev.preventDefault()];
                        if (!self.cancel()) {
                            self.close_func();
                        }
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.prefs.main"}
                });
                return ρσ_anonfunc;
            })()})])));
            container = container.firstChild;
            ρσ_interpolate_kwargs.call(this, create_top_bar, [container.firstChild].concat([ρσ_desugar_kwargs({title: self.main_title, icon: "close", action: self.onclose})]));
            self.container_id = ensure_id(container.lastChild);
            self.stack = ["top"];
            self.display_top(container.lastChild);
        };
        if (!Prefs.prototype.__init__.__argnames__) Object.defineProperties(Prefs.prototype.__init__, {
            __argnames__ : {value: ["container", "close_func", "on_change"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.__argnames__ = Prefs.prototype.__init__.__argnames__;
        Prefs.__handles_kwarg_interpolation__ = Prefs.prototype.__init__.__handles_kwarg_interpolation__;
        Prefs.prototype.set_top_title = function set_top_title(val) {
            var self = this;
            set_title(self.container.parentNode, val);
        };
        if (!Prefs.prototype.set_top_title.__argnames__) Object.defineProperties(Prefs.prototype.set_top_title, {
            __argnames__ : {value: ["val"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.onchange = function onchange() {
            var self = this;
            self.on_change();
        };
        if (!Prefs.prototype.onchange.__module__) Object.defineProperties(Prefs.prototype.onchange, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.cancel = function cancel() {
            var self = this;
            if (self.stack.length > 1) {
                self.stack.pop();
                self.display_panel((ρσ_expr_temp = self.stack)[ρσ_expr_temp.length-1]);
                return true;
            }
        };
        if (!Prefs.prototype.cancel.__module__) Object.defineProperties(Prefs.prototype.cancel, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.onclose = function onclose() {
            var self = this;
            var which, close_func;
            if (self.stack.length > 1) {
                which = self.stack.pop();
                close_func = getattr(self, "close_" + which, null);
                if (close_func) {
                    close_func.bind(self)();
                }
                self.display_panel((ρσ_expr_temp = self.stack)[ρσ_expr_temp.length-1]);
            } else {
                self.close_func();
            }
        };
        if (!Prefs.prototype.onclose.__module__) Object.defineProperties(Prefs.prototype.onclose, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.create_panel = function create_panel(container, which, create_func, needs_onchange) {
            var self = this;
            self.set_top_title((ρσ_expr_temp = self.title_map)[(typeof which === "number" && which < 0) ? ρσ_expr_temp.length + which : which] || which);
            if (needs_onchange) {
                create_func(container, self.onclose, self.cancel, self.onchange);
            } else {
                create_func(container, self.onclose, self.cancel);
            }
        };
        if (!Prefs.prototype.create_panel.__argnames__) Object.defineProperties(Prefs.prototype.create_panel, {
            __argnames__ : {value: ["container", "which", "create_func", "needs_onchange"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_panel = function display_panel(which) {
            var self = this;
            var container;
            container = self.container;
            clear(container);
            getattr(self, "display_" + which)(container);
            container.setAttribute("tabindex", "-1");
            container.focus();
        };
        if (!Prefs.prototype.display_panel.__argnames__) Object.defineProperties(Prefs.prototype.display_panel, {
            __argnames__ : {value: ["which"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.show_panel = function show_panel(which) {
            var self = this;
            self.stack.push(which);
            self.display_panel(which);
        };
        if (!Prefs.prototype.show_panel.__argnames__) Object.defineProperties(Prefs.prototype.show_panel, {
            __argnames__ : {value: ["which"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_top = function display_top(container) {
            var self = this;
            var c, items;
            self.set_top_title(self.main_title);
            c = E.div();
            container.appendChild(c);
            self.title_map = Object.create(null);
            items = ρσ_list_decorate([]);
            function ci(title, which, subtitle) {
                items.push(create_item(title, self.show_panel.bind(null, which), subtitle));
                (ρσ_expr_temp = self.title_map)[(typeof which === "number" && which < 0) ? ρσ_expr_temp.length + which : which] = title;
            };
            if (!ci.__argnames__) Object.defineProperties(ci, {
                __argnames__ : {value: ["title", "which", "subtitle"]},
                __module__ : {value: "read_book.prefs.main"}
            });

            ci(_("Colors"), "colors", _("Colors of the page and text"));
            ci(_("Page layout"), "layout", _("Page margins and number of pages per screen"));
            ci(_("Styles"), "user_stylesheet", _("Style rules for text and background image"));
            ci(_("Headers and footers"), "head_foot", _("Customize the headers and footers"));
            ci(_("Scrolling behavior"), "scrolling", _("Control how the viewer scrolls"));
            ci(_("Selection behavior"), "selection", _("Control how the viewer selects text"));
            ci(_("Touch behavior"), "touch", _("Customize what various touchscreen gestures do"));
            ci(_("Keyboard shortcuts"), "keyboard", _("Customize the keyboard shortcuts"));
            if (runtime.is_standalone_viewer) {
                ci(_("Fonts"), "fonts", _("Font choices"));
                ci(_("Miscellaneous"), "misc", _("Window size, last read position, toolbar, etc."));
            }
            build_list(c, items);
        };
        if (!Prefs.prototype.display_top.__argnames__) Object.defineProperties(Prefs.prototype.display_top, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_fonts = function display_fonts(container) {
            var self = this;
            self.create_panel(container, "fonts", create_fonts_panel);
        };
        if (!Prefs.prototype.display_fonts.__argnames__) Object.defineProperties(Prefs.prototype.display_fonts, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.close_fonts = function close_fonts() {
            var self = this;
            commit_fonts(self.onchange, self.container);
        };
        if (!Prefs.prototype.close_fonts.__module__) Object.defineProperties(Prefs.prototype.close_fonts, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_misc = function display_misc(container) {
            var self = this;
            self.create_panel(container, "misc", create_misc_panel);
        };
        if (!Prefs.prototype.display_misc.__argnames__) Object.defineProperties(Prefs.prototype.display_misc, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.close_misc = function close_misc() {
            var self = this;
            commit_misc(self.onchange, self.container);
        };
        if (!Prefs.prototype.close_misc.__module__) Object.defineProperties(Prefs.prototype.close_misc, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_colors = function display_colors(container) {
            var self = this;
            self.create_panel(container, "colors", create_colors_panel);
        };
        if (!Prefs.prototype.display_colors.__argnames__) Object.defineProperties(Prefs.prototype.display_colors, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.close_colors = function close_colors() {
            var self = this;
            commit_colors(self.onchange, self.container);
        };
        if (!Prefs.prototype.close_colors.__module__) Object.defineProperties(Prefs.prototype.close_colors, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_layout = function display_layout(container) {
            var self = this;
            self.create_panel(container, "layout", create_layout_panel);
        };
        if (!Prefs.prototype.display_layout.__argnames__) Object.defineProperties(Prefs.prototype.display_layout, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.close_layout = function close_layout() {
            var self = this;
            commit_layout(self.onchange, self.container);
        };
        if (!Prefs.prototype.close_layout.__module__) Object.defineProperties(Prefs.prototype.close_layout, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_user_stylesheet = function display_user_stylesheet(container) {
            var self = this;
            self.create_panel(container, "user_stylesheet", create_user_stylesheet_panel);
        };
        if (!Prefs.prototype.display_user_stylesheet.__argnames__) Object.defineProperties(Prefs.prototype.display_user_stylesheet, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.close_user_stylesheet = function close_user_stylesheet() {
            var self = this;
            commit_user_stylesheet(self.onchange, self.container);
        };
        if (!Prefs.prototype.close_user_stylesheet.__module__) Object.defineProperties(Prefs.prototype.close_user_stylesheet, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_head_foot = function display_head_foot(container) {
            var self = this;
            self.create_panel(container, "head_foot", create_head_foot_panel);
        };
        if (!Prefs.prototype.display_head_foot.__argnames__) Object.defineProperties(Prefs.prototype.display_head_foot, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.close_head_foot = function close_head_foot() {
            var self = this;
            commit_head_foot(self.onchange, self.container);
        };
        if (!Prefs.prototype.close_head_foot.__module__) Object.defineProperties(Prefs.prototype.close_head_foot, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_keyboard = function display_keyboard(container) {
            var self = this;
            self.create_panel(container, "keyboard", create_keyboard_panel, true);
        };
        if (!Prefs.prototype.display_keyboard.__argnames__) Object.defineProperties(Prefs.prototype.display_keyboard, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.close_keyboard = function close_keyboard() {
            var self = this;
            commit_keyboard(self.onchange, self.container);
        };
        if (!Prefs.prototype.close_keyboard.__module__) Object.defineProperties(Prefs.prototype.close_keyboard, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_scrolling = function display_scrolling(container) {
            var self = this;
            self.create_panel(container, "scrolling", create_scrolling_panel);
        };
        if (!Prefs.prototype.display_scrolling.__argnames__) Object.defineProperties(Prefs.prototype.display_scrolling, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.close_scrolling = function close_scrolling() {
            var self = this;
            commit_scrolling(self.onchange, self.container);
        };
        if (!Prefs.prototype.close_scrolling.__module__) Object.defineProperties(Prefs.prototype.close_scrolling, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_selection = function display_selection(container) {
            var self = this;
            self.create_panel(container, "selection", create_selection_panel);
        };
        if (!Prefs.prototype.display_selection.__argnames__) Object.defineProperties(Prefs.prototype.display_selection, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.close_selection = function close_selection() {
            var self = this;
            commit_selection(self.onchange, self.container);
        };
        if (!Prefs.prototype.close_selection.__module__) Object.defineProperties(Prefs.prototype.close_selection, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.display_touch = function display_touch(container) {
            var self = this;
            self.create_panel(container, "touch", create_touch_panel);
        };
        if (!Prefs.prototype.display_touch.__argnames__) Object.defineProperties(Prefs.prototype.display_touch, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.close_touch = function close_touch() {
            var self = this;
            commit_touch(self.onchange, self.container);
        };
        if (!Prefs.prototype.close_touch.__module__) Object.defineProperties(Prefs.prototype.close_touch, {
            __module__ : {value: "read_book.prefs.main"}
        });
        Prefs.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        Prefs.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(Prefs.prototype, "__bases__", {value: []});
        

        function create_prefs_panel(container, close_func, on_change) {
            return new Prefs(container, close_func, on_change);
        };
        if (!create_prefs_panel.__argnames__) Object.defineProperties(create_prefs_panel, {
            __argnames__ : {value: ["container", "close_func", "on_change"]},
            __module__ : {value: "read_book.prefs.main"}
        });

        ρσ_modules["read_book.prefs.main"].Prefs = Prefs;
        ρσ_modules["read_book.prefs.main"].create_prefs_panel = create_prefs_panel;
    })();

    (function(){
        var __name__ = "read_book.word_actions";
        var current_data;
        var E = ρσ_modules.elementmaker.E;

        var _ = ρσ_modules.gettext.gettext;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var create_item = ρσ_modules["book_list.item_list"].create_item;
        var create_item_list = ρσ_modules["book_list.item_list"].create_item_list;

        var clear = ρσ_modules.dom.clear;
        var ensure_id = ρσ_modules.dom.ensure_id;

        var error_dialog = ρσ_modules.modals.error_dialog;

        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var create_button = ρσ_modules.widgets.create_button;

        function lookup(close_panel_func, url) {
            close_panel_func();
            ui_operations.open_url(url);
        };
        if (!lookup.__argnames__) Object.defineProperties(lookup, {
            __argnames__ : {value: ["close_panel_func", "url"]},
            __module__ : {value: "read_book.word_actions"}
        });

        function toggle_custom_container(container_id, visible) {
            var container, c, list_container;
            container = document.getElementById(container_id);
            if (container) {
                c = container.lastChild;
                list_container = c.previousSibling;
                list_container.style.display = (visible) ? "none" : "block";
                c.style.display = (visible) ? "block" : "none";
                return c;
            }
        };
        if (!toggle_custom_container.__argnames__) Object.defineProperties(toggle_custom_container, {
            __argnames__ : {value: ["container_id", "visible"]},
            __module__ : {value: "read_book.word_actions"}
        });

        function add(container_id) {
            var container, c, name, url, sd, actions;
            container = document.getElementById(container_id);
            if (!container) {
                return;
            }
            c = container.lastChild;
            name = c.querySelector("input[name=\"name\"]").value;
            url = c.querySelector("input[name=\"url\"]").value;
            if (!name || !url) {
                error_dialog(_("Required fields missing"), _("You must specify both a name and a URL."));
                return;
            }
            sd = get_session_data();
            actions = sd.get("word_actions", []);
            actions.push((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["title"] = name;
                ρσ_d["url"] = url;
                return ρσ_d;
            }).call(this));
            sd.set("word_actions", actions);
            toggle_custom_container(container_id, false);
            populate_list(container);
        };
        if (!add.__argnames__) Object.defineProperties(add, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "read_book.word_actions"}
        });

        function add_custom(container_id) {
            var container, do_add;
            container = toggle_custom_container(container_id, true);
            if (!container) {
                return;
            }
            clear(container);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Enter the name and URL for a custom lookup source. The URL must contain  {0} in it, which will be replaced by the word being looked up. For example:  {1}").format("{word}", "https://google.com/search?q={word}")].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
            do_add = add.bind(null, container_id);
            container.appendChild(E.form(ρσ_interpolate_kwargs.call(E, E.button, [ρσ_desugar_kwargs({style: "display:none", onclick: do_add})]), ρσ_interpolate_kwargs.call(E, E.table, [E.tr(E.td(_("Name:") + " "), E.td(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "text", name: "name"})]))), E.tr(E.td(" "), E.td(" ")), E.tr(E.td(_("URL:") + " "), E.td(ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "url", name: "url"})])))].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})]))));
            container.append(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(this, create_button, [_("Add"), "plus", add.bind(null, container_id)].concat([ρσ_desugar_kwargs({highlight: true})])), " ", ρσ_interpolate_kwargs.call(this, create_button, [_("Cancel")].concat([ρσ_desugar_kwargs({action: toggle_custom_container.bind(null, container_id, false)})]))].concat([ρσ_desugar_kwargs({style: "margin: 1rem; display: flex"})])));
            container.querySelector("input").focus();
        };
        if (!add_custom.__argnames__) Object.defineProperties(add_custom, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "read_book.word_actions"}
        });

        function remove(container_id, num) {
            var container, sd, actions;
            container = document.getElementById(container_id);
            if (!container) {
                return;
            }
            sd = get_session_data();
            actions = sd.get("word_actions", []);
            actions.splice(num, 1);
            sd.set("word_actions", actions);
            toggle_custom_container(container_id, false);
            populate_list(container);
        };
        if (!remove.__argnames__) Object.defineProperties(remove, {
            __argnames__ : {value: ["container_id", "num"]},
            __module__ : {value: "read_book.word_actions"}
        });

        function remove_custom(container_id) {
            var container, items, sd, actions, ρσ_unpack, i, item;
            container = toggle_custom_container(container_id, true);
            if (!container) {
                return;
            }
            clear(container);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Choose a custom lookup to remove")].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
            items = ρσ_list_decorate([ create_item(_("Cancel (no removals)"), toggle_custom_container.bind(null, container_id, false)) ]);
            sd = get_session_data();
            actions = sd.get("word_actions", []);
            var ρσ_Iter0 = ρσ_Iterable(enumerate(actions));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                ρσ_unpack = ρσ_Iter0[ρσ_Index0];
                i = ρσ_unpack[0];
                item = ρσ_unpack[1];
                items.push(create_item(item.title, remove.bind(null, container_id, i)));
            }
            container.appendChild(E.div());
            create_item_list(container.lastChild, items);
        };
        if (!remove_custom.__argnames__) Object.defineProperties(remove_custom, {
            __argnames__ : {value: ["container_id"]},
            __module__ : {value: "read_book.word_actions"}
        });

        function lookup_items(word, close_panel_func, container_id) {
            var eword, items, custom_actions, has_custom, entry;
            eword = encodeURIComponent(word);
            items = ρσ_list_decorate([]);
            function a(title, url) {
                items.push(create_item(title, lookup.bind(word, close_panel_func, ρσ_interpolate_kwargs.call(url, url.format, [ρσ_desugar_kwargs({word: eword})]))));
            };
            if (!a.__argnames__) Object.defineProperties(a, {
                __argnames__ : {value: ["title", "url"]},
                __module__ : {value: "read_book.word_actions"}
            });

            custom_actions = get_session_data().get("word_actions", []);
            has_custom = custom_actions && custom_actions.length;
            if (has_custom) {
                var ρσ_Iter1 = ρσ_Iterable(custom_actions);
                for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                    entry = ρσ_Iter1[ρσ_Index1];
                    if (entry.title && entry.url) {
                        a(entry.title, entry.url);
                    }
                }
            }
            a(_("Google dictionary"), "https://google.com/search?q=define:{word}");
            a(_("Wordnik"), "https://www.wordnik.com/words/{word}");
            a(_("Search the internet"), "https://google.com/search?q={word}");
            items.push(create_item(_("Add a custom lookup"), add_custom.bind(null, container_id)));
            if (has_custom) {
                items.push(create_item(_("Remove a custom lookup"), remove_custom.bind(null, container_id)));
            }
            return items;
        };
        if (!lookup_items.__argnames__) Object.defineProperties(lookup_items, {
            __argnames__ : {value: ["word", "close_panel_func", "container_id"]},
            __module__ : {value: "read_book.word_actions"}
        });

        current_data = null;
        function populate_list(container) {
            var ρσ_unpack, word, close_panel_func, list_container;
            ρσ_unpack = current_data;
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            word = ρσ_unpack[0];
            close_panel_func = ρσ_unpack[1];
            list_container = container.lastChild.previousSibling;
            clear(list_container);
            create_item_list(list_container, lookup_items(word, close_panel_func, ensure_id(container)));
        };
        if (!populate_list.__argnames__) Object.defineProperties(populate_list, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.word_actions"}
        });

        function create_word_actions_panel(container, word, close_panel_func) {
            word = str.replace(word, "\u00ad", "");
            current_data = [word, close_panel_func];
            container.appendChild(E.div());
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display:none"})]));
            populate_list(container);
        };
        if (!create_word_actions_panel.__argnames__) Object.defineProperties(create_word_actions_panel, {
            __argnames__ : {value: ["container", "word", "close_panel_func"]},
            __module__ : {value: "read_book.word_actions"}
        });

        function develop(container) {
            container.appendChild(E.div());
            create_word_actions_panel(container, "develop", (function() {
                var ρσ_anonfunc = function () {
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.word_actions"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!develop.__argnames__) Object.defineProperties(develop, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.word_actions"}
        });

        ρσ_modules["read_book.word_actions"].current_data = current_data;
        ρσ_modules["read_book.word_actions"].lookup = lookup;
        ρσ_modules["read_book.word_actions"].toggle_custom_container = toggle_custom_container;
        ρσ_modules["read_book.word_actions"].add = add;
        ρσ_modules["read_book.word_actions"].add_custom = add_custom;
        ρσ_modules["read_book.word_actions"].remove = remove;
        ρσ_modules["read_book.word_actions"].remove_custom = remove_custom;
        ρσ_modules["read_book.word_actions"].lookup_items = lookup_items;
        ρσ_modules["read_book.word_actions"].populate_list = populate_list;
        ρσ_modules["read_book.word_actions"].create_word_actions_panel = create_word_actions_panel;
        ρσ_modules["read_book.word_actions"].develop = develop;
    })();

    (function(){
        var __name__ = "read_book.overlay";
        var E = ρσ_modules.elementmaker.E;

        var BD_CLASS_NAME = ρσ_modules["book_list.book_details"].CLASS_NAME;
        var render_metadata = ρσ_modules["book_list.book_details"].render_metadata;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var current_library_id = ρσ_modules["book_list.library_data"].current_library_id;
        var set_book_metadata = ρσ_modules["book_list.library_data"].set_book_metadata;
        var sync_library_books = ρσ_modules["book_list.library_data"].sync_library_books;

        var home = ρσ_modules["book_list.router"].home;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var create_top_bar = ρσ_modules["book_list.top_bar"].create_top_bar;

        var query_as_href = ρσ_modules["book_list.ui"].query_as_href;
        var show_panel = ρσ_modules["book_list.ui"].show_panel;

        var clear = ρσ_modules.dom.clear;
        var ensure_id = ρσ_modules.dom.ensure_id;
        var set_css = ρσ_modules.dom.set_css;
        var svgicon = ρσ_modules.dom.svgicon;

        var _ = ρσ_modules.gettext.gettext;

        var error_dialog = ρσ_modules.modals.error_dialog;
        var question_dialog = ρσ_modules.modals.question_dialog;

        var create_bookmarks_panel = ρσ_modules["read_book.bookmarks"].create_bookmarks_panel;

        var apply_viewer_chrome_colors = ρσ_modules["read_book.chrome"].apply_viewer_chrome_colors;
        var viewer_chrome_colors = ρσ_modules["read_book.chrome"].viewer_chrome_colors;

        var is_dark_theme = ρσ_modules["read_book.globals"].is_dark_theme;
        var runtime = ρσ_modules["read_book.globals"].runtime;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var create_goto_panel = ρσ_modules["read_book.goto"].create_goto_panel;
        var create_location_overlay = ρσ_modules["read_book.goto"].create_location_overlay;
        var create_page_list_overlay = ρσ_modules["read_book.goto"].create_page_list_overlay;

        var builtin_color = ρσ_modules["read_book.highlights"].builtin_color;
        var create_highlights_panel = ρσ_modules["read_book.highlights"].create_highlights_panel;

        var MAIN_OVERLAY_ACTION_CONTROL_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_ACTION_CONTROL_CLASS;
        var MAIN_OVERLAY_ACTION_ICON_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_ACTION_ICON_CLASS;
        var MAIN_OVERLAY_ACTIONS_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_ACTIONS_CLASS;
        var MAIN_OVERLAY_FOOTER_ACTION_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_ACTION_CLASS;
        var MAIN_OVERLAY_FOOTER_ACTIONS_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_ACTIONS_CLASS;
        var MAIN_OVERLAY_FOOTER_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_CLASS;
        var MAIN_OVERLAY_FOOTER_MIDDLE_SLOT_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_MIDDLE_SLOT_CLASS;
        var MAIN_OVERLAY_FOOTER_RIGHT_SLOT_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_RIGHT_SLOT_CLASS;
        var MAIN_OVERLAY_FOOTER_SLOT_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_FOOTER_SLOT_CLASS;
        var MAIN_OVERLAY_ICON_SIZE = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_ICON_SIZE;
        var MAIN_OVERLAY_TEXT_ICON_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_TEXT_ICON_CLASS;
        var MAIN_OVERLAY_TIMER_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_TIMER_CLASS;
        var MAIN_OVERLAY_TITLE_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_TITLE_CLASS;
        var MAIN_OVERLAY_TOP_ROW_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_TOP_ROW_CLASS;
        var MAIN_OVERLAY_TS_CLASS = ρσ_modules["read_book.main_overlay_style"].MAIN_OVERLAY_TS_CLASS;
        var timer_id = ρσ_modules["read_book.main_overlay_style"].timer_id;

        var create_profiles_panel = ρσ_modules["read_book.profiles"].create_profiles_panel;

        var create_open_book = ρσ_modules["read_book.open_book"].create_open_book;

        var create_font_size_panel = ρσ_modules["read_book.prefs.font_size"].create_font_size_panel;

        var time_formatter = ρσ_modules["read_book.prefs.head_foot"].time_formatter;
        var format_time_left = ρσ_modules["read_book.prefs.head_foot"].format_time_left;

        var create_prefs_panel = ρσ_modules["read_book.prefs.main"].create_prefs_panel;

        var create_toc_panel = ρσ_modules["read_book.toc"].create_toc_panel;

        var create_word_actions_panel = ρσ_modules["read_book.word_actions"].create_word_actions_panel;

        var session_defaults = ρσ_modules.session.session_defaults;
        var get_device_uuid = ρσ_modules.session.get_device_uuid;

        var default_context_menu_should_be_allowed = ρσ_modules.utils.default_context_menu_should_be_allowed;
        var full_screen_element = ρσ_modules.utils.full_screen_element;
        var full_screen_supported = ρσ_modules.utils.full_screen_supported;
        var is_ios = ρσ_modules.utils.is_ios;
        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;

        var short_uuid = ρσ_modules.uuid.short_uuid;

        var create_button = ρσ_modules.widgets.create_button;
        var create_spinner = ρσ_modules.widgets.create_spinner;

        function LoadingMessage() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            LoadingMessage.prototype.__bind_methods__.call(this);
            LoadingMessage.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(LoadingMessage.prototype, "__bind_methods__", {value: function () {
            this.show = LoadingMessage.prototype.show.bind(this);
            this.set_msg = LoadingMessage.prototype.set_msg.bind(this);
            this.on_container_click = LoadingMessage.prototype.on_container_click.bind(this);
        }});
        LoadingMessage.prototype.__init__ = function __init__(msg, current_color_scheme) {
            var self = this;
            self.msg = msg || "";
            self.current_color_scheme = current_color_scheme;
            self.is_not_escapable = true;
        };
        if (!LoadingMessage.prototype.__init__.__argnames__) Object.defineProperties(LoadingMessage.prototype.__init__, {
            __argnames__ : {value: ["msg", "current_color_scheme"]},
            __module__ : {value: "read_book.overlay"}
        });
        LoadingMessage.__argnames__ = LoadingMessage.prototype.__init__.__argnames__;
        LoadingMessage.__handles_kwarg_interpolation__ = LoadingMessage.prototype.__init__.__handles_kwarg_interpolation__;
        LoadingMessage.prototype.show = function show(container) {
            var self = this;
            self.container_id = container.getAttribute("id");
            container.style.backgroundColor = self.current_color_scheme.background;
            container.style.color = self.current_color_scheme.foreground;
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.div(create_spinner("100px", "100px")), E.h2()].concat([ρσ_desugar_kwargs({style: "text-align:center"})])));
            safe_set_inner_html(container.firstChild.lastChild, self.msg);
            ρσ_interpolate_kwargs.call(this, set_css, [container.firstChild].concat([ρσ_desugar_kwargs({position: "relative", top: "50%", transform: "translateY(-50%)"})]));
        };
        if (!LoadingMessage.prototype.show.__argnames__) Object.defineProperties(LoadingMessage.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        LoadingMessage.prototype.set_msg = function set_msg(msg) {
            var self = this;
            var container;
            self.msg = msg;
            container = document.getElementById(self.container_id);
            safe_set_inner_html(container.firstChild.lastChild, self.msg);
        };
        if (!LoadingMessage.prototype.set_msg.__argnames__) Object.defineProperties(LoadingMessage.prototype.set_msg, {
            __argnames__ : {value: ["msg"]},
            __module__ : {value: "read_book.overlay"}
        });
        LoadingMessage.prototype.on_container_click = function on_container_click(evt) {
            var self = this;
        };
        if (!LoadingMessage.prototype.on_container_click.__argnames__) Object.defineProperties(LoadingMessage.prototype.on_container_click, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        LoadingMessage.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        LoadingMessage.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(LoadingMessage.prototype, "__bases__", {value: []});

        function DeleteBook() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            DeleteBook.prototype.__bind_methods__.call(this);
            DeleteBook.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(DeleteBook.prototype, "__bind_methods__", {value: function () {
            this.show = DeleteBook.prototype.show.bind(this);
            this.focus_me = DeleteBook.prototype.focus_me.bind(this);
            this.show_working = DeleteBook.prototype.show_working.bind(this);
            this.on_container_click = DeleteBook.prototype.on_container_click.bind(this);
            this.delete_book = DeleteBook.prototype.delete_book.bind(this);
            this.cancel = DeleteBook.prototype.cancel.bind(this);
        }});
        DeleteBook.prototype.__init__ = function __init__(overlay, question, ok_icon, ok_text, reload_book) {
            var self = this;
            self.overlay = overlay;
            self.question = question || _("Are you sure you want to remove this book from local storage? You will have to re-download it from calibre if you want to read it again.");
            self.ok_icon = ok_icon || "trash";
            self.ok_text = ok_text || _("Delete book");
            self.reload_book = reload_book;
        };
        if (!DeleteBook.prototype.__init__.__argnames__) Object.defineProperties(DeleteBook.prototype.__init__, {
            __argnames__ : {value: ["overlay", "question", "ok_icon", "ok_text", "reload_book"]},
            __module__ : {value: "read_book.overlay"}
        });
        DeleteBook.__argnames__ = DeleteBook.prototype.__init__.__argnames__;
        DeleteBook.__handles_kwarg_interpolation__ = DeleteBook.prototype.__init__.__handles_kwarg_interpolation__;
        DeleteBook.prototype.show = function show(container) {
            var self = this;
            self.container_id = container.getAttribute("id");
            apply_viewer_chrome_colors(container);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [E.h2(self.question), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(this, create_button, [self.ok_text, self.ok_icon].concat([ρσ_desugar_kwargs({action: self.delete_book, highlight: true})])), E.span(" "), ρσ_interpolate_kwargs.call(this, create_button, [_("Cancel")].concat([ρσ_desugar_kwargs({action: self.cancel})]))].concat([ρσ_desugar_kwargs({style: "display:flex; justify-content:flex-end; margin-top:1rem"})]))].concat([ρσ_desugar_kwargs({style: "margin:1ex 1em; max-width: 80%"})]))].concat([ρσ_desugar_kwargs({style: "display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%", tabindex: "0", onkeyup: (function() {
                var ρσ_anonfunc = function (ev) {
                    if (ev.key === "Escape") {
                        [ev.stopPropagation(), ev.preventDefault()];
                        self.cancel();
                    } else if (ev.key === "Enter" || ev.key === "Return") {
                        [ev.stopPropagation(), ev.preventDefault()];
                        self.delete_book();
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.overlay"}
                });
                return ρσ_anonfunc;
            })()})])));
            window.setTimeout(self.focus_me, 0);
        };
        if (!DeleteBook.prototype.show.__argnames__) Object.defineProperties(DeleteBook.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        DeleteBook.prototype.focus_me = function focus_me() {
            var self = this;
            document.getElementById(self.container_id).lastChild.focus();
        };
        if (!DeleteBook.prototype.focus_me.__module__) Object.defineProperties(DeleteBook.prototype.focus_me, {
            __module__ : {value: "read_book.overlay"}
        });
        DeleteBook.prototype.show_working = function show_working() {
            var self = this;
            var container;
            container = document.getElementById(self.container_id);
            clear(container);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.div(create_spinner("100px", "100px")), E.h2()].concat([ρσ_desugar_kwargs({style: "text-align:center"})])));
            safe_set_inner_html(container.lastChild.lastChild, _("Deleting local book copy, please wait..."));
        };
        if (!DeleteBook.prototype.show_working.__module__) Object.defineProperties(DeleteBook.prototype.show_working, {
            __module__ : {value: "read_book.overlay"}
        });
        DeleteBook.prototype.on_container_click = function on_container_click(evt) {
            var self = this;
        };
        if (!DeleteBook.prototype.on_container_click.__argnames__) Object.defineProperties(DeleteBook.prototype.on_container_click, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        DeleteBook.prototype.delete_book = function delete_book() {
            var self = this;
            var view;
            if (runtime.is_standalone_viewer) {
                if (self.reload_book) {
                    self.overlay.view.reload_book();
                }
                return;
            }
            self.show_working();
            view = self.overlay.view;
            ui_operations.delete_book(view.book, (function() {
                var ρσ_anonfunc = function (book, errmsg) {
                    self.overlay.hide_current_panel();
                    if (errmsg) {
                        view.ui.show_error(_("Failed to delete book"), _("Failed to delete book from local storage, click \"Show details\" for more information."), errmsg);
                    } else {
                        if (self.reload_book) {
                            self.overlay.view.reload_book();
                        } else {
                            home();
                        }
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["book", "errmsg"]},
                    __module__ : {value: "read_book.overlay"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!DeleteBook.prototype.delete_book.__module__) Object.defineProperties(DeleteBook.prototype.delete_book, {
            __module__ : {value: "read_book.overlay"}
        });
        DeleteBook.prototype.cancel = function cancel() {
            var self = this;
            self.overlay.hide_current_panel();
        };
        if (!DeleteBook.prototype.cancel.__module__) Object.defineProperties(DeleteBook.prototype.cancel, {
            __module__ : {value: "read_book.overlay"}
        });
        DeleteBook.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        DeleteBook.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(DeleteBook.prototype, "__bases__", {value: []});

        function SyncBook() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            SyncBook.prototype.__bind_methods__.call(this);
            SyncBook.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(SyncBook.prototype, "__bind_methods__", {value: function () {
            this.show = SyncBook.prototype.show.bind(this);
            this.on_container_click = SyncBook.prototype.on_container_click.bind(this);
            this.cancel = SyncBook.prototype.cancel.bind(this);
            this.sync_data_received = SyncBook.prototype.sync_data_received.bind(this);
        }});
        SyncBook.prototype.__init__ = function __init__(overlay) {
            var self = this;
            self.overlay = overlay;
            self.canceled = false;
        };
        if (!SyncBook.prototype.__init__.__argnames__) Object.defineProperties(SyncBook.prototype.__init__, {
            __argnames__ : {value: ["overlay"]},
            __module__ : {value: "read_book.overlay"}
        });
        SyncBook.__argnames__ = SyncBook.prototype.__init__.__argnames__;
        SyncBook.__handles_kwarg_interpolation__ = SyncBook.prototype.__init__.__handles_kwarg_interpolation__;
        SyncBook.prototype.show = function show(container) {
            var self = this;
            var book, to_sync, view;
            self.container_id = container.getAttribute("id");
            apply_viewer_chrome_colors(container);
            book = self.overlay.view.book;
            to_sync = [[book.key, new Date(0)]];
            view = self.overlay.view;
            function start_download() {
                sync_library_books(book.key[0], to_sync, self.sync_data_received);
            };
            if (!start_download.__module__) Object.defineProperties(start_download, {
                __module__ : {value: "read_book.overlay"}
            });

            function after_position_upload(success) {
                start_download();
            };
            if (!after_position_upload.__argnames__) Object.defineProperties(after_position_upload, {
                __argnames__ : {value: ["success"]},
                __module__ : {value: "read_book.overlay"}
            });

            function after_annot_upload(success) {
                view.upload_current_position(after_position_upload);
            };
            if (!after_annot_upload.__argnames__) Object.defineProperties(after_annot_upload, {
                __argnames__ : {value: ["success"]},
                __module__ : {value: "read_book.overlay"}
            });

            if (ui_operations.upload_pending_annotations) {
                ui_operations.upload_pending_annotations(after_annot_upload);
            } else {
                after_annot_upload(true);
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [E.h2(_("Syncing last read position and annotations")), E.p(_("Downloading data from server, please wait...")), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(this, create_button, [_("Cancel")].concat([ρσ_desugar_kwargs({action: self.cancel})]))].concat([ρσ_desugar_kwargs({style: "display:flex; justify-content:flex-end"})]))].concat([ρσ_desugar_kwargs({style: "margin:1ex 1em; max-width: 80vw"})]))].concat([ρσ_desugar_kwargs({style: "display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100%"})])));
        };
        if (!SyncBook.prototype.show.__argnames__) Object.defineProperties(SyncBook.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        SyncBook.prototype.on_container_click = function on_container_click(evt) {
            var self = this;
        };
        if (!SyncBook.prototype.on_container_click.__argnames__) Object.defineProperties(SyncBook.prototype.on_container_click, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        SyncBook.prototype.cancel = function cancel() {
            var self = this;
            self.canceled = true;
            self.overlay.hide_current_panel();
        };
        if (!SyncBook.prototype.cancel.__module__) Object.defineProperties(SyncBook.prototype.cancel, {
            __module__ : {value: "read_book.overlay"}
        });
        SyncBook.prototype.sync_data_received = function sync_data_received(library_id, lrmap, load_type, xhr, ev) {
            var self = this;
            var data, book, dev, epoch, ans, new_annotations_map, ρσ_unpack, book_id, fmt, new_vals, last_read_positions, d, key, cfi;
            if (self.canceled) {
                return;
            }
            self.overlay.hide();
            if (load_type !== "load") {
                if (xhr.responseText === "login required for sync") {
                    error_dialog(_("Failed to fetch sync data"), _("You must setup user accounts and login to use the sync functionality"));
                } else {
                    error_dialog(_("Failed to fetch sync data"), _("Failed to download sync data from server, click \"Show details\" for more information."), xhr.error_html);
                }
                return;
            }
            data = JSON.parse(xhr.responseText);
            book = self.overlay.view.book;
            dev = get_device_uuid();
            epoch = 0;
            ans = null;
            new_annotations_map = null;
            var ρσ_Iter0 = ρσ_Iterable(data);
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                key = ρσ_Iter0[ρσ_Index0];
                ρσ_unpack = ρσ_eslice(key.partition(":"), 2);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                book_id = ρσ_unpack[0];
                fmt = ρσ_unpack[1];
                if (book_id === str(book.key[1]) && fmt.upper() === book.key[2].upper()) {
                    new_vals = data[(typeof key === "number" && key < 0) ? data.length + key : key];
                    last_read_positions = new_vals.last_read_positions;
                    new_annotations_map = new_vals.annotations_map;
                    var ρσ_Iter1 = ρσ_Iterable(last_read_positions);
                    for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                        d = ρσ_Iter1[ρσ_Index1];
                        if (d.device !== dev && d.epoch > epoch) {
                            epoch = d.epoch;
                            ans = d;
                        }
                    }
                    break;
                }
            }
            cfi = (typeof ans !== "undefined" && ans !== null ? ans : Object.create(null)).cfi;
            if (new_annotations_map || cfi) {
                self.overlay.view.sync_data_received(cfi, new_annotations_map);
            }
        };
        if (!SyncBook.prototype.sync_data_received.__argnames__) Object.defineProperties(SyncBook.prototype.sync_data_received, {
            __argnames__ : {value: ["library_id", "lrmap", "load_type", "xhr", "ev"]},
            __module__ : {value: "read_book.overlay"}
        });
        SyncBook.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        SyncBook.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(SyncBook.prototype, "__bases__", {value: []});

        function create_main_overlay_action_with_icon() {
            var text = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var tooltip = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var action = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var icon_elem = ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[3];
            var icon_color = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_main_overlay_action_with_icon.__defaults__.icon_color : arguments[4];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "icon_color")){
                icon_color = ρσ_kwargs_obj.icon_color;
            }
            if (icon_color) {
                icon_elem.style.color = icon_color;
            }
            icon_elem.classList.add(MAIN_OVERLAY_ACTION_ICON_CLASS);
            return E.li(ρσ_interpolate_kwargs.call(E, E.button, [icon_elem, text].concat([ρσ_desugar_kwargs({class_: MAIN_OVERLAY_ACTION_CONTROL_CLASS, title: tooltip, type: "button", onclick: action})])));
        };
        if (!create_main_overlay_action_with_icon.__defaults__) Object.defineProperties(create_main_overlay_action_with_icon, {
            __defaults__ : {value: {icon_color:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["text", "tooltip", "action", "icon_elem", "icon_color"]},
            __module__ : {value: "read_book.overlay"}
        });

        function create_main_overlay_action() {
            var text = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var tooltip = ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[1];
            var action = ( 2 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[2];
            var icon = ( 3 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[3];
            var icon_color = (arguments[4] === undefined || ( 4 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? create_main_overlay_action.__defaults__.icon_color : arguments[4];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "icon_color")){
                icon_color = ρσ_kwargs_obj.icon_color;
            }
            return create_main_overlay_action_with_icon(text, tooltip, action, svgicon(icon, MAIN_OVERLAY_ICON_SIZE, MAIN_OVERLAY_ICON_SIZE), icon_color);
        };
        if (!create_main_overlay_action.__defaults__) Object.defineProperties(create_main_overlay_action, {
            __defaults__ : {value: {icon_color:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["text", "tooltip", "action", "icon", "icon_color"]},
            __module__ : {value: "read_book.overlay"}
        });

        function create_main_overlay_text_action(text, tooltip, action, icon_text) {
            return create_main_overlay_action_with_icon(text, tooltip, action, ρσ_interpolate_kwargs.call(E, E.span, [icon_text].concat([ρσ_desugar_kwargs({class_: MAIN_OVERLAY_TEXT_ICON_CLASS})])));
        };
        if (!create_main_overlay_text_action.__argnames__) Object.defineProperties(create_main_overlay_text_action, {
            __argnames__ : {value: ["text", "tooltip", "action", "icon_text"]},
            __module__ : {value: "read_book.overlay"}
        });

        function create_main_overlay_footer_action(icon, text, tooltip, action) {
            return ρσ_interpolate_kwargs.call(E, E.button, [svgicon(icon, MAIN_OVERLAY_ICON_SIZE, MAIN_OVERLAY_ICON_SIZE), text].concat([ρσ_desugar_kwargs({class_: MAIN_OVERLAY_FOOTER_ACTION_CLASS, title: tooltip, type: "button", onclick: action})]));
        };
        if (!create_main_overlay_footer_action.__argnames__) Object.defineProperties(create_main_overlay_footer_action, {
            __argnames__ : {value: ["icon", "text", "tooltip", "action"]},
            __module__ : {value: "read_book.overlay"}
        });

        function create_main_overlay_footer(close_action, help_action) {
            var middle, right, footer;
            middle = ρσ_interpolate_kwargs.call(E, E.div, [" "].concat([ρσ_desugar_kwargs({class_: " ".join(ρσ_list_decorate([ MAIN_OVERLAY_FOOTER_SLOT_CLASS, MAIN_OVERLAY_FOOTER_MIDDLE_SLOT_CLASS ]))})]));
            right = ρσ_interpolate_kwargs.call(E, E.div, [" "].concat([ρσ_desugar_kwargs({class_: " ".join(ρσ_list_decorate([ MAIN_OVERLAY_FOOTER_SLOT_CLASS, MAIN_OVERLAY_FOOTER_RIGHT_SLOT_CLASS ]))})]));
            footer = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [create_main_overlay_footer_action("close", _("Close"), _("Close the viewer controls"), close_action), create_main_overlay_footer_action("help", _("Help"), _("Show viewer help"), help_action)].concat([ρσ_desugar_kwargs({class_: MAIN_OVERLAY_FOOTER_ACTIONS_CLASS})])), middle, right].concat([ρσ_desugar_kwargs({class_: MAIN_OVERLAY_FOOTER_CLASS})]));
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["footer"] = footer;
                ρσ_d["middle_slot"] = middle;
                ρσ_d["right_slot"] = right;
                return ρσ_d;
            }).call(this);
        };
        if (!create_main_overlay_footer.__argnames__) Object.defineProperties(create_main_overlay_footer, {
            __argnames__ : {value: ["close_action", "help_action"]},
            __module__ : {value: "read_book.overlay"}
        });

        function render_main_overlay_footer_templates(footer_parts, renderer) {
            if (!renderer) {
                return;
            }
            renderer(footer_parts.middle_slot, "controls_footer", "middle", "");
            renderer(footer_parts.right_slot, "controls_footer", "right", "");
        };
        if (!render_main_overlay_footer_templates.__argnames__) Object.defineProperties(render_main_overlay_footer_templates, {
            __argnames__ : {value: ["footer_parts", "renderer"]},
            __module__ : {value: "read_book.overlay"}
        });

        function simple_overlay_title(title, overlay, container, close_action) {
            apply_viewer_chrome_colors(container);
            function action() {
                var event;
                event = this;
                event.stopPropagation();
                overlay.hide_current_panel(event);
            };
            if (!action.__module__) Object.defineProperties(action, {
                __module__ : {value: "read_book.overlay"}
            });

            ρσ_interpolate_kwargs.call(this, create_top_bar, [container].concat([ρσ_desugar_kwargs({title: title, icon: "close", action: close_action || action})]));
        };
        if (!simple_overlay_title.__argnames__) Object.defineProperties(simple_overlay_title, {
            __argnames__ : {value: ["title", "overlay", "container", "close_action"]},
            __module__ : {value: "read_book.overlay"}
        });

        function MainOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            MainOverlay.prototype.__bind_methods__.call(this);
            MainOverlay.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(MainOverlay.prototype, "__bind_methods__", {value: function () {
            this.create_actions = MainOverlay.prototype.create_actions.bind(this);
            this.create_top_section = MainOverlay.prototype.create_top_section.bind(this);
            this.create_footer = MainOverlay.prototype.create_footer.bind(this);
            this.show = MainOverlay.prototype.show.bind(this);
            this.update_time = MainOverlay.prototype.update_time.bind(this);
            this.on_hide = MainOverlay.prototype.on_hide.bind(this);
            this.back = MainOverlay.prototype.back.bind(this);
            this.forward = MainOverlay.prototype.forward.bind(this);
        }});
        MainOverlay.prototype.__init__ = function __init__(overlay, elements) {
            var self = this;
            self.overlay = overlay;
            self.elements = elements || Object.create(null);
            self.timer = null;
            if (ρσ_exists.d(window.Intl).DateTimeFormat) {
                self.date_formatter = window.Intl.DateTimeFormat(undefined, (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["hour"] = "numeric";
                    ρσ_d["minute"] = "numeric";
                    return ρσ_d;
                }).call(this));
            } else {
                self.date_formatter = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["format"] = (function() {
                        var ρσ_anonfunc = function (date) {
                            return "{}:{}".format(date.getHours(), date.getMinutes());
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["date"]},
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })();
                    return ρσ_d;
                }).call(this);
            }
        };
        if (!MainOverlay.prototype.__init__.__argnames__) Object.defineProperties(MainOverlay.prototype.__init__, {
            __argnames__ : {value: ["overlay", "elements"]},
            __module__ : {value: "read_book.overlay"}
        });
        MainOverlay.__argnames__ = MainOverlay.prototype.__init__.__argnames__;
        MainOverlay.__handles_kwarg_interpolation__ = MainOverlay.prototype.__init__.__handles_kwarg_interpolation__;
        MainOverlay.prototype.create_actions = function create_actions(sd) {
            var self = this;
            var ac, text_ac, sync_icon_color, sync_action, delete_action, reload_action, back_action, forward_action, nav_actions, reload_actions, editable_formats, fmt, bookmarks_action, highlights_action, reading_stats_action, toc_actions, actions_div, home_action, library_action, book_action, full_screen_actions, text, asa, no_selection_bar, copy_actions;
            ac = create_main_overlay_action;
            text_ac = create_main_overlay_text_action;
            sync_icon_color = null;
            if (ui_operations.has_unsynced_changes && ui_operations.has_unsynced_changes()) {
                sync_icon_color = builtin_color("yellow", is_dark_theme());
            }
            sync_action = ac(_("Sync"), _("Get last read position and annotations from the server"), self.overlay.sync_book, "cloud-download", sync_icon_color);
            delete_action = ac(_("Delete"), _("Delete this book from local storage"), self.overlay.delete_book, "trash");
            reload_action = ac(_("Reload"), _("Reload this book from the {}").format((runtime.is_standalone_viewer) ? _("computer") : _("server")), self.overlay.reload_book, "refresh");
            back_action = ac(_("Back"), _("Go back"), self.back, "arrow-left");
            forward_action = ac(_("Forward"), _("Go forward"), self.forward, "arrow-right");
            nav_actions = E.ul(back_action, forward_action);
            if (runtime.is_standalone_viewer) {
                reload_actions = E.ul(ac(_("Open book"), _("Open a book"), self.overlay.open_book, "book"), reload_action);
                editable_formats = ["AZW3", "EPUB", "KEPUB"];
                fmt = ρσ_exists.d(ρσ_exists.d(self.overlay.view).book).manifest.book_format || "";
                if (ρσ_in(fmt.toUpperCase(), editable_formats)) {
                    reload_actions.appendChild(ac(_("Edit book"), _("Edit this book"), self.overlay.view.edit_book, "edit"));
                }
            } else {
                reload_actions = E.ul(sync_action, delete_action, reload_action);
            }
            bookmarks_action = ac(_("Bookmarks"), _("Browse all bookmarks"), self.overlay.show_bookmarks, "bookmark");
            highlights_action = ac(_("Highlights"), _("Browse all highlights"), (function() {
                var ρσ_anonfunc = function () {
                    self.overlay.show_highlights();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.overlay"}
                });
                return ρσ_anonfunc;
            })(), "image");
            reading_stats_action = ac(_("Reading statistics"), _("Show reading statistics for this book"), (function() {
                var ρσ_anonfunc = function () {
                    self.overlay.show_reading_stats();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.overlay"}
                });
                return ρσ_anonfunc;
            })(), "hourglass");
            toc_actions = E.ul(ac(_("Table of Contents"), _("Browse the Table of Contents"), self.overlay.show_toc, "toc"));
            toc_actions.appendChild(ac(_("Reference mode"), _("Toggle the Reference mode"), self.overlay.toggle_reference_mode, "reference-mode"));
            actions_div = ρσ_interpolate_kwargs.call(E, E.div, [nav_actions, E.ul(ac(_("Search"), _("Search for text in this book"), self.overlay.show_search, "search"), ac(_("Go to"), _("Go to a specific location in the book"), self.overlay.show_goto, "chevron-right")), reload_actions, toc_actions, E.ul(highlights_action, bookmarks_action, reading_stats_action), E.ul(text_ac(_("Font size"), _("Change text size"), self.overlay.show_font_size_chooser, "Aa"), ac(_("Preferences"), _("Configure the E-book viewer"), self.overlay.show_prefs, "cogs"))].concat([ρσ_desugar_kwargs({class_: MAIN_OVERLAY_ACTIONS_CLASS})]));
            if (!runtime.is_standalone_viewer) {
                home_action = ac(_("Home"), _("Return to the home page"), (function() {
                    var ρσ_anonfunc = function () {
                        home();
                        ui_operations.close_book();
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.overlay"}
                    });
                    return ρσ_anonfunc;
                })(), "home");
                library_action = ac(_("Library"), _("Return to the library page"), self.overlay.show_library, "library");
                book_action = ac(_("Book"), _("Return to the book's page"), self.overlay.show_book_page, "book");
                actions_div.insertBefore(E.ul(home_action, library_action, book_action), actions_div.firstChild);
            }
            full_screen_actions = ρσ_list_decorate([]);
            if (runtime.is_standalone_viewer) {
                text = (runtime.viewer_in_full_screen) ? _("Exit full screen") : _("Enter full screen");
                full_screen_actions.push(ac(text, _("Toggle full screen mode"), (function() {
                    var ρσ_anonfunc = function () {
                        [self.overlay.hide(), ui_operations.toggle_full_screen()];
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.overlay"}
                    });
                    return ρσ_anonfunc;
                })(), "full-screen"));
                full_screen_actions.push(ac(_("Print"), _("Print book to PDF"), (function() {
                    var ρσ_anonfunc = function () {
                        [self.overlay.hide(), ui_operations.print_book()];
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.overlay"}
                    });
                    return ρσ_anonfunc;
                })(), "print"));
            } else {
                if (!is_ios && full_screen_supported()) {
                    text = (full_screen_element()) ? _("Exit full screen") : _("Enter full screen");
                    full_screen_actions.push(ac(text, _("Toggle full screen mode"), (function() {
                        var ρσ_anonfunc = function () {
                            [self.overlay.hide(), ui_operations.toggle_full_screen()];
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })(), "full-screen"));
                }
            }
            if (sd.get("read_mode") === "flow") {
                asa = self.overlay.view.autoscroll_active;
                full_screen_actions.append(ac((asa) ? _("Stop auto scroll") : _("Auto scroll"), _("Toggle auto-scrolling"), (function() {
                    var ρσ_anonfunc = function () {
                        self.overlay.hide();
                        window.setTimeout(self.overlay.view.toggle_autoscroll, 0);
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.overlay"}
                    });
                    return ρσ_anonfunc;
                })(), "auto-scroll"));
            }
            actions_div.appendChild(E.ul(ac(_("Read aloud"), _("Read the book aloud"), (function() {
                var ρσ_anonfunc = function () {
                    self.overlay.hide();
                    self.overlay.view.start_read_aloud();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.overlay"}
                });
                return ρσ_anonfunc;
            })(), "bullhorn"), ac(_("Profiles"), _("Quickly switch between different settings"), (function() {
                var ρσ_anonfunc = function () {
                    self.overlay.show_profiles();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.overlay"}
                });
                return ρσ_anonfunc;
            })(), "convert")));
            if (full_screen_actions.length) {
                actions_div.appendChild(E.ul.apply(E, full_screen_actions));
            }
            no_selection_bar = !sd.get("show_selection_bar");
            if (runtime.is_standalone_viewer) {
                if (no_selection_bar) {
                    actions_div.appendChild(E.ul(ac(_("Lookup/search word"), _("Lookup or search for the currently selected word"), (function() {
                        var ρσ_anonfunc = function () {
                            [self.overlay.hide(), ui_operations.toggle_lookup(true)];
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })(), "library")));
                }
                copy_actions = E.ul();
                if (self.elements.link) {
                    copy_actions.appendChild(ac(_("Copy link"), _("Copy the current link"), (function() {
                        var ρσ_anonfunc = function () {
                            [self.overlay.hide(), ui_operations.copy_selection(self.elements.link)];
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })(), "link"));
                }
                if (self.elements.img) {
                    copy_actions.appendChild(ac(_("View image"), _("View the current image"), (function() {
                        var ρσ_anonfunc = function () {
                            [self.overlay.hide(), ui_operations.view_image(self.elements.img)];
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })(), "image"));
                    copy_actions.appendChild(ac(_("Copy image"), _("Copy the current image"), (function() {
                        var ρσ_anonfunc = function () {
                            [self.overlay.hide(), ui_operations.copy_image(self.elements.img)];
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })(), "copy"));
                }
                if (copy_actions.childNodes.length) {
                    actions_div.appendChild(copy_actions);
                }
                actions_div.appendChild(E.ul(ac(_("Inspector"), _("Show the content inspector"), (function() {
                    var ρσ_anonfunc = function () {
                        [self.overlay.hide(), ui_operations.toggle_inspector()];
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.overlay"}
                    });
                    return ρσ_anonfunc;
                })(), "bug"), ac(_("Reset interface"), _("Reset E-book viewer panels, toolbars and scrollbars to defaults"), (function() {
                    var ρσ_anonfunc = function () {
                        question_dialog(_("Are you sure?"), _("Are you sure you want to reset the viewer interface to its default appearance?"), (function() {
                            var ρσ_anonfunc = function (yes) {
                                var sd;
                                if (yes) {
                                    self.overlay.hide();
                                    ui_operations.reset_interface();
                                    sd = get_session_data();
                                    sd.set("skipped_dialogs", session_defaults().skipped_dialogs);
                                }
                            };
                            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                                __argnames__ : {value: ["yes"]},
                                __module__ : {value: "read_book.overlay"}
                            });
                            return ρσ_anonfunc;
                        })());
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.overlay"}
                    });
                    return ρσ_anonfunc;
                })(), "window-restore"), ac(_("Quit"), _("Close the E-book viewer"), (function() {
                    var ρσ_anonfunc = function () {
                        [self.overlay.hide(), ui_operations.quit()];
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.overlay"}
                    });
                    return ρσ_anonfunc;
                })(), "remove")));
            } else {
                copy_actions = E.ul();
                if (self.elements.link) {
                    copy_actions.appendChild(ac(_("Copy link"), _("Copy the current link"), (function() {
                        var ρσ_anonfunc = function () {
                            [self.overlay.hide(), ui_operations.copy_selection(self.elements.link)];
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })(), "link"));
                }
                if (self.elements.img) {
                    copy_actions.appendChild(ac(_("View image"), _("View the current image"), (function() {
                        var ρσ_anonfunc = function () {
                            [self.overlay.hide(), ui_operations.view_image(self.elements.img)];
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })(), "image"));
                    if (window.navigator.clipboard) {
                        copy_actions.appendChild(ac(_("Copy image"), _("Copy the current image"), (function() {
                            var ρσ_anonfunc = function () {
                                [self.overlay.hide(), ui_operations.copy_image(self.elements.img)];
                            };
                            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                                __module__ : {value: "read_book.overlay"}
                            });
                            return ρσ_anonfunc;
                        })(), "copy"));
                    }
                }
                if (copy_actions.childNodes.length) {
                    actions_div.appendChild(copy_actions);
                }
            }
            return actions_div;
        };
        if (!MainOverlay.prototype.create_actions.__argnames__) Object.defineProperties(MainOverlay.prototype.create_actions, {
            __argnames__ : {value: ["sd"]},
            __module__ : {value: "read_book.overlay"}
        });
        MainOverlay.prototype.create_top_section = function create_top_section(actions_div) {
            var self = this;
            return ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_exists.d(ρσ_exists.d(self.overlay.view.book).metadata).title || _("Unknown")].concat([ρσ_desugar_kwargs({class_: MAIN_OVERLAY_TITLE_CLASS})])), ρσ_interpolate_kwargs.call(E, E.div, [time_formatter.format(new Date)].concat([ρσ_desugar_kwargs({id: timer_id(), class_: MAIN_OVERLAY_TIMER_CLASS})]))].concat([ρσ_desugar_kwargs({class_: MAIN_OVERLAY_TOP_ROW_CLASS})])), actions_div].concat([ρσ_desugar_kwargs({class_: MAIN_OVERLAY_TS_CLASS, onclick: (function() {
                var ρσ_anonfunc = function (evt) {
                    evt.stopPropagation();
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["evt"]},
                    __module__ : {value: "read_book.overlay"}
                });
                return ρσ_anonfunc;
            })()})]));
        };
        if (!MainOverlay.prototype.create_top_section.__argnames__) Object.defineProperties(MainOverlay.prototype.create_top_section, {
            __argnames__ : {value: ["actions_div"]},
            __module__ : {value: "read_book.overlay"}
        });
        MainOverlay.prototype.create_footer = function create_footer() {
            var self = this;
            var footer_parts;
            function close_viewer_controls(ev) {
                ev.stopPropagation();
                self.overlay.hide_current_panel(ev);
            };
            if (!close_viewer_controls.__argnames__) Object.defineProperties(close_viewer_controls, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "read_book.overlay"}
            });

            function show_viewer_help(ev) {
                ev.stopPropagation();
                ui_operations.show_help("viewer");
                self.overlay.hide_current_panel(ev);
            };
            if (!show_viewer_help.__argnames__) Object.defineProperties(show_viewer_help, {
                __argnames__ : {value: ["ev"]},
                __module__ : {value: "read_book.overlay"}
            });

            footer_parts = create_main_overlay_footer(close_viewer_controls, show_viewer_help);
            render_main_overlay_footer_templates(footer_parts, self.overlay.view.create_template_renderer());
            return footer_parts.footer;
        };
        if (!MainOverlay.prototype.create_footer.__module__) Object.defineProperties(MainOverlay.prototype.create_footer, {
            __module__ : {value: "read_book.overlay"}
        });
        MainOverlay.prototype.show = function show(container) {
            var self = this;
            var sd;
            self.container_id = container.getAttribute("id");
            sd = get_session_data();
            container.appendChild(self.create_top_section(self.create_actions(sd)));
            container.appendChild(self.create_footer());
            self.on_hide();
            self.timer = setInterval(self.update_time, 1e3);
        };
        if (!MainOverlay.prototype.show.__argnames__) Object.defineProperties(MainOverlay.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        MainOverlay.prototype.update_time = function update_time() {
            var self = this;
            var tm;
            tm = document.getElementById(timer_id());
            if (tm) {
                tm.textContent = self.date_formatter.format(new Date);
            }
        };
        if (!MainOverlay.prototype.update_time.__module__) Object.defineProperties(MainOverlay.prototype.update_time, {
            __module__ : {value: "read_book.overlay"}
        });
        MainOverlay.prototype.on_hide = function on_hide() {
            var self = this;
            if (self.timer !== null) {
                clearInterval(self.timer);
            }
            self.timer = null;
        };
        if (!MainOverlay.prototype.on_hide.__module__) Object.defineProperties(MainOverlay.prototype.on_hide, {
            __module__ : {value: "read_book.overlay"}
        });
        MainOverlay.prototype.back = function back() {
            var self = this;
            window.history.back();
            self.overlay.hide();
        };
        if (!MainOverlay.prototype.back.__module__) Object.defineProperties(MainOverlay.prototype.back, {
            __module__ : {value: "read_book.overlay"}
        });
        MainOverlay.prototype.forward = function forward() {
            var self = this;
            window.history.forward();
            self.overlay.hide();
        };
        if (!MainOverlay.prototype.forward.__module__) Object.defineProperties(MainOverlay.prototype.forward, {
            __module__ : {value: "read_book.overlay"}
        });
        MainOverlay.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        MainOverlay.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(MainOverlay.prototype, "__bases__", {value: []});

        function SimpleOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            SimpleOverlay.prototype.__bind_methods__.call(this);
            SimpleOverlay.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(SimpleOverlay.prototype, "__bind_methods__", {value: function () {
            this.on_container_click = SimpleOverlay.prototype.on_container_click.bind(this);
            this.show = SimpleOverlay.prototype.show.bind(this);
        }});
        SimpleOverlay.prototype.__init__ = function __init__(overlay, create_func, title) {
            var self = this;
            self.overlay = overlay;
            self.create_func = create_func;
            self.title = title;
        };
        if (!SimpleOverlay.prototype.__init__.__argnames__) Object.defineProperties(SimpleOverlay.prototype.__init__, {
            __argnames__ : {value: ["overlay", "create_func", "title"]},
            __module__ : {value: "read_book.overlay"}
        });
        SimpleOverlay.__argnames__ = SimpleOverlay.prototype.__init__.__argnames__;
        SimpleOverlay.__handles_kwarg_interpolation__ = SimpleOverlay.prototype.__init__.__handles_kwarg_interpolation__;
        SimpleOverlay.prototype.on_container_click = function on_container_click(evt) {
            var self = this;
        };
        if (!SimpleOverlay.prototype.on_container_click.__argnames__) Object.defineProperties(SimpleOverlay.prototype.on_container_click, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        SimpleOverlay.prototype.show = function show(container) {
            var self = this;
            simple_overlay_title(self.title, self.overlay, container);
            self.create_func(self.overlay, container);
        };
        if (!SimpleOverlay.prototype.show.__argnames__) Object.defineProperties(SimpleOverlay.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        SimpleOverlay.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        SimpleOverlay.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(SimpleOverlay.prototype, "__bases__", {value: []});

        function TOCOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            TOCOverlay.prototype.__bind_methods__.call(this);
            TOCOverlay.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(TOCOverlay, SimpleOverlay);
        Object.defineProperty(TOCOverlay.prototype, "__bind_methods__", {value: function () {
            SimpleOverlay.prototype.__bind_methods__ && SimpleOverlay.prototype.__bind_methods__.call(this);
            this.show = TOCOverlay.prototype.show.bind(this);
            this.handle_activate = TOCOverlay.prototype.handle_activate.bind(this);
        }});
        TOCOverlay.prototype.__init__ = function __init__(overlay, create_func, title) {
            var self = this;
            self.overlay = overlay;
            self.create_func = create_func || create_toc_panel;
            self.title = title || _("Table of Contents");
        };
        if (!TOCOverlay.prototype.__init__.__argnames__) Object.defineProperties(TOCOverlay.prototype.__init__, {
            __argnames__ : {value: ["overlay", "create_func", "title"]},
            __module__ : {value: "read_book.overlay"}
        });
        TOCOverlay.__argnames__ = TOCOverlay.prototype.__init__.__argnames__;
        TOCOverlay.__handles_kwarg_interpolation__ = TOCOverlay.prototype.__init__.__handles_kwarg_interpolation__;
        TOCOverlay.prototype.show = function show(container) {
            var self = this;
            container.appendChild(E.div());
            container = container.firstChild;
            simple_overlay_title(self.title, self.overlay, container);
            self.create_func(self.overlay.view.book, container, self.handle_activate);
        };
        if (!TOCOverlay.prototype.show.__argnames__) Object.defineProperties(TOCOverlay.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        TOCOverlay.prototype.handle_activate = function handle_activate(dest, frag) {
            var self = this;
            self.overlay.hide();
            if (typeof dest === "function") {
                dest(self.overlay.view, frag);
            } else {
                self.overlay.view.goto_named_destination(dest, frag);
            }
        };
        if (!TOCOverlay.prototype.handle_activate.__argnames__) Object.defineProperties(TOCOverlay.prototype.handle_activate, {
            __argnames__ : {value: ["dest", "frag"]},
            __module__ : {value: "read_book.overlay"}
        });
        TOCOverlay.prototype.__repr__ = function __repr__ () {
            if(SimpleOverlay.prototype.__repr__) return SimpleOverlay.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        TOCOverlay.prototype.__str__ = function __str__ () {
            if(SimpleOverlay.prototype.__str__) return SimpleOverlay.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(TOCOverlay.prototype, "__bases__", {value: [SimpleOverlay]});

        function GotoOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            GotoOverlay.prototype.__bind_methods__.call(this);
            GotoOverlay.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(GotoOverlay.prototype, "__bind_methods__", {value: function () {
            this.on_container_click = GotoOverlay.prototype.on_container_click.bind(this);
            this.show = GotoOverlay.prototype.show.bind(this);
            this.handle_navigate = GotoOverlay.prototype.handle_navigate.bind(this);
            this.show_sub_panel = GotoOverlay.prototype.show_sub_panel.bind(this);
        }});
        GotoOverlay.prototype.__init__ = function __init__(overlay) {
            var self = this;
            self.overlay = overlay;
        };
        if (!GotoOverlay.prototype.__init__.__argnames__) Object.defineProperties(GotoOverlay.prototype.__init__, {
            __argnames__ : {value: ["overlay"]},
            __module__ : {value: "read_book.overlay"}
        });
        GotoOverlay.__argnames__ = GotoOverlay.prototype.__init__.__argnames__;
        GotoOverlay.__handles_kwarg_interpolation__ = GotoOverlay.prototype.__init__.__handles_kwarg_interpolation__;
        GotoOverlay.prototype.on_container_click = function on_container_click(evt) {
            var self = this;
        };
        if (!GotoOverlay.prototype.on_container_click.__argnames__) Object.defineProperties(GotoOverlay.prototype.on_container_click, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        GotoOverlay.prototype.show = function show(container) {
            var self = this;
            var inner;
            container.appendChild(E.div());
            inner = container.firstChild;
            simple_overlay_title(_("Go to…"), self.overlay, inner);
            create_goto_panel(self.overlay.view.current_position_data, self.overlay.view.book, inner, self.handle_navigate, self.show_sub_panel);
        };
        if (!GotoOverlay.prototype.show.__argnames__) Object.defineProperties(GotoOverlay.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        GotoOverlay.prototype.handle_navigate = function handle_navigate(dest, frag) {
            var self = this;
            self.overlay.hide();
            if (typeof dest === "function") {
                dest(self.overlay.view, frag);
            } else {
                self.overlay.view.goto_named_destination(dest, frag);
            }
        };
        if (!GotoOverlay.prototype.handle_navigate.__argnames__) Object.defineProperties(GotoOverlay.prototype.handle_navigate, {
            __argnames__ : {value: ["dest", "frag"]},
            __module__ : {value: "read_book.overlay"}
        });
        GotoOverlay.prototype.show_sub_panel = function show_sub_panel(name) {
            var self = this;
            if (name === "location") {
                self.overlay.panels.push(new SimpleOverlay(self.overlay, create_location_overlay.bind(null, self.overlay.view.current_position_data, self.overlay.view.book), _("Go to location, position or reference…")));
            } else if (name === "metadata") {
                self.overlay.panels.push(self.overlay._build_metadata_panel());
            } else if (name === "page_list") {
                self.overlay.panels.push(new SimpleOverlay(self.overlay, create_page_list_overlay.bind(null, self.overlay.view.book), _("Go to page")));
            }
            self.overlay.show_current_panel();
        };
        if (!GotoOverlay.prototype.show_sub_panel.__argnames__) Object.defineProperties(GotoOverlay.prototype.show_sub_panel, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "read_book.overlay"}
        });
        GotoOverlay.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        GotoOverlay.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(GotoOverlay.prototype, "__bases__", {value: []});

        function WordActionsOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            WordActionsOverlay.prototype.__bind_methods__.call(this);
            WordActionsOverlay.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(WordActionsOverlay.prototype, "__bind_methods__", {value: function () {
            this.on_container_click = WordActionsOverlay.prototype.on_container_click.bind(this);
            this.show = WordActionsOverlay.prototype.show.bind(this);
        }});
        WordActionsOverlay.prototype.__init__ = function __init__(word, overlay) {
            var self = this;
            self.word = word;
            self.overlay = overlay;
        };
        if (!WordActionsOverlay.prototype.__init__.__argnames__) Object.defineProperties(WordActionsOverlay.prototype.__init__, {
            __argnames__ : {value: ["word", "overlay"]},
            __module__ : {value: "read_book.overlay"}
        });
        WordActionsOverlay.__argnames__ = WordActionsOverlay.prototype.__init__.__argnames__;
        WordActionsOverlay.__handles_kwarg_interpolation__ = WordActionsOverlay.prototype.__init__.__handles_kwarg_interpolation__;
        WordActionsOverlay.prototype.on_container_click = function on_container_click(evt) {
            var self = this;
        };
        if (!WordActionsOverlay.prototype.on_container_click.__argnames__) Object.defineProperties(WordActionsOverlay.prototype.on_container_click, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        WordActionsOverlay.prototype.show = function show(container) {
            var self = this;
            simple_overlay_title(_("Lookup: {}").format(self.word), self.overlay, container);
            create_word_actions_panel(container, self.word, self.overlay.hide);
        };
        if (!WordActionsOverlay.prototype.show.__argnames__) Object.defineProperties(WordActionsOverlay.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        WordActionsOverlay.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        WordActionsOverlay.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(WordActionsOverlay.prototype, "__bases__", {value: []});

        function PrefsOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            PrefsOverlay.prototype.__bind_methods__.call(this);
            PrefsOverlay.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(PrefsOverlay.prototype, "__bind_methods__", {value: function () {
            this.on_container_click = PrefsOverlay.prototype.on_container_click.bind(this);
            this.create_panel_impl = PrefsOverlay.prototype.create_panel_impl.bind(this);
            this.show = PrefsOverlay.prototype.show.bind(this);
            this.on_change = PrefsOverlay.prototype.on_change.bind(this);
            this.handle_escape = PrefsOverlay.prototype.handle_escape.bind(this);
            this.on_hide = PrefsOverlay.prototype.on_hide.bind(this);
        }});
        PrefsOverlay.prototype.__init__ = function __init__(overlay) {
            var self = this;
            self.overlay = overlay;
            self.changes_occurred = false;
        };
        if (!PrefsOverlay.prototype.__init__.__argnames__) Object.defineProperties(PrefsOverlay.prototype.__init__, {
            __argnames__ : {value: ["overlay"]},
            __module__ : {value: "read_book.overlay"}
        });
        PrefsOverlay.__argnames__ = PrefsOverlay.prototype.__init__.__argnames__;
        PrefsOverlay.__handles_kwarg_interpolation__ = PrefsOverlay.prototype.__init__.__handles_kwarg_interpolation__;
        PrefsOverlay.prototype.on_container_click = function on_container_click(evt) {
            var self = this;
        };
        if (!PrefsOverlay.prototype.on_container_click.__argnames__) Object.defineProperties(PrefsOverlay.prototype.on_container_click, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        PrefsOverlay.prototype.create_panel_impl = function create_panel_impl(container) {
            var self = this;
            return create_prefs_panel(container, self.overlay.hide_current_panel, self.on_change);
        };
        if (!PrefsOverlay.prototype.create_panel_impl.__argnames__) Object.defineProperties(PrefsOverlay.prototype.create_panel_impl, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        PrefsOverlay.prototype.show = function show(container) {
            var self = this;
            self.changes_occurred = false;
            apply_viewer_chrome_colors(container);
            self.prefs = self.create_panel_impl(container);
        };
        if (!PrefsOverlay.prototype.show.__argnames__) Object.defineProperties(PrefsOverlay.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        PrefsOverlay.prototype.on_change = function on_change() {
            var self = this;
            self.changes_occurred = true;
        };
        if (!PrefsOverlay.prototype.on_change.__module__) Object.defineProperties(PrefsOverlay.prototype.on_change, {
            __module__ : {value: "read_book.overlay"}
        });
        PrefsOverlay.prototype.handle_escape = function handle_escape() {
            var self = this;
            self.prefs.onclose();
        };
        if (!PrefsOverlay.prototype.handle_escape.__module__) Object.defineProperties(PrefsOverlay.prototype.handle_escape, {
            __module__ : {value: "read_book.overlay"}
        });
        PrefsOverlay.prototype.on_hide = function on_hide() {
            var self = this;
            if (self.changes_occurred) {
                self.changes_occurred = false;
                self.overlay.view.preferences_changed();
            }
        };
        if (!PrefsOverlay.prototype.on_hide.__module__) Object.defineProperties(PrefsOverlay.prototype.on_hide, {
            __module__ : {value: "read_book.overlay"}
        });
        PrefsOverlay.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        PrefsOverlay.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(PrefsOverlay.prototype, "__bases__", {value: []});

        function ProfilesOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ProfilesOverlay.prototype.__bind_methods__.call(this);
            ProfilesOverlay.prototype.__init__.apply(this, arguments);
        }
        ρσ_extends(ProfilesOverlay, PrefsOverlay);
        Object.defineProperty(ProfilesOverlay.prototype, "__bind_methods__", {value: function () {
            PrefsOverlay.prototype.__bind_methods__ && PrefsOverlay.prototype.__bind_methods__.call(this);
            this.create_panel_impl = ProfilesOverlay.prototype.create_panel_impl.bind(this);
            this.handle_escape = ProfilesOverlay.prototype.handle_escape.bind(this);
        }});
        ProfilesOverlay.prototype.__init__ = function __init__ () {
            PrefsOverlay.prototype.__init__ && PrefsOverlay.prototype.__init__.apply(this, arguments);
        };
        ProfilesOverlay.prototype.create_panel_impl = function create_panel_impl(container) {
            var self = this;
            return create_profiles_panel(container, self.overlay.hide_current_panel, self.on_change);
        };
        if (!ProfilesOverlay.prototype.create_panel_impl.__argnames__) Object.defineProperties(ProfilesOverlay.prototype.create_panel_impl, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        ProfilesOverlay.prototype.handle_escape = function handle_escape() {
            var self = this;
            self.overlay.hide_current_panel();
        };
        if (!ProfilesOverlay.prototype.handle_escape.__module__) Object.defineProperties(ProfilesOverlay.prototype.handle_escape, {
            __module__ : {value: "read_book.overlay"}
        });
        ProfilesOverlay.prototype.__repr__ = function __repr__ () {
            if(PrefsOverlay.prototype.__repr__) return PrefsOverlay.prototype.__repr__.call(this);
            return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ProfilesOverlay.prototype.__str__ = function __str__ () {
            if(PrefsOverlay.prototype.__str__) return PrefsOverlay.prototype.__str__.call(this);
return this.__repr__();
        };
        Object.defineProperty(ProfilesOverlay.prototype, "__bases__", {value: [PrefsOverlay]});

        function FontSizeOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            FontSizeOverlay.prototype.__bind_methods__.call(this);
            FontSizeOverlay.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(FontSizeOverlay.prototype, "__bind_methods__", {value: function () {
            this.show = FontSizeOverlay.prototype.show.bind(this);
        }});
        FontSizeOverlay.prototype.__init__ = function __init__(overlay) {
            var self = this;
            self.overlay = overlay;
        };
        if (!FontSizeOverlay.prototype.__init__.__argnames__) Object.defineProperties(FontSizeOverlay.prototype.__init__, {
            __argnames__ : {value: ["overlay"]},
            __module__ : {value: "read_book.overlay"}
        });
        FontSizeOverlay.__argnames__ = FontSizeOverlay.prototype.__init__.__argnames__;
        FontSizeOverlay.__handles_kwarg_interpolation__ = FontSizeOverlay.prototype.__init__.__handles_kwarg_interpolation__;
        FontSizeOverlay.prototype.show = function show(container) {
            var self = this;
            create_font_size_panel(container, self.overlay.hide_current_panel);
        };
        if (!FontSizeOverlay.prototype.show.__argnames__) Object.defineProperties(FontSizeOverlay.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        FontSizeOverlay.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        FontSizeOverlay.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(FontSizeOverlay.prototype, "__bases__", {value: []});

        function OpenBook() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            OpenBook.prototype.__bind_methods__.call(this);
            OpenBook.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(OpenBook.prototype, "__bind_methods__", {value: function () {
            this.handle_escape = OpenBook.prototype.handle_escape.bind(this);
            this.on_container_click = OpenBook.prototype.on_container_click.bind(this);
            this.show = OpenBook.prototype.show.bind(this);
        }});
        OpenBook.prototype.__init__ = function __init__(overlay, closeable) {
            var self = this;
            self.overlay = overlay;
            self.closeable = closeable;
        };
        if (!OpenBook.prototype.__init__.__argnames__) Object.defineProperties(OpenBook.prototype.__init__, {
            __argnames__ : {value: ["overlay", "closeable"]},
            __module__ : {value: "read_book.overlay"}
        });
        OpenBook.__argnames__ = OpenBook.prototype.__init__.__argnames__;
        OpenBook.__handles_kwarg_interpolation__ = OpenBook.prototype.__init__.__handles_kwarg_interpolation__;
        OpenBook.prototype.handle_escape = function handle_escape() {
            var self = this;
            if (self.closeable) {
                self.overlay.hide_current_panel();
            } else {
                if (self.overlay.handling_context_menu_event === null) {
                    ui_operations.quit();
                }
            }
        };
        if (!OpenBook.prototype.handle_escape.__module__) Object.defineProperties(OpenBook.prototype.handle_escape, {
            __module__ : {value: "read_book.overlay"}
        });
        OpenBook.prototype.on_container_click = function on_container_click(evt) {
            var self = this;
        };
        if (!OpenBook.prototype.on_container_click.__argnames__) Object.defineProperties(OpenBook.prototype.on_container_click, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        OpenBook.prototype.show = function show(container) {
            var self = this;
            simple_overlay_title(_("Open a book"), self.overlay, container, (function() {
                var ρσ_anonfunc = function () {
                    var ev;
                    ev = this;
                    [ev.stopPropagation(), ev.preventDefault()];
                    if (self.closeable) {
                        self.overlay.hide_current_panel(ev);
                    } else {
                        ui_operations.quit();
                    }
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.overlay"}
                });
                return ρσ_anonfunc;
            })());
            create_open_book(container, ρσ_exists.d(self.overlay.view).book);
        };
        if (!OpenBook.prototype.show.__argnames__) Object.defineProperties(OpenBook.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        OpenBook.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        OpenBook.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(OpenBook.prototype, "__bases__", {value: []});

        function ReadingStatsOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ReadingStatsOverlay.prototype.__bind_methods__.call(this);
            ReadingStatsOverlay.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ReadingStatsOverlay.prototype, "__bind_methods__", {value: function () {
            this.on_container_click = ReadingStatsOverlay.prototype.on_container_click.bind(this);
            this.reset_stats = ReadingStatsOverlay.prototype.reset_stats.bind(this);
            this.do_reset = ReadingStatsOverlay.prototype.do_reset.bind(this);
            this.show = ReadingStatsOverlay.prototype.show.bind(this);
        }});
        ReadingStatsOverlay.prototype.__init__ = function __init__(overlay) {
            var self = this;
            self.overlay = overlay;
        };
        if (!ReadingStatsOverlay.prototype.__init__.__argnames__) Object.defineProperties(ReadingStatsOverlay.prototype.__init__, {
            __argnames__ : {value: ["overlay"]},
            __module__ : {value: "read_book.overlay"}
        });
        ReadingStatsOverlay.__argnames__ = ReadingStatsOverlay.prototype.__init__.__argnames__;
        ReadingStatsOverlay.__handles_kwarg_interpolation__ = ReadingStatsOverlay.prototype.__init__.__handles_kwarg_interpolation__;
        ReadingStatsOverlay.prototype.on_container_click = function on_container_click(evt) {
            var self = this;
        };
        if (!ReadingStatsOverlay.prototype.on_container_click.__argnames__) Object.defineProperties(ReadingStatsOverlay.prototype.on_container_click, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        ReadingStatsOverlay.prototype.reset_stats = function reset_stats() {
            var self = this;
            question_dialog(_("Reset reading statistics"), _("Are you sure you want to delete all reading statistics? This will remove all saved reading rate data."), (function() {
                var ρσ_anonfunc = function (yes) {
                    if (yes) {
                        self.do_reset();
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["yes"]},
                    __module__ : {value: "read_book.overlay"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!ReadingStatsOverlay.prototype.reset_stats.__module__) Object.defineProperties(ReadingStatsOverlay.prototype.reset_stats, {
            __module__ : {value: "read_book.overlay"}
        });
        ReadingStatsOverlay.prototype.do_reset = function do_reset() {
            var self = this;
            var view;
            view = self.overlay.view;
            if (view.timers) {
                view.timers.rates = [];
                view.timers.chapter_times = {};
                view.timers.average = view.timers.stddev = 0;
            }
            if (ui_operations.reset_reading_rates) {
                ui_operations.reset_reading_rates();
            }
            self.overlay.hide_current_panel();
        };
        if (!ReadingStatsOverlay.prototype.do_reset.__module__) Object.defineProperties(ReadingStatsOverlay.prototype.do_reset, {
            __module__ : {value: "read_book.overlay"}
        });
        ReadingStatsOverlay.prototype.show = function show(container) {
            var self = this;
            var view, book, spine, current_name, current_idx, file_progress, chapter_length, remaining_chars, chapter_remaining_time, chapter_done_pct, total_chapters, next_idx, next_name, next_chapter_time, next_length, book_remaining_chars, spine_idx, book_remaining_time, content, chapter_times, bar_data, max_time, name, length, is_current, actual_t, rem, t, is_actual, i, BAR_H, BAR_W, BAR_GAP, COLOR_ACTUAL, COLOR_CURRENT, COLOR_ESTIMATED, COLOR_PAST_EST, graph_section, bars_row, bd, h, color, outline, label, tip, bar, scroll_offset, legend;
            simple_overlay_title(_("Reading statistics"), self.overlay, container);
            view = self.overlay.view;
            book = view.book;
            if (!book || !book.manifest) {
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("No book open")].concat([ρσ_desugar_kwargs({style: "padding: 1ex 1em"})])));
                return;
            }
            spine = book.manifest.spine;
            current_name = view.currently_showing.name;
            current_idx = spine.indexOf(current_name);
            file_progress = view.current_file_progress_frac;
            chapter_length = ρσ_exists.d((ρσ_expr_temp = book.manifest.files)[(typeof current_name === "number" && current_name < 0) ? ρσ_expr_temp.length + current_name : current_name]).length || 0;
            remaining_chars = chapter_length * max(0, 1 - file_progress);
            chapter_remaining_time = view.timers.time_for(remaining_chars);
            chapter_done_pct = Math.round(file_progress * 100);
            total_chapters = spine.length;
            next_idx = current_idx + 1;
            next_name = (next_idx < spine.length) ? spine[(typeof next_idx === "number" && next_idx < 0) ? spine.length + next_idx : next_idx] : null;
            next_chapter_time = null;
            if (next_name) {
                next_length = ρσ_exists.d((ρσ_expr_temp = book.manifest.files)[(typeof next_name === "number" && next_name < 0) ? ρσ_expr_temp.length + next_name : next_name]).length || 0;
                next_chapter_time = view.timers.time_for(next_length);
            }
            book_remaining_chars = remaining_chars;
            for (var ρσ_Index2 = next_idx; ρσ_Index2 < spine.length; ρσ_Index2++) {
                spine_idx = ρσ_Index2;
                book_remaining_chars += ρσ_exists.d((ρσ_expr_temp = book.manifest.files)[ρσ_bound_index(spine[(typeof spine_idx === "number" && spine_idx < 0) ? spine.length + spine_idx : spine_idx], ρσ_expr_temp)]).length || 0;
            }
            book_remaining_time = view.timers.time_for(book_remaining_chars);
            content = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "padding: 1ex 1em"})]);
            if (current_idx >= 0) {
                content.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [(ρσ_expr_temp = _("Chapter {current} of {total}: {pct}% complete"), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.format, [ρσ_desugar_kwargs({current: current_idx + 1, total: total_chapters, pct: chapter_done_pct})]))].concat([ρσ_desugar_kwargs({style: "margin: 0.5ex 0; font-weight: bold"})])));
            }
            if (chapter_remaining_time !== null) {
                content.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [_("Time remaining in chapter: {}").format(format_time_left(chapter_remaining_time))].concat([ρσ_desugar_kwargs({style: "margin: 0.5ex 0"})])));
            } else {
                content.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [_("Time remaining in chapter: {}").format(_("Calculating…"))].concat([ρσ_desugar_kwargs({style: "margin: 0.5ex 0"})])));
            }
            if (book_remaining_time !== null) {
                content.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [_("Time remaining in book: {}").format(format_time_left(book_remaining_time))].concat([ρσ_desugar_kwargs({style: "margin: 0.5ex 0"})])));
            } else {
                content.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [_("Time remaining in book: {}").format(_("Calculating…"))].concat([ρσ_desugar_kwargs({style: "margin: 0.5ex 0"})])));
            }
            if (next_name) {
                if (next_chapter_time !== null) {
                    content.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [_("Time to read next chapter: {}").format(format_time_left(next_chapter_time))].concat([ρσ_desugar_kwargs({style: "margin: 0.5ex 0"})])));
                } else {
                    content.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [_("Time to read next chapter: {}").format(_("Calculating…"))].concat([ρσ_desugar_kwargs({style: "margin: 0.5ex 0"})])));
                }
            } else {
                content.appendChild(ρσ_interpolate_kwargs.call(E, E.p, [_("This is the last chapter")].concat([ρσ_desugar_kwargs({style: "margin: 0.5ex 0"})])));
            }
            container.appendChild(content);
            chapter_times = view.timers.chapter_times;
            bar_data = [];
            max_time = 0;
            for (var ρσ_Index3 = 0; ρσ_Index3 < spine.length; ρσ_Index3++) {
                i = ρσ_Index3;
                name = spine[(typeof i === "number" && i < 0) ? spine.length + i : i];
                length = ρσ_exists.d((ρσ_expr_temp = book.manifest.files)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]).length || 0;
                is_current = (i === current_idx || typeof i === "object" && ρσ_equals(i, current_idx));
                if (is_current) {
                    actual_t = chapter_times[(typeof name === "number" && name < 0) ? chapter_times.length + name : name] || 0;
                    rem = view.timers.time_for(remaining_chars);
                    t = (rem !== null) ? actual_t + rem : view.timers.time_for(length);
                    is_actual = actual_t > 0;
                } else if (i < current_idx) {
                    actual_t = chapter_times[(typeof name === "number" && name < 0) ? chapter_times.length + name : name];
                    if (actual_t && actual_t > 0) {
                        t = actual_t;
                        is_actual = true;
                    } else {
                        t = view.timers.time_for(length);
                        is_actual = false;
                    }
                } else {
                    t = view.timers.time_for(length);
                    is_actual = false;
                }
                if (t !== null && t > 0) {
                    max_time = Math.max(max_time, t);
                }
                bar_data.push((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["t"] = t;
                    ρσ_d["is_actual"] = is_actual;
                    ρσ_d["is_current"] = is_current;
                    ρσ_d["past"] = i < current_idx;
                    return ρσ_d;
                }).call(this));
            }
            BAR_H = 120;
            BAR_W = 22;
            BAR_GAP = 3;
            COLOR_ACTUAL = "#27ae60";
            COLOR_CURRENT = "#e67e22";
            COLOR_ESTIMATED = "#7fb3d3";
            COLOR_PAST_EST = "#95a5a6";
            graph_section = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "padding: 0 1em 1em 1em"})]);
            graph_section.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Chapter reading times")].concat([ρσ_desugar_kwargs({style: "font-size: smaller; font-weight: bold; margin-bottom: 0.5ex"})])));
            if (max_time > 0) {
                bars_row = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display: flex; align-items: flex-end; overflow-x: auto; " + ("border-bottom: 1px solid currentColor; min-height: " + ρσ_str.format("{}", BAR_H + 4) + "px; padding-top: 4px")})]);
                for (var ρσ_Index4 = 0; ρσ_Index4 < bar_data.length; ρσ_Index4++) {
                    i = ρσ_Index4;
                    bd = bar_data[(typeof i === "number" && i < 0) ? bar_data.length + i : i];
                    t = bd.t;
                    if (t !== null && t > 0) {
                        h = max(2, Math.round(t / max_time * BAR_H));
                    } else {
                        h = 2;
                    }
                    if (bd.is_current) {
                        color = COLOR_CURRENT;
                    } else if (bd.is_actual) {
                        color = COLOR_ACTUAL;
                    } else if (bd.past) {
                        color = COLOR_PAST_EST;
                    } else {
                        color = COLOR_ESTIMATED;
                    }
                    outline = (bd.is_current) ? "outline: 2px solid currentColor; outline-offset: 1px; " : "";
                    label = str(i + 1);
                    tip = _("Chapter {}").format(i + 1);
                    if (t && t > 0) {
                        tip += ": " + format_time_left(t);
                    } else if (bd.is_current || bd.past) {
                        tip += " (" + _("no data") + ")";
                    } else {
                        tip += " (" + _("Calculating…") + ")";
                    }
                    bar = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "width: " + ρσ_str.format("{}", BAR_W) + "px; height: " + ρσ_str.format("{}", h) + "px; background-color: " + ρσ_str.format("{}", color) + "; " + ρσ_str.format("{}", outline) + ""})]), ρσ_interpolate_kwargs.call(E, E.div, [label].concat([ρσ_desugar_kwargs({style: "font-size: 9px; text-align: center; width: " + ρσ_str.format("{}", BAR_W) + "px; margin-top: 2px; overflow: hidden"})]))].concat([ρσ_desugar_kwargs({style: "display: inline-flex; flex-direction: column; align-items: center; " + ("width: " + ρσ_str.format("{}", BAR_W) + "px; flex-shrink: 0; margin-right: " + ρσ_str.format("{}", BAR_GAP) + "px; cursor: default"), title: tip})]));
                    bars_row.appendChild(bar);
                }
                graph_section.appendChild(bars_row);
                if (current_idx >= 0) {
                    scroll_offset = max(0, current_idx * (BAR_W + BAR_GAP) - 80);
                    window.setTimeout((function() {
                        var ρσ_anonfunc = function () {
                            bars_row.scrollLeft = scroll_offset;
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })(), 0);
                }
            } else {
                graph_section.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Start reading to see chapter time statistics")].concat([ρσ_desugar_kwargs({style: "color: {}; font-style: italic".format(get_color("faded-text"))})])));
            }
            legend = ρσ_interpolate_kwargs.call(E, E.div, [E.span(ρσ_interpolate_kwargs.call(E, E.span, ["■ "].concat([ρσ_desugar_kwargs({style: "color: " + ρσ_str.format("{}", COLOR_ACTUAL) + ""})])), _("Actual time")), E.span(ρσ_interpolate_kwargs.call(E, E.span, ["■ "].concat([ρσ_desugar_kwargs({style: "color: " + ρσ_str.format("{}", COLOR_CURRENT) + ""})])), _("Current chapter")), E.span(ρσ_interpolate_kwargs.call(E, E.span, ["■ "].concat([ρσ_desugar_kwargs({style: "color: " + ρσ_str.format("{}", COLOR_ESTIMATED) + ""})])), _("Estimated")), E.span(ρσ_interpolate_kwargs.call(E, E.span, ["■ "].concat([ρσ_desugar_kwargs({style: "color: " + ρσ_str.format("{}", COLOR_PAST_EST) + ""})])), _("Previous (estimated)"))].concat([ρσ_desugar_kwargs({style: "display: flex; gap: 1em; margin-top: 0.5ex; font-size: smaller; flex-wrap: wrap"})]));
            graph_section.appendChild(legend);
            container.appendChild(graph_section);
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("For reading stats, a \"chapter\" is a single internal file inside the larger book. If you see very few \"chapters\" above, then try converting your book to EPUB in calibre, that will often automatically split up the book into per chapter files.")].concat([ρσ_desugar_kwargs({style: "padding: 0 1em 1em 1em; font-size: smaller"})])));
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(this, create_button, [_("Reset statistics"), "trash"].concat([ρσ_desugar_kwargs({action: self.reset_stats})]))].concat([ρσ_desugar_kwargs({style: "padding: 0 1em 1em 1em; display: flex; justify-content: flex-end"})])));
        };
        if (!ReadingStatsOverlay.prototype.show.__argnames__) Object.defineProperties(ReadingStatsOverlay.prototype.show, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.overlay"}
        });
        ReadingStatsOverlay.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ReadingStatsOverlay.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ReadingStatsOverlay.prototype, "__bases__", {value: []});

        function Overlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            Overlay.prototype.__bind_methods__.call(this);
            Overlay.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(Overlay.prototype, "__bind_methods__", {value: function () {
            this.oncontextmenu = Overlay.prototype.oncontextmenu.bind(this);
            this.clear_container = Overlay.prototype.clear_container.bind(this);
            this.update_visibility = Overlay.prototype.update_visibility.bind(this);
            this.container_clicked = Overlay.prototype.container_clicked.bind(this);
            this.show_loading_message = Overlay.prototype.show_loading_message.bind(this);
            this.hide_loading_message = Overlay.prototype.hide_loading_message.bind(this);
            this.hide_current_panel = Overlay.prototype.hide_current_panel.bind(this);
            this.handle_escape = Overlay.prototype.handle_escape.bind(this);
            this.show_current_panel = Overlay.prototype.show_current_panel.bind(this);
            this.show = Overlay.prototype.show.bind(this);
            this.hide = Overlay.prototype.hide.bind(this);
            this.delete_book = Overlay.prototype.delete_book.bind(this);
            this.reload_book = Overlay.prototype.reload_book.bind(this);
            this.open_book = Overlay.prototype.open_book.bind(this);
            this.sync_book = Overlay.prototype.sync_book.bind(this);
            this.show_toc = Overlay.prototype.show_toc.bind(this);
            this.toggle_reference_mode = Overlay.prototype.toggle_reference_mode.bind(this);
            this.show_bookmarks = Overlay.prototype.show_bookmarks.bind(this);
            this.show_highlights = Overlay.prototype.show_highlights.bind(this);
            this.show_profiles = Overlay.prototype.show_profiles.bind(this);
            this.show_goto = Overlay.prototype.show_goto.bind(this);
            this._build_metadata_panel = Overlay.prototype._build_metadata_panel.bind(this);
            this.show_metadata = Overlay.prototype.show_metadata.bind(this);
            this.show_ask_for_location = Overlay.prototype.show_ask_for_location.bind(this);
            this.show_page_list = Overlay.prototype.show_page_list.bind(this);
            this.show_search = Overlay.prototype.show_search.bind(this);
            this.show_reading_stats = Overlay.prototype.show_reading_stats.bind(this);
            this.show_prefs = Overlay.prototype.show_prefs.bind(this);
            this.show_library = Overlay.prototype.show_library.bind(this);
            this.show_book_page = Overlay.prototype.show_book_page.bind(this);
            this.show_font_size_chooser = Overlay.prototype.show_font_size_chooser.bind(this);
            this.show_word_actions = Overlay.prototype.show_word_actions.bind(this);
        }});
        Object.defineProperties(Overlay.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById("book-overlay");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "is_visible": {
                "enumerable": true, 
                "get": function is_visible() {
                    var self = this;
                    return self.container.style.display !== "none";
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        Overlay.prototype.__init__ = function __init__(view) {
            var self = this;
            var c;
            self.view = view;
            self.handling_context_menu_event = null;
            c = self.clear_container();
            c.addEventListener("click", self.container_clicked);
            c.addEventListener("contextmenu", self.oncontextmenu, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            self.panels = ρσ_list_decorate([]);
        };
        if (!Overlay.prototype.__init__.__argnames__) Object.defineProperties(Overlay.prototype.__init__, {
            __argnames__ : {value: ["view"]},
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.__argnames__ = Overlay.prototype.__init__.__argnames__;
        Overlay.__handles_kwarg_interpolation__ = Overlay.prototype.__init__.__handles_kwarg_interpolation__;
        Overlay.prototype.oncontextmenu = function oncontextmenu(evt) {
            var self = this;
            if (default_context_menu_should_be_allowed(evt)) {
                return;
            }
            evt.preventDefault();
            self.handling_context_menu_event = evt;
            self.handle_escape();
            self.handling_context_menu_event = null;
        };
        if (!Overlay.prototype.oncontextmenu.__argnames__) Object.defineProperties(Overlay.prototype.oncontextmenu, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.clear_container = function clear_container() {
            var self = this;
            var c, colors;
            c = self.container;
            colors = viewer_chrome_colors();
            clear(c);
            c.style.backgroundColor = "transparent";
            c.style.color = colors.foreground;
            if (c.style.display !== "block") {
                c.style.display = "block";
            }
            return c;
        };
        if (!Overlay.prototype.clear_container.__module__) Object.defineProperties(Overlay.prototype.clear_container, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.update_visibility = function update_visibility() {
            var self = this;
            if (self.panels.length) {
                self.container.style.display = "block";
                self.view.overlay_visibility_changed(true);
            } else if (self.container.style.display === "block") {
                self.container.style.display = "none";
                self.view.focus_iframe();
                self.view.overlay_visibility_changed(false);
            }
        };
        if (!Overlay.prototype.update_visibility.__module__) Object.defineProperties(Overlay.prototype.update_visibility, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.container_clicked = function container_clicked(evt) {
            var self = this;
            if (self.panels.length && typeof (ρσ_expr_temp = self.panels)[ρσ_expr_temp.length-1].on_container_click === "function") {
                (ρσ_expr_temp = self.panels)[ρσ_expr_temp.length-1].on_container_click(evt);
            } else {
                self.hide_current_panel();
            }
        };
        if (!Overlay.prototype.container_clicked.__argnames__) Object.defineProperties(Overlay.prototype.container_clicked, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_loading_message = function show_loading_message(msg) {
            var self = this;
            var lm;
            if (ui_operations.show_loading_message) {
                ui_operations.show_loading_message(msg);
            } else {
                lm = new LoadingMessage(msg, self.view.current_color_scheme);
                self.panels.push(lm);
                self.show_current_panel();
            }
        };
        if (!Overlay.prototype.show_loading_message.__argnames__) Object.defineProperties(Overlay.prototype.show_loading_message, {
            __argnames__ : {value: ["msg"]},
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.hide_loading_message = function hide_loading_message() {
            var self = this;
            var p;
            if (ui_operations.show_loading_message) {
                ui_operations.show_loading_message(null);
            } else {
                self.panels = (function() {
                    var ρσ_Iter = ρσ_Iterable(self.panels), ρσ_Result = [], p;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        p = ρσ_Iter[ρσ_Index];
                        if (!(ρσ_instanceof(p, LoadingMessage))) {
                            ρσ_Result.push(p);
                        }
                    }
                    ρσ_Result = ρσ_list_constructor(ρσ_Result);
                    return ρσ_Result;
                })();
                self.show_current_panel();
            }
        };
        if (!Overlay.prototype.hide_loading_message.__module__) Object.defineProperties(Overlay.prototype.hide_loading_message, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.hide_current_panel = function hide_current_panel() {
            var self = this;
            var p;
            p = self.panels.pop();
            if (p && callable(p.on_hide)) {
                p.on_hide();
            }
            self.show_current_panel();
        };
        if (!Overlay.prototype.hide_current_panel.__module__) Object.defineProperties(Overlay.prototype.hide_current_panel, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.handle_escape = function handle_escape() {
            var self = this;
            var p;
            if (self.panels.length) {
                p = (ρσ_expr_temp = self.panels)[ρσ_expr_temp.length-1];
                if (!p.is_not_escapable) {
                    if (p.handle_escape) {
                        p.handle_escape();
                    } else {
                        self.hide_current_panel();
                    }
                    return true;
                }
            }
            return false;
        };
        if (!Overlay.prototype.handle_escape.__module__) Object.defineProperties(Overlay.prototype.handle_escape, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_current_panel = function show_current_panel() {
            var self = this;
            var c;
            if (self.panels.length) {
                c = self.clear_container();
                (ρσ_expr_temp = self.panels)[ρσ_expr_temp.length-1].show(c);
            }
            self.update_visibility();
        };
        if (!Overlay.prototype.show_current_panel.__module__) Object.defineProperties(Overlay.prototype.show_current_panel, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show = function show(elements) {
            var self = this;
            self.panels = ρσ_list_decorate([ new MainOverlay(self, elements) ]);
            self.show_current_panel();
        };
        if (!Overlay.prototype.show.__argnames__) Object.defineProperties(Overlay.prototype.show, {
            __argnames__ : {value: ["elements"]},
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.hide = function hide() {
            var self = this;
            while (self.panels.length) {
                self.hide_current_panel();
            }
            self.update_visibility();
        };
        if (!Overlay.prototype.hide.__module__) Object.defineProperties(Overlay.prototype.hide, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.delete_book = function delete_book() {
            var self = this;
            self.hide_current_panel();
            self.panels = ρσ_list_decorate([ new DeleteBook(self) ]);
            self.show_current_panel();
        };
        if (!Overlay.prototype.delete_book.__module__) Object.defineProperties(Overlay.prototype.delete_book, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.reload_book = function reload_book() {
            var self = this;
            self.hide_current_panel();
            self.panels = ρσ_list_decorate([ new DeleteBook(self, _("Are you sure you want to reload this book?"), "refresh", _("Reload book"), true) ]);
            self.show_current_panel();
        };
        if (!Overlay.prototype.reload_book.__module__) Object.defineProperties(Overlay.prototype.reload_book, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.open_book = function open_book(closeable) {
            var self = this;
            self.hide_current_panel();
            if (typeof closeable !== "boolean") {
                closeable = true;
            }
            self.panels = ρσ_list_decorate([ new OpenBook(self, closeable) ]);
            self.show_current_panel();
        };
        if (!Overlay.prototype.open_book.__argnames__) Object.defineProperties(Overlay.prototype.open_book, {
            __argnames__ : {value: ["closeable"]},
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.sync_book = function sync_book() {
            var self = this;
            self.hide_current_panel();
            self.panels = ρσ_list_decorate([ new SyncBook(self) ]);
            self.show_current_panel();
        };
        if (!Overlay.prototype.sync_book.__module__) Object.defineProperties(Overlay.prototype.sync_book, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_toc = function show_toc() {
            var self = this;
            self.hide_current_panel();
            if (runtime.is_standalone_viewer) {
                ui_operations.toggle_toc();
                return;
            }
            self.panels.push(new TOCOverlay(self));
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_toc.__module__) Object.defineProperties(Overlay.prototype.show_toc, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.toggle_reference_mode = function toggle_reference_mode() {
            var self = this;
            self.hide_current_panel();
            self.view.toggle_reference_mode();
        };
        if (!Overlay.prototype.toggle_reference_mode.__module__) Object.defineProperties(Overlay.prototype.toggle_reference_mode, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_bookmarks = function show_bookmarks() {
            var self = this;
            self.hide_current_panel();
            if (runtime.is_standalone_viewer) {
                ui_operations.toggle_bookmarks();
                return;
            }
            function do_it(action, data) {
                self.panels.push(new TOCOverlay(self, create_bookmarks_panel.bind(null, self.view.annotations_manager, data), _("Bookmarks")));
                self.show_current_panel();
            };
            if (!do_it.__argnames__) Object.defineProperties(do_it, {
                __argnames__ : {value: ["action", "data"]},
                __module__ : {value: "read_book.overlay"}
            });

            self.view.get_current_cfi("show-bookmarks", do_it);
        };
        if (!Overlay.prototype.show_bookmarks.__module__) Object.defineProperties(Overlay.prototype.show_bookmarks, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_highlights = function show_highlights() {
            var self = this;
            self.hide_current_panel();
            if (ui_operations.toggle_highlights) {
                self.hide();
                ui_operations.toggle_highlights();
                return;
            }
            self.panels.push(new TOCOverlay(self, create_highlights_panel.bind(null, self.view.annotations_manager, self.hide_current_panel), _("Highlights")));
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_highlights.__module__) Object.defineProperties(Overlay.prototype.show_highlights, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_profiles = function show_profiles() {
            var self = this;
            self.hide_current_panel();
            self.panels.push(new ProfilesOverlay(self));
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_profiles.__module__) Object.defineProperties(Overlay.prototype.show_profiles, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_goto = function show_goto() {
            var self = this;
            self.hide_current_panel();
            self.panels.push(new GotoOverlay(self));
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_goto.__module__) Object.defineProperties(Overlay.prototype.show_goto, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype._build_metadata_panel = function _build_metadata_panel() {
            var self = this;
            var from_read_book, book, key, ρσ_unpack, lname, book_id, panel;
            from_read_book = short_uuid();
            function show_metadata_overlay(mi, pathtoebook, calibre_book_in_library_url, lname, book_id, overlay, container) {
                var container_id, table, a;
                container_id = ensure_id(container);
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({class_: BD_CLASS_NAME, style: "padding: 1ex 1em"})]));
                table = ρσ_interpolate_kwargs.call(E, E.table, [ρσ_desugar_kwargs({class_: "metadata"})]);
                function handle_message(msg) {
                    var data, mi, book_id, book;
                    data = msg.data;
                    if (data.from_read_book !== from_read_book) {
                        return;
                    }
                    if (data.type === "edit_metadata_closed") {
                        ui_operations.stop_waiting_for_messages_from(this);
                        self.hide_current_panel();
                        return;
                    }
                    if (data.type === "update_cached_book_metadata" && data.metadata) {
                        if (current_library_id() === data.library_id) {
                            mi = data.metadata;
                            book_id = int(data.book_id);
                            set_book_metadata(book_id, mi);
                            book = self.view.book;
                            if (book && book.key[0] === data.library_id && book.key[1] === book_id) {
                                ui_operations.update_metadata(book, mi);
                            }
                        }
                    }
                };
                if (!handle_message.__argnames__) Object.defineProperties(handle_message, {
                    __argnames__ : {value: ["msg"]},
                    __module__ : {value: "read_book.overlay"}
                });

                if (!runtime.is_standalone_viewer && lname) {
                    container.lastChild.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.a, [_("Edit the metadata for this book in the library")].concat([ρσ_desugar_kwargs({class_: "blue-link", onclick: (function() {
                        var ρσ_anonfunc = function () {
                            var container, w;
                            container = document.getElementById(container_id);
                            clear(container);
                            container.appendChild(ρσ_interpolate_kwargs.call(E, E.iframe, [ρσ_desugar_kwargs({style: "position: absolute; left: 0; top: 0; width: 100vw; height: 100vh; border-width: 0", src: query_as_href((function(){
                                var ρσ_d = Object.create(null);
                                ρσ_d["from_read_book"] = from_read_book;
                                ρσ_d["library_id"] = lname;
                                ρσ_d["book_id"] = book_id + "";
                                return ρσ_d;
                            }).call(this), "edit_metadata")})]));
                            w = container.lastChild.contentWindow;
                            ui_operations.wait_for_messages_from(w, handle_message.bind(w));
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })()})]))].concat([ρσ_desugar_kwargs({style: "text-align: right"})])));
                }
                container.lastChild.appendChild(table);
                render_metadata(mi, table, null, "html { font-size: " + ρσ_str.format("{}", document.documentElement.style.fontSize) + " }");
                var ρσ_Iter5 = ρσ_Iterable(table.querySelectorAll("a[href]"));
                for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                    a = ρσ_Iter5[ρσ_Index5];
                    a.removeAttribute("href");
                    a.removeAttribute("title");
                    a.classList.remove("blue-link");
                    a.style.color = "currentColor";
                    a.style.textDecorationLine = "none";
                }
                if (pathtoebook) {
                    container.lastChild.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("Path:"), " ", ρσ_interpolate_kwargs.call(E, E.a, [pathtoebook].concat([ρσ_desugar_kwargs({href: "javascript: void(0)", class_: "blue-link", title: _("Click to open the folder the book is in"), onclick: (function() {
                        var ρσ_anonfunc = function () {
                            ui_operations.show_book_folder();
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.overlay"}
                        });
                        return ρσ_anonfunc;
                    })()})]))].concat([ρσ_desugar_kwargs({style: "margin-top: 1ex; padding-top: 1ex; border-top: solid 1px"})])));
                }
                if (calibre_book_in_library_url) {
                    container.lastChild.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.a, [_("Show book in the main calibre program")].concat([ρσ_desugar_kwargs({href: calibre_book_in_library_url, class_: "blue-link", title: _("Click to see this book in the main calibre program book list")})]))].concat([ρσ_desugar_kwargs({style: "margin-top: 1ex; padding-top: 1ex;"})])));
                }
            };
            if (!show_metadata_overlay.__argnames__) Object.defineProperties(show_metadata_overlay, {
                __argnames__ : {value: ["mi", "pathtoebook", "calibre_book_in_library_url", "lname", "book_id", "overlay", "container"]},
                __module__ : {value: "read_book.overlay"}
            });

            book = self.view.book;
            key = book.key || [null, 0];
            ρσ_unpack = key;
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            lname = ρσ_unpack[0];
            book_id = ρσ_unpack[1];
            book_id = int(book_id || 0);
            panel = new SimpleOverlay(self, show_metadata_overlay.bind(null, book.metadata, book.manifest.pathtoebook, book.calibre_book_in_library_url, lname, book_id), self.view.book.metadata.title);
            panel.from_read_book = from_read_book;
            return panel;
        };
        if (!Overlay.prototype._build_metadata_panel.__module__) Object.defineProperties(Overlay.prototype._build_metadata_panel, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_metadata = function show_metadata() {
            var self = this;
            self.hide_current_panel();
            self.panels.push(self._build_metadata_panel());
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_metadata.__module__) Object.defineProperties(Overlay.prototype.show_metadata, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_ask_for_location = function show_ask_for_location() {
            var self = this;
            self.hide_current_panel();
            self.panels.push(new SimpleOverlay(self, create_location_overlay.bind(null, self.view.current_position_data, self.view.book), _("Go to location, position or reference…")));
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_ask_for_location.__module__) Object.defineProperties(Overlay.prototype.show_ask_for_location, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_page_list = function show_page_list() {
            var self = this;
            self.hide_current_panel();
            self.panels.push(new SimpleOverlay(self, create_page_list_overlay.bind(null, self.view.book), _("Go to page")));
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_page_list.__module__) Object.defineProperties(Overlay.prototype.show_page_list, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_search = function show_search() {
            var self = this;
            self.hide();
            self.view.show_search();
        };
        if (!Overlay.prototype.show_search.__module__) Object.defineProperties(Overlay.prototype.show_search, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_reading_stats = function show_reading_stats() {
            var self = this;
            self.hide_current_panel();
            self.panels.push(new ReadingStatsOverlay(self));
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_reading_stats.__module__) Object.defineProperties(Overlay.prototype.show_reading_stats, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_prefs = function show_prefs() {
            var self = this;
            self.hide_current_panel();
            self.panels.push(new PrefsOverlay(self));
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_prefs.__module__) Object.defineProperties(Overlay.prototype.show_prefs, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_library = function show_library() {
            var self = this;
            var book;
            self.hide_current_panel();
            book = self.view.book;
            ρσ_interpolate_kwargs.call(this, show_panel, ["book_list", (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["library_id"] = book.key[0];
                ρσ_d["book_id"] = book.key[1] + "";
                return ρσ_d;
            }).call(this)].concat([ρσ_desugar_kwargs({replace: false})]));
            ui_operations.close_book();
        };
        if (!Overlay.prototype.show_library.__module__) Object.defineProperties(Overlay.prototype.show_library, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_book_page = function show_book_page() {
            var self = this;
            self.hide_current_panel();
            self.view.open_book_page();
            ui_operations.close_book();
        };
        if (!Overlay.prototype.show_book_page.__module__) Object.defineProperties(Overlay.prototype.show_book_page, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_font_size_chooser = function show_font_size_chooser() {
            var self = this;
            self.hide_current_panel();
            self.panels.push(new FontSizeOverlay(self));
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_font_size_chooser.__module__) Object.defineProperties(Overlay.prototype.show_font_size_chooser, {
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.show_word_actions = function show_word_actions(word) {
            var self = this;
            self.hide_current_panel();
            self.panels.push(new WordActionsOverlay(word, self));
            self.show_current_panel();
        };
        if (!Overlay.prototype.show_word_actions.__argnames__) Object.defineProperties(Overlay.prototype.show_word_actions, {
            __argnames__ : {value: ["word"]},
            __module__ : {value: "read_book.overlay"}
        });
        Overlay.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        Overlay.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(Overlay.prototype, "__bases__", {value: []});
        
        

        ρσ_modules["read_book.overlay"].LoadingMessage = LoadingMessage;
        ρσ_modules["read_book.overlay"].DeleteBook = DeleteBook;
        ρσ_modules["read_book.overlay"].SyncBook = SyncBook;
        ρσ_modules["read_book.overlay"].create_main_overlay_action_with_icon = create_main_overlay_action_with_icon;
        ρσ_modules["read_book.overlay"].create_main_overlay_action = create_main_overlay_action;
        ρσ_modules["read_book.overlay"].create_main_overlay_text_action = create_main_overlay_text_action;
        ρσ_modules["read_book.overlay"].create_main_overlay_footer_action = create_main_overlay_footer_action;
        ρσ_modules["read_book.overlay"].create_main_overlay_footer = create_main_overlay_footer;
        ρσ_modules["read_book.overlay"].render_main_overlay_footer_templates = render_main_overlay_footer_templates;
        ρσ_modules["read_book.overlay"].simple_overlay_title = simple_overlay_title;
        ρσ_modules["read_book.overlay"].MainOverlay = MainOverlay;
        ρσ_modules["read_book.overlay"].SimpleOverlay = SimpleOverlay;
        ρσ_modules["read_book.overlay"].TOCOverlay = TOCOverlay;
        ρσ_modules["read_book.overlay"].GotoOverlay = GotoOverlay;
        ρσ_modules["read_book.overlay"].WordActionsOverlay = WordActionsOverlay;
        ρσ_modules["read_book.overlay"].PrefsOverlay = PrefsOverlay;
        ρσ_modules["read_book.overlay"].ProfilesOverlay = ProfilesOverlay;
        ρσ_modules["read_book.overlay"].FontSizeOverlay = FontSizeOverlay;
        ρσ_modules["read_book.overlay"].OpenBook = OpenBook;
        ρσ_modules["read_book.overlay"].ReadingStatsOverlay = ReadingStatsOverlay;
        ρσ_modules["read_book.overlay"].Overlay = Overlay;
    })();

    (function(){
        var __name__ = "read_book.read_aloud";
        var HIDDEN, WAITING_FOR_PLAY_TO_START, PAUSED, PLAYING, STOPPED;
        var E = ρσ_modules.elementmaker.E;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var clear = ρσ_modules.dom.clear;
        var svgicon = ρσ_modules.dom.svgicon;
        var unique_id = ρσ_modules.dom.unique_id;

        var _ = ρσ_modules.gettext.gettext;

        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var ICON_SIZE = ρσ_modules["read_book.highlights"].ICON_SIZE;

        var BUTTON_MARGIN = ρσ_modules["read_book.selection_bar"].BUTTON_MARGIN;
        var get_margins = ρσ_modules["read_book.selection_bar"].get_margins;
        var map_to_iframe_coords = ρσ_modules["read_book.selection_bar"].map_to_iframe_coords;

        var shortcut_for_key_event = ρσ_modules["read_book.shortcuts"].shortcut_for_key_event;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        HIDDEN = 0;
        WAITING_FOR_PLAY_TO_START = 1;
        PAUSED = 2;
        PLAYING = 3;
        STOPPED = 4;
        function is_flow_mode() {
            var sd, mode;
            sd = get_session_data();
            mode = sd.get("read_mode");
            return mode === "flow";
        };
        if (!is_flow_mode.__module__) Object.defineProperties(is_flow_mode, {
            __module__ : {value: "read_book.read_aloud"}
        });

        function bar_class_and_position() {
            var sd, bp, iclass;
            sd = get_session_data();
            bp = sd.get("tts_bar_position");
            iclass = (ρσ_in("float", bp)) ? "floating" : "docked";
            return [iclass, bp];
        };
        if (!bar_class_and_position.__module__) Object.defineProperties(bar_class_and_position, {
            __module__ : {value: "read_book.read_aloud"}
        });

        function ReadAloud() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ReadAloud.prototype.__bind_methods__.call(this);
            ReadAloud.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ReadAloud.prototype, "__bind_methods__", {value: function () {
            this.hide = ReadAloud.prototype.hide.bind(this);
            this.show = ReadAloud.prototype.show.bind(this);
            this.focus = ReadAloud.prototype.focus.bind(this);
            this.build_docked_bar = ReadAloud.prototype.build_docked_bar.bind(this);
            this.create_buttons = ReadAloud.prototype.create_buttons.bind(this);
            this.build_bar = ReadAloud.prototype.build_bar.bind(this);
            this.configure = ReadAloud.prototype.configure.bind(this);
            this.slower = ReadAloud.prototype.slower.bind(this);
            this.faster = ReadAloud.prototype.faster.bind(this);
            this.play = ReadAloud.prototype.play.bind(this);
            this.pause = ReadAloud.prototype.pause.bind(this);
            this.stop = ReadAloud.prototype.stop.bind(this);
            this.toggle = ReadAloud.prototype.toggle.bind(this);
            this.container_clicked = ReadAloud.prototype.container_clicked.bind(this);
            this.on_keydown = ReadAloud.prototype.on_keydown.bind(this);
            this.handle_tts_event = ReadAloud.prototype.handle_tts_event.bind(this);
            this.send_message = ReadAloud.prototype.send_message.bind(this);
            this.handle_message = ReadAloud.prototype.handle_message.bind(this);
        }});
        Object.defineProperties(ReadAloud.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById("book-read-aloud-overlay");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "bar": {
                "enumerable": true, 
                "get": function bar() {
                    var self = this;
                    return document.getElementById(self.bar_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "is_visible": {
                "enumerable": true, 
                "get": function is_visible() {
                    var self = this;
                    return self.container.style.display !== "none";
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "state": {
                "enumerable": true, 
                "get": function state() {
                    var self = this;
                    return self._state;
                }, 
                "set": function state(val) {
                    var self = this;
                    if (val !== self._state) {
                        self._state = val;
                        self.build_bar();
                    }
                }
            }, 
        });
        ReadAloud.prototype.__init__ = function __init__(view) {
            var self = this;
            var container;
            self.view = view;
            self._state = HIDDEN;
            self.bar_id = unique_id("bar");
            container = self.container;
            container.setAttribute("tabindex", "0");
            container.style.overflow = "hidden";
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: self.bar_id})]));
            container.appendChild(E.style("#" + ρσ_str.format("{}", self.bar_id) + ".floating" + "{ border: solid 1px currentColor; border-radius: 5px; display: flex;" + " flex-direction: column; margin: 1rem; }\n\n", "#" + ρσ_str.format("{}", self.bar_id) + ".docked" + "{ border-radius: 1em; height: 2em; padding:0.5em; display: flex; justify-content: center; align-items: center; }\n\n", "#" + ρσ_str.format("{}", self.bar_id) + ".speaking " + "{ opacity: 0.5 }\n\n", "#" + ρσ_str.format("{}", self.bar_id) + ".speaking:hover " + "{ opacity: 1.0 }\n\n"));
            container.addEventListener("keydown", self.on_keydown, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("click", self.container_clicked, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("contextmenu", self.toggle, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
        };
        if (!ReadAloud.prototype.__init__.__argnames__) Object.defineProperties(ReadAloud.prototype.__init__, {
            __argnames__ : {value: ["view"]},
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.__argnames__ = ReadAloud.prototype.__init__.__argnames__;
        ReadAloud.__handles_kwarg_interpolation__ = ReadAloud.prototype.__init__.__handles_kwarg_interpolation__;
        ReadAloud.prototype.hide = function hide() {
            var self = this;
            if (self.state !== HIDDEN) {
                ui_operations.tts("stop");
                self.state = HIDDEN;
                self.container.style.display = "none";
                self.view.focus_iframe();
                if (ui_operations.read_aloud_state_changed) {
                    ui_operations.read_aloud_state_changed(false);
                }
            }
        };
        if (!ReadAloud.prototype.hide.__module__) Object.defineProperties(ReadAloud.prototype.hide, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.show = function show() {
            var self = this;
            if (self.state === HIDDEN) {
                self.container.style.display = "flex";
                self.state = STOPPED;
                self.focus();
                if (ui_operations.read_aloud_state_changed) {
                    ui_operations.read_aloud_state_changed(true);
                }
            }
        };
        if (!ReadAloud.prototype.show.__module__) Object.defineProperties(ReadAloud.prototype.show, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.focus = function focus() {
            var self = this;
            self.container.focus();
        };
        if (!ReadAloud.prototype.focus.__module__) Object.defineProperties(ReadAloud.prototype.focus, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.build_docked_bar = function build_docked_bar(bar_container, bar_position) {
            var self = this;
            var container;
            container = self.container;
            container.style.alignItems = (ρσ_in("bottom", bar_position)) ? "flex-end" : "flex-start";
            container.style.justifyContent = (ρσ_in("right", bar_position)) ? "flex-end" : (ρσ_in("left", bar_position)) ? "flex-start" : "center";
            self.create_buttons(bar_container);
        };
        if (!ReadAloud.prototype.build_docked_bar.__argnames__) Object.defineProperties(ReadAloud.prototype.build_docked_bar, {
            __argnames__ : {value: ["bar_container", "bar_position"]},
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.create_buttons = function create_buttons(bar) {
            var self = this;
            function cb(name, icon, text) {
                var ans;
                ans = svgicon(icon, ICON_SIZE, ICON_SIZE, text);
                if (name) {
                    ans.addEventListener("click", (function() {
                        var ρσ_anonfunc = function (ev) {
                            [ev.stopPropagation(), ev.preventDefault()];
                            self[(typeof name === "number" && name < 0) ? self.length + name : name](ev);
                            self.view.focus_iframe();
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["ev"]},
                            __module__ : {value: "read_book.read_aloud"}
                        });
                        return ρσ_anonfunc;
                    })());
                }
                ans.classList.add("simple-link");
                ans.style.marginLeft = ans.style.marginRight = BUTTON_MARGIN;
                return ans;
            };
            if (!cb.__argnames__) Object.defineProperties(cb, {
                __argnames__ : {value: ["name", "icon", "text"]},
                __module__ : {value: "read_book.read_aloud"}
            });

            if (self.state === PLAYING) {
                bar.appendChild(cb("pause", "pause", _("Pause reading")));
            } else if (self.state === WAITING_FOR_PLAY_TO_START) {
                bar.appendChild(cb(null, "hourglass", _("Pause reading")));
            } else {
                bar.appendChild(cb("play", "play", (self.state === STOPPED) ? _("Start reading") : _("Resume reading")));
            }
            bar.appendChild(cb("slower", "slower", _("Slow down speech")));
            bar.appendChild(cb("faster", "faster", _("Speed up speech")));
            bar.appendChild(cb("configure", "cogs", _("Configure Read aloud")));
            bar.appendChild(cb("hide", "off", _("Close Read aloud")));
        };
        if (!ReadAloud.prototype.create_buttons.__argnames__) Object.defineProperties(ReadAloud.prototype.create_buttons, {
            __argnames__ : {value: ["bar"]},
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.build_bar = function build_bar() {
            var self = this;
            var bar_container, ρσ_unpack, iclass, bp, container, x, notes_container;
            if (self.state === HIDDEN) {
                return;
            }
            bar_container = self.bar;
            bar_container.classList.remove("floating");
            bar_container.classList.remove("docked");
            ρσ_unpack = bar_class_and_position();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            iclass = ρσ_unpack[0];
            bp = ρσ_unpack[1];
            bar_container.classList.add(iclass);
            bar_container.style.maxWidth = "min(40rem, 80vw)";
            bar_container.style.backgroundColor = get_color("window-background");
            if (self.state === PLAYING) {
                bar_container.classList.add("speaking");
            } else {
                bar_container.classList.remove("speaking");
            }
            clear(bar_container);
            if (iclass !== "floating") {
                return self.build_docked_bar(bar_container, bp);
            }
            container = self.container;
            container.style.alignItems = (is_flow_mode()) ? "flex-end" : "flex-start";
            container.style.justifyContent = "flex-end";
            var ρσ_Iter0 = ρσ_Iterable(ρσ_list_decorate([ ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "height: 4ex; display: flex; align-items: center; padding: 5px; justify-content: center"})]), ρσ_interpolate_kwargs.call(E, E.hr, [ρσ_desugar_kwargs({style: "border-top: solid 1px; margin: 0; padding: 0; display: none"})]), ρσ_interpolate_kwargs.call(E, E.div, [E.div()].concat([ρσ_desugar_kwargs({style: "display: none; padding: 5px; font-size: smaller"})])) ]));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                x = ρσ_Iter0[ρσ_Index0];
                bar_container.appendChild(x);
            }
            self.create_buttons(bar_container.firstChild);
            if (self.state !== WAITING_FOR_PLAY_TO_START) {
                notes_container = bar_container.lastChild;
                notes_container.style.display = notes_container.previousSibling.style.display = "block";
                notes_container = notes_container.lastChild;
                if (self.state === STOPPED) {
                    notes_container.textContent = _("Tap/click on a word to start from there");
                } else if (self.state === PLAYING) {
                    notes_container.textContent = _("Tap/click on a word to skip to it");
                } else {
                    notes_container.textContent = _("Tap/click on a word to continue from there");
                }
            }
        };
        if (!ReadAloud.prototype.build_bar.__module__) Object.defineProperties(ReadAloud.prototype.build_bar, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.configure = function configure() {
            var self = this;
            self.pause();
            self.waiting_for_configure = true;
            ui_operations.tts("configure");
        };
        if (!ReadAloud.prototype.configure.__module__) Object.defineProperties(ReadAloud.prototype.configure, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.slower = function slower() {
            var self = this;
            ui_operations.tts("slower");
        };
        if (!ReadAloud.prototype.slower.__module__) Object.defineProperties(ReadAloud.prototype.slower, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.faster = function faster() {
            var self = this;
            ui_operations.tts("faster");
        };
        if (!ReadAloud.prototype.faster.__module__) Object.defineProperties(ReadAloud.prototype.faster, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.play = function play() {
            var self = this;
            if (self.state === PAUSED) {
                ui_operations.tts((self.waiting_for_configure) ? "resume_after_configure" : "resume");
                self.waiting_for_configure = false;
                self.state = PLAYING;
            } else if (self.state === STOPPED) {
                self.send_message("play");
                self.state = WAITING_FOR_PLAY_TO_START;
            }
        };
        if (!ReadAloud.prototype.play.__module__) Object.defineProperties(ReadAloud.prototype.play, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.pause = function pause() {
            var self = this;
            if (self.state === PLAYING) {
                ui_operations.tts("pause");
                self.state = PAUSED;
            }
        };
        if (!ReadAloud.prototype.pause.__module__) Object.defineProperties(ReadAloud.prototype.pause, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.stop = function stop() {
            var self = this;
            if (self.state === PLAYING || self.state === PAUSED) {
                ui_operations.tts("stop");
                self.state = STOPPED;
            }
        };
        if (!ReadAloud.prototype.stop.__module__) Object.defineProperties(ReadAloud.prototype.stop, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.toggle = function toggle() {
            var self = this;
            if (self.state === PLAYING) {
                self.pause();
            } else if (self.state === PAUSED || self.state === STOPPED) {
                self.play();
            }
        };
        if (!ReadAloud.prototype.toggle.__module__) Object.defineProperties(ReadAloud.prototype.toggle, {
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.container_clicked = function container_clicked(ev) {
            var self = this;
            var margins, pos;
            if (ev.button !== 0) {
                return;
            }
            [ev.stopPropagation(), ev.preventDefault()];
            margins = get_margins();
            pos = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["x"] = ev.clientX;
                ρσ_d["y"] = ev.clientY;
                return ρσ_d;
            }).call(this);
            pos = map_to_iframe_coords(pos, margins);
            ρσ_interpolate_kwargs.call(self, self.send_message, ["play"].concat([ρσ_desugar_kwargs({pos: pos})]));
        };
        if (!ReadAloud.prototype.container_clicked.__argnames__) Object.defineProperties(ReadAloud.prototype.container_clicked, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.on_keydown = function on_keydown(ev) {
            var self = this;
            var sc_name;
            [ev.stopPropagation(), ev.preventDefault()];
            if (ev.key === "Escape") {
                self.hide();
                return;
            }
            if (ev.key === " " || ev.key === "MediaPlayPause" || ev.key === "PlayPause") {
                self.toggle();
                return;
            }
            if (ev.key === "Play" || ev.key === "MediaPlay") {
                self.play();
                return;
            }
            if (ev.key === "Pause" || ev.key === "MediaPause") {
                self.pause();
                return;
            }
            if (ev.key === "MediaStop") {
                self.stop();
                return;
            }
            sc_name = shortcut_for_key_event(ev, self.view.keyboard_shortcut_map);
            if (!sc_name) {
                return;
            }
            if (sc_name === "show_chrome") {
                self.hide();
            } else if (sc_name === "quit") {
                self.hide();
                ui_operations.quit();
            }
        };
        if (!ReadAloud.prototype.on_keydown.__argnames__) Object.defineProperties(ReadAloud.prototype.on_keydown, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.handle_tts_event = function handle_tts_event(which, data) {
            var self = this;
            if (which === "mark") {
                ρσ_interpolate_kwargs.call(self, self.send_message, ["mark"].concat([ρσ_desugar_kwargs({num: data})]));
            } else if (which === "begin") {
                self.state = PLAYING;
            } else if (which === "pause") {
                self.state = PAUSED;
            } else if (which === "resume") {
                self.state = PLAYING;
            } else if (which === "end") {
                self.state = STOPPED;
                self.view.show_next_spine_item();
            } else if (which === "configured") {
                self.focus();
                if (self.waiting_for_configure) {
                    self.play();
                }
                if (data !== null) {
                }
            }
        };
        if (!ReadAloud.prototype.handle_tts_event.__argnames__) Object.defineProperties(ReadAloud.prototype.handle_tts_event, {
            __argnames__ : {value: ["which", "data"]},
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.send_message = function send_message() {
            var self = this;
            var type = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            ρσ_interpolate_kwargs.call(self.view.iframe_wrapper, self.view.iframe_wrapper.send_message, ["tts"].concat([ρσ_desugar_kwargs(kw, {type: type})]));
        };
        if (!ReadAloud.prototype.send_message.__handles_kwarg_interpolation__) Object.defineProperties(ReadAloud.prototype.send_message, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["type"]},
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.handle_message = function handle_message(msg) {
            var self = this;
            if (msg.type === "text-extracted") {
                if (msg.pos) {
                    self.stop();
                }
                ui_operations.tts("play", (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["marked_text"] = msg.marked_text;
                    return ρσ_d;
                }).call(this));
            }
        };
        if (!ReadAloud.prototype.handle_message.__argnames__) Object.defineProperties(ReadAloud.prototype.handle_message, {
            __argnames__ : {value: ["msg"]},
            __module__ : {value: "read_book.read_aloud"}
        });
        ReadAloud.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ReadAloud.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ReadAloud.prototype, "__bases__", {value: []});
        ReadAloud.prototype.dont_hide_on_content_loaded = true;
        ReadAloud.prototype.prevent_navigation = true;
        
        
        
        
        

        ρσ_modules["read_book.read_aloud"].HIDDEN = HIDDEN;
        ρσ_modules["read_book.read_aloud"].WAITING_FOR_PLAY_TO_START = WAITING_FOR_PLAY_TO_START;
        ρσ_modules["read_book.read_aloud"].PAUSED = PAUSED;
        ρσ_modules["read_book.read_aloud"].PLAYING = PLAYING;
        ρσ_modules["read_book.read_aloud"].STOPPED = STOPPED;
        ρσ_modules["read_book.read_aloud"].is_flow_mode = is_flow_mode;
        ρσ_modules["read_book.read_aloud"].bar_class_and_position = bar_class_and_position;
        ρσ_modules["read_book.read_aloud"].ReadAloud = ReadAloud;
    })();

    (function(){
        var __name__ = "read_book.read_audio_ebook";
        var ρσ_unpack, HIDDEN, PLAYING, PAUSED;
        var E = ρσ_modules.elementmaker.E;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var change_icon_image = ρσ_modules.dom.change_icon_image;
        var svgicon = ρσ_modules.dom.svgicon;

        var _ = ρσ_modules.gettext.gettext;

        var error_dialog = ρσ_modules.modals.error_dialog;

        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var ICON_SIZE = ρσ_modules["read_book.highlights"].ICON_SIZE;

        var BUTTON_MARGIN = ρσ_modules["read_book.selection_bar"].BUTTON_MARGIN;
        var get_margins = ρσ_modules["read_book.selection_bar"].get_margins;
        var map_to_iframe_coords = ρσ_modules["read_book.selection_bar"].map_to_iframe_coords;

        var shortcut_for_key_event = ρσ_modules["read_book.shortcuts"].shortcut_for_key_event;

        var find_next_audio_in_spine = ρσ_modules["read_book.smil"].find_next_audio_in_spine;
        var get_smil_id_for_timestamp = ρσ_modules["read_book.smil"].get_smil_id_for_timestamp;
        var next_audio_file_for_spine_item = ρσ_modules["read_book.smil"].next_audio_file_for_spine_item;

        ρσ_unpack = ["HIDDEN", "PLAYING", "PAUSED"];
        HIDDEN = ρσ_unpack[0];
        PLAYING = ρσ_unpack[1];
        PAUSED = ρσ_unpack[2];
        function seconds_to_ms(seconds) {
            var minutes, remaining_seconds;
            minutes = Math.floor(seconds / 60);
            remaining_seconds = int(seconds % 60);
            return str(minutes) + ":" + str(remaining_seconds).zfill(2);
        };
        if (!seconds_to_ms.__argnames__) Object.defineProperties(seconds_to_ms, {
            __argnames__ : {value: ["seconds"]},
            __module__ : {value: "read_book.read_audio_ebook"}
        });

        function ReadAudioEbook() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ReadAudioEbook.prototype.__bind_methods__.call(this);
            ReadAudioEbook.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ReadAudioEbook.prototype, "__bind_methods__", {value: function () {
            this.initialize = ReadAudioEbook.prototype.initialize.bind(this);
            this.mark_for_timeupdate = ReadAudioEbook.prototype.mark_for_timeupdate.bind(this);
            this.play_next_audio_file = ReadAudioEbook.prototype.play_next_audio_file.bind(this);
            this.set_audio_src = ReadAudioEbook.prototype.set_audio_src.bind(this);
            this.start_playback = ReadAudioEbook.prototype.start_playback.bind(this);
            this.hide = ReadAudioEbook.prototype.hide.bind(this);
            this.show = ReadAudioEbook.prototype.show.bind(this);
            this.focus = ReadAudioEbook.prototype.focus.bind(this);
            this.slower = ReadAudioEbook.prototype.slower.bind(this);
            this.faster = ReadAudioEbook.prototype.faster.bind(this);
            this.play = ReadAudioEbook.prototype.play.bind(this);
            this.pause = ReadAudioEbook.prototype.pause.bind(this);
            this.toggle = ReadAudioEbook.prototype.toggle.bind(this);
            this.on_bar_clicked = ReadAudioEbook.prototype.on_bar_clicked.bind(this);
            this.on_container_clicked = ReadAudioEbook.prototype.on_container_clicked.bind(this);
            this.on_keydown = ReadAudioEbook.prototype.on_keydown.bind(this);
            this.send_message = ReadAudioEbook.prototype.send_message.bind(this);
            this.handle_message = ReadAudioEbook.prototype.handle_message.bind(this);
        }});
        Object.defineProperties(ReadAudioEbook.prototype,  {
            "bar": {
                "enumerable": true, 
                "get": function bar() {
                    var self = this;
                    return self.container.querySelector("[data-component=bar]");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "time_display": {
                "enumerable": true, 
                "get": function time_display() {
                    var self = this;
                    return self.container.querySelector("[data-component=time_display]");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "progress_bar": {
                "enumerable": true, 
                "get": function progress_bar() {
                    var self = this;
                    return self.container.querySelector("[data-component=progress_bar]");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById("audio-ebooks-overlay");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "audio_player": {
                "enumerable": true, 
                "get": function audio_player() {
                    var self = this;
                    return self.container.querySelector("[data-component=audio]");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "is_visible": {
                "enumerable": true, 
                "get": function is_visible() {
                    var self = this;
                    return self.container.style.display !== "none";
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "state": {
                "enumerable": true, 
                "get": function state() {
                    var self = this;
                    return self._state;
                }, 
                "set": function state(val) {
                    var self = this;
                    var speaking;
                    if (val !== self._state) {
                        speaking = false;
                        if (val === HIDDEN) {
                            self._state = HIDDEN;
                        } else if (val === PLAYING) {
                            self._state = PLAYING;
                            speaking = true;
                        } else if (val === PAUSED) {
                            self._state = PAUSED;
                        }
                        if (speaking) {
                            self.bar.classList.add("speaking");
                        } else {
                            self.bar.classList.remove("speaking");
                        }
                    }
                }
            }, 
            "play_pause_button": {
                "enumerable": true, 
                "get": function play_pause_button() {
                    var self = this;
                    return self.container.querySelector("[data-button=\"toggle\"]");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        ReadAudioEbook.prototype.__init__ = function __init__(view) {
            var self = this;
            self.view = view;
            self._state = HIDDEN;
            self.initialized = false;
            self.current_audio_src = "";
        };
        if (!ReadAudioEbook.prototype.__init__.__argnames__) Object.defineProperties(ReadAudioEbook.prototype.__init__, {
            __argnames__ : {value: ["view"]},
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.__argnames__ = ReadAudioEbook.prototype.__init__.__argnames__;
        ReadAudioEbook.__handles_kwarg_interpolation__ = ReadAudioEbook.prototype.__init__.__handles_kwarg_interpolation__;
        ReadAudioEbook.prototype.initialize = function initialize() {
            var self = this;
            var container, bar_container, x, ap;
            if (self.initialized) {
                return;
            }
            self.initialized = true;
            container = self.container;
            container.style.backgroundColor = "rgba(0, 0, 0, 0)";
            container.style.justifyContent = "center";
            container.style.alignItems = "flex-end";
            container.setAttribute("tabindex", "0");
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({data_component: "bar", style: "position: absolute; bottom: 0; width: min(600px, 80vw); height: 2em; border-radius: 1em; padding:0.5em; display: flex; justify-content: center; align-items: center; background-color: " + ρσ_str.format("{}", get_color("window-background")) + ";"})]));
            bar_container = container.lastChild;
            container.appendChild(E.style("#" + ρσ_str.format("{}", container.id) + " .speaking " + "{ opacity: 0.5 }\n\n", "#" + ρσ_str.format("{}", container.id) + " .speaking:hover " + "{ opacity: 1.0 }\n\n"));
            container.addEventListener("keydown", self.on_keydown, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("click", self.on_container_clicked, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            container.addEventListener("contextmenu", self.toggle, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            function create_button(name, icon, text) {
                var ans;
                ans = svgicon(icon, ICON_SIZE, ICON_SIZE, text);
                if (name) {
                    ans.addEventListener("click", (function() {
                        var ρσ_anonfunc = function (ev) {
                            [ev.stopPropagation(), ev.preventDefault()];
                            self[(typeof name === "number" && name < 0) ? self.length + name : name](ev);
                            self.view.focus_iframe();
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["ev"]},
                            __module__ : {value: "read_book.read_audio_ebook"}
                        });
                        return ρσ_anonfunc;
                    })());
                }
                ans.dataset.button = name;
                ans.classList.add("simple-link");
                ans.style.marginLeft = ans.style.marginRight = BUTTON_MARGIN;
                return ans;
            };
            if (!create_button.__argnames__) Object.defineProperties(create_button, {
                __argnames__ : {value: ["name", "icon", "text"]},
                __module__ : {value: "read_book.read_audio_ebook"}
            });

            var ρσ_Iter0 = ρσ_Iterable(ρσ_list_decorate([ ρσ_interpolate_kwargs.call(E, E.div, [create_button("toggle", "pause", _("Pause audio"))].concat([ρσ_desugar_kwargs({style: "height: 3ex; display: flex; align-items: center; justify-content: center"})])), ρσ_interpolate_kwargs.call(E, E.div, [E.text("")].concat([ρσ_desugar_kwargs({data_component: "time_display"})])), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "display:block; width: 0%; background-color:" + ρσ_str.format("{}", get_color("window-foreground")) + "; height:100%"})])].concat([ρσ_desugar_kwargs({data_component: "progress_bar", style: "height:1.5em; border-radius: 0.75em; overflow: hidden; flex-grow: 100; display:block; background-color:" + ρσ_str.format("{}", get_color("window-background2")) + "; margin:1em; cursor: pointer"})])), ρσ_interpolate_kwargs.call(E, E.div, [create_button("slower", "slower", _("Slow down audio")), create_button("faster", "faster", _("Speed up audio")), create_button("hide", "off", _("Close Read aloud"))].concat([ρσ_desugar_kwargs({style: "height: 3ex; display: flex; align-items: center; justify-content: center"})])) ]));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                x = ρσ_Iter0[ρσ_Index0];
                bar_container.appendChild(x);
            }
            bar_container.addEventListener("click", self.on_bar_clicked, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["passive"] = false;
                return ρσ_d;
            }).call(this));
            self.container.appendChild(ρσ_interpolate_kwargs.call(E, E.audio, [ρσ_desugar_kwargs({data_component: "audio", style: "display:none"})]));
            ap = self.container.lastChild;
            ap.addEventListener("timeupdate", (function() {
                var ρσ_anonfunc = function () {
                    var ap, audio_current_time, progress;
                    if (self.state !== HIDDEN) {
                        ap = self.audio_player;
                        if (ap.duration) {
                            audio_current_time = ap.currentTime;
                            progress = audio_current_time / ap.duration * 100;
                            self.progress_bar.firstChild.style.width = progress + "%";
                            self.time_display.textContent = "" + ρσ_str.format("{}", seconds_to_ms(audio_current_time)) + "/" + ρσ_str.format("{}", seconds_to_ms(ap.duration)) + "";
                            self.mark_for_timeupdate(audio_current_time);
                        } else {
                            self.time_display.textContent = "00:00";
                            self.progress_bar.firstChild.style.width = "0%";
                        }
                    }
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.read_audio_ebook"}
                });
                return ρσ_anonfunc;
            })());
            ap.addEventListener("ended", (function() {
                var ρσ_anonfunc = function () {
                    self.play_next_audio_file();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.read_audio_ebook"}
                });
                return ρσ_anonfunc;
            })());
            self.progress_bar.addEventListener("click", (function() {
                var ρσ_anonfunc = function (event) {
                    var ap, rect, x, total_width, skip_time;
                    ap = self.audio_player;
                    if (ap.duration) {
                        rect = self.progress_bar.getBoundingClientRect();
                        x = event.clientX - rect.left;
                        total_width = rect.width;
                        if (total_width) {
                            skip_time = x / total_width * ap.duration;
                            ap.currentTime = skip_time;
                        }
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.read_audio_ebook"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!ReadAudioEbook.prototype.initialize.__module__) Object.defineProperties(ReadAudioEbook.prototype.initialize, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.mark_for_timeupdate = function mark_for_timeupdate(audio_time) {
            var self = this;
            var sam, ρσ_unpack, smil_id, idx;
            sam = self.view.currently_showing.smil_audio_map;
            if (sam) {
                ρσ_unpack = get_smil_id_for_timestamp(self.current_audio_src, audio_time, sam, self.last_marked_smil_idx);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                smil_id = ρσ_unpack[0];
                idx = ρσ_unpack[1];
                if (smil_id && smil_id !== self.last_marked_smil_id) {
                    ρσ_interpolate_kwargs.call(self, self.send_message, ["mark"].concat([ρσ_desugar_kwargs({anchor: smil_id, idx: idx})]));
                }
            }
        };
        if (!ReadAudioEbook.prototype.mark_for_timeupdate.__argnames__) Object.defineProperties(ReadAudioEbook.prototype.mark_for_timeupdate, {
            __argnames__ : {value: ["audio_time"]},
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.play_next_audio_file = function play_next_audio_file() {
            var self = this;
            var ρσ_unpack, next_audio_file, par, spine_name;
            ρσ_unpack = next_audio_file_for_spine_item(self.current_audio_src, self.view.currently_showing.smil_audio_map);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            next_audio_file = ρσ_unpack[0];
            par = ρσ_unpack[1];
            if (next_audio_file) {
                self.set_audio_src(next_audio_file, (function() {
                    var ρσ_anonfunc = function () {
                        self.audio_player.currentTime = ρσ_exists.d(par.audio).start || 0;
                        self.play();
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.read_audio_ebook"}
                    });
                    return ρσ_anonfunc;
                })());
                return;
            }
            ρσ_unpack = find_next_audio_in_spine(self.view.currently_showing.spine_index, self.view.book.manifest);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            spine_name = ρσ_unpack[0];
            par = ρσ_unpack[1];
            if (spine_name) {
                ρσ_interpolate_kwargs.call(self.view, self.view.show_name, [spine_name].concat([ρσ_desugar_kwargs({initial_position: (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "smil_id";
                    ρσ_d["anchor"] = par.anchor;
                    return ρσ_d;
                }).call(this)})]));
            } else {
                self.hide();
            }
        };
        if (!ReadAudioEbook.prototype.play_next_audio_file.__module__) Object.defineProperties(ReadAudioEbook.prototype.play_next_audio_file, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.set_audio_src = function set_audio_src(name, proceed) {
            var self = this;
            var ap;
            if (self.current_audio_src === name) {
                proceed();
                return;
            }
            self.last_marked_smil_id = self.last_marked_smil_idx = null;
            self.current_audio_src = name;
            ap = self.audio_player;
            if (ui_operations.get_url_for_book_file_name) {
                ap.onloadeddata = (function() {
                    var ρσ_anonfunc = function () {
                        proceed();
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.read_audio_ebook"}
                    });
                    return ρσ_anonfunc;
                })();
                ap.onerror = (function() {
                    var ρσ_anonfunc = function (evt) {
                        console.error(evt);
                        error_dialog(_("Could not load audio"), _("Could not load the audio file: {} with error: {}").format(name, evt.message));
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["evt"]},
                        __module__ : {value: "read_book.read_audio_ebook"}
                    });
                    return ρσ_anonfunc;
                })();
                ap.src = ui_operations.get_url_for_book_file_name(name);
                return;
            }
            if (ap.src) {
                ap.onloadeddata = (function() {
                    var ρσ_anonfunc = function () {
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.read_audio_ebook"}
                    });
                    return ρσ_anonfunc;
                })();
                ap.onerror = (function() {
                    var ρσ_anonfunc = function () {
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.read_audio_ebook"}
                    });
                    return ρσ_anonfunc;
                })();
                window.URL.revokeObjectURL(ap.src);
                ap.src = "";
            }
            ui_operations.get_file(self.view.book, name, (function() {
                var ρσ_anonfunc = function (blob, name, mimetype) {
                    var ap;
                    ap = self.audio_player;
                    ap.onloadeddata = (function() {
                        var ρσ_anonfunc = function () {
                            proceed();
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.read_audio_ebook"}
                        });
                        return ρσ_anonfunc;
                    })();
                    ap.onerror = (function() {
                        var ρσ_anonfunc = function (evt) {
                            console.error(evt);
                            error_dialog(_("Could not load audio"), _("Could not load the audio file: {} with error: {}").format(name, evt.message));
                        };
                        if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                            __argnames__ : {value: ["evt"]},
                            __module__ : {value: "read_book.read_audio_ebook"}
                        });
                        return ρσ_anonfunc;
                    })();
                    ap.src = window.URL.createObjectURL(blob);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["blob", "name", "mimetype"]},
                    __module__ : {value: "read_book.read_audio_ebook"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!ReadAudioEbook.prototype.set_audio_src.__argnames__) Object.defineProperties(ReadAudioEbook.prototype.set_audio_src, {
            __argnames__ : {value: ["name", "proceed"]},
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.start_playback = function start_playback() {
            var self = this;
            var cn, ρσ_unpack, spine_name, par;
            cn = self.view.currently_showing.name;
            if (ρσ_exists.d((ρσ_expr_temp = self.view.book.manifest.files)[(typeof cn === "number" && cn < 0) ? ρσ_expr_temp.length + cn : cn]).smil_map) {
                self.send_message("play");
                return;
            }
            ρσ_unpack = find_next_audio_in_spine(self.view.currently_showing.spine_index, self.view.book.manifest);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            spine_name = ρσ_unpack[0];
            par = ρσ_unpack[1];
            if (!spine_name) {
                ρσ_unpack = find_next_audio_in_spine(-1, self.view.book.manifest);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                spine_name = ρσ_unpack[0];
                par = ρσ_unpack[1];
            }
            if (spine_name) {
                ρσ_interpolate_kwargs.call(self.view, self.view.show_name, [spine_name].concat([ρσ_desugar_kwargs({initial_position: (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "smil_id";
                    ρσ_d["anchor"] = par.anchor;
                    return ρσ_d;
                }).call(this)})]));
            } else {
                self.hide();
                error_dialog(_("No audio"), _("No audio found in this book"));
            }
        };
        if (!ReadAudioEbook.prototype.start_playback.__module__) Object.defineProperties(ReadAudioEbook.prototype.start_playback, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.hide = function hide() {
            var self = this;
            if (self.state !== HIDDEN) {
                self.send_message("mark");
                self.pause();
                self.container.style.display = "none";
                self.view.focus_iframe();
                self.state = HIDDEN;
                if (ui_operations.read_aloud_state_changed) {
                    ui_operations.read_aloud_state_changed(false);
                }
            }
        };
        if (!ReadAudioEbook.prototype.hide.__module__) Object.defineProperties(ReadAudioEbook.prototype.hide, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.show = function show() {
            var self = this;
            if (self.state === HIDDEN) {
                self.initialize();
                self.state = PLAYING;
                change_icon_image(self.play_pause_button, "pause", _("Pause audio"));
                self.start_playback();
                self.container.style.display = self.CONTAINER_DISPLAY;
                self.focus();
                if (ui_operations.read_aloud_state_changed) {
                    ui_operations.read_aloud_state_changed(true);
                }
            }
        };
        if (!ReadAudioEbook.prototype.show.__module__) Object.defineProperties(ReadAudioEbook.prototype.show, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.focus = function focus() {
            var self = this;
            self.container.focus();
        };
        if (!ReadAudioEbook.prototype.focus.__module__) Object.defineProperties(ReadAudioEbook.prototype.focus, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.slower = function slower() {
            var self = this;
            self.audio_player.playbackRate -= .1;
        };
        if (!ReadAudioEbook.prototype.slower.__module__) Object.defineProperties(ReadAudioEbook.prototype.slower, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.faster = function faster() {
            var self = this;
            self.audio_player.playbackRate += .1;
        };
        if (!ReadAudioEbook.prototype.faster.__module__) Object.defineProperties(ReadAudioEbook.prototype.faster, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.play = function play() {
            var self = this;
            var ap;
            self.state = PLAYING;
            change_icon_image(self.play_pause_button, "pause", _("Pause audio"));
            ap = self.audio_player;
            if (ap.getAttribute("src")) {
                ap.play();
            }
        };
        if (!ReadAudioEbook.prototype.play.__module__) Object.defineProperties(ReadAudioEbook.prototype.play, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.pause = function pause() {
            var self = this;
            var ap;
            self.state = PAUSED;
            change_icon_image(self.play_pause_button, "play", _("Play audio"));
            ap = self.audio_player;
            if (ap.getAttribute("src")) {
                ap.pause();
            }
        };
        if (!ReadAudioEbook.prototype.pause.__module__) Object.defineProperties(ReadAudioEbook.prototype.pause, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.toggle = function toggle() {
            var self = this;
            if (self.state === PLAYING) {
                self.pause();
            } else if (self.state === PAUSED) {
                self.play();
            }
        };
        if (!ReadAudioEbook.prototype.toggle.__module__) Object.defineProperties(ReadAudioEbook.prototype.toggle, {
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.on_bar_clicked = function on_bar_clicked(ev) {
            var self = this;
            [ev.stopPropagation(), ev.preventDefault()];
        };
        if (!ReadAudioEbook.prototype.on_bar_clicked.__argnames__) Object.defineProperties(ReadAudioEbook.prototype.on_bar_clicked, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.on_container_clicked = function on_container_clicked(ev) {
            var self = this;
            var margins, pos;
            if (ev.button !== 0) {
                return;
            }
            [ev.stopPropagation(), ev.preventDefault()];
            margins = get_margins();
            pos = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["x"] = ev.clientX;
                ρσ_d["y"] = ev.clientY;
                return ρσ_d;
            }).call(this);
            pos = map_to_iframe_coords(pos, margins);
            ρσ_interpolate_kwargs.call(self, self.send_message, ["play"].concat([ρσ_desugar_kwargs({pos: pos})]));
        };
        if (!ReadAudioEbook.prototype.on_container_clicked.__argnames__) Object.defineProperties(ReadAudioEbook.prototype.on_container_clicked, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.on_keydown = function on_keydown(ev) {
            var self = this;
            var sc_name;
            [ev.stopPropagation(), ev.preventDefault()];
            if (ev.key === "Escape") {
                self.hide();
                return;
            }
            if (ev.key === " " || ev.key === "MediaPlayPause" || ev.key === "PlayPause") {
                self.toggle();
                return;
            }
            if (ev.key === "Play" || ev.key === "MediaPlay") {
                self.play();
                return;
            }
            if (ev.key === "Pause" || ev.key === "MediaPause") {
                self.pause();
                return;
            }
            sc_name = shortcut_for_key_event(ev, self.view.keyboard_shortcut_map);
            if (!sc_name) {
                return;
            }
            if (sc_name === "show_chrome") {
                self.hide();
            } else if (sc_name === "quit") {
                self.hide();
            }
        };
        if (!ReadAudioEbook.prototype.on_keydown.__argnames__) Object.defineProperties(ReadAudioEbook.prototype.on_keydown, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.send_message = function send_message() {
            var self = this;
            var message_type = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var kw = arguments[arguments.length-1];
            if (kw === null || typeof kw !== "object" || kw [ρσ_kwargs_symbol] !== true) kw = {};
            ρσ_interpolate_kwargs.call(self.view.iframe_wrapper, self.view.iframe_wrapper.send_message, ["audio-ebook"].concat([ρσ_desugar_kwargs(kw, {type: message_type})]));
        };
        if (!ReadAudioEbook.prototype.send_message.__handles_kwarg_interpolation__) Object.defineProperties(ReadAudioEbook.prototype.send_message, {
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["message_type"]},
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.handle_message = function handle_message(message) {
            var self = this;
            if (message.type === "start_play_at") {
                if (message.par) {
                    self.set_audio_src(message.par.audio, (function() {
                        var ρσ_anonfunc = function () {
                            self.audio_player.currentTime = message.par.start || 0;
                            self.play();
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.read_audio_ebook"}
                        });
                        return ρσ_anonfunc;
                    })());
                } else {
                    if (message.anchor) {
                        self.send_message("play");
                        return;
                    }
                    if (message.pos) {
                    } else {
                        self.pause();
                        error_dialog(_("Audio element not found"), _("Could not play audio as no associated audio was found"));
                    }
                }
            } else if (message.type === "marked") {
                if (message.anchor) {
                    self.last_marked_smil_id = message.anchor;
                    self.last_marked_smil_idx = message.idx;
                } else {
                    self.last_marked_smil_id = self.last_marked_smil_idx = null;
                }
            } else {
                console.error("Unknown audio ebook message type from iframe: " + ρσ_str.format("{}", message.type) + "");
            }
        };
        if (!ReadAudioEbook.prototype.handle_message.__argnames__) Object.defineProperties(ReadAudioEbook.prototype.handle_message, {
            __argnames__ : {value: ["message"]},
            __module__ : {value: "read_book.read_audio_ebook"}
        });
        ReadAudioEbook.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ReadAudioEbook.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ReadAudioEbook.prototype, "__bases__", {value: []});
        ReadAudioEbook.prototype.dont_hide_on_content_loaded = true;
        ReadAudioEbook.prototype.prevent_navigation = true;
        ReadAudioEbook.prototype.CONTAINER_DISPLAY = "flex";
        
        
        
        
        
        
        
        
        

        ρσ_modules["read_book.read_audio_ebook"].ρσ_unpack = ρσ_unpack;
        ρσ_modules["read_book.read_audio_ebook"].HIDDEN = HIDDEN;
        ρσ_modules["read_book.read_audio_ebook"].PLAYING = PLAYING;
        ρσ_modules["read_book.read_audio_ebook"].PAUSED = PAUSED;
        ρσ_modules["read_book.read_audio_ebook"].seconds_to_ms = seconds_to_ms;
        ρσ_modules["read_book.read_audio_ebook"].ReadAudioEbook = ReadAudioEbook;
    })();

    (function(){
        var __name__ = "read_book.scrollbar";
        var SIZE;
        var E = ρσ_modules.elementmaker.E;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var cached_color_to_rgba = ρσ_modules["book_list.theme"].cached_color_to_rgba;

        var unique_id = ρσ_modules.dom.unique_id;

        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        SIZE = 10;
        function BookScrollbar() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            BookScrollbar.prototype.__bind_methods__.call(this);
            BookScrollbar.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(BookScrollbar.prototype, "__bind_methods__", {value: function () {
            this.create = BookScrollbar.prototype.create.bind(this);
            this.context_menu = BookScrollbar.prototype.context_menu.bind(this);
            this.bar_clicked = BookScrollbar.prototype.bar_clicked.bind(this);
            this.on_bob_mouse_event = BookScrollbar.prototype.on_bob_mouse_event.bind(this);
            this.apply_visibility = BookScrollbar.prototype.apply_visibility.bind(this);
            this.set_position = BookScrollbar.prototype.set_position.bind(this);
            this._sync_to_contents = BookScrollbar.prototype._sync_to_contents.bind(this);
            this.sync_to_contents = BookScrollbar.prototype.sync_to_contents.bind(this);
            this.apply_color_scheme = BookScrollbar.prototype.apply_color_scheme.bind(this);
        }});
        Object.defineProperties(BookScrollbar.prototype,  {
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById(self.container_id);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "effective_width": {
                "enumerable": true, 
                "get": function effective_width() {
                    var self = this;
                    return (self.container.style.display === "block") ? SIZE : 0;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        BookScrollbar.prototype.__init__ = function __init__(view) {
            var self = this;
            self.view = view;
            self.container_id = unique_id("book-scrollbar");
            self.sync_to_contents_timer = 0;
            self.sync_contents_timer = 0;
        };
        if (!BookScrollbar.prototype.__init__.__argnames__) Object.defineProperties(BookScrollbar.prototype.__init__, {
            __argnames__ : {value: ["view"]},
            __module__ : {value: "read_book.scrollbar"}
        });
        BookScrollbar.__argnames__ = BookScrollbar.prototype.__init__.__argnames__;
        BookScrollbar.__handles_kwarg_interpolation__ = BookScrollbar.prototype.__init__.__handles_kwarg_interpolation__;
        BookScrollbar.prototype.create = function create() {
            var self = this;
            self.on_bob_mousedown = self.on_bob_mouse_event.bind(null, "down");
            self.on_bob_mousemove = self.on_bob_mouse_event.bind(null, "move");
            self.on_bob_mouseup = self.on_bob_mouse_event.bind(null, "up");
            return ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "position: relative; width: 100%; height: " + ρσ_str.format("{}", int(2.2 * SIZE)) + "px; background-color: #444; border-radius: 5px", onmousedown: self.on_bob_mousedown})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "position: absolute; z-index: 2147483647; width: 100vw; height: 100vh; left: 0; top: 0; display: none;"})])].concat([ρσ_desugar_kwargs({id: self.container_id, style: "height: 100vh; background-color: #aaa; width: " + ρσ_str.format("{}", SIZE) + "px; border-radius: 5px", onclick: self.bar_clicked, oncontextmenu: self.context_menu})]));
        };
        if (!BookScrollbar.prototype.create.__module__) Object.defineProperties(BookScrollbar.prototype.create, {
            __module__ : {value: "read_book.scrollbar"}
        });
        BookScrollbar.prototype.context_menu = function context_menu(ev) {
            var self = this;
            var c, bob, height, top, frac;
            if (ui_operations.scrollbar_context_menu) {
                [ev.preventDefault(), ev.stopPropagation()];
                c = self.container;
                bob = c.firstChild;
                height = c.clientHeight - bob.clientHeight;
                top = max(0, min(ev.clientY - bob.clientHeight, height));
                frac = max(0, min(top / height, 1));
                ui_operations.scrollbar_context_menu(ev.screenX, ev.screenY, frac);
            }
        };
        if (!BookScrollbar.prototype.context_menu.__argnames__) Object.defineProperties(BookScrollbar.prototype.context_menu, {
            __argnames__ : {value: ["ev"]},
            __module__ : {value: "read_book.scrollbar"}
        });
        BookScrollbar.prototype.bar_clicked = function bar_clicked(evt) {
            var self = this;
            var c, b, bob_top, bob_bottom;
            if (evt.button === 0) {
                c = self.container;
                b = c.firstChild;
                bob_top = b.offsetTop;
                bob_bottom = bob_top + b.offsetHeight;
                if (evt.clientY < bob_top) {
                    self.view.side_margin_clicked("left", evt);
                } else if (evt.clientY > bob_bottom) {
                    self.view.side_margin_clicked("right", evt);
                }
            }
        };
        if (!BookScrollbar.prototype.bar_clicked.__argnames__) Object.defineProperties(BookScrollbar.prototype.bar_clicked, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.scrollbar"}
        });
        BookScrollbar.prototype.on_bob_mouse_event = function on_bob_mouse_event(which, evt) {
            var self = this;
            var c, bob, mouse_grab, top, height, frac;
            c = self.container;
            bob = c.firstChild;
            mouse_grab = bob.nextSibling;
            if (which === "move") {
                top = evt.pageY - self.down_y;
                height = c.clientHeight - bob.clientHeight;
                top = max(0, min(top, height));
                bob.style.top = "" + ρσ_str.format("{}", top) + "px";
                [evt.preventDefault(), evt.stopPropagation()];
                frac = bob.offsetTop / height;
                if (self.sync_contents_timer) {
                    window.clearTimeout(self.sync_contents_timer);
                }
                self.sync_contents_timer = window.setTimeout(self.view.goto_frac.bind(null, frac), 2);
            } else if (which === "down") {
                if (evt.button !== 0) {
                    return;
                }
                [evt.preventDefault(), evt.stopPropagation()];
                self.down_y = evt.clientY - bob.getBoundingClientRect().top;
                mouse_grab.style.display = "block";
                window.addEventListener("mousemove", self.on_bob_mousemove, (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["capture"] = true;
                    ρσ_d["passive"] = false;
                    return ρσ_d;
                }).call(this));
                window.addEventListener("mouseup", self.on_bob_mouseup, (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["capture"] = true;
                    ρσ_d["passive"] = false;
                    return ρσ_d;
                }).call(this));
            } else if (which === "up") {
                self.down_y = 0;
                window.removeEventListener("mousemove", self.on_bob_mousemove, (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["capture"] = true;
                    ρσ_d["passive"] = false;
                    return ρσ_d;
                }).call(this));
                window.removeEventListener("mouseup", self.on_bob_mouseup, (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["capture"] = true;
                    ρσ_d["passive"] = false;
                    return ρσ_d;
                }).call(this));
                window.setTimeout((function() {
                    var ρσ_anonfunc = function () {
                        self.container.firstChild.nextSibling.style.display = "none";
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.scrollbar"}
                    });
                    return ρσ_anonfunc;
                })(), 10);
                [evt.preventDefault(), evt.stopPropagation()];
            }
        };
        if (!BookScrollbar.prototype.on_bob_mouse_event.__argnames__) Object.defineProperties(BookScrollbar.prototype.on_bob_mouse_event, {
            __argnames__ : {value: ["which", "evt"]},
            __module__ : {value: "read_book.scrollbar"}
        });
        BookScrollbar.prototype.apply_visibility = function apply_visibility() {
            var self = this;
            var sd;
            sd = get_session_data();
            self.container.style.display = (sd.get("book_scrollbar")) ? "block" : "none";
        };
        if (!BookScrollbar.prototype.apply_visibility.__module__) Object.defineProperties(BookScrollbar.prototype.apply_visibility, {
            __module__ : {value: "read_book.scrollbar"}
        });
        BookScrollbar.prototype.set_position = function set_position(frac) {
            var self = this;
            var c;
            c = self.container;
            frac = max(0, min(frac, 1));
            c.firstChild.style.top = "" + ρσ_str.format("{}", frac * (c.clientHeight - c.firstChild.clientHeight)) + "px";
        };
        if (!BookScrollbar.prototype.set_position.__argnames__) Object.defineProperties(BookScrollbar.prototype.set_position, {
            __argnames__ : {value: ["frac"]},
            __module__ : {value: "read_book.scrollbar"}
        });
        BookScrollbar.prototype._sync_to_contents = function _sync_to_contents() {
            var self = this;
            self.sync_to_contents_timer = 0;
            self.set_position(self.sync_to_contents_frac);
        };
        if (!BookScrollbar.prototype._sync_to_contents.__module__) Object.defineProperties(BookScrollbar.prototype._sync_to_contents, {
            __module__ : {value: "read_book.scrollbar"}
        });
        BookScrollbar.prototype.sync_to_contents = function sync_to_contents(frac) {
            var self = this;
            self.sync_to_contents_frac = frac;
            if (!self.sync_to_contents_timer) {
                self.sync_to_contents_timer = window.setTimeout(self._sync_to_contents, 50);
            }
        };
        if (!BookScrollbar.prototype.sync_to_contents.__argnames__) Object.defineProperties(BookScrollbar.prototype.sync_to_contents, {
            __argnames__ : {value: ["frac"]},
            __module__ : {value: "read_book.scrollbar"}
        });
        BookScrollbar.prototype.apply_color_scheme = function apply_color_scheme(colors) {
            var self = this;
            var fg, bg, rbg, rfg, c;
            fg = cached_color_to_rgba(colors.foreground);
            bg = cached_color_to_rgba(colors.background);
            function mix(fg, bg, frac) {
                function m(x) {
                    return frac * fg[(typeof x === "number" && x < 0) ? fg.length + x : x] + (1 - frac) * bg[(typeof x === "number" && x < 0) ? bg.length + x : x];
                };
                if (!m.__argnames__) Object.defineProperties(m, {
                    __argnames__ : {value: ["x"]},
                    __module__ : {value: "read_book.scrollbar"}
                });

                return [m[0], m[1], m[2]];
            };
            if (!mix.__argnames__) Object.defineProperties(mix, {
                __argnames__ : {value: ["fg", "bg", "frac"]},
                __module__ : {value: "read_book.scrollbar"}
            });

            rbg = mix(fg, bg, .3);
            rfg = mix(fg, bg, .7);
            c = self.container;
            c.style.backgroundColor = "rgb(" + ρσ_str.format("{}", rbg[0]) + ", " + ρσ_str.format("{}", rbg[1]) + ", " + ρσ_str.format("{}", rbg[2]) + ")";
            c.firstChild.style.backgroundColor = "rgb(" + ρσ_str.format("{}", rfg[0]) + ", " + ρσ_str.format("{}", rfg[1]) + ", " + ρσ_str.format("{}", rfg[2]) + ")";
        };
        if (!BookScrollbar.prototype.apply_color_scheme.__argnames__) Object.defineProperties(BookScrollbar.prototype.apply_color_scheme, {
            __argnames__ : {value: ["colors"]},
            __module__ : {value: "read_book.scrollbar"}
        });
        BookScrollbar.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        BookScrollbar.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(BookScrollbar.prototype, "__bases__", {value: []});
        
        

        ρσ_modules["read_book.scrollbar"].SIZE = SIZE;
        ρσ_modules["read_book.scrollbar"].BookScrollbar = BookScrollbar;
    })();

    (function(){
        var __name__ = "read_book.search_worker";
        var GET_SPINE_FAILED, CONNECT_FAILED, UNHANDLED_ERROR, DB_ERROR, _RE_ESCAPE, quote_map, qpat, spat, invisible_chars, _ESCAPED_ATOM, wc;
        var DB = ρσ_modules["read_book.db"].DB;

        var text_from_serialized_html = ρσ_modules["read_book.resources"].text_from_serialized_html;

        var format_exception = ρσ_modules.traceback.format_exception;

        GET_SPINE_FAILED = 1;
        CONNECT_FAILED = 2;
        UNHANDLED_ERROR = 3;
        DB_ERROR = 4;
        _RE_ESCAPE = /[\/\\^$*+?.()|[\]{}]/g;
        quote_map = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["\""] = "\"“”";
            ρσ_d["'"] = "'‘’";
            return ρσ_d;
        }).call(this);
        qpat = /(['"])/g;
        spat = /(\s+)/g;
        invisible_chars = "(?:[\u00ad\u200c\u200d]{0,1})";
        _ESCAPED_ATOM = /\\[\s\S]|[\s\S]/gu;
        function escape(string) {
            return string.replace(_RE_ESCAPE, "\\$&");
        };
        if (!escape.__argnames__) Object.defineProperties(escape, {
            __argnames__ : {value: ["string"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function split_string(pat, string) {
            pat.lastIndex = 0;
            return string.split(pat);
        };
        if (!split_string.__argnames__) Object.defineProperties(split_string, {
            __argnames__ : {value: ["pat", "string"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function text_to_regex(text) {
            var has_leading, has_trailing, ans, r, atoms, part, wpart;
            if (text && !text.strip()) {
                return "\\s+";
            }
            has_leading = text.lstrip() !== text;
            has_trailing = text.rstrip() !== text;
            ans = [];
            if (has_leading) {
                ans.push("\\s+");
            }
            var ρσ_Iter0 = ρσ_Iterable(split_string(spat, text.strip()));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                wpart = ρσ_Iter0[ρσ_Index0];
                if (!wpart.strip()) {
                    ans.push("\\s+");
                } else {
                    var ρσ_Iter1 = ρσ_Iterable(split_string(qpat, wpart));
                    for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                        part = ρσ_Iter1[ρσ_Index1];
                        r = quote_map[(typeof part === "number" && part < 0) ? quote_map.length + part : part];
                        if (r) {
                            ans.push("[" + r + "]");
                        } else if (part) {
                            atoms = escape(part).match(_ESCAPED_ATOM);
                            if (atoms) {
                                ans.push(atoms.join(invisible_chars));
                            }
                        }
                    }
                }
            }
            if (has_trailing) {
                ans.push("\\s+");
            }
            return ans.join("");
        };
        if (!text_to_regex.__argnames__) Object.defineProperties(text_to_regex, {
            __argnames__ : {value: ["text"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function ToCOffsetMap() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            ToCOffsetMap.prototype.__bind_methods__.call(this);
            ToCOffsetMap.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(ToCOffsetMap.prototype, "__bind_methods__", {value: function () {
            this.toc_nodes_for_offset = ToCOffsetMap.prototype.toc_nodes_for_offset.bind(this);
        }});
        ToCOffsetMap.prototype.__init__ = function __init__(toc_nodes, offset_map, previous_toc_node, parent_map) {
            var self = this;
            self.toc_nodes = toc_nodes || [];
            self.offset_map = offset_map || Object.create(null);
            self.previous_toc_node = previous_toc_node || null;
            self.parent_map = parent_map || Object.create(null);
        };
        if (!ToCOffsetMap.prototype.__init__.__argnames__) Object.defineProperties(ToCOffsetMap.prototype.__init__, {
            __argnames__ : {value: ["toc_nodes", "offset_map", "previous_toc_node", "parent_map"]},
            __module__ : {value: "read_book.search_worker"}
        });
        ToCOffsetMap.__argnames__ = ToCOffsetMap.prototype.__init__.__argnames__;
        ToCOffsetMap.__handles_kwarg_interpolation__ = ToCOffsetMap.prototype.__init__.__handles_kwarg_interpolation__;
        ToCOffsetMap.prototype.toc_nodes_for_offset = function toc_nodes_for_offset(offset) {
            var self = this;
            var matches, q, node, ans, ancestors, parent;
            matches = [];
            var ρσ_Iter2 = ρσ_Iterable(self.toc_nodes);
            for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                node = ρσ_Iter2[ρσ_Index2];
                q = (ρσ_expr_temp = self.offset_map)[ρσ_bound_index(node.id, ρσ_expr_temp)];
                if ((typeof q !== "undefined" && q !== null)) {
                    if (q > offset) {
                        break;
                    }
                    matches.push(node);
                }
            }
            if (!matches && self.previous_toc_node) {
                matches.push(self.previous_toc_node);
            }
            ans = [];
            if (matches.length) {
                ancestors = [];
                node = matches[matches.length-1];
                parent = (ρσ_expr_temp = self.parent_map)[ρσ_bound_index(node.id, ρσ_expr_temp)];
                while ((typeof parent !== "undefined" && parent !== null)) {
                    ancestors.push(parent);
                    parent = (ρσ_expr_temp = self.parent_map)[ρσ_bound_index(parent.id, ρσ_expr_temp)];
                }
                if (ancestors.length > 1) {
                    for (var i = ancestors.length - 1; i-- > 0;) {
                        ans.push(ancestors[(typeof i === "number" && i < 0) ? ancestors.length + i : i].id);
                    }
                }
                ans.push(node.id);
            }
            return ans;
        };
        if (!ToCOffsetMap.prototype.toc_nodes_for_offset.__argnames__) Object.defineProperties(ToCOffsetMap.prototype.toc_nodes_for_offset, {
            __argnames__ : {value: ["offset"]},
            __module__ : {value: "read_book.search_worker"}
        });
        ToCOffsetMap.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        ToCOffsetMap.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(ToCOffsetMap.prototype, "__bases__", {value: []});

        function toc_offset_map_for_name(name) {
            var anchor_map, toc_data, idx, toc_nodes, offset_map, node_id, aid, offset, node, prev_toc_node, spine_name, ptn;
            if ((ρσ_expr_temp = wc.toc_offset_map_cache)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]) {
                return (ρσ_expr_temp = wc.toc_offset_map_cache)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name];
            }
            anchor_map = (ρσ_expr_temp = wc.text_cache)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name][1];
            toc_data = wc.current_book.toc_data;
            idx = (ρσ_expr_temp = toc_data.spine_idx_map)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name];
            toc_nodes = (ρσ_expr_temp = toc_data.spine_toc_map)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name];
            if (!(typeof idx !== "undefined" && idx !== null) || idx < 0) {
                (ρσ_expr_temp = wc.toc_offset_map_cache)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name] = new ToCOffsetMap;
                return (ρσ_expr_temp = wc.toc_offset_map_cache)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name];
            }
            offset_map = Object.create(null);
            var ρσ_Iter3 = ρσ_Iterable(toc_nodes);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                node = ρσ_Iter3[ρσ_Index3];
                node_id = node.id;
                if ((typeof node_id !== "undefined" && node_id !== null)) {
                    aid = node.frag;
                    offset = anchor_map[(typeof aid === "number" && aid < 0) ? anchor_map.length + aid : aid] || 0;
                    offset_map[(typeof node_id === "number" && node_id < 0) ? offset_map.length + node_id : node_id] = offset;
                }
            }
            prev_toc_node = null;
            for (var i = idx; i-- > 0;) {
                spine_name = (ρσ_expr_temp = wc.current_book.spine)[(typeof i === "number" && i < 0) ? ρσ_expr_temp.length + i : i];
                ptn = (ρσ_expr_temp = toc_data.spine_toc_map)[(typeof spine_name === "number" && spine_name < 0) ? ρσ_expr_temp.length + spine_name : spine_name];
                if ((typeof ptn !== "undefined" && ptn !== null)) {
                    prev_toc_node = ptn[ptn.length-1];
                    break;
                }
            }
            (ρσ_expr_temp = wc.toc_offset_map_cache)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name] = new ToCOffsetMap(toc_nodes, offset_map, prev_toc_node, toc_data.parent_map);
            return (ρσ_expr_temp = wc.toc_offset_map_cache)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name];
        };
        if (!toc_offset_map_for_name.__argnames__) Object.defineProperties(toc_offset_map_for_name, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function toc_nodes_for_search_result(sr) {
            var sidx, name, tmap;
            sidx = sr.spine_idx;
            name = (ρσ_expr_temp = wc.current_book.spine)[(typeof sidx === "number" && sidx < 0) ? ρσ_expr_temp.length + sidx : sidx];
            if (!name) {
                return [];
            }
            tmap = toc_offset_map_for_name(name);
            return tmap.toc_nodes_for_offset(sr.offset);
        };
        if (!toc_nodes_for_search_result.__argnames__) Object.defineProperties(toc_nodes_for_search_result, {
            __argnames__ : {value: ["sr"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function Worker() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            Worker.prototype.__bind_methods__.call(this);
            Worker.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(Worker.prototype, "__bind_methods__", {value: function () {
            this.clear_caches = Worker.prototype.clear_caches.bind(this);
        }});
        Object.defineProperties(Worker.prototype,  {
            "initialize_error_msg": {
                "enumerable": true, 
                "get": function initialize_error_msg() {
                    var self = this;
                    return ρσ_exists.d(self.db).initialize_error_msg;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        Worker.prototype.__init__ = function __init__() {
            var self = this;
            self.db = null;
            self.connected_to_db = false;
            self.pending_search = null;
            self.searching = false;
            self.current_query = null;
            self.current_query_id = null;
            self.current_book = null;
            self.regex = null;
            self.result_num = 0;
            self.clear_caches();
        };
        if (!Worker.prototype.__init__.__module__) Object.defineProperties(Worker.prototype.__init__, {
            __module__ : {value: "read_book.search_worker"}
        });
        Worker.__argnames__ = Worker.prototype.__init__.__argnames__;
        Worker.__handles_kwarg_interpolation__ = Worker.prototype.__init__.__handles_kwarg_interpolation__;
        Worker.prototype.clear_caches = function clear_caches() {
            var self = this;
            self.text_cache = Object.create(null);
            self.toc_offset_map_cache = Object.create(null);
        };
        if (!Worker.prototype.clear_caches.__module__) Object.defineProperties(Worker.prototype.clear_caches, {
            __module__ : {value: "read_book.search_worker"}
        });
        Worker.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        Worker.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(Worker.prototype, "__bases__", {value: []});
        

        wc = new Worker;
        function send_search_complete() {
            self.postMessage((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "search_complete";
                ρσ_d["id"] = wc.current_query_id;
                return ρσ_d;
            }).call(this));
            wc.current_query = wc.current_query_id = null;
        };
        if (!send_search_complete.__module__) Object.defineProperties(send_search_complete, {
            __module__ : {value: "read_book.search_worker"}
        });

        function search_in_text_of(name) {
            var ctx_size, r, haystack, match_counts, spine_idx, m, text, ρσ_unpack, start, end, before, after, q, result;
            ctx_size = 75;
            r = wc.regex;
            r.lastIndex = 0;
            haystack = (ρσ_expr_temp = wc.text_cache)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name][0] || "";
            match_counts = Object.create(null);
            spine_idx = wc.current_book.spine.indexOf(name);
            while (true) {
                m = r.exec(haystack);
                if (!m) {
                    break;
                }
                text = m[0];
                ρσ_unpack = [m.index, r.lastIndex];
                start = ρσ_unpack[0];
                end = ρσ_unpack[1];
                before = haystack.slice(Math.max(0, start - ctx_size), start);
                after = haystack.slice(end, end + ctx_size);
                q = (before || "").slice(-15) + text + (after || "").slice(0, 15);
                match_counts[(typeof q === "number" && q < 0) ? match_counts.length + q : q] = match_counts[(typeof q === "number" && q < 0) ? match_counts.length + q : q] || 0;
                wc.result_num += 1;
                result = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["file_name"] = name;
                    ρσ_d["spine_idx"] = spine_idx;
                    ρσ_d["index"] = match_counts[(typeof q === "number" && q < 0) ? match_counts.length + q : q];
                    ρσ_d["offset"] = start;
                    ρσ_d["text"] = text;
                    ρσ_d["before"] = before;
                    ρσ_d["after"] = after;
                    ρσ_d["mode"] = wc.current_query.query.mode;
                    ρσ_d["q"] = q;
                    ρσ_d["result_num"] = wc.result_num;
                    ρσ_d["on_discovery"] = wc.current_query_id;
                    return ρσ_d;
                }).call(this);
                result.toc_nodes = toc_nodes_for_search_result(result);
                self.postMessage((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "search_result";
                    ρσ_d["id"] = wc.current_query_id;
                    ρσ_d["result"] = result;
                    return ρσ_d;
                }).call(this));
                if (wc.current_query.query.only_first_match) {
                    break;
                }
                match_counts[(typeof q === "number" && q < 0) ? match_counts.length + q : q] += 1;
            }
        };
        if (!search_in_text_of.__argnames__) Object.defineProperties(search_in_text_of, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function queue_next_spine_item(spine_idx, allow_current_name) {
            var name, query;
            spine_idx = spine_idx % wc.current_book.spine.length;
            name = (ρσ_expr_temp = wc.current_book.spine)[(typeof spine_idx === "number" && spine_idx < 0) ? ρσ_expr_temp.length + spine_idx : spine_idx];
            if (wc.current_query.query.only_first_match && wc.result_num > 0) {
                send_search_complete();
                return;
            }
            if (!name || !allow_current_name && name === wc.current_query.current_name) {
                send_search_complete();
                return;
            }
            if ((ρσ_expr_temp = wc.text_cache)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]) {
                search_in_text_of(name);
                setTimeout(queue_next_spine_item.bind(null, spine_idx + 1), 0);
                return;
            }
            query = wc.current_query;
            wc.db.get_book_file(wc.current_book.book_hash, wc.current_book.stored_files, name, got_spine_item.bind(null, query.id, spine_idx));
        };
        if (!queue_next_spine_item.__argnames__) Object.defineProperties(queue_next_spine_item, {
            __argnames__ : {value: ["spine_idx", "allow_current_name"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function got_spine_item(query_id, spine_idx, result) {
            var name, data;
            if (query_id !== wc.current_query_id) {
                return;
            }
            if (result.ok) {
                name = (ρσ_expr_temp = wc.current_book.spine)[(typeof spine_idx === "number" && spine_idx < 0) ? ρσ_expr_temp.length + spine_idx : spine_idx];
                data = result.result;
                if (data instanceof Blob) {
                    queue_next_spine_item(spine_idx + 1);
                    return;
                }
                (ρσ_expr_temp = wc.text_cache)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name] = text_from_serialized_html(data, true);
                search_in_text_of(name);
                setTimeout(queue_next_spine_item.bind(null, spine_idx + 1), 0);
            } else {
                if (result.details === "ENOENT") {
                    queue_next_spine_item(spine_idx + 1);
                } else {
                    send_error(GET_SPINE_FAILED, result.details);
                    wc.current_query = wc.current_query_id = null;
                }
            }
        };
        if (!got_spine_item.__argnames__) Object.defineProperties(got_spine_item, {
            __argnames__ : {value: ["query_id", "spine_idx", "result"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function regex_for_query(query) {
            var expr, flags, words, part;
            expr = query.text;
            flags = "umg";
            if (!query.case_sensitive) {
                flags += "i";
            }
            if (query.mode !== "regex") {
                if (query.mode === "word") {
                    words = [];
                    var ρσ_Iter4 = ρσ_Iterable(expr.split(" "));
                    for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                        part = ρσ_Iter4[ρσ_Index4];
                        words.push("\\b" + text_to_regex(part) + "\\b");
                    }
                    expr = words.join("\\s+");
                } else {
                    expr = text_to_regex(expr);
                }
            }
            return new RegExp(expr, flags);
        };
        if (!regex_for_query.__argnames__) Object.defineProperties(regex_for_query, {
            __argnames__ : {value: ["query"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function perform_search(query) {
            var idx;
            wc.current_query = query;
            wc.current_query_id = query.id;
            wc.result_num = 0;
            if (!wc.current_book || !ρσ_exists.d(wc.current_book.spine).length || !query.query.text) {
                send_search_complete();
                return;
            }
            wc.regex = regex_for_query(query.query);
            idx = wc.current_book.spine.indexOf(query.current_name);
            if (idx < 0) {
                idx = 0;
            }
            wc.current_query.current_name = (ρσ_expr_temp = wc.current_book.spine)[(typeof idx === "number" && idx < 0) ? ρσ_expr_temp.length + idx : idx];
            queue_next_spine_item(idx, true);
        };
        if (!perform_search.__argnames__) Object.defineProperties(perform_search, {
            __argnames__ : {value: ["query"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function worker_connection_done() {
            var s;
            wc.connected_to_db = true;
            if (!wc.initialize_error_msg) {
                if (wc.pending_search) {
                    s = wc.pending_search;
                    wc.pending_search = null;
                    perform_search(s);
                }
            }
        };
        if (!worker_connection_done.__module__) Object.defineProperties(worker_connection_done, {
            __module__ : {value: "read_book.search_worker"}
        });

        function send_error(code, msg, error) {
            self.postMessage((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "error";
                ρσ_d["code"] = code;
                ρσ_d["msg"] = msg;
                ρσ_d["id"] = wc.current_query_id;
                ρσ_d["error"] = error;
                return ρσ_d;
            }).call(this));
        };
        if (!send_error.__argnames__) Object.defineProperties(send_error, {
            __argnames__ : {value: ["code", "msg", "error"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function on_worker_db_error(title, msg, details) {
            send_error(DB_ERROR, msg, (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["title"] = title;
                ρσ_d["msg"] = msg;
                ρσ_d["details"] = details;
                return ρσ_d;
            }).call(this));
        };
        if (!on_worker_db_error.__argnames__) Object.defineProperties(on_worker_db_error, {
            __argnames__ : {value: ["title", "msg", "details"]},
            __module__ : {value: "read_book.search_worker"}
        });

        function worker_main() {
            wc.db = new DB(worker_connection_done, on_worker_db_error);
            self.onmessage = (function() {
                var ρσ_anonfunc = function (e) {
                    if (e.data.type === "search") {
                        wc.current_query_id = e.data.id;
                        if (wc.connected_to_db) {
                            if (wc.initialize_error_msg) {
                                send_error(CONNECT_FAILED, wc.initialize_error_msg);
                            } else {
                                perform_search(e.data);
                            }
                        } else {
                            wc.pending_search = e.data;
                        }
                    } else if (e.data.type === "clear_caches") {
                        wc.clear_caches();
                        wc.current_book = e.data.book;
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["e"]},
                    __module__ : {value: "read_book.search_worker"}
                });
                return ρσ_anonfunc;
            })();
            self.addEventListener("error", (function() {
                var ρσ_anonfunc = function (e) {
                    send_error(UNHANDLED_ERROR, "" + ρσ_str.format("{}", e.lineno) + ":" + ρσ_str.format("{}", e.message) + "" + "\n\n" + format_exception(e.error).join(""));
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["e"]},
                    __module__ : {value: "read_book.search_worker"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!worker_main.__module__) Object.defineProperties(worker_main, {
            __module__ : {value: "read_book.search_worker"}
        });

        ρσ_modules["read_book.search_worker"].GET_SPINE_FAILED = GET_SPINE_FAILED;
        ρσ_modules["read_book.search_worker"].CONNECT_FAILED = CONNECT_FAILED;
        ρσ_modules["read_book.search_worker"].UNHANDLED_ERROR = UNHANDLED_ERROR;
        ρσ_modules["read_book.search_worker"].DB_ERROR = DB_ERROR;
        ρσ_modules["read_book.search_worker"]._RE_ESCAPE = _RE_ESCAPE;
        ρσ_modules["read_book.search_worker"].quote_map = quote_map;
        ρσ_modules["read_book.search_worker"].qpat = qpat;
        ρσ_modules["read_book.search_worker"].spat = spat;
        ρσ_modules["read_book.search_worker"].invisible_chars = invisible_chars;
        ρσ_modules["read_book.search_worker"]._ESCAPED_ATOM = _ESCAPED_ATOM;
        ρσ_modules["read_book.search_worker"].wc = wc;
        ρσ_modules["read_book.search_worker"].escape = escape;
        ρσ_modules["read_book.search_worker"].split_string = split_string;
        ρσ_modules["read_book.search_worker"].text_to_regex = text_to_regex;
        ρσ_modules["read_book.search_worker"].ToCOffsetMap = ToCOffsetMap;
        ρσ_modules["read_book.search_worker"].toc_offset_map_for_name = toc_offset_map_for_name;
        ρσ_modules["read_book.search_worker"].toc_nodes_for_search_result = toc_nodes_for_search_result;
        ρσ_modules["read_book.search_worker"].Worker = Worker;
        ρσ_modules["read_book.search_worker"].send_search_complete = send_search_complete;
        ρσ_modules["read_book.search_worker"].search_in_text_of = search_in_text_of;
        ρσ_modules["read_book.search_worker"].queue_next_spine_item = queue_next_spine_item;
        ρσ_modules["read_book.search_worker"].got_spine_item = got_spine_item;
        ρσ_modules["read_book.search_worker"].regex_for_query = regex_for_query;
        ρσ_modules["read_book.search_worker"].perform_search = perform_search;
        ρσ_modules["read_book.search_worker"].worker_connection_done = worker_connection_done;
        ρσ_modules["read_book.search_worker"].send_error = send_error;
        ρσ_modules["read_book.search_worker"].on_worker_db_error = on_worker_db_error;
        ρσ_modules["read_book.search_worker"].worker_main = worker_main;
    })();

    (function(){
        var __name__ = "worker";
        var main_js = ρσ_modules["book_list.globals"].main_js;

        function worker_js_url(entry_point) {
            if (!worker_js_url.ans) {
                worker_js_url.ans = window.URL.createObjectURL(new Blob(ρσ_list_decorate([ main_js() ])), (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "text/javascript";
                    return ρσ_d;
                }).call(this));
            }
            return worker_js_url.ans + "#" + entry_point;
        };
        if (!worker_js_url.__argnames__) Object.defineProperties(worker_js_url, {
            __argnames__ : {value: ["entry_point"]},
            __module__ : {value: "worker"}
        });

        function start_worker(entry_point) {
            return new window.Worker(worker_js_url(entry_point));
        };
        if (!start_worker.__argnames__) Object.defineProperties(start_worker, {
            __argnames__ : {value: ["entry_point"]},
            __module__ : {value: "worker"}
        });

        ρσ_modules.worker.worker_js_url = worker_js_url;
        ρσ_modules.worker.start_worker = start_worker;
    })();

    (function(){
        var __name__ = "read_book.search";
        var main;
        var E = ρσ_modules.elementmaker.E;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var get_color = ρσ_modules["book_list.theme"].get_color;

        var create_top_bar = ρσ_modules["book_list.top_bar"].create_top_bar;

        var create_search_bar = ρσ_modules.complete.create_search_bar;

        var clear = ρσ_modules.dom.clear;
        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;

        var _ = ρσ_modules.gettext.gettext;
        var ngettext = ρσ_modules.gettext.ngettext;

        var error_dialog = ρσ_modules.modals.error_dialog;

        var current_book = ρσ_modules["read_book.globals"].current_book;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var CONNECT_FAILED = ρσ_modules["read_book.search_worker"].CONNECT_FAILED;
        var DB_ERROR = ρσ_modules["read_book.search_worker"].DB_ERROR;
        var GET_SPINE_FAILED = ρσ_modules["read_book.search_worker"].GET_SPINE_FAILED;
        var UNHANDLED_ERROR = ρσ_modules["read_book.search_worker"].UNHANDLED_ERROR;
        var worker_main = ρσ_modules["read_book.search_worker"].worker_main;

        var shortcut_for_key_event = ρσ_modules["read_book.shortcuts"].shortcut_for_key_event;

        var create_button = ρσ_modules.widgets.create_button;
        var create_spinner = ρσ_modules.widgets.create_spinner;
        var create_select = ρσ_modules.widgets.create_select;

        var start_worker = ρσ_modules.worker.start_worker;

        function parse_error_msg(msg) {
            var details, emsg;
            details = msg.msg;
            emsg = _("Unknown error");
            if (msg.code === GET_SPINE_FAILED) {
                emsg = _("Loading text from the book failed.");
            } else if (msg.code === CONNECT_FAILED) {
                emsg = _("Connecting to database storing the local copy of the book failed in the worker thread.");
            } else if (msg.code === UNHANDLED_ERROR) {
                emsg = _("There was an unhandled error while searching.");
            } else if (msg.code === DB_ERROR) {
                emsg = msg.error.msg;
                details = msg.error.details;
            }
            return [emsg, details];
        };
        if (!parse_error_msg.__argnames__) Object.defineProperties(parse_error_msg, {
            __argnames__ : {value: ["msg"]},
            __module__ : {value: "read_book.search"}
        });

        function get_toc_data(book) {
            var spine, spine_toc_map, name, parent_map, toc_id_map, toc;
            spine = book.manifest.spine;
            spine_toc_map = (function() {
                var ρσ_Iter = ρσ_Iterable(spine), ρσ_Result = Object.create(null), name;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    name = ρσ_Iter[ρσ_Index];
                    ρσ_Result[name] = ([]);
                }
                return ρσ_Result;
            })();
            parent_map = Object.create(null);
            toc_id_map = Object.create(null);
            function process_node(node) {
                var items, children, child;
                toc_id_map[ρσ_bound_index(node.id, toc_id_map)] = node;
                items = spine_toc_map[ρσ_bound_index(node.dest, spine_toc_map)];
                if (items) {
                    items.push(node);
                }
                children = node.children;
                if (children) {
                    var ρσ_Iter0 = ρσ_Iterable(children);
                    for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                        child = ρσ_Iter0[ρσ_Index0];
                        parent_map[ρσ_bound_index(child.id, parent_map)] = node;
                        process_node(child);
                    }
                }
            };
            if (!process_node.__argnames__) Object.defineProperties(process_node, {
                __argnames__ : {value: ["node"]},
                __module__ : {value: "read_book.search"}
            });

            toc = book.manifest.toc;
            if (toc) {
                process_node(toc);
            }
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["spine"] = spine;
                ρσ_d["spine_toc_map"] = spine_toc_map;
                ρσ_d["spine_idx_map"] = (function() {
                    var ρσ_Iter = ρσ_Iterable(enumerate(spine)), ρσ_Result = Object.create(null), idx, name;
                    for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                        ρσ_unpack = ρσ_Iter[ρσ_Index];
                        idx = ρσ_unpack[0];
                        name = ρσ_unpack[1];
                        ρσ_Result[name] = (idx);
                    }
                    return ρσ_Result;
                })();
                ρσ_d["parent_map"] = parent_map;
                ρσ_d["toc_id_map"] = toc_id_map;
                return ρσ_d;
            }).call(this);
        };
        if (!get_toc_data.__argnames__) Object.defineProperties(get_toc_data, {
            __argnames__ : {value: ["book"]},
            __module__ : {value: "read_book.search"}
        });

        function SearchOverlay() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            SearchOverlay.prototype.__bind_methods__.call(this);
            SearchOverlay.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(SearchOverlay.prototype, "__bind_methods__", {value: function () {
            this.show_wait = SearchOverlay.prototype.show_wait.bind(this);
            this.show_results = SearchOverlay.prototype.show_results.bind(this);
            this.clear_results = SearchOverlay.prototype.clear_results.bind(this);
            this.do_initial_search = SearchOverlay.prototype.do_initial_search.bind(this);
            this.handle_initial_search_result = SearchOverlay.prototype.handle_initial_search_result.bind(this);
            this.queue_search = SearchOverlay.prototype.queue_search.bind(this);
            this.set_original_pos = SearchOverlay.prototype.set_original_pos.bind(this);
            this.return_to_original_position = SearchOverlay.prototype.return_to_original_position.bind(this);
            this.on_worker_message = SearchOverlay.prototype.on_worker_message.bind(this);
            this.no_result_received = SearchOverlay.prototype.no_result_received.bind(this);
            this.result_received = SearchOverlay.prototype.result_received.bind(this);
            this.make_result_current = SearchOverlay.prototype.make_result_current.bind(this);
            this.search_result_discovered = SearchOverlay.prototype.search_result_discovered.bind(this);
            this.search_result_not_found = SearchOverlay.prototype.search_result_not_found.bind(this);
            this.select_search_result_in_book = SearchOverlay.prototype.select_search_result_in_book.bind(this);
            this.result_clicked = SearchOverlay.prototype.result_clicked.bind(this);
            this.clear_caches = SearchOverlay.prototype.clear_caches.bind(this);
            this.next_match = SearchOverlay.prototype.next_match.bind(this);
            this.onkeyup = SearchOverlay.prototype.onkeyup.bind(this);
            this.onkeydown = SearchOverlay.prototype.onkeydown.bind(this);
            this.find_next = SearchOverlay.prototype.find_next.bind(this);
            this.set_text = SearchOverlay.prototype.set_text.bind(this);
            this.hide = SearchOverlay.prototype.hide.bind(this);
            this.show = SearchOverlay.prototype.show.bind(this);
            this.run_search = SearchOverlay.prototype.run_search.bind(this);
        }});
        Object.defineProperties(SearchOverlay.prototype,  {
            "current_query": {
                "enumerable": true, 
                "get": function current_query() {
                    var self = this;
                    var c;
                    c = self.container;
                    return (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["mode"] = c.querySelector("select[name=mode]").value;
                        ρσ_d["case_sensitive"] = c.querySelector("input[name=case_sensitive]").checked;
                        ρσ_d["text"] = c.querySelector("input[type=search]").value;
                        return ρσ_d;
                    }).call(this);
                }, 
                "set": function current_query(q) {
                    var self = this;
                    var c;
                    c = self.container;
                    c.querySelector("select[name=mode]").value = q.mode || "contains";
                    c.querySelector("input[name=case_sensitive]").checked = bool(q.case_sensitive);
                    c.querySelector("input[type=search]").value = q.text || "";
                }
            }, 
            "bottom_container": {
                "enumerable": true, 
                "get": function bottom_container() {
                    var self = this;
                    return self.container.lastChild;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "results_container": {
                "enumerable": true, 
                "get": function results_container() {
                    var self = this;
                    return self.bottom_container.lastChild;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "worker": {
                "enumerable": true, 
                "get": function worker() {
                    var self = this;
                    if (!self._worker) {
                        self._worker = start_worker("read_book.search");
                        self._worker.onmessage = self.on_worker_message;
                        self.clear_caches();
                    }
                    return self._worker;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "current_result_container": {
                "enumerable": true, 
                "get": function current_result_container() {
                    var self = this;
                    return self.container.querySelector(".current");
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "container": {
                "enumerable": true, 
                "get": function container() {
                    var self = this;
                    return document.getElementById(self.CONTAINER_ID);
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "is_visible": {
                "enumerable": true, 
                "get": function is_visible() {
                    var self = this;
                    return self.container.style.display !== "none";
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        SearchOverlay.prototype.__init__ = function __init__(view) {
            var self = this;
            var c, search_button, sd, mode, ρσ_unpack, ssc, ss, child;
            self.view = view;
            self.search_in_flight = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["id"] = null;
                ρσ_d["mode"] = "contains";
                ρσ_d["case_sensitive"] = false;
                return ρσ_d;
            }).call(this);
            self._worker = null;
            self.request_counter = 0;
            self.result_map = Object.create(null);
            c = self.container;
            c.style.backgroundColor = get_color("window-background");
            c.style.maxHeight = "100vh";
            c.style.minHeight = "100vh";
            c.style.flexDirection = "column";
            c.style.alignItems = "stretch";
            c.style.overflow = "hidden";
            c.style.userSelect = "none";
            c.addEventListener("keydown", self.onkeydown);
            c.addEventListener("keyup", self.onkeyup);
            self.result_handler = null;
            ρσ_interpolate_kwargs.call(this, create_top_bar, [c].concat([ρσ_desugar_kwargs({title: _("Search in book"), action: self.hide, icon: "close"})]));
            search_button = create_button(_("Search"), "search");
            c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(this, create_search_bar, [self.run_search, "search-in-book"].concat([ρσ_desugar_kwargs({button: search_button})])), E.div("  "), search_button].concat([ρσ_desugar_kwargs({style: "display: flex; padding: 1rem; padding-bottom: 0.5rem; overflow: hidden"})])));
            c.lastChild.firstChild.style.flexGrow = "100";
            sd = get_session_data();
            mode = sd.get("book_search_mode");
            ρσ_unpack = ρσ_interpolate_kwargs.call(this, create_select, [_("Type of search:\n\nContains: Search for the entered text anywhere\n\nWhole words: Search for whole words that equal the entered text\n\nRegex: Interpret the entered text as a regular expression"), mode].concat([ρσ_desugar_kwargs({contains: _("Contains"), word: _("Whole words"), regex: _("Regex")})]));
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            ssc = ρσ_unpack[0];
            ss = ρσ_unpack[1];
            ss.setAttribute("name", "mode");
            ss.addEventListener("change", (function() {
                var ρσ_anonfunc = function (ev) {
                    get_session_data().set("book_search_mode", ev.target.value);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.search"}
                });
                return ρσ_anonfunc;
            })());
            c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [E.label(_("Search type:") + " ", ssc), E.div("  "), ρσ_interpolate_kwargs.call(E, E.label, [ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({type: "checkbox", name: "case_sensitive", checked: bool(sd.get("book_search_case_sensitive"))})]), _("Case sensitive")].concat([ρσ_desugar_kwargs({onchange: (function() {
                var ρσ_anonfunc = function (event) {
                    get_session_data().set("book_search_case_sensitive", event.target.checked);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["event"]},
                    __module__ : {value: "read_book.search"}
                });
                return ρσ_anonfunc;
            })()})])), E.div("  "), ρσ_interpolate_kwargs.call(this, create_button, [_("Return"), "chevron-left"].concat([ρσ_desugar_kwargs({action: self.return_to_original_position, tooltip: _("Go back to where you were before searching")})]))].concat([ρσ_desugar_kwargs({style: "display: flex; padding: 1rem; padding-top: 0.5rem; padding-bottom: 0; align-items: center; overflow: hidden"})])));
            c.appendChild(E.hr());
            c.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [E.div(create_spinner("4em", "4em")), ρσ_interpolate_kwargs.call(E, E.div, [_("Searching, please wait…")].concat([ρσ_desugar_kwargs({style: "margin-top: 1ex"})]))].concat([ρσ_desugar_kwargs({style: "text-align: center"})])), E.div()].concat([ρσ_desugar_kwargs({style: "display: none; overflow: auto", tabindex: "0"})])));
            var ρσ_Iter1 = ρσ_Iterable(c.childNodes);
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                child = ρσ_Iter1[ρσ_Index1];
                if (child !== c.lastChild) {
                    child.style.flexShrink = "0";
                }
            }
        };
        if (!SearchOverlay.prototype.__init__.__argnames__) Object.defineProperties(SearchOverlay.prototype.__init__, {
            __argnames__ : {value: ["view"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.__argnames__ = SearchOverlay.prototype.__init__.__argnames__;
        SearchOverlay.__handles_kwarg_interpolation__ = SearchOverlay.prototype.__init__.__handles_kwarg_interpolation__;
        SearchOverlay.prototype.show_wait = function show_wait() {
            var self = this;
            var c;
            c = self.bottom_container;
            c.style.display = "block";
            c.firstChild.style.display = "block";
            c.lastChild.style.display = "none";
        };
        if (!SearchOverlay.prototype.show_wait.__module__) Object.defineProperties(SearchOverlay.prototype.show_wait, {
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.show_results = function show_results() {
            var self = this;
            var c;
            c = self.bottom_container;
            c.style.display = "block";
            c.firstChild.style.display = "none";
            c.lastChild.style.display = "block";
            c.focus();
        };
        if (!SearchOverlay.prototype.show_results.__module__) Object.defineProperties(SearchOverlay.prototype.show_results, {
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.clear_results = function clear_results() {
            var self = this;
            clear(self.results_container);
            self.result_map = Object.create(null);
        };
        if (!SearchOverlay.prototype.clear_results.__module__) Object.defineProperties(SearchOverlay.prototype.clear_results, {
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.do_initial_search = function do_initial_search(text, query) {
            var self = this;
            var q;
            q = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["mode"] = "contains";
                ρσ_d["case_sensitive"] = true;
                ρσ_d["text"] = text;
                ρσ_d["only_first_match"] = true;
                return ρσ_d;
            }).call(this);
            self.request_counter += 1;
            self.initial_search_result_counter = 0;
            self.initial_search_human_readable_query = query;
            self.search_in_flight.id = self.request_counter;
            self.result_handler = self.handle_initial_search_result;
            self.worker.postMessage((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "search";
                ρσ_d["current_name"] = "";
                ρσ_d["id"] = self.request_counter;
                ρσ_d["query"] = q;
                return ρσ_d;
            }).call(this));
        };
        if (!SearchOverlay.prototype.do_initial_search.__argnames__) Object.defineProperties(SearchOverlay.prototype.do_initial_search, {
            __argnames__ : {value: ["text", "query"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.handle_initial_search_result = function handle_initial_search_result(msg) {
            var self = this;
            var ρσ_unpack, emsg, details;
            if (msg.type === "error") {
                ρσ_unpack = parse_error_msg(msg);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                emsg = ρσ_unpack[0];
                details = ρσ_unpack[1];
                self.view.hide_loading();
                window.setTimeout((function() {
                    var ρσ_anonfunc = function () {
                        error_dialog(_("Could not search"), emsg, details);
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.search"}
                    });
                    return ρσ_anonfunc;
                })(), 1e3);
                self.result_handler = null;
                self.initial_search_result_counter = 0;
            } else if (msg.id === self.search_in_flight.id) {
                if (msg.type === "search_complete") {
                    self.search_in_flight.id = null;
                    self.result_handler = null;
                    if (self.initial_search_result_counter === 0) {
                        self.view.hide_loading();
                        window.alert(_("The full text search query {} was not found in the book, try a manual search.").format(self.initial_search_human_readable_query));
                    }
                    self.initial_search_result_counter = 0;
                } else if (msg.type === "search_result") {
                    self.initial_search_result_counter += 1;
                    if (self.initial_search_result_counter === 1) {
                        self.view.discover_search_result(msg.result);
                        self.view.hide_loading();
                    }
                }
            }
        };
        if (!SearchOverlay.prototype.handle_initial_search_result.__argnames__) Object.defineProperties(SearchOverlay.prototype.handle_initial_search_result, {
            __argnames__ : {value: ["msg"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.queue_search = function queue_search(query, book, current_name) {
            var self = this;
            self.request_counter += 1;
            self.original_position = self.view.currently_showing.bookpos;
            self.view.get_current_cfi("search-original-pos", self.set_original_pos);
            self.search_in_flight.id = self.request_counter;
            self.worker.postMessage((function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "search";
                ρσ_d["current_name"] = current_name;
                ρσ_d["id"] = self.request_counter;
                ρσ_d["query"] = query;
                return ρσ_d;
            }).call(this));
            self.clear_results();
            self.show_wait();
        };
        if (!SearchOverlay.prototype.queue_search.__argnames__) Object.defineProperties(SearchOverlay.prototype.queue_search, {
            __argnames__ : {value: ["query", "book", "current_name"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.set_original_pos = function set_original_pos(request_id, data) {
            var self = this;
            self.original_position = data.cfi;
        };
        if (!SearchOverlay.prototype.set_original_pos.__argnames__) Object.defineProperties(SearchOverlay.prototype.set_original_pos, {
            __argnames__ : {value: ["request_id", "data"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.return_to_original_position = function return_to_original_position() {
            var self = this;
            if (self.original_position) {
                self.view.goto_cfi(self.original_position);
            }
            self.hide();
        };
        if (!SearchOverlay.prototype.return_to_original_position.__module__) Object.defineProperties(SearchOverlay.prototype.return_to_original_position, {
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.on_worker_message = function on_worker_message(evt) {
            var self = this;
            var msg, ρσ_unpack, emsg, details;
            msg = evt.data;
            if (self.result_handler) {
                return self.result_handler(msg);
            }
            if (msg.type === "error") {
                ρσ_unpack = parse_error_msg(msg);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                emsg = ρσ_unpack[0];
                details = ρσ_unpack[1];
                error_dialog(_("Could not search"), emsg, details);
            } else if (msg.id === self.search_in_flight.id) {
                if (msg.type === "search_complete") {
                    self.search_in_flight.id = null;
                    if (Object.keys(self.result_map).length === 0) {
                        self.no_result_received();
                    }
                } else if (msg.type === "search_result") {
                    self.result_received(msg.result);
                }
            }
        };
        if (!SearchOverlay.prototype.on_worker_message.__argnames__) Object.defineProperties(SearchOverlay.prototype.on_worker_message, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.no_result_received = function no_result_received() {
            var self = this;
            self.show_results();
            self.results_container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [_("No matching results found")].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
        };
        if (!SearchOverlay.prototype.no_result_received.__module__) Object.defineProperties(SearchOverlay.prototype.no_result_received, {
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.result_received = function result_received(result) {
            var self = this;
            var sr, toc_node_id, toc_node, c, group, appended, csi, child, ul, tt, lines, ρσ_unpack, i, node_id, rnum, entry;
            self.show_results();
            (ρσ_expr_temp = self.result_map)[ρσ_bound_index(result.result_num, ρσ_expr_temp)] = result;
            sr = Object.assign(Object.create(null), result);
            self.view.discover_search_result(sr);
            toc_node_id = (result.toc_nodes.length) ? result.toc_nodes[0] : -1;
            toc_node = (ρσ_expr_temp = self.toc_data.toc_id_map)[(typeof toc_node_id === "number" && toc_node_id < 0) ? ρσ_expr_temp.length + toc_node_id : toc_node_id];
            c = self.results_container;
            group = c.querySelector("[data-toc-node-id=\"" + ρσ_str.format("{}", toc_node_id) + "\"]");
            if (!group) {
                group = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.span, ["+ "].concat([ρσ_desugar_kwargs({style: "display: none"})])), E.span((typeof toc_node !== "undefined" && toc_node !== null ? toc_node : Object.create(null)).title || _("Unknown"))].concat([ρσ_desugar_kwargs({title: _("Click to show/hide the results in this chapter"), onclick: (function() {
                    var ρσ_anonfunc = function (ev) {
                        ev.target.closest("[data-toc-node-id]").classList.toggle("collapsed");
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["ev"]},
                        __module__ : {value: "read_book.search"}
                    });
                    return ρσ_anonfunc;
                })()})])), E.ul()].concat([ρσ_desugar_kwargs({data_toc_node_id: toc_node_id + "", data_spine_index: result.spine_idx + ""})]));
                appended = false;
                var ρσ_Iter2 = ρσ_Iterable(c.querySelectorAll("[data-spine-index]"));
                for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                    child = ρσ_Iter2[ρσ_Index2];
                    csi = parseInt(child.dataset.spineIndex);
                    if (csi > result.spine_idx) {
                        appended = true;
                        c.insertBefore(group, child);
                        break;
                    }
                }
                if (!appended) {
                    c.appendChild(group);
                }
            }
            ul = group.getElementsByTagName("ul")[0];
            tt = "";
            if (result.toc_nodes.length) {
                lines = [];
                var ρσ_Iter3 = ρσ_Iterable(enumerate(result.toc_nodes));
                for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                    ρσ_unpack = ρσ_Iter3[ρσ_Index3];
                    i = ρσ_unpack[0];
                    node_id = ρσ_unpack[1];
                    lines.push("  ".repeat(i) + "➤ " + (ρσ_exists.d((ρσ_expr_temp = self.toc_data.toc_id_map)[(typeof node_id === "number" && node_id < 0) ? ρσ_expr_temp.length + node_id : node_id]).title || _("Unknown")));
                }
                tt = ngettext("Table of Contents section:", "Table of Contents sections:", lines.length);
                tt += "\n" + lines.join("\n");
            }
            rnum = result.result_num;
            entry = ρσ_interpolate_kwargs.call(E, E.li, [ρσ_desugar_kwargs({title: tt, data_result_num: rnum + "", onclick: self.result_clicked.bind(null, rnum)})]);
            if (result.before) {
                entry.appendChild(E.span("…" + result.before));
            }
            entry.appendChild(E.strong(result.text));
            if (result.after) {
                entry.appendChild(E.span(result.after + "…"));
            }
            ul.appendChild(entry);
        };
        if (!SearchOverlay.prototype.result_received.__argnames__) Object.defineProperties(SearchOverlay.prototype.result_received, {
            __argnames__ : {value: ["result"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.make_result_current = function make_result_current(result_num) {
            var self = this;
            var q, li;
            q = result_num + "";
            var ρσ_Iter4 = ρσ_Iterable(self.container.querySelectorAll("[data-result-num]"));
            for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                li = ρσ_Iter4[ρσ_Index4];
                if (li.dataset.resultNum === q) {
                    li.classList.add("current");
                    li.scrollIntoView();
                } else {
                    li.classList.remove("current");
                }
            }
        };
        if (!SearchOverlay.prototype.make_result_current.__argnames__) Object.defineProperties(SearchOverlay.prototype.make_result_current, {
            __argnames__ : {value: ["result_num"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.search_result_discovered = function search_result_discovered(sr) {
            var self = this;
            self.make_result_current(sr.result_num);
        };
        if (!SearchOverlay.prototype.search_result_discovered.__argnames__) Object.defineProperties(SearchOverlay.prototype.search_result_discovered, {
            __argnames__ : {value: ["sr"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.search_result_not_found = function search_result_not_found(sr) {
            var self = this;
            if (sr.on_discovery) {
                return;
            }
            error_dialog(_("Search result not found"), _("This search result matches text that is hidden in the book and cannot be displayed"));
            self.show();
        };
        if (!SearchOverlay.prototype.search_result_not_found.__argnames__) Object.defineProperties(SearchOverlay.prototype.search_result_not_found, {
            __argnames__ : {value: ["sr"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.select_search_result_in_book = function select_search_result_in_book(result_num) {
            var self = this;
            var sr;
            sr = Object.assign(Object.create(null), (ρσ_expr_temp = self.result_map)[(typeof result_num === "number" && result_num < 0) ? ρσ_expr_temp.length + result_num : result_num]);
            sr.on_discovery = 0;
            self.view.show_search_result(sr);
        };
        if (!SearchOverlay.prototype.select_search_result_in_book.__argnames__) Object.defineProperties(SearchOverlay.prototype.select_search_result_in_book, {
            __argnames__ : {value: ["result_num"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.result_clicked = function result_clicked(rnum) {
            var self = this;
            self.make_result_current(rnum);
            self.select_search_result_in_book(rnum);
            self.hide();
        };
        if (!SearchOverlay.prototype.result_clicked.__argnames__) Object.defineProperties(SearchOverlay.prototype.result_clicked, {
            __argnames__ : {value: ["rnum"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.clear_caches = function clear_caches(book) {
            var self = this;
            var data;
            self.clear_results();
            self.bottom_container.style.display = "none";
            if (self._worker) {
                book = book || current_book();
                self.toc_data = get_toc_data(book);
                data = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["book_hash"] = book.book_hash;
                    ρσ_d["stored_files"] = book.stored_files;
                    ρσ_d["spine"] = book.manifest.spine;
                    ρσ_d["toc_data"] = self.toc_data;
                    return ρσ_d;
                }).call(this);
                self.worker.postMessage((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "clear_caches";
                    ρσ_d["book"] = data;
                    return ρσ_d;
                }).call(this));
            }
        };
        if (!SearchOverlay.prototype.clear_caches.__argnames__) Object.defineProperties(SearchOverlay.prototype.clear_caches, {
            __argnames__ : {value: ["book"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.next_match = function next_match(delta) {
            var self = this;
            var num_of_results, c, rnum, cr;
            delta = delta || 1;
            num_of_results = Object.keys(self.result_map).length;
            c = self.current_result_container;
            if (c) {
                rnum = parseInt(c.dataset.resultNum) - 1;
                rnum = (rnum + delta + num_of_results) % num_of_results;
                rnum += 1;
            } else {
                rnum = 1;
            }
            self.make_result_current(rnum);
            self.results_container.focus();
            cr = self.current_result_container;
            if (cr) {
                self.select_search_result_in_book(cr.dataset.resultNum);
            }
        };
        if (!SearchOverlay.prototype.next_match.__argnames__) Object.defineProperties(SearchOverlay.prototype.next_match, {
            __argnames__ : {value: ["delta"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.onkeyup = function onkeyup(event) {
            var self = this;
            if (event.key === "Escape" || event.key === "Esc") {
                self.hide();
                [event.stopPropagation(), event.preventDefault()];
            }
        };
        if (!SearchOverlay.prototype.onkeyup.__argnames__) Object.defineProperties(SearchOverlay.prototype.onkeyup, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.onkeydown = function onkeydown(event) {
            var self = this;
            var sc_name;
            sc_name = shortcut_for_key_event(event, self.view.keyboard_shortcut_map);
            if (sc_name === "next_match") {
                self.next_match(1);
                [event.stopPropagation(), event.preventDefault()];
                return;
            }
            if (sc_name === "previous_match") {
                self.next_match(-1);
                [event.stopPropagation(), event.preventDefault()];
                return;
            }
        };
        if (!SearchOverlay.prototype.onkeydown.__argnames__) Object.defineProperties(SearchOverlay.prototype.onkeydown, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.find_next = function find_next(backwards) {
            var self = this;
            self.next_match((backwards) ? -1 : 1);
        };
        if (!SearchOverlay.prototype.find_next.__argnames__) Object.defineProperties(SearchOverlay.prototype.find_next, {
            __argnames__ : {value: ["backwards"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.set_text = function set_text(text) {
            var self = this;
            self.container.querySelector("input[type=search]").value = text || "";
        };
        if (!SearchOverlay.prototype.set_text.__argnames__) Object.defineProperties(SearchOverlay.prototype.set_text, {
            __argnames__ : {value: ["text"]},
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.hide = function hide() {
            var self = this;
            self.container.style.display = "none";
            ui_operations.focus_iframe();
        };
        if (!SearchOverlay.prototype.hide.__module__) Object.defineProperties(SearchOverlay.prototype.hide, {
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.show = function show() {
            var self = this;
            var c, inp;
            c = self.container;
            c.style.display = self.display_type;
            inp = c.querySelector("input");
            [inp.focus(), inp.select()];
        };
        if (!SearchOverlay.prototype.show.__module__) Object.defineProperties(SearchOverlay.prototype.show, {
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.run_search = function run_search() {
            var self = this;
            var q;
            q = self.current_query;
            if (!q.text) {
                self.clear_results();
                self.show_results();
            } else {
                self.queue_search(q, current_book(), self.view.currently_showing.name);
            }
        };
        if (!SearchOverlay.prototype.run_search.__module__) Object.defineProperties(SearchOverlay.prototype.run_search, {
            __module__ : {value: "read_book.search"}
        });
        SearchOverlay.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        SearchOverlay.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(SearchOverlay.prototype, "__bases__", {value: []});
        SearchOverlay.prototype.display_type = "flex";
        SearchOverlay.prototype.CONTAINER_ID = "book-search-overlay";
        
        
        
        
        
        
        
        

        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var css, sel;
                css = "";
                sel = "#" + ρσ_str.format("{}", SearchOverlay.prototype.CONTAINER_ID) + " ";
                sel += " div[data-toc-node-id]";
                css += ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({margin: "1rem"})]));
                css += sel + ".collapsed > div > span { display: inline !important; }";
                css += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ".collapsed > ul"].concat([ρσ_desugar_kwargs({display: "none"})]));
                css += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " > div"].concat([ρσ_desugar_kwargs({font_style: "italic", font_weight: "bold", cursor: "pointer"})]));
                css += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " li"].concat([ρσ_desugar_kwargs({list_style_type: "none", margin: "1rem", margin_right: "0", cursor: "pointer"})]));
                css += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " li.current"].concat([ρσ_desugar_kwargs({border_left: "solid 2px var(--calibre-color-primary)", padding_left: "2px"})]));
                css += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " li strong"].concat([ρσ_desugar_kwargs({color: "var(--calibre-color-primary)", font_style: "italic"})]));
                return css;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "read_book.search"}
            });
            return ρσ_anonfunc;
        })());
        main = worker_main;
        ρσ_modules["read_book.search"].main = main;
        ρσ_modules["read_book.search"].parse_error_msg = parse_error_msg;
        ρσ_modules["read_book.search"].get_toc_data = get_toc_data;
        ρσ_modules["read_book.search"].SearchOverlay = SearchOverlay;
    })();

    (function(){
        var __name__ = "read_book.timers";
        var THRESHOLD, FILTER_THRESHOLD, MAX_SAMPLES;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        THRESHOLD = 5;
        FILTER_THRESHOLD = 25;
        MAX_SAMPLES = 256;
        function Timers() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            Timers.prototype.__bind_methods__.call(this);
            Timers.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(Timers.prototype, "__bind_methods__", {value: function () {
            this.start_book = Timers.prototype.start_book.bind(this);
            this.set_chapter = Timers.prototype.set_chapter.bind(this);
            this.reset_read_timer = Timers.prototype.reset_read_timer.bind(this);
            this.calculate = Timers.prototype.calculate.bind(this);
            this.on_human_scroll = Timers.prototype.on_human_scroll.bind(this);
            this.time_for = Timers.prototype.time_for.bind(this);
        }});
        Timers.prototype.__init__ = function __init__() {
            var self = this;
            self.reset_read_timer();
            self.rates = [];
            self.average = self.stddev = 0;
            self.chapter_times = {};
            self.current_chapter = null;
        };
        if (!Timers.prototype.__init__.__module__) Object.defineProperties(Timers.prototype.__init__, {
            __module__ : {value: "read_book.timers"}
        });
        Timers.__argnames__ = Timers.prototype.__init__.__argnames__;
        Timers.__handles_kwarg_interpolation__ = Timers.prototype.__init__.__handles_kwarg_interpolation__;
        Timers.prototype.start_book = function start_book(book) {
            var self = this;
            self.reset_read_timer();
            self.rates = [];
            self.chapter_times = {};
            self.current_chapter = null;
            if (ρσ_exists.d((typeof book !== "undefined" && book !== null ? book : Object.create(null)).saved_reading_rates).rates) {
                self.rates = book.saved_reading_rates.rates.slice(0);
                self.calculate();
            }
            if (ρσ_exists.d((typeof book !== "undefined" && book !== null ? book : Object.create(null)).saved_reading_rates).chapter_times) {
                self.chapter_times = Object.assign({}, book.saved_reading_rates.chapter_times);
            }
        };
        if (!Timers.prototype.start_book.__argnames__) Object.defineProperties(Timers.prototype.start_book, {
            __argnames__ : {value: ["book"]},
            __module__ : {value: "read_book.timers"}
        });
        Timers.prototype.set_chapter = function set_chapter(name) {
            var self = this;
            self.current_chapter = name;
        };
        if (!Timers.prototype.set_chapter.__argnames__) Object.defineProperties(Timers.prototype.set_chapter, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "read_book.timers"}
        });
        Timers.prototype.reset_read_timer = function reset_read_timer() {
            var self = this;
            self.last_scroll_at = null;
        };
        if (!Timers.prototype.reset_read_timer.__module__) Object.defineProperties(Timers.prototype.reset_read_timer, {
            __module__ : {value: "read_book.timers"}
        });
        Timers.prototype.calculate = function calculate() {
            var self = this;
            var rates, rlen, avg, sq, x;
            rates = self.rates;
            rlen = rates.length;
            if (rlen >= THRESHOLD) {
                avg = 0;
                for (var i = 0; i < rlen; i++) {
                    avg += rates[(typeof i === "number" && i < 0) ? rates.length + i : i];
                }
                avg /= rlen;
                self.average = avg;
                sq = 0;
                for (var i = 0; i < rlen; i++) {
                    x = rates[(typeof i === "number" && i < 0) ? rates.length + i : i] - avg;
                    sq += x * x;
                }
                self.stddev = Math.sqrt(sq / (rlen - 1));
            } else {
                self.average = self.stddev = 0;
            }
        };
        if (!Timers.prototype.calculate.__module__) Object.defineProperties(Timers.prototype.calculate, {
            __module__ : {value: "read_book.timers"}
        });
        Timers.prototype.on_human_scroll = function on_human_scroll(amt_scrolled) {
            var self = this;
            var last_scroll_at, now, time_since_last_scroll, rate;
            last_scroll_at = self.last_scroll_at;
            self.last_scroll_at = now = window.performance.now();
            if (last_scroll_at === null) {
                return;
            }
            time_since_last_scroll = (now - last_scroll_at) / 1e3;
            if (time_since_last_scroll <= 0 || time_since_last_scroll >= 300) {
                return;
            }
            if (self.current_chapter) {
                (ρσ_expr_temp = self.chapter_times)[ρσ_bound_index(self.current_chapter, ρσ_expr_temp)] = ((ρσ_expr_temp = self.chapter_times)[ρσ_bound_index(self.current_chapter, ρσ_expr_temp)] || 0) + time_since_last_scroll;
            }
            if (time_since_last_scroll < 2) {
                return;
            }
            rate = amt_scrolled / time_since_last_scroll;
            if (self.rates.length >= FILTER_THRESHOLD && Math.abs(rate - self.average) > 2 * self.stddev) {
                return;
            }
            if (self.rates.length >= MAX_SAMPLES) {
                self.rates.shift();
            }
            self.rates.push(rate);
            self.calculate();
            if (ui_operations.update_reading_rates) {
                ui_operations.update_reading_rates((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["rates"] = self.rates.slice(0);
                    ρσ_d["chapter_times"] = Object.assign({}, self.chapter_times);
                    return ρσ_d;
                }).call(this));
            }
        };
        if (!Timers.prototype.on_human_scroll.__argnames__) Object.defineProperties(Timers.prototype.on_human_scroll, {
            __argnames__ : {value: ["amt_scrolled"]},
            __module__ : {value: "read_book.timers"}
        });
        Timers.prototype.time_for = function time_for(length) {
            var self = this;
            if (length >= 0 && self.rates.length >= THRESHOLD && self.average > 0) {
                return length / self.average;
            }
            return null;
        };
        if (!Timers.prototype.time_for.__argnames__) Object.defineProperties(Timers.prototype.time_for, {
            __argnames__ : {value: ["length"]},
            __module__ : {value: "read_book.timers"}
        });
        Timers.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        Timers.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(Timers.prototype, "__bases__", {value: []});

        ρσ_modules["read_book.timers"].THRESHOLD = THRESHOLD;
        ρσ_modules["read_book.timers"].FILTER_THRESHOLD = FILTER_THRESHOLD;
        ρσ_modules["read_book.timers"].MAX_SAMPLES = MAX_SAMPLES;
        ρσ_modules["read_book.timers"].Timers = Timers;
    })();

    (function(){
        var __name__ = "read_book.view";
        var E = ρσ_modules.elementmaker.E;

        var read_book = ρσ_modules.read_book;
        read_book.iframe = ρσ_modules["read_book.iframe"];

        var ajax_send = ρσ_modules.ajax.ajax_send;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;

        var update_book_in_recently_read_by_user_on_home_page = ρσ_modules["book_list.home"].update_book_in_recently_read_by_user_on_home_page;

        var cached_color_to_rgba = ρσ_modules["book_list.theme"].cached_color_to_rgba;
        var get_color = ρσ_modules["book_list.theme"].get_color;
        var set_ui_colors = ρσ_modules["book_list.theme"].set_ui_colors;

        var show_panel = ρσ_modules["book_list.ui"].show_panel;

        var add_extra_css = ρσ_modules.dom.add_extra_css;
        var build_rule = ρσ_modules.dom.build_rule;
        var clear = ρσ_modules.dom.clear;
        var set_css = ρσ_modules.dom.set_css;
        var svgicon = ρσ_modules.dom.svgicon;
        var unique_id = ρσ_modules.dom.unique_id;

        var _ = ρσ_modules.gettext.gettext;

        var create_wrapped_iframe = ρσ_modules.iframe_comm.create_wrapped_iframe;

        var error_dialog = ρσ_modules.modals.error_dialog;
        var warning_dialog = ρσ_modules.modals.warning_dialog;

        var AnnotationsManager = ρσ_modules["read_book.annotations"].AnnotationsManager;

        var create_new_bookmark = ρσ_modules["read_book.bookmarks"].create_new_bookmark;

        var ContentPopupOverlay = ρσ_modules["read_book.content_popup"].ContentPopupOverlay;

        var current_book = ρσ_modules["read_book.globals"].current_book;
        var current_spine_item = ρσ_modules["read_book.globals"].current_spine_item;
        var is_dark_theme = ρσ_modules["read_book.globals"].is_dark_theme;
        var rtl_page_progression = ρσ_modules["read_book.globals"].rtl_page_progression;
        var runtime = ρσ_modules["read_book.globals"].runtime;
        var set_current_spine_item = ρσ_modules["read_book.globals"].set_current_spine_item;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var get_next_section = ρσ_modules["read_book.goto"].get_next_section;

        var get_current_link_prefix = ρσ_modules["read_book.highlights"].get_current_link_prefix;
        var link_to_epubcfi = ρσ_modules["read_book.highlights"].link_to_epubcfi;

        var Hints = ρσ_modules["read_book.hints"].Hints;

        var add_book_to_recently_viewed = ρσ_modules["read_book.open_book"].add_book_to_recently_viewed;

        var Overlay = ρσ_modules["read_book.overlay"].Overlay;

        var resolve_color_scheme = ρσ_modules["read_book.prefs.colors"].resolve_color_scheme;

        var change_font_size_by = ρσ_modules["read_book.prefs.font_size"].change_font_size_by;
        var restore_default_font_size = ρσ_modules["read_book.prefs.font_size"].restore_default_font_size;

        var current_zoom_step_size = ρσ_modules["read_book.prefs.fonts"].current_zoom_step_size;

        var render_head_foot = ρσ_modules["read_book.prefs.head_foot"].render_head_foot;

        var SCROLL_SPEED_STEP = ρσ_modules["read_book.prefs.scrolling"].MIN_SCROLL_SPEED_AUTO;
        var change_scroll_speed = ρσ_modules["read_book.prefs.scrolling"].change_scroll_speed;

        var modify_background_image_url_for_fetch = ρσ_modules["read_book.prefs.user_stylesheet"].modify_background_image_url_for_fetch;

        var ReadAloud = ρσ_modules["read_book.read_aloud"].ReadAloud;

        var ReadAudioEbook = ρσ_modules["read_book.read_audio_ebook"].ReadAudioEbook;

        var load_resources = ρσ_modules["read_book.resources"].load_resources;

        var BookScrollbar = ρσ_modules["read_book.scrollbar"].BookScrollbar;

        var SearchOverlay = ρσ_modules["read_book.search"].SearchOverlay;

        var SelectionBar = ρσ_modules["read_book.selection_bar"].SelectionBar;

        var create_shortcut_map = ρσ_modules["read_book.shortcuts"].create_shortcut_map;

        var get_smil_audio_map = ρσ_modules["read_book.smil"].get_smil_audio_map;

        var Timers = ρσ_modules["read_book.timers"].Timers;

        var get_current_toc_nodes = ρσ_modules["read_book.toc"].get_current_toc_nodes;
        var update_visible_toc_nodes = ρσ_modules["read_book.toc"].update_visible_toc_nodes;
        var get_current_pagelist_items = ρσ_modules["read_book.toc"].get_current_pagelist_items;

        var set_left_margin_handler = ρσ_modules["read_book.touch"].set_left_margin_handler;
        var set_right_margin_handler = ρσ_modules["read_book.touch"].set_right_margin_handler;

        var get_device_uuid = ρσ_modules.session.get_device_uuid;
        var get_interface_data = ρσ_modules.session.get_interface_data;
        var all_settings = ρσ_modules.session.all_settings;

        var default_context_menu_should_be_allowed = ρσ_modules.utils.default_context_menu_should_be_allowed;
        var html_escape = ρσ_modules.utils.html_escape;
        var parse_url_params = ρσ_modules.utils.parse_url_params;
        var safe_set_inner_html = ρσ_modules.utils.safe_set_inner_html;
        var username_key = ρσ_modules.utils.username_key;

        var CHARS_PER_PAGE = ρσ_modules["viewer.constants"].CHARS_PER_PAGE;

        add_extra_css((function() {
            var ρσ_anonfunc = function () {
                var sel, ans;
                sel = ".book-side-margin";
                ans = ρσ_interpolate_kwargs.call(this, build_rule, [sel].concat([ρσ_desugar_kwargs({cursor: "pointer", text_align: "center", height: "100dvh", user_select: "none", display: "flex", align_items: "center", justify_content: "space-between", flex_direction: "column"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " > .arrow"].concat([ρσ_desugar_kwargs({display: "none"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + " > *"].concat([ρσ_desugar_kwargs({max_width: "100%", overflow: "hidden"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ":hover > .not-arrow"].concat([ρσ_desugar_kwargs({display: "none"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ":active > .not-arrow"].concat([ρσ_desugar_kwargs({display: "none"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ":hover > .arrow"].concat([ρσ_desugar_kwargs({display: "block"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [sel + ":active > .arrow"].concat([ρσ_desugar_kwargs({display: "block", transform: "scale(2)"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [".book-h-margin .visible-on-hover"].concat([ρσ_desugar_kwargs({visibility: "hidden"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [".book-h-margin:hover .visible-on-hover"].concat([ρσ_desugar_kwargs({visibility: "visible"})]));
                ans += ρσ_interpolate_kwargs.call(this, build_rule, [".book-h-margin .visible-on-hover:hover"].concat([ρσ_desugar_kwargs({color: get_color("window-hover-foreground")})]));
                return ans;
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: "read_book.view"}
            });
            return ρσ_anonfunc;
        })());
        function show_controls_help() {
            var container, div, left_msg, left_width, right_msg, right_width, left_grow, right_grow, ρσ_unpack;
            container = document.getElementById("controls-help-overlay");
            container.style.display = "block";
            container.style.backgroundColor = get_color("window-background");
            if (!show_controls_help.listener_added) {
                show_controls_help.listener_added = true;
                container.addEventListener("click", (function() {
                    var ρσ_anonfunc = function () {
                        document.getElementById("controls-help-overlay").style.display = "none";
                        ui_operations.focus_iframe();
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.view"}
                    });
                    return ρσ_anonfunc;
                })());
                container.addEventListener("contextmenu", (function() {
                    var ρσ_anonfunc = function (evt) {
                        [evt.preventDefault(), evt.stopPropagation()];
                        document.getElementById("controls-help-overlay").style.display = "none";
                        ui_operations.focus_iframe();
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["evt"]},
                        __module__ : {value: "read_book.view"}
                    });
                    return ρσ_anonfunc;
                })(), (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["passive"] = false;
                    return ρσ_d;
                }).call(this));
                container.addEventListener("keydown", (function() {
                    var ρσ_anonfunc = function (event) {
                        [event.preventDefault(), event.stopPropagation()];
                        document.getElementById("controls-help-overlay").style.display = "none";
                        ui_operations.focus_iframe();
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["event"]},
                        __module__ : {value: "read_book.view"}
                    });
                    return ρσ_anonfunc;
                })(), (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["passive"] = false;
                    return ρσ_d;
                }).call(this));
            }
            function focus() {
                if (container.style.display === "block") {
                    container.querySelector("input").focus();
                    window.setTimeout(focus, 10);
                }
            };
            if (!focus.__module__) Object.defineProperties(focus, {
                __module__ : {value: "read_book.view"}
            });

            if (runtime.is_standalone_viewer) {
                clear(container);
                container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-top: 1rem"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-top: 1rem"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-top: 1rem"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-top: 1rem"})]), ρσ_interpolate_kwargs.call(E, E.input, [ρσ_desugar_kwargs({style: "background: transparent; border-width: 0; outline: none", readonly: "readonly"})])].concat([ρσ_desugar_kwargs({style: "margin: 1rem"})])));
                div = container.lastChild.firstChild;
                safe_set_inner_html(div, _("Welcome to the <b>calibre E-book viewer</b>!"));
                div = div.nextSibling;
                safe_set_inner_html(div, _("Use the <b>PageUp/PageDn</b> or <b>Arrow keys</b> to turn pages"));
                div = div.nextSibling;
                safe_set_inner_html(div, _("Press the <b>Esc</b> key or <b>{}</b> or <b>tap on the top third</b> of the text area to show the viewer controls").format((ρσ_in("macos", window.navigator.userAgent)) ? _("control+click") : _("right click")));
                div = div.nextSibling;
                safe_set_inner_html(div, _("Press any key to continue…"));
                focus();
                return;
            }
            function msg(txt) {
                return ρσ_interpolate_kwargs.call(this, set_css, [E.div(txt)].concat([ρσ_desugar_kwargs({padding: "1ex 1em", text_align: "center", margin: "auto"})]));
            };
            if (!msg.__argnames__) Object.defineProperties(msg, {
                __argnames__ : {value: ["txt"]},
                __module__ : {value: "read_book.view"}
            });

            left_msg = msg(_("Tap to turn back"));
            left_width = "min(25vw, 1in)";
            right_msg = msg(_("Tap to turn page"));
            right_width = "auto";
            left_grow = 0;
            right_grow = 1;
            if (rtl_page_progression()) {
                ρσ_unpack = [right_msg, left_msg];
                left_msg = ρσ_unpack[0];
                right_msg = ρσ_unpack[1];
                ρσ_unpack = [right_width, left_width];
                left_width = ρσ_unpack[0];
                right_width = ρσ_unpack[1];
                ρσ_unpack = [right_grow, left_grow];
                left_grow = ρσ_unpack[0];
                right_grow = ρσ_unpack[1];
            }
            if (container.firstChild) {
                container.removeChild(container.firstChild);
            }
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [msg(_("Tap (or right click) for controls"))].concat([ρσ_desugar_kwargs({style: "height: 25dvh; display:flex; align-items: center; border-bottom: solid 2px currentColor"})])), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [left_msg].concat([ρσ_desugar_kwargs({style: "width: " + ρσ_str.format("{}", left_width) + "; flex-grow: " + ρσ_str.format("{}", left_grow) + "; display:flex; align-items: center; border-right: solid 2px currentColor"})])), ρσ_interpolate_kwargs.call(E, E.div, [right_msg].concat([ρσ_desugar_kwargs({style: "width: " + ρσ_str.format("{}", right_width) + "; display:flex; flex-grow: " + ρσ_str.format("{}", right_grow) + "; align-items: center"})]))].concat([ρσ_desugar_kwargs({style: "display: flex; align-items: stretch; flex-grow: 10"})]))].concat([ρσ_desugar_kwargs({style: "overflow: hidden; width: 100vw; height: 100dvh; text-align: center; font-size: 1.3rem; font-weight: bold; background: " + ρσ_str.format("{}", get_color("window-background")) + ";" + "display:flex; flex-direction: column; align-items: stretch"})])));
        };
        if (!show_controls_help.__module__) Object.defineProperties(show_controls_help, {
            __module__ : {value: "read_book.view"}
        });

        function body_font_size() {
            var ans, q;
            ans = body_font_size.ans;
            if (!ans || window.devicePixelRatio !== body_font_size.dpr) {
                body_font_size.dpr = window.devicePixelRatio;
                q = window.getComputedStyle(document.body).fontSize;
                if (q && q.endsWith("px")) {
                    q = parseInt(q);
                    if (q && !isNaN(q)) {
                        ans = body_font_size.ans = q;
                        return ans;
                    }
                }
                ans = body_font_size.ans = 16;
            }
            return ans;
        };
        if (!body_font_size.__module__) Object.defineProperties(body_font_size, {
            __module__ : {value: "read_book.view"}
        });

        function header_footer_font_size(sz) {
            return min(max(0, sz - 6), body_font_size());
        };
        if (!header_footer_font_size.__argnames__) Object.defineProperties(header_footer_font_size, {
            __argnames__ : {value: ["sz"]},
            __module__ : {value: "read_book.view"}
        });

        function margin_elem(sd, which, id, onclick, oncontextmenu) {
            var sz, fsz, s, ans;
            sz = sd.get(which, 20);
            fsz = header_footer_font_size(sz);
            s = "; text-overflow: ellipsis; white-space: nowrap; overflow: hidden";
            ans = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-right: 1.5em" + s})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: s})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "margin-left: 1.5em" + s})])].concat([ρσ_desugar_kwargs({style: "height:" + ρσ_str.format("{}", sz) + "px; overflow: hidden; font-size:" + ρσ_str.format("{}", fsz) + "px; width:100%; padding: 0; display: flex; justify-content: space-between; align-items: center; user-select: none; cursor: pointer", class_: "book-h-margin", id: id})]));
            if (onclick) {
                ans.addEventListener("click", onclick);
            }
            if (oncontextmenu) {
                ans.addEventListener("contextmenu", oncontextmenu);
            }
            return ans;
        };
        if (!margin_elem.__argnames__) Object.defineProperties(margin_elem, {
            __argnames__ : {value: ["sd", "which", "id", "onclick", "oncontextmenu"]},
            __module__ : {value: "read_book.view"}
        });

        function side_margin_elem(self, sd, which, icon) {
            var ans;
            ans = ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [svgicon("caret-" + ρσ_str.format("{}", icon) + "", "100%", "100%")].concat([ρσ_desugar_kwargs({class_: "arrow", style: "order: 3"})])), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "order:1"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "order:2", class_: "not-arrow"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "order:4"})])].concat([ρσ_desugar_kwargs({style: "width:{}px; user-select: none".format(sd.get("margin_" + ρσ_str.format("{}", which) + "", 20)), class_: "book-side-margin", id: "book-" + ρσ_str.format("{}", which) + "-margin", onclick: self.side_margin_clicked.bind(null, which), oncontextmenu: self.margin_context_menu.bind(null, which), onwheel: self.on_margin_wheel.bind(null, which)})]));
            return ans;
        };
        if (!side_margin_elem.__argnames__) Object.defineProperties(side_margin_elem, {
            __argnames__ : {value: ["self", "sd", "which", "icon"]},
            __module__ : {value: "read_book.view"}
        });

        function View() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            View.prototype.__bind_methods__.call(this);
            View.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(View.prototype, "__bind_methods__", {value: function () {
            this.copy_to_clipboard = View.prototype.copy_to_clipboard.bind(this);
            this.show_not_a_library_book_error = View.prototype.show_not_a_library_book_error.bind(this);
            this.copy_current_location_to_clipboard = View.prototype.copy_current_location_to_clipboard.bind(this);
            this.set_scrollbar_visibility = View.prototype.set_scrollbar_visibility.bind(this);
            this.toggle_scrollbar = View.prototype.toggle_scrollbar.bind(this);
            this.on_annotations_message = View.prototype.on_annotations_message.bind(this);
            this.on_tts_message = View.prototype.on_tts_message.bind(this);
            this.on_audio_ebook_message = View.prototype.on_audio_ebook_message.bind(this);
            this.on_hints_message = View.prototype.on_hints_message.bind(this);
            this.side_margin_clicked = View.prototype.side_margin_clicked.bind(this);
            this.top_margin_clicked = View.prototype.top_margin_clicked.bind(this);
            this.bottom_margin_clicked = View.prototype.bottom_margin_clicked.bind(this);
            this.margin_context_menu = View.prototype.margin_context_menu.bind(this);
            this.on_margin_wheel = View.prototype.on_margin_wheel.bind(this);
            this.send_wheel_event_to_iframe = View.prototype.send_wheel_event_to_iframe.bind(this);
            this.forward_gesture = View.prototype.forward_gesture.bind(this);
            this.native_gesture = View.prototype.native_gesture.bind(this);
            this.iframe_size = View.prototype.iframe_size.bind(this);
            this.on_request_size = View.prototype.on_request_size.bind(this);
            this.on_print = View.prototype.on_print.bind(this);
            this.on_human_scroll = View.prototype.on_human_scroll.bind(this);
            this.on_handle_keypress = View.prototype.on_handle_keypress.bind(this);
            this.handle_keypress = View.prototype.handle_keypress.bind(this);
            this.overlay_visibility_changed = View.prototype.overlay_visibility_changed.bind(this);
            this.on_handle_shortcut = View.prototype.on_handle_shortcut.bind(this);
            this.edit_book = View.prototype.edit_book.bind(this);
            this.on_selection_change = View.prototype.on_selection_change.bind(this);
            this.new_bookmark = View.prototype.new_bookmark.bind(this);
            this.update_selection_position = View.prototype.update_selection_position.bind(this);
            this.on_columns_per_screen_changed = View.prototype.on_columns_per_screen_changed.bind(this);
            this.switch_color_scheme = View.prototype.switch_color_scheme.bind(this);
            this.toggle_paged_mode = View.prototype.toggle_paged_mode.bind(this);
            this.toggle_autoscroll = View.prototype.toggle_autoscroll.bind(this);
            this.toggle_toolbar = View.prototype.toggle_toolbar.bind(this);
            this.on_invisible_text = View.prototype.on_invisible_text.bind(this);
            this.bump_font_size = View.prototype.bump_font_size.bind(this);
            this.on_show_footnote = View.prototype.on_show_footnote.bind(this);
            this.hide_overlays = View.prototype.hide_overlays.bind(this);
            this.focus_iframe = View.prototype.focus_iframe.bind(this);
            this.start_read_aloud = View.prototype.start_read_aloud.bind(this);
            this.toggle_read_aloud = View.prototype.toggle_read_aloud.bind(this);
            this.toggle_hints = View.prototype.toggle_hints.bind(this);
            this.show_chrome = View.prototype.show_chrome.bind(this);
            this.show_chrome_force = View.prototype.show_chrome_force.bind(this);
            this.do_show_chrome = View.prototype.do_show_chrome.bind(this);
            this.prepare_for_close = View.prototype.prepare_for_close.bind(this);
            this.show_search = View.prototype.show_search.bind(this);
            this.show_content_popup = View.prototype.show_content_popup.bind(this);
            this.set_margins = View.prototype.set_margins.bind(this);
            this.on_iframe_ready = View.prototype.on_iframe_ready.bind(this);
            this.do_pending_load = View.prototype.do_pending_load.bind(this);
            this.on_iframe_error = View.prototype.on_iframe_error.bind(this);
            this.apply_color_scheme = View.prototype.apply_color_scheme.bind(this);
            this.on_resize = View.prototype.on_resize.bind(this);
            this.show_loading_message = View.prototype.show_loading_message.bind(this);
            this.show_loading = View.prototype.show_loading.bind(this);
            this.hide_loading = View.prototype.hide_loading.bind(this);
            this.parse_cfi = View.prototype.parse_cfi.bind(this);
            this.open_book_page = View.prototype.open_book_page.bind(this);
            this.clear_book_resource_caches = View.prototype.clear_book_resource_caches.bind(this);
            this.reload_book = View.prototype.reload_book.bind(this);
            this.display_book = View.prototype.display_book.bind(this);
            this.preferences_changed = View.prototype.preferences_changed.bind(this);
            this.redisplay_book = View.prototype.redisplay_book.bind(this);
            this.iframe_settings = View.prototype.iframe_settings.bind(this);
            this.show_name = View.prototype.show_name.bind(this);
            this.load_doc = View.prototype.load_doc.bind(this);
            this.goto_doc_boundary = View.prototype.goto_doc_boundary.bind(this);
            this.goto_frac = View.prototype.goto_frac.bind(this);
            this.goto_book_position = View.prototype.goto_book_position.bind(this);
            this.goto_pagelist_item = View.prototype.goto_pagelist_item.bind(this);
            this.on_link_to_missing_activated = View.prototype.on_link_to_missing_activated.bind(this);
            this.on_scroll_to_anchor = View.prototype.on_scroll_to_anchor.bind(this);
            this.link_in_content_popup_activated = View.prototype.link_in_content_popup_activated.bind(this);
            this.goto_cfi = View.prototype.goto_cfi.bind(this);
            this.goto_reference = View.prototype.goto_reference.bind(this);
            this.goto_named_destination = View.prototype.goto_named_destination.bind(this);
            this.goto_toc_node = View.prototype.goto_toc_node.bind(this);
            this.sync_data_received = View.prototype.sync_data_received.bind(this);
            this.set_notes_for_highlight = View.prototype.set_notes_for_highlight.bind(this);
            this.add_notes_or_create_highlight = View.prototype.add_notes_or_create_highlight.bind(this);
            this.show_next_spine_item = View.prototype.show_next_spine_item.bind(this);
            this.on_next_spine_item = View.prototype.on_next_spine_item.bind(this);
            this.on_next_section = View.prototype.on_next_section.bind(this);
            this.get_current_cfi = View.prototype.get_current_cfi.bind(this);
            this.update_cfi_data = View.prototype.update_cfi_data.bind(this);
            this.on_report_cfi = View.prototype.on_report_cfi.bind(this);
            this.on_update_progress_frac = View.prototype.on_update_progress_frac.bind(this);
            this.on_update_cfi = View.prototype.on_update_cfi.bind(this);
            this.show_status_message = View.prototype.show_status_message.bind(this);
            this.upload_current_position = View.prototype.upload_current_position.bind(this);
            this.show_unsynced_indicator = View.prototype.show_unsynced_indicator.bind(this);
            this.create_template_renderer = View.prototype.create_template_renderer.bind(this);
            this.update_header_footer = View.prototype.update_header_footer.bind(this);
            this.on_update_toc_position = View.prototype.on_update_toc_position.bind(this);
            this.show_spine_item = View.prototype.show_spine_item.bind(this);
            this.show_spine_item_stage2 = View.prototype.show_spine_item_stage2.bind(this);
            this.on_content_loaded = View.prototype.on_content_loaded.bind(this);
            this.set_progress_frac = View.prototype.set_progress_frac.bind(this);
            this.update_font_size = View.prototype.update_font_size.bind(this);
            this.viewer_font_size_changed = View.prototype.viewer_font_size_changed.bind(this);
            this.update_scroll_speed = View.prototype.update_scroll_speed.bind(this);
            this.update_color_scheme = View.prototype.update_color_scheme.bind(this);
            this.toggle_reference_mode = View.prototype.toggle_reference_mode.bind(this);
            this.discover_search_result = View.prototype.discover_search_result.bind(this);
            this.handle_search_result_discovery = View.prototype.handle_search_result_discovery.bind(this);
            this.search_result_discovered = View.prototype.search_result_discovered.bind(this);
            this.search_result_not_found = View.prototype.search_result_not_found.bind(this);
            this.show_search_result = View.prototype.show_search_result.bind(this);
            this.highlight_action = View.prototype.highlight_action.bind(this);
        }});
        Object.defineProperties(View.prototype,  {
            "iframe": {
                "enumerable": true, 
                "get": function iframe() {
                    var self = this;
                    return self.iframe_wrapper.iframe;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "overlay_prevents_navigation": {
                "enumerable": true, 
                "get": function overlay_prevents_navigation() {
                    var self = this;
                    var x;
                    var ρσ_Iter0 = ρσ_Iterable(self.modal_overlays);
                    for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                        x = ρσ_Iter0[ρσ_Index0];
                        if (x.is_visible && x.prevent_navigation) {
                            return true;
                        }
                    }
                    return false;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
            "current_position_data": {
                "enumerable": true, 
                "get": function current_position_data() {
                    var self = this;
                    var book_length, name, chapter_length, pos;
                    if (ρσ_exists.d(self.book).manifest) {
                        book_length = self.book.manifest.spine_length || 0;
                        name = self.currently_showing.name;
                        chapter_length = ρσ_exists.d((ρσ_expr_temp = self.book.manifest.files)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]).length || 0;
                    } else {
                        book_length = chapter_length = 0;
                    }
                    pos = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["progress_frac"] = self.current_progress_frac;
                        ρσ_d["book_length"] = book_length;
                        ρσ_d["chapter_length"] = chapter_length;
                        ρσ_d["file_progress_frac"] = self.current_file_progress_frac;
                        ρσ_d["cfi"] = ρσ_exists.d(self.currently_showing).bookpos;
                        ρσ_d["page_counts"] = self.current_page_counts;
                        return ρσ_d;
                    }).call(this);
                    return pos;
                }, 
                "set": function () { throw new AttributeError("can't set attribute") }
            }, 
        });
        View.prototype.__init__ = function __init__(container) {
            var self = this;
            var sd, left_margin, right_margin, handlers, iframe_id, entry_point, iframe_kw, ρσ_unpack, iframe, _hl_colors;
            self.container = container;
            self.timers = new Timers;
            self.reference_mode_enabled = false;
            self.loaded_resources = Object.create(null);
            self.current_progress_frac = self.current_file_progress_frac = 0;
            self.current_page_counts = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["current"] = 0;
                ρσ_d["total"] = 0;
                ρσ_d["pages_per_screen"] = 1;
                return ρσ_d;
            }).call(this);
            self.current_status_message = "";
            self.unsynced_message = "";
            self.last_position_data = null;
            self.current_toc_node = self.current_toc_toplevel_node = null;
            self.current_toc_families = [];
            self.report_cfi_callbacks = Object.create(null);
            self.get_cfi_counter = 0;
            self.show_loading_callback_timer = null;
            self.timer_ids = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["clock"] = 0;
                return ρσ_d;
            }).call(this);
            self.book_scrollbar = new BookScrollbar(self);
            sd = get_session_data();
            self.keyboard_shortcut_map = create_shortcut_map(sd.get("keyboard_shortcuts"));
            if (ui_operations.export_shortcut_map) {
                ui_operations.export_shortcut_map(self.keyboard_shortcut_map);
            }
            left_margin = side_margin_elem(self, sd, "left", (sd.get("reverse_page_turn_zones")) ? "right" : "left");
            set_left_margin_handler(left_margin);
            right_margin = side_margin_elem(self, sd, "right", (sd.get("reverse_page_turn_zones")) ? "left" : "right");
            set_right_margin_handler(right_margin);
            handlers = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["autoscroll_state_changed"] = (function() {
                    var ρσ_anonfunc = function (data) {
                        self.autoscroll_active = !!data.running;
                        if (ui_operations.autoscroll_state_changed) {
                            ui_operations.autoscroll_state_changed(self.autoscroll_active);
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["data"]},
                        __module__ : {value: "read_book.view"}
                    });
                    return ρσ_anonfunc;
                })();
                ρσ_d["bump_font_size"] = self.bump_font_size;
                ρσ_d["content_loaded"] = self.on_content_loaded;
                ρσ_d["error"] = self.on_iframe_error;
                ρσ_d["invisible_text"] = self.on_invisible_text;
                ρσ_d["goto_doc_boundary"] = (function() {
                    var ρσ_anonfunc = function (data) {
                        self.goto_doc_boundary(data.start);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["data"]},
                        __module__ : {value: "read_book.view"}
                    });
                    return ρσ_anonfunc;
                })();
                ρσ_d["handle_keypress"] = self.on_handle_keypress;
                ρσ_d["handle_shortcut"] = self.on_handle_shortcut;
                ρσ_d["human_scroll"] = self.on_human_scroll;
                ρσ_d["next_section"] = self.on_next_section;
                ρσ_d["next_spine_item"] = self.on_next_spine_item;
                ρσ_d["print"] = self.on_print;
                ρσ_d["ready"] = self.on_iframe_ready;
                ρσ_d["report_cfi"] = self.on_report_cfi;
                ρσ_d["request_size"] = self.on_request_size;
                ρσ_d["scroll_to_anchor"] = self.on_scroll_to_anchor;
                ρσ_d["link_to_missing_activated"] = self.on_link_to_missing_activated;
                ρσ_d["selectionchange"] = self.on_selection_change;
                ρσ_d["update_selection_position"] = self.update_selection_position;
                ρσ_d["columns_per_screen_changed"] = self.on_columns_per_screen_changed;
                ρσ_d["show_chrome"] = self.show_chrome;
                ρσ_d["show_footnote"] = self.on_show_footnote;
                ρσ_d["update_cfi"] = self.on_update_cfi;
                ρσ_d["update_progress_frac"] = self.on_update_progress_frac;
                ρσ_d["update_toc_position"] = self.on_update_toc_position;
                ρσ_d["search_result_not_found"] = self.search_result_not_found;
                ρσ_d["search_result_discovered"] = self.search_result_discovered;
                ρσ_d["annotations"] = self.on_annotations_message;
                ρσ_d["tts"] = self.on_tts_message;
                ρσ_d["audio_ebook_message"] = self.on_audio_ebook_message;
                ρσ_d["hints"] = self.on_hints_message;
                ρσ_d["copy_text_to_clipboard"] = (function() {
                    var ρσ_anonfunc = function (data) {
                        ui_operations.copy_selection(data.text, data.html);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["data"]},
                        __module__ : {value: "read_book.view"}
                    });
                    return ρσ_anonfunc;
                })();
                ρσ_d["view_image"] = (function() {
                    var ρσ_anonfunc = function (data) {
                        if (ui_operations.view_image) {
                            ui_operations.view_image(data.calibre_src);
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["data"]},
                        __module__ : {value: "read_book.view"}
                    });
                    return ρσ_anonfunc;
                })();
                return ρσ_d;
            }).call(this);
            iframe_id = unique_id("read-book-iframe");
            if (runtime.is_standalone_viewer) {
                entry_point = "" + ρσ_str.format("{}", runtime.FAKE_PROTOCOL) + "://" + ρσ_str.format("{}", runtime.SANDBOX_HOST) + "/book/__index__";
            } else {
                entry_point = "read_book.iframe";
            }
            iframe_kw = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["id"] = iframe_id;
                ρσ_d["seamless"] = true;
                ρσ_d["sandbox"] = "allow-popups allow-scripts allow-popups-to-escape-sandbox";
                ρσ_d["style"] = "flex-grow: 2; width: 100%; max-width: 100%; min-width: 0; overflow: hidden;";
                ρσ_d["allowfullscreen"] = "true";
                return ρσ_d;
            }).call(this);
            ρσ_unpack = create_wrapped_iframe(handlers, _("Bootstrapping book reader..."), entry_point, iframe_kw);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            iframe = ρσ_unpack[0];
            self.iframe_wrapper = ρσ_unpack[1];
            container.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [ρσ_interpolate_kwargs.call(E, E.div, [left_margin, ρσ_interpolate_kwargs.call(E, E.div, [margin_elem(sd, "margin_top", "book-top-margin", self.top_margin_clicked, self.margin_context_menu.bind(null, "top")), iframe, margin_elem(sd, "margin_bottom", "book-bottom-margin", self.bottom_margin_clicked, self.margin_context_menu.bind(null, "bottom"))].concat([ρσ_desugar_kwargs({style: "min-width: 0; flex-grow:2; display:flex; align-items:stretch; flex-direction: column; overflow-x: hidden"})])), right_margin, self.book_scrollbar.create(), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "position: absolute; top:0; left:0; width: 100%; height: 100%; display:none;", id: "book-selection-bar-overlay"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "position: absolute; top:0; left:0; width: 100%; height: 100%; display:none;", id: "book-read-aloud-overlay"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "position: absolute; top:0; left:0; width: 100%; height: 100%; display:none;", id: "book-hints-overlay"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "position: absolute; top:0; left:0; width: 100%; height:100%; display:none", id: SearchOverlay.prototype.CONTAINER_ID})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "position: absolute; top:0; left:0; width: 100%; height: 100%; display:none", id: "book-content-popup-overlay"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "position: absolute; top:0; left:0; width: 100%; height: 100%; overflow: auto; display:none", id: "book-overlay"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "position: absolute; top:0; left:0; width: 100%; height: 100%; display:none", id: "controls-help-overlay"})]), ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({style: "position: absolute; bottom:0em; width: 100%; height: 100%; display:none", id: "audio-ebooks-overlay"})])].concat([ρσ_desugar_kwargs({style: "position: relative; max-height: 100dvh; min-width: 0; flex-grow: 2; display:flex; align-items: stretch; overflow: hidden"})]))].concat([ρσ_desugar_kwargs({style: "max-height: 100dvh; min-width: 0; display: flex; flex-direction: column; align-items: stretch; flex-grow:2"})]))].concat([ρσ_desugar_kwargs({style: "max-height: 100dvh; width: 100%; max-width: 100%; height: 100dvh; overflow: hidden; overflow-x: hidden; display: flex; align-items: stretch", oncontextmenu: (function() {
                var ρσ_anonfunc = function (ev) {
                    if (!default_context_menu_should_be_allowed(ev)) {
                        ev.preventDefault();
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: "read_book.view"}
                });
                return ρσ_anonfunc;
            })()})])));
            self.current_color_scheme = resolve_color_scheme();
            if (runtime.is_standalone_viewer) {
                document.documentElement.addEventListener("keydown", self.handle_keypress, (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["passive"] = false;
                    return ρσ_d;
                }).call(this));
                _hl_colors = all_settings.ui_highlight_colors.default;
                set_ui_colors(self.current_color_scheme.is_dark_theme, (self.current_color_scheme.is_dark_theme) ? _hl_colors.dark : _hl_colors.light);
            }
            is_dark_theme(self.current_color_scheme.is_dark_theme);
            self.search_overlay = new SearchOverlay(self);
            self.content_popup_overlay = new ContentPopupOverlay(self);
            self.overlay = new Overlay(self);
            self.selection_bar = new SelectionBar(self);
            self.read_aloud = new ReadAloud(self);
            self.read_audio_ebook = new ReadAudioEbook(self);
            self.hints = new Hints(self);
            self.modal_overlays = [self.selection_bar, self.read_aloud, self.hints, self.read_audio_ebook];
            self.processing_spine_item_display = false;
            self.pending_load = null;
            self.currently_showing = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["selection"] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["empty"] = true;
                    return ρσ_d;
                }).call(this);
                ρσ_d["on_load"] = [];
                return ρσ_d;
            }).call(this);
            self.book_scrollbar.apply_visibility();
            self.annotations_manager = new AnnotationsManager(self);
        };
        if (!View.prototype.__init__.__argnames__) Object.defineProperties(View.prototype.__init__, {
            __argnames__ : {value: ["container"]},
            __module__ : {value: "read_book.view"}
        });
        View.__argnames__ = View.prototype.__init__.__argnames__;
        View.__handles_kwarg_interpolation__ = View.prototype.__init__.__handles_kwarg_interpolation__;
        View.prototype.copy_to_clipboard = function copy_to_clipboard() {
            var self = this;
            self.iframe_wrapper.send_message("copy_selection");
        };
        if (!View.prototype.copy_to_clipboard.__module__) Object.defineProperties(View.prototype.copy_to_clipboard, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_not_a_library_book_error = function show_not_a_library_book_error() {
            var self = this;
            error_dialog(_("Not a calibre library book"), _("This book is not a part of a calibre library, so no calibre:// URL for it exists."));
        };
        if (!View.prototype.show_not_a_library_book_error.__module__) Object.defineProperties(View.prototype.show_not_a_library_book_error, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.copy_current_location_to_clipboard = function copy_current_location_to_clipboard(as_url) {
            var self = this;
            var link_prefix;
            link_prefix = get_current_link_prefix();
            if (!link_prefix && as_url) {
                return self.show_not_a_library_book_error();
            }
            self.get_current_cfi("copy-location-url", (function() {
                var ρσ_anonfunc = function (req_id, data) {
                    var text;
                    if (as_url) {
                        text = link_to_epubcfi(data.cfi, link_prefix);
                    } else {
                        text = data.cfi;
                    }
                    ui_operations.copy_selection(text);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["req_id", "data"]},
                    __module__ : {value: "read_book.view"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!View.prototype.copy_current_location_to_clipboard.__argnames__) Object.defineProperties(View.prototype.copy_current_location_to_clipboard, {
            __argnames__ : {value: ["as_url"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.set_scrollbar_visibility = function set_scrollbar_visibility(visible) {
            var self = this;
            var sd;
            sd = get_session_data();
            sd.set("book_scrollbar", bool(visible));
            self.book_scrollbar.apply_visibility();
        };
        if (!View.prototype.set_scrollbar_visibility.__argnames__) Object.defineProperties(View.prototype.set_scrollbar_visibility, {
            __argnames__ : {value: ["visible"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.toggle_scrollbar = function toggle_scrollbar() {
            var self = this;
            var sd;
            sd = get_session_data();
            self.set_scrollbar_visibility(!sd.get("book_scrollbar"));
        };
        if (!View.prototype.toggle_scrollbar.__module__) Object.defineProperties(View.prototype.toggle_scrollbar, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_annotations_message = function on_annotations_message(data) {
            var self = this;
            self.selection_bar.handle_message(data);
        };
        if (!View.prototype.on_annotations_message.__argnames__) Object.defineProperties(View.prototype.on_annotations_message, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_tts_message = function on_tts_message(data) {
            var self = this;
            self.read_aloud.handle_message(data);
        };
        if (!View.prototype.on_tts_message.__argnames__) Object.defineProperties(View.prototype.on_tts_message, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_audio_ebook_message = function on_audio_ebook_message(data) {
            var self = this;
            self.read_audio_ebook.handle_message(data);
        };
        if (!View.prototype.on_audio_ebook_message.__argnames__) Object.defineProperties(View.prototype.on_audio_ebook_message, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_hints_message = function on_hints_message(data) {
            var self = this;
            self.hints.handle_message(data);
        };
        if (!View.prototype.on_hints_message.__argnames__) Object.defineProperties(View.prototype.on_hints_message, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.side_margin_clicked = function side_margin_clicked(which, event) {
            var self = this;
            var backwards, sd;
            backwards = which === "left";
            if (get_session_data().get("reverse_page_turn_zones")) {
                backwards = !backwards;
            }
            if (event.button === 0) {
                [event.preventDefault(), event.stopPropagation()];
                sd = get_session_data();
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["next_screen"].concat([ρσ_desugar_kwargs({backwards: backwards, flip_if_rtl_page_progression: true, all_pages_on_screen: sd.get("paged_margin_clicks_scroll_by_screen")})]));
            } else if (event.button === 2) {
                [event.preventDefault(), event.stopPropagation()];
                window.setTimeout(self.show_chrome, 0);
            }
            self.focus_iframe();
        };
        if (!View.prototype.side_margin_clicked.__argnames__) Object.defineProperties(View.prototype.side_margin_clicked, {
            __argnames__ : {value: ["which", "event"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.top_margin_clicked = function top_margin_clicked(event) {
            var self = this;
            if (event.button === 0 || event.button === 2) {
                [event.preventDefault(), event.stopPropagation()];
                self.show_chrome();
            } else {
                self.focus_iframe();
            }
        };
        if (!View.prototype.top_margin_clicked.__argnames__) Object.defineProperties(View.prototype.top_margin_clicked, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.bottom_margin_clicked = function bottom_margin_clicked(event) {
            var self = this;
            if (event.button === 0 || event.button === 2) {
                [event.preventDefault(), event.stopPropagation()];
                window.setTimeout(self.show_chrome, 0);
            }
            self.focus_iframe();
        };
        if (!View.prototype.bottom_margin_clicked.__argnames__) Object.defineProperties(View.prototype.bottom_margin_clicked, {
            __argnames__ : {value: ["event"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.margin_context_menu = function margin_context_menu(which, event) {
            var self = this;
            [event.preventDefault(), event.stopPropagation()];
            self.show_chrome();
        };
        if (!View.prototype.margin_context_menu.__argnames__) Object.defineProperties(View.prototype.margin_context_menu, {
            __argnames__ : {value: ["which", "event"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_margin_wheel = function on_margin_wheel(which, event) {
            var self = this;
            event.preventDefault();
            self.send_wheel_event_to_iframe(event, "margin-" + ρσ_str.format("{}", which) + "");
        };
        if (!View.prototype.on_margin_wheel.__argnames__) Object.defineProperties(View.prototype.on_margin_wheel, {
            __argnames__ : {value: ["which", "event"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.send_wheel_event_to_iframe = function send_wheel_event_to_iframe(event, location) {
            var self = this;
            var evt, attr;
            evt = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["location"] = location;
                return ρσ_d;
            }).call(this);
            var ρσ_Iter1 = ρσ_Iterable(ρσ_list_decorate([ "deltaX", "deltaY", "deltaMode", "altKey", "ctrlKey", "shiftKey", "metaKey" ]));
            for (var ρσ_Index1 = 0; ρσ_Index1 < ρσ_Iter1.length; ρσ_Index1++) {
                attr = ρσ_Iter1[ρσ_Index1];
                evt[(typeof attr === "number" && attr < 0) ? evt.length + attr : attr] = event[(typeof attr === "number" && attr < 0) ? event.length + attr : attr];
            }
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["fake_wheel_event"].concat([ρσ_desugar_kwargs({evt: evt})]));
        };
        if (!View.prototype.send_wheel_event_to_iframe.__argnames__) Object.defineProperties(View.prototype.send_wheel_event_to_iframe, {
            __argnames__ : {value: ["event", "location"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.forward_gesture = function forward_gesture(gesture) {
            var self = this;
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["gesture_from_margin"].concat([ρσ_desugar_kwargs({gesture: gesture})]));
        };
        if (!View.prototype.forward_gesture.__argnames__) Object.defineProperties(View.prototype.forward_gesture, {
            __argnames__ : {value: ["gesture"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.native_gesture = function native_gesture(gesture) {
            var self = this;
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["native_gesture"].concat([ρσ_desugar_kwargs({gesture: gesture})]));
        };
        if (!View.prototype.native_gesture.__argnames__) Object.defineProperties(View.prototype.native_gesture, {
            __argnames__ : {value: ["gesture"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.iframe_size = function iframe_size() {
            var self = this;
            var iframe, ρσ_unpack, l, r, w, t, b, h;
            iframe = self.iframe;
            ρσ_unpack = [document.getElementById("book-left-margin"), document.getElementById("book-right-margin")];
            l = ρσ_unpack[0];
            r = ρσ_unpack[1];
            w = r.offsetLeft - l.offsetLeft - iframe.offsetLeft;
            ρσ_unpack = [document.getElementById("book-top-margin"), document.getElementById("book-bottom-margin")];
            t = ρσ_unpack[0];
            b = ρσ_unpack[1];
            h = b.offsetTop - t.offsetTop - iframe.offsetTop;
            return [w, h];
        };
        if (!View.prototype.iframe_size.__module__) Object.defineProperties(View.prototype.iframe_size, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_request_size = function on_request_size(data) {
            var self = this;
            var ρσ_unpack, w, h;
            window.scrollTo(0, 0);
            ρσ_unpack = self.iframe_size();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            w = ρσ_unpack[0];
            h = ρσ_unpack[1];
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["window_size"].concat([ρσ_desugar_kwargs({width: w, height: h})]));
        };
        if (!View.prototype.on_request_size.__argnames__) Object.defineProperties(View.prototype.on_request_size, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_print = function on_print(data) {
            var self = this;
            print(data.string);
        };
        if (!View.prototype.on_print.__argnames__) Object.defineProperties(View.prototype.on_print, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_human_scroll = function on_human_scroll(data) {
            var self = this;
            var name, length, amt_scrolled;
            if (data.scrolled_by_frac === null) {
                self.timers.reset_read_timer();
            } else {
                name = self.currently_showing.name;
                length = ρσ_exists.d((ρσ_expr_temp = self.book.manifest.files)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]).length;
                if (length) {
                    amt_scrolled = data.scrolled_by_frac * length;
                    self.timers.on_human_scroll(amt_scrolled);
                }
            }
        };
        if (!View.prototype.on_human_scroll.__argnames__) Object.defineProperties(View.prototype.on_human_scroll, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_handle_keypress = function on_handle_keypress(data) {
            var self = this;
            self.handle_keypress(data.evt);
        };
        if (!View.prototype.on_handle_keypress.__argnames__) Object.defineProperties(View.prototype.on_handle_keypress, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.handle_keypress = function handle_keypress(evt) {
            var self = this;
            if (self.overlay.is_visible && evt.key === "Escape") {
                if (self.overlay.handle_escape()) {
                    if (evt.preventDefault) {
                        [evt.preventDefault(), evt.stopPropagation()];
                    }
                }
            }
        };
        if (!View.prototype.handle_keypress.__argnames__) Object.defineProperties(View.prototype.handle_keypress, {
            __argnames__ : {value: ["evt"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.overlay_visibility_changed = function overlay_visibility_changed(visible) {
            var self = this;
            var x;
            if (self.iframe_wrapper.send_message) {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["overlay_visibility_changed"].concat([ρσ_desugar_kwargs({visible: visible})]));
            }
            if (ui_operations.overlay_visibility_changed) {
                ui_operations.overlay_visibility_changed(visible);
            }
            if (visible) {
                var ρσ_Iter2 = ρσ_Iterable(self.modal_overlays);
                for (var ρσ_Index2 = 0; ρσ_Index2 < ρσ_Iter2.length; ρσ_Index2++) {
                    x = ρσ_Iter2[ρσ_Index2];
                    x.hide();
                }
            } else {
                self.selection_bar.update_position();
            }
        };
        if (!View.prototype.overlay_visibility_changed.__argnames__) Object.defineProperties(View.prototype.overlay_visibility_changed, {
            __argnames__ : {value: ["visible"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_handle_shortcut = function on_handle_shortcut(data) {
            var self = this;
            if (!data.name) {
                return;
            }
            if (data.name === "back") {
                window.history.back();
            } else if (data.name === "forward") {
                window.history.forward();
            } else if (data.name === "show_chrome") {
                self.show_chrome();
            } else if (data.name === "show_chrome_force") {
                self.show_chrome_force();
            } else if (data.name === "toggle_toc") {
                ui_operations.toggle_toc();
            } else if (data.name === "toggle_bookmarks") {
                if (ui_operations.toggle_bookmarks) {
                    ui_operations.toggle_bookmarks();
                } else {
                    self.overlay.show_bookmarks();
                }
            } else if (data.name === "show_profiles") {
                self.overlay.show_profiles();
            } else if (data.name === "toggle_highlights") {
                ui_operations.toggle_highlights();
            } else if (data.name === "new_bookmark") {
                self.new_bookmark();
            } else if (data.name === "copy_to_clipboard") {
                self.copy_to_clipboard();
            } else if (data.name === "copy_location_to_clipboard" || data.name === "copy_location_as_url_to_clipboard") {
                self.copy_current_location_to_clipboard(ρσ_in("url", data.name));
            } else if (data.name === "toggle_inspector") {
                ui_operations.toggle_inspector();
            } else if (data.name === "toggle_lookup") {
                ui_operations.toggle_lookup();
            } else if (data.name === "toggle_full_screen") {
                ui_operations.toggle_full_screen();
            } else if (data.name === "toggle_paged_mode") {
                self.toggle_paged_mode();
            } else if (data.name === "toggle_toolbar") {
                self.toggle_toolbar();
            } else if (data.name === "toggle_scrollbar") {
                self.toggle_scrollbar();
            } else if (data.name === "quit") {
                ui_operations.quit();
            } else if (data.name === "start_search") {
                self.show_search();
            } else if (data.name === "next_match") {
                ui_operations.find_next();
            } else if (data.name === "previous_match") {
                ui_operations.find_next(true);
            } else if (data.name === "increase_font_size") {
                self.bump_font_size((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["increase"] = true;
                    return ρσ_d;
                }).call(this));
            } else if (data.name === "decrease_font_size") {
                self.bump_font_size((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["increase"] = false;
                    return ρσ_d;
                }).call(this));
            } else if (data.name === "default_font_size") {
                restore_default_font_size();
            } else if (data.name === "toggle_full_screen") {
                ui_operations.toggle_full_screen();
            } else if (data.name === "toggle_reference_mode") {
                self.toggle_reference_mode();
            } else if (data.name === "read_aloud") {
                self.start_read_aloud();
            } else if (data.name === "toggle_hints") {
                self.toggle_hints();
            } else if (data.name === "toggle_read_aloud") {
                self.toggle_read_aloud();
            } else if (data.name === "reload_book") {
                self.reload_book();
            } else if (data.name === "sync_book") {
                self.overlay.sync_book();
            } else if (data.name === "next_section") {
                self.on_next_section((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["forward"] = true;
                    return ρσ_d;
                }).call(this));
            } else if (data.name === "previous_section") {
                self.on_next_section((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["forward"] = false;
                    return ρσ_d;
                }).call(this));
            } else if (data.name === "open_book") {
                self.overlay.open_book();
            } else if (data.name === "next") {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["next_screen"].concat([ρσ_desugar_kwargs({backwards: false, flip_if_rtl_page_progression: false, all_pages_on_screen: get_session_data().get("paged_margin_clicks_scroll_by_screen")})]));
            } else if (data.name === "previous") {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["next_screen"].concat([ρσ_desugar_kwargs({backwards: true, flip_if_rtl_page_progression: false, all_pages_on_screen: get_session_data().get("paged_margin_clicks_scroll_by_screen")})]));
            } else if (data.name === "clear_selection") {
                self.iframe_wrapper.send_message("clear_selection");
            } else if (data.name === "print") {
                ui_operations.print_book();
            } else if (data.name === "preferences") {
                self.show_chrome((function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["initial_panel"] = "show_prefs";
                    return ρσ_d;
                }).call(this));
            } else if (data.name === "metadata") {
                self.overlay.show_metadata();
            } else if (data.name === "edit_book") {
                self.edit_book();
            } else if (data.name === "goto_location") {
                self.overlay.show_ask_for_location();
            } else if (data.name === "select_all") {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["modify_selection"].concat([ρσ_desugar_kwargs({granularity: "all"})]));
            } else if (data.name.startsWith("shrink_selection_by_")) {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["modify_selection"].concat([ρσ_desugar_kwargs({direction: "backward", granularity: (ρσ_expr_temp = data.name.rpartition("_"))[ρσ_expr_temp.length-1]})]));
            } else if (data.name.startsWith("extend_selection_by_")) {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["modify_selection"].concat([ρσ_desugar_kwargs({direction: "forward", granularity: (ρσ_expr_temp = data.name.rpartition("_"))[ρσ_expr_temp.length-1]})]));
            } else if (data.name === "extend_selection_to_start_of_line") {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["modify_selection"].concat([ρσ_desugar_kwargs({direction: "backward", granularity: "lineboundary"})]));
            } else if (data.name === "extend_selection_to_end_of_line") {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["modify_selection"].concat([ρσ_desugar_kwargs({direction: "forward", granularity: "lineboundary"})]));
            } else if (data.name === "scrollspeed_increase") {
                self.update_scroll_speed(SCROLL_SPEED_STEP);
            } else if (data.name === "scrollspeed_decrease") {
                self.update_scroll_speed(-SCROLL_SPEED_STEP);
            } else if (data.name === "toggle_autoscroll") {
                self.toggle_autoscroll();
            } else if (data.name.startsWith("switch_color_scheme:")) {
                self.switch_color_scheme((ρσ_expr_temp = data.name.partition(":"))[ρσ_expr_temp.length-1]);
            } else if (data.name === "increase_number_of_columns") {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["change_number_of_columns"].concat([ρσ_desugar_kwargs({delta: 1})]));
            } else if (data.name === "decrease_number_of_columns") {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["change_number_of_columns"].concat([ρσ_desugar_kwargs({delta: -1})]));
            } else if (data.name === "reset_number_of_columns") {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["change_number_of_columns"].concat([ρσ_desugar_kwargs({delta: 0})]));
            } else {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["handle_navigation_shortcut"].concat([ρσ_desugar_kwargs({name: data.name})]));
            }
        };
        if (!View.prototype.on_handle_shortcut.__argnames__) Object.defineProperties(View.prototype.on_handle_shortcut, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.edit_book = function edit_book() {
            var self = this;
            ui_operations.edit_book(current_spine_item(), self.current_file_progress_frac, ρσ_exists.d(ρσ_exists.d(self.currently_showing).selection).text);
        };
        if (!View.prototype.edit_book.__module__) Object.defineProperties(View.prototype.edit_book, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_selection_change = function on_selection_change(data) {
            var self = this;
            self.currently_showing.selection = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["text"] = data.text;
                ρσ_d["empty"] = data.empty;
                ρσ_d["start"] = data.selection_extents.start;
                ρσ_d["end"] = data.selection_extents.end;
                ρσ_d["annot_id"] = data.annot_id;
                ρσ_d["drag_mouse_position"] = data.drag_mouse_position;
                ρσ_d["selection_change_caused_by_search"] = data.selection_change_caused_by_search;
                ρσ_d["rtl"] = data.rtl;
                ρσ_d["vertical"] = data.vertical;
                ρσ_d["start_is_anchor"] = data.start_is_anchor;
                return ρσ_d;
            }).call(this);
            if (ui_operations.selection_changed) {
                ui_operations.selection_changed(self.currently_showing.selection.text, self.currently_showing.selection.annot_id);
            }
            self.selection_bar.update_position();
        };
        if (!View.prototype.on_selection_change.__argnames__) Object.defineProperties(View.prototype.on_selection_change, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.new_bookmark = function new_bookmark() {
            var self = this;
            if (ui_operations.new_bookmark) {
                self.get_current_cfi("new-bookmark", ui_operations.new_bookmark);
            } else {
                self.get_current_cfi("new-bookmark", (function() {
                    var ρσ_anonfunc = function (req_id, data) {
                        create_new_bookmark(self.annotations_manager, data);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["req_id", "data"]},
                        __module__ : {value: "read_book.view"}
                    });
                    return ρσ_anonfunc;
                })());
            }
        };
        if (!View.prototype.new_bookmark.__module__) Object.defineProperties(View.prototype.new_bookmark, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.update_selection_position = function update_selection_position(data) {
            var self = this;
            var sel;
            sel = self.currently_showing.selection;
            sel.start = data.selection_extents.start;
            sel.end = data.selection_extents.end;
            self.selection_bar.update_position();
        };
        if (!View.prototype.update_selection_position.__argnames__) Object.defineProperties(View.prototype.update_selection_position, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_columns_per_screen_changed = function on_columns_per_screen_changed(data) {
            var self = this;
            var sd, cps;
            sd = get_session_data();
            cps = sd.get("columns_per_screen") || Object.create(null);
            cps[ρσ_bound_index(data.which, cps)] = int(data.cps);
            sd.set("columns_per_screen", cps);
        };
        if (!View.prototype.on_columns_per_screen_changed.__argnames__) Object.defineProperties(View.prototype.on_columns_per_screen_changed, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.switch_color_scheme = function switch_color_scheme(name) {
            var self = this;
            get_session_data().set("current_color_scheme", name);
            ui_operations.redisplay_book();
        };
        if (!View.prototype.switch_color_scheme.__argnames__) Object.defineProperties(View.prototype.switch_color_scheme, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.toggle_paged_mode = function toggle_paged_mode() {
            var self = this;
            var sd, mode, new_mode;
            sd = get_session_data();
            mode = sd.get("read_mode");
            new_mode = (mode === "paged") ? "flow" : "paged";
            sd.set("read_mode", new_mode);
            ui_operations.redisplay_book();
        };
        if (!View.prototype.toggle_paged_mode.__module__) Object.defineProperties(View.prototype.toggle_paged_mode, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.toggle_autoscroll = function toggle_autoscroll() {
            var self = this;
            self.iframe_wrapper.send_message("toggle_autoscroll");
        };
        if (!View.prototype.toggle_autoscroll.__module__) Object.defineProperties(View.prototype.toggle_autoscroll, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.toggle_toolbar = function toggle_toolbar() {
            var self = this;
            var sd, misc;
            sd = get_session_data();
            misc = sd.get("standalone_misc_settings");
            misc.show_actions_toolbar = !misc.show_actions_toolbar;
            sd.set("standalone_misc_settings", misc);
        };
        if (!View.prototype.toggle_toolbar.__module__) Object.defineProperties(View.prototype.toggle_toolbar, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_invisible_text = function on_invisible_text(data) {
            var self = this;
            ρσ_interpolate_kwargs.call(this, warning_dialog, [_("Not found"), _("The text: <i>{}</i> is present on this page but not visible").format(html_escape(data.text))].concat([ρσ_desugar_kwargs({on_close: (function() {
                var ρσ_anonfunc = function () {
                    self.search_overlay.show();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: "read_book.view"}
                });
                return ρσ_anonfunc;
            })()})]));
        };
        if (!View.prototype.on_invisible_text.__argnames__) Object.defineProperties(View.prototype.on_invisible_text, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.bump_font_size = function bump_font_size(data) {
            var self = this;
            var mult, frac;
            mult = (data.increase) ? 1 : -1;
            frac = .2;
            if (runtime.is_standalone_viewer) {
                frac = current_zoom_step_size() / 100;
            }
            change_font_size_by(mult * frac);
        };
        if (!View.prototype.bump_font_size.__argnames__) Object.defineProperties(View.prototype.bump_font_size, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_show_footnote = function on_show_footnote(data) {
            var self = this;
            self.show_content_popup();
            self.content_popup_overlay.show_footnote(data);
        };
        if (!View.prototype.on_show_footnote.__argnames__) Object.defineProperties(View.prototype.on_show_footnote, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.hide_overlays = function hide_overlays() {
            var self = this;
            self.overlay.hide();
            self.search_overlay.hide();
            self.content_popup_overlay.hide();
            self.focus_iframe();
        };
        if (!View.prototype.hide_overlays.__module__) Object.defineProperties(View.prototype.hide_overlays, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.focus_iframe = function focus_iframe() {
            var self = this;
            var x;
            var ρσ_Iter3 = ρσ_Iterable(self.modal_overlays);
            for (var ρσ_Index3 = 0; ρσ_Index3 < ρσ_Iter3.length; ρσ_Index3++) {
                x = ρσ_Iter3[ρσ_Index3];
                if (x.is_visible) {
                    x.focus();
                    return;
                }
            }
            self.iframe.contentWindow.focus();
        };
        if (!View.prototype.focus_iframe.__module__) Object.defineProperties(View.prototype.focus_iframe, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.start_read_aloud = function start_read_aloud(dont_start_talking) {
            var self = this;
            var x;
            if (self.book.manifest.has_smil) {
                var ρσ_Iter4 = ρσ_Iterable(self.modal_overlays);
                for (var ρσ_Index4 = 0; ρσ_Index4 < ρσ_Iter4.length; ρσ_Index4++) {
                    x = ρσ_Iter4[ρσ_Index4];
                    if (x !== self.read_audio_ebook) {
                        x.hide();
                    }
                }
                self.read_audio_ebook.show();
            } else {
                var ρσ_Iter5 = ρσ_Iterable(self.modal_overlays);
                for (var ρσ_Index5 = 0; ρσ_Index5 < ρσ_Iter5.length; ρσ_Index5++) {
                    x = ρσ_Iter5[ρσ_Index5];
                    if (x !== self.read_aloud) {
                        x.hide();
                    }
                }
                self.read_aloud.show();
                if (!dont_start_talking) {
                    self.read_aloud.play();
                }
            }
        };
        if (!View.prototype.start_read_aloud.__argnames__) Object.defineProperties(View.prototype.start_read_aloud, {
            __argnames__ : {value: ["dont_start_talking"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.toggle_read_aloud = function toggle_read_aloud() {
            var self = this;
            if (self.read_audio_ebook.is_visible) {
                self.read_audio_ebook.hide();
            } else if (self.read_aloud.is_visible) {
                self.read_aloud.hide();
            } else {
                self.start_read_aloud();
            }
        };
        if (!View.prototype.toggle_read_aloud.__module__) Object.defineProperties(View.prototype.toggle_read_aloud, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.toggle_hints = function toggle_hints() {
            var self = this;
            var x;
            if (self.hints.is_visible) {
                self.hints.hide();
            } else {
                var ρσ_Iter6 = ρσ_Iterable(self.modal_overlays);
                for (var ρσ_Index6 = 0; ρσ_Index6 < ρσ_Iter6.length; ρσ_Index6++) {
                    x = ρσ_Iter6[ρσ_Index6];
                    if (x !== self.hints) {
                        x.hide();
                    }
                }
                self.hints.show();
            }
        };
        if (!View.prototype.toggle_hints.__module__) Object.defineProperties(View.prototype.toggle_hints, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_chrome = function show_chrome(data) {
            var self = this;
            var elements, initial_panel;
            if (self.content_popup_overlay.is_visible) {
                self.content_popup_overlay.hide();
                return;
            }
            self.content_popup_overlay;
            elements = Object.create(null);
            if (data && data.elements) {
                elements = data.elements;
            }
            initial_panel = (typeof data !== "undefined" && data !== null ? data : Object.create(null)).initial_panel || null;
            self.get_current_cfi("show-chrome", self.do_show_chrome.bind(null, elements, initial_panel));
        };
        if (!View.prototype.show_chrome.__argnames__) Object.defineProperties(View.prototype.show_chrome, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_chrome_force = function show_chrome_force() {
            var self = this;
            self.hide_overlays();
            self.show_chrome();
        };
        if (!View.prototype.show_chrome_force.__module__) Object.defineProperties(View.prototype.show_chrome_force, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.do_show_chrome = function do_show_chrome(elements, initial_panel, request_id, cfi_data) {
            var self = this;
            self.hide_overlays();
            self.update_cfi_data(cfi_data);
            if (initial_panel) {
                getattr(self.overlay, initial_panel)();
            } else {
                self.overlay.show(elements);
            }
        };
        if (!View.prototype.do_show_chrome.__argnames__) Object.defineProperties(View.prototype.do_show_chrome, {
            __argnames__ : {value: ["elements", "initial_panel", "request_id", "cfi_data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.prepare_for_close = function prepare_for_close() {
            var self = this;
            function close_prepared(request_id, cfi_data) {
                ui_operations.close_prep_finished(cfi_data.cfi);
            };
            if (!close_prepared.__argnames__) Object.defineProperties(close_prepared, {
                __argnames__ : {value: ["request_id", "cfi_data"]},
                __module__ : {value: "read_book.view"}
            });

            self.get_current_cfi("prepare-close", close_prepared);
        };
        if (!View.prototype.prepare_for_close.__module__) Object.defineProperties(View.prototype.prepare_for_close, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_search = function show_search(trigger) {
            var self = this;
            var text;
            self.hide_overlays();
            text = self.currently_showing.selection.text;
            if (runtime.is_standalone_viewer) {
                ui_operations.show_search(text || "", trigger);
            } else {
                if (text) {
                    self.search_overlay.set_text(text);
                }
                self.search_overlay.show(text);
                if (trigger && text) {
                    self.search_overlay.find_next();
                }
            }
        };
        if (!View.prototype.show_search.__argnames__) Object.defineProperties(View.prototype.show_search, {
            __argnames__ : {value: ["trigger"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_content_popup = function show_content_popup() {
            var self = this;
            self.hide_overlays();
            self.content_popup_overlay.show();
        };
        if (!View.prototype.show_content_popup.__module__) Object.defineProperties(View.prototype.show_content_popup, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.set_margins = function set_margins() {
            var self = this;
            var no_margins, sd, margin_left, margin_right, margin_top, margin_bottom, container_width, container_height, max_text_height, th, extra, max_text_width, tw;
            no_margins = self.currently_showing.name === self.book.manifest.title_page_name;
            sd = get_session_data();
            margin_left = (no_margins) ? 0 : sd.get("margin_left");
            margin_right = (no_margins) ? 0 : sd.get("margin_right");
            margin_top = (no_margins) ? 0 : sd.get("margin_top");
            margin_bottom = (no_margins) ? 0 : sd.get("margin_bottom");
            container_width = self.container.clientWidth || window.innerWidth;
            container_height = self.container.clientHeight || window.innerHeight;
            max_text_height = sd.get("max_text_height");
            th = container_height - margin_top - margin_bottom;
            if (!no_margins && max_text_height > 100 && th > max_text_height) {
                extra = Math.floor((th - max_text_height) / 2);
                margin_top += extra;
                margin_bottom += extra;
            }
            max_text_width = sd.get("max_text_width");
            tw = container_width - margin_left - margin_right;
            if (!no_margins && max_text_width > 100 && tw > max_text_width) {
                extra = Math.floor((tw - max_text_width) / 2);
                margin_left += extra;
                margin_right += extra;
            }
            ρσ_interpolate_kwargs.call(this, set_css, [document.getElementById("book-top-margin")].concat([ρσ_desugar_kwargs({height: margin_top + "px", font_size: header_footer_font_size(margin_top) + "px"})]));
            ρσ_interpolate_kwargs.call(this, set_css, [document.getElementById("book-bottom-margin")].concat([ρσ_desugar_kwargs({height: margin_bottom + "px", font_size: header_footer_font_size(margin_bottom) + "px"})]));
            function side_margin(which, val) {
                var m, usable_width, s;
                m = document.getElementById("book-{}-margin".format(which));
                if (which === "left") {
                    usable_width = max(0, container_width - margin_left - margin_right - self.book_scrollbar.effective_width);
                    m.nextSibling.style.maxWidth = usable_width + "px";
                }
                ρσ_interpolate_kwargs.call(this, set_css, [m].concat([ρσ_desugar_kwargs({width: val + "px"})]));
                val = min(val, 25);
                s = m.querySelector(".arrow").style;
                s.width = val + "px";
                s.height = val + "px";
            };
            if (!side_margin.__argnames__) Object.defineProperties(side_margin, {
                __argnames__ : {value: ["which", "val"]},
                __module__ : {value: "read_book.view"}
            });

            [side_margin("left", margin_left), side_margin("right", margin_right)];
        };
        if (!View.prototype.set_margins.__module__) Object.defineProperties(View.prototype.set_margins, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_iframe_ready = function on_iframe_ready(data) {
            var self = this;
            var ρσ_unpack;
            ρσ_unpack = self.iframe_size();
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            data.width = ρσ_unpack[0];
            data.height = ρσ_unpack[1];
            if (ui_operations.on_iframe_ready) {
                ui_operations.on_iframe_ready();
            }
            return self.do_pending_load;
        };
        if (!View.prototype.on_iframe_ready.__argnames__) Object.defineProperties(View.prototype.on_iframe_ready, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.do_pending_load = function do_pending_load() {
            var self = this;
            var data;
            if (self.pending_load) {
                data = self.pending_load;
                self.pending_load = null;
                self.show_spine_item_stage2(data);
            }
        };
        if (!View.prototype.do_pending_load.__module__) Object.defineProperties(View.prototype.do_pending_load, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_iframe_error = function on_iframe_error(data) {
            var self = this;
            var title, msg;
            title = data.title || _("There was an error processing the book");
            msg = _("Unknown error");
            if (data.errkey) {
                if (data.errkey === "no-auto-scroll-in-paged-mode") {
                    title = _("No auto scroll in paged mode");
                    msg = _("Switch to flow mode (Viewer preferences->Page layout) to enable auto scrolling");
                } else if (data.errkey === "changing-columns-in-flow-mode") {
                    title = _("In flow mode");
                    msg = _("Cannot change number of pages per screen in flow mode, switch to paged mode first.");
                } else if (data.errkey = "unhandled-error") {
                    title = _("Unhandled error");
                }
            }
            if (data.is_non_critical) {
                ρσ_interpolate_kwargs.call(this, warning_dialog, [title, msg, data.details].concat([ρσ_desugar_kwargs({on_close: ui_operations.focus_iframe})]));
                return;
            }
            ui_operations.show_error(title, msg, data.details);
        };
        if (!View.prototype.on_iframe_error.__argnames__) Object.defineProperties(View.prototype.on_iframe_error, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.apply_color_scheme = function apply_color_scheme() {
            var self = this;
            var ans, iframe, _hl_colors, m, s, mc, ρσ_unpack, which, sd, node, bg_image, fade, rgba, bg_image_fade, ms;
            self.current_color_scheme = ans = resolve_color_scheme();
            iframe = self.iframe;
            if (runtime.is_standalone_viewer) {
                _hl_colors = all_settings.ui_highlight_colors.default;
                set_ui_colors(self.current_color_scheme.is_dark_theme, (self.current_color_scheme.is_dark_theme) ? _hl_colors.dark : _hl_colors.light);
            } else {
                iframe.style.colorScheme = (self.current_color_scheme.is_dark_theme) ? "dark" : "light";
            }
            is_dark_theme(self.current_color_scheme.is_dark_theme);
            var ρσ_Iter7 = ρσ_Iterable("left top right bottom".split(" "));
            for (var ρσ_Index7 = 0; ρσ_Index7 < ρσ_Iter7.length; ρσ_Index7++) {
                which = ρσ_Iter7[ρσ_Index7];
                m = document.getElementById("book-{}-margin".format(which));
                s = m.style;
                mc = ans[ρσ_bound_index("margin_" + ρσ_str.format("{}", which) + "", ans)];
                if (mc) {
                    ρσ_unpack = mc.split(":");
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                    s.backgroundColor = ρσ_unpack[0];
                    s.color = ρσ_unpack[1];
                } else {
                    s.color = ans.foreground;
                    s.backgroundColor = "transparent";
                }
            }
            sd = get_session_data();
            var ρσ_Iter8 = ρσ_Iterable(ρσ_list_decorate([ iframe, iframe.parentNode ]));
            for (var ρσ_Index8 = 0; ρσ_Index8 < ρσ_Iter8.length; ρσ_Index8++) {
                node = ρσ_Iter8[ρσ_Index8];
                node.style.backgroundColor = "transparent";
                node.style.backgroundImage = "none";
            }
            s = iframe.parentNode.parentNode.style;
            bg_image = sd.get("background_image");
            if (bg_image) {
                s.backgroundImage = "url(" + ρσ_str.format("{}", modify_background_image_url_for_fetch(bg_image)) + ")";
                fade = int(sd.get("background_image_fade"));
                if (fade > 0) {
                    rgba = cached_color_to_rgba(ans.background);
                    bg_image_fade = "rgba(" + ρσ_str.format("{}", rgba[0]) + ", " + ρσ_str.format("{}", rgba[1]) + ", " + ρσ_str.format("{}", rgba[2]) + ", " + ρσ_str.format("{}", fade / 100) + ")";
                    iframe.parentNode.style.backgroundColor = bg_image_fade;
                    var ρσ_Iter9 = ρσ_Iterable("left right".split(" "));
                    for (var ρσ_Index9 = 0; ρσ_Index9 < ρσ_Iter9.length; ρσ_Index9++) {
                        which = ρσ_Iter9[ρσ_Index9];
                        ms = document.getElementById("book-" + ρσ_str.format("{}", which) + "-margin").style;
                        if (ms.backgroundColor === "transparent") {
                            ms.backgroundColor = bg_image_fade;
                        }
                    }
                }
            } else {
                s.backgroundColor = ans.background || "white";
                s.backgroundImage = "none";
            }
            if (sd.get("background_image_style") === "scaled") {
                s.backgroundSize = "100% 100%";
                s.backgroundRepeat = "no-repeat";
                s.backgroundAttachment = "scroll";
                s.backgroundPosition = "center";
            } else {
                s.backgroundSize = "auto";
                s.backgroundRepeat = "repeat";
                s.backgroundAttachment = "scroll";
                s.backgroundPosition = "0 0";
            }
            self.content_popup_overlay.apply_color_scheme(ans.background, ans.foreground);
            self.book_scrollbar.apply_color_scheme(ans);
            return ans;
        };
        if (!View.prototype.apply_color_scheme.__module__) Object.defineProperties(View.prototype.apply_color_scheme, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_resize = function on_resize() {
            var self = this;
            var sd;
            if (self.book && self.currently_showing.name) {
                sd = get_session_data();
                if (sd.get("max_text_width") || sd.get("max_text_height")) {
                    self.set_margins();
                }
            }
        };
        if (!View.prototype.on_resize.__module__) Object.defineProperties(View.prototype.on_resize, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_loading_message = function show_loading_message(msg) {
            var self = this;
            self.overlay.show_loading_message(msg);
        };
        if (!View.prototype.show_loading_message.__argnames__) Object.defineProperties(View.prototype.show_loading_message, {
            __argnames__ : {value: ["msg"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_loading = function show_loading() {
            var self = this;
            var msg;
            msg = (ρσ_expr_temp = _("Loading next section from <i>{title}</i>, please wait…"), ρσ_interpolate_kwargs.call(ρσ_expr_temp, ρσ_expr_temp.format, [ρσ_desugar_kwargs({title: self.book.metadata.title || _("Unknown")})]));
            if (self.show_loading_callback_timer !== null) {
                clearTimeout(self.show_loading_callback_timer);
            }
            self.show_loading_callback_timer = setTimeout(self.show_loading_message.bind(null, msg), 200);
        };
        if (!View.prototype.show_loading.__module__) Object.defineProperties(View.prototype.show_loading, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.hide_loading = function hide_loading() {
            var self = this;
            var q;
            if (window.read_book_initial_open_search_text) {
                q = window.read_book_initial_open_search_text;
                delete window.read_book_initial_open_search_text;
                self.search_overlay.do_initial_search(q.text, q.query);
                self.show_loading_message(_("Searching for: {}").format(q.query));
                return;
            }
            if (self.show_loading_callback_timer !== null) {
                clearTimeout(self.show_loading_callback_timer);
                self.show_loading_callback_timer = null;
            }
            self.iframe.style.visibility = "visible";
            self.overlay.hide_loading_message();
            self.focus_iframe();
        };
        if (!View.prototype.hide_loading.__module__) Object.defineProperties(View.prototype.hide_loading, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.parse_cfi = function parse_cfi(encoded_cfi, book) {
            var self = this;
            var name, cfi, ρσ_unpack, snum, rest;
            name = cfi = null;
            if (encoded_cfi && encoded_cfi.startswith("epubcfi(/")) {
                cfi = encoded_cfi.slice(len("epubcfi(/"), -1);
                ρσ_unpack = ρσ_eslice(cfi.partition("/"), 2);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
                snum = ρσ_unpack[0];
                rest = ρσ_unpack[1];
                try {
                    snum = int(snum);
                } catch (ρσ_Exception) {
                    ρσ_last_exception = ρσ_Exception;
                    if (ρσ_Exception instanceof Error) {
                        print("Invalid spine number in CFI:", snum);
                    } else {
                        throw ρσ_Exception;
                    }
                }
                if (typeof snum === "number") {
                    name = (ρσ_expr_temp = book.manifest.spine)[ρσ_bound_index(Math.floor(int(snum) / 2) - 1, ρσ_expr_temp)] || name;
                    cfi = "/" + rest;
                }
            }
            return [name, cfi];
        };
        if (!View.prototype.parse_cfi.__argnames__) Object.defineProperties(View.prototype.parse_cfi, {
            __argnames__ : {value: ["encoded_cfi", "book"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.open_book_page = function open_book_page() {
            var self = this;
            if (self.book && self.book.key) {
                ρσ_interpolate_kwargs.call(this, show_panel, ["book_details", (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["library_id"] = self.book.key[0];
                    ρσ_d["book_id"] = self.book.key[1] + "";
                    return ρσ_d;
                }).call(this)].concat([ρσ_desugar_kwargs({replace: false})]));
            }
        };
        if (!View.prototype.open_book_page.__module__) Object.defineProperties(View.prototype.open_book_page, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.clear_book_resource_caches = function clear_book_resource_caches() {
            var self = this;
            self.loaded_resources = Object.create(null);
            self.content_popup_overlay.loaded_resources = Object.create(null);
        };
        if (!View.prototype.clear_book_resource_caches.__module__) Object.defineProperties(View.prototype.clear_book_resource_caches, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.reload_book = function reload_book() {
            var self = this;
            self.clear_book_resource_caches();
            ui_operations.reload_book();
        };
        if (!View.prototype.reload_book.__module__) Object.defineProperties(View.prototype.reload_book, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.display_book = function display_book(book, initial_position, is_redisplay) {
            var self = this;
            var is_current_book, unkey, hl, pos, name, cfi, q, ρσ_unpack, cfiname, internal_cfi, navigated, sd, help_key, c;
            self.hide_overlays();
            self.iframe.focus();
            is_current_book = self.book && (self.book.key === book.key || typeof self.book.key === "object" && ρσ_equals(self.book.key, book.key));
            self.book_load_started = true;
            if (is_current_book) {
                if (!is_redisplay) {
                    self.search_overlay.clear_caches(book);
                }
            } else {
                if (self.book) {
                    self.iframe_wrapper.reset();
                    self.content_popup_overlay.reset();
                }
                self.clear_book_resource_caches();
                self.timers.start_book(book);
                self.search_overlay.clear_caches(book);
            }
            unkey = username_key(get_interface_data().username);
            self.book = current_book.book = book;
            hl = null;
            if (!is_redisplay) {
                if (self.read_audio_ebook) {
                    self.read_audio_ebook.hide();
                    clear(self.read_audio_ebook.container);
                }
                if (runtime.is_standalone_viewer) {
                    hl = book.highlights;
                    delete book.highlights;
                } else {
                    if (unkey && (ρσ_expr_temp = book.annotations_map)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey]) {
                        hl = (ρσ_expr_temp = book.annotations_map)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey].highlight;
                        self.annotations_manager.set_bookmarks((ρσ_expr_temp = book.annotations_map)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey].bookmark || []);
                    }
                }
                self.annotations_manager.set_highlights(hl || []);
                if (runtime.is_standalone_viewer) {
                    add_book_to_recently_viewed(book);
                }
            }
            if (ui_operations.update_last_read_time) {
                ui_operations.update_last_read_time(book);
            }
            pos = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["replace_history"] = true;
                return ρσ_d;
            }).call(this);
            if (!book.manifest.spine.length) {
                ui_operations.show_error(_("Invalid book"), _("This book is empty, with no items in the spine"));
                return;
            }
            name = book.manifest.spine[0];
            cfi = null;
            if (initial_position && initial_position.type === "cfi" && initial_position.data.startswith("epubcfi(/")) {
                cfi = initial_position.data;
            } else {
                q = parse_url_params();
                if (q.bookpos && q.bookpos.startswith("epubcfi(/")) {
                    cfi = q.bookpos;
                } else if (book.last_read_position && (ρσ_expr_temp = book.last_read_position)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey]) {
                    cfi = (ρσ_expr_temp = book.last_read_position)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey];
                }
            }
            ρσ_unpack = self.parse_cfi(cfi, book);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            cfiname = ρσ_unpack[0];
            internal_cfi = ρσ_unpack[1];
            if (cfiname && internal_cfi) {
                name = cfiname;
                ρσ_unpack = ["cfi", internal_cfi];
                pos.type = ρσ_unpack[0];
                pos.cfi = ρσ_unpack[1];
            }
            navigated = false;
            if (initial_position) {
                if (initial_position.type === "toc") {
                    navigated = self.goto_toc_node(initial_position.data);
                } else if (initial_position.type === "bookpos") {
                    navigated = true;
                    self.goto_book_position(initial_position.data);
                } else if (initial_position.type === "ref") {
                    navigated = self.goto_reference(initial_position.data);
                }
            }
            if (navigated) {
                self.hide_loading();
            } else {
                ρσ_interpolate_kwargs.call(self, self.show_name, [name].concat([ρσ_desugar_kwargs({initial_position: pos})]));
            }
            sd = get_session_data();
            help_key = "controls_help_shown_count" + ((rtl_page_progression()) ? "_rtl_page_progression" : "");
            if (!self[(typeof help_key === "number" && help_key < 0) ? self.length + help_key : help_key]) {
                self[(typeof help_key === "number" && help_key < 0) ? self.length + help_key : help_key] = true;
                c = sd.get(help_key, 0);
                if (c < 2) {
                    show_controls_help();
                    sd.set("controls_help_shown_count" + ((rtl_page_progression()) ? "_rtl_page_progression" : ""), c + 1);
                }
            }
        };
        if (!View.prototype.display_book.__argnames__) Object.defineProperties(View.prototype.display_book, {
            __argnames__ : {value: ["book", "initial_position", "is_redisplay"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.preferences_changed = function preferences_changed() {
            var self = this;
            self.set_margins();
            ui_operations.update_url_state(true);
            ui_operations.redisplay_book();
        };
        if (!View.prototype.preferences_changed.__module__) Object.defineProperties(View.prototype.preferences_changed, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.redisplay_book = function redisplay_book() {
            var self = this;
            var sd;
            if (!self.book) {
                if (runtime.is_standalone_viewer) {
                    self.overlay.open_book();
                }
                return;
            }
            sd = get_session_data();
            self.keyboard_shortcut_map = create_shortcut_map(sd.get("keyboard_shortcuts"));
            if (ui_operations.export_shortcut_map) {
                ui_operations.export_shortcut_map(self.keyboard_shortcut_map);
            }
            self.book_scrollbar.apply_visibility();
            self.display_book(self.book, null, true);
        };
        if (!View.prototype.redisplay_book.__module__) Object.defineProperties(View.prototype.redisplay_book, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.iframe_settings = function iframe_settings(name) {
            var self = this;
            var sd, cs;
            sd = get_session_data();
            cs = self.apply_color_scheme();
            return (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["margin_left"] = (name === self.book.manifest.title_page_name) ? 0 : sd.get("margin_left");
                ρσ_d["margin_right"] = (name === self.book.manifest.title_page_name) ? 0 : sd.get("margin_right");
                ρσ_d["margin_top"] = (name === self.book.manifest.title_page_name) ? 0 : sd.get("margin_top");
                ρσ_d["margin_bottom"] = (name === self.book.manifest.title_page_name) ? 0 : sd.get("margin_bottom");
                ρσ_d["read_mode"] = sd.get("read_mode");
                ρσ_d["columns_per_screen"] = sd.get("columns_per_screen");
                ρσ_d["color_scheme"] = cs;
                ρσ_d["override_book_colors"] = sd.get("override_book_colors");
                ρσ_d["is_dark_theme"] = cs.is_dark_theme;
                ρσ_d["base_font_size"] = sd.get("base_font_size");
                ρσ_d["user_stylesheet"] = sd.get("user_stylesheet");
                ρσ_d["keyboard_shortcuts"] = sd.get("keyboard_shortcuts");
                ρσ_d["hide_tooltips"] = sd.get("hide_tooltips");
                ρσ_d["cover_preserve_aspect_ratio"] = sd.get("cover_preserve_aspect_ratio");
                ρσ_d["paged_wheel_scrolls_by_screen"] = sd.get("paged_wheel_scrolls_by_screen");
                ρσ_d["paged_wheel_section_jumps"] = sd.get("paged_wheel_section_jumps");
                ρσ_d["paged_pixel_scroll_threshold"] = sd.get("paged_pixel_scroll_threshold");
                ρσ_d["lines_per_sec_auto"] = sd.get("lines_per_sec_auto");
                ρσ_d["lines_per_sec_smooth"] = sd.get("lines_per_sec_smooth");
                ρσ_d["scroll_auto_boundary_delay"] = sd.get("scroll_auto_boundary_delay");
                ρσ_d["scroll_mouse_boundary_delay"] = sd.get("scroll_mouse_boundary_delay");
                ρσ_d["scroll_stop_boundaries"] = sd.get("scroll_stop_boundaries");
                ρσ_d["reverse_page_turn_zones"] = sd.get("reverse_page_turn_zones");
                ρσ_d["gesture_overrides"] = sd.get("gesture_overrides");
                return ρσ_d;
            }).call(this);
        };
        if (!View.prototype.iframe_settings.__argnames__) Object.defineProperties(View.prototype.iframe_settings, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_name = function show_name() {
            var self = this;
            var name = ( 0 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true) ? undefined : arguments[0];
            var initial_position = (arguments[1] === undefined || ( 1 === arguments.length-1 && arguments[arguments.length-1] !== null && typeof arguments[arguments.length-1] === "object" && arguments[arguments.length-1] [ρσ_kwargs_symbol] === true)) ? show_name.__defaults__.initial_position : arguments[1];
            var ρσ_kwargs_obj = arguments[arguments.length-1];
            if (ρσ_kwargs_obj === null || typeof ρσ_kwargs_obj !== "object" || ρσ_kwargs_obj [ρσ_kwargs_symbol] !== true) ρσ_kwargs_obj = {};
            if (Object.prototype.hasOwnProperty.call(ρσ_kwargs_obj, "initial_position")){
                initial_position = ρσ_kwargs_obj.initial_position;
            }
            var spine, idx;
            if (self.currently_showing.loading) {
                return;
            }
            self.processing_spine_item_display = false;
            initial_position = initial_position || (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["replace_history"] = false;
                return ρσ_d;
            }).call(this);
            spine = self.book.manifest.spine;
            idx = spine.indexOf(name);
            self.currently_showing = (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["name"] = name;
                ρσ_d["settings"] = self.iframe_settings(name);
                ρσ_d["initial_position"] = initial_position;
                ρσ_d["loading"] = true;
                ρσ_d["spine_index"] = idx;
                ρσ_d["selection"] = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["empty"] = true;
                    return ρσ_d;
                }).call(this);
                ρσ_d["on_load"] = [];
                return ρσ_d;
            }).call(this);
            self.timers.set_chapter(name);
            self.show_loading();
            set_current_spine_item(name);
            if (idx > -1) {
                self.currently_showing.bookpos = "epubcfi(/{})".format(2 * (idx + 1));
            }
            self.set_margins();
            self.load_doc(name, self.show_spine_item);
        };
        if (!View.prototype.show_name.__defaults__) Object.defineProperties(View.prototype.show_name, {
            __defaults__ : {value: {initial_position:null}},
            __handles_kwarg_interpolation__ : {value: true},
            __argnames__ : {value: ["name", "initial_position"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.load_doc = function load_doc(name, done_callback) {
            var self = this;
            function cb(resource_data) {
                self.loaded_resources = resource_data;
                done_callback(resource_data);
            };
            if (!cb.__argnames__) Object.defineProperties(cb, {
                __argnames__ : {value: ["resource_data"]},
                __module__ : {value: "read_book.view"}
            });

            load_resources(self.book, name, self.loaded_resources, cb);
        };
        if (!View.prototype.load_doc.__argnames__) Object.defineProperties(View.prototype.load_doc, {
            __argnames__ : {value: ["name", "done_callback"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.goto_doc_boundary = function goto_doc_boundary(start) {
            var self = this;
            var name;
            name = (ρσ_expr_temp = self.book.manifest.spine)[ρσ_bound_index((start) ? 0 : self.book.manifest.spine.length - 1, ρσ_expr_temp)];
            ρσ_interpolate_kwargs.call(self, self.show_name, [name].concat([ρσ_desugar_kwargs({initial_position: (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "frac";
                ρσ_d["frac"] = (start) ? 0 : 1;
                ρσ_d["replace_history"] = false;
                return ρσ_d;
            }).call(this)})]));
        };
        if (!View.prototype.goto_doc_boundary.__argnames__) Object.defineProperties(View.prototype.goto_doc_boundary, {
            __argnames__ : {value: ["start"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.goto_frac = function goto_frac(frac) {
            var self = this;
            var chapter_start_page, total_length, page, chapter_frac, chapter_name, chapter_length, chapter_end_page, num_pages, name;
            if (!self.book || !self.book.manifest) {
                return;
            }
            chapter_start_page = 0;
            total_length = self.book.manifest.spine_length;
            page = total_length * frac;
            chapter_frac = 0;
            chapter_name = null;
            var ρσ_Iter10 = ρσ_Iterable(self.book.manifest.spine);
            for (var ρσ_Index10 = 0; ρσ_Index10 < ρσ_Iter10.length; ρσ_Index10++) {
                name = ρσ_Iter10[ρσ_Index10];
                chapter_length = ρσ_exists.d((ρσ_expr_temp = self.book.manifest.files)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name]).length || 0;
                chapter_end_page = chapter_start_page + chapter_length;
                if (chapter_start_page <= page && page <= chapter_end_page) {
                    num_pages = chapter_end_page - chapter_start_page - 1;
                    if (num_pages > 0) {
                        chapter_frac = (page - chapter_start_page) / num_pages;
                    } else {
                        chapter_frac = 0;
                    }
                    chapter_name = name;
                    break;
                }
                chapter_start_page = chapter_end_page;
            }
            if (!chapter_name) {
                chapter_name = (ρσ_expr_temp = self.book.manifest.spine)[ρσ_expr_temp.length-1];
            }
            chapter_frac = max(0, min(chapter_frac, 1));
            if (self.currently_showing.name === chapter_name) {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["scroll_to_frac"].concat([ρσ_desugar_kwargs({frac: chapter_frac})]));
            } else {
                ρσ_interpolate_kwargs.call(self, self.show_name, [chapter_name].concat([ρσ_desugar_kwargs({initial_position: (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "frac";
                    ρσ_d["frac"] = chapter_frac;
                    ρσ_d["replace_history"] = true;
                    return ρσ_d;
                }).call(this)})]));
            }
        };
        if (!View.prototype.goto_frac.__argnames__) Object.defineProperties(View.prototype.goto_frac, {
            __argnames__ : {value: ["frac"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.goto_book_position = function goto_book_position(bpos) {
            var self = this;
            var pages, val;
            pages = Math.ceil(self.current_position_data.book_length / CHARS_PER_PAGE);
            val = max(0, min(float(bpos) / pages, 1));
            return self.goto_frac(val);
        };
        if (!View.prototype.goto_book_position.__argnames__) Object.defineProperties(View.prototype.goto_book_position, {
            __argnames__ : {value: ["bpos"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.goto_pagelist_item = function goto_pagelist_item(item) {
            var self = this;
            var name, frag;
            name = item.dest;
            frag = item.frag || "";
            ρσ_interpolate_kwargs.call(self, self.show_name, [name].concat([ρσ_desugar_kwargs({initial_position: (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "pagelist_ref";
                ρσ_d["anchor"] = frag;
                ρσ_d["replace_history"] = false;
                return ρσ_d;
            }).call(this)})]));
        };
        if (!View.prototype.goto_pagelist_item.__argnames__) Object.defineProperties(View.prototype.goto_pagelist_item, {
            __argnames__ : {value: ["item"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_link_to_missing_activated = function on_link_to_missing_activated(data) {
            var self = this;
            ui_operations.show_error(_("Invalid link"), _("This link points to the file {} which does not exist in the book").format(data.name));
        };
        if (!View.prototype.on_link_to_missing_activated.__argnames__) Object.defineProperties(View.prototype.on_link_to_missing_activated, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_scroll_to_anchor = function on_scroll_to_anchor(data) {
            var self = this;
            ρσ_interpolate_kwargs.call(self, self.show_name, [data.name].concat([ρσ_desugar_kwargs({initial_position: (function(){
                var ρσ_d = Object.create(null);
                ρσ_d["type"] = "anchor";
                ρσ_d["anchor"] = data.frag;
                ρσ_d["replace_history"] = false;
                return ρσ_d;
            }).call(this)})]));
        };
        if (!View.prototype.on_scroll_to_anchor.__argnames__) Object.defineProperties(View.prototype.on_scroll_to_anchor, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.link_in_content_popup_activated = function link_in_content_popup_activated(name, frag, is_popup, title) {
            var self = this;
            self.content_popup_overlay.hide();
            if (is_popup) {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["fake_popup_activation"].concat([ρσ_desugar_kwargs({name: name, frag: frag, title: title})]));
            } else {
                self.goto_named_destination(name, frag);
            }
        };
        if (!View.prototype.link_in_content_popup_activated.__argnames__) Object.defineProperties(View.prototype.link_in_content_popup_activated, {
            __argnames__ : {value: ["name", "frag", "is_popup", "title"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.goto_cfi = function goto_cfi(bookpos, add_to_history) {
            var self = this;
            var ρσ_unpack, cfiname, internal_cfi, pos, name;
            ρσ_unpack = self.parse_cfi(bookpos, self.book);
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            cfiname = ρσ_unpack[0];
            internal_cfi = ρσ_unpack[1];
            if (cfiname && internal_cfi) {
                pos = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["replace_history"] = !add_to_history;
                    return ρσ_d;
                }).call(this);
                name = cfiname;
                ρσ_unpack = ["cfi", internal_cfi];
                pos.type = ρσ_unpack[0];
                pos.cfi = ρσ_unpack[1];
                ρσ_interpolate_kwargs.call(self, self.show_name, [name].concat([ρσ_desugar_kwargs({initial_position: pos})]));
                return true;
            }
            return false;
        };
        if (!View.prototype.goto_cfi.__argnames__) Object.defineProperties(View.prototype.goto_cfi, {
            __argnames__ : {value: ["bookpos", "add_to_history"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.goto_reference = function goto_reference(reference) {
            var self = this;
            var ρσ_unpack, index, refnum, chapter_name;
            if (!self.book || !self.book.manifest) {
                return;
            }
            ρσ_unpack = reference.split(".");
ρσ_unpack = ρσ_unpack_asarray(2, ρσ_unpack);
            index = ρσ_unpack[0];
            refnum = ρσ_unpack[1];
            ρσ_unpack = [int(index), (refnum) ? int(refnum) : 1];
            index = ρσ_unpack[0];
            refnum = ρσ_unpack[1];
            chapter_name = (ρσ_expr_temp = self.book.manifest.spine)[(typeof index === "number" && index < 0) ? ρσ_expr_temp.length + index : index];
            if (!chapter_name) {
                return false;
            }
            if (self.currently_showing.name === chapter_name) {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["scroll_to_ref"].concat([ρσ_desugar_kwargs({refnum: refnum})]));
            } else {
                ρσ_interpolate_kwargs.call(self, self.show_name, [chapter_name].concat([ρσ_desugar_kwargs({initial_position: (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "ref";
                    ρσ_d["refnum"] = refnum;
                    ρσ_d["replace_history"] = true;
                    return ρσ_d;
                }).call(this)})]));
            }
            return true;
        };
        if (!View.prototype.goto_reference.__argnames__) Object.defineProperties(View.prototype.goto_reference, {
            __argnames__ : {value: ["reference"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.goto_named_destination = function goto_named_destination(name, frag) {
            var self = this;
            var spine, idx;
            if (self.currently_showing.name === name) {
                ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["scroll_to_anchor"].concat([ρσ_desugar_kwargs({frag: frag})]));
            } else {
                spine = self.book.manifest.spine;
                idx = spine.indexOf(name);
                if (idx === -1) {
                    ρσ_interpolate_kwargs.call(this, error_dialog, [_("Destination does not exist"), _("The file {} does not exist in this book").format(name)].concat([ρσ_desugar_kwargs({on_close: (function() {
                        var ρσ_anonfunc = function () {
                            ui_operations.focus_iframe();
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: "read_book.view"}
                        });
                        return ρσ_anonfunc;
                    })()})]));
                    return false;
                }
                ρσ_interpolate_kwargs.call(self, self.show_name, [name].concat([ρσ_desugar_kwargs({initial_position: (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "anchor";
                    ρσ_d["anchor"] = frag;
                    ρσ_d["replace_history"] = false;
                    return ρσ_d;
                }).call(this)})]));
            }
            return true;
        };
        if (!View.prototype.goto_named_destination.__argnames__) Object.defineProperties(View.prototype.goto_named_destination, {
            __argnames__ : {value: ["name", "frag"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.goto_toc_node = function goto_toc_node(node_id) {
            var self = this;
            var toc, found;
            if (self.overlay_prevents_navigation) {
                return;
            }
            toc = self.book.manifest.toc;
            found = false;
            function process_node(x) {
                var c;
                if (x.id === node_id) {
                    self.goto_named_destination(x.dest || "", x.frag || "");
                    found = true;
                    return;
                }
                var ρσ_Iter11 = ρσ_Iterable(x.children);
                for (var ρσ_Index11 = 0; ρσ_Index11 < ρσ_Iter11.length; ρσ_Index11++) {
                    c = ρσ_Iter11[ρσ_Index11];
                    process_node(c);
                }
            };
            if (!process_node.__argnames__) Object.defineProperties(process_node, {
                __argnames__ : {value: ["x"]},
                __module__ : {value: "read_book.view"}
            });

            if (toc) {
                process_node(toc);
            }
            return found;
        };
        if (!View.prototype.goto_toc_node.__argnames__) Object.defineProperties(View.prototype.goto_toc_node, {
            __argnames__ : {value: ["node_id"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.sync_data_received = function sync_data_received(reading_pos_cfi, annotations_map) {
            var self = this;
            var hl;
            if (annotations_map) {
                ui_operations.annotations_synced(annotations_map);
                if (annotations_map.highlight) {
                    if (self.annotations_manager.merge_highlights(annotations_map.highlight)) {
                        hl = self.annotations_manager.highlights_for_currently_showing();
                        ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["replace_highlights"].concat([ρσ_desugar_kwargs({highlights: hl})]));
                    }
                }
            }
            if (reading_pos_cfi) {
                self.goto_cfi(reading_pos_cfi);
            }
        };
        if (!View.prototype.sync_data_received.__argnames__) Object.defineProperties(View.prototype.sync_data_received, {
            __argnames__ : {value: ["reading_pos_cfi", "annotations_map"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.set_notes_for_highlight = function set_notes_for_highlight(uuid, notes) {
            var self = this;
            if (self.annotations_manager.set_notes_for_highlight(uuid, notes)) {
                self.selection_bar.notes_edited(uuid);
                self.selection_bar.update_position();
            }
        };
        if (!View.prototype.set_notes_for_highlight.__argnames__) Object.defineProperties(View.prototype.set_notes_for_highlight, {
            __argnames__ : {value: ["uuid", "notes"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.add_notes_or_create_highlight = function add_notes_or_create_highlight(notes, style) {
            var self = this;
            if (self.selection_bar.is_visible) {
                return self.selection_bar.add_notes_or_create_highlight(notes, style);
            }
            self.show_error(_("No selection"), _("Cannot create highlight as there is no active selection"));
        };
        if (!View.prototype.add_notes_or_create_highlight.__argnames__) Object.defineProperties(View.prototype.add_notes_or_create_highlight, {
            __argnames__ : {value: ["notes", "style"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_next_spine_item = function show_next_spine_item(previous) {
            var self = this;
            var spine, idx;
            spine = self.book.manifest.spine;
            idx = spine.indexOf(self.currently_showing.name);
            if (previous) {
                if (idx === 0) {
                    return false;
                }
                idx = min(spine.length - 1, max(idx - 1, 0));
                ρσ_interpolate_kwargs.call(self, self.show_name, [spine[(typeof idx === "number" && idx < 0) ? spine.length + idx : idx]].concat([ρσ_desugar_kwargs({initial_position: (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "frac";
                    ρσ_d["frac"] = 1;
                    ρσ_d["replace_history"] = true;
                    return ρσ_d;
                }).call(this)})]));
            } else {
                if (idx === spine.length - 1) {
                    return false;
                }
                idx = max(0, min(spine.length - 1, idx + 1));
                ρσ_interpolate_kwargs.call(self, self.show_name, [spine[(typeof idx === "number" && idx < 0) ? spine.length + idx : idx]].concat([ρσ_desugar_kwargs({initial_position: (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "frac";
                    ρσ_d["frac"] = 0;
                    ρσ_d["replace_history"] = true;
                    return ρσ_d;
                }).call(this)})]));
            }
            return true;
        };
        if (!View.prototype.show_next_spine_item.__argnames__) Object.defineProperties(View.prototype.show_next_spine_item, {
            __argnames__ : {value: ["previous"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_next_spine_item = function on_next_spine_item(data) {
            var self = this;
            self.show_next_spine_item(data.previous);
        };
        if (!View.prototype.on_next_spine_item.__argnames__) Object.defineProperties(View.prototype.on_next_spine_item, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_next_section = function on_next_section(data) {
            var self = this;
            var toc_node;
            toc_node = get_next_section(data.forward);
            if (toc_node) {
                self.goto_named_destination(toc_node.dest, toc_node.frag);
            }
        };
        if (!View.prototype.on_next_section.__argnames__) Object.defineProperties(View.prototype.on_next_section, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.get_current_cfi = function get_current_cfi(request_id, callback) {
            var self = this;
            self.get_cfi_counter += 1;
            request_id += ":" + self.get_cfi_counter;
            (ρσ_expr_temp = self.report_cfi_callbacks)[(typeof request_id === "number" && request_id < 0) ? ρσ_expr_temp.length + request_id : request_id] = callback;
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["get_current_cfi"].concat([ρσ_desugar_kwargs({request_id: request_id})]));
        };
        if (!View.prototype.get_current_cfi.__argnames__) Object.defineProperties(View.prototype.get_current_cfi, {
            __argnames__ : {value: ["request_id", "callback"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.update_cfi_data = function update_cfi_data(data) {
            var self = this;
            var username, unkey;
            if (ui_operations.update_last_read_position) {
                ui_operations.update_last_read_position(data.cfi, data.progress_frac);
            }
            username = get_interface_data().username;
            if (self.book) {
                self.currently_showing.bookpos = data.cfi;
                unkey = username_key(username);
                if (!self.book.last_read_position) {
                    self.book.last_read_position = Object.create(null);
                }
                (ρσ_expr_temp = self.book.last_read_position)[(typeof unkey === "number" && unkey < 0) ? ρσ_expr_temp.length + unkey : unkey] = data.cfi;
                self.set_progress_frac(data.progress_frac, data.file_progress_frac, data.page_counts);
                self.update_header_footer();
                if (ui_operations.update_last_read_time) {
                    ui_operations.update_last_read_time(self.book);
                }
            }
            return username;
        };
        if (!View.prototype.update_cfi_data.__argnames__) Object.defineProperties(View.prototype.update_cfi_data, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_report_cfi = function on_report_cfi(data) {
            var self = this;
            var cb;
            cb = (ρσ_expr_temp = self.report_cfi_callbacks)[ρσ_bound_index(data.request_id, ρσ_expr_temp)];
            if (cb) {
                cb(data.request_id.rpartition(":")[0], (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["cfi"] = data.cfi;
                    ρσ_d["progress_frac"] = data.progress_frac;
                    ρσ_d["file_progress_frac"] = data.file_progress_frac;
                    ρσ_d["selected_text"] = data.selected_text;
                    ρσ_d["selection_bounds"] = data.selection_bounds;
                    ρσ_d["page_counts"] = data.page_counts;
                    return ρσ_d;
                }).call(this));
                delete self.report_cfi_callbacks[data.request_id];
            }
        };
        if (!View.prototype.on_report_cfi.__argnames__) Object.defineProperties(View.prototype.on_report_cfi, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_update_progress_frac = function on_update_progress_frac(data) {
            var self = this;
            self.set_progress_frac(data.progress_frac, data.file_progress_frac, data.page_counts);
            self.update_header_footer();
        };
        if (!View.prototype.on_update_progress_frac.__argnames__) Object.defineProperties(View.prototype.on_update_progress_frac, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_update_cfi = function on_update_cfi(data) {
            var self = this;
            var overlay_shown, username, key, lrd;
            overlay_shown = !self.processing_spine_item_display && self.overlay.is_visible;
            if (overlay_shown || self.search_overlay.is_visible || self.content_popup_overlay.is_visible) {
                return;
            }
            username = self.update_cfi_data(data);
            ui_operations.update_url_state(data.replace_history);
            if (username) {
                key = self.book.key;
                lrd = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["device"] = get_device_uuid();
                    ρσ_d["cfi"] = data.cfi;
                    ρσ_d["pos_frac"] = data.progress_frac;
                    return ρσ_d;
                }).call(this);
                self.last_position_data = lrd;
                ajax_send(ρσ_interpolate_kwargs.call("book-set-last-read-position/{library_id}/{book_id}/{fmt}", "book-set-last-read-position/{library_id}/{book_id}/{fmt}".format, [ρσ_desugar_kwargs({library_id: key[0], book_id: key[1], fmt: key[2]})]), lrd, (function() {
                    var ρσ_anonfunc = function (end_type, xhr, ev) {
                        if (end_type !== "load") {
                            print("Failed to update last read position, AJAX call did not succeed");
                        }
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["end_type", "xhr", "ev"]},
                        __module__ : {value: "read_book.view"}
                    });
                    return ρσ_anonfunc;
                })());
                update_book_in_recently_read_by_user_on_home_page(key[0], key[1], key[2], data.cfi);
            }
        };
        if (!View.prototype.on_update_cfi.__argnames__) Object.defineProperties(View.prototype.on_update_cfi, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_status_message = function show_status_message(msg, timeout) {
            var self = this;
            self.current_status_message = msg || "";
            self.update_header_footer();
            if (self.current_status_message) {
                if (!(typeof timeout !== "undefined" && timeout !== null)) {
                    timeout = 1e4;
                }
                window.setTimeout((function() {
                    var ρσ_anonfunc = function () {
                        self.show_status_message();
                    };
                    if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                        __module__ : {value: "read_book.view"}
                    });
                    return ρσ_anonfunc;
                })(), timeout);
            }
        };
        if (!View.prototype.show_status_message.__argnames__) Object.defineProperties(View.prototype.show_status_message, {
            __argnames__ : {value: ["msg", "timeout"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.upload_current_position = function upload_current_position(callback) {
            var self = this;
            var key;
            if (!self.last_position_data || !self.book) {
                callback(true);
                return;
            }
            key = self.book.key;
            ajax_send(ρσ_interpolate_kwargs.call("book-set-last-read-position/{library_id}/{book_id}/{fmt}", "book-set-last-read-position/{library_id}/{book_id}/{fmt}".format, [ρσ_desugar_kwargs({library_id: key[0], book_id: key[1], fmt: key[2]})]), self.last_position_data, (function() {
                var ρσ_anonfunc = function (end_type, xhr, ev) {
                    callback(end_type === "load");
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["end_type", "xhr", "ev"]},
                    __module__ : {value: "read_book.view"}
                });
                return ρσ_anonfunc;
            })());
        };
        if (!View.prototype.upload_current_position.__argnames__) Object.defineProperties(View.prototype.upload_current_position, {
            __argnames__ : {value: ["callback"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_unsynced_indicator = function show_unsynced_indicator(visible) {
            var self = this;
            self.unsynced_message = (visible) ? _("Unsynced changes") : "";
            self.update_header_footer();
        };
        if (!View.prototype.show_unsynced_indicator.__argnames__) Object.defineProperties(View.prototype.show_unsynced_indicator, {
            __argnames__ : {value: ["visible"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.create_template_renderer = function create_template_renderer() {
            var self = this;
            var pos, book_length, chapter_length, book_time, chapter_time, mi, sd, view_mode;
            if (!self.book) {
                return;
            }
            pos = self.current_position_data;
            book_length = pos.book_length * max(0, 1 - pos.progress_frac);
            chapter_length = pos.chapter_length * max(0, 1 - pos.file_progress_frac);
            book_time = self.timers.time_for(book_length);
            chapter_time = self.timers.time_for(chapter_length);
            mi = self.book.metadata;
            sd = get_session_data();
            view_mode = sd.get("read_mode");
            function render(div, name, which, override) {
                return render_head_foot(div, name, which, mi, self.current_toc_node, self.current_toc_toplevel_node, self.current_pagelist_items, book_time, chapter_time, pos, override, view_mode);
            };
            if (!render.__argnames__) Object.defineProperties(render, {
                __argnames__ : {value: ["div", "name", "which", "override"]},
                __module__ : {value: "read_book.view"}
            });

            return render;
        };
        if (!View.prototype.create_template_renderer.__module__) Object.defineProperties(View.prototype.create_template_renderer, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.update_header_footer = function update_header_footer() {
            var self = this;
            var renderer, sd, has_clock, div, tname, edge;
            renderer = self.create_template_renderer();
            if (!renderer) {
                return;
            }
            sd = get_session_data();
            has_clock = false;
            function render_template(div, edge, name) {
                var c, b, a, override, hca, hcb, hcc;
                c = div.lastChild;
                b = c.previousSibling;
                a = b.previousSibling;
                if (sd.get("margin_" + ρσ_str.format("{}", edge) + "", 20) > 5) {
                    override = (edge === "bottom") ? self.current_status_message || self.unsynced_message : "";
                    hca = renderer(a, name, "left", override);
                    hcb = renderer(b, name, "middle", "");
                    hcc = renderer(c, name, "right", "");
                    if (hca || hcb || hcc) {
                        has_clock = true;
                    }
                } else {
                    [clear(a), clear(b), clear(c)];
                }
            };
            if (!render_template.__argnames__) Object.defineProperties(render_template, {
                __argnames__ : {value: ["div", "edge", "name"]},
                __module__ : {value: "read_book.view"}
            });

            var ρσ_Iter12 = ρσ_Iterable(ρσ_list_decorate([ "left", "right", "top", "bottom" ]));
            for (var ρσ_Index12 = 0; ρσ_Index12 < ρσ_Iter12.length; ρσ_Index12++) {
                edge = ρσ_Iter12[ρσ_Index12];
                div = document.getElementById("book-" + ρσ_str.format("{}", edge) + "-margin");
                if (div) {
                    tname = (ρσ_expr_temp = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["left"] = "left-margin";
                        ρσ_d["right"] = "right-margin";
                        ρσ_d["top"] = "header";
                        ρσ_d["bottom"] = "footer";
                        return ρσ_d;
                    }).call(this))[(typeof edge === "number" && edge < 0) ? ρσ_expr_temp.length + edge : edge];
                    render_template(div, edge, tname);
                }
            }
            if (has_clock) {
                if (!self.timer_ids.clock) {
                    self.timer_ids.clock = window.setInterval(self.update_header_footer, 6e4);
                }
            } else {
                if (self.timer_ids.clock) {
                    window.clearInterval(self.timer_ids.clock);
                    self.timer_ids.clock = 0;
                }
            }
        };
        if (!View.prototype.update_header_footer.__module__) Object.defineProperties(View.prototype.update_header_footer, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_update_toc_position = function on_update_toc_position(data) {
            var self = this;
            var first, r, fam;
            update_visible_toc_nodes(data.visible_anchors);
            self.current_toc_families = get_current_toc_nodes();
            self.current_pagelist_items = get_current_pagelist_items();
            if (self.current_toc_families.length) {
                first = self.current_toc_families[0];
                self.current_toc_node = first[first.length-1];
                self.current_toc_toplevel_node = first[0];
            } else {
                self.current_toc_node = self.current_toc_toplevel_node = null;
            }
            if (runtime.is_standalone_viewer) {
                r = [];
                var ρσ_Iter13 = ρσ_Iterable(self.current_toc_families);
                for (var ρσ_Index13 = 0; ρσ_Index13 < ρσ_Iter13.length; ρσ_Index13++) {
                    fam = ρσ_Iter13[ρσ_Index13];
                    if (fam.length) {
                        r.push(fam[fam.length-1].id);
                    }
                }
                ui_operations.update_current_toc_nodes(r);
            }
            self.update_header_footer();
        };
        if (!View.prototype.on_update_toc_position.__argnames__) Object.defineProperties(View.prototype.on_update_toc_position, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_spine_item = function show_spine_item(resource_data) {
            var self = this;
            self.pending_load = resource_data;
            if (self.iframe_wrapper.ready) {
                self.do_pending_load();
            } else {
                self.iframe_wrapper.init();
            }
        };
        if (!View.prototype.show_spine_item.__argnames__) Object.defineProperties(View.prototype.show_spine_item, {
            __argnames__ : {value: ["resource_data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_spine_item_stage2 = function show_spine_item_stage2(resource_data) {
            var self = this;
            var fdata, smil_map;
            self.processing_spine_item_display = true;
            self.current_status_message = "";
            self.iframe.style.visibility = "hidden";
            fdata = (ρσ_expr_temp = self.book.manifest.files)[ρσ_bound_index(self.currently_showing.name, ρσ_expr_temp)];
            smil_map = null;
            if (self.book.manifest.has_smil && fdata) {
                smil_map = fdata.smil_map;
                self.currently_showing.smil_audio_map = get_smil_audio_map(smil_map);
            }
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_unencrypted_message, ["display"].concat([ρσ_desugar_kwargs({resource_data: resource_data, book: self.book, name: self.currently_showing.name, initial_position: self.currently_showing.initial_position, smil_map: smil_map || null, settings: self.currently_showing.settings, reference_mode_enabled: self.reference_mode_enabled, is_titlepage: self.currently_showing.name === self.book.manifest.title_page_name, highlights: self.annotations_manager.highlights_for_currently_showing()})]));
        };
        if (!View.prototype.show_spine_item_stage2.__argnames__) Object.defineProperties(View.prototype.show_spine_item_stage2, {
            __argnames__ : {value: ["resource_data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.on_content_loaded = function on_content_loaded(data) {
            var self = this;
            var x;
            var ρσ_Iter14 = ρσ_Iterable(self.modal_overlays);
            for (var ρσ_Index14 = 0; ρσ_Index14 < ρσ_Iter14.length; ρσ_Index14++) {
                x = ρσ_Iter14[ρσ_Index14];
                if (!x.dont_hide_on_content_loaded) {
                    x.hide();
                }
            }
            self.processing_spine_item_display = false;
            self.currently_showing.loading = false;
            self.hide_loading();
            self.set_progress_frac(data.progress_frac, data.file_progress_frac, data.page_counts);
            self.update_header_footer();
            window.scrollTo(0, 0);
            if (self.book_load_started) {
                self.book_load_started = false;
                if (ui_operations.clear_history) {
                    ui_operations.clear_history();
                }
            }
            if (ui_operations.content_file_changed) {
                ui_operations.content_file_changed(self.currently_showing.name);
            }
            if (self.read_aloud.is_visible) {
                self.read_aloud.play();
            }
            var ρσ_Iter15 = ρσ_Iterable(self.currently_showing.on_load);
            for (var ρσ_Index15 = 0; ρσ_Index15 < ρσ_Iter15.length; ρσ_Index15++) {
                x = ρσ_Iter15[ρσ_Index15];
                x();
            }
            self.currently_showing.on_load = [];
        };
        if (!View.prototype.on_content_loaded.__argnames__) Object.defineProperties(View.prototype.on_content_loaded, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.set_progress_frac = function set_progress_frac(progress_frac, file_progress_frac, page_counts) {
            var self = this;
            self.current_progress_frac = progress_frac || 0;
            self.current_file_progress_frac = file_progress_frac || 0;
            self.current_page_counts = page_counts;
            self.book_scrollbar.sync_to_contents(self.current_progress_frac);
        };
        if (!View.prototype.set_progress_frac.__argnames__) Object.defineProperties(View.prototype.set_progress_frac, {
            __argnames__ : {value: ["progress_frac", "file_progress_frac", "page_counts"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.update_font_size = function update_font_size() {
            var self = this;
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["change_font_size"].concat([ρσ_desugar_kwargs({base_font_size: get_session_data().get("base_font_size")})]));
        };
        if (!View.prototype.update_font_size.__module__) Object.defineProperties(View.prototype.update_font_size, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.viewer_font_size_changed = function viewer_font_size_changed() {
            var self = this;
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["viewer_font_size_changed"].concat([ρσ_desugar_kwargs({base_font_size: get_session_data().get("base_font_size")})]));
        };
        if (!View.prototype.viewer_font_size_changed.__module__) Object.defineProperties(View.prototype.viewer_font_size_changed, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.update_scroll_speed = function update_scroll_speed(amt) {
            var self = this;
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["change_scroll_speed"].concat([ρσ_desugar_kwargs({lines_per_sec_auto: change_scroll_speed(amt)})]));
        };
        if (!View.prototype.update_scroll_speed.__argnames__) Object.defineProperties(View.prototype.update_scroll_speed, {
            __argnames__ : {value: ["amt"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.update_color_scheme = function update_color_scheme() {
            var self = this;
            var cs;
            cs = self.apply_color_scheme();
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["change_color_scheme"].concat([ρσ_desugar_kwargs({color_scheme: cs})]));
        };
        if (!View.prototype.update_color_scheme.__module__) Object.defineProperties(View.prototype.update_color_scheme, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.toggle_reference_mode = function toggle_reference_mode() {
            var self = this;
            self.reference_mode_enabled = !self.reference_mode_enabled;
            ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["set_reference_mode"].concat([ρσ_desugar_kwargs({enabled: self.reference_mode_enabled})]));
            if (ui_operations.reference_mode_changed) {
                ui_operations.reference_mode_changed(self.reference_mode_enabled);
            }
        };
        if (!View.prototype.toggle_reference_mode.__module__) Object.defineProperties(View.prototype.toggle_reference_mode, {
            __module__ : {value: "read_book.view"}
        });
        View.prototype.discover_search_result = function discover_search_result(sr) {
            var self = this;
            if (sr.search_finished) {
                if (self.search_result_discovery) {
                    self.search_result_discovery.finished = true;
                    if (!self.search_result_discovery.discovered && self.search_result_discovery.first_search_result && self.search_result_discovery.queue.length === 0) {
                        sr = self.search_result_discovery.first_search_result;
                        sr.force_jump_to = true;
                        self.search_result_discovery.jump_forced = true;
                        self.show_search_result(sr);
                    }
                }
                return;
            }
            if (sr.result_num === 1) {
                self.search_result_discovery = (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["queue"] = [];
                    ρσ_d["on_discovery"] = sr.on_discovery;
                    ρσ_d["in_flight"] = null;
                    ρσ_d["discovered"] = false;
                    ρσ_d["first_search_result"] = sr;
                    ρσ_d["finished"] = false;
                    ρσ_d["jump_forced"] = false;
                    return ρσ_d;
                }).call(this);
            }
            if (!self.search_result_discovery || self.search_result_discovery.discovered || self.search_result_discovery.on_discovery !== sr.on_discovery) {
                return;
            }
            self.search_result_discovery.queue.push(sr);
            if (!self.search_result_discovery.in_flight) {
                self.show_search_result(self.search_result_discovery.queue.shift());
            }
        };
        if (!View.prototype.discover_search_result.__argnames__) Object.defineProperties(View.prototype.discover_search_result, {
            __argnames__ : {value: ["sr"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.handle_search_result_discovery = function handle_search_result_discovery(sr, discovered) {
            var self = this;
            if (ρσ_exists.d(self.search_result_discovery).on_discovery === sr.on_discovery) {
                self.search_result_discovery.in_flight = null;
                if (discovered) {
                    if (!self.search_result_discovery.discovered) {
                        self.search_result_discovery.discovered = true;
                        ui_operations.search_result_discovered(sr);
                    }
                } else if (!self.search_result_discovery.discovered && self.search_result_discovery.queue.length) {
                    self.show_search_result(self.search_result_discovery.queue.shift());
                } else if (!self.search_result_discovery.discovered && self.search_result_discovery.finished && !self.search_result_discovery.jump_forced) {
                    sr = self.search_result_discovery.first_search_result;
                    sr.force_jump_to = true;
                    self.search_result_discovery.jump_forced = true;
                    self.show_search_result(sr);
                }
            }
        };
        if (!View.prototype.handle_search_result_discovery.__argnames__) Object.defineProperties(View.prototype.handle_search_result_discovery, {
            __argnames__ : {value: ["sr", "discovered"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.search_result_discovered = function search_result_discovered(data) {
            var self = this;
            self.handle_search_result_discovery(data.search_result, data.discovered);
        };
        if (!View.prototype.search_result_discovered.__argnames__) Object.defineProperties(View.prototype.search_result_discovered, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.search_result_not_found = function search_result_not_found(data) {
            var self = this;
            if (ui_operations.search_result_not_found) {
                ui_operations.search_result_not_found(data.search_result);
            }
            self.handle_search_result_discovery(data.search_result, false);
        };
        if (!View.prototype.search_result_not_found.__argnames__) Object.defineProperties(View.prototype.search_result_not_found, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.show_search_result = function show_search_result(sr) {
            var self = this;
            if (self.currently_showing.name === sr.file_name) {
                if (self.currently_showing.loading) {
                    self.currently_showing.on_load.push(self.show_search_result.bind(null, sr));
                } else {
                    ρσ_interpolate_kwargs.call(self.iframe_wrapper, self.iframe_wrapper.send_message, ["show_search_result"].concat([ρσ_desugar_kwargs({search_result: sr})]));
                }
            } else {
                ρσ_interpolate_kwargs.call(self, self.show_name, [sr.file_name].concat([ρσ_desugar_kwargs({initial_position: (function(){
                    var ρσ_d = Object.create(null);
                    ρσ_d["type"] = "search_result";
                    ρσ_d["search_result"] = sr;
                    ρσ_d["replace_history"] = true;
                    return ρσ_d;
                }).call(this)})]));
            }
            if (ρσ_exists.d(self.search_result_discovery).on_discovery === sr.on_discovery) {
                self.search_result_discovery.in_flight = sr.result_num;
            }
        };
        if (!View.prototype.show_search_result.__argnames__) Object.defineProperties(View.prototype.show_search_result, {
            __argnames__ : {value: ["sr"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.highlight_action = function highlight_action(uuid, which) {
            var self = this;
            var spine, spine_index, cfi;
            spine = self.book.manifest.spine;
            spine_index = self.annotations_manager.spine_index_for_highlight(uuid, spine);
            if (spine_index < 0 || spine_index >= spine.length) {
                if (which === "edit") {
                    self.selection_bar.report_failed_edit_highlight(uuid);
                }
                return;
            }
            if (which === "edit") {
                if (self.currently_showing.spine_index === spine_index) {
                    self.selection_bar.edit_highlight(uuid);
                } else {
                    ρσ_interpolate_kwargs.call(self, self.show_name, [spine[(typeof spine_index === "number" && spine_index < 0) ? spine.length + spine_index : spine_index]].concat([ρσ_desugar_kwargs({initial_position: (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["type"] = "edit_annotation";
                        ρσ_d["uuid"] = uuid;
                        ρσ_d["replace_history"] = true;
                        return ρσ_d;
                    }).call(this)})]));
                }
            } else if (which === "delete") {
                self.selection_bar.remove_highlight_with_id(uuid);
            } else if (which === "goto") {
                cfi = self.annotations_manager.cfi_for_highlight(uuid, spine_index);
                if (cfi) {
                    self.goto_cfi(cfi, true);
                }
            }
        };
        if (!View.prototype.highlight_action.__argnames__) Object.defineProperties(View.prototype.highlight_action, {
            __argnames__ : {value: ["uuid", "which"]},
            __module__ : {value: "read_book.view"}
        });
        View.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        View.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(View.prototype, "__bases__", {value: []});
        
        
        

        ρσ_modules["read_book.view"].show_controls_help = show_controls_help;
        ρσ_modules["read_book.view"].body_font_size = body_font_size;
        ρσ_modules["read_book.view"].header_footer_font_size = header_footer_font_size;
        ρσ_modules["read_book.view"].margin_elem = margin_elem;
        ρσ_modules["read_book.view"].side_margin_elem = side_margin_elem;
        ρσ_modules["read_book.view"].View = View;
    })();

    (function(){

        var __name__ = "__main__";


        var book, view, profiles_callbacks, TRANSLATIONS_DATA;
        var E = ρσ_modules.elementmaker.E;

        var initialize = ρσ_modules.initialize;

        var traceback = ρσ_modules.traceback;

        var absolute_path = ρσ_modules.ajax.absolute_path;
        var ajax = ρσ_modules.ajax.ajax;
        var workaround_qt_bug = ρσ_modules.ajax.workaround_qt_bug;

        var get_session_data = ρσ_modules["book_list.globals"].get_session_data;
        var set_session_data = ρσ_modules["book_list.globals"].set_session_data;

        var library_data = ρσ_modules["book_list.library_data"].library_data;

        var css_for_variables = ρσ_modules["book_list.theme"].css_for_variables;
        var get_color = ρσ_modules["book_list.theme"].get_color;

        var format_date = ρσ_modules.date.format_date;

        var get_widget_css = ρσ_modules.dom.get_widget_css;
        var set_css = ρσ_modules.dom.set_css;

        var _ = ρσ_modules.gettext.gettext;
        var install = ρσ_modules.gettext.install;

        var create_modal_container = ρσ_modules.modals.create_modal_container;

        var from_python = ρσ_modules.qt.from_python;
        var to_python = ρσ_modules.qt.to_python;

        var new_book = ρσ_modules["read_book.db"].new_book;

        var footnotes_main = ρσ_modules["read_book.footnotes"].main;

        var default_color_schemes = ρσ_modules["read_book.globals"].default_color_schemes;
        var runtime = ρσ_modules["read_book.globals"].runtime;
        var set_system_colors = ρσ_modules["read_book.globals"].set_system_colors;
        var ui_operations = ρσ_modules["read_book.globals"].ui_operations;

        var iframe_main = ρσ_modules["read_book.iframe"].main;

        var remove_recently_opened = ρσ_modules["read_book.open_book"].remove_recently_opened;

        var set_time_formatter = ρσ_modules["read_book.prefs.head_foot"].set_time_formatter;

        var View = ρσ_modules["read_book.view"].View;

        var apply_reader_profile = ρσ_modules.session.apply_reader_profile;
        var default_interface_data = ρσ_modules.session.default_interface_data;
        var local_storage = ρσ_modules.session.local_storage;
        var session_defaults = ρσ_modules.session.session_defaults;
        var settings_for_reader_profile = ρσ_modules.session.settings_for_reader_profile;

        var debounce = ρσ_modules.utils.debounce;
        var encode_query_with_path = ρσ_modules.utils.encode_query_with_path;
        var parse_url_params = ρσ_modules.utils.parse_url_params;

        var FAKE_HOST = ρσ_modules["viewer.constants"].FAKE_HOST;
        var FAKE_PROTOCOL = ρσ_modules["viewer.constants"].FAKE_PROTOCOL;

        runtime.is_standalone_viewer = true;
        runtime.FAKE_HOST = FAKE_HOST;
        runtime.SANDBOX_HOST = FAKE_HOST.rpartition(".")[0] + ".sandbox";
        runtime.FAKE_PROTOCOL = FAKE_PROTOCOL;
        book = null;
        view = null;
        function file_received(name, file_data, proceed, end_type, xhr, ev) {
            var result;
            end_type = workaround_qt_bug(xhr, end_type);
            if (end_type === "abort") {
                return;
            }
            if (end_type !== "load") {
                show_error(_("Failed to load file from book"), _("Could not load the file: {} with error: {}").format(name, xhr.error_html));
                return;
            }
            if (!xhr.responseType || xhr.responseType === "text") {
                result = xhr.responseText;
            } else if (xhr.responseType === "blob") {
                result = xhr.response;
            } else {
                show_error(_("Failed to load file from book"), _("Could not load the file: {} unknown response type: {}").format(name, xhr.responseType));
                return;
            }
            proceed(result, name, file_data.mimetype, book);
        };
        if (!file_received.__argnames__) Object.defineProperties(file_received, {
            __argnames__ : {value: ["name", "file_data", "proceed", "end_type", "xhr", "ev"]},
            __module__ : {value: null}
        });

        function get_url_for_book_file_name(name) {
            return absolute_path("book/" + name);
        };
        if (!get_url_for_book_file_name.__argnames__) Object.defineProperties(get_url_for_book_file_name, {
            __argnames__ : {value: ["name"]},
            __module__ : {value: null}
        });

        function get_file(book, name, proceed) {
            var entry, xhr;
            entry = (ρσ_expr_temp = book.manifest.files)[(typeof name === "number" && name < 0) ? ρσ_expr_temp.length + name : name];
            if (!entry) {
                throw new ValueError("No file named " + ρσ_str.format("{}", name) + " in the book manifest");
            }
            xhr = ρσ_interpolate_kwargs.call(this, ajax, ["book/" + name, file_received.bind(null, name, entry, proceed)].concat([ρσ_desugar_kwargs({ok_code: 0})]));
            if (entry.is_html || entry.mimetype.startswith("text/") || entry.mimetype === "application/javascript") {
                xhr.responseType = "text";
            } else {
                xhr.responseType = "blob";
            }
            xhr.send();
        };
        if (!get_file.__argnames__) Object.defineProperties(get_file, {
            __argnames__ : {value: ["book", "name", "proceed"]},
            __module__ : {value: null}
        });

        profiles_callbacks = (function(){
            var ρσ_d = Object.create(null);
            ρσ_d["all"] = null;
            ρσ_d["saved"] = null;
            return ρσ_d;
        }).call(this);
        
        var profile_response = from_python((function() {
            var ρσ_anonfunc = function profile_response(which, x) {
                var sd, settings;
                if (which === "all-profiles") {
                    profiles_callbacks.all(x);
                    profiles_callbacks.all = null;
                } else if (which === "save-profile") {
                    profiles_callbacks.saved();
                    profiles_callbacks.saved = null;
                } else if (which === "apply-profile") {
                    sd = get_session_data();
                    apply_reader_profile(sd, x);
                    if (view) {
                        view.preferences_changed();
                    }
                    ui_operations.apply_profile(x);
                } else if (which === "request-save") {
                    sd = get_session_data();
                    settings = settings_for_reader_profile(sd);
                    save_profile(x, settings, (function() {
                        var ρσ_anonfunc = function () {
                        };
                        if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                            __module__ : {value: null}
                        });
                        return ρσ_anonfunc;
                    })());
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["which", "x"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        function get_all_profiles(proceed) {
            profiles_callbacks.all = proceed;
            to_python.profile_op("all-profiles", "", null);
        };
        if (!get_all_profiles.__argnames__) Object.defineProperties(get_all_profiles, {
            __argnames__ : {value: ["proceed"]},
            __module__ : {value: null}
        });

        function save_profile(name, settings, proceed) {
            profiles_callbacks.saved = proceed;
            to_python.profile_op("save-profile", name, settings);
        };
        if (!save_profile.__argnames__) Object.defineProperties(save_profile, {
            __argnames__ : {value: ["name", "settings", "proceed"]},
            __module__ : {value: null}
        });

        function get_mathjax_files(proceed) {
            proceed(Object.create(null));
        };
        if (!get_mathjax_files.__argnames__) Object.defineProperties(get_mathjax_files, {
            __argnames__ : {value: ["proceed"]},
            __module__ : {value: null}
        });

        function update_url_state(replace) {
            var bookpos, query;
            if (view && view.currently_showing) {
                bookpos = view.currently_showing.bookpos;
                if (bookpos) {
                    query = (function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["bookpos"] = bookpos;
                        return ρσ_d;
                    }).call(this);
                    query = encode_query_with_path(query);
                    if (replace) {
                        window.history.replaceState(null, "", query);
                    } else {
                        window.history.pushState(null, "", query);
                    }
                }
            }
        };
        if (!update_url_state.__argnames__) Object.defineProperties(update_url_state, {
            __argnames__ : {value: ["replace"]},
            __module__ : {value: null}
        });

        function on_pop_state() {
            var data;
            if (view && view.currently_showing) {
                data = parse_url_params();
                if (data.bookpos && data.bookpos.startswith("epubcfi(/")) {
                    view.goto_cfi(data.bookpos);
                }
            }
        };
        if (!on_pop_state.__module__) Object.defineProperties(on_pop_state, {
            __module__ : {value: null}
        });

        function show_error(title, msg, details) {
            to_python.show_error(title, msg, details);
        };
        if (!show_error.__argnames__) Object.defineProperties(show_error, {
            __argnames__ : {value: ["title", "msg", "details"]},
            __module__ : {value: null}
        });

        function manifest_received(key, initial_position, pathtoebook, highlights, book_url, reading_rates, book_in_library_url, end_type, xhr, ev) {
            var data;
            end_type = workaround_qt_bug(xhr, end_type);
            if (end_type === "load") {
                book = new_book(key, Object.create(null));
                data = xhr.response;
                book.manifest = data[0];
                book.metadata = book.manifest.metadata = data[1];
                book.manifest.pathtoebook = pathtoebook;
                book.highlights = highlights;
                book.stored_files = Object.create(null);
                book.calibre_book_url = book_url;
                book.calibre_book_in_library_url = book_in_library_url;
                book.saved_reading_rates = reading_rates;
                book.is_complete = true;
                delete book.manifest["metadata"];
                delete book.manifest["last_read_positions"];
                view.display_book(book, initial_position);
            } else {
                show_error(_("Could not open book"), _("Failed to load book manifest, click \"Show details\" for more info"), xhr.error_html || null);
            }
        };
        if (!manifest_received.__argnames__) Object.defineProperties(manifest_received, {
            __argnames__ : {value: ["key", "initial_position", "pathtoebook", "highlights", "book_url", "reading_rates", "book_in_library_url", "end_type", "xhr", "ev"]},
            __module__ : {value: null}
        });

        function clone(x) {
            if (x) {
                x = window.structuredClone(x);
            }
            return x;
        };
        if (!clone.__argnames__) Object.defineProperties(clone, {
            __argnames__ : {value: ["x"]},
            __module__ : {value: null}
        });

        function SessionData() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            SessionData.prototype.__bind_methods__.call(this);
            SessionData.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(SessionData.prototype, "__bind_methods__", {value: function () {
            this.get = SessionData.prototype.get.bind(this);
            this.set = SessionData.prototype.set.bind(this);
            this.set_bulk = SessionData.prototype.set_bulk.bind(this);
            this.clear = SessionData.prototype.clear.bind(this);
        }});
        SessionData.prototype.__init__ = function __init__(prefs) {
            var self = this;
            var defaults, k;
            defaults = session_defaults();
            self.data = (function() {
                var ρσ_Iter = ρσ_Iterable(defaults), ρσ_Result = Object.create(null), k;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    k = ρσ_Iter[ρσ_Index];
                    ρσ_Result[k] = ((prefs[(typeof k === "number" && k < 0) ? prefs.length + k : k] === undefined) ? clone(defaults[(typeof k === "number" && k < 0) ? defaults.length + k : k]) : clone(prefs[(typeof k === "number" && k < 0) ? prefs.length + k : k]));
                }
                return ρσ_Result;
            })();
        };
        if (!SessionData.prototype.__init__.__argnames__) Object.defineProperties(SessionData.prototype.__init__, {
            __argnames__ : {value: ["prefs"]},
            __module__ : {value: null}
        });
        SessionData.__argnames__ = SessionData.prototype.__init__.__argnames__;
        SessionData.__handles_kwarg_interpolation__ = SessionData.prototype.__init__.__handles_kwarg_interpolation__;
        SessionData.prototype.get = function get(key, defval) {
            var self = this;
            var ans;
            ans = (ρσ_expr_temp = self.data)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
            if (ans === undefined || ans === null) {
                if (defval === undefined) {
                    defval = null;
                }
                return defval;
            }
            return ans;
        };
        if (!SessionData.prototype.get.__argnames__) Object.defineProperties(SessionData.prototype.get, {
            __argnames__ : {value: ["key", "defval"]},
            __module__ : {value: null}
        });
        SessionData.prototype.set = function set(key, val) {
            var self = this;
            if (val === null) {
                (ρσ_expr_temp = self.data)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = clone((ρσ_expr_temp = session_defaults())[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key]);
            } else {
                (ρσ_expr_temp = self.data)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = val;
            }
            to_python.set_session_data(key, val);
        };
        if (!SessionData.prototype.set.__argnames__) Object.defineProperties(SessionData.prototype.set, {
            __argnames__ : {value: ["key", "val"]},
            __module__ : {value: null}
        });
        SessionData.prototype.set_bulk = function set_bulk(changes) {
            var self = this;
            var defaults, val, key;
            defaults = session_defaults();
            var ρσ_Iter0 = ρσ_Iterable(Object.keys(changes));
            for (var ρσ_Index0 = 0; ρσ_Index0 < ρσ_Iter0.length; ρσ_Index0++) {
                key = ρσ_Iter0[ρσ_Index0];
                val = changes[(typeof key === "number" && key < 0) ? changes.length + key : key];
                if (val === null) {
                    (ρσ_expr_temp = self.data)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = clone(defaults[(typeof key === "number" && key < 0) ? defaults.length + key : key]);
                } else {
                    (ρσ_expr_temp = self.data)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = val;
                }
            }
            to_python.set_session_data(changes, null);
        };
        if (!SessionData.prototype.set_bulk.__argnames__) Object.defineProperties(SessionData.prototype.set_bulk, {
            __argnames__ : {value: ["changes"]},
            __module__ : {value: null}
        });
        SessionData.prototype.clear = function clear() {
            var self = this;
            var defaults, k;
            defaults = session_defaults();
            self.data = (function() {
                var ρσ_Iter = ρσ_Iterable(defaults), ρσ_Result = Object.create(null), k;
                for (var ρσ_Index = 0; ρσ_Index < ρσ_Iter.length; ρσ_Index++) {
                    k = ρσ_Iter[ρσ_Index];
                    ρσ_Result[k] = (clone(defaults[(typeof k === "number" && k < 0) ? defaults.length + k : k]));
                }
                return ρσ_Result;
            })();
            to_python.set_session_data("*", null);
        };
        if (!SessionData.prototype.clear.__module__) Object.defineProperties(SessionData.prototype.clear, {
            __module__ : {value: null}
        });
        SessionData.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        SessionData.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(SessionData.prototype, "__bases__", {value: []});

        function LocalStorage() {
            if (this.ρσ_object_id === undefined) Object.defineProperty(this, "ρσ_object_id", {"value":++ρσ_object_counter});
            LocalStorage.prototype.__bind_methods__.call(this);
            LocalStorage.prototype.__init__.apply(this, arguments);
        }
        Object.defineProperty(LocalStorage.prototype, "__bind_methods__", {value: function () {
            this.get = LocalStorage.prototype.get.bind(this);
            this.set = LocalStorage.prototype.set.bind(this);
            this.clear = LocalStorage.prototype.clear.bind(this);
        }});
        LocalStorage.prototype.__init__ = function __init__(data) {
            var self = this;
            self.data = data;
        };
        if (!LocalStorage.prototype.__init__.__argnames__) Object.defineProperties(LocalStorage.prototype.__init__, {
            __argnames__ : {value: ["data"]},
            __module__ : {value: null}
        });
        LocalStorage.__argnames__ = LocalStorage.prototype.__init__.__argnames__;
        LocalStorage.__handles_kwarg_interpolation__ = LocalStorage.prototype.__init__.__handles_kwarg_interpolation__;
        LocalStorage.prototype.get = function get(key, defval) {
            var self = this;
            var ans;
            ans = (ρσ_expr_temp = self.data)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key];
            if (ans === undefined || ans === null) {
                if (defval === undefined) {
                    defval = null;
                }
                return defval;
            }
            return ans;
        };
        if (!LocalStorage.prototype.get.__argnames__) Object.defineProperties(LocalStorage.prototype.get, {
            __argnames__ : {value: ["key", "defval"]},
            __module__ : {value: null}
        });
        LocalStorage.prototype.set = function set(key, val) {
            var self = this;
            (ρσ_expr_temp = self.data)[(typeof key === "number" && key < 0) ? ρσ_expr_temp.length + key : key] = val;
            to_python.set_local_storage(key, val);
        };
        if (!LocalStorage.prototype.set.__argnames__) Object.defineProperties(LocalStorage.prototype.set, {
            __argnames__ : {value: ["key", "val"]},
            __module__ : {value: null}
        });
        LocalStorage.prototype.clear = function clear() {
            var self = this;
            self.data = Object.create(null);
            to_python.set_local_storage("*", null);
        };
        if (!LocalStorage.prototype.clear.__module__) Object.defineProperties(LocalStorage.prototype.clear, {
            __module__ : {value: null}
        });
        LocalStorage.prototype.__repr__ = function __repr__ () {
                        return "<" + __name__ + "." + this.constructor.name + " #" + this.ρσ_object_id + ">";
        };
        LocalStorage.prototype.__str__ = function __str__ () {
            return this.__repr__();
        };
        Object.defineProperty(LocalStorage.prototype, "__bases__", {value: []});

        function create_session_data(prefs, local_storage_data) {
            var sd;
            sd = new SessionData(prefs);
            set_session_data(sd);
            local_storage.storage = new LocalStorage(local_storage_data);
        };
        if (!create_session_data.__argnames__) Object.defineProperties(create_session_data, {
            __argnames__ : {value: ["prefs", "local_storage_data"]},
            __module__ : {value: null}
        });

        
        var create_view = from_python((function() {
            var ρσ_anonfunc = function create_view(prefs, local_storage, field_metadata, ui_data) {
                set_system_colors(ui_data.system_colors);
                runtime.all_font_families = ui_data.all_font_families;
                library_data.field_metadata = field_metadata;
                document.documentElement.style.fontFamily = "\"" + ρσ_str.format("{}", ui_data.ui_font_family) + "\", sans-serif";
                document.documentElement.style.fontSize = ui_data.ui_font_sz;
                runtime.QT_VERSION = ui_data.QT_VERSION;
                set_time_formatter((function() {
                    var ρσ_anonfunc = function (d) {
                        return format_date(d, ui_data.short_time_fmt);
                    };
                    if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                        __argnames__ : {value: ["d"]},
                        __module__ : {value: null}
                    });
                    return ρσ_anonfunc;
                })());
                if (view === null) {
                    create_session_data(prefs, local_storage);
                    view = new View(document.getElementById("view"));
                    window.addEventListener("resize", debounce(view.on_resize.bind(self), 250));
                    to_python.view_created((function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["default_color_schemes"] = default_color_schemes;
                        return ρσ_d;
                    }).call(this));
                    default_interface_data.use_roman_numerals_for_series_number = ui_data.use_roman_numerals_for_series_number;
                    if (ui_data.show_home_page_on_ready) {
                        view.overlay.open_book(false);
                    }
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["prefs", "local_storage", "field_metadata", "ui_data"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var set_system_palette = from_python((function() {
            var ρσ_anonfunc = function set_system_palette(system_colors) {
                set_system_colors(system_colors);
                if (view) {
                    view.update_color_scheme();
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["system_colors"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var highlight_action = from_python((function() {
            var ρσ_anonfunc = function highlight_action(uuid, which) {
                if (view) {
                    view.highlight_action(uuid, which);
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["uuid", "which"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var generic_action = from_python((function() {
            var ρσ_anonfunc = function generic_action(which, data) {
                if (which === "set-notes-in-highlight") {
                    view.set_notes_for_highlight(data.uuid, data.notes || "");
                } else if (which === "show-status-message") {
                    view.show_status_message(data.text);
                } else if (which === "remove-recently-opened") {
                    remove_recently_opened(data.path);
                } else if (which === "add-notes-or-create-highlight") {
                    view.add_notes_or_create_highlight(data.notes, data.style);
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["which", "data"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var tts_event = from_python((function() {
            var ρσ_anonfunc = function tts_event(which, data) {
                view.read_aloud.handle_tts_event(which, data);
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["which", "data"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var show_home_page = from_python((function() {
            var ρσ_anonfunc = function show_home_page() {
                view.overlay.open_book(false);
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var redraw_tts_bar = from_python((function() {
            var ρσ_anonfunc = function redraw_tts_bar(pos) {
                var sd;
                sd = get_session_data();
                sd.set("tts_bar_position", pos);
                if (view) {
                    view.read_aloud.build_bar();
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["pos"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var start_book_load = from_python((function() {
            var ρσ_anonfunc = function start_book_load(key, initial_position, pathtoebook, highlights, book_url, reading_rates, book_in_library_url) {
                var xhr;
                xhr = ρσ_interpolate_kwargs.call(this, ajax, ["manifest", manifest_received.bind(null, key, initial_position, pathtoebook, highlights, book_url, reading_rates, book_in_library_url)].concat([ρσ_desugar_kwargs({ok_code: 0})]));
                xhr.responseType = "json";
                xhr.send();
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["key", "initial_position", "pathtoebook", "highlights", "book_url", "reading_rates", "book_in_library_url"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var goto_toc_node = from_python((function() {
            var ρσ_anonfunc = function goto_toc_node(node_id) {
                view.goto_toc_node(node_id);
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["node_id"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var goto_cfi = from_python((function() {
            var ρσ_anonfunc = function goto_cfi(cfi, add_to_history) {
                return view.goto_cfi(cfi, !!add_to_history);
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["cfi", "add_to_history"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var full_screen_state_changed = from_python((function() {
            var ρσ_anonfunc = function full_screen_state_changed(viewer_in_full_screen) {
                runtime.viewer_in_full_screen = viewer_in_full_screen;
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["viewer_in_full_screen"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var get_current_cfi = from_python((function() {
            var ρσ_anonfunc = function get_current_cfi(request_id) {
                view.get_current_cfi(request_id, ui_operations.report_cfi);
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["request_id"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var goto_frac = from_python((function() {
            var ρσ_anonfunc = function goto_frac(frac) {
                if (view) {
                    view.goto_frac(frac);
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["frac"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var background_image_changed = from_python((function() {
            var ρσ_anonfunc = function background_image_changed(img_id, url) {
                var img;
                img = document.getElementById(img_id);
                if (img) {
                    img.src = "" + ρσ_str.format("{}", url) + "?" + ρσ_str.format("{}", (new Date).getTime()) + "";
                    img.dataset.url = url;
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["img_id", "url"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var trigger_shortcut = from_python((function() {
            var ρσ_anonfunc = function trigger_shortcut(which) {
                if (view) {
                    view.on_handle_shortcut((function(){
                        var ρσ_d = Object.create(null);
                        ρσ_d["name"] = which;
                        return ρσ_d;
                    }).call(this));
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["which"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var show_search_result = from_python((function() {
            var ρσ_anonfunc = function show_search_result(sr) {
                if (view) {
                    if (sr.on_discovery) {
                        view.discover_search_result(sr);
                    } else {
                        view.show_search_result(sr);
                    }
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["sr"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var prepare_for_close = from_python((function() {
            var ρσ_anonfunc = function prepare_for_close() {
                if (view) {
                    view.prepare_for_close();
                } else {
                    ui_operations.close_prep_finished(null);
                }
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var repair_after_fullscreen_switch = from_python((function() {
            var ρσ_anonfunc = function repair_after_fullscreen_switch() {
                if (view) {
                    view.show_status_message("...", 200);
                }
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var viewer_font_size_changed = from_python((function() {
            var ρσ_anonfunc = function viewer_font_size_changed() {
                if (view) {
                    view.viewer_font_size_changed();
                }
            };
            if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        
        var native_gesture = from_python((function() {
            var ρσ_anonfunc = function native_gesture(gesture) {
                if (view) {
                    view.native_gesture(gesture);
                }
            };
            if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                __argnames__ : {value: ["gesture"]},
                __module__ : {value: null}
            });
            return ρσ_anonfunc;
        })());

        function onerror(msg, script_url, line_number, column_number, error_object) {
            var fname, details;
            if (!error_object) {
                return false;
            }
            fname = (ρσ_expr_temp = script_url.rpartition("/"))[ρσ_expr_temp.length-1] || script_url;
            msg += "<br><span style=\"font-size:smaller\">" + "Error at {}:{}:{}".format(fname, line_number, column_number || "") + "</span>";
            details = "";
            console.log(error_object);
            details = traceback.format_exception(error_object).join("");
            show_error(_("Unhandled error"), msg, details);
            return true;
        };
        if (!onerror.__argnames__) Object.defineProperties(onerror, {
            __argnames__ : {value: ["msg", "script_url", "line_number", "column_number", "error_object"]},
            __module__ : {value: null}
        });

        if (window === window.top) {
            TRANSLATIONS_DATA = __TRANSLATIONS_DATA__;
            if (TRANSLATIONS_DATA) {
                install(TRANSLATIONS_DATA);
            }
            ui_operations.get_all_profiles = get_all_profiles;
            ui_operations.save_profile = save_profile;
            ui_operations.apply_profile = (function() {
                var ρσ_anonfunc = function (profile) {
                    to_python.profile_op("apply-profile-to-viewer-ui", "", profile);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["profile"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.get_file = get_file;
            ui_operations.get_url_for_book_file_name = get_url_for_book_file_name;
            ui_operations.get_mathjax_files = get_mathjax_files;
            ui_operations.update_url_state = update_url_state;
            ui_operations.show_error = show_error;
            ui_operations.redisplay_book = (function() {
                var ρσ_anonfunc = function () {
                    view.redisplay_book();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.reload_book = (function() {
                var ρσ_anonfunc = function () {
                    to_python.reload_book();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.forward_gesture = (function() {
                var ρσ_anonfunc = function (gesture) {
                    view.forward_gesture(gesture);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["gesture"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.update_color_scheme = (function() {
                var ρσ_anonfunc = function () {
                    view.update_color_scheme();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.update_font_size = (function() {
                var ρσ_anonfunc = function () {
                    view.update_font_size();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.focus_iframe = (function() {
                var ρσ_anonfunc = function () {
                    view.focus_iframe();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.goto_cfi = (function() {
                var ρσ_anonfunc = function (cfi) {
                    return view.goto_cfi(cfi);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["cfi"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.goto_frac = (function() {
                var ρσ_anonfunc = function (frac) {
                    return view.goto_frac(frac);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["frac"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.goto_book_position = (function() {
                var ρσ_anonfunc = function (bpos) {
                    return view.goto_book_position(bpos);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["bpos"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.goto_reference = (function() {
                var ρσ_anonfunc = function (ref) {
                    return view.goto_reference(ref);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ref"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.toggle_toc = (function() {
                var ρσ_anonfunc = function () {
                    to_python.toggle_toc();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.toggle_bookmarks = (function() {
                var ρσ_anonfunc = function () {
                    to_python.toggle_bookmarks();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.toggle_highlights = (function() {
                var ρσ_anonfunc = function () {
                    to_python.toggle_highlights();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.new_bookmark = (function() {
                var ρσ_anonfunc = function (request_id, data) {
                    if (request_id === "new-bookmark") {
                        to_python.new_bookmark(data);
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["request_id", "data"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.toggle_inspector = (function() {
                var ρσ_anonfunc = function () {
                    to_python.toggle_inspector();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.content_file_changed = (function() {
                var ρσ_anonfunc = function (name) {
                    to_python.content_file_changed(name);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["name"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.update_last_read_position = (function() {
                var ρσ_anonfunc = function (cfi, pos_frac) {
                    to_python.update_last_read_position(cfi, pos_frac);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["cfi", "pos_frac"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.show_search = (function() {
                var ρσ_anonfunc = function (text, trigger) {
                    to_python.show_search(text, !!trigger);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["text", "trigger"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.find_next = (function() {
                var ρσ_anonfunc = function (previous) {
                    to_python.find_next(previous);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["previous"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.reset_interface = (function() {
                var ρσ_anonfunc = function () {
                    var sd, defaults, m;
                    sd = get_session_data();
                    defaults = session_defaults();
                    m = sd.get("standalone_misc_settings", Object.create(null));
                    delete m.show_actions_toolbar;
                    sd.set("standalone_misc_settings", m);
                    sd.set("book_scrollbar", false);
                    view.book_scrollbar.apply_visibility();
                    sd.set("header", defaults.header);
                    sd.set("footer", defaults.footer);
                    view.update_header_footer();
                    to_python.reset_interface();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.open_url = (function() {
                var ρσ_anonfunc = function (url) {
                    to_python.open_url(url);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["url"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.quit = (function() {
                var ρσ_anonfunc = function () {
                    to_python.quit();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.toggle_lookup = (function() {
                var ρσ_anonfunc = function (force_show) {
                    to_python.toggle_lookup(!!force_show);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["force_show"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.selection_changed = (function() {
                var ρσ_anonfunc = function (selected_text, annot_id) {
                    to_python.selection_changed(selected_text, annot_id || null);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["selected_text", "annot_id"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.update_current_toc_nodes = (function() {
                var ρσ_anonfunc = function (families) {
                    to_python.update_current_toc_nodes(families);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["families"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.toggle_full_screen = (function() {
                var ρσ_anonfunc = function () {
                    to_python.toggle_full_screen();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.report_cfi = (function() {
                var ρσ_anonfunc = function (request_id, data) {
                    to_python.report_cfi(request_id, data);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["request_id", "data"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.ask_for_open = (function() {
                var ρσ_anonfunc = function (path) {
                    to_python.ask_for_open(path);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["path"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.copy_selection = (function() {
                var ρσ_anonfunc = function (text, html) {
                    to_python.copy_selection(text || null, html || null);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["text", "html"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.view_image = (function() {
                var ρσ_anonfunc = function (name) {
                    to_python.view_image(name);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["name"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.copy_image = (function() {
                var ρσ_anonfunc = function (name) {
                    to_python.copy_image(name);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["name"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.change_background_image = (function() {
                var ρσ_anonfunc = function (img_id) {
                    to_python.change_background_image(img_id);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["img_id"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.quit = (function() {
                var ρσ_anonfunc = function () {
                    to_python.quit();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.overlay_visibility_changed = (function() {
                var ρσ_anonfunc = function (visible) {
                    to_python.overlay_visibility_changed(visible);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["visible"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.reference_mode_changed = (function() {
                var ρσ_anonfunc = function (enabled) {
                    to_python.reference_mode_changed(enabled);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["enabled"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.show_loading_message = (function() {
                var ρσ_anonfunc = function (msg) {
                    to_python.show_loading_message(msg);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["msg"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.export_shortcut_map = (function() {
                var ρσ_anonfunc = function (smap) {
                    to_python.export_shortcut_map(smap);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["smap"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.print_book = (function() {
                var ρσ_anonfunc = function () {
                    to_python.print_book();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.clear_history = (function() {
                var ρσ_anonfunc = function () {
                    to_python.clear_history();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.customize_toolbar = (function() {
                var ρσ_anonfunc = function () {
                    to_python.customize_toolbar();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.autoscroll_state_changed = (function() {
                var ρσ_anonfunc = function (active) {
                    to_python.autoscroll_state_changed(active);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["active"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.read_aloud_state_changed = (function() {
                var ρσ_anonfunc = function (active) {
                    to_python.read_aloud_state_changed(active);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["active"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.search_result_not_found = (function() {
                var ρσ_anonfunc = function (sr) {
                    to_python.search_result_not_found(sr);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["sr"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.search_result_discovered = (function() {
                var ρσ_anonfunc = function (sr) {
                    to_python.search_result_discovered(sr);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["sr"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.scrollbar_context_menu = (function() {
                var ρσ_anonfunc = function (x, y, frac) {
                    to_python.scrollbar_context_menu(x, y, frac);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["x", "y", "frac"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.close_prep_finished = (function() {
                var ρσ_anonfunc = function (cfi) {
                    to_python.close_prep_finished(cfi);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["cfi"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.annots_changed = (function() {
                var ρσ_anonfunc = function (amap) {
                    if (amap.highlight) {
                        to_python.highlights_changed(amap.highlight);
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["amap"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.speak_simple_text = (function() {
                var ρσ_anonfunc = function (text) {
                    to_python.speak_simple_text(text);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["text"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.tts = (function() {
                var ρσ_anonfunc = function (action, data) {
                    to_python.tts(action, data || {});
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["action", "data"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.edit_book = (function() {
                var ρσ_anonfunc = function (spine_name, frac, selected_text) {
                    to_python.edit_book(spine_name, frac, selected_text || "");
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["spine_name", "frac", "selected_text"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.show_book_folder = (function() {
                var ρσ_anonfunc = function () {
                    to_python.show_book_folder();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.show_help = (function() {
                var ρσ_anonfunc = function (which) {
                    to_python.show_help(which);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["which"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.on_iframe_ready = (function() {
                var ρσ_anonfunc = function () {
                    to_python.on_iframe_ready();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.update_reading_rates = (function() {
                var ρσ_anonfunc = function (rates) {
                    to_python.update_reading_rates(rates);
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["rates"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            ui_operations.reset_reading_rates = (function() {
                var ρσ_anonfunc = function () {
                    to_python.reset_reading_rates();
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })();
            document.addEventListener("focusin", (function() {
                var ρσ_anonfunc = function (ev) {
                    var elem;
                    elem = ev.target;
                    if (elem && (elem.isContentEditable || elem.nodeName === "TEXTAREA" || elem.nodeName === "INPUT")) {
                        to_python.html_input_focusin();
                    }
                };
                if (!ρσ_anonfunc.__argnames__) Object.defineProperties(ρσ_anonfunc, {
                    __argnames__ : {value: ["ev"]},
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })(), true);
            document.body.appendChild(ρσ_interpolate_kwargs.call(E, E.div, [ρσ_desugar_kwargs({id: "view"})]));
            window.onerror = onerror;
            create_modal_container();
            document.head.appendChild(E.style(css_for_variables() + "\n\n" + get_widget_css()));
            ρσ_interpolate_kwargs.call(this, set_css, [document.body].concat([ρσ_desugar_kwargs({background_color: get_color("window-background"), color: get_color("window-foreground")})]));
            setTimeout((function() {
                var ρσ_anonfunc = function () {
                    window.onpopstate = on_pop_state;
                };
                if (!ρσ_anonfunc.__module__) Object.defineProperties(ρσ_anonfunc, {
                    __module__ : {value: null}
                });
                return ρσ_anonfunc;
            })(), 0);
        } else {
            if (document.location.pathname.endsWith("/__index__")) {
                iframe_main();
            } else if (document.location.pathname.endsWith("/__popup__")) {
                footnotes_main();
            }
        }
    })();
})();
