wp/wp-includes/js/dist/router.js
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
    40 // EXPORTS
    40 // EXPORTS
    41 __webpack_require__.d(__webpack_exports__, {
    41 __webpack_require__.d(__webpack_exports__, {
    42   privateApis: () => (/* reexport */ privateApis)
    42   privateApis: () => (/* reexport */ privateApis)
    43 });
    43 });
    44 
    44 
    45 ;// CONCATENATED MODULE: external ["wp","element"]
    45 ;// ./node_modules/route-recognizer/dist/route-recognizer.es.js
    46 const external_wp_element_namespaceObject = window["wp"]["element"];
    46 var createObject = Object.create;
    47 ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
    47 function createMap() {
       
    48     var map = createObject(null);
       
    49     map["__"] = undefined;
       
    50     delete map["__"];
       
    51     return map;
       
    52 }
       
    53 
       
    54 var Target = function Target(path, matcher, delegate) {
       
    55     this.path = path;
       
    56     this.matcher = matcher;
       
    57     this.delegate = delegate;
       
    58 };
       
    59 Target.prototype.to = function to (target, callback) {
       
    60     var delegate = this.delegate;
       
    61     if (delegate && delegate.willAddRoute) {
       
    62         target = delegate.willAddRoute(this.matcher.target, target);
       
    63     }
       
    64     this.matcher.add(this.path, target);
       
    65     if (callback) {
       
    66         if (callback.length === 0) {
       
    67             throw new Error("You must have an argument in the function passed to `to`");
       
    68         }
       
    69         this.matcher.addChild(this.path, target, callback, this.delegate);
       
    70     }
       
    71 };
       
    72 var Matcher = function Matcher(target) {
       
    73     this.routes = createMap();
       
    74     this.children = createMap();
       
    75     this.target = target;
       
    76 };
       
    77 Matcher.prototype.add = function add (path, target) {
       
    78     this.routes[path] = target;
       
    79 };
       
    80 Matcher.prototype.addChild = function addChild (path, target, callback, delegate) {
       
    81     var matcher = new Matcher(target);
       
    82     this.children[path] = matcher;
       
    83     var match = generateMatch(path, matcher, delegate);
       
    84     if (delegate && delegate.contextEntered) {
       
    85         delegate.contextEntered(target, match);
       
    86     }
       
    87     callback(match);
       
    88 };
       
    89 function generateMatch(startingPath, matcher, delegate) {
       
    90     function match(path, callback) {
       
    91         var fullPath = startingPath + path;
       
    92         if (callback) {
       
    93             callback(generateMatch(fullPath, matcher, delegate));
       
    94         }
       
    95         else {
       
    96             return new Target(fullPath, matcher, delegate);
       
    97         }
       
    98     }
       
    99     
       
   100     return match;
       
   101 }
       
   102 function addRoute(routeArray, path, handler) {
       
   103     var len = 0;
       
   104     for (var i = 0; i < routeArray.length; i++) {
       
   105         len += routeArray[i].path.length;
       
   106     }
       
   107     path = path.substr(len);
       
   108     var route = { path: path, handler: handler };
       
   109     routeArray.push(route);
       
   110 }
       
   111 function eachRoute(baseRoute, matcher, callback, binding) {
       
   112     var routes = matcher.routes;
       
   113     var paths = Object.keys(routes);
       
   114     for (var i = 0; i < paths.length; i++) {
       
   115         var path = paths[i];
       
   116         var routeArray = baseRoute.slice();
       
   117         addRoute(routeArray, path, routes[path]);
       
   118         var nested = matcher.children[path];
       
   119         if (nested) {
       
   120             eachRoute(routeArray, nested, callback, binding);
       
   121         }
       
   122         else {
       
   123             callback.call(binding, routeArray);
       
   124         }
       
   125     }
       
   126 }
       
   127 var map = function (callback, addRouteCallback) {
       
   128     var matcher = new Matcher();
       
   129     callback(generateMatch("", matcher, this.delegate));
       
   130     eachRoute([], matcher, function (routes) {
       
   131         if (addRouteCallback) {
       
   132             addRouteCallback(this, routes);
       
   133         }
       
   134         else {
       
   135             this.add(routes);
       
   136         }
       
   137     }, this);
       
   138 };
       
   139 
       
   140 // Normalizes percent-encoded values in `path` to upper-case and decodes percent-encoded
       
   141 // values that are not reserved (i.e., unicode characters, emoji, etc). The reserved
       
   142 // chars are "/" and "%".
       
   143 // Safe to call multiple times on the same path.
       
   144 // Normalizes percent-encoded values in `path` to upper-case and decodes percent-encoded
       
   145 function normalizePath(path) {
       
   146     return path.split("/")
       
   147         .map(normalizeSegment)
       
   148         .join("/");
       
   149 }
       
   150 // We want to ensure the characters "%" and "/" remain in percent-encoded
       
   151 // form when normalizing paths, so replace them with their encoded form after
       
   152 // decoding the rest of the path
       
   153 var SEGMENT_RESERVED_CHARS = /%|\//g;
       
   154 function normalizeSegment(segment) {
       
   155     if (segment.length < 3 || segment.indexOf("%") === -1)
       
   156         { return segment; }
       
   157     return decodeURIComponent(segment).replace(SEGMENT_RESERVED_CHARS, encodeURIComponent);
       
   158 }
       
   159 // We do not want to encode these characters when generating dynamic path segments
       
   160 // See https://tools.ietf.org/html/rfc3986#section-3.3
       
   161 // sub-delims: "!", "$", "&", "'", "(", ")", "*", "+", ",", ";", "="
       
   162 // others allowed by RFC 3986: ":", "@"
       
   163 //
       
   164 // First encode the entire path segment, then decode any of the encoded special chars.
       
   165 //
       
   166 // The chars "!", "'", "(", ")", "*" do not get changed by `encodeURIComponent`,
       
   167 // so the possible encoded chars are:
       
   168 // ['%24', '%26', '%2B', '%2C', '%3B', '%3D', '%3A', '%40'].
       
   169 var PATH_SEGMENT_ENCODINGS = /%(?:2(?:4|6|B|C)|3(?:B|D|A)|40)/g;
       
   170 function encodePathSegment(str) {
       
   171     return encodeURIComponent(str).replace(PATH_SEGMENT_ENCODINGS, decodeURIComponent);
       
   172 }
       
   173 
       
   174 var escapeRegex = /(\/|\.|\*|\+|\?|\||\(|\)|\[|\]|\{|\}|\\)/g;
       
   175 var isArray = Array.isArray;
       
   176 var route_recognizer_es_hasOwnProperty = Object.prototype.hasOwnProperty;
       
   177 function getParam(params, key) {
       
   178     if (typeof params !== "object" || params === null) {
       
   179         throw new Error("You must pass an object as the second argument to `generate`.");
       
   180     }
       
   181     if (!route_recognizer_es_hasOwnProperty.call(params, key)) {
       
   182         throw new Error("You must provide param `" + key + "` to `generate`.");
       
   183     }
       
   184     var value = params[key];
       
   185     var str = typeof value === "string" ? value : "" + value;
       
   186     if (str.length === 0) {
       
   187         throw new Error("You must provide a param `" + key + "`.");
       
   188     }
       
   189     return str;
       
   190 }
       
   191 var eachChar = [];
       
   192 eachChar[0 /* Static */] = function (segment, currentState) {
       
   193     var state = currentState;
       
   194     var value = segment.value;
       
   195     for (var i = 0; i < value.length; i++) {
       
   196         var ch = value.charCodeAt(i);
       
   197         state = state.put(ch, false, false);
       
   198     }
       
   199     return state;
       
   200 };
       
   201 eachChar[1 /* Dynamic */] = function (_, currentState) {
       
   202     return currentState.put(47 /* SLASH */, true, true);
       
   203 };
       
   204 eachChar[2 /* Star */] = function (_, currentState) {
       
   205     return currentState.put(-1 /* ANY */, false, true);
       
   206 };
       
   207 eachChar[4 /* Epsilon */] = function (_, currentState) {
       
   208     return currentState;
       
   209 };
       
   210 var regex = [];
       
   211 regex[0 /* Static */] = function (segment) {
       
   212     return segment.value.replace(escapeRegex, "\\$1");
       
   213 };
       
   214 regex[1 /* Dynamic */] = function () {
       
   215     return "([^/]+)";
       
   216 };
       
   217 regex[2 /* Star */] = function () {
       
   218     return "(.+)";
       
   219 };
       
   220 regex[4 /* Epsilon */] = function () {
       
   221     return "";
       
   222 };
       
   223 var generate = [];
       
   224 generate[0 /* Static */] = function (segment) {
       
   225     return segment.value;
       
   226 };
       
   227 generate[1 /* Dynamic */] = function (segment, params) {
       
   228     var value = getParam(params, segment.value);
       
   229     if (RouteRecognizer.ENCODE_AND_DECODE_PATH_SEGMENTS) {
       
   230         return encodePathSegment(value);
       
   231     }
       
   232     else {
       
   233         return value;
       
   234     }
       
   235 };
       
   236 generate[2 /* Star */] = function (segment, params) {
       
   237     return getParam(params, segment.value);
       
   238 };
       
   239 generate[4 /* Epsilon */] = function () {
       
   240     return "";
       
   241 };
       
   242 var EmptyObject = Object.freeze({});
       
   243 var EmptyArray = Object.freeze([]);
       
   244 // The `names` will be populated with the paramter name for each dynamic/star
       
   245 // segment. `shouldDecodes` will be populated with a boolean for each dyanamic/star
       
   246 // segment, indicating whether it should be decoded during recognition.
       
   247 function parse(segments, route, types) {
       
   248     // normalize route as not starting with a "/". Recognition will
       
   249     // also normalize.
       
   250     if (route.length > 0 && route.charCodeAt(0) === 47 /* SLASH */) {
       
   251         route = route.substr(1);
       
   252     }
       
   253     var parts = route.split("/");
       
   254     var names = undefined;
       
   255     var shouldDecodes = undefined;
       
   256     for (var i = 0; i < parts.length; i++) {
       
   257         var part = parts[i];
       
   258         var flags = 0;
       
   259         var type = 0;
       
   260         if (part === "") {
       
   261             type = 4 /* Epsilon */;
       
   262         }
       
   263         else if (part.charCodeAt(0) === 58 /* COLON */) {
       
   264             type = 1 /* Dynamic */;
       
   265         }
       
   266         else if (part.charCodeAt(0) === 42 /* STAR */) {
       
   267             type = 2 /* Star */;
       
   268         }
       
   269         else {
       
   270             type = 0 /* Static */;
       
   271         }
       
   272         flags = 2 << type;
       
   273         if (flags & 12 /* Named */) {
       
   274             part = part.slice(1);
       
   275             names = names || [];
       
   276             names.push(part);
       
   277             shouldDecodes = shouldDecodes || [];
       
   278             shouldDecodes.push((flags & 4 /* Decoded */) !== 0);
       
   279         }
       
   280         if (flags & 14 /* Counted */) {
       
   281             types[type]++;
       
   282         }
       
   283         segments.push({
       
   284             type: type,
       
   285             value: normalizeSegment(part)
       
   286         });
       
   287     }
       
   288     return {
       
   289         names: names || EmptyArray,
       
   290         shouldDecodes: shouldDecodes || EmptyArray,
       
   291     };
       
   292 }
       
   293 function isEqualCharSpec(spec, char, negate) {
       
   294     return spec.char === char && spec.negate === negate;
       
   295 }
       
   296 // A State has a character specification and (`charSpec`) and a list of possible
       
   297 // subsequent states (`nextStates`).
       
   298 //
       
   299 // If a State is an accepting state, it will also have several additional
       
   300 // properties:
       
   301 //
       
   302 // * `regex`: A regular expression that is used to extract parameters from paths
       
   303 //   that reached this accepting state.
       
   304 // * `handlers`: Information on how to convert the list of captures into calls
       
   305 //   to registered handlers with the specified parameters
       
   306 // * `types`: How many static, dynamic or star segments in this route. Used to
       
   307 //   decide which route to use if multiple registered routes match a path.
       
   308 //
       
   309 // Currently, State is implemented naively by looping over `nextStates` and
       
   310 // comparing a character specification against a character. A more efficient
       
   311 // implementation would use a hash of keys pointing at one or more next states.
       
   312 var State = function State(states, id, char, negate, repeat) {
       
   313     this.states = states;
       
   314     this.id = id;
       
   315     this.char = char;
       
   316     this.negate = negate;
       
   317     this.nextStates = repeat ? id : null;
       
   318     this.pattern = "";
       
   319     this._regex = undefined;
       
   320     this.handlers = undefined;
       
   321     this.types = undefined;
       
   322 };
       
   323 State.prototype.regex = function regex$1 () {
       
   324     if (!this._regex) {
       
   325         this._regex = new RegExp(this.pattern);
       
   326     }
       
   327     return this._regex;
       
   328 };
       
   329 State.prototype.get = function get (char, negate) {
       
   330         var this$1 = this;
       
   331 
       
   332     var nextStates = this.nextStates;
       
   333     if (nextStates === null)
       
   334         { return; }
       
   335     if (isArray(nextStates)) {
       
   336         for (var i = 0; i < nextStates.length; i++) {
       
   337             var child = this$1.states[nextStates[i]];
       
   338             if (isEqualCharSpec(child, char, negate)) {
       
   339                 return child;
       
   340             }
       
   341         }
       
   342     }
       
   343     else {
       
   344         var child$1 = this.states[nextStates];
       
   345         if (isEqualCharSpec(child$1, char, negate)) {
       
   346             return child$1;
       
   347         }
       
   348     }
       
   349 };
       
   350 State.prototype.put = function put (char, negate, repeat) {
       
   351     var state;
       
   352     // If the character specification already exists in a child of the current
       
   353     // state, just return that state.
       
   354     if (state = this.get(char, negate)) {
       
   355         return state;
       
   356     }
       
   357     // Make a new state for the character spec
       
   358     var states = this.states;
       
   359     state = new State(states, states.length, char, negate, repeat);
       
   360     states[states.length] = state;
       
   361     // Insert the new state as a child of the current state
       
   362     if (this.nextStates == null) {
       
   363         this.nextStates = state.id;
       
   364     }
       
   365     else if (isArray(this.nextStates)) {
       
   366         this.nextStates.push(state.id);
       
   367     }
       
   368     else {
       
   369         this.nextStates = [this.nextStates, state.id];
       
   370     }
       
   371     // Return the new state
       
   372     return state;
       
   373 };
       
   374 // Find a list of child states matching the next character
       
   375 State.prototype.match = function match (ch) {
       
   376         var this$1 = this;
       
   377 
       
   378     var nextStates = this.nextStates;
       
   379     if (!nextStates)
       
   380         { return []; }
       
   381     var returned = [];
       
   382     if (isArray(nextStates)) {
       
   383         for (var i = 0; i < nextStates.length; i++) {
       
   384             var child = this$1.states[nextStates[i]];
       
   385             if (isMatch(child, ch)) {
       
   386                 returned.push(child);
       
   387             }
       
   388         }
       
   389     }
       
   390     else {
       
   391         var child$1 = this.states[nextStates];
       
   392         if (isMatch(child$1, ch)) {
       
   393             returned.push(child$1);
       
   394         }
       
   395     }
       
   396     return returned;
       
   397 };
       
   398 function isMatch(spec, char) {
       
   399     return spec.negate ? spec.char !== char && spec.char !== -1 /* ANY */ : spec.char === char || spec.char === -1 /* ANY */;
       
   400 }
       
   401 // This is a somewhat naive strategy, but should work in a lot of cases
       
   402 // A better strategy would properly resolve /posts/:id/new and /posts/edit/:id.
       
   403 //
       
   404 // This strategy generally prefers more static and less dynamic matching.
       
   405 // Specifically, it
       
   406 //
       
   407 //  * prefers fewer stars to more, then
       
   408 //  * prefers using stars for less of the match to more, then
       
   409 //  * prefers fewer dynamic segments to more, then
       
   410 //  * prefers more static segments to more
       
   411 function sortSolutions(states) {
       
   412     return states.sort(function (a, b) {
       
   413         var ref = a.types || [0, 0, 0];
       
   414         var astatics = ref[0];
       
   415         var adynamics = ref[1];
       
   416         var astars = ref[2];
       
   417         var ref$1 = b.types || [0, 0, 0];
       
   418         var bstatics = ref$1[0];
       
   419         var bdynamics = ref$1[1];
       
   420         var bstars = ref$1[2];
       
   421         if (astars !== bstars) {
       
   422             return astars - bstars;
       
   423         }
       
   424         if (astars) {
       
   425             if (astatics !== bstatics) {
       
   426                 return bstatics - astatics;
       
   427             }
       
   428             if (adynamics !== bdynamics) {
       
   429                 return bdynamics - adynamics;
       
   430             }
       
   431         }
       
   432         if (adynamics !== bdynamics) {
       
   433             return adynamics - bdynamics;
       
   434         }
       
   435         if (astatics !== bstatics) {
       
   436             return bstatics - astatics;
       
   437         }
       
   438         return 0;
       
   439     });
       
   440 }
       
   441 function recognizeChar(states, ch) {
       
   442     var nextStates = [];
       
   443     for (var i = 0, l = states.length; i < l; i++) {
       
   444         var state = states[i];
       
   445         nextStates = nextStates.concat(state.match(ch));
       
   446     }
       
   447     return nextStates;
       
   448 }
       
   449 var RecognizeResults = function RecognizeResults(queryParams) {
       
   450     this.length = 0;
       
   451     this.queryParams = queryParams || {};
       
   452 };
       
   453 
       
   454 RecognizeResults.prototype.splice = Array.prototype.splice;
       
   455 RecognizeResults.prototype.slice = Array.prototype.slice;
       
   456 RecognizeResults.prototype.push = Array.prototype.push;
       
   457 function findHandler(state, originalPath, queryParams) {
       
   458     var handlers = state.handlers;
       
   459     var regex = state.regex();
       
   460     if (!regex || !handlers)
       
   461         { throw new Error("state not initialized"); }
       
   462     var captures = originalPath.match(regex);
       
   463     var currentCapture = 1;
       
   464     var result = new RecognizeResults(queryParams);
       
   465     result.length = handlers.length;
       
   466     for (var i = 0; i < handlers.length; i++) {
       
   467         var handler = handlers[i];
       
   468         var names = handler.names;
       
   469         var shouldDecodes = handler.shouldDecodes;
       
   470         var params = EmptyObject;
       
   471         var isDynamic = false;
       
   472         if (names !== EmptyArray && shouldDecodes !== EmptyArray) {
       
   473             for (var j = 0; j < names.length; j++) {
       
   474                 isDynamic = true;
       
   475                 var name = names[j];
       
   476                 var capture = captures && captures[currentCapture++];
       
   477                 if (params === EmptyObject) {
       
   478                     params = {};
       
   479                 }
       
   480                 if (RouteRecognizer.ENCODE_AND_DECODE_PATH_SEGMENTS && shouldDecodes[j]) {
       
   481                     params[name] = capture && decodeURIComponent(capture);
       
   482                 }
       
   483                 else {
       
   484                     params[name] = capture;
       
   485                 }
       
   486             }
       
   487         }
       
   488         result[i] = {
       
   489             handler: handler.handler,
       
   490             params: params,
       
   491             isDynamic: isDynamic
       
   492         };
       
   493     }
       
   494     return result;
       
   495 }
       
   496 function decodeQueryParamPart(part) {
       
   497     // http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
       
   498     part = part.replace(/\+/gm, "%20");
       
   499     var result;
       
   500     try {
       
   501         result = decodeURIComponent(part);
       
   502     }
       
   503     catch (error) {
       
   504         result = "";
       
   505     }
       
   506     return result;
       
   507 }
       
   508 var RouteRecognizer = function RouteRecognizer() {
       
   509     this.names = createMap();
       
   510     var states = [];
       
   511     var state = new State(states, 0, -1 /* ANY */, true, false);
       
   512     states[0] = state;
       
   513     this.states = states;
       
   514     this.rootState = state;
       
   515 };
       
   516 RouteRecognizer.prototype.add = function add (routes, options) {
       
   517     var currentState = this.rootState;
       
   518     var pattern = "^";
       
   519     var types = [0, 0, 0];
       
   520     var handlers = new Array(routes.length);
       
   521     var allSegments = [];
       
   522     var isEmpty = true;
       
   523     var j = 0;
       
   524     for (var i = 0; i < routes.length; i++) {
       
   525         var route = routes[i];
       
   526         var ref = parse(allSegments, route.path, types);
       
   527             var names = ref.names;
       
   528             var shouldDecodes = ref.shouldDecodes;
       
   529         // preserve j so it points to the start of newly added segments
       
   530         for (; j < allSegments.length; j++) {
       
   531             var segment = allSegments[j];
       
   532             if (segment.type === 4 /* Epsilon */) {
       
   533                 continue;
       
   534             }
       
   535             isEmpty = false;
       
   536             // Add a "/" for the new segment
       
   537             currentState = currentState.put(47 /* SLASH */, false, false);
       
   538             pattern += "/";
       
   539             // Add a representation of the segment to the NFA and regex
       
   540             currentState = eachChar[segment.type](segment, currentState);
       
   541             pattern += regex[segment.type](segment);
       
   542         }
       
   543         handlers[i] = {
       
   544             handler: route.handler,
       
   545             names: names,
       
   546             shouldDecodes: shouldDecodes
       
   547         };
       
   548     }
       
   549     if (isEmpty) {
       
   550         currentState = currentState.put(47 /* SLASH */, false, false);
       
   551         pattern += "/";
       
   552     }
       
   553     currentState.handlers = handlers;
       
   554     currentState.pattern = pattern + "$";
       
   555     currentState.types = types;
       
   556     var name;
       
   557     if (typeof options === "object" && options !== null && options.as) {
       
   558         name = options.as;
       
   559     }
       
   560     if (name) {
       
   561         // if (this.names[name]) {
       
   562         //   throw new Error("You may not add a duplicate route named `" + name + "`.");
       
   563         // }
       
   564         this.names[name] = {
       
   565             segments: allSegments,
       
   566             handlers: handlers
       
   567         };
       
   568     }
       
   569 };
       
   570 RouteRecognizer.prototype.handlersFor = function handlersFor (name) {
       
   571     var route = this.names[name];
       
   572     if (!route) {
       
   573         throw new Error("There is no route named " + name);
       
   574     }
       
   575     var result = new Array(route.handlers.length);
       
   576     for (var i = 0; i < route.handlers.length; i++) {
       
   577         var handler = route.handlers[i];
       
   578         result[i] = handler;
       
   579     }
       
   580     return result;
       
   581 };
       
   582 RouteRecognizer.prototype.hasRoute = function hasRoute (name) {
       
   583     return !!this.names[name];
       
   584 };
       
   585 RouteRecognizer.prototype.generate = function generate$1 (name, params) {
       
   586     var route = this.names[name];
       
   587     var output = "";
       
   588     if (!route) {
       
   589         throw new Error("There is no route named " + name);
       
   590     }
       
   591     var segments = route.segments;
       
   592     for (var i = 0; i < segments.length; i++) {
       
   593         var segment = segments[i];
       
   594         if (segment.type === 4 /* Epsilon */) {
       
   595             continue;
       
   596         }
       
   597         output += "/";
       
   598         output += generate[segment.type](segment, params);
       
   599     }
       
   600     if (output.charAt(0) !== "/") {
       
   601         output = "/" + output;
       
   602     }
       
   603     if (params && params.queryParams) {
       
   604         output += this.generateQueryString(params.queryParams);
       
   605     }
       
   606     return output;
       
   607 };
       
   608 RouteRecognizer.prototype.generateQueryString = function generateQueryString (params) {
       
   609     var pairs = [];
       
   610     var keys = Object.keys(params);
       
   611     keys.sort();
       
   612     for (var i = 0; i < keys.length; i++) {
       
   613         var key = keys[i];
       
   614         var value = params[key];
       
   615         if (value == null) {
       
   616             continue;
       
   617         }
       
   618         var pair = encodeURIComponent(key);
       
   619         if (isArray(value)) {
       
   620             for (var j = 0; j < value.length; j++) {
       
   621                 var arrayPair = key + "[]" + "=" + encodeURIComponent(value[j]);
       
   622                 pairs.push(arrayPair);
       
   623             }
       
   624         }
       
   625         else {
       
   626             pair += "=" + encodeURIComponent(value);
       
   627             pairs.push(pair);
       
   628         }
       
   629     }
       
   630     if (pairs.length === 0) {
       
   631         return "";
       
   632     }
       
   633     return "?" + pairs.join("&");
       
   634 };
       
   635 RouteRecognizer.prototype.parseQueryString = function parseQueryString (queryString) {
       
   636     var pairs = queryString.split("&");
       
   637     var queryParams = {};
       
   638     for (var i = 0; i < pairs.length; i++) {
       
   639         var pair = pairs[i].split("="), key = decodeQueryParamPart(pair[0]), keyLength = key.length, isArray = false, value = (void 0);
       
   640         if (pair.length === 1) {
       
   641             value = "true";
       
   642         }
       
   643         else {
       
   644             // Handle arrays
       
   645             if (keyLength > 2 && key.slice(keyLength - 2) === "[]") {
       
   646                 isArray = true;
       
   647                 key = key.slice(0, keyLength - 2);
       
   648                 if (!queryParams[key]) {
       
   649                     queryParams[key] = [];
       
   650                 }
       
   651             }
       
   652             value = pair[1] ? decodeQueryParamPart(pair[1]) : "";
       
   653         }
       
   654         if (isArray) {
       
   655             queryParams[key].push(value);
       
   656         }
       
   657         else {
       
   658             queryParams[key] = value;
       
   659         }
       
   660     }
       
   661     return queryParams;
       
   662 };
       
   663 RouteRecognizer.prototype.recognize = function recognize (path) {
       
   664     var results;
       
   665     var states = [this.rootState];
       
   666     var queryParams = {};
       
   667     var isSlashDropped = false;
       
   668     var hashStart = path.indexOf("#");
       
   669     if (hashStart !== -1) {
       
   670         path = path.substr(0, hashStart);
       
   671     }
       
   672     var queryStart = path.indexOf("?");
       
   673     if (queryStart !== -1) {
       
   674         var queryString = path.substr(queryStart + 1, path.length);
       
   675         path = path.substr(0, queryStart);
       
   676         queryParams = this.parseQueryString(queryString);
       
   677     }
       
   678     if (path.charAt(0) !== "/") {
       
   679         path = "/" + path;
       
   680     }
       
   681     var originalPath = path;
       
   682     if (RouteRecognizer.ENCODE_AND_DECODE_PATH_SEGMENTS) {
       
   683         path = normalizePath(path);
       
   684     }
       
   685     else {
       
   686         path = decodeURI(path);
       
   687         originalPath = decodeURI(originalPath);
       
   688     }
       
   689     var pathLen = path.length;
       
   690     if (pathLen > 1 && path.charAt(pathLen - 1) === "/") {
       
   691         path = path.substr(0, pathLen - 1);
       
   692         originalPath = originalPath.substr(0, originalPath.length - 1);
       
   693         isSlashDropped = true;
       
   694     }
       
   695     for (var i = 0; i < path.length; i++) {
       
   696         states = recognizeChar(states, path.charCodeAt(i));
       
   697         if (!states.length) {
       
   698             break;
       
   699         }
       
   700     }
       
   701     var solutions = [];
       
   702     for (var i$1 = 0; i$1 < states.length; i$1++) {
       
   703         if (states[i$1].handlers) {
       
   704             solutions.push(states[i$1]);
       
   705         }
       
   706     }
       
   707     states = sortSolutions(solutions);
       
   708     var state = solutions[0];
       
   709     if (state && state.handlers) {
       
   710         // if a trailing slash was dropped and a star segment is the last segment
       
   711         // specified, put the trailing slash back
       
   712         if (isSlashDropped && state.pattern && state.pattern.slice(-5) === "(.+)$") {
       
   713             originalPath = originalPath + "/";
       
   714         }
       
   715         results = findHandler(state, originalPath, queryParams);
       
   716     }
       
   717     return results;
       
   718 };
       
   719 RouteRecognizer.VERSION = "0.3.4";
       
   720 // Set to false to opt-out of encoding and decoding path segments.
       
   721 // See https://github.com/tildeio/route-recognizer/pull/55
       
   722 RouteRecognizer.ENCODE_AND_DECODE_PATH_SEGMENTS = true;
       
   723 RouteRecognizer.Normalizer = {
       
   724     normalizeSegment: normalizeSegment, normalizePath: normalizePath, encodePathSegment: encodePathSegment
       
   725 };
       
   726 RouteRecognizer.prototype.map = map;
       
   727 
       
   728 /* harmony default export */ const route_recognizer_es = (RouteRecognizer);
       
   729 
       
   730 
       
   731 ;// ./node_modules/@babel/runtime/helpers/esm/extends.js
    48 function extends_extends() {
   732 function extends_extends() {
    49   extends_extends = Object.assign ? Object.assign.bind() : function (target) {
   733   return extends_extends = Object.assign ? Object.assign.bind() : function (n) {
    50     for (var i = 1; i < arguments.length; i++) {
   734     for (var e = 1; e < arguments.length; e++) {
    51       var source = arguments[i];
   735       var t = arguments[e];
    52       for (var key in source) {
   736       for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
    53         if (Object.prototype.hasOwnProperty.call(source, key)) {
   737     }
    54           target[key] = source[key];
   738     return n;
    55         }
   739   }, extends_extends.apply(null, arguments);
    56       }
   740 }
    57     }
   741 
    58     return target;
   742 ;// ./node_modules/history/index.js
    59   };
       
    60   return extends_extends.apply(this, arguments);
       
    61 }
       
    62 ;// CONCATENATED MODULE: ./node_modules/history/index.js
       
    63 
   743 
    64 
   744 
    65 /**
   745 /**
    66  * Actions represent the type of change to a location value.
   746  * Actions represent the type of change to a location value.
    67  *
   747  *
   847   return parsedPath;
  1527   return parsedPath;
   848 }
  1528 }
   849 
  1529 
   850 
  1530 
   851 
  1531 
   852 ;// CONCATENATED MODULE: external ["wp","url"]
  1532 ;// external ["wp","element"]
       
  1533 const external_wp_element_namespaceObject = window["wp"]["element"];
       
  1534 ;// external ["wp","url"]
   853 const external_wp_url_namespaceObject = window["wp"]["url"];
  1535 const external_wp_url_namespaceObject = window["wp"]["url"];
   854 ;// CONCATENATED MODULE: ./node_modules/@wordpress/router/build-module/history.js
  1536 ;// external ["wp","compose"]
       
  1537 const external_wp_compose_namespaceObject = window["wp"]["compose"];
       
  1538 ;// external "ReactJSXRuntime"
       
  1539 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
       
  1540 ;// ./node_modules/@wordpress/router/build-module/router.js
       
  1541 /* wp:polyfill */
   855 /**
  1542 /**
   856  * External dependencies
  1543  * External dependencies
   857  */
  1544  */
   858 
  1545 
   859 
  1546 
       
  1547 
   860 /**
  1548 /**
   861  * WordPress dependencies
  1549  * WordPress dependencies
   862  */
  1550  */
   863 
  1551 
   864 const history_history = createBrowserHistory();
  1552 
   865 const originalHistoryPush = history_history.push;
  1553 
   866 const originalHistoryReplace = history_history.replace;
  1554 
   867 
  1555 /**
   868 // Preserve the `wp_theme_preview` query parameter when navigating
  1556  * Internal dependencies
   869 // around the Site Editor.
  1557  */
   870 // TODO: move this hack out of the router into Site Editor code.
  1558 
   871 function preserveThemePreview(params) {
  1559 const router_history = createBrowserHistory();
   872   if (params.hasOwnProperty('wp_theme_preview')) {
  1560 const RoutesContext = (0,external_wp_element_namespaceObject.createContext)(null);
   873     return params;
  1561 const ConfigContext = (0,external_wp_element_namespaceObject.createContext)({
   874   }
  1562   pathArg: 'p'
   875   const currentSearch = new URLSearchParams(history_history.location.search);
  1563 });
   876   const currentThemePreview = currentSearch.get('wp_theme_preview');
       
   877   if (currentThemePreview === null) {
       
   878     return params;
       
   879   }
       
   880   return {
       
   881     ...params,
       
   882     wp_theme_preview: currentThemePreview
       
   883   };
       
   884 }
       
   885 function push(params, state) {
       
   886   const search = (0,external_wp_url_namespaceObject.buildQueryString)(preserveThemePreview(params));
       
   887   return originalHistoryPush.call(history_history, {
       
   888     search
       
   889   }, state);
       
   890 }
       
   891 function replace(params, state) {
       
   892   const search = (0,external_wp_url_namespaceObject.buildQueryString)(preserveThemePreview(params));
       
   893   return originalHistoryReplace.call(history_history, {
       
   894     search
       
   895   }, state);
       
   896 }
       
   897 const locationMemo = new WeakMap();
  1564 const locationMemo = new WeakMap();
   898 function getLocationWithParams() {
  1565 function getLocationWithQuery() {
   899   const location = history_history.location;
  1566   const location = router_history.location;
   900   let locationWithParams = locationMemo.get(location);
  1567   let locationWithQuery = locationMemo.get(location);
   901   if (!locationWithParams) {
  1568   if (!locationWithQuery) {
   902     locationWithParams = {
  1569     locationWithQuery = {
   903       ...location,
  1570       ...location,
   904       params: Object.fromEntries(new URLSearchParams(location.search))
  1571       query: Object.fromEntries(new URLSearchParams(location.search))
   905     };
  1572     };
   906     locationMemo.set(location, locationWithParams);
  1573     locationMemo.set(location, locationWithQuery);
   907   }
  1574   }
   908   return locationWithParams;
  1575   return locationWithQuery;
   909 }
  1576 }
   910 history_history.push = push;
  1577 function useLocation() {
   911 history_history.replace = replace;
  1578   const context = (0,external_wp_element_namespaceObject.useContext)(RoutesContext);
   912 history_history.getLocationWithParams = getLocationWithParams;
  1579   if (!context) {
   913 /* harmony default export */ const build_module_history = (history_history);
  1580     throw new Error('useLocation must be used within a RouterProvider');
   914 
  1581   }
   915 ;// CONCATENATED MODULE: external "ReactJSXRuntime"
  1582   return context;
   916 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
  1583 }
   917 ;// CONCATENATED MODULE: ./node_modules/@wordpress/router/build-module/router.js
  1584 function useHistory() {
       
  1585   const {
       
  1586     pathArg,
       
  1587     beforeNavigate
       
  1588   } = (0,external_wp_element_namespaceObject.useContext)(ConfigContext);
       
  1589   const navigate = (0,external_wp_compose_namespaceObject.useEvent)(async (rawPath, options = {}) => {
       
  1590     var _getPath;
       
  1591     const query = (0,external_wp_url_namespaceObject.getQueryArgs)(rawPath);
       
  1592     const path = (_getPath = (0,external_wp_url_namespaceObject.getPath)('http://domain.com/' + rawPath)) !== null && _getPath !== void 0 ? _getPath : '';
       
  1593     const performPush = () => {
       
  1594       const result = beforeNavigate ? beforeNavigate({
       
  1595         path,
       
  1596         query
       
  1597       }) : {
       
  1598         path,
       
  1599         query
       
  1600       };
       
  1601       return router_history.push({
       
  1602         search: (0,external_wp_url_namespaceObject.buildQueryString)({
       
  1603           [pathArg]: result.path,
       
  1604           ...result.query
       
  1605         })
       
  1606       }, options.state);
       
  1607     };
       
  1608 
       
  1609     /*
       
  1610      * Skip transition in mobile, otherwise it crashes the browser.
       
  1611      * See: https://github.com/WordPress/gutenberg/pull/63002.
       
  1612      */
       
  1613     const isMediumOrBigger = window.matchMedia('(min-width: 782px)').matches;
       
  1614     if (!isMediumOrBigger || !document.startViewTransition || !options.transition) {
       
  1615       performPush();
       
  1616       return;
       
  1617     }
       
  1618     await new Promise(resolve => {
       
  1619       var _options$transition;
       
  1620       const classname = (_options$transition = options.transition) !== null && _options$transition !== void 0 ? _options$transition : '';
       
  1621       document.documentElement.classList.add(classname);
       
  1622       const transition = document.startViewTransition(() => performPush());
       
  1623       transition.finished.finally(() => {
       
  1624         document.documentElement.classList.remove(classname);
       
  1625         resolve();
       
  1626       });
       
  1627     });
       
  1628   });
       
  1629   return (0,external_wp_element_namespaceObject.useMemo)(() => ({
       
  1630     navigate,
       
  1631     back: router_history.back
       
  1632   }), [navigate]);
       
  1633 }
       
  1634 function useMatch(location, matcher, pathArg, matchResolverArgs) {
       
  1635   const {
       
  1636     query: rawQuery = {}
       
  1637   } = location;
       
  1638   return (0,external_wp_element_namespaceObject.useMemo)(() => {
       
  1639     const {
       
  1640       [pathArg]: path = '/',
       
  1641       ...query
       
  1642     } = rawQuery;
       
  1643     const result = matcher.recognize(path)?.[0];
       
  1644     if (!result) {
       
  1645       return {
       
  1646         name: '404',
       
  1647         path: (0,external_wp_url_namespaceObject.addQueryArgs)(path, query),
       
  1648         areas: {},
       
  1649         widths: {},
       
  1650         query,
       
  1651         params: {}
       
  1652       };
       
  1653     }
       
  1654     const matchedRoute = result.handler;
       
  1655     const resolveFunctions = (record = {}) => {
       
  1656       return Object.fromEntries(Object.entries(record).map(([key, value]) => {
       
  1657         if (typeof value === 'function') {
       
  1658           return [key, value({
       
  1659             query,
       
  1660             params: result.params,
       
  1661             ...matchResolverArgs
       
  1662           })];
       
  1663         }
       
  1664         return [key, value];
       
  1665       }));
       
  1666     };
       
  1667     return {
       
  1668       name: matchedRoute.name,
       
  1669       areas: resolveFunctions(matchedRoute.areas),
       
  1670       widths: resolveFunctions(matchedRoute.widths),
       
  1671       params: result.params,
       
  1672       query,
       
  1673       path: (0,external_wp_url_namespaceObject.addQueryArgs)(path, query)
       
  1674     };
       
  1675   }, [matcher, rawQuery, pathArg, matchResolverArgs]);
       
  1676 }
       
  1677 function RouterProvider({
       
  1678   routes,
       
  1679   pathArg,
       
  1680   beforeNavigate,
       
  1681   children,
       
  1682   matchResolverArgs
       
  1683 }) {
       
  1684   const location = (0,external_wp_element_namespaceObject.useSyncExternalStore)(router_history.listen, getLocationWithQuery, getLocationWithQuery);
       
  1685   const matcher = (0,external_wp_element_namespaceObject.useMemo)(() => {
       
  1686     const ret = new route_recognizer_es();
       
  1687     routes.forEach(route => {
       
  1688       ret.add([{
       
  1689         path: route.path,
       
  1690         handler: route
       
  1691       }], {
       
  1692         as: route.name
       
  1693       });
       
  1694     });
       
  1695     return ret;
       
  1696   }, [routes]);
       
  1697   const match = useMatch(location, matcher, pathArg, matchResolverArgs);
       
  1698   const config = (0,external_wp_element_namespaceObject.useMemo)(() => ({
       
  1699     beforeNavigate,
       
  1700     pathArg
       
  1701   }), [beforeNavigate, pathArg]);
       
  1702   return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ConfigContext.Provider, {
       
  1703     value: config,
       
  1704     children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(RoutesContext.Provider, {
       
  1705       value: match,
       
  1706       children: children
       
  1707     })
       
  1708   });
       
  1709 }
       
  1710 
       
  1711 ;// ./node_modules/@wordpress/router/build-module/link.js
   918 /**
  1712 /**
   919  * WordPress dependencies
  1713  * WordPress dependencies
   920  */
  1714  */
   921 
  1715 
   922 
  1716 
       
  1717 
   923 /**
  1718 /**
   924  * Internal dependencies
  1719  * Internal dependencies
   925  */
  1720  */
   926 
  1721 
   927 
  1722 
   928 const RoutesContext = (0,external_wp_element_namespaceObject.createContext)();
  1723 function useLink(to, options = {}) {
   929 const HistoryContext = (0,external_wp_element_namespaceObject.createContext)();
  1724   var _getPath;
   930 function useLocation() {
  1725   const history = useHistory();
   931   return (0,external_wp_element_namespaceObject.useContext)(RoutesContext);
  1726   const {
   932 }
  1727     pathArg,
   933 function useHistory() {
  1728     beforeNavigate
   934   return (0,external_wp_element_namespaceObject.useContext)(HistoryContext);
  1729   } = (0,external_wp_element_namespaceObject.useContext)(ConfigContext);
   935 }
  1730   function onClick(event) {
   936 function RouterProvider({
  1731     event?.preventDefault();
   937   children
  1732     history.navigate(to, options);
       
  1733   }
       
  1734   const query = (0,external_wp_url_namespaceObject.getQueryArgs)(to);
       
  1735   const path = (_getPath = (0,external_wp_url_namespaceObject.getPath)('http://domain.com/' + to)) !== null && _getPath !== void 0 ? _getPath : '';
       
  1736   const link = (0,external_wp_element_namespaceObject.useMemo)(() => {
       
  1737     return beforeNavigate ? beforeNavigate({
       
  1738       path,
       
  1739       query
       
  1740     }) : {
       
  1741       path,
       
  1742       query
       
  1743     };
       
  1744   }, [path, query, beforeNavigate]);
       
  1745   const [before] = window.location.href.split('?');
       
  1746   return {
       
  1747     href: `${before}?${(0,external_wp_url_namespaceObject.buildQueryString)({
       
  1748       [pathArg]: link.path,
       
  1749       ...link.query
       
  1750     })}`,
       
  1751     onClick
       
  1752   };
       
  1753 }
       
  1754 function Link({
       
  1755   to,
       
  1756   options,
       
  1757   children,
       
  1758   ...props
   938 }) {
  1759 }) {
   939   const location = (0,external_wp_element_namespaceObject.useSyncExternalStore)(build_module_history.listen, build_module_history.getLocationWithParams, build_module_history.getLocationWithParams);
  1760   const {
   940   return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(HistoryContext.Provider, {
  1761     href,
   941     value: build_module_history,
  1762     onClick
   942     children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(RoutesContext.Provider, {
  1763   } = useLink(to, options);
   943       value: location,
  1764   return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("a", {
   944       children: children
  1765     href: href,
   945     })
  1766     onClick: onClick,
       
  1767     ...props,
       
  1768     children: children
   946   });
  1769   });
   947 }
  1770 }
   948 
  1771 
   949 ;// CONCATENATED MODULE: external ["wp","privateApis"]
  1772 ;// external ["wp","privateApis"]
   950 const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
  1773 const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
   951 ;// CONCATENATED MODULE: ./node_modules/@wordpress/router/build-module/lock-unlock.js
  1774 ;// ./node_modules/@wordpress/router/build-module/lock-unlock.js
   952 /**
  1775 /**
   953  * WordPress dependencies
  1776  * WordPress dependencies
   954  */
  1777  */
   955 
  1778 
   956 const {
  1779 const {
   957   lock,
  1780   lock,
   958   unlock
  1781   unlock
   959 } = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/router');
  1782 } = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/router');
   960 
  1783 
   961 ;// CONCATENATED MODULE: ./node_modules/@wordpress/router/build-module/private-apis.js
  1784 ;// ./node_modules/@wordpress/router/build-module/private-apis.js
   962 /**
  1785 /**
   963  * Internal dependencies
  1786  * Internal dependencies
   964  */
  1787  */
       
  1788 
   965 
  1789 
   966 
  1790 
   967 const privateApis = {};
  1791 const privateApis = {};
   968 lock(privateApis, {
  1792 lock(privateApis, {
   969   useHistory: useHistory,
  1793   useHistory: useHistory,
   970   useLocation: useLocation,
  1794   useLocation: useLocation,
   971   RouterProvider: RouterProvider
  1795   RouterProvider: RouterProvider,
       
  1796   useLink: useLink,
       
  1797   Link: Link
   972 });
  1798 });
   973 
  1799 
   974 ;// CONCATENATED MODULE: ./node_modules/@wordpress/router/build-module/index.js
  1800 ;// ./node_modules/@wordpress/router/build-module/index.js
   975 
  1801 
   976 
  1802 
   977 (window.wp = window.wp || {}).router = __webpack_exports__;
  1803 (window.wp = window.wp || {}).router = __webpack_exports__;
   978 /******/ })()
  1804 /******/ })()
   979 ;
  1805 ;