@opentripplanner/core-utils 13.0.0-alpha.1 → 13.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/esm/graphql.d.js.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/itinerary.js +78 -115
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +3 -3
- package/esm/map.js.map +1 -1
- package/esm/profile.js +17 -18
- package/esm/profile.js.map +1 -1
- package/esm/query-gen.js +35 -45
- package/esm/query-gen.js.map +1 -1
- package/esm/query.js +135 -191
- package/esm/query.js.map +1 -1
- package/esm/route.js +74 -97
- package/esm/route.js.map +1 -1
- package/esm/storage.js +4 -5
- package/esm/storage.js.map +1 -1
- package/esm/suspense.js +1 -3
- package/esm/suspense.js.map +1 -1
- package/esm/time.js +13 -17
- package/esm/time.js.map +1 -1
- package/esm/ui.js +0 -5
- package/esm/ui.js.map +1 -1
- package/lib/graphql.d.js.map +1 -1
- package/lib/index.js +3 -19
- package/lib/index.js.map +1 -1
- package/lib/itinerary.js +114 -199
- package/lib/itinerary.js.map +1 -1
- package/lib/map.d.ts +1 -1
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +9 -20
- package/lib/map.js.map +1 -1
- package/lib/profile.js +17 -19
- package/lib/profile.js.map +1 -1
- package/lib/query-gen.d.ts +4 -4
- package/lib/query-gen.d.ts.map +1 -1
- package/lib/query-gen.js +34 -45
- package/lib/query-gen.js.map +1 -1
- package/lib/query-params.jsx +893 -0
- package/lib/query.js +66 -118
- package/lib/query.js.map +1 -1
- package/lib/route.js +73 -101
- package/lib/route.js.map +1 -1
- package/lib/storage.js +6 -11
- package/lib/storage.js.map +1 -1
- package/lib/suspense.d.ts +1 -1
- package/lib/suspense.d.ts.map +1 -1
- package/lib/suspense.js +3 -9
- package/lib/suspense.js.map +1 -1
- package/lib/time.js +19 -38
- package/lib/time.js.map +1 -1
- package/lib/ui.js +1 -8
- package/lib/ui.js.map +1 -1
- package/package.json +7 -8
- package/src/query-params.jsx +893 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/esm/query-params.js +0 -786
- package/esm/query-params.js.map +0 -1
- package/lib/query-params.js +0 -756
- package/lib/query-params.js.map +0 -1
- /package/{src/query-params.js → esm/query-params.jsx} +0 -0
package/esm/route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/route.ts"],"names":["chroma","getTransitOperatorFromFeedIdAndAgencyId","feedId","agencyId","transitOperators","find","transitOperator","getTransitOperatorFromLeg","leg","routeId","split","getTransitOperatorFromOtpRoute","route","id","agency","END_OF_LIST_COMPARATOR_VALUE","getTransitOperatorComparatorValue","length","name","agencyName","order","makeTransitOperatorComparator","a","b","aVal","bVal","getSortValues","getterFn","modeComparatorValue","SUBWAY","TRAM","TROLLEYBUS","RAIL","GONDOLA","FERRY","CABLE_CAR","FUNICULAR","BUS","routeTypeComparatorValue","getRouteTypeComparatorValue","Error","mode","type","console","warn","routeTypeComparator","startsWithAlphabeticCharacter","val","firstCharCode","charCodeAt","alphabeticShortNameComparator","aStartsWithAlphabeticCharacter","shortName","bStartsWithAlphabeticCharacter","makeNumericValueComparator","objGetterFn","isNaN","makeStringValueComparator","getRouteSortOrderValue","undefined","makeMultiCriteriaSort","criteria","i","curCriteriaComparatorValue","makeRouteComparator","obj","sortOrder","parseInt","longName","getMostReadableTextColor","backgroundColor","proposedTextColor","startsWith","fgLuminance","luminance","bgLuminance","Math","abs"],"mappings":"AACA,OAAOA,MAAP,MAAmB,WAAnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,uCAAT,CACLC,MADK,EAELC,QAFK,EAGLC,gBAHK,EAIY;AACjB,SACEA,gBAAgB,CAACC,IAAjB,CACE,UAAAC,eAAe;AAAA,WACbA,eAAe,CAACJ,MAAhB,KAA2BA,MAA3B,IACAI,eAAe,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,IAAsC,GAHxC,EAIE;AACA,WAAOF,iBAAP;AACD,GAtBO,CAwBR;AACA;;;AACA,SAAOvE,MAAM,CAACsE,eAAD,CAAN,CAAwBI,SAAxB,KAAsC,GAAtC,GAA4C,SAA5C,GAAwD,SAA/D;AACD","sourcesContent":["import { Leg, Route, TransitOperator } from \"@opentripplanner/types\";\nimport chroma from \"chroma-js\";\n/**\n * Returns the transit operator (if an exact match is found) from the transit\n * operators config value. It is critical to use both the feedId and agencyId in\n * this method because it is possible in OTP for there to be a duplicate\n * agencyId in separate feeds.\n *\n * @param {string} feedId The feedId that this transit agency belongs to\n * @param {string} agencyId The agencyId of the transit agency\n * @param {array} transitOperators The transitOperators list from the config\n * @return {object} The transitOperator if a match was found or null if no match\n * was found\n */\nexport function getTransitOperatorFromFeedIdAndAgencyId(\n feedId: string,\n agencyId: string | number,\n transitOperators: TransitOperator[]\n): TransitOperator {\n return (\n transitOperators.find(\n transitOperator =>\n transitOperator.feedId === feedId &&\n transitOperator.agencyId === agencyId\n ) || null\n );\n}\n\n/**\n * Looks up an operator from the provided leg.\n *\n * @param {object} leg The Itinerary Leg from which to find the transit\n * operator\n * @param {object} transitOperators transitOperators from config.\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromLeg(\n leg: Leg,\n transitOperators: TransitOperator[]\n): TransitOperator {\n if (!leg.routeId || !leg.agencyId) return null;\n const feedId = leg.routeId.split(\":\")[0];\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n leg.agencyId,\n transitOperators\n );\n}\n\n/**\n * Looks up an operator from the provided configuration given an OTP route.\n * NOTE: this assumes the use of the OTP Route model or a modified OTP\n * RouteShort model (such as the one found in the IBI fork of OTP) that also\n * returns the agencyId.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromOtpRoute(\n route: Route,\n transitOperators: TransitOperator[]\n): TransitOperator {\n if (!route.id) return null;\n const feedId = route.id.split(\":\")[0];\n let agencyId: string | number;\n if (route.agency) {\n // This is returned in the OTP Route model\n agencyId = route.agency.id;\n } else if (route.agencyId) {\n // This is returned in the OTP RouteShort model (such as in the IBI fork)\n agencyId = route.agencyId;\n } else {\n return null;\n }\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n agencyId,\n transitOperators\n );\n}\n\n// The functions below are for enhanced route sorting functions for the route\n// viewer on OTP-react-redux.\n// They address route ordering issues discussed in\n// https://github.com/opentripplanner/otp-react-redux/pull/123 and\n// https://github.com/opentripplanner/otp-react-redux/pull/124.\n\n/**\n * A large comparator value that can safely be used in mathematical sort\n * comparisons to place things at the end of lists\n */\nconst END_OF_LIST_COMPARATOR_VALUE = 999999999999;\n\n/**\n * Returns a transit operator comparator value given a route and an optional\n * transitOperators config value. This function will do its best to handle all\n * kinds of input data as certain deployments of an implementing webapp may have\n * incomplete data and certain versions of OTP might not have a modified\n * implementation of the RouteShort model.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {mixed} this could return a string value (the route's agency name) if\n * the transitOperators value is not defined. Otherwise an integer will be\n * returned.\n */\nfunction getTransitOperatorComparatorValue(\n route: Route,\n transitOperators: TransitOperator[]\n): number | string {\n // if the transitOperators is undefined or has zero length, use the route's\n // agency name as the comparator value\n if (!transitOperators || transitOperators.length === 0) {\n // OTP Route\n if (route.agency) return route.agency.name;\n // OTP RouteShort (base OTP repo or IBI fork)\n if (route.agencyName) return route.agencyName;\n // shouldn't happen as agency names will be defined\n return \"zzz\";\n }\n\n // find operator associated with route\n const transitOperator = getTransitOperatorFromOtpRoute(\n route,\n transitOperators\n );\n\n // if transit operator not found, return infinity\n if (!transitOperator) return END_OF_LIST_COMPARATOR_VALUE;\n\n // return the transit operator's sort value or END_OF_LIST_COMPARATOR_VALUE if\n // the sort value is not a number\n return typeof transitOperator.order === \"number\"\n ? transitOperator.order\n : END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of the\n * route's agency and provided transitOperators config data.\n */\nfunction makeTransitOperatorComparator(transitOperators: TransitOperator[]) {\n return (a: Route, b: Route) => {\n const aVal = getTransitOperatorComparatorValue(a, transitOperators);\n const bVal = getTransitOperatorComparatorValue(b, transitOperators);\n if (typeof aVal === \"string\") {\n // happens when transitOperators is undefined. Both aVal are guaranteed to\n // be strings. Make a string comparison.\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n }\n // @ts-expect-error transitOperators are defined and therefore a numeric value is guaranteed\n // to be returned\n return aVal - bVal;\n };\n}\n\n/**\n * Gets the desired sort values according to an optional getter function. If the\n * getter function is not defined, the original sort values are returned.\n */\nfunction getSortValues(\n getterFn: (item: unknown) => unknown,\n a: unknown,\n b: unknown\n) {\n let aVal: unknown;\n let bVal: unknown;\n if (typeof getterFn === \"function\") {\n aVal = getterFn(a);\n bVal = getterFn(b);\n } else {\n aVal = a;\n bVal = b;\n }\n return { aVal, bVal };\n}\n\n// Lookup for the sort values associated with various OTP modes.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst modeComparatorValue = {\n SUBWAY: 1,\n TRAM: 2,\n TROLLEYBUS: 9,\n RAIL: 3,\n GONDOLA: 4,\n FERRY: 5,\n CABLE_CAR: 6,\n FUNICULAR: 7,\n BUS: 8\n};\n\n// Lookup that maps route types to the OTP mode sort values.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst routeTypeComparatorValue = {\n 0: modeComparatorValue.TRAM, // - Tram, Streetcar, Light rail.\n 1: modeComparatorValue.SUBWAY, // - Subway, Metro.\n 2: modeComparatorValue.RAIL, // - Rail. Used for intercity or long-distance travel.\n 3: modeComparatorValue.BUS, // - Bus.\n 4: modeComparatorValue.FERRY, // - Ferry.\n 5: modeComparatorValue.CABLE_CAR, // - Cable tram.\n 6: modeComparatorValue.GONDOLA, // - Gondola, etc.\n 7: modeComparatorValue.FUNICULAR, // - Funicular.\n // TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just\n // associate them with bus/rail.\n 11: modeComparatorValue.BUS, // - Trolleybus.\n 12: modeComparatorValue.RAIL, // - Monorail.\n 13: modeComparatorValue.TROLLEYBUS\n};\n\n// Gets a comparator value for a given route's type (OTP mode).\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// ttps://github.com/documentationjs/documentation/issues/372\nfunction getRouteTypeComparatorValue(route: Route): number {\n // For some strange reason, the short route response in OTP returns the\n // string-based modes, but the long route response returns the\n // integer route type. This attempts to account for both of those cases.\n if (!route) throw new Error(`Route is undefined. ${route}`);\n if (typeof modeComparatorValue[route.mode] !== \"undefined\") {\n return modeComparatorValue[route.mode];\n }\n if (typeof routeTypeComparatorValue[route.type] !== \"undefined\") {\n return routeTypeComparatorValue[route.type];\n }\n // Default the comparator value to a large number (placing the route at the\n // end of the list).\n // eslint-disable-next-line no-console\n console.warn(\"no mode/route type found for route\", route);\n return END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of route type\n * (OTP mode).\n */\nfunction routeTypeComparator(a: Route, b: Route): number {\n return getRouteTypeComparatorValue(a) - getRouteTypeComparatorValue(b);\n}\n\n/**\n * Determines whether a value is a string that starts with an alphabetic\n * ascii character.\n */\nfunction startsWithAlphabeticCharacter(val: unknown): boolean {\n if (typeof val === \"string\" && val.length > 0) {\n const firstCharCode = val.charCodeAt(0);\n return (\n (firstCharCode >= 65 && firstCharCode <= 90) ||\n (firstCharCode >= 97 && firstCharCode <= 122)\n );\n }\n return false;\n}\n\n/**\n * Sorts routes based off of whether the shortName begins with an alphabetic\n * character. Routes with shortn that do start with an alphabetic character will\n * be prioritized over those that don't.\n */\nfunction alphabeticShortNameComparator(a: Route, b: Route): number {\n const aStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n a.shortName\n );\n const bStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n b.shortName\n );\n\n if (aStartsWithAlphabeticCharacter && bStartsWithAlphabeticCharacter) {\n // both start with an alphabetic character, return equivalence\n return 0;\n }\n // a does start with an alphabetic character, but b does not. Prioritize a\n if (aStartsWithAlphabeticCharacter) return -1;\n // b does start with an alphabetic character, but a does not. Prioritize b\n if (bStartsWithAlphabeticCharacter) return 1;\n // neither route has a shortName that starts with an alphabetic character.\n // Return equivalence\n return 0;\n}\n\n/**\n * Checks whether an appropriate comparison of numeric values can be made for\n * sorting purposes. If both values are not valid numbers according to the\n * isNaN check, then this function returns undefined which indicates that a\n * secondary sorting criteria should be used instead. If one value is valid and\n * the other is not, then the valid value will be given sorting priority. If\n * both values are valid numbers, the difference is obtained as the sort value.\n *\n * An optional argument can be provided which will be used to obtain the\n * comparison value from the comparison function arguments.\n *\n * IMPORTANT: the comparison values must be numeric values or at least be\n * attempted to be converted to numeric values! If one of the arguments is\n * something crazy like an empty string, unexpected behavior will occur because\n * JavaScript.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeNumericValueComparator(\n objGetterFn?: (item: Route) => number\n) {\n /* Note: Using the global version of isNaN (the Number version behaves differently. */\n /* eslint-disable no-restricted-globals */\n return (a: number, b: number): number => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n if (typeof aVal !== \"number\" || typeof bVal !== \"number\") return 0;\n\n // if both values aren't valid numbers, use the next sort criteria\n if (isNaN(aVal) && isNaN(bVal)) return 0;\n // b is a valid number, b gets priority\n if (isNaN(aVal)) return 1;\n // a is a valid number, a gets priority\n if (isNaN(bVal)) return -1;\n // a and b are valid numbers, return the sort value\n return aVal - bVal;\n };\n}\n\n/**\n * Create a comparator function that compares string values. The comparison\n * values feed to the sort comparator function are assumed to be objects that\n * will have either undefined, null or string values at the given key. If one\n * object has undefined, null or an empty string, but the other does have a\n * string with length > 0, then that string will get priority.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeStringValueComparator(\n objGetterFn?: (item: Route) => string\n) {\n return (a: string, b: string): number => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n // both a and b are uncomparable strings, return equivalent value\n if (!aVal && !bVal) return 0;\n // a is not a comparable string, b gets priority\n if (!aVal) return 1;\n // b is not a comparable string, a gets priority\n if (!bVal) return -1;\n // a and b are comparable strings, return the sort value\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n };\n}\n\n/**\n * OpenTripPlanner sets the routeSortOrder to -999 by default. So, if that value\n * is encountered, assume that it actually means that the routeSortOrder is not\n * set in the GTFS.\n *\n * See https://github.com/opentripplanner/OpenTripPlanner/issues/2938\n * Also see https://github.com/opentripplanner/otp-react-redux/issues/122\n */\nfunction getRouteSortOrderValue(val: number): number {\n return val === -999 ? undefined : val;\n}\n\n/**\n * Create a multi-criteria sort comparator function composed of other sort\n * comparator functions. Each comparator function will be ran in the order given\n * until a non-zero comparison value is obtained which is then immediately\n * returned. If all comparison functions return equivalence, then the values\n * are assumed to be equivalent.\n */\nfunction makeMultiCriteriaSort(\n ...criteria: ((a: unknown, b: unknown) => number)[]\n) {\n return (a: number, b: number): number => {\n for (let i = 0; i < criteria.length; i++) {\n const curCriteriaComparatorValue = criteria[i](a, b);\n // if the comparison objects are not equivalent, return the value obtained\n // in this current criteria comparison\n if (curCriteriaComparatorValue !== 0) {\n return curCriteriaComparatorValue;\n }\n }\n return 0;\n };\n}\n\n/**\n * Creates a sort comparator function to compares routes for the purposes of\n * sorting and displaying in a user interface. This takes in a single optional\n * argument which should be a list of transitOperators as defined in the config\n * file. Due to GTFS feeds having varying levels of data quality, a multi-\n * criteria sort is needed to account for various differences. The criteria\n * included here are each applied to the routes in the order listed. If a given\n * sort criterion yields equivalence (e.g., two routes have the short name\n * \"20\"), the comparator falls back onto the next sort criterion (e.g., long\n * name). The sort operates on the following values (in order):\n *\n * 1. Transit Operator. The transit operator will be attempted to be obtained\n * for each route. If no argument is provided when creating this comparator\n * function, then routes will be sorted by their agency's name. If an\n * argument is provided and a match is found based off of the route's feed_id\n * and agency_id and a transitOperator's feed_id and agency_id, then the\n * field transitOperator.order will be used as the comparator value as long\n * as it is numeric. If it is not numeric, a value is returned indicating\n * that this transit operator should be placed at the end of the list.\n * 2. sortOrder. Routes that do not have a valid sortOrder will be placed\n * beneath those that do.\n * 3. route type (OTP mode). See routeTypeComparator code for prioritization of\n * route types.\n * 4. shortNames that begin with alphabetic characters. shortNames that do not\n * start with alphabetic characters will be place beneath those that do.\n * 5. shortName as integer. shortNames that cannot be parsed as integers will\n * be placed beneath those that are valid.\n * 6. shortName as string. Routes without shortNames will be placed beneath\n * those with shortNames.\n * 7. longName as string.\n */\nexport function makeRouteComparator(\n transitOperators: TransitOperator[]\n): (a: number, b: number) => number {\n return makeMultiCriteriaSort(\n makeTransitOperatorComparator(transitOperators),\n makeNumericValueComparator(obj => getRouteSortOrderValue(obj.sortOrder)),\n routeTypeComparator,\n alphabeticShortNameComparator,\n makeNumericValueComparator(obj => parseInt(obj.shortName, 10)),\n makeStringValueComparator(obj => obj.shortName),\n makeStringValueComparator(obj => obj.longName)\n );\n}\n\n/**\n * Tests if a pair of colors is readable. If it is, that readable color is returned.\n * If it is not, a more appropriate alternative is returned.\n *\n * Uses algorithm based on combined luminance. Values have been derived from\n * looking at real agency color pairings. These pairings are difficult to\n * generate for, as some colors see both white and black used by different agencies.\n *\n * This method therefore can accept multiple colors (including black and white) for the same background color.\n *\n * @param backgroundColor A hex string, usually the \"routeColor\"\n * @param proposedTextColor A hex string, usually the \"routeTextColor\"\n */\nexport function getMostReadableTextColor(\n backgroundColor: string,\n proposedTextColor?: string\n): string {\n // Sometimes input will defy the method signature. Therefore we need extra fallbacks\n if (!backgroundColor) backgroundColor = \"#333333\";\n if (!proposedTextColor) proposedTextColor = \"#ffffff\";\n\n if (!backgroundColor.startsWith(\"#\")) {\n backgroundColor = `#${backgroundColor}`;\n }\n if (!proposedTextColor.startsWith(\"#\")) {\n proposedTextColor = `#${proposedTextColor}`;\n }\n\n // Check if proposed color is readable\n // Luminance thresholds have been selected based on actual transit agency colors\n const fgLuminance = chroma(proposedTextColor).luminance();\n const bgLuminance = chroma(backgroundColor).luminance();\n if (\n bgLuminance + fgLuminance < 1.41 &&\n bgLuminance + fgLuminance > 0.25 &&\n Math.abs(bgLuminance - fgLuminance) > 0.2\n ) {\n return proposedTextColor;\n }\n\n // Return black or white based on luminance of background color\n // When generating colors, white is preferred.\n return chroma(backgroundColor).luminance() < 0.4 ? \"#ffffff\" : \"#000000\";\n}\n"],"file":"route.js"}
|
|
1
|
+
{"version":3,"file":"route.js","names":["chroma","getTransitOperatorFromFeedIdAndAgencyId","feedId","agencyId","transitOperators","find","transitOperator","getTransitOperatorFromLeg","leg","routeId","split","getTransitOperatorFromOtpRoute","route","id","agency","END_OF_LIST_COMPARATOR_VALUE","getTransitOperatorComparatorValue","length","name","agencyName","order","makeTransitOperatorComparator","a","b","aVal","bVal","getSortValues","getterFn","modeComparatorValue","SUBWAY","TRAM","TROLLEYBUS","RAIL","GONDOLA","FERRY","CABLE_CAR","FUNICULAR","BUS","routeTypeComparatorValue","getRouteTypeComparatorValue","Error","concat","mode","type","console","warn","routeTypeComparator","startsWithAlphabeticCharacter","val","firstCharCode","charCodeAt","alphabeticShortNameComparator","aStartsWithAlphabeticCharacter","shortName","bStartsWithAlphabeticCharacter","makeNumericValueComparator","objGetterFn","_getSortValues","isNaN","makeStringValueComparator","_getSortValues2","getRouteSortOrderValue","undefined","makeMultiCriteriaSort","_len","arguments","criteria","Array","_key","i","curCriteriaComparatorValue","makeRouteComparator","obj","sortOrder","parseInt","longName","getMostReadableTextColor","backgroundColor","proposedTextColor","startsWith","fgLuminance","luminance","bgLuminance","Math","abs"],"sources":["../src/route.ts"],"sourcesContent":["import { Leg, Route, TransitOperator } from \"@opentripplanner/types\";\nimport chroma from \"chroma-js\";\n/**\n * Returns the transit operator (if an exact match is found) from the transit\n * operators config value. It is critical to use both the feedId and agencyId in\n * this method because it is possible in OTP for there to be a duplicate\n * agencyId in separate feeds.\n *\n * @param {string} feedId The feedId that this transit agency belongs to\n * @param {string} agencyId The agencyId of the transit agency\n * @param {array} transitOperators The transitOperators list from the config\n * @return {object} The transitOperator if a match was found or null if no match\n * was found\n */\nexport function getTransitOperatorFromFeedIdAndAgencyId(\n feedId: string,\n agencyId: string | number,\n transitOperators: TransitOperator[]\n): TransitOperator {\n return (\n transitOperators.find(\n transitOperator =>\n transitOperator.feedId === feedId &&\n transitOperator.agencyId === agencyId\n ) || null\n );\n}\n\n/**\n * Looks up an operator from the provided leg.\n *\n * @param {object} leg The Itinerary Leg from which to find the transit\n * operator\n * @param {object} transitOperators transitOperators from config.\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromLeg(\n leg: Leg,\n transitOperators: TransitOperator[]\n): TransitOperator {\n if (!leg.routeId || !leg.agencyId) return null;\n const feedId = leg.routeId.split(\":\")[0];\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n leg.agencyId,\n transitOperators\n );\n}\n\n/**\n * Looks up an operator from the provided configuration given an OTP route.\n * NOTE: this assumes the use of the OTP Route model or a modified OTP\n * RouteShort model (such as the one found in the IBI fork of OTP) that also\n * returns the agencyId.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {object} the operator if one was found or null if no match was found\n */\nexport function getTransitOperatorFromOtpRoute(\n route: Route,\n transitOperators: TransitOperator[]\n): TransitOperator {\n if (!route.id) return null;\n const feedId = route.id.split(\":\")[0];\n let agencyId: string | number;\n if (route.agency) {\n // This is returned in the OTP Route model\n agencyId = route.agency.id;\n } else if (route.agencyId) {\n // This is returned in the OTP RouteShort model (such as in the IBI fork)\n agencyId = route.agencyId;\n } else {\n return null;\n }\n return getTransitOperatorFromFeedIdAndAgencyId(\n feedId,\n agencyId,\n transitOperators\n );\n}\n\n// The functions below are for enhanced route sorting functions for the route\n// viewer on OTP-react-redux.\n// They address route ordering issues discussed in\n// https://github.com/opentripplanner/otp-react-redux/pull/123 and\n// https://github.com/opentripplanner/otp-react-redux/pull/124.\n\n/**\n * A large comparator value that can safely be used in mathematical sort\n * comparisons to place things at the end of lists\n */\nconst END_OF_LIST_COMPARATOR_VALUE = 999999999999;\n\n/**\n * Returns a transit operator comparator value given a route and an optional\n * transitOperators config value. This function will do its best to handle all\n * kinds of input data as certain deployments of an implementing webapp may have\n * incomplete data and certain versions of OTP might not have a modified\n * implementation of the RouteShort model.\n *\n * @param {object} route Either an OTP Route or RouteShort model\n * @param {array} transitOperators transitOperators from config\n * @return {mixed} this could return a string value (the route's agency name) if\n * the transitOperators value is not defined. Otherwise an integer will be\n * returned.\n */\nfunction getTransitOperatorComparatorValue(\n route: Route,\n transitOperators: TransitOperator[]\n): number | string {\n // if the transitOperators is undefined or has zero length, use the route's\n // agency name as the comparator value\n if (!transitOperators || transitOperators.length === 0) {\n // OTP Route\n if (route.agency) return route.agency.name;\n // OTP RouteShort (base OTP repo or IBI fork)\n if (route.agencyName) return route.agencyName;\n // shouldn't happen as agency names will be defined\n return \"zzz\";\n }\n\n // find operator associated with route\n const transitOperator = getTransitOperatorFromOtpRoute(\n route,\n transitOperators\n );\n\n // if transit operator not found, return infinity\n if (!transitOperator) return END_OF_LIST_COMPARATOR_VALUE;\n\n // return the transit operator's sort value or END_OF_LIST_COMPARATOR_VALUE if\n // the sort value is not a number\n return typeof transitOperator.order === \"number\"\n ? transitOperator.order\n : END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of the\n * route's agency and provided transitOperators config data.\n */\nfunction makeTransitOperatorComparator(transitOperators: TransitOperator[]) {\n return (a: Route, b: Route) => {\n const aVal = getTransitOperatorComparatorValue(a, transitOperators);\n const bVal = getTransitOperatorComparatorValue(b, transitOperators);\n if (typeof aVal === \"string\") {\n // happens when transitOperators is undefined. Both aVal are guaranteed to\n // be strings. Make a string comparison.\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n }\n // @ts-expect-error transitOperators are defined and therefore a numeric value is guaranteed\n // to be returned\n return aVal - bVal;\n };\n}\n\n/**\n * Gets the desired sort values according to an optional getter function. If the\n * getter function is not defined, the original sort values are returned.\n */\nfunction getSortValues(\n getterFn: (item: unknown) => unknown,\n a: unknown,\n b: unknown\n) {\n let aVal: unknown;\n let bVal: unknown;\n if (typeof getterFn === \"function\") {\n aVal = getterFn(a);\n bVal = getterFn(b);\n } else {\n aVal = a;\n bVal = b;\n }\n return { aVal, bVal };\n}\n\n// Lookup for the sort values associated with various OTP modes.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst modeComparatorValue = {\n SUBWAY: 1,\n TRAM: 2,\n TROLLEYBUS: 9,\n RAIL: 3,\n GONDOLA: 4,\n FERRY: 5,\n CABLE_CAR: 6,\n FUNICULAR: 7,\n BUS: 8\n};\n\n// Lookup that maps route types to the OTP mode sort values.\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// https://github.com/documentationjs/documentation/issues/372\nconst routeTypeComparatorValue = {\n 0: modeComparatorValue.TRAM, // - Tram, Streetcar, Light rail.\n 1: modeComparatorValue.SUBWAY, // - Subway, Metro.\n 2: modeComparatorValue.RAIL, // - Rail. Used for intercity or long-distance travel.\n 3: modeComparatorValue.BUS, // - Bus.\n 4: modeComparatorValue.FERRY, // - Ferry.\n 5: modeComparatorValue.CABLE_CAR, // - Cable tram.\n 6: modeComparatorValue.GONDOLA, // - Gondola, etc.\n 7: modeComparatorValue.FUNICULAR, // - Funicular.\n // TODO: 11 and 12 are not a part of OTP as of 2019-02-14, but for now just\n // associate them with bus/rail.\n 11: modeComparatorValue.BUS, // - Trolleybus.\n 12: modeComparatorValue.RAIL, // - Monorail.\n 13: modeComparatorValue.TROLLEYBUS\n};\n\n// Gets a comparator value for a given route's type (OTP mode).\n// Note: JSDoc format not used to avoid bug in documentationjs.\n// ttps://github.com/documentationjs/documentation/issues/372\nfunction getRouteTypeComparatorValue(route: Route): number {\n // For some strange reason, the short route response in OTP returns the\n // string-based modes, but the long route response returns the\n // integer route type. This attempts to account for both of those cases.\n if (!route) throw new Error(`Route is undefined. ${route}`);\n if (typeof modeComparatorValue[route.mode] !== \"undefined\") {\n return modeComparatorValue[route.mode];\n }\n if (typeof routeTypeComparatorValue[route.type] !== \"undefined\") {\n return routeTypeComparatorValue[route.type];\n }\n // Default the comparator value to a large number (placing the route at the\n // end of the list).\n // eslint-disable-next-line no-console\n console.warn(\"no mode/route type found for route\", route);\n return END_OF_LIST_COMPARATOR_VALUE;\n}\n\n/**\n * Calculates the sort comparator value given two routes based off of route type\n * (OTP mode).\n */\nfunction routeTypeComparator(a: Route, b: Route): number {\n return getRouteTypeComparatorValue(a) - getRouteTypeComparatorValue(b);\n}\n\n/**\n * Determines whether a value is a string that starts with an alphabetic\n * ascii character.\n */\nfunction startsWithAlphabeticCharacter(val: unknown): boolean {\n if (typeof val === \"string\" && val.length > 0) {\n const firstCharCode = val.charCodeAt(0);\n return (\n (firstCharCode >= 65 && firstCharCode <= 90) ||\n (firstCharCode >= 97 && firstCharCode <= 122)\n );\n }\n return false;\n}\n\n/**\n * Sorts routes based off of whether the shortName begins with an alphabetic\n * character. Routes with shortn that do start with an alphabetic character will\n * be prioritized over those that don't.\n */\nfunction alphabeticShortNameComparator(a: Route, b: Route): number {\n const aStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n a.shortName\n );\n const bStartsWithAlphabeticCharacter = startsWithAlphabeticCharacter(\n b.shortName\n );\n\n if (aStartsWithAlphabeticCharacter && bStartsWithAlphabeticCharacter) {\n // both start with an alphabetic character, return equivalence\n return 0;\n }\n // a does start with an alphabetic character, but b does not. Prioritize a\n if (aStartsWithAlphabeticCharacter) return -1;\n // b does start with an alphabetic character, but a does not. Prioritize b\n if (bStartsWithAlphabeticCharacter) return 1;\n // neither route has a shortName that starts with an alphabetic character.\n // Return equivalence\n return 0;\n}\n\n/**\n * Checks whether an appropriate comparison of numeric values can be made for\n * sorting purposes. If both values are not valid numbers according to the\n * isNaN check, then this function returns undefined which indicates that a\n * secondary sorting criteria should be used instead. If one value is valid and\n * the other is not, then the valid value will be given sorting priority. If\n * both values are valid numbers, the difference is obtained as the sort value.\n *\n * An optional argument can be provided which will be used to obtain the\n * comparison value from the comparison function arguments.\n *\n * IMPORTANT: the comparison values must be numeric values or at least be\n * attempted to be converted to numeric values! If one of the arguments is\n * something crazy like an empty string, unexpected behavior will occur because\n * JavaScript.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeNumericValueComparator(\n objGetterFn?: (item: Route) => number\n) {\n /* Note: Using the global version of isNaN (the Number version behaves differently. */\n /* eslint-disable no-restricted-globals */\n return (a: number, b: number): number => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n if (typeof aVal !== \"number\" || typeof bVal !== \"number\") return 0;\n\n // if both values aren't valid numbers, use the next sort criteria\n if (isNaN(aVal) && isNaN(bVal)) return 0;\n // b is a valid number, b gets priority\n if (isNaN(aVal)) return 1;\n // a is a valid number, a gets priority\n if (isNaN(bVal)) return -1;\n // a and b are valid numbers, return the sort value\n return aVal - bVal;\n };\n}\n\n/**\n * Create a comparator function that compares string values. The comparison\n * values feed to the sort comparator function are assumed to be objects that\n * will have either undefined, null or string values at the given key. If one\n * object has undefined, null or an empty string, but the other does have a\n * string with length > 0, then that string will get priority.\n *\n * @param {function} [objGetterFn] An optional function to obtain the\n * comparison value from the comparator function arguments\n */\nexport function makeStringValueComparator(\n objGetterFn?: (item: Route) => string\n) {\n return (a: string, b: string): number => {\n const { aVal, bVal } = getSortValues(objGetterFn, a, b);\n // both a and b are uncomparable strings, return equivalent value\n if (!aVal && !bVal) return 0;\n // a is not a comparable string, b gets priority\n if (!aVal) return 1;\n // b is not a comparable string, a gets priority\n if (!bVal) return -1;\n // a and b are comparable strings, return the sort value\n if (aVal < bVal) return -1;\n if (aVal > bVal) return 1;\n return 0;\n };\n}\n\n/**\n * OpenTripPlanner sets the routeSortOrder to -999 by default. So, if that value\n * is encountered, assume that it actually means that the routeSortOrder is not\n * set in the GTFS.\n *\n * See https://github.com/opentripplanner/OpenTripPlanner/issues/2938\n * Also see https://github.com/opentripplanner/otp-react-redux/issues/122\n */\nfunction getRouteSortOrderValue(val: number): number {\n return val === -999 ? undefined : val;\n}\n\n/**\n * Create a multi-criteria sort comparator function composed of other sort\n * comparator functions. Each comparator function will be ran in the order given\n * until a non-zero comparison value is obtained which is then immediately\n * returned. If all comparison functions return equivalence, then the values\n * are assumed to be equivalent.\n */\nfunction makeMultiCriteriaSort(\n ...criteria: ((a: unknown, b: unknown) => number)[]\n) {\n return (a: number, b: number): number => {\n for (let i = 0; i < criteria.length; i++) {\n const curCriteriaComparatorValue = criteria[i](a, b);\n // if the comparison objects are not equivalent, return the value obtained\n // in this current criteria comparison\n if (curCriteriaComparatorValue !== 0) {\n return curCriteriaComparatorValue;\n }\n }\n return 0;\n };\n}\n\n/**\n * Creates a sort comparator function to compares routes for the purposes of\n * sorting and displaying in a user interface. This takes in a single optional\n * argument which should be a list of transitOperators as defined in the config\n * file. Due to GTFS feeds having varying levels of data quality, a multi-\n * criteria sort is needed to account for various differences. The criteria\n * included here are each applied to the routes in the order listed. If a given\n * sort criterion yields equivalence (e.g., two routes have the short name\n * \"20\"), the comparator falls back onto the next sort criterion (e.g., long\n * name). The sort operates on the following values (in order):\n *\n * 1. Transit Operator. The transit operator will be attempted to be obtained\n * for each route. If no argument is provided when creating this comparator\n * function, then routes will be sorted by their agency's name. If an\n * argument is provided and a match is found based off of the route's feed_id\n * and agency_id and a transitOperator's feed_id and agency_id, then the\n * field transitOperator.order will be used as the comparator value as long\n * as it is numeric. If it is not numeric, a value is returned indicating\n * that this transit operator should be placed at the end of the list.\n * 2. sortOrder. Routes that do not have a valid sortOrder will be placed\n * beneath those that do.\n * 3. route type (OTP mode). See routeTypeComparator code for prioritization of\n * route types.\n * 4. shortNames that begin with alphabetic characters. shortNames that do not\n * start with alphabetic characters will be place beneath those that do.\n * 5. shortName as integer. shortNames that cannot be parsed as integers will\n * be placed beneath those that are valid.\n * 6. shortName as string. Routes without shortNames will be placed beneath\n * those with shortNames.\n * 7. longName as string.\n */\nexport function makeRouteComparator(\n transitOperators: TransitOperator[]\n): (a: number, b: number) => number {\n return makeMultiCriteriaSort(\n makeTransitOperatorComparator(transitOperators),\n makeNumericValueComparator(obj => getRouteSortOrderValue(obj.sortOrder)),\n routeTypeComparator,\n alphabeticShortNameComparator,\n makeNumericValueComparator(obj => parseInt(obj.shortName, 10)),\n makeStringValueComparator(obj => obj.shortName),\n makeStringValueComparator(obj => obj.longName)\n );\n}\n\n/**\n * Tests if a pair of colors is readable. If it is, that readable color is returned.\n * If it is not, a more appropriate alternative is returned.\n *\n * Uses algorithm based on combined luminance. Values have been derived from\n * looking at real agency color pairings. These pairings are difficult to\n * generate for, as some colors see both white and black used by different agencies.\n *\n * This method therefore can accept multiple colors (including black and white) for the same background color.\n *\n * @param backgroundColor A hex string, usually the \"routeColor\"\n * @param proposedTextColor A hex string, usually the \"routeTextColor\"\n */\nexport function getMostReadableTextColor(\n backgroundColor: string,\n proposedTextColor?: string\n): string {\n // Sometimes input will defy the method signature. Therefore we need extra fallbacks\n if (!backgroundColor) backgroundColor = \"#333333\";\n if (!proposedTextColor) proposedTextColor = \"#ffffff\";\n\n if (!backgroundColor.startsWith(\"#\")) {\n backgroundColor = `#${backgroundColor}`;\n }\n if (!proposedTextColor.startsWith(\"#\")) {\n proposedTextColor = `#${proposedTextColor}`;\n }\n\n // Check if proposed color is readable\n // Luminance thresholds have been selected based on actual transit agency colors\n const fgLuminance = chroma(proposedTextColor).luminance();\n const bgLuminance = chroma(backgroundColor).luminance();\n if (\n bgLuminance + fgLuminance < 1.41 &&\n bgLuminance + fgLuminance > 0.25 &&\n Math.abs(bgLuminance - fgLuminance) > 0.2\n ) {\n return proposedTextColor;\n }\n\n // Return black or white based on luminance of background color\n // When generating colors, white is preferred.\n return chroma(backgroundColor).luminance() < 0.4 ? \"#ffffff\" : \"#000000\";\n}\n"],"mappings":"AACA,OAAOA,MAAM,MAAM,WAAW;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uCAAuCA,CACrDC,MAAc,EACdC,QAAyB,EACzBC,gBAAmC,EAClB;EACjB,OACEA,gBAAgB,CAACC,IAAI,CACnB,UAAAC,eAAe;IAAA,OACbA,eAAe,CAACJ,MAAM,KAAKA,MAAM,IACjCI,eAAe,CAACH,QAAQ,KAAKA,QAAQ;EAAA,CACzC,CAAC,IAAI,IAAI;AAEb;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,yBAAyBA,CACvCC,GAAQ,EACRJ,gBAAmC,EAClB;EACjB,IAAI,CAACI,GAAG,CAACC,OAAO,IAAI,CAACD,GAAG,CAACL,QAAQ,EAAE,OAAO,IAAI;EAC9C,IAAMD,MAAM,GAAGM,GAAG,CAACC,OAAO,CAACC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EACxC,OAAOT,uCAAuC,CAC5CC,MAAM,EACNM,GAAG,CAACL,QAAQ,EACZC,gBACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,8BAA8BA,CAC5CC,KAAY,EACZR,gBAAmC,EAClB;EACjB,IAAI,CAACQ,KAAK,CAACC,EAAE,EAAE,OAAO,IAAI;EAC1B,IAAMX,MAAM,GAAGU,KAAK,CAACC,EAAE,CAACH,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EACrC,IAAIP,QAAyB;EAC7B,IAAIS,KAAK,CAACE,MAAM,EAAE;IAChB;IACAX,QAAQ,GAAGS,KAAK,CAACE,MAAM,CAACD,EAAE;EAC5B,CAAC,MAAM,IAAID,KAAK,CAACT,QAAQ,EAAE;IACzB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GhF,MAAM,CAAC8E,iBAAiB,CAAC,CAACG,SAAS,CAAC,CAAC;EACzD,IAAMC,WAAW,GAAGlF,MAAM,CAAC6E,eAAe,CAAC,CAACI,SAAS,CAAC,CAAC;EACvD,IACEC,WAAW,GAAGF,WAAW,GAAG,IAAI,IAChCE,WAAW,GAAGF,WAAW,GAAG,IAAI,IAChCG,IAAI,CAACC,GAAG,CAACF,WAAW,GAAGF,WAAW,CAAC,GAAG,GAAG,EACzC;IACA,OAAOF,iBAAiB;EAC1B;;EAEA;EACA;EACA,OAAO9E,MAAM,CAAC6E,eAAe,CAAC,CAACI,SAAS,CAAC,CAAC,GAAG,GAAG,GAAG,SAAS,GAAG,SAAS;AAC1E","ignoreList":[]}
|
package/esm/storage.js
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
// Prefix to use with local storage keys.
|
|
3
3
|
var STORAGE_PREFIX = "otp";
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Store a javascript object at the specified key.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
8
|
export function storeItem(key, object) {
|
|
9
9
|
if (window) {
|
|
10
10
|
window.localStorage.setItem("".concat(STORAGE_PREFIX, ".").concat(key), JSON.stringify(object));
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* Retrieve a javascript object at the specified key. If not found, defaults to
|
|
15
16
|
* null or, the optionally provided notFoundValue.
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
18
|
export function getItem(key) {
|
|
19
19
|
var notFoundValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
20
20
|
var itemAsString;
|
|
21
|
-
|
|
22
21
|
try {
|
|
23
22
|
itemAsString = window.localStorage.getItem("".concat(STORAGE_PREFIX, ".").concat(key));
|
|
24
23
|
var json = JSON.parse(itemAsString);
|
|
@@ -30,20 +29,20 @@ export function getItem(key) {
|
|
|
30
29
|
return notFoundValue;
|
|
31
30
|
}
|
|
32
31
|
}
|
|
32
|
+
|
|
33
33
|
/**
|
|
34
34
|
* Remove item at specified key.
|
|
35
35
|
*/
|
|
36
|
-
|
|
37
36
|
export function removeItem(key) {
|
|
38
37
|
if (window) {
|
|
39
38
|
window.localStorage.removeItem("".concat(STORAGE_PREFIX, ".").concat(key));
|
|
40
39
|
}
|
|
41
40
|
}
|
|
41
|
+
|
|
42
42
|
/**
|
|
43
43
|
* Generate a random ID. This might not quite be a UUID, but it serves our
|
|
44
44
|
* purposes for now.
|
|
45
45
|
*/
|
|
46
|
-
|
|
47
46
|
export function randId() {
|
|
48
47
|
return Math.random().toString(36).substr(2, 9);
|
|
49
48
|
}
|
package/esm/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"storage.js","names":["STORAGE_PREFIX","storeItem","key","object","window","localStorage","setItem","concat","JSON","stringify","getItem","notFoundValue","arguments","length","undefined","itemAsString","json","parse","e","console","warn","removeItem","randId","Math","random","toString","substr"],"sources":["../src/storage.ts"],"sourcesContent":["/* eslint-disable no-console */\n// Prefix to use with local storage keys.\nconst STORAGE_PREFIX = \"otp\";\n\n/**\n * Store a javascript object at the specified key.\n */\nexport function storeItem(key: string, object: unknown): void {\n if (window) {\n window.localStorage.setItem(\n `${STORAGE_PREFIX}.${key}`,\n JSON.stringify(object)\n );\n }\n}\n\n/**\n * Retrieve a javascript object at the specified key. If not found, defaults to\n * null or, the optionally provided notFoundValue.\n */\nexport function getItem(key: string, notFoundValue: unknown = null): unknown {\n let itemAsString: string;\n try {\n itemAsString = window.localStorage.getItem(`${STORAGE_PREFIX}.${key}`);\n const json = JSON.parse(itemAsString);\n if (json) return json;\n return notFoundValue;\n } catch (e) {\n // Catch any errors associated with parsing bad JSON.\n console.warn(e, itemAsString);\n return notFoundValue;\n }\n}\n\n/**\n * Remove item at specified key.\n */\nexport function removeItem(key: string): void {\n if (window) {\n window.localStorage.removeItem(`${STORAGE_PREFIX}.${key}`);\n }\n}\n\n/**\n * Generate a random ID. This might not quite be a UUID, but it serves our\n * purposes for now.\n */\nexport function randId(): string {\n return Math.random()\n .toString(36)\n .substr(2, 9);\n}\n"],"mappings":"AAAA;AACA;AACA,IAAMA,cAAc,GAAG,KAAK;;AAE5B;AACA;AACA;AACA,OAAO,SAASC,SAASA,CAACC,GAAW,EAAEC,MAAe,EAAQ;EAC5D,IAAIC,MAAM,EAAE;IACVA,MAAM,CAACC,YAAY,CAACC,OAAO,IAAAC,MAAA,CACtBP,cAAc,OAAAO,MAAA,CAAIL,GAAG,GACxBM,IAAI,CAACC,SAAS,CAACN,MAAM,CACvB,CAAC;EACH;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASO,OAAOA,CAACR,GAAW,EAA0C;EAAA,IAAxCS,aAAsB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,IAAI;EAChE,IAAIG,YAAoB;EACxB,IAAI;IACFA,YAAY,GAAGX,MAAM,CAACC,YAAY,CAACK,OAAO,IAAAH,MAAA,CAAIP,cAAc,OAAAO,MAAA,CAAIL,GAAG,CAAE,CAAC;IACtE,IAAMc,IAAI,GAAGR,IAAI,CAACS,KAAK,CAACF,YAAY,CAAC;IACrC,IAAIC,IAAI,EAAE,OAAOA,IAAI;IACrB,OAAOL,aAAa;EACtB,CAAC,CAAC,OAAOO,CAAC,EAAE;IACV;IACAC,OAAO,CAACC,IAAI,CAACF,CAAC,EAAEH,YAAY,CAAC;IAC7B,OAAOJ,aAAa;EACtB;AACF;;AAEA;AACA;AACA;AACA,OAAO,SAASU,UAAUA,CAACnB,GAAW,EAAQ;EAC5C,IAAIE,MAAM,EAAE;IACVA,MAAM,CAACC,YAAY,CAACgB,UAAU,IAAAd,MAAA,CAAIP,cAAc,OAAAO,MAAA,CAAIL,GAAG,CAAE,CAAC;EAC5D;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASoB,MAAMA,CAAA,EAAW;EAC/B,OAAOC,IAAI,CAACC,MAAM,CAAC,CAAC,CACjBC,QAAQ,CAAC,EAAE,CAAC,CACZC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;AACjB","ignoreList":[]}
|
package/esm/suspense.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import React, { Suspense } from "react";
|
|
2
|
-
|
|
3
2
|
var SafeSuspense = function SafeSuspense(_ref) {
|
|
4
3
|
var children = _ref.children,
|
|
5
|
-
|
|
4
|
+
fallback = _ref.fallback;
|
|
6
5
|
var IS_TEST_RUNNER = window.navigator.userAgent.match(/StorybookTestRunner/);
|
|
7
6
|
return IS_TEST_RUNNER ? /*#__PURE__*/React.createElement(React.Fragment, null, fallback) : /*#__PURE__*/React.createElement(Suspense, {
|
|
8
7
|
fallback: fallback
|
|
9
8
|
}, children);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
10
|
export default SafeSuspense;
|
|
13
11
|
//# sourceMappingURL=suspense.js.map
|
package/esm/suspense.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"suspense.js","names":["React","Suspense","SafeSuspense","_ref","children","fallback","IS_TEST_RUNNER","window","navigator","userAgent","match","createElement","Fragment"],"sources":["../src/suspense.tsx"],"sourcesContent":["import React, { ReactElement, ReactNode, Suspense } from \"react\";\n\ntype Props = {\n children: ReactNode;\n fallback: ReactNode;\n};\n\nconst SafeSuspense = ({ children, fallback }: Props): ReactElement => {\n const IS_TEST_RUNNER = window.navigator.userAgent.match(\n /StorybookTestRunner/\n );\n return IS_TEST_RUNNER ? (\n <>{fallback}</>\n ) : (\n <Suspense fallback={fallback}>{children}</Suspense>\n );\n};\n\nexport default SafeSuspense;\n"],"mappings":"AAAA,OAAOA,KAAK,IAA6BC,QAAQ,QAAQ,OAAO;AAOhE,IAAMC,YAAY,GAAG,SAAfA,YAAYA,CAAAC,IAAA,EAAoD;EAAA,IAA9CC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;EACxC,IAAMC,cAAc,GAAGC,MAAM,CAACC,SAAS,CAACC,SAAS,CAACC,KAAK,CACrD,qBACF,CAAC;EACD,OAAOJ,cAAc,gBACnBN,KAAA,CAAAW,aAAA,CAAAX,KAAA,CAAAY,QAAA,QAAGP,QAAW,CAAC,gBAEfL,KAAA,CAAAW,aAAA,CAACV,QAAQ;IAACI,QAAQ,EAAEA;EAAS,GAAED,QAAmB,CACnD;AACH,CAAC;AAED,eAAeF,YAAY","ignoreList":[]}
|
package/esm/time.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { startOfDay, add, format } from "date-fns";
|
|
2
|
-
import { utcToZonedTime } from "date-fns-tz";
|
|
3
|
-
// regardless of whatever the user has configured as the display format.
|
|
2
|
+
import { utcToZonedTime } from "date-fns-tz";
|
|
4
3
|
|
|
4
|
+
// Date/time formats (per date-fns) when sending/receiving date from OTP
|
|
5
|
+
// regardless of whatever the user has configured as the display format.
|
|
5
6
|
export var OTP_API_DATE_FORMAT = "yyyy-MM-dd";
|
|
6
7
|
export var OTP_API_TIME_FORMAT = "HH:mm";
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Breaks up a duration in seconds into hours, minutes, and seconds.
|
|
9
11
|
* @param {number} seconds The number of seconds to break up
|
|
10
12
|
* @returns an object with fields with the corresponding, hours, minutes, seconds.
|
|
11
13
|
*/
|
|
12
|
-
|
|
13
14
|
export function toHoursMinutesSeconds(seconds) {
|
|
14
15
|
return {
|
|
15
16
|
hours: Math.floor(seconds / 3600),
|
|
@@ -17,76 +18,71 @@ export function toHoursMinutesSeconds(seconds) {
|
|
|
17
18
|
seconds: seconds % 60
|
|
18
19
|
};
|
|
19
20
|
}
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* @param {[type]} config the OTP config object found in store
|
|
22
24
|
* @return {string} the config-defined time formatter or HH:mm (24-hr time)
|
|
23
25
|
*/
|
|
24
|
-
|
|
25
26
|
export function getTimeFormat(config) {
|
|
26
27
|
var _config$dateTime;
|
|
27
|
-
|
|
28
|
-
return (config === null || config === void 0 ? void 0 : (_config$dateTime = config.dateTime) === null || _config$dateTime === void 0 ? void 0 : _config$dateTime.timeFormat) || OTP_API_TIME_FORMAT;
|
|
28
|
+
return (config === null || config === void 0 || (_config$dateTime = config.dateTime) === null || _config$dateTime === void 0 ? void 0 : _config$dateTime.timeFormat) || OTP_API_TIME_FORMAT;
|
|
29
29
|
}
|
|
30
30
|
export function getDateFormat(config) {
|
|
31
31
|
var _config$dateTime2;
|
|
32
|
-
|
|
33
|
-
return (config === null || config === void 0 ? void 0 : (_config$dateTime2 = config.dateTime) === null || _config$dateTime2 === void 0 ? void 0 : _config$dateTime2.dateFormat) || OTP_API_DATE_FORMAT;
|
|
32
|
+
return (config === null || config === void 0 || (_config$dateTime2 = config.dateTime) === null || _config$dateTime2 === void 0 ? void 0 : _config$dateTime2.dateFormat) || OTP_API_DATE_FORMAT;
|
|
34
33
|
}
|
|
35
|
-
/** @deprecated */
|
|
36
34
|
|
|
35
|
+
/** @deprecated */
|
|
37
36
|
export function getLongDateFormat(config) {
|
|
38
37
|
var _config$dateTime3;
|
|
39
|
-
|
|
40
|
-
return (config === null || config === void 0 ? void 0 : (_config$dateTime3 = config.dateTime) === null || _config$dateTime3 === void 0 ? void 0 : _config$dateTime3.longDateFormat) || "D MMMM YYYY";
|
|
38
|
+
return (config === null || config === void 0 || (_config$dateTime3 = config.dateTime) === null || _config$dateTime3 === void 0 ? void 0 : _config$dateTime3.longDateFormat) || "D MMMM YYYY";
|
|
41
39
|
}
|
|
42
40
|
/**
|
|
43
41
|
* Offsets a time according to the provided time options
|
|
44
42
|
* and returns the result.
|
|
45
43
|
*/
|
|
46
|
-
|
|
47
44
|
export function offsetTime(ms, options) {
|
|
48
45
|
return ms + ((options === null || options === void 0 ? void 0 : options.offset) || 0);
|
|
49
46
|
}
|
|
47
|
+
|
|
50
48
|
/**
|
|
51
49
|
* Formats a seconds after midnight value for display in narrative
|
|
52
50
|
* @param {number} seconds time since midnight in seconds
|
|
53
51
|
* @param {string} timeFormat A valid date-fns time format
|
|
54
52
|
* @return {string} formatted text representation
|
|
55
53
|
*/
|
|
56
|
-
|
|
57
54
|
export function formatSecondsAfterMidnight(seconds, timeFormat) {
|
|
58
55
|
var time = add(startOfDay(new Date()), {
|
|
59
56
|
seconds: seconds
|
|
60
57
|
});
|
|
61
58
|
return format(time, timeFormat);
|
|
62
59
|
}
|
|
60
|
+
|
|
63
61
|
/**
|
|
64
62
|
* Uses Intl.DateTimeFormat() api to get the user's time zone. In a test
|
|
65
63
|
* environment, pulls timezone information from an env variable. Default to
|
|
66
64
|
* GMT+0 if the Intl API is unavailable.
|
|
67
65
|
*/
|
|
68
|
-
|
|
69
66
|
export function getUserTimezone() {
|
|
70
67
|
var _Intl;
|
|
71
|
-
|
|
72
68
|
var fallbackTimezone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "Etc/Greenwich";
|
|
73
69
|
if (process.env.NODE_ENV === "test") return process.env.TZ;
|
|
74
70
|
return ((_Intl = Intl) === null || _Intl === void 0 ? void 0 : _Intl.DateTimeFormat().resolvedOptions().timeZone) || fallbackTimezone;
|
|
75
71
|
}
|
|
72
|
+
|
|
76
73
|
/**
|
|
77
74
|
* Formats current time for use in OTP query
|
|
78
75
|
* The conversion to the user's timezone is needed for testing purposes.
|
|
79
76
|
*/
|
|
80
|
-
|
|
81
77
|
export function getCurrentTime() {
|
|
82
78
|
var timezone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getUserTimezone();
|
|
83
79
|
return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);
|
|
84
80
|
}
|
|
81
|
+
|
|
85
82
|
/**
|
|
86
83
|
* Formats current date for use in OTP query
|
|
87
84
|
* The conversion to the user's timezone is needed for testing purposes.
|
|
88
85
|
*/
|
|
89
|
-
|
|
90
86
|
export function getCurrentDate() {
|
|
91
87
|
var timezone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getUserTimezone();
|
|
92
88
|
return format(utcToZonedTime(Date.now(), timezone), OTP_API_DATE_FORMAT);
|
package/esm/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"time.js","names":["startOfDay","add","format","utcToZonedTime","OTP_API_DATE_FORMAT","OTP_API_TIME_FORMAT","toHoursMinutesSeconds","seconds","hours","Math","floor","minutes","getTimeFormat","config","_config$dateTime","dateTime","timeFormat","getDateFormat","_config$dateTime2","dateFormat","getLongDateFormat","_config$dateTime3","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","_Intl","fallbackTimezone","arguments","length","undefined","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"sources":["../src/time.ts"],"sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport { startOfDay, add, format } from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// Date/time formats (per date-fns) when sending/receiving date from OTP\n// regardless of whatever the user has configured as the display format.\nexport const OTP_API_DATE_FORMAT = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * Breaks up a duration in seconds into hours, minutes, and seconds.\n * @param {number} seconds The number of seconds to break up\n * @returns an object with fields with the corresponding, hours, minutes, seconds.\n */\nexport function toHoursMinutesSeconds(\n seconds: number\n): {\n hours: number;\n minutes: number;\n seconds: number;\n} {\n return {\n hours: Math.floor(seconds / 3600),\n minutes: Math.floor(seconds / 60) % 60,\n seconds: seconds % 60\n };\n}\n\n/**\n * @param {[type]} config the OTP config object found in store\n * @return {string} the config-defined time formatter or HH:mm (24-hr time)\n */\nexport function getTimeFormat(config: Config): string {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config: Config): string {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\n/** @deprecated */\nexport function getLongDateFormat(config: Config): string {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n/**\n * Offsets a time according to the provided time options\n * and returns the result.\n */\nexport function offsetTime(ms, options) {\n return ms + (options?.offset || 0);\n}\n\n/**\n * Formats a seconds after midnight value for display in narrative\n * @param {number} seconds time since midnight in seconds\n * @param {string} timeFormat A valid date-fns time format\n * @return {string} formatted text representation\n */\nexport function formatSecondsAfterMidnight(\n seconds: number,\n timeFormat: string\n): string {\n const time = add(startOfDay(new Date()), { seconds });\n return format(time, timeFormat);\n}\n\n/**\n * Uses Intl.DateTimeFormat() api to get the user's time zone. In a test\n * environment, pulls timezone information from an env variable. Default to\n * GMT+0 if the Intl API is unavailable.\n */\nexport function getUserTimezone(fallbackTimezone = \"Etc/Greenwich\"): string {\n if (process.env.NODE_ENV === \"test\") return process.env.TZ;\n return Intl?.DateTimeFormat().resolvedOptions().timeZone || fallbackTimezone;\n}\n\n/**\n * Formats current time for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentTime(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_TIME_FORMAT);\n}\n\n/**\n * Formats current date for use in OTP query\n * The conversion to the user's timezone is needed for testing purposes.\n */\nexport function getCurrentDate(timezone = getUserTimezone()): string {\n return format(utcToZonedTime(Date.now(), timezone), OTP_API_DATE_FORMAT);\n}\n"],"mappings":"AACA,SAASA,UAAU,EAAEC,GAAG,EAAEC,MAAM,QAAQ,UAAU;AAClD,SAASC,cAAc,QAAQ,aAAa;;AAE5C;AACA;AACA,OAAO,IAAMC,mBAAmB,GAAG,YAAY;AAC/C,OAAO,IAAMC,mBAAmB,GAAG,OAAO;;AAE1C;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACnCC,OAAe,EAKf;EACA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g.,
|
|
9
9
|
* https://github.com/conveyal/trimet-mod-otp/issues/92.
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
11
|
export function enableScrollForSelector(selector) {
|
|
13
12
|
var overlay = document.querySelector(selector);
|
|
14
13
|
var clientY = null; // remember Y position on touch start
|
|
@@ -17,21 +16,17 @@ export function enableScrollForSelector(selector) {
|
|
|
17
16
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions
|
|
18
17
|
return overlay.scrollHeight - overlay.scrollTop <= overlay.clientHeight;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
19
|
function disableRubberBand(event) {
|
|
22
20
|
var clientYDelta = event.targetTouches[0].clientY - clientY;
|
|
23
|
-
|
|
24
21
|
if (overlay.scrollTop === 0 && clientYDelta > 0) {
|
|
25
22
|
// element is at the top of its scroll
|
|
26
23
|
event.preventDefault();
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
if (isOverlayTotallyScrolled() && clientYDelta < 0) {
|
|
30
26
|
// element is at the top of its scroll
|
|
31
27
|
event.preventDefault();
|
|
32
28
|
}
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
overlay.addEventListener("touchstart", function (event) {
|
|
36
31
|
if (event.targetTouches.length === 1) {
|
|
37
32
|
// detect single touch
|
package/esm/ui.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ui.js","names":["isMobile","test","navigator","userAgent","enableScrollForSelector","selector","overlay","document","querySelector","clientY","isOverlayTotallyScrolled","scrollHeight","scrollTop","clientHeight","disableRubberBand","event","clientYDelta","targetTouches","preventDefault","addEventListener","length"],"sources":["../src/ui.ts"],"sourcesContent":["export function isMobile(): boolean {\n // TODO: consider using 3rd-party library?\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(\n navigator.userAgent\n );\n}\n/**\n * Enables scrolling for a specified selector, while disabling scrolling for all\n * other targets. This is adapted from https://stackoverflow.com/a/41601290/915811\n * and intended to fix issues with iOS elastic scrolling, e.g.,\n * https://github.com/conveyal/trimet-mod-otp/issues/92.\n */\nexport function enableScrollForSelector(selector: string): void {\n const overlay = document.querySelector(selector);\n let clientY = null; // remember Y position on touch start\n\n function isOverlayTotallyScrolled(): boolean {\n // https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions\n return overlay.scrollHeight - overlay.scrollTop <= overlay.clientHeight;\n }\n\n function disableRubberBand(event: TouchEvent) {\n const clientYDelta = event.targetTouches[0].clientY - clientY;\n\n if (overlay.scrollTop === 0 && clientYDelta > 0) {\n // element is at the top of its scroll\n event.preventDefault();\n }\n\n if (isOverlayTotallyScrolled() && clientYDelta < 0) {\n // element is at the top of its scroll\n event.preventDefault();\n }\n }\n\n overlay.addEventListener(\n \"touchstart\",\n function(event: TouchEvent) {\n if (event.targetTouches.length === 1) {\n // detect single touch\n clientY = event.targetTouches[0].clientY;\n }\n },\n false\n );\n\n overlay.addEventListener(\n \"touchmove\",\n function(event: TouchEvent) {\n if (event.targetTouches.length === 1) {\n // detect single touch\n disableRubberBand(event);\n }\n },\n false\n );\n}\n"],"mappings":"AAAA,OAAO,SAASA,QAAQA,CAAA,EAAY;EAClC;EACA,OAAO,gEAAgE,CAACC,IAAI,CAC1EC,SAAS,CAACC,SACZ,CAAC;AACH;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CAACC,QAAgB,EAAQ;EAC9D,IAAMC,OAAO,GAAGC,QAAQ,CAACC,aAAa,CAACH,QAAQ,CAAC;EAChD,IAAII,OAAO,GAAG,IAAI,CAAC,CAAC;;EAEpB,SAASC,wBAAwBA,CAAA,EAAY;IAC3C;IACA,OAAOJ,OAAO,CAACK,YAAY,GAAGL,OAAO,CAACM,SAAS,IAAIN,OAAO,CAACO,YAAY;EACzE;EAEA,SAASC,iBAAiBA,CAACC,KAAiB,EAAE;IAC5C,IAAMC,YAAY,GAAGD,KAAK,CAACE,aAAa,CAAC,CAAC,CAAC,CAACR,OAAO,GAAGA,OAAO;IAE7D,IAAIH,OAAO,CAACM,SAAS,KAAK,CAAC,IAAII,YAAY,GAAG,CAAC,EAAE;MAC/C;MACAD,KAAK,CAACG,cAAc,CAAC,CAAC;IACxB;IAEA,IAAIR,wBAAwB,CAAC,CAAC,IAAIM,YAAY,GAAG,CAAC,EAAE;MAClD;MACAD,KAAK,CAACG,cAAc,CAAC,CAAC;IACxB;EACF;EAEAZ,OAAO,CAACa,gBAAgB,CACtB,YAAY,EACZ,UAASJ,KAAiB,EAAE;IAC1B,IAAIA,KAAK,CAACE,aAAa,CAACG,MAAM,KAAK,CAAC,EAAE;MACpC;MACAX,OAAO,GAAGM,KAAK,CAACE,aAAa,CAAC,CAAC,CAAC,CAACR,OAAO;IAC1C;EACF,CAAC,EACD,KACF,CAAC;EAEDH,OAAO,CAACa,gBAAgB,CACtB,WAAW,EACX,UAASJ,KAAiB,EAAE;IAC1B,IAAIA,KAAK,CAACE,aAAa,CAACG,MAAM,KAAK,CAAC,EAAE;MACpC;MACAN,iBAAiB,CAACC,KAAK,CAAC;IAC1B;EACF,CAAC,EACD,KACF,CAAC;AACH","ignoreList":[]}
|
package/lib/graphql.d.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"graphql.d.js","names":[],"sources":["../src/graphql.d.ts"],"sourcesContent":["declare module \"*.graphql\" {\n import { DocumentNode } from \"graphql\";\n\n const Schema: DocumentNode;\n\n export = Schema;\n}\n"],"mappings":"","ignoreList":[]}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -12,33 +11,19 @@ Object.defineProperty(exports, "SafeSuspense", {
|
|
|
12
11
|
}
|
|
13
12
|
});
|
|
14
13
|
exports.default = void 0;
|
|
15
|
-
|
|
16
14
|
var itinerary = _interopRequireWildcard(require("./itinerary"));
|
|
17
|
-
|
|
18
15
|
var map = _interopRequireWildcard(require("./map"));
|
|
19
|
-
|
|
20
16
|
var profile = _interopRequireWildcard(require("./profile"));
|
|
21
|
-
|
|
22
17
|
var query = _interopRequireWildcard(require("./query"));
|
|
23
|
-
|
|
24
18
|
var queryParams = _interopRequireWildcard(require("./query-params"));
|
|
25
|
-
|
|
26
19
|
var route = _interopRequireWildcard(require("./route"));
|
|
27
|
-
|
|
28
20
|
var storage = _interopRequireWildcard(require("./storage"));
|
|
29
|
-
|
|
30
21
|
var time = _interopRequireWildcard(require("./time"));
|
|
31
|
-
|
|
32
22
|
var ui = _interopRequireWildcard(require("./ui"));
|
|
33
|
-
|
|
34
23
|
var queryGen = _interopRequireWildcard(require("./query-gen"));
|
|
35
|
-
|
|
36
24
|
var _suspense = _interopRequireDefault(require("./suspense"));
|
|
37
|
-
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
41
|
-
|
|
25
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
26
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
42
27
|
const core = {
|
|
43
28
|
itinerary,
|
|
44
29
|
map,
|
|
@@ -51,6 +36,5 @@ const core = {
|
|
|
51
36
|
time,
|
|
52
37
|
ui
|
|
53
38
|
};
|
|
54
|
-
var _default = core;
|
|
55
|
-
exports.default = _default;
|
|
39
|
+
var _default = exports.default = core;
|
|
56
40
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["itinerary","_interopRequireWildcard","require","map","profile","query","queryParams","route","storage","time","ui","queryGen","_suspense","_interopRequireDefault","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","core","_default","exports"],"sources":["../src/index.ts"],"sourcesContent":["import * as itinerary from \"./itinerary\";\nimport * as map from \"./map\";\nimport * as profile from \"./profile\";\nimport * as query from \"./query\";\nimport * as queryParams from \"./query-params\";\nimport * as route from \"./route\";\nimport * as storage from \"./storage\";\nimport * as time from \"./time\";\nimport * as ui from \"./ui\";\nimport * as queryGen from \"./query-gen\";\nimport SafeSuspense from \"./suspense\";\n\nconst core = {\n itinerary,\n map,\n profile,\n query,\n queryGen,\n queryParams,\n route,\n storage,\n time,\n ui\n};\n\nexport { SafeSuspense };\nexport default core;\n"],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