import { r as registerInstance, j as createEvent, h, g as getElement } from './index-aeac5cad.js';
import { c as createCommonjsModule, g as getDefaultExportFromCjs, a as commonjsGlobal } from './_commonjsHelpers-91fffb88.js';
import { d as dist$1 } from './index-fdd60c34.js';

var Rule_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.create = exports.setFallback = exports.add = exports.Rule = void 0;
class Rule {
    filter(value) {
        return value.filter(element => this.is(element));
    }
    stringify(precedence = 0) {
        let result = this.toString();
        if (this.precedence < precedence)
            result = "(" + result + ")";
        return result;
    }
}
exports.Rule = Rule;
const creators = [
    criteria => (criteria instanceof Rule ? criteria : undefined),
];
function add(create) {
    creators.push(create);
}
exports.add = add;
let always;
function setFallback(fallback) {
    always = fallback;
}
exports.setFallback = setFallback;
function create(criteria) {
    let result;
    for (const c of creators) {
        result = c(criteria);
        if (result)
            break;
    }
    return result || always;
}
exports.create = create;

});

const Rule = /*@__PURE__*/getDefaultExportFromCjs(Rule_1);

var Always_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Always = void 0;

class Always extends Rule_1.Rule {
    constructor() {
        super();
        this.precedence = Number.MAX_SAFE_INTEGER;
        this.class = "Always";
    }
    is(value) {
        return true;
    }
    toString() {
        return "";
    }
}
exports.Always = Always;
Rule_1.setFallback(new Always());

});

const Always = /*@__PURE__*/getDefaultExportFromCjs(Always_1);

var Property_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.property = exports.Property = void 0;


class Property extends Rule_1.Rule {
    constructor(name, criteria) {
        super();
        this.name = name;
        this.criteria = criteria;
        this.precedence = Property.precedence;
        this.class = "Property";
    }
    is(value) {
        return typeof value == "object" && this.criteria.is(value[this.name]);
    }
    toString() {
        return `${this.name}:${this.criteria.stringify(this.precedence)}`;
    }
}
exports.Property = Property;
Property.precedence = 80;
function property(name, criteria, value) {
    const result = (Array.isArray(name) ? name : [name]).reduceRight((r, p) => new Property(p, r), Rule_1.create(criteria));
    return value ? result.is(value) : result;
}
exports.property = property;
Rule_1.add(criteria => typeof criteria == "object" && !(criteria instanceof Rule_1.Rule) && !Array.isArray(criteria)
    ? And_1.and(...Object.getOwnPropertyNames(criteria).map(p => property(p, criteria[p])))
    : undefined);

});

const Property = /*@__PURE__*/getDefaultExportFromCjs(Property_1);

var Any_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.any = exports.Any = void 0;

class Any extends Rule_1.Rule {
    constructor(criteria) {
        super();
        this.criteria = criteria;
        this.precedence = 50;
        this.class = "Any";
    }
    is(value) {
        return (value &&
            typeof value == "object" &&
            Object.getOwnPropertyNames(value).some(property => this.criteria.is(value[property]) || this.is(value[property])));
    }
    toString() {
        return this.criteria.stringify(this.precedence);
    }
}
exports.Any = Any;
function any(criteria, value) {
    const result = new Any(Rule_1.create(criteria));
    return value ? result.is(value) : result;
}
exports.any = any;

});

const Any = /*@__PURE__*/getDefaultExportFromCjs(Any_1);

var And_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.and = exports.And = void 0;



class And extends Rule_1.Rule {
    constructor(rules) {
        super();
        this.precedence = 40;
        this.class = "And";
        this.rules = rules.reduce((r, e) => (e instanceof And ? [...r, ...e.rules] : [...r, e]), []);
    }
    is(value) {
        return this.rules.every(c => c.is(value));
    }
    toString() {
        return this.rules.map(c => c.stringify(this.precedence)).join(" ");
    }
    generalize() {
        return new And(this.rules.map(r => (r instanceof Property_1.Property ? r : new Any_1.Any(r))));
    }
}
exports.And = And;
function and(...criterias) {
    return new And(criterias.map(Rule_1.create));
}
exports.and = and;

});

const And = /*@__PURE__*/getDefaultExportFromCjs(And_1);

var EndsWith_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.endsWith = exports.EndsWith = void 0;

class EndsWith extends Rule_1.Rule {
    constructor(needle) {
        super();
        this.needle = needle;
        this.precedence = Number.MAX_SAFE_INTEGER;
        this.class = "EndsWith";
    }
    is(value) {
        return typeof value == "string" && value.endsWith(this.needle);
    }
    toString() {
        return `*${this.needle}`;
    }
}
exports.EndsWith = EndsWith;
function endsWith(needle, value) {
    const result = new EndsWith(needle);
    return value ? result.is(value) : result;
}
exports.endsWith = endsWith;

});

const EndsWith = /*@__PURE__*/getDefaultExportFromCjs(EndsWith_1);

var Every_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.every = exports.Every = void 0;

class Every extends Rule_1.Rule {
    constructor(criteria) {
        super();
        this.criteria = criteria;
        this.precedence = Number.MAX_SAFE_INTEGER;
        this.class = "Every";
    }
    is(value) {
        return Array.isArray(value) && value.every(v => this.criteria.is(v));
    }
    toString() {
        return `every(${this.criteria.toString()})`;
    }
}
exports.Every = Every;
function every(criteria, value) {
    const result = new Every(Rule_1.create(criteria));
    return value ? result.is(value) : result;
}
exports.every = every;

});

const Every = /*@__PURE__*/getDefaultExportFromCjs(Every_1);

var Includes_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.includes = exports.Includes = void 0;

class Includes extends Rule_1.Rule {
    constructor(needle) {
        super();
        this.needle = needle;
        this.precedence = Number.MAX_SAFE_INTEGER;
        this.class = "Includes";
    }
    is(value) {
        return typeof value == "string" && value.includes(this.needle);
    }
    toString() {
        return `*${this.needle}*`;
    }
}
exports.Includes = Includes;
function includes(needle, value) {
    const result = new Includes(needle);
    return value ? result.is(value) : result;
}
exports.includes = includes;

});

const Includes = /*@__PURE__*/getDefaultExportFromCjs(Includes_1);

var Is_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.is = exports.Is = void 0;

class Is extends Rule_1.Rule {
    constructor(value) {
        super();
        this.value = value;
        this.precedence = Number.MAX_SAFE_INTEGER;
        this.class = "Is";
    }
    is(value) {
        return value == this.value;
    }
    toString() {
        return this.value.toString();
    }
}
exports.Is = Is;
function is(criteria, value) {
    const result = new Is(criteria);
    return value ? result.is(value) : result;
}
exports.is = is;
Rule_1.add(criteria => typeof criteria == "bigint" ||
    typeof criteria == "boolean" ||
    typeof criteria == "number" ||
    typeof criteria == "string"
    ? new Is(criteria)
    : undefined);

});

const Is = /*@__PURE__*/getDefaultExportFromCjs(Is_1);

var Match_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.match = exports.Match = void 0;

class Match extends Rule_1.Rule {
    constructor(criteria) {
        super();
        this.criteria = criteria;
        this.precedence = Number.MAX_SAFE_INTEGER;
        this.class = "Match";
    }
    is(value) {
        return typeof value == "string" && this.criteria.test(value);
    }
    toString() {
        return `/${this.criteria}/`;
    }
}
exports.Match = Match;
function match(criteria) {
    return new Match(criteria);
}
exports.match = match;

});

const Match = /*@__PURE__*/getDefaultExportFromCjs(Match_1);

var Not_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.not = exports.Not = void 0;

class Not extends Rule_1.Rule {
    constructor(criteria) {
        super();
        this.criteria = criteria;
        this.precedence = Not.precedence;
        this.class = "Not";
    }
    is(value) {
        return !this.criteria.is(value);
    }
    toString() {
        return `!${this.criteria.stringify(this.precedence)}`;
    }
}
exports.Not = Not;
Not.precedence = 90;
function not(criteria, value) {
    const result = new Not(Rule_1.create(criteria));
    return value ? result.is(value) : result;
}
exports.not = not;

});

const Not = /*@__PURE__*/getDefaultExportFromCjs(Not_1);

var Or_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.or = exports.Or = void 0;

class Or extends Rule_1.Rule {
    constructor(criterias) {
        super();
        this.precedence = Or.precedence;
        this.class = "Or";
        this.criteria = criterias.reduce((r, c) => (c instanceof Or ? [...r, ...c.criteria] : [...r, c]), []);
    }
    is(value) {
        return this.criteria.some(c => c.is(value));
    }
    toString() {
        return this.criteria.map(c => c.stringify(this.precedence)).join(" | ");
    }
}
exports.Or = Or;
Or.precedence = 30;
function or(...criterias) {
    return new Or(criterias.map(Rule_1.create));
}
exports.or = or;

});

const Or = /*@__PURE__*/getDefaultExportFromCjs(Or_1);

var Some_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.some = exports.Some = void 0;

class Some extends Rule_1.Rule {
    constructor(criteria) {
        super();
        this.criteria = criteria;
        this.precedence = Number.MAX_SAFE_INTEGER;
        this.class = "Some";
    }
    is(value) {
        return Array.isArray(value) && value.some(v => this.criteria.is(v));
    }
    toString() {
        return `some(${this.criteria.toString()})`;
    }
}
exports.Some = Some;
function some(criteria, value) {
    const result = new Some(Rule_1.create(criteria));
    return value ? result.is(value) : result;
}
exports.some = some;

});

const Some = /*@__PURE__*/getDefaultExportFromCjs(Some_1);

var StartsWith_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startsWith = exports.StartsWith = void 0;

class StartsWith extends Rule_1.Rule {
    constructor(needle) {
        super();
        this.needle = needle;
        this.precedence = Number.MAX_SAFE_INTEGER;
        this.class = "StartsWith";
    }
    is(value) {
        return typeof value == "string" && value.startsWith(this.needle);
    }
    toString() {
        return `${this.needle}*`;
    }
}
exports.StartsWith = StartsWith;
function startsWith(needle, value) {
    const result = new StartsWith(needle);
    return value ? result.is(value) : result;
}
exports.startsWith = startsWith;

});

const StartsWith = /*@__PURE__*/getDefaultExportFromCjs(StartsWith_1);

var Tuple_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tuple = void 0;

class Tuple extends Rule_1.Rule {
    constructor(criteria) {
        super();
        this.criteria = criteria;
        this.precedence = Number.MAX_SAFE_INTEGER;
        this.class = "Tuple";
    }
    is(value) {
        return this.criteria.length == value.length && this.criteria.every((c, index) => c.is(value[index]));
    }
    toString() {
        return `[${this.criteria.map(c => c.toString()).join(", ")}]`;
    }
}
exports.Tuple = Tuple;
Rule_1.add(criteria => (Array.isArray(criteria) ? new Tuple(criteria.map(Rule_1.create)) : undefined));

});

const Tuple = /*@__PURE__*/getDefaultExportFromCjs(Tuple_1);

var Level_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Level;
(function (Level) {
    Level[Level["Logging"] = 0] = "Logging";
    Level[Level["Debug"] = 1] = "Debug";
    Level[Level["Warning"] = 2] = "Warning";
    Level[Level["Recoverable"] = 3] = "Recoverable";
    Level[Level["Critical"] = 4] = "Critical";
})(Level = exports.Level || (exports.Level = {}));

});

const Level = /*@__PURE__*/getDefaultExportFromCjs(Level_1);

var Message_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class Message {
    constructor(description, level = Level_1.Level.Recoverable, type = "unknown", region) {
        this.description = description;
        this.level = level;
        this.type = type;
        this.region = region;
    }
    toString() {
        return Level_1.Level[this.level] + ": " + this.type + " error. " + this.description + (this.region ? " @ " + this.region.toString() : "");
    }
}
exports.Message = Message;

});

const Message = /*@__PURE__*/getDefaultExportFromCjs(Message_1);

var ConsoleHandler_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class ConsoleHandler {
    raise(message, level, type, region) {
        if (!(message instanceof Message_1.Message))
            message = new Message_1.Message(message, level, type, region);
        console.error(message.toString());
    }
}
exports.ConsoleHandler = ConsoleHandler;

});

const ConsoleHandler = /*@__PURE__*/getDefaultExportFromCjs(ConsoleHandler_1);

var Position_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Position {
    constructor(line, column) {
        this.line = line;
        this.column = column;
    }
    toString() {
        return "Ln " + this.line + ", Col " + this.column;
    }
}
exports.Position = Position;

});

const Position = /*@__PURE__*/getDefaultExportFromCjs(Position_1);

var Location_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class Location extends Position_1.Position {
    constructor(resource, line, column) {
        super(line, column);
        this.resource = resource;
    }
    toString() {
        return this.resource.toString() + " @ " + super.toString();
    }
}
exports.Location = Location;

});

const Location = /*@__PURE__*/getDefaultExportFromCjs(Location_1);

var Region_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Region {
    constructor(resource, start, end, content) {
        this.resource = resource;
        this.start = start;
        this.end = end;
        this.content = content;
    }
    merge(other) { return other ? new Region(this.resource, this.start, other.end, this.content ? this.content : "" + other.content ? other.content : "") : this; }
    toString() {
        let result = this.resource.toString();
        if (this.start && this.end)
            result += " (" + this.start.toString() + " - " + this.end.toString() + ") ";
        if (this.content)
            result += this.content;
        return result;
    }
}
exports.Region = Region;

});

const Region = /*@__PURE__*/getDefaultExportFromCjs(Region_1);

var _Error = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

exports.ConsoleHandler = ConsoleHandler_1.ConsoleHandler;

exports.Level = Level_1.Level;

exports.Location = Location_1.Location;

exports.Message = Message_1.Message;

exports.Position = Position_1.Position;

exports.Region = Region_1.Region;

});

const index = /*@__PURE__*/getDefaultExportFromCjs(_Error);

var User_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class User {
    constructor(name, password) {
        this.name = name;
        this.password = password;
    }
    get isEmpty() {
        return !this.name && !this.password;
    }
    toString() {
        let result = "";
        if (this.name)
            result = this.name;
        if (this.password)
            result += ":" + this.password;
        return result;
    }
    static parse(data) {
        let result;
        if (data) {
            const splitted = data.split(":", 2);
            result = new User(splitted[0], splitted[1]);
        }
        else
            result = new User();
        return result;
    }
}
exports.User = User;

});

const User = /*@__PURE__*/getDefaultExportFromCjs(User_1);

var Endpoint_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Endpoint {
    constructor(host = [], port) {
        this.host = host;
        this.port = port;
    }
    get isEmpty() {
        return this.host.length == 0 && !this.port;
    }
    toString() {
        let result = this.host.join(".");
        if (this.port)
            result += ":" + this.port.toString();
        return result;
    }
    static parse(data) {
        let result;
        if (data) {
            const splitted = data.split(":", 2);
            result = new Endpoint(splitted[0].split("."), splitted.length > 1 ? parseInt(splitted[1]) : undefined);
        }
        else
            result = new Endpoint();
        return result;
    }
}
exports.Endpoint = Endpoint;

});

const Endpoint = /*@__PURE__*/getDefaultExportFromCjs(Endpoint_1);

var Authority_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


class Authority {
    constructor(user = new User_1.User(), endpoint = new Endpoint_1.Endpoint()) {
        this.user = user;
        this.endpoint = endpoint;
    }
    get isEmpty() {
        return this.user.isEmpty && this.endpoint.isEmpty;
    }
    toString() {
        let result = "";
        if (!this.user.isEmpty)
            result = this.user.toString() + "@";
        if (!this.endpoint.isEmpty)
            result = result + this.endpoint.toString();
        return result;
    }
    static parse(data) {
        let result;
        if (data) {
            const splitted = data.split("@", 2);
            result = new Authority(User_1.User.parse(splitted.length == 2 ? splitted.pop() : undefined), Endpoint_1.Endpoint.parse(splitted.pop()));
        }
        return result;
    }
}
exports.Authority = Authority;

});

const Authority = /*@__PURE__*/getDefaultExportFromCjs(Authority_1);

var Locator_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class Locator {
    constructor(scheme = [], authority = new Authority_1.Authority(), path = [], query = {}, fragment) {
        this.scheme = scheme;
        this.authority = authority;
        this.path = path;
        this.query = query;
        this.fragment = fragment;
    }
    get isRelative() {
        return this.path[0] == "." || this.path[0] == "..";
    }
    get isFolder() {
        return this.path[this.path.length - 1] == "";
    }
    get folder() {
        return this.isFolder ? this : new Locator(this.scheme, this.authority, this.path.filter((value, index) => index < this.path.length - 1), this.query, this.fragment);
    }
    get name() {
        return this.path[this.path.length - 1];
    }
    get extension() {
        const splitted = this.name.split(".");
        return splitted.length > 1 ? splitted[splitted.length - 1] : "";
    }
    createArray(value, count) {
        const result = [];
        while (count-- > 0)
            result.push(value);
        return result;
    }
    normalize() {
        let skip = 0;
        const path = this.path.reverse().filter((item, index) => {
            let r = false;
            if ((item == "" || item == ".") && index < this.path.length - 1)
                r = false;
            else if (item == "..")
                skip++;
            else if (skip > 0)
                skip--;
            else
                r = true;
            return r;
        }).concat(this.createArray("..", skip)).reverse();
        return new Locator(this.scheme, this.authority, path, this.query, this.fragment);
    }
    resolve(absolute) {
        return !absolute ? this : new Locator(this.scheme.length > 0 ? this.scheme : absolute.scheme, !this.authority.isEmpty ? this.authority : absolute.authority, this.isRelative ? absolute.folder.path.concat(this.path) : this.path, this.query, this.fragment).normalize();
    }
    appendPath(path) {
        return new Locator(this.scheme, this.authority, path instanceof Array ? [...this.path, ...path] : [...this.path, path], this.query, this.fragment);
    }
    toString() {
        let result = "";
        if (this.scheme.length > 0)
            result += this.scheme.join("+") + ":";
        if (!this.authority.isEmpty)
            result += "//" + this.authority.toString();
        else if (this.scheme.length > 0)
            result += "//";
        if (this.path) {
            let path = this.path.join("/");
            if (path[0] != "." || result.length > 0)
                path = "/" + path;
            result += path;
        }
        if (Object.keys(this.query).length > 0)
            result += "?" + this.query.toString();
        if (this.fragment)
            result += "#" + this.fragment;
        return result;
    }
    static parse(data) {
        let result;
        switch (data) {
            case "":
            case null:
            case undefined:
                break;
            default:
                let hasAuthority = true;
                let scheme = [];
                let splitted = data.split("://", 2);
                if (splitted.length > 1) {
                    scheme = (splitted.shift() || "").split("+");
                    data = splitted.shift();
                }
                else if (data.slice(0, 2) == "//")
                    data = data.slice(2);
                else
                    hasAuthority = false;
                let index;
                let fragment;
                if (data && (index = data.lastIndexOf("#")) > -1) {
                    fragment = data.slice(index + 1);
                    data = data.slice(0, index);
                }
                let query = {};
                if (data && (index = data.lastIndexOf("?")) > -1) {
                    query = new Object();
                    data.slice(index + 1).split(";").forEach(element => {
                        splitted = element.split("=");
                        const key = splitted.shift();
                        const value = splitted.shift();
                        if (key && value)
                            query[key] = value;
                    });
                    data = data.slice(0, index);
                }
                let authority;
                let path = [];
                if (data) {
                    splitted = data.split("/");
                    if (splitted.length > 0) {
                        switch (splitted[0]) {
                            case ".":
                            case "..":
                                break;
                            case "":
                                splitted.shift();
                                break;
                            default:
                                if (hasAuthority)
                                    authority = Authority_1.Authority.parse(splitted.shift());
                                else
                                    splitted.unshift(".");
                                break;
                        }
                        path = splitted;
                    }
                }
                result = new Locator(scheme, authority, path, query, fragment);
                break;
        }
        return result;
    }
}
exports.Locator = Locator;
Locator.empty = new Locator(undefined, undefined, undefined, undefined, undefined);

});

const Locator = /*@__PURE__*/getDefaultExportFromCjs(Locator_1);

var Uri = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

exports.Authority = Authority_1.Authority;

exports.Endpoint = Endpoint_1.Endpoint;

exports.Locator = Locator_1.Locator;

exports.User = User_1.User;

});

const index$1 = /*@__PURE__*/getDefaultExportFromCjs(Uri);

var Device_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Device {
}
exports.Device = Device;

});

const Device = /*@__PURE__*/getDefaultExportFromCjs(Device_1);

var InDevice_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class InDevice extends Device_1.Device {
}
exports.InDevice = InDevice;

});

const InDevice = /*@__PURE__*/getDefaultExportFromCjs(InDevice_1);

var Reader_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class Reader extends InDevice_1.InDevice {
    static addOpener(open, priority) {
        if (!priority)
            priority = 0;
        Reader.openers.push({ open, priority });
        Reader.openers = Reader.openers.sort((left, right) => right.priority - left.priority);
    }
    static open(locator) {
        let result;
        let i = 0;
        do
            result = Reader.openers[i++].open(locator);
        while (!result && i < Reader.openers.length);
        return result;
    }
}
exports.Reader = Reader;
Reader.openers = [];

});

const Reader = /*@__PURE__*/getDefaultExportFromCjs(Reader_1);

var BufferedReader_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });



var Reader_2 = Reader_1;
exports.Reader = Reader_2.Reader;
class BufferedReader extends Reader_1.Reader {
    constructor(backend) {
        super();
        this.backend = backend;
        this.buffer = [];
        this.lastContent = "";
        this.lastMark = this.locationValue = this.backend.location;
    }
    get tabSize() { return this.backend.tabSize; }
    set tabSize(size) { this.backend.tabSize = size; }
    get readable() { return !!this.backend; }
    get opened() { return !!this.backend; }
    get isEmpty() { return (this.buffer.length == 0 || this.buffer[0].data == "\0") && this.backend.isEmpty; }
    get resource() {
        const location = this.location;
        return location ? location.resource : Uri.Locator.empty;
    }
    get location() {
        return this.locationValue;
    }
    get region() {
        return new _Error.Region(this.resource, this.lastMark, this.location, this.lastContent);
    }
    close() {
        return this.backend.close();
    }
    peek(length) {
        if (!length)
            length = 1;
        let next;
        while (length > this.buffer.length && (next = this.backend.read()))
            this.buffer.push({ data: next, location: this.backend.location });
        return this.buffer.length == 0 ? undefined : this.buffer.slice(0, length > this.buffer.length ? this.buffer.length : length).map(value => value.data).join("");
    }
    read(length) {
        if (!length)
            length = 1;
        const result = this.peek(length);
        if (result && result.length > 0) {
            this.locationValue = this.buffer[result.length - 1].location;
            this.buffer.splice(0, result.length);
            this.lastContent += result;
        }
        return result;
    }
    peekIs(value, count) {
        let result;
        if (value)
            if (typeof (value) == "string") {
                const v = value;
                while (count && count-- > 0)
                    value += v;
                result = this.peek(value.length) == value ? value : undefined;
            }
            else if (value.length > 0 && !(result = this.peekIs(value[0])) && value.length)
                result = this.peekIs(value.slice(1));
        return result;
    }
    readIf(value) {
        let result;
        if (value)
            if (typeof (value) == "string")
                result = this.peek(value.length) == value && this.read(value.length) || undefined;
            else if (value.length > 0 && !(result = this.readIf(value[0])) && value.length)
                result = this.readIf(value.slice(1));
        return result;
    }
    readAll() {
        let result = "";
        while (this.peek())
            result += this.read();
        return result != "" ? result : undefined;
    }
    mark() {
        const result = this.region;
        this.lastMark = this.location;
        this.lastContent = "";
        return result;
    }
    static create(backend) {
        return backend ? new BufferedReader(backend) : undefined;
    }
}
exports.BufferedReader = BufferedReader;

});

const BufferedReader = /*@__PURE__*/getDefaultExportFromCjs(BufferedReader_1);

var fs_browser = createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
function close(fd) {
    return __awaiter(this, void 0, void 0, function* () { });
}
exports.close = close;
function fsync(fd) {
    return __awaiter(this, void 0, void 0, function* () { });
}
exports.fsync = fsync;
function open(path, flags, mode) {
    return __awaiter(this, void 0, void 0, function* () { return 0; });
}
exports.open = open;
function write(fd, buffer, offset, encoding) {
    return __awaiter(this, void 0, void 0, function* () { return { bytesWritten: 0 }; });
}
exports.write = write;
function lstatSync(path, options) { return { isDirectory: () => false }; }
exports.lstatSync = lstatSync;
function readdirSync(path) { return []; }
exports.readdirSync = readdirSync;
function readFileSync(path, encoding) { return ""; }
exports.readFileSync = readFileSync;

});

const fs_browser$1 = /*@__PURE__*/getDefaultExportFromCjs(fs_browser);

var path_browser = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const sep = "/";
exports.sep = sep;

});

const path_browser$1 = /*@__PURE__*/getDefaultExportFromCjs(path_browser);

var StringReader_1 = createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });



class StringReader extends Reader_1.Reader {
    constructor(content, resource) {
        super();
        this.content = content;
        this.resource = resource;
        this.tabSize = 2;
        this.count = 0;
        this.line = 1;
        this.column = 1;
        this.lastContent = "";
        this.readable = true;
        this.content += "\0";
        this.lastPosition = this.location;
    }
    get opened() { return this.count + 1 >= this.content.length; }
    get isEmpty() { return this.opened; }
    get location() { return new _Error.Location(this.resource, this.line, this.column); }
    get region() { return new _Error.Region(this.resource, this.lastPosition, this.location, this.lastContent); }
    close() {
        return __awaiter(this, void 0, void 0, function* () {
            const result = !(yield this.isEmpty);
            if (result)
                this.count = this.content.length;
            return result;
        });
    }
    read() {
        let result;
        if (this.count < this.content.length)
            result = this.content.charAt(this.count);
        else if (this.count == this.content.length)
            result = undefined;
        this.count++;
        if (result) {
            switch (result) {
                case "\n":
                    this.line++;
                    this.column = 1;
                    break;
                case "\t":
                    this.column += this.tabSize;
                    break;
                default:
                    this.column++;
                    break;
            }
            this.lastContent += result;
        }
        return result;
    }
    mark() {
        const result = this.region;
        this.lastPosition = this.location;
        this.lastContent = "";
        return result;
    }
    static create(content, resource) {
        return content != undefined ? new StringReader(content, resource || Uri.Locator.empty) : undefined;
    }
}
exports.StringReader = StringReader;

});

const StringReader = /*@__PURE__*/getDefaultExportFromCjs(StringReader_1);

var FileReader_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });





class FileReader extends Reader_1.Reader {
    constructor(backend) {
        super();
        this.backend = backend;
    }
    get tabSize() { return this.backend.tabSize; }
    set tabSize(size) { this.backend.tabSize = size; }
    get readable() { return this.backend.readable; }
    get opened() { return this.backend.opened; }
    get isEmpty() { return this.backend.isEmpty; }
    get resource() { return this.backend ? this.backend.resource : Uri.Locator.empty; }
    get location() { return this.backend.location; }
    get region() { return this.backend.region; }
    close() {
        return this.backend.close();
    }
    read() { return this.backend.read(); }
    mark() { return this.backend.mark(); }
    static open(resource) {
        let backend;
        if (resource && (resource.scheme.length == 0 || resource.scheme.length == 1 && resource.scheme[0] == "file"))
            try {
                backend = StringReader_1.StringReader.create(fs_browser.readFileSync((resource.isRelative ? "" : path_browser.sep) + resource.path.join(path_browser.sep), "utf-8"), resource);
            }
            catch (error) {
                console.log(`Failed to open file: ${resource.toString()}`);
            }
        return backend ? new FileReader(backend) : undefined;
    }
}
exports.FileReader = FileReader;
Reader_1.Reader.addOpener(p => FileReader.open(p), 10);

});

const FileReader = /*@__PURE__*/getDefaultExportFromCjs(FileReader_1);

var FolderReader_1 = createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });






class FolderReader extends Reader_1.Reader {
    constructor(files) {
        super();
        this.files = files;
        this.tabSizeValue = 2;
        this.lastLocation = new _Error.Location(Uri.Locator.empty, 0, 0);
    }
    get tabSize() { return this.tabSizeValue; }
    set tabSize(size) {
        this.tabSizeValue = size;
        if (this.current)
            this.current.tabSize = size;
    }
    get readable() { return this.current != undefined && this.current.readable || this.files.length > 0; }
    get opened() { return this.current != undefined || this.files.length > 0; }
    get isEmpty() { return this.files.length == 0 && (!this.current || this.current.isEmpty); }
    get resource() { return this.current ? this.current.resource : this.lastLocation.resource; }
    get location() { return this.current ? this.current.location : this.lastLocation; }
    get region() { return this.current ? this.current.region : new _Error.Region(this.resource); }
    close() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.current != undefined && (yield this.current.close());
        });
    }
    read() {
        let result;
        if (!this.current && this.files.length > 0) {
            this.current = FileReader_1.FileReader.open(this.files.shift());
            this.current.tabSize = this.tabSize;
        }
        if (this.current) {
            result = this.current.read();
            if (result == undefined || result == "\0") {
                this.current.close();
                this.current = undefined;
            }
        }
        this.lastLocation = this.location;
        return result;
    }
    mark() { return this.current ? this.current.mark() : new _Error.Region(this.resource); }
    static getFiles(folder, filetype, ignoreFiles = []) {
        let result = [];
        const files = fs_browser.readdirSync(folder);
        files.forEach(file => {
            const filename = folder + path_browser.sep + file;
            if (ignoreFiles.indexOf(filename) == -1) {
                if (fs_browser.lstatSync(filename).isDirectory())
                    result = result.concat(FolderReader.getFiles(filename, filetype, ignoreFiles));
                else if (file.length > filetype.length && file.lastIndexOf(filetype, file.length - filetype.length) === file.length - filetype.length)
                    result.push(filename);
            }
        });
        return result;
    }
    static open(resource) {
        let files;
        try {
            if (resource && (resource.scheme.length == 0 || resource.scheme.length == 1 && resource.scheme[0] == "file") && resource.isFolder || resource.name.match("*"))
                files = FolderReader.getFiles((resource.isRelative ? "" : path_browser.sep) + resource.folder.path.join(path_browser.sep), resource.extension);
        }
        catch (error) {
        }
        return files ? new FolderReader(files.map(f => new Uri.Locator(["file"], undefined, f.split(path_browser.sep)))) : undefined;
    }
}
exports.FolderReader = FolderReader;
Reader_1.Reader.addOpener((resource) => FolderReader.open(resource), 0);

});

const FolderReader = /*@__PURE__*/getDefaultExportFromCjs(FolderReader_1);

var Enumerator_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function* generate(next) {
    let result;
    while ((result = next()) != undefined)
        yield result;
}
function isIterator(item) {
    return item.next instanceof Function;
}
function* merge(left, right) {
    let result;
    while (!(result = left.next()).done)
        yield result.value;
    if (isIterator(right))
        while (!(result = right.next()).done)
            yield result.value;
    else
        yield right;
}
class Enumerator {
    constructor(backend) {
        this.iterator = backend instanceof Function ? generate(backend) : backend;
    }
    get length() {
        let result = 0;
        while (!this.next().done)
            result++;
        return result;
    }
    get last() {
        return this.nextValue && !this.nextValue.done ? this.nextValue.value : undefined;
    }
    fetch() {
        const result = this.next();
        return result.done ? undefined : result.value;
    }
    next(value) {
        return this.nextValue = this.iterator.next(value);
    }
    append(item) {
        return new Enumerator(merge(this, item));
    }
    map(mapping) {
        return new Enumerator(() => {
            const item = this.fetch();
            return (item != undefined) ? mapping(item) : undefined;
        });
    }
    reduce(reduce, result) {
        const item = this.fetch();
        return item ? this.reduce(reduce, reduce(result, item)) : result;
    }
    apply(apply) {
        const item = this.fetch();
        if (item) {
            apply(item);
            this.apply(apply);
        }
    }
    filter(filter) {
        return new Enumerator(() => {
            let item;
            do
                item = this.fetch();
            while (item != undefined && !filter(item));
            return item;
        });
    }
    toArray() {
        const item = this.fetch();
        let result;
        if (!item)
            result = [];
        else {
            result = this.toArray();
            result.unshift(item);
        }
        return result;
    }
    static from(backend) {
        return new Enumerator(backend);
    }
}
exports.Enumerator = Enumerator;
Enumerator.empty = Enumerator.from(() => undefined);

});

const Enumerator = /*@__PURE__*/getDefaultExportFromCjs(Enumerator_1);

var Enumerable_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

function isIterable(other) {
    return other == null ? false : typeof other[Symbol.iterator] === "function";
}
class Enumerable {
    constructor(get) {
        this.get = get;
    }
    get length() {
        return this.get().length;
    }
    get first() {
        return this.get().fetch();
    }
    get last() {
        return this.get().last;
    }
    getEnumerator() {
        return new Enumerator_1.Enumerator(this.get());
    }
    [Symbol.iterator]() {
        return this.getEnumerator();
    }
    append(item) {
        return new Enumerable(() => this.get().append(item));
    }
    map(mapping) {
        return new Enumerable(() => this.get().map(mapping));
    }
    reduce(reduce, result) {
        return this.get().reduce(reduce, result);
    }
    apply(apply) {
        this.get().apply(apply);
    }
    filter(filter) {
        return new Enumerable(() => this.get().filter(filter));
    }
    toArray() {
        return this.getEnumerator().toArray();
    }
    static from(get) {
        return isIterable(get) ? new Enumerable(() => new Enumerator_1.Enumerator(get[Symbol.iterator]())) : new Enumerable(() => {
            const r = get();
            return r instanceof Enumerator_1.Enumerator ? r : new Enumerator_1.Enumerator(r);
        });
    }
}
exports.Enumerable = Enumerable;
Enumerable.empty = Enumerable.from([]);

});

const Enumerable = /*@__PURE__*/getDefaultExportFromCjs(Enumerable_1);

var ArrayEnumerator_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class ArrayEnumerator extends Enumerator_1.Enumerator {
    constructor(backend) {
        super(() => this.position < this.backend.length ? this.backend[this.position++] : undefined);
        this.backend = backend;
        this.position = 0;
    }
}
exports.ArrayEnumerator = ArrayEnumerator;

});

const ArrayEnumerator = /*@__PURE__*/getDefaultExportFromCjs(ArrayEnumerator_1);

var BufferedEnumerator_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class BufferedEnumerator extends Enumerator_1.Enumerator {
    constructor(backend) {
        super(() => {
            const result = this.peek(0);
            if (this.buffer.length > 0)
                this.buffer.shift();
            return result;
        });
        this.backend = backend;
        this.buffer = [];
    }
    peek(position) {
        if (!position)
            position = 0;
        let next;
        while (position > this.buffer.length - 1 && (next = this.backend.fetch()))
            this.buffer.push(next);
        return position > this.buffer.length - 1 ? undefined : this.buffer[position];
    }
}
exports.BufferedEnumerator = BufferedEnumerator;

});

const BufferedEnumerator = /*@__PURE__*/getDefaultExportFromCjs(BufferedEnumerator_1);

var _String = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class String {
    static padLeft(value, paddingCharacter, width) {
        return String.pad(value, paddingCharacter, width, true);
    }
    static padRight(value, paddingCharacter, width) {
        return String.pad(value, paddingCharacter, width, false);
    }
    static pad(value, paddingCharacter, width, padLeft) {
        let padding = "";
        const count = width - value.length;
        for (let i = 0; i < count; i++)
            padding += paddingCharacter;
        return padLeft ? padding + value : value + padding;
    }
}
exports.String = String;

});

const _String$1 = /*@__PURE__*/getDefaultExportFromCjs(_String);

var Utilities = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

exports.Enumerator = Enumerator_1.Enumerator;

exports.Enumerable = Enumerable_1.Enumerable;

exports.ArrayEnumerator = ArrayEnumerator_1.ArrayEnumerator;

exports.BufferedEnumerator = BufferedEnumerator_1.BufferedEnumerator;

exports.String = _String.String;

});

const index$2 = /*@__PURE__*/getDefaultExportFromCjs(Utilities);

var OutDevice_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class OutDevice extends Device_1.Device {
}
exports.OutDevice = OutDevice;

});

const OutDevice = /*@__PURE__*/getDefaultExportFromCjs(OutDevice_1);

var Writer_1 = createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });



class Writer extends OutDevice_1.OutDevice {
    constructor() {
        super(...arguments);
        this.newLineSymbol = "\n";
    }
    write(message) {
        return __awaiter(this, void 0, void 0, function* () {
            return message instanceof Utilities.Enumerator ? this.writeImplementation(message) :
                message instanceof Array ? this.writeImplementation(new Utilities.ArrayEnumerator(message)) :
                    this.writeImplementation(new Utilities.ArrayEnumerator([message]));
        });
    }
    writeLine(message) {
        return __awaiter(this, void 0, void 0, function* () {
            return message instanceof Utilities.Enumerator ? this.writeImplementation(message.append(this.newLineSymbol)) :
                message instanceof Array ? this.writeImplementation(new Utilities.ArrayEnumerator([...message, this.newLineSymbol])) :
                    message ? this.writeImplementation(new Utilities.ArrayEnumerator([message, this.newLineSymbol])) :
                        this.writeImplementation(new Utilities.ArrayEnumerator([this.newLineSymbol]));
        });
    }
    static addOpener(open, priority) {
        if (!priority)
            priority = 0;
        Writer.openers.push({ open, priority });
        Writer.openers = Writer.openers.sort((left, right) => right.priority - left.priority);
    }
    static open(resource) {
        return __awaiter(this, void 0, void 0, function* () {
            let result;
            if (typeof (resource) == "string") {
                const r = Uri.Locator.parse(resource);
                result = r ? yield Writer.open(r) : undefined;
            }
            else {
                let i = 0;
                do
                    result = yield Writer.openers[i++].open(resource);
                while (!result && i < Writer.openers.length);
            }
            return result;
        });
    }
}
exports.Writer = Writer;
Writer.openers = [];

});

const Writer = /*@__PURE__*/getDefaultExportFromCjs(Writer_1);

var Indenter_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class Indenter extends Writer_1.Writer {
    constructor(backend) {
        super();
        this.backend = backend;
        this.autoFlush = true;
        this.indentionSymbol = "\t";
        this.indentionCount = 0;
        this.indentNext = false;
    }
    get resource() { return this.backend.resource; }
    get opened() { return this.backend.opened; }
    get writable() { return this.backend.writable; }
    flush() {
        return this.backend.flush();
    }
    close() {
        return this.backend.close();
    }
    increase() {
        this.indentionCount++;
        return true;
    }
    decrease() {
        this.indentionCount--;
        return this.indentionCount >= 0;
    }
    getIndention() {
        return this.indentionSymbol.repeat(this.indentionCount);
    }
    writeImplementation(buffer) {
        const result = [];
        let item;
        let next = buffer.fetch();
        if (next)
            do {
                item = next;
                next = buffer.fetch();
                if (this.indentNext)
                    item = this.getIndention() + item;
                this.indentNext = item.endsWith(this.newLineSymbol);
                item = item.replace(this.newLineSymbol, this.newLineSymbol + this.getIndention());
                if (this.indentNext)
                    item = item.substring(0, item.length - this.indentionCount * this.indentionSymbol.length);
                result.push(this.backend.write(item));
            } while (next);
        return Promise.all(result).then(r => r.reduce((previous, current) => previous && current, true));
    }
}
exports.Indenter = Indenter;

});

const Indenter = /*@__PURE__*/getDefaultExportFromCjs(Indenter_1);

var PrefixReader_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


class PrefixReader extends Reader_1.Reader {
    constructor(backend, prefix) {
        super();
        this.prefix = prefix;
        this.done = false;
        this.backend = backend instanceof BufferedReader_1.BufferedReader ? backend : BufferedReader_1.BufferedReader.create(backend);
    }
    get tabSize() { return this.backend.tabSize; }
    set tabSize(size) { this.backend.tabSize = size; }
    get readable() { return this.backend.readable; }
    get opened() { return this.backend.opened; }
    get isEmpty() { return this.done || this.backend.isEmpty; }
    get resource() { return this.backend.resource; }
    get location() { return this.backend.location; }
    get region() { return this.backend.region; }
    close() {
        return this.backend.close();
    }
    read() {
        let result;
        if (!this.done) {
            result = this.backend.read();
            this.done = result == "\n" && !this.backend.readIf(this.prefix) && !this.backend.peekIs("\n");
        }
        return result;
    }
    mark() { return this.backend.mark(); }
    static create(backend, prefix) {
        return backend && prefix ? new PrefixReader(backend, prefix) : backend;
    }
}
exports.PrefixReader = PrefixReader;

});

const PrefixReader = /*@__PURE__*/getDefaultExportFromCjs(PrefixReader_1);

var FileWriter_1 = createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (commonjsGlobal && commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });



class FileWriter extends Writer_1.Writer {
    constructor(resource, descriptor) {
        super();
        this.resource = resource;
        this.descriptor = descriptor;
        this.autoFlush = false;
    }
    get opened() { return this.descriptor > 0; }
    get writable() { return this.descriptor > 0; }
    flush() {
        return __awaiter(this, void 0, void 0, function* () {
            let result = true;
            try {
                yield fs_browser.fsync(this.descriptor);
            }
            catch (error) {
                result = false;
            }
            return result;
        });
    }
    close() {
        return __awaiter(this, void 0, void 0, function* () {
            let result = this.opened;
            if (result) {
                try {
                    yield fs_browser.close(this.descriptor);
                }
                catch (error) {
                    result = false;
                }
                this.descriptor = 0;
            }
            return result;
        });
    }
    writeImplementation(buffer) {
        return __awaiter(this, void 0, void 0, function* () {
            let result = true;
            const content = Buffer.from(buffer.reduce((r, item) => r + item, ""));
            try {
                const r = yield fs_browser.write(this.descriptor, content, 0, "utf8");
                result = r.bytesWritten == content.length;
            }
            catch (error) {
                result = false;
            }
            return result && (!this.autoFlush || (yield this.flush()));
        });
    }
    static open(resource) {
        return __awaiter(this, void 0, void 0, function* () {
            let backend;
            if (resource && (resource.scheme.length == 0 || resource.scheme.length == 1 && resource.scheme[0] == "file"))
                try {
                    backend = yield fs_browser.open((resource.isRelative ? "" : path_browser.sep) + resource.path.join(path_browser.sep), "w");
                }
                catch (error) {
                    backend = undefined;
                }
            return backend ? new FileWriter(resource, backend) : undefined;
        });
    }
}
exports.FileWriter = FileWriter;
Writer_1.Writer.addOpener(FileWriter.open);

});

const FileWriter = /*@__PURE__*/getDefaultExportFromCjs(FileWriter_1);

var TillReader_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


class TillReader extends Reader_1.Reader {
    constructor(backend, endMark) {
        super();
        this.endMark = endMark;
        this.done = false;
        this.backend = backend instanceof BufferedReader_1.BufferedReader ? backend : BufferedReader_1.BufferedReader.create(backend);
        this.done = this.backend.peekIs(this.endMark) != undefined;
    }
    get tabSize() { return this.backend.tabSize; }
    set tabSize(size) { this.backend.tabSize = size; }
    get readable() { return this.backend.readable; }
    get opened() { return !this.done && this.backend.opened; }
    get isEmpty() { return this.done || this.backend.isEmpty; }
    get resource() { return this.backend.resource; }
    get location() { return this.backend.location; }
    get region() { return this.backend.region; }
    close() {
        const result = !this.done;
        if (result)
            this.done = true;
        return Promise.resolve(result);
    }
    read() {
        let result;
        if (!this.done) {
            result = this.backend.read();
            this.done = this.backend.peekIs(this.endMark) != undefined;
        }
        return result;
    }
    mark() { return this.backend.mark(); }
    static create(backend, endMark) {
        return backend && endMark ? new TillReader(backend, endMark) : backend;
    }
}
exports.TillReader = TillReader;

});

const TillReader = /*@__PURE__*/getDefaultExportFromCjs(TillReader_1);

var UntilReader_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


class UntilReader extends Reader_1.Reader {
    constructor(backend, endMark) {
        super();
        this.endMark = endMark;
        this.done = -1;
        this.backend = backend instanceof BufferedReader_1.BufferedReader ? backend : BufferedReader_1.BufferedReader.create(backend);
        const peeked = this.backend.peekIs(this.endMark);
        if (peeked)
            this.done = peeked.length;
    }
    get tabSize() { return this.backend.tabSize; }
    set tabSize(size) { this.backend.tabSize = size; }
    get readable() { return this.backend.readable; }
    get opened() { return !this.done && this.backend.opened; }
    get isEmpty() { return this.done == 0 || this.backend.isEmpty; }
    get resource() { return this.backend.resource; }
    get location() { return this.backend.location; }
    get region() { return this.backend.region; }
    close() {
        const result = this.done > 0;
        if (result)
            this.done = 0;
        return Promise.resolve(result);
    }
    read() {
        let result;
        if (this.done != 0) {
            result = this.backend.read();
            let peeked;
            if (this.done > 0)
                this.done--;
            else if (peeked = this.backend.peekIs(this.endMark))
                this.done = peeked.length;
        }
        return result;
    }
    mark() { return this.backend.mark(); }
    static create(backend, endMark) {
        return backend && endMark ? new UntilReader(backend, endMark) : backend;
    }
}
exports.UntilReader = UntilReader;

});

const UntilReader = /*@__PURE__*/getDefaultExportFromCjs(UntilReader_1);

var IO = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

exports.BufferedReader = BufferedReader_1.BufferedReader;

exports.Device = Device_1.Device;

exports.FileReader = FileReader_1.FileReader;

exports.FolderReader = FolderReader_1.FolderReader;

exports.Indenter = Indenter_1.Indenter;

exports.InDevice = InDevice_1.InDevice;

exports.OutDevice = OutDevice_1.OutDevice;

exports.PrefixReader = PrefixReader_1.PrefixReader;

exports.Reader = Reader_1.Reader;

exports.StringReader = StringReader_1.StringReader;

exports.FileWriter = FileWriter_1.FileWriter;

exports.TillReader = TillReader_1.TillReader;

exports.UntilReader = UntilReader_1.UntilReader;

exports.Writer = Writer_1.Writer;

});

const index$3 = /*@__PURE__*/getDefaultExportFromCjs(IO);

var build = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

exports.Error = _Error;

exports.IO = IO;

exports.Uri = Uri;

exports.Utilities = Utilities;

});

const index$4 = /*@__PURE__*/getDefaultExportFromCjs(build);

var Source_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Source = void 0;

class Source extends build.IO.BufferedReader {
    constructor(reader, errorHandler) {
        super(typeof reader == "string" ? build.IO.StringReader.create(reader) : reader);
        this.errorHandler = errorHandler;
    }
    raise(message, level, type = "lexical", region) {
        if (!(message instanceof build.Error.Message)) {
            if (!level)
                level = build.Error.Level.Critical;
            if (!region)
                region = this.region;
            message = new build.Error.Message(message, level, type, region);
        }
        if (this.errorHandler)
            this.errorHandler.raise(message);
    }
    requirePrefix(prefix) {
        return new Source(new build.IO.PrefixReader(this, prefix), this.errorHandler);
    }
    till(endMark) {
        return new Source(build.IO.TillReader.create(this, endMark), this.errorHandler);
    }
    until(endMark) {
        return new Source(build.IO.UntilReader.create(this, endMark), this.errorHandler);
    }
    peekIsSymbol() {
        return !!this.peekIs(["!", "(", ")", "[", "]", "|", "*", ":", "."]);
    }
    peekIsWhitespace() {
        return !!this.peekIs([" ", "\n", "\t"]);
    }
}
exports.Source = Source;

});

const Source = /*@__PURE__*/getDefaultExportFromCjs(Source_1);

var lexer = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tokenize = exports.Source = void 0;


Object.defineProperty(exports, "Source", { enumerable: true, get: function () { return Source_1.Source; } });
function tokenize(reader, errorHandler) {
    const source = new Source_1.Source(reader, errorHandler);
    return new build.Utilities.Enumerator(() => {
        let result;
        if (!source.isEmpty) {
            while (source.peekIsWhitespace())
                source.read();
            if (source.peekIsSymbol())
                result = { value: source.read() || "", region: source.mark() };
            else {
                let value = "";
                while (!source.isEmpty && !source.peekIsWhitespace() && !source.peekIsSymbol())
                    value += source.read();
                if (value)
                    result = { value, region: source.mark() };
            }
        }
        return result;
    });
}
exports.tokenize = tokenize;

});

const index$5 = /*@__PURE__*/getDefaultExportFromCjs(lexer);

var Source_1$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Source = void 0;

class Source extends build.Utilities.BufferedEnumerator {
    constructor(tokens, errorHandler) {
        super(Array.isArray(tokens) ? new build.Utilities.ArrayEnumerator(tokens) : tokens);
        this.errorHandler = errorHandler;
    }
    clone(start = "(", end = ")") {
        let nestingCount = 0;
        return new Source(new build.Utilities.Enumerator(() => {
            let result;
            if (this.peekIs(start))
                nestingCount++;
            else if (this.peekIs(end))
                nestingCount--;
            if (nestingCount >= 0)
                result = this.fetch();
            return result;
        }), this);
    }
    peekIs(...needles) {
        return needles.every((needle, index) => {
            const peeked = this.peek(index);
            return peeked && peeked.value && Source.is(needle, peeked.value);
        });
    }
    fetchIf(...needles) {
        const result = [];
        if (this.peekIs(...needles))
            needles.forEach(_ => result.push(this.fetch()));
        return needles.length == 1
            ? result.length == 1
                ? result[0]
                : undefined
            : needles.length == result.length
                ? result
                : undefined;
    }
    mark() {
        return build.Utilities.Enumerable.from(build.Utilities.Enumerable.empty);
    }
    raise(message, level = build.Error.Level.Critical, type = "grammatical", region) {
        if (typeof message == "string") {
            if (!region && this.last)
                region = this.last.region;
            message = new build.Error.Message(message, level, type, region);
        }
        this.errorHandler.raise(message);
    }
    static is(needle, value) {
        return Array.isArray(needle)
            ? needle.some(n => Source.is(n, value))
            : typeof needle != "string"
                ? needle.test(value)
                : needle.startsWith("!") && needle != "!"
                    ? !Source.is(needle.substring(1), value)
                    : needle == "any"
                        ? Source.symbol.every(s => s != value)
                        : needle == "symbol"
                            ? Source.symbol.some(s => s == value)
                            : needle == "identifier"
                                ? /[A-Za-z][A-Za-z0-9_]*/.test(value)
                                : needle == value;
    }
}
exports.Source = Source;
Source.wildcard = ["*", "?"];
Source.separator = ["(", ")", ":", "."];
Source.operator = ["!", "|"];
Source.symbol = [...Source.wildcard, ...Source.separator, ...Source.operator];

});

const Source$1 = /*@__PURE__*/getDefaultExportFromCjs(Source_1$1);

var parse_1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.add = exports.parseNext = exports.parse = void 0;





function parse(source, handler) {
    if (typeof source == "string") {
        handler = handler || new build.Error.ConsoleHandler();
        const tokens = lexer.tokenize(source, handler).toArray();
        source = new Source_1$1.Source(tokens, handler);
    }
    handler = handler instanceof Rule_1.Rule ? handler : undefined;
    const result = [];
    while (source.peek())
        result.push(parseNext(0, source));
    return result.length == 1 ? result[0] : new And_1.And(result);
}
exports.parse = parse;
function parseNext(previous, source) {
    let result;
    const precedenceTest = typeof previous == "number" ? p => previous < p : p => previous.precedence > p;
    const left = typeof previous == "number" ? undefined : previous;
    for (const parser of parsers)
        if (precedenceTest(parser[1] || Number.MAX_SAFE_INTEGER)) {
            const r = parser[0](source, left);
            if (r) {
                result = parseNext(r, source);
                break;
            }
        }
    return result || left || new And_1.And([]);
}
exports.parseNext = parseNext;
const parsers = [];
function add(parser, precedence) {
    parsers.push([parser, precedence]);
}
exports.add = add;

});

const parse = /*@__PURE__*/getDefaultExportFromCjs(parse_1);

var Every$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


parse_1.add(source => {
    const result = source.fetchIf("every", "(") && new Every_1.Every(parse_1.parse(source.clone()));
    if (result && !source.fetchIf(")"))
        source.raise("Missing end of parenthesis.");
    return result;
});

});

const Every$2 = /*@__PURE__*/getDefaultExportFromCjs(Every$1);

var Some$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


parse_1.add(source => {
    const result = source.fetchIf("some", "(") && new Some_1.Some(parse_1.parse(source.clone()));
    if (result && !source.fetchIf(")"))
        source.raise("Missing end of parenthesis.");
    return result;
});

});

const Some$2 = /*@__PURE__*/getDefaultExportFromCjs(Some$1);

var group = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

parse_1.add(source => {
    const result = source.fetchIf("(") && parse_1.parse(source.clone());
    if (result && !source.fetchIf(")"))
        source.raise("Missing end of parenthesis.");
    return result;
});

});

const group$1 = /*@__PURE__*/getDefaultExportFromCjs(group);

var Or$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


parse_1.add((source, previous) => previous && source.fetchIf("|") && new Or_1.Or([previous, parse_1.parseNext(Or_1.Or.precedence, source)]), Or_1.Or.precedence);

});

const Or$2 = /*@__PURE__*/getDefaultExportFromCjs(Or$1);

var Not$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


parse_1.add(source => source.fetchIf("!") && new Not_1.Not(parse_1.parseNext(Not_1.Not.precedence, source)));

});

const Not$2 = /*@__PURE__*/getDefaultExportFromCjs(Not$1);

var Property$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


parse_1.add(source => {
    const result = [];
    let fetched;
    while ((fetched = source.fetchIf("identifier", ".")))
        result.push(fetched[0].value);
    if ((fetched = source.fetchIf("identifier", ":")))
        result.push(fetched[0].value);
    return (result.length > 0 && result.reduceRight((r, name) => new Property_1.Property(name, r), parse_1.parseNext(Property_1.Property.precedence, source)));
});

});

const Property$2 = /*@__PURE__*/getDefaultExportFromCjs(Property$1);

var Includes$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


parse_1.add(source => {
    const fetched = source.fetchIf("*", "any", "*");
    return fetched && new Includes_1.Includes(fetched[1].value);
});

});

const Includes$2 = /*@__PURE__*/getDefaultExportFromCjs(Includes$1);

var StartsWith$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


parse_1.add(source => {
    const fetched = source.fetchIf("any", "*");
    return fetched && new StartsWith_1.StartsWith(fetched[0].value);
});

});

const StartsWith$2 = /*@__PURE__*/getDefaultExportFromCjs(StartsWith$1);

var EndsWith$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


parse_1.add(source => {
    const fetched = source.fetchIf("*", "any");
    return fetched && new EndsWith_1.EndsWith(fetched[1].value);
});

});

const EndsWith$2 = /*@__PURE__*/getDefaultExportFromCjs(EndsWith$1);

var Is$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


parse_1.add(source => {
    const fetched = source.fetchIf("any");
    return fetched && new Is_1.Is(fetched.value);
});

});

const Is$2 = /*@__PURE__*/getDefaultExportFromCjs(Is$1);

var ignore = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

parse_1.add(source => {
    source.raise(`Ignoring unknown token "${source.fetch()}"`);
    return false;
});

});

const ignore$1 = /*@__PURE__*/getDefaultExportFromCjs(ignore);

var parse$1 = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } });












});

const index$6 = /*@__PURE__*/getDefaultExportFromCjs(parse$1);

var dist = createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.startsWith = exports.some = exports.property = exports.parse = exports.or = exports.not = exports.match = exports.is = exports.includes = exports.filter = exports.every = exports.endsWith = exports.create = exports.and = exports.any = exports.Tuple = exports.StartsWith = exports.Some = exports.Rule = exports.Property = exports.Or = exports.Not = exports.Match = exports.Is = exports.Includes = exports.Every = exports.EndsWith = exports.Any = exports.And = void 0;


Object.defineProperty(exports, "and", { enumerable: true, get: function () { return And_1.and; } });
Object.defineProperty(exports, "And", { enumerable: true, get: function () { return And_1.And; } });

Object.defineProperty(exports, "any", { enumerable: true, get: function () { return Any_1.any; } });
Object.defineProperty(exports, "Any", { enumerable: true, get: function () { return Any_1.Any; } });

Object.defineProperty(exports, "endsWith", { enumerable: true, get: function () { return EndsWith_1.endsWith; } });
Object.defineProperty(exports, "EndsWith", { enumerable: true, get: function () { return EndsWith_1.EndsWith; } });

Object.defineProperty(exports, "every", { enumerable: true, get: function () { return Every_1.every; } });
Object.defineProperty(exports, "Every", { enumerable: true, get: function () { return Every_1.Every; } });

Object.defineProperty(exports, "includes", { enumerable: true, get: function () { return Includes_1.includes; } });
Object.defineProperty(exports, "Includes", { enumerable: true, get: function () { return Includes_1.Includes; } });

Object.defineProperty(exports, "Is", { enumerable: true, get: function () { return Is_1.Is; } });

Object.defineProperty(exports, "match", { enumerable: true, get: function () { return Match_1.match; } });
Object.defineProperty(exports, "Match", { enumerable: true, get: function () { return Match_1.Match; } });

Object.defineProperty(exports, "not", { enumerable: true, get: function () { return Not_1.not; } });
Object.defineProperty(exports, "Not", { enumerable: true, get: function () { return Not_1.Not; } });

Object.defineProperty(exports, "or", { enumerable: true, get: function () { return Or_1.or; } });
Object.defineProperty(exports, "Or", { enumerable: true, get: function () { return Or_1.Or; } });

Object.defineProperty(exports, "property", { enumerable: true, get: function () { return Property_1.property; } });
Object.defineProperty(exports, "Property", { enumerable: true, get: function () { return Property_1.Property; } });

Object.defineProperty(exports, "Rule", { enumerable: true, get: function () { return Rule_1.Rule; } });
Object.defineProperty(exports, "create", { enumerable: true, get: function () { return Rule_1.create; } });

Object.defineProperty(exports, "some", { enumerable: true, get: function () { return Some_1.some; } });
Object.defineProperty(exports, "Some", { enumerable: true, get: function () { return Some_1.Some; } });

Object.defineProperty(exports, "startsWith", { enumerable: true, get: function () { return StartsWith_1.startsWith; } });
Object.defineProperty(exports, "StartsWith", { enumerable: true, get: function () { return StartsWith_1.StartsWith; } });

Object.defineProperty(exports, "Tuple", { enumerable: true, get: function () { return Tuple_1.Tuple; } });

Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse$1.parse; } });
function is(criteria, value) {
    const result = Rule_1.create(criteria);
    return value ? result.is(value) : result;
}
exports.is = is;
function filter(criteria, value) {
    const c = Rule_1.create(criteria);
    return c.filter(value);
}
exports.filter = filter;

});

const index$7 = /*@__PURE__*/getDefaultExportFromCjs(dist);

const sv = {
  Filter: "Filtrera",
  "Remove filter": "Ta bort filter",
  "Apply filter": "Tillämpa filter",
};

function create(language) {
  return dist$1.create({
    sv,
  }, language);
}

const styleCss = ".sc-payfunc-filter-h{display:block;width:100%;max-width:90em;margin:auto}[hidden].sc-payfunc-filter-h{display:none}.sc-payfunc-filter-h>form.sc-payfunc-filter{border:1px solid rgb(var(--smoothly-medium-color));margin:0.2em 0 0.5em 0;clear:both}.sc-payfunc-filter-h>form.sc-payfunc-filter>smoothly-input.sc-payfunc-filter{width:calc(100% - 80px);display:inline-block}.sc-payfunc-filter-h>form.sc-payfunc-filter>smoothly-submit.sc-payfunc-filter{display:inline-block}";

const PayfuncFilter = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.filterChanged = createEvent(this, "filterChanged", 7);
    this.textEntered = false;
    this.criteriaString = "";
  }
  async componentWillLoad() {
    this.t = create(this.element);
  }
  checkTextEntered() {
    const input = document.getElementById("filter");
    if (hasValue(input))
      this.textEntered = input.value != "";
  }
  onFilter(e) {
    this.criteriaString = e.detail.filter;
    this.applyFilter();
    this.checkTextEntered();
  }
  criteriaStringChanged() {
    const input = document.getElementById("filter");
    if (hasValue(input))
      input.value = this.criteriaString;
    this.textEntered = true;
    this.applyFilter();
  }
  applyFilter(criteria) {
    this.filter = criteria || dist.and(dist.parse(this.criteriaString)).generalize();
    this.filterChanged.emit(dist.filter(this.filter, this.value));
  }
  reset() {
    this.criteriaString = "";
    this.applyFilter();
    const input = document.getElementById("filter");
    if (hasValue(input))
      input.value = "";
    this.textEntered = false;
  }
  render() {
    return (h("form", null, h("smoothly-input", { type: "text", id: "filter", name: "filter", onKeyDown: this.checkTextEntered.bind(this) }, this.t("Filter")), h("smoothly-submit", { fill: "clear", prevent: true, onSubmit: (e) => this.onFilter(e), style: { visibility: this.textEntered ? "visible" : "hidden" } }, h("smoothly-icon", { toolTip: this.t("Apply filter"), name: "search", size: "small" })), h("smoothly-submit", { fill: "clear", prevent: true, onSubmit: () => this.reset() }, h("smoothly-icon", { toolTip: this.t("Remove filter"), size: "small", name: "backspace" }))));
  }
  get element() { return getElement(this); }
  static get watchers() { return {
    "criteriaString": ["criteriaStringChanged"]
  }; }
};
function hasValue(element) {
  return element.value == undefined || typeof element.value === "string";
}
PayfuncFilter.style = styleCss;

export { PayfuncFilter as payfunc_filter };
