/*! Built with http://stenciljs.com */
import { h } from "./webcomponents.core.js";
var DEFAULT_DELIMITER = "/", DEFAULT_DELIMITERS = "./", PATH_REGEXP = new RegExp(["(\\\\.)", "(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"), "g");
function parse(e, t) { for (var n, r = [], o = 0, i = 0, a = "", s = t && t.delimiter || DEFAULT_DELIMITER, c = t && t.delimiters || DEFAULT_DELIMITERS, p = !1; null !== (n = PATH_REGEXP.exec(e));) {
    var u = n[0], l = n[1], d = n.index;
    if (a += e.slice(i, d), i = d + u.length, l)
        a += l[1], p = !0;
    else {
        var f = "", h = e[i], g = n[2], E = n[3], m = n[4], v = n[5];
        if (!p && a.length) {
            var x = a.length - 1;
            c.indexOf(a[x]) > -1 && (f = a[x], a = a.slice(0, x));
        }
        a && (r.push(a), a = "", p = !1);
        var y = "" !== f && void 0 !== h && h !== f, R = "+" === v || "*" === v, w = "?" === v || "*" === v, O = f || s, T = E || m;
        r.push({ name: g || o++, prefix: f, delimiter: O, optional: w, repeat: R, partial: y, pattern: T ? escapeGroup(T) : "[^" + escapeString(O) + "]+?" });
    }
} return (a || i < e.length) && r.push(a + e.substr(i)), r; }
function escapeString(e) { return e.replace(/([.+*?=^!:${}()[\]|/\\])/g, "\\$1"); }
function escapeGroup(e) { return e.replace(/([=!:$/()])/g, "\\$1"); }
function flags(e) { return e && e.sensitive ? "" : "i"; }
function regexpToRegexp(e, t) { if (!t)
    return e; var n = e.source.match(/\((?!\?)/g); if (n)
    for (var r = 0; r < n.length; r++)
        t.push({ name: r, prefix: null, delimiter: null, optional: !1, repeat: !1, partial: !1, pattern: null }); return e; }
function arrayToRegexp(e, t, n) { for (var r = [], o = 0; o < e.length; o++)
    r.push(pathToRegexp(e[o], t, n).source); return new RegExp("(?:" + r.join("|") + ")", flags(n)); }
function stringToRegexp(e, t, n) { return tokensToRegExp(parse(e, n), t, n); }
function tokensToRegExp(e, t, n) { for (var r = (n = n || {}).strict, o = !1 !== n.end, i = escapeString(n.delimiter || DEFAULT_DELIMITER), a = n.delimiters || DEFAULT_DELIMITERS, s = [].concat(n.endsWith || []).map(escapeString).concat("$").join("|"), c = "", p = !1, u = 0; u < e.length; u++) {
    var l = e[u];
    if ("string" == typeof l)
        c += escapeString(l), p = u === e.length - 1 && a.indexOf(l[l.length - 1]) > -1;
    else {
        var d = escapeString(l.prefix), f = l.repeat ? "(?:" + l.pattern + ")(?:" + d + "(?:" + l.pattern + "))*" : l.pattern;
        t && t.push(l), l.optional ? l.partial ? c += d + "(" + f + ")?" : c += "(?:" + d + "(" + f + "))?" : c += d + "(" + f + ")";
    }
} return o ? (r || (c += "(?:" + i + ")?"), c += "$" === s ? "$" : "(?=" + s + ")") : (r || (c += "(?:" + i + "(?=" + s + "))?"), p || (c += "(?=" + i + "|" + s + ")")), new RegExp("^" + c, flags(n)); }
function pathToRegexp(e, t, n) { return e instanceof RegExp ? regexpToRegexp(e, t) : Array.isArray(e) ? arrayToRegexp(e, t, n) : stringToRegexp(e, t, n); }
var patternCache = {}, cacheLimit = 1e4;
var cacheCount = 0;
function compilePath(e, t) { var n = "" + t.end + t.strict, r = patternCache[n] || (patternCache[n] = {}), o = JSON.stringify(e); if (r[o])
    return r[o]; var i = [], a = { re: pathToRegexp(e, i, t), keys: i }; return cacheCount < cacheLimit && (r[o] = a, cacheCount += 1), a; }
function matchPath(e, t) {
    if (t === void 0) { t = {}; }
    "string" == typeof t && (t = { path: t });
    var _a = t.path, n = _a === void 0 ? "/" : _a, _b = t.exact, r = _b === void 0 ? !1 : _b, _c = t.strict, o = _c === void 0 ? !1 : _c, _d = compilePath(n, { end: r, strict: o }), i = _d.re, a = _d.keys, s = i.exec(e);
    if (!s)
        return null;
    var c = s[0], p = s.slice(1), u = e === c;
    return r && !u ? null : { path: n, url: "/" === n && "" === c ? "/" : c, isExact: u, params: a.reduce(function (e, t, n) { return e[t.name] = p[n], e; }, {}) };
}
var __rest = function (e, t) { var n = {}; for (var r in e)
    Object.prototype.hasOwnProperty.call(e, r) && t.indexOf(r) < 0 && (n[r] = e[r]); if (null != e && "function" == typeof Object.getOwnPropertySymbols) {
    var o = 0;
    for (r = Object.getOwnPropertySymbols(e); o < r.length; o++)
        t.indexOf(r[o]) < 0 && (n[r[o]] = e[r[o]]);
} return n; };
function defaultConsumerRender(e, t) { return h("context-consumer", { subscribe: e, renderer: t }); }
function createProviderConsumer(e, t) {
    if (t === void 0) { t = defaultConsumerRender; }
    var n = new Map, r = e;
    function o(e, t) { Array.isArray(e) ? e.slice().forEach(function (e) { t[e] = r[e]; }) : t[e] = Object.assign({}, r), t.forceUpdate(); }
    function i(e) { return function (t) { n.has(t) || (n.set(t, e), o(e, t)); }; }
    function a(e, t) { return i(t)(e), function () { n.delete(e); }; }
    return { Provider: function (_a) {
            var e = _a.state, t = _a.children;
            return r = e, n.forEach(o), t;
        }, Consumer: function (_a) {
            var e = _a.children;
            return t(a, e[0]);
        }, wrapConsumer: function (e, t) { var n = e.is; return function (e) { var r = e.children, o = __rest(e, ["children"]); return h(n, Object.assign({ ref: i(t) }, o), r); }; }, injectProps: function (e, t) { var n = null; var r = e.prototype.componentWillLoad; e.prototype.componentWillLoad = function () { if (n = a(this.el, t), r)
            return r.bind(this)(); }; var o = e.prototype.componentDidUnload; e.prototype.componentDidUnload = function () { if (n(), o)
            return o.bind(this)(); }; } };
}
var ActiveRouter = createProviderConsumer({ location: null, titleSuffix: "", root: "/", history: null, subscribeGroupMember: function () { }, createSubscriptionGroup: function () { } });
var canUseDOM = !("undefined" == typeof window || !window.document || !window.document.createElement), addEventListener = function (e, t, n) { return e.addEventListener ? e.addEventListener(t, n, !1) : e.attachEvent("on" + t, n); }, removeEventListener = function (e, t, n) { return e.removeEventListener ? e.removeEventListener(t, n, !1) : e.detachEvent("on" + t, n); }, getConfirmation = function (e, t) { return t(window.confirm(e)); }, isModifiedEvent = function (e) { return e.metaKey || e.altKey || e.ctrlKey || e.shiftKey; }, supportsHistory = function () { var e = window.navigator.userAgent; return (-1 === e.indexOf("Android 2.") && -1 === e.indexOf("Android 4.0") || -1 === e.indexOf("Mobile Safari") || -1 !== e.indexOf("Chrome") || -1 !== e.indexOf("Windows Phone")) && window.history && "pushState" in window.history; }, supportsPopStateOnHashChange = function () { return -1 === window.navigator.userAgent.indexOf("Trident"); }, supportsGoWithoutReloadUsingHash = function () { return -1 === window.navigator.userAgent.indexOf("Firefox"); }, isExtraneousPopstateEvent = function (e) { return void 0 === e.state && -1 === navigator.userAgent.indexOf("CriOS"); }, storageAvailable = function (e) { try {
    var t = window[e], n = "__storage_test__";
    return t.setItem(n, n), t.removeItem(n), !0;
}
catch (e) {
    return e instanceof DOMException && (22 === e.code || 1014 === e.code || "QuotaExceededError" === e.name || "NS_ERROR_DOM_QUOTA_REACHED" === e.name) && 0 !== t.length;
} };
export { matchPath as a, ActiveRouter as b, storageAvailable as c, canUseDOM as d, addEventListener as e, removeEventListener as f, getConfirmation as g, supportsHistory as h, supportsPopStateOnHashChange as i, isExtraneousPopstateEvent as j, supportsGoWithoutReloadUsingHash as k, isModifiedEvent as l };
