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O,EAAE,OAAO,CAAC,CAAC;QAC1D,IAAI,kBAAS,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC;YAAE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC7E,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IACH,eAAC;AAAD,CAAC,AA5SD,IA4SC;AA5SY,4BAAQ",
10 "sourcesContent": [
11 "import { UIRouter } from '../router';\nimport { Disposable } from '../interface';\nimport { MatcherUrlRule, UrlRule, UrlRuleHandlerFn, UrlRuleMatchFn, UrlRulesApi } from './interface';\nimport { TargetState, TargetStateDef } from '../state';\nimport { UrlMatcher } from './urlMatcher';\nimport { is, isDefined, isFunction, isString, removeFrom, val } from '../common';\nimport { UrlRuleFactory } from './urlRule';\n\nconst prioritySort = (a: UrlRule, b: UrlRule) => (b.priority || 0) - (a.priority || 0);\n\nconst typeSort = (a: UrlRule, b: UrlRule) => {\n const weights = { STATE: 4, URLMATCHER: 4, REGEXP: 3, RAW: 2, OTHER: 1 };\n return (weights[a.type] || 0) - (weights[b.type] || 0);\n};\n\nconst urlMatcherSort = (a: MatcherUrlRule, b: MatcherUrlRule) =>\n !a.urlMatcher || !b.urlMatcher ? 0 : UrlMatcher.compare(a.urlMatcher, b.urlMatcher);\n\nconst idSort = (a: UrlRule, b: UrlRule) => {\n // Identically sorted STATE and URLMATCHER best rule will be chosen by `matchPriority` after each rule matches the URL\n const useMatchPriority = { STATE: true, URLMATCHER: true };\n const equal = useMatchPriority[a.type] && useMatchPriority[b.type];\n return equal ? 0 : (a.$id || 0) - (b.$id || 0);\n};\n\n/**\n * Default rule priority sorting function.\n *\n * Sorts rules by:\n *\n * - Explicit priority (set rule priority using [[UrlRules.when]])\n * - Rule type (STATE: 4, URLMATCHER: 4, REGEXP: 3, RAW: 2, OTHER: 1)\n * - `UrlMatcher` specificity ([[UrlMatcher.compare]]): works for STATE and URLMATCHER types to pick the most specific rule.\n * - Rule registration order (for rule types other than STATE and URLMATCHER)\n * - Equally sorted State and UrlMatcher rules will each match the URL.\n * Then, the *best* match is chosen based on how many parameter values were matched.\n */\nlet defaultRuleSortFn: (a: UrlRule, b: UrlRule) => number;\ndefaultRuleSortFn = (a, b) => {\n let cmp = prioritySort(a, b);\n if (cmp !== 0) return cmp;\n\n cmp = typeSort(a, b);\n if (cmp !== 0) return cmp;\n\n cmp = urlMatcherSort(a as MatcherUrlRule, b as MatcherUrlRule);\n if (cmp !== 0) return cmp;\n\n return idSort(a, b);\n};\n\nfunction getHandlerFn(handler: string | UrlRuleHandlerFn | TargetState | TargetStateDef): UrlRuleHandlerFn {\n if (!isFunction(handler) && !isString(handler) && !is(TargetState)(handler) && !TargetState.isDef(handler)) {\n throw new Error(\"'handler' must be a string, function, TargetState, or have a state: 'newtarget' property\");\n }\n return isFunction(handler) ? (handler as UrlRuleHandlerFn) : val(handler);\n}\n\n/**\n * API for managing URL rules\n *\n * This API is used to create and manage URL rules.\n * URL rules are a mechanism to respond to specific URL patterns.\n *\n * The most commonly used methods are [[otherwise]] and [[when]].\n *\n * This API is found at `router.urlService.rules` (see: [[UIRouter.urlService]], [[URLService.rules]])\n */\nexport class UrlRules implements Disposable {\n /** used to create [[UrlRule]] objects for common cases */\n public urlRuleFactory: UrlRuleFactory;\n\n /** @internal */ private _sortFn = defaultRuleSortFn;\n /** @internal */ private _otherwiseFn: UrlRule;\n /** @internal */ private _sorted: boolean;\n /** @internal */ private _rules: UrlRule[] = [];\n /** @internal */ private _id = 0;\n\n /** @internal */\n constructor(/** @internal */ private router: UIRouter) {\n this.urlRuleFactory = new UrlRuleFactory(router);\n }\n\n /** @internal */\n public dispose(router?: UIRouter) {\n this._rules = [];\n delete this._otherwiseFn;\n }\n\n /**\n * Defines the initial state, path, or behavior to use when the app starts.\n *\n * This rule defines the initial/starting state for the application.\n *\n * This rule is triggered the first time the URL is checked (when the app initially loads).\n * The rule is triggered only when the url matches either `\"\"` or `\"/\"`.\n *\n * Note: The rule is intended to be used when the root of the application is directly linked to.\n * When the URL is *not* `\"\"` or `\"/\"` and doesn't match other rules, the [[otherwise]] rule is triggered.\n * This allows 404-like behavior when an unknown URL is deep-linked.\n *\n * #### Example:\n * Start app at `home` state.\n * ```js\n * .initial({ state: 'home' });\n * ```\n *\n * #### Example:\n * Start app at `/home` (by url)\n * ```js\n * .initial('/home');\n * ```\n *\n * #### Example:\n * When no other url rule matches, go to `home` state\n * ```js\n * .initial((matchValue, url, router) => {\n * console.log('initial state');\n * return { state: 'home' };\n * })\n * ```\n *\n * @param handler The initial state or url path, or a function which returns the state or url path (or performs custom logic).\n */\n public initial(handler: string | UrlRuleHandlerFn | TargetState | TargetStateDef) {\n const handlerFn: UrlRuleHandlerFn = getHandlerFn(handler);\n const matchFn: UrlRuleMatchFn = (urlParts, router) =>\n router.globals.transitionHistory.size() === 0 && !!/^\\/?$/.exec(urlParts.path);\n\n this.rule(this.urlRuleFactory.create(matchFn, handlerFn));\n }\n\n /**\n * Defines the state, url, or behavior to use when no other rule matches the URL.\n *\n * This rule is matched when *no other rule* matches.\n * It is generally used to handle unknown URLs (similar to \"404\" behavior, but on the client side).\n *\n * - If `handler` a string, it is treated as a url redirect\n *\n * #### Example:\n * When no other url rule matches, redirect to `/index`\n * ```js\n * .otherwise('/index');\n * ```\n *\n * - If `handler` is an object with a `state` property, the state is activated.\n *\n * #### Example:\n * When no other url rule matches, redirect to `home` and provide a `dashboard` parameter value.\n * ```js\n * .otherwise({ state: 'home', params: { dashboard: 'default' } });\n * ```\n *\n * - If `handler` is a function, the function receives the current url ([[UrlParts]]) and the [[UIRouter]] object.\n * The function can perform actions, and/or return a value.\n *\n * #### Example:\n * When no other url rule matches, manually trigger a transition to the `home` state\n * ```js\n * .otherwise((matchValue, urlParts, router) => {\n * router.stateService.go('home');\n * });\n * ```\n *\n * #### Example:\n * When no other url rule matches, go to `home` state\n * ```js\n * .otherwise((matchValue, urlParts, router) => {\n * return { state: 'home' };\n * });\n * ```\n *\n * @param handler The url path to redirect to, or a function which returns the url path (or performs custom logic).\n */\n public otherwise(handler: string | UrlRuleHandlerFn | TargetState | TargetStateDef) {\n const handlerFn: UrlRuleHandlerFn = getHandlerFn(handler);\n\n this._otherwiseFn = this.urlRuleFactory.create(val(true), handlerFn);\n this._sorted = false;\n }\n\n /**\n * Remove a rule previously registered\n *\n * @param rule the matcher rule that was previously registered using [[rule]]\n */\n public removeRule(rule): void {\n removeFrom(this._rules, rule);\n }\n\n /**\n * Manually adds a URL Rule.\n *\n * Usually, a url rule is added using [[StateDeclaration.url]] or [[when]].\n * This api can be used directly for more control (to register a [[BaseUrlRule]], for example).\n * Rules can be created using [[urlRuleFactory]], or created manually as simple objects.\n *\n * A rule should have a `match` function which returns truthy if the rule matched.\n * It should also have a `handler` function which is invoked if the rule is the best match.\n *\n * @return a function that deregisters the rule\n */\n public rule(rule: UrlRule): Function {\n if (!UrlRuleFactory.isUrlRule(rule)) throw new Error('invalid rule');\n rule.$id = this._id++;\n rule.priority = rule.priority || 0;\n\n this._rules.push(rule);\n this._sorted = false;\n\n return () => this.removeRule(rule);\n }\n\n /**\n * Gets all registered rules\n *\n * @returns an array of all the registered rules\n */\n public rules(): UrlRule[] {\n this.ensureSorted();\n return this._rules.concat(this._otherwiseFn ? [this._otherwiseFn] : []);\n }\n\n /**\n * Defines URL Rule priorities\n *\n * More than one rule ([[UrlRule]]) might match a given URL.\n * This `compareFn` is used to sort the rules by priority.\n * Higher priority rules should sort earlier.\n *\n * The [[defaultRuleSortFn]] is used by default.\n *\n * You only need to call this function once.\n * The `compareFn` will be used to sort the rules as each is registered.\n *\n * If called without any parameter, it will re-sort the rules.\n *\n * ---\n *\n * Url rules may come from multiple sources: states's urls ([[StateDeclaration.url]]), [[when]], and [[rule]].\n * Each rule has a (user-provided) [[UrlRule.priority]], a [[UrlRule.type]], and a [[UrlRule.$id]]\n * The `$id` is is the order in which the rule was registered.\n *\n * The sort function should use these data, or data found on a specific type\n * of [[UrlRule]] (such as [[StateRule.state]]), to order the rules as desired.\n *\n * #### Example:\n * This compare function prioritizes rules by the order in which the rules were registered.\n * A rule registered earlier has higher priority.\n *\n * ```js\n * function compareFn(a, b) {\n * return a.$id - b.$id;\n * }\n * ```\n *\n * @param compareFn a function that compares to [[UrlRule]] objects.\n * The `compareFn` should abide by the `Array.sort` compare function rules.\n * Given two rules, `a` and `b`, return a negative number if `a` should be higher priority.\n * Return a positive number if `b` should be higher priority.\n * Return `0` if the rules are identical.\n *\n * See the [mozilla reference](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#Description)\n * for details.\n */\n sort(compareFn?: (a: UrlRule, b: UrlRule) => number) {\n const sorted = this.stableSort(this._rules, (this._sortFn = compareFn || this._sortFn));\n\n // precompute _sortGroup values and apply to each rule\n let group = 0;\n for (let i = 0; i < sorted.length; i++) {\n sorted[i]._group = group;\n if (i < sorted.length - 1 && this._sortFn(sorted[i], sorted[i + 1]) !== 0) {\n group++;\n }\n }\n\n this._rules = sorted;\n this._sorted = true;\n }\n\n /** @internal */\n private ensureSorted() {\n this._sorted || this.sort();\n }\n\n /** @internal */\n private stableSort(arr, compareFn) {\n const arrOfWrapper = arr.map((elem, idx) => ({ elem, idx }));\n\n arrOfWrapper.sort((wrapperA, wrapperB) => {\n const cmpDiff = compareFn(wrapperA.elem, wrapperB.elem);\n return cmpDiff === 0 ? wrapperA.idx - wrapperB.idx : cmpDiff;\n });\n\n return arrOfWrapper.map((wrapper) => wrapper.elem);\n }\n\n /**\n * Registers a `matcher` and `handler` for custom URLs handling.\n *\n * The `matcher` can be:\n *\n * - a [[UrlMatcher]]: See: [[UrlMatcherFactory.compile]]\n * - a `string`: The string is compiled to a [[UrlMatcher]]\n * - a `RegExp`: The regexp is used to match the url.\n *\n * The `handler` can be:\n *\n * - a string: The url is redirected to the value of the string.\n * - a function: The url is redirected to the return value of the function.\n *\n * ---\n *\n * When the `handler` is a `string` and the `matcher` is a `UrlMatcher` (or string), the redirect\n * string is interpolated with parameter values.\n *\n * #### Example:\n * When the URL is `/foo/123` the rule will redirect to `/bar/123`.\n * ```js\n * .when(\"/foo/:param1\", \"/bar/:param1\")\n * ```\n *\n * ---\n *\n * When the `handler` is a string and the `matcher` is a `RegExp`, the redirect string is\n * interpolated with capture groups from the RegExp.\n *\n * #### Example:\n * When the URL is `/foo/123` the rule will redirect to `/bar/123`.\n * ```js\n * .when(new RegExp(\"^/foo/(.*)$\"), \"/bar/$1\");\n * ```\n *\n * ---\n *\n * When the handler is a function, it receives the matched value, the current URL, and the `UIRouter` object (See [[UrlRuleHandlerFn]]).\n * The \"matched value\" differs based on the `matcher`.\n * For [[UrlMatcher]]s, it will be the matched state params.\n * For `RegExp`, it will be the match array from `regexp.exec()`.\n *\n * If the handler returns a string, the URL is redirected to the string.\n *\n * #### Example:\n * When the URL is `/foo/123` the rule will redirect to `/bar/123`.\n * ```js\n * .when(new RegExp(\"^/foo/(.*)$\"), match => \"/bar/\" + match[1]);\n * ```\n *\n * Note: the `handler` may also invoke arbitrary code, such as `$state.go()`\n *\n * @param matcher A pattern `string` to match, compiled as a [[UrlMatcher]], or a `RegExp`.\n * @param handler The path to redirect to, or a function that returns the path.\n * @param options `{ priority: number }`\n *\n * @return the registered [[UrlRule]]\n */\n public when(\n matcher: RegExp | UrlMatcher | string,\n handler: string | UrlRuleHandlerFn,\n options?: { priority: number }\n ): UrlRule {\n const rule = this.urlRuleFactory.create(matcher, handler);\n if (isDefined(options && options.priority)) rule.priority = options.priority;\n this.rule(rule);\n return rule;\n }\n}\n"
12 ]
13}
\No newline at end of file