@opentripplanner/core-utils 4.11.6-alpha.1 → 5.0.0
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/esm/deprecated-with-types.js +47 -0
- package/esm/deprecated-with-types.js.map +1 -0
- package/esm/index.js +0 -4
- package/esm/index.js.map +1 -1
- package/esm/itinerary.js +1 -1
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +4 -9
- package/esm/map.js.map +1 -1
- package/esm/route.js +5 -3
- package/esm/route.js.map +1 -1
- package/esm/storage.js +1 -0
- package/esm/storage.js.map +1 -1
- package/esm/time.js +6 -36
- package/esm/time.js.map +1 -1
- package/esm/ui.js +1 -1
- package/esm/ui.js.map +1 -1
- package/lib/deprecated-with-types.d.ts +23 -0
- package/lib/deprecated-with-types.d.ts.map +1 -0
- package/lib/deprecated-with-types.js +61 -0
- package/lib/deprecated-with-types.js.map +1 -0
- package/lib/index.d.ts +19 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +0 -6
- package/lib/index.js.map +1 -1
- package/lib/itinerary.d.ts +113 -0
- package/lib/itinerary.d.ts.map +1 -0
- package/lib/itinerary.js +2 -1
- package/lib/itinerary.js.map +1 -1
- package/lib/map.d.ts +30 -0
- package/lib/map.d.ts.map +1 -0
- package/lib/map.js +3 -8
- package/lib/map.js.map +1 -1
- package/lib/route.d.ts +98 -0
- package/lib/route.d.ts.map +1 -0
- package/lib/route.js +5 -3
- package/lib/route.js.map +1 -1
- package/lib/storage.d.ts +19 -0
- package/lib/storage.d.ts.map +1 -0
- package/lib/storage.js +2 -0
- package/lib/storage.js.map +1 -1
- package/lib/time.d.ts +65 -0
- package/lib/time.d.ts.map +1 -0
- package/lib/time.js +22 -39
- package/lib/time.js.map +1 -1
- package/lib/ui.d.ts +13 -0
- package/lib/ui.d.ts.map +1 -0
- package/lib/ui.js +1 -1
- package/lib/ui.js.map +1 -1
- package/package.json +4 -1
- package/src/__tests__/__snapshots__/route.js.snap +30 -30
- package/src/deprecated-with-types.ts +62 -0
- package/src/{index.js → index.ts} +0 -4
- package/src/{itinerary.js → itinerary.ts} +70 -36
- package/src/{map.js → map.ts} +43 -31
- package/src/{route.js → route.ts} +52 -28
- package/src/{storage.js → storage.ts} +6 -5
- package/src/{time.js → time.ts} +28 -46
- package/src/{ui.js → ui.ts} +8 -8
- package/tsconfig.json +15 -0
- package/tsconfig.tsbuildinfo +4921 -0
- package/esm/messages.js +0 -25
- package/esm/messages.js.map +0 -1
- package/esm/types.js +0 -560
- package/esm/types.js.map +0 -1
- package/lib/messages.js +0 -29
- package/lib/messages.js.map +0 -1
- package/lib/types.js +0 -661
- package/lib/types.js.map +0 -1
- package/src/messages.js +0 -20
- package/src/types.js +0 -605
package/esm/time.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { startOfDay, add, format, formatDuration as dateFnsFormatDuration } from "date-fns";
|
|
2
|
-
import { utcToZonedTime } from "date-fns-tz";
|
|
2
|
+
import { utcToZonedTime } from "date-fns-tz";
|
|
3
|
+
/* eslint-disable import/no-cycle */
|
|
4
|
+
|
|
5
|
+
import { formatTime, formatDurationWithSeconds, formatDuration } from "./deprecated-with-types";
|
|
6
|
+
export { formatTime, formatDuration, formatDurationWithSeconds }; // special constants for making sure the following date format is always sent to
|
|
3
7
|
// OTP regardless of whatever the user has configured as the display format
|
|
4
8
|
|
|
5
9
|
export var OTP_API_DATE_FORMAT = "YYYY-MM-DD"; // Date-Fns uses a different string format than moment.js
|
|
@@ -17,7 +21,7 @@ export var OTP_API_TIME_FORMAT = "HH:mm";
|
|
|
17
21
|
* @returns Formatted duration
|
|
18
22
|
*/
|
|
19
23
|
|
|
20
|
-
function formatDurationLikeMoment(seconds, showSeconds) {
|
|
24
|
+
export function formatDurationLikeMoment(seconds, showSeconds) {
|
|
21
25
|
var localize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
22
26
|
enabled: true,
|
|
23
27
|
code: "en-US"
|
|
@@ -58,7 +62,6 @@ function formatDurationLikeMoment(seconds, showSeconds) {
|
|
|
58
62
|
* @returns an object with fields with the corresponding, hours, minutes, seconds.
|
|
59
63
|
*/
|
|
60
64
|
|
|
61
|
-
|
|
62
65
|
export function toHoursMinutesSeconds(seconds) {
|
|
63
66
|
var hours = Math.floor(seconds / 3600);
|
|
64
67
|
var minutes = Math.floor((seconds - hours * 3600) / 60);
|
|
@@ -88,29 +91,6 @@ export function getLongDateFormat(config) {
|
|
|
88
91
|
|
|
89
92
|
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";
|
|
90
93
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Formats an elapsed time duration for display in narrative.
|
|
93
|
-
* TODO: internationalization
|
|
94
|
-
* @param {number} seconds duration in seconds
|
|
95
|
-
* @returns {string} formatted text representation
|
|
96
|
-
*/
|
|
97
|
-
|
|
98
|
-
export function formatDuration(seconds) {
|
|
99
|
-
return formatDurationLikeMoment(seconds, false);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Formats an elapsed time in seconds, minutes, hours duration for display in narrative
|
|
103
|
-
* @param {number} seconds duration in seconds
|
|
104
|
-
* @param {object} region an object that allows internationalization of the time
|
|
105
|
-
* @returns {string} formatted text representation
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
export function formatDurationWithSeconds(seconds, region) {
|
|
109
|
-
return formatDurationLikeMoment(seconds, {
|
|
110
|
-
enabled: true,
|
|
111
|
-
code: region
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
94
|
/**
|
|
115
95
|
* Offsets a time according to the provided time options
|
|
116
96
|
* and returns the result.
|
|
@@ -119,16 +99,6 @@ export function formatDurationWithSeconds(seconds, region) {
|
|
|
119
99
|
export function offsetTime(ms, options) {
|
|
120
100
|
return ms + ((options === null || options === void 0 ? void 0 : options.offset) || 0);
|
|
121
101
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Formats a time value for display in narrative
|
|
124
|
-
* TODO: internationalization/timezone
|
|
125
|
-
* @param {number} ms epoch time value in milliseconds
|
|
126
|
-
* @returns {string} formatted text representation
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
export function formatTime(ms, options) {
|
|
130
|
-
return format(offsetTime(ms, options), (options === null || options === void 0 ? void 0 : options.format) || OTP_API_TIME_FORMAT);
|
|
131
|
-
}
|
|
132
102
|
/**
|
|
133
103
|
* Formats a seconds after midnight value for display in narrative
|
|
134
104
|
* @param {number} seconds time since midnight in seconds
|
package/esm/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/time.js"],"names":["startOfDay","add","format","formatDuration","dateFnsFormatDuration","utcToZonedTime","OTP_API_DATE_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","OTP_API_TIME_FORMAT","formatDurationLikeMoment","seconds","showSeconds","localize","enabled","code","hours","Math","floor","minutes","secondsLeftOver","specLookup","xHours","xMinutes","xSeconds","locale","formatDistance","spec","val","undefined","toHoursMinutesSeconds","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","formatDurationWithSeconds","region","offsetTime","ms","options","offset","formatTime","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime","timezone","now","getCurrentDate"],"mappings":"AAAA,SACEA,UADF,EAEEC,GAFF,EAGEC,MAHF,EAIEC,cAAc,IAAIC,qBAJpB,QAKO,UALP;AAMA,SAASC,cAAT,QAA+B,aAA/B,C,CAEA;AACA;;AACA,OAAO,IAAMC,mBAAmB,GAAG,YAA5B,C,CACP;AACA;;AACA,OAAO,IAAMC,4BAA4B,GAAG,YAArC;AACP,OAAO,IAAMC,mBAAmB,GAAG,OAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,S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BX,eAAe,EAAI;AAC3D,SAAO9C,MAAM,CAACG,cAAc,CAAC0C,IAAI,CAACa,GAAL,EAAD,EAAaD,QAAb,CAAf,EAAuCnD,mBAAvC,CAAb;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASqD,cAAT,GAAsD;AAAA,MAA9BF,QAA8B,uEAAnBX,eAAe,EAAI;AAC3D,SAAO9C,MAAM,CACXG,cAAc,CAAC0C,IAAI,CAACa,GAAL,EAAD,EAAaD,QAAb,CADH,EAEXpD,4BAFW,CAAb;AAID","sourcesContent":["import {\n startOfDay,\n add,\n format,\n formatDuration as dateFnsFormatDuration\n} from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n// special constants for making sure the following date format is always sent to\n// OTP regardless of whatever the user has configured as the display format\nexport const OTP_API_DATE_FORMAT = \"YYYY-MM-DD\";\n// Date-Fns uses a different string format than moment.js\n// see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md\nexport const OTP_API_DATE_FORMAT_DATE_FNS = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * To ease the transition away from moment.js, this method uses date-fns to format durations\n * the way moment.js did.\n * @param {number} seconds The number of seconds to format\n * @param {boolean} showSeconds Whether to render seconds or not\n * @param {boolean} localize If true, will create output like moment.js using date-fns locale.\n * Otherwise, uses date-fns default\n * @returns Formatted duration\n */\nfunction formatDurationLikeMoment(\n seconds,\n showSeconds,\n localize = { enabled: true, code: \"en-US\" }\n) {\n // date-fns doesn't do this automatically\n if ((!showSeconds && seconds < 60) || seconds === 0) {\n return \"0 min\";\n }\n\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n const secondsLeftOver = showSeconds\n ? seconds - hours * 3600 - minutes * 60\n : 0;\n const specLookup = {\n xHours: \"hr\",\n xMinutes: \"min\",\n xSeconds: \"sec\"\n };\n const locale = localize\n ? {\n // Maintain backwards compatibility when called with localize=true\n code: localize?.code || \"en-US\",\n formatDistance: (spec, val) => {\n return `${val} ${specLookup[spec]}`;\n }\n }\n : undefined;\n\n return dateFnsFormatDuration(\n {\n hours,\n minutes,\n seconds: secondsLeftOver\n },\n {\n format: [\"hours\", \"minutes\", \"seconds\"],\n locale\n }\n );\n}\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(seconds) {\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n return {\n hours,\n minutes,\n seconds: seconds - hours * 3600 - minutes * 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) {\n return config?.dateTime?.timeFormat || OTP_API_TIME_FORMAT;\n}\n\nexport function getDateFormat(config) {\n return config?.dateTime?.dateFormat || OTP_API_DATE_FORMAT;\n}\n\nexport function getLongDateFormat(config) {\n return config?.dateTime?.longDateFormat || \"D MMMM YYYY\";\n}\n\n/**\n * Formats an elapsed time duration for display in narrative.\n * TODO: internationalization\n * @param {number} seconds duration in seconds\n * @returns {string} formatted text representation\n */\nexport function formatDuration(seconds) {\n return formatDurationLikeMoment(seconds, false);\n}\n\n/**\n * Formats an elapsed time in seconds, minutes, hours duration for display in narrative\n * @param {number} seconds duration in seconds\n * @param {object} region an object that allows internationalization of the time\n * @returns {string} formatted text representation\n */\nexport function formatDurationWithSeconds(seconds, region) {\n return formatDurationLikeMoment(seconds, { enabled: true, code: region });\n}\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 time value for display in narrative\n * TODO: internationalization/timezone\n * @param {number} ms epoch time value in milliseconds\n * @returns {string} formatted text representation\n */\nexport function formatTime(ms, options) {\n return format(\n offsetTime(ms, options),\n options?.format || OTP_API_TIME_FORMAT\n );\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(seconds, timeFormat) {\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\") {\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()) {\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()) {\n return format(\n utcToZonedTime(Date.now(), timezone),\n OTP_API_DATE_FORMAT_DATE_FNS\n );\n}\n"],"file":"time.js"}
|
|
1
|
+
{"version":3,"sources":["../src/time.ts"],"names":["startOfDay","add","format","formatDuration","dateFnsFormatDuration","utcToZonedTime","formatTime","formatDurationWithSeconds","OTP_API_DATE_FORMAT","OTP_API_DATE_FORMAT_DATE_FNS","OTP_API_TIME_FORMAT","formatDurationLikeMoment","seconds","showSeconds","localize","enabled","code","hours","Math","floor","minutes","secondsLeftOver","specLookup","xHours","xMinutes","xSeconds","locale","formatDistance","spec","val","undefined","toHoursMinutesSeconds","getTimeFormat","config","dateTime","timeFormat","getDateFormat","dateFormat","getLongDateFormat","longDateFormat","offsetTime","ms","options","offset","formatSecondsAfterMidnight","time","Date","getUserTimezone","fallbackTimezone","process","env","NODE_ENV","TZ","Intl","DateTimeFormat","resolvedOptions","timeZone","getCurrentTime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SAASkD,cAAT,GAA8D;AAAA,MAAtCF,QAAsC,uEAA3BX,eAAe,EAAY;AACnE,SAAO7C,MAAM,CACXG,cAAc,CAACyC,IAAI,CAACa,GAAL,EAAD,EAAaD,QAAb,CADH,EAEXjD,4BAFW,CAAb;AAID","sourcesContent":["import { Config } from \"@opentripplanner/types\";\nimport {\n startOfDay,\n add,\n format,\n formatDuration as dateFnsFormatDuration\n} from \"date-fns\";\nimport { utcToZonedTime } from \"date-fns-tz\";\n\n/* eslint-disable import/no-cycle */\nimport {\n formatTime,\n formatDurationWithSeconds,\n formatDuration\n} from \"./deprecated-with-types\";\n\nexport { formatTime, formatDuration, formatDurationWithSeconds };\n\n// special constants for making sure the following date format is always sent to\n// OTP regardless of whatever the user has configured as the display format\nexport const OTP_API_DATE_FORMAT = \"YYYY-MM-DD\";\n// Date-Fns uses a different string format than moment.js\n// see https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md\nexport const OTP_API_DATE_FORMAT_DATE_FNS = \"yyyy-MM-dd\";\nexport const OTP_API_TIME_FORMAT = \"HH:mm\";\n\n/**\n * To ease the transition away from moment.js, this method uses date-fns to format durations\n * the way moment.js did.\n * @param {number} seconds The number of seconds to format\n * @param {boolean} showSeconds Whether to render seconds or not\n * @param {boolean} localize If true, will create output like moment.js using date-fns locale.\n * Otherwise, uses date-fns default\n * @returns Formatted duration\n */\nexport function formatDurationLikeMoment(\n seconds: number,\n showSeconds: boolean,\n localize: { enabled: boolean; code: string } = {\n enabled: true,\n code: \"en-US\"\n }\n): string {\n // date-fns doesn't do this automatically\n if ((!showSeconds && seconds < 60) || seconds === 0) {\n return \"0 min\";\n }\n\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n const secondsLeftOver = showSeconds\n ? seconds - hours * 3600 - minutes * 60\n : 0;\n const specLookup = {\n xHours: \"hr\",\n xMinutes: \"min\",\n xSeconds: \"sec\"\n };\n const locale = localize\n ? {\n // Maintain backwards compatibility when called with localize=true\n code: localize?.code || \"en-US\",\n formatDistance: (spec, val) => {\n return `${val} ${specLookup[spec]}`;\n }\n }\n : undefined;\n\n return dateFnsFormatDuration(\n {\n hours,\n minutes,\n seconds: secondsLeftOver\n },\n {\n format: [\"hours\", \"minutes\", \"seconds\"],\n locale\n }\n );\n}\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(seconds) {\n const hours = Math.floor(seconds / 3600);\n const minutes = Math.floor((seconds - hours * 3600) / 60);\n return {\n hours,\n minutes,\n seconds: seconds - hours * 3600 - minutes * 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\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(\n utcToZonedTime(Date.now(), timezone),\n OTP_API_DATE_FORMAT_DATE_FNS\n );\n}\n"],"file":"time.js"}
|
package/esm/ui.js
CHANGED
|
@@ -8,7 +8,7 @@ export function isMobile() {
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export function isIE() {
|
|
11
|
-
return bowser.
|
|
11
|
+
return bowser.parse(navigator.userAgent).browser === "Internet Explorer";
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* Enables scrolling for a specified selector, while disabling scrolling for all
|
package/esm/ui.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ui.
|
|
1
|
+
{"version":3,"sources":["../src/ui.ts"],"names":["bowser","isMobile","test","navigator","userAgent","isIE","parse","browser","enableScrollForSelector","selector","overlay","document","querySelector","clientY","isOverlayTotallyScrolled","scrollHeight","scrollTop","clientHeight","disableRubberBand","event","clientYDelta","targetTouches","preventDefault","addEventListener","length"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,QAAnB;AAEA,OAAO,SAASC,QAAT,GAA6B;AAClC;AACA,SAAO,iEAAiEC,IAAjE,CACLC,SAAS,CAACC,SADL,CAAP;AAGD;AAED;AACA;AACA;;AACA,OAAO,SAASC,IAAT,GAAyB;AAC9B,SAAOL,MAAM,CAACM,KAAP,CAAaH,SAAS,CAACC,SAAvB,EAAkCG,OAAlC,KAA8C,mBAArD;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,uBAAT,CAAiCC,QAAjC,EAAyD;AAC9D,MAAMC,OAAO,GAAGC,QAAQ,CAACC,aAAT,CAAuBH,QAAvB,CAAhB;AACA,MAAII,OAAO,GAAG,IAAd,CAF8D,CAE1C;;AAEpB,WAASC,wBAAT,GAA6C;AAC3C;AACA,WAAOJ,OAAO,CAACK,YAAR,GAAuBL,OAAO,CAACM,SAA/B,IAA4CN,OAAO,CAACO,YAA3D;AACD;;AAED,WAASC,iBAAT,CAA2BC,KAA3B,EAA8C;AAC5C,QAAMC,YAAY,GAAGD,KAAK,CAACE,aAAN,CAAoB,CAApB,EAAuBR,OAAvB,GAAiCA,OAAtD;;AAEA,QAAIH,OAAO,CAACM,SAAR,KAAsB,CAAtB,IAA2BI,YAAY,GAAG,CAA9C,EAAiD;AAC/C;AACAD,MAAAA,KAAK,CAACG,cAAN;AACD;;AAED,QAAIR,wBAAwB,MAAMM,YAAY,GAAG,CAAjD,EAAoD;AAClD;AACAD,MAAAA,KAAK,CAACG,cAAN;AACD;AACF;;AAEDZ,EAAAA,OAAO,CAACa,gBAAR,CACE,YADF,EAEE,UAASJ,KAAT,EAA4B;AAC1B,QAAIA,KAAK,CAACE,aAAN,CAAoBG,MAApB,KAA+B,CAAnC,EAAsC;AACpC;AACAX,MAAAA,OAAO,GAAGM,KAAK,CAACE,aAAN,CAAoB,CAApB,EAAuBR,OAAjC;AACD;AACF,GAPH,EAQE,KARF;AAWAH,EAAAA,OAAO,CAACa,gBAAR,CACE,WADF,EAEE,UAASJ,KAAT,EAA4B;AAC1B,QAAIA,KAAK,CAACE,aAAN,CAAoBG,MAApB,KAA+B,CAAnC,EAAsC;AACpC;AACAN,MAAAA,iBAAiB,CAACC,KAAD,CAAjB;AACD;AACF,GAPH,EAQE,KARF;AAUD","sourcesContent":["import bowser from \"bowser\";\n\nexport 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/**\n * Returns true if the user is using a [redacted] browser\n */\nexport function isIE(): boolean {\n return bowser.parse(navigator.userAgent).browser === \"Internet Explorer\";\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"],"file":"ui.js"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { TimeOptions } from "@opentripplanner/types";
|
|
2
|
+
/**
|
|
3
|
+
* Formats a time value for display in narrative
|
|
4
|
+
* TODO: internationalization/timezone
|
|
5
|
+
* @param {number} ms epoch time value in milliseconds
|
|
6
|
+
* @returns {string} formatted text representation
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatTime(ms: number, options: TimeOptions): string;
|
|
9
|
+
/**
|
|
10
|
+
* Formats an elapsed time duration for display in narrative.
|
|
11
|
+
* TODO: internationalization
|
|
12
|
+
* @param {number} seconds duration in seconds
|
|
13
|
+
* @returns {string} formatted text representation
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatDuration(seconds: number, region: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Formats an elapsed time in seconds, minutes, hours duration for display in narrative
|
|
18
|
+
* @param {number} seconds duration in seconds
|
|
19
|
+
* @param {object} region an object that allows internationalization of the time
|
|
20
|
+
* @returns {string} formatted text representation
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatDurationWithSeconds(seconds: number, region: string): string;
|
|
23
|
+
//# sourceMappingURL=deprecated-with-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecated-with-types.d.ts","sourceRoot":"","sources":["../src/deprecated-with-types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAYrD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,MAAM,CAOnE;AAED;;;;;GAKG;AAEH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAOtE;AAED;;;;;GAKG;AAEH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,GACb,MAAM,CAOR"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.formatTime = formatTime;
|
|
7
|
+
exports.formatDuration = formatDuration;
|
|
8
|
+
exports.formatDurationWithSeconds = formatDurationWithSeconds;
|
|
9
|
+
|
|
10
|
+
var _dateFns = require("date-fns");
|
|
11
|
+
|
|
12
|
+
var _deprecated = require("./deprecated");
|
|
13
|
+
|
|
14
|
+
var _time = require("./time");
|
|
15
|
+
|
|
16
|
+
/* eslint-disable import/no-cycle */
|
|
17
|
+
// time.ts
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Formats a time value for display in narrative
|
|
21
|
+
* TODO: internationalization/timezone
|
|
22
|
+
* @param {number} ms epoch time value in milliseconds
|
|
23
|
+
* @returns {string} formatted text representation
|
|
24
|
+
*/
|
|
25
|
+
function formatTime(ms, options) {
|
|
26
|
+
(0, _deprecated.logDeprecationWarning)("formatTime", "formatjs");
|
|
27
|
+
return (0, _dateFns.format)((0, _time.offsetTime)(ms, options), (options === null || options === void 0 ? void 0 : options.format) || _time.OTP_API_TIME_FORMAT);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Formats an elapsed time duration for display in narrative.
|
|
31
|
+
* TODO: internationalization
|
|
32
|
+
* @param {number} seconds duration in seconds
|
|
33
|
+
* @returns {string} formatted text representation
|
|
34
|
+
*/
|
|
35
|
+
// TS TODO: region as type?
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
function formatDuration(seconds, region) {
|
|
39
|
+
(0, _deprecated.logDeprecationWarning)("formatDuration", "formatjs");
|
|
40
|
+
return (0, _time.formatDurationLikeMoment)(seconds, false, {
|
|
41
|
+
enabled: true,
|
|
42
|
+
code: region
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Formats an elapsed time in seconds, minutes, hours duration for display in narrative
|
|
47
|
+
* @param {number} seconds duration in seconds
|
|
48
|
+
* @param {object} region an object that allows internationalization of the time
|
|
49
|
+
* @returns {string} formatted text representation
|
|
50
|
+
*/
|
|
51
|
+
// TS TODO: region as type?
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function formatDurationWithSeconds(seconds, region) {
|
|
55
|
+
(0, _deprecated.logDeprecationWarning)("formatDurationWithSeconds", "formatjs");
|
|
56
|
+
return (0, _time.formatDurationLikeMoment)(seconds, true, {
|
|
57
|
+
enabled: true,
|
|
58
|
+
code: region
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=deprecated-with-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deprecated-with-types.ts"],"names":["formatTime","ms","options","format","OTP_API_TIME_FORMAT","formatDuration","seconds","region","enabled","code","formatDurationWithSeconds"],"mappings":";;;;;;;;;AAEA;;AAEA;;AACA;;AALA;AAWA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAT,CAAoBC,EAApB,EAAgCC,OAAhC,EAA8D;AACnE,yCAAsB,YAAtB,EAAoC,UAApC;AAEA,SAAO,qBACL,sBAAWD,EAAX,EAAeC,OAAf,CADK,EAEL,CAAAA,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEC,MAAT,KAAmBC,yBAFd,CAAP;AAID;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,cAAT,CAAwBC,OAAxB,EAAyCC,MAAzC,EAAiE;AACtE,yCAAsB,gBAAtB,EAAwC,UAAxC;AAEA,SAAO,oCAAyBD,OAAzB,EAAkC,KAAlC,EAAyC;AAC9CE,IAAAA,OAAO,EAAE,IADqC;AAE9CC,IAAAA,IAAI,EAAEF;AAFwC,GAAzC,CAAP;AAID;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,yBAAT,CACLJ,OADK,EAELC,MAFK,EAGG;AACR,yCAAsB,2BAAtB,EAAmD,UAAnD;AAEA,SAAO,oCAAyBD,OAAzB,EAAkC,IAAlC,EAAwC;AAC7CE,IAAAA,OAAO,EAAE,IADoC;AAE7CC,IAAAA,IAAI,EAAEF;AAFuC,GAAxC,CAAP;AAID","sourcesContent":["/* eslint-disable import/no-cycle */\nimport { TimeOptions } from \"@opentripplanner/types\";\nimport { format } from \"date-fns\";\n\nimport { logDeprecationWarning } from \"./deprecated\";\nimport {\n formatDurationLikeMoment,\n offsetTime,\n OTP_API_TIME_FORMAT\n} from \"./time\";\n\n// time.ts\n\n/**\n * Formats a time value for display in narrative\n * TODO: internationalization/timezone\n * @param {number} ms epoch time value in milliseconds\n * @returns {string} formatted text representation\n */\nexport function formatTime(ms: number, options: TimeOptions): string {\n logDeprecationWarning(\"formatTime\", \"formatjs\");\n\n return format(\n offsetTime(ms, options),\n options?.format || OTP_API_TIME_FORMAT\n );\n}\n\n/**\n * Formats an elapsed time duration for display in narrative.\n * TODO: internationalization\n * @param {number} seconds duration in seconds\n * @returns {string} formatted text representation\n */\n// TS TODO: region as type?\nexport function formatDuration(seconds: number, region: string): string {\n logDeprecationWarning(\"formatDuration\", \"formatjs\");\n\n return formatDurationLikeMoment(seconds, false, {\n enabled: true,\n code: region\n });\n}\n\n/**\n * Formats an elapsed time in seconds, minutes, hours duration for display in narrative\n * @param {number} seconds duration in seconds\n * @param {object} region an object that allows internationalization of the time\n * @returns {string} formatted text representation\n */\n// TS TODO: region as type?\nexport function formatDurationWithSeconds(\n seconds: number,\n region: string\n): string {\n logDeprecationWarning(\"formatDurationWithSeconds\", \"formatjs\");\n\n return formatDurationLikeMoment(seconds, true, {\n enabled: true,\n code: region\n });\n}\n"],"file":"deprecated-with-types.js"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as itinerary from "./itinerary";
|
|
2
|
+
import * as map from "./map";
|
|
3
|
+
import * as route from "./route";
|
|
4
|
+
import * as storage from "./storage";
|
|
5
|
+
import * as time from "./time";
|
|
6
|
+
import * as ui from "./ui";
|
|
7
|
+
declare const core: {
|
|
8
|
+
itinerary: typeof itinerary;
|
|
9
|
+
map: typeof map;
|
|
10
|
+
profile: any;
|
|
11
|
+
query: any;
|
|
12
|
+
queryParams: any;
|
|
13
|
+
route: typeof route;
|
|
14
|
+
storage: typeof storage;
|
|
15
|
+
time: typeof time;
|
|
16
|
+
ui: typeof ui;
|
|
17
|
+
};
|
|
18
|
+
export default core;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAI7B,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC;AAE3B,QAAA,MAAM,IAAI;;;;;;;;;;CAUT,CAAC;AAEF,eAAe,IAAI,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -9,8 +9,6 @@ var itinerary = _interopRequireWildcard(require("./itinerary"));
|
|
|
9
9
|
|
|
10
10
|
var map = _interopRequireWildcard(require("./map"));
|
|
11
11
|
|
|
12
|
-
var messages = _interopRequireWildcard(require("./messages"));
|
|
13
|
-
|
|
14
12
|
var profile = _interopRequireWildcard(require("./profile"));
|
|
15
13
|
|
|
16
14
|
var query = _interopRequireWildcard(require("./query"));
|
|
@@ -23,8 +21,6 @@ var storage = _interopRequireWildcard(require("./storage"));
|
|
|
23
21
|
|
|
24
22
|
var time = _interopRequireWildcard(require("./time"));
|
|
25
23
|
|
|
26
|
-
var types = _interopRequireWildcard(require("./types"));
|
|
27
|
-
|
|
28
24
|
var ui = _interopRequireWildcard(require("./ui"));
|
|
29
25
|
|
|
30
26
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -34,14 +30,12 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
34
30
|
const core = {
|
|
35
31
|
itinerary,
|
|
36
32
|
map,
|
|
37
|
-
messages,
|
|
38
33
|
profile,
|
|
39
34
|
query,
|
|
40
35
|
queryParams,
|
|
41
36
|
route,
|
|
42
37
|
storage,
|
|
43
38
|
time,
|
|
44
|
-
types,
|
|
45
39
|
ui
|
|
46
40
|
};
|
|
47
41
|
var _default = core;
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["core","itinerary","map","profile","query","queryParams","route","storage","time","ui"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,IAAI,GAAG;AACXC,EAAAA,SADW;AAEXC,EAAAA,GAFW;AAGXC,EAAAA,OAHW;AAIXC,EAAAA,KAJW;AAKXC,EAAAA,WALW;AAMXC,EAAAA,KANW;AAOXC,EAAAA,OAPW;AAQXC,EAAAA,IARW;AASXC,EAAAA;AATW,CAAb;eAYeT,I","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\";\n\nconst core = {\n itinerary,\n map,\n profile,\n query,\n queryParams,\n route,\n storage,\n time,\n ui\n};\n\nexport default core;\n"],"file":"index.js"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Company, Config, ElevationProfile, FlexBookingInfo, Itinerary, LatLngArray, Leg, Step } from "@opentripplanner/types";
|
|
2
|
+
import { calculateFares, getLegModeLabel, getModeForPlace, getPlaceName, getStepDirection, getStepInstructions, getStepStreetName, getTimeZoneOffset, getTransitFare } from "./deprecated";
|
|
3
|
+
export { calculateFares, getLegModeLabel, getModeForPlace, getPlaceName, getStepDirection, getStepInstructions, getStepStreetName, getTimeZoneOffset, getTransitFare };
|
|
4
|
+
export declare const transitModes: string[];
|
|
5
|
+
/**
|
|
6
|
+
* @param {config} config OTP-RR configuration object
|
|
7
|
+
* @return {Array} List of all transit modes defined in config; otherwise default mode list
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTransitModes(config: Config): string[];
|
|
10
|
+
export declare function isTransit(mode: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if the leg pickup rules enabled which require
|
|
13
|
+
* calling ahead for the service to run. "mustPhone" is the only
|
|
14
|
+
* property of boardRule which encodes this info.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isReservationRequired(leg: Leg): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Returns true if the leg has continuous dropoff enabled which requires
|
|
19
|
+
* asking the driver to let the user off. "coordinateWithDriver" is the only
|
|
20
|
+
* property of alightRule which encodes this info.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isContinuousDropoff(leg: Leg): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The two rules checked by the above two functions are the only values
|
|
25
|
+
* returned by OTP when a leg is a flex leg.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isFlex(leg: Leg): boolean;
|
|
28
|
+
export declare function isAdvanceBookingRequired(info: FlexBookingInfo): boolean;
|
|
29
|
+
export declare function legDropoffRequiresAdvanceBooking(leg: Leg): boolean;
|
|
30
|
+
export declare function isWalk(mode: string): boolean;
|
|
31
|
+
export declare function isBicycle(mode: string): boolean;
|
|
32
|
+
export declare function isBicycleRent(mode: string): boolean;
|
|
33
|
+
export declare function isCar(mode: string): boolean;
|
|
34
|
+
export declare function isMicromobility(mode: string): boolean;
|
|
35
|
+
export declare function isAccessMode(mode: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
38
|
+
* @return {boolean} whether any of the modes are transit modes
|
|
39
|
+
*/
|
|
40
|
+
export declare function hasTransit(modesStr: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
43
|
+
* @return {boolean} whether any of the modes are car-based modes
|
|
44
|
+
*/
|
|
45
|
+
export declare function hasCar(modesStr: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
48
|
+
* @return {boolean} whether any of the modes are bicycle-based modes
|
|
49
|
+
*/
|
|
50
|
+
export declare function hasBike(modesStr: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
53
|
+
* @return {boolean} whether any of the modes are micromobility-based modes
|
|
54
|
+
*/
|
|
55
|
+
export declare function hasMicromobility(modesStr: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
58
|
+
* @return {boolean} whether any of the modes is a hailing mode
|
|
59
|
+
*/
|
|
60
|
+
export declare function hasHail(modesStr: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* @param {string} modesStr a comma-separated list of OTP modes
|
|
63
|
+
* @return {boolean} whether any of the modes is a rental mode
|
|
64
|
+
*/
|
|
65
|
+
export declare function hasRental(modesStr: string): boolean;
|
|
66
|
+
export declare function getMapColor(mode: string): string;
|
|
67
|
+
export declare function toSentenceCase(str: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Derive the company string based on mode and network associated with leg.
|
|
70
|
+
*/
|
|
71
|
+
export declare function getCompanyFromLeg(leg: Leg): string;
|
|
72
|
+
export declare function getItineraryBounds(itinerary: Itinerary): LatLngArray[];
|
|
73
|
+
/**
|
|
74
|
+
* Return a coords object that encloses the given leg's geometry.
|
|
75
|
+
*/
|
|
76
|
+
export declare function getLegBounds(leg: Leg): number[];
|
|
77
|
+
export declare function legLocationAtDistance(leg: Leg, distance: number): number[];
|
|
78
|
+
export declare function legElevationAtDistance(points: number[][], distance: number): number;
|
|
79
|
+
export declare function getElevationProfile(steps: Step[], unitConversion?: number): ElevationProfile;
|
|
80
|
+
/**
|
|
81
|
+
* Uses canvas.measureText to compute and return the width of the given text of given font in pixels.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} text The text to be rendered.
|
|
84
|
+
* @param {string} font The css font descriptor that text is to be rendered with (e.g. "bold 14px verdana").
|
|
85
|
+
*
|
|
86
|
+
* @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
|
|
87
|
+
*/
|
|
88
|
+
export declare function getTextWidth(text: string, font?: string): number;
|
|
89
|
+
/**
|
|
90
|
+
* Get the configured company object for the given network string if the company
|
|
91
|
+
* has been defined in the provided companies array config.
|
|
92
|
+
*/
|
|
93
|
+
export declare function getCompanyForNetwork(networkString: string, companies?: Company[]): Company;
|
|
94
|
+
/**
|
|
95
|
+
* Get a string label to display from a list of vehicle rental networks.
|
|
96
|
+
*
|
|
97
|
+
* @param {Array<string>} networks A list of network ids.
|
|
98
|
+
* @param {Array<object>} [companies=[]] An optional list of the companies config.
|
|
99
|
+
* @return {string} A label for use in presentation on a website.
|
|
100
|
+
*/
|
|
101
|
+
export declare function getCompaniesLabelFromNetworks(networks: string[], companies?: Company[]): string;
|
|
102
|
+
export declare function getTNCLocation(leg: Leg, type: string): string;
|
|
103
|
+
export declare function calculatePhysicalActivity(itinerary: Itinerary): {
|
|
104
|
+
bikeDuration: number;
|
|
105
|
+
caloriesBurned: number;
|
|
106
|
+
walkDuration: number;
|
|
107
|
+
};
|
|
108
|
+
export declare function calculateTncFares(itinerary: any): {
|
|
109
|
+
maxTNCFare: any;
|
|
110
|
+
minTNCFare: any;
|
|
111
|
+
tncCurrencyCode: any;
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=itinerary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"itinerary.d.ts","sourceRoot":"","sources":["../src/itinerary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,SAAS,EACT,WAAW,EACX,GAAG,EACH,IAAI,EACL,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EAC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,EAAE,MAAM,EAAE,EAClB,SAAS,GAAE,OAAO,EAAO,GACxB,MAAM,CAMR;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG7D;AAED,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,SAAS,GACnB;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB,CAcA;AAED,wBAAgB,iBAAiB,CAAC,SAAS,KAAA;;;;EAQ1C"}
|
package/lib/itinerary.js
CHANGED
|
@@ -111,7 +111,7 @@ exports.transitModes = transitModes;
|
|
|
111
111
|
|
|
112
112
|
function getTransitModes(config) {
|
|
113
113
|
if (!config || !config.modes || !config.modes.transitModes) return transitModes;
|
|
114
|
-
return config.modes.transitModes.map(tm => tm.mode);
|
|
114
|
+
return config.modes.transitModes.map(tm => typeof tm !== "string" ? tm.mode : tm);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
function isTransit(mode) {
|
|
@@ -441,6 +441,7 @@ function getElevationProfile(steps, unitConversion = 1) {
|
|
|
441
441
|
|
|
442
442
|
|
|
443
443
|
function getTextWidth(text, font = "22px Arial") {
|
|
444
|
+
// Create custom type for function including re-used canvas object
|
|
444
445
|
// re-use canvas object for better performance
|
|
445
446
|
const canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
|
|
446
447
|
const context = canvas.getContext("2d");
|
package/lib/itinerary.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/itinerary.js"],"names":["transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","isContinuousDropoff","alightRule","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","polyline","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","maxTNCFare","minTNCFare","tncCurrencyCode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAwBA;AACO,MAAMA,YAAY,GAAG,CAC1B,MAD0B,EAE1B,KAF0B,EAG1B,QAH0B,EAI1B,OAJ0B,EAK1B,MAL0B,EAM1B,SAN0B,CAArB;AASP;AACA;AACA;AACA;;;;AAEO,SAASC,eAAT,CAAyBC,MAAzB,EAAiC;AACtC,MAAI,CAACA,MAAD,IAAW,CAACA,MAAM,CAACC,KAAnB,IAA4B,CAACD,MAAM,CAACC,KAAP,CAAaH,YAA9C,EACE,OAAOA,YAAP;AACF,SAAOE,MAAM,CAACC,KAAP,CAAaH,YAAb,CAA0BI,GAA1B,CAA8BC,EAAE,IAAIA,EAAE,CAACC,IAAvC,CAAP;AACD;;AAEM,SAASC,SAAT,CAAmBD,IAAnB,EAAyB;AAC9B,SAAON,YAAY,CAACQ,QA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,SAA3B,EAAsC;AAC3C;AACA;AACA,QAAM;AAAEiF,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,MAA8C,gCAClDnF,SADkD,EAElD,IAFkD,CAApD;AAIA,SAAO;AAAEiF,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,GAAP;AACD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport turfAlong from \"@turf/along\";\n\nimport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTimeZoneOffset,\n getTransitFare\n} from \"./deprecated\";\n\nexport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTimeZoneOffset,\n getTransitFare\n};\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config) {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n return config.modes.transitModes.map(tm => tm.mode);\n}\n\nexport function isTransit(mode) {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property of boardRule which encodes this info.\n */\nexport function isReservationRequired(leg) {\n return leg.boardRule === \"mustPhone\";\n}\n/**\n * Returns true if the leg has continuous dropoff enabled which requires\n * asking the driver to let the user off. \"coordinateWithDriver\" is the only\n * property of alightRule which encodes this info.\n */\nexport function isContinuousDropoff(leg) {\n return leg.alightRule === \"coordinateWithDriver\";\n}\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg) {\n return isReservationRequired(leg) || isContinuousDropoff(leg);\n}\n\nexport function isAdvanceBookingRequired(info) {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg) {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\nexport function isWalk(mode) {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode) {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode) {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode) {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode) {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode) {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr) {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr) {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr) {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr) {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr) {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr) {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode) {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str) {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg) {\n if (!leg) return null;\n const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && tncData) {\n return tncData.company;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(itinerary) {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg) {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg, distance) {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(points, distance) {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return iterpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(steps, unitConversion = 1) {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous = null;\n const points = [];\n steps.forEach(step => {\n if (!step.elevation || step.elevation.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < step.elevation.length; i++) {\n const elev = step.elevation[i];\n if (previous) {\n const diff = (elev.second - previous.second) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.first !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.second * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.first, elev.second]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (i === step.elevation.length - 1 && elev.first !== step.distance) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text, font = \"22px Arial\") {\n // re-use canvas object for better performance\n const canvas =\n getTextWidth.canvas ||\n (getTextWidth.canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(networkString, companies = []) {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(networks, companies = []) {\n return networks\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg, type) {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(itinerary) {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\nexport function calculateTncFares(itinerary) {\n // TODO: don't rely on deprecated methods!\n // At the moment this is safe as none of these exported variables contain strings\n const { maxTNCFare, minTNCFare, tncCurrencyCode } = calculateFares(\n itinerary,\n true\n );\n return { maxTNCFare, minTNCFare, tncCurrencyCode };\n}\n"],"file":"itinerary.js"}
|
|
1
|
+
{"version":3,"sources":["../src/itinerary.ts"],"names":["transitModes","getTransitModes","config","modes","map","tm","mode","isTransit","includes","isReservationRequired","leg","boardRule","isContinuousDropoff","alightRule","isFlex","isAdvanceBookingRequired","info","latestBookingTime","daysPrior","legDropoffRequiresAdvanceBooking","dropOffBookingInfo","isWalk","isBicycle","isBicycleRent","isCar","startsWith","isMicromobility","isAccessMode","hasTransit","modesStr","split","some","hasCar","hasBike","hasMicromobility","hasHail","indexOf","hasRental","getMapColor","get","toSentenceCase","str","String","charAt","toUpperCase","substr","toLowerCase","getCompanyFromLeg","from","rentedBike","rentedCar","rentedVehicle","tncData","networks","company","getItineraryBounds","itinerary","coords","legs","forEach","legCoords","polyline","toGeoJSON","legGeometry","points","coordinates","c","getLegBounds","length","push","lat","lon","to","legLocationAtDistance","distance","line","pt","units","geometry","e","legElevationAtDistance","traversed","unshift","i","start","elevDistanceSpan","console","warn","pct","elevSpan","getElevationProfile","steps","unitConversion","minElev","maxElev","gain","loss","previous","step","elevation","elev","diff","second","first","convertedElevation","getTextWidth","text","font","canvas","document","createElement","context","getContext","metrics","measureText","width","getCompanyForNetwork","networkString","companies","find","co","id","getCompaniesLabelFromNetworks","network","filter","label","join","getTNCLocation","type","location","toFixed","calculatePhysicalActivity","walkDuration","bikeDuration","duration","caloriesBurned","calculateTncFares","maxTNCFare","minTNCFare","tncCurrencyCode"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAWA;;AAEA;;AAwBA;AACO,MAAMA,YAAY,GAAG,CAC1B,MAD0B,EAE1B,KAF0B,EAG1B,QAH0B,EAI1B,OAJ0B,EAK1B,MAL0B,EAM1B,SAN0B,CAArB;AASP;AACA;AACA;AACA;;;;AAEO,SAASC,eAAT,CAAyBC,MAAzB,EAAmD;AACxD,MAAI,CAACA,MAAD,IAAW,CAACA,MAAM,CAACC,KAAnB,IAA4B,CAACD,MAAM,CAACC,KAAP,CAAaH,YAA9C,EACE,OAAOA,YAAP;AAEF,SAAOE,MAAM,CAACC,KAAP,CAAaH,YAAb,CAA0BI,GAA1B,CAA8BC,EAAE,IACrC,OAAOA,EAAP,KAAc,QAAd,GAAyBA,EAAE,CAACC,IAA5B,GAAmCD,EAD9B,CAAP;AAGD;;AAEM,SAASE,SAAT,CAAmBD,IAAnB,EAA0C;AAC/C,SAAON,YAAY,CAACQ,QAAb,CAAsBF,IAAtB,KAA+BA,IAAI,KAAK,SAA/C;AACD;AAED;AACA;AACA;AACA;AACA;;;AACO,SAASG,qBAAT,CAA+BC,GAA/B,EAAkD;AACvD,SAAOA,GAAG,CAACC,SAAJ,KAAkB,WAAzB;AACD;AACD;AACA;AACA;AACA;AACA;;;AACO,SAASC,mBAAT,CAA6BF,GAA7B,EAAgD;AACrD,SAAOA,GAAG,CAACG,UAAJ,KAAmB,sBAA1B;AACD;AACD;AACA;AACA;AACA;;;AACO,SAASC,MAAT,CAAgBJ,GAAhB,EAAmC;AACxC,SAAOD,qBAAq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EAAwD;AAC7D,QAAMC,QAAQ,GAAGvH,GAAG,CAACsH,IAAD,CAApB;AACA,SAAQ,GAAEC,QAAQ,CAAC3D,GAAT,CAAa4D,OAAb,CAAqB,CAArB,CAAwB,IAAGD,QAAQ,CAAC1D,GAAT,CAAa2D,OAAb,CAAqB,CAArB,CAAwB,EAA7D;AACD;;AAEM,SAASC,yBAAT,CACL3E,SADK,EAML;AACA,MAAI4E,YAAY,GAAG,CAAnB;AACA,MAAIC,YAAY,GAAG,CAAnB;AACA7E,EAAAA,SAAS,CAACE,IAAV,CAAeC,OAAf,CAAuBjD,GAAG,IAAI;AAC5B,QAAIA,GAAG,CAACJ,IAAJ,CAASmB,UAAT,CAAoB,MAApB,CAAJ,EAAiC2G,YAAY,IAAI1H,GAAG,CAAC4H,QAApB;AACjC,QAAI5H,GAAG,CAACJ,IAAJ,CAASmB,UAAT,CAAoB,SAApB,CAAJ,EAAoC4G,YAAY,IAAI3H,GAAG,CAAC4H,QAApB;AACrC,GAHD;AAIA,QAAMC,cAAc,GACjBH,YAAY,GAAG,IAAhB,GAAwB,GAAxB,GAA+BC,YAAY,GAAG,IAAhB,GAAwB,GADxD;AAEA,SAAO;AACLA,IAAAA,YADK;AAELE,IAAAA,cAFK;AAGLH,IAAAA;AAHK,GAAP;AAKD;;AAEM,SAASI,iBAAT,CAA2BhF,SAA3B,EAAsC;AAC3C;AACA;AACA,QAAM;AAAEiF,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,MAA8C,gCAClDnF,SADkD,EAElD,IAFkD,CAApD;AAIA,SAAO;AAAEiF,IAAAA,UAAF;AAAcC,IAAAA,UAAd;AAA0BC,IAAAA;AAA1B,GAAP;AACD","sourcesContent":["import polyline from \"@mapbox/polyline\";\nimport {\n Company,\n Config,\n ElevationProfile,\n FlexBookingInfo,\n Itinerary,\n LatLngArray,\n Leg,\n Step\n} from \"@opentripplanner/types\";\nimport turfAlong from \"@turf/along\";\n\nimport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTimeZoneOffset,\n getTransitFare\n} from \"./deprecated\";\n\nexport {\n calculateFares,\n getLegModeLabel,\n getModeForPlace,\n getPlaceName,\n getStepDirection,\n getStepInstructions,\n getStepStreetName,\n getTimeZoneOffset,\n getTransitFare\n};\n\n// All OTP transit modes\nexport const transitModes = [\n \"TRAM\",\n \"BUS\",\n \"SUBWAY\",\n \"FERRY\",\n \"RAIL\",\n \"GONDOLA\"\n];\n\n/**\n * @param {config} config OTP-RR configuration object\n * @return {Array} List of all transit modes defined in config; otherwise default mode list\n */\n\nexport function getTransitModes(config: Config): string[] {\n if (!config || !config.modes || !config.modes.transitModes)\n return transitModes;\n\n return config.modes.transitModes.map(tm =>\n typeof tm !== \"string\" ? tm.mode : tm\n );\n}\n\nexport function isTransit(mode: string): boolean {\n return transitModes.includes(mode) || mode === \"TRANSIT\";\n}\n\n/**\n * Returns true if the leg pickup rules enabled which require\n * calling ahead for the service to run. \"mustPhone\" is the only\n * property of boardRule which encodes this info.\n */\nexport function isReservationRequired(leg: Leg): boolean {\n return leg.boardRule === \"mustPhone\";\n}\n/**\n * Returns true if the leg has continuous dropoff enabled which requires\n * asking the driver to let the user off. \"coordinateWithDriver\" is the only\n * property of alightRule which encodes this info.\n */\nexport function isContinuousDropoff(leg: Leg): boolean {\n return leg.alightRule === \"coordinateWithDriver\";\n}\n/**\n * The two rules checked by the above two functions are the only values\n * returned by OTP when a leg is a flex leg.\n */\nexport function isFlex(leg: Leg): boolean {\n return isReservationRequired(leg) || isContinuousDropoff(leg);\n}\n\nexport function isAdvanceBookingRequired(info: FlexBookingInfo): boolean {\n return info?.latestBookingTime?.daysPrior > 0;\n}\nexport function legDropoffRequiresAdvanceBooking(leg: Leg): boolean {\n return isAdvanceBookingRequired(leg.dropOffBookingInfo);\n}\n\nexport function isWalk(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"WALK\";\n}\n\nexport function isBicycle(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE\";\n}\n\nexport function isBicycleRent(mode: string): boolean {\n if (!mode) return false;\n\n return mode === \"BICYCLE_RENT\";\n}\n\nexport function isCar(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"CAR\");\n}\n\nexport function isMicromobility(mode: string): boolean {\n if (!mode) return false;\n return mode.startsWith(\"MICROMOBILITY\") || mode.startsWith(\"SCOOTER\");\n}\n\nexport function isAccessMode(mode: string): boolean {\n return (\n isWalk(mode) ||\n isBicycle(mode) ||\n isBicycleRent(mode) ||\n isCar(mode) ||\n isMicromobility(mode)\n );\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are transit modes\n */\nexport function hasTransit(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isTransit(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are car-based modes\n */\nexport function hasCar(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isCar(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are bicycle-based modes\n */\nexport function hasBike(modesStr: string): boolean {\n return modesStr\n .split(\",\")\n .some(mode => isBicycle(mode) || isBicycleRent(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes are micromobility-based modes\n */\nexport function hasMicromobility(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => isMicromobility(mode));\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a hailing mode\n */\nexport function hasHail(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_HAIL\") > -1);\n}\n\n/**\n * @param {string} modesStr a comma-separated list of OTP modes\n * @return {boolean} whether any of the modes is a rental mode\n */\nexport function hasRental(modesStr: string): boolean {\n return modesStr.split(\",\").some(mode => mode.indexOf(\"_RENT\") > -1);\n}\n\nexport function getMapColor(mode: string): string {\n mode = mode || this.get(\"mode\");\n if (mode === \"WALK\") return \"#444\";\n if (mode === \"BICYCLE\") return \"#0073e5\";\n if (mode === \"SUBWAY\") return \"#e60000\";\n if (mode === \"RAIL\") return \"#b00\";\n if (mode === \"BUS\") return \"#080\";\n if (mode === \"TRAM\") return \"#800\";\n if (mode === \"FERRY\") return \"#008\";\n if (mode === \"CAR\") return \"#444\";\n if (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") return \"#f5a729\";\n return \"#aaa\";\n}\n\nexport function toSentenceCase(str: string): string {\n if (str == null) {\n return \"\";\n }\n str = String(str);\n return str.charAt(0).toUpperCase() + str.substr(1).toLowerCase();\n}\n\n/**\n * Derive the company string based on mode and network associated with leg.\n */\nexport function getCompanyFromLeg(leg: Leg): string {\n if (!leg) return null;\n const { from, mode, rentedBike, rentedCar, rentedVehicle, tncData } = leg;\n if (mode === \"CAR\" && rentedCar) {\n return from.networks[0];\n }\n if (mode === \"CAR\" && tncData) {\n return tncData.company;\n }\n if (mode === \"BICYCLE\" && rentedBike && from.networks) {\n return from.networks[0];\n }\n if (\n (mode === \"MICROMOBILITY\" || mode === \"SCOOTER\") &&\n rentedVehicle &&\n from.networks\n ) {\n return from.networks[0];\n }\n return null;\n}\n\nexport function getItineraryBounds(itinerary: Itinerary): LatLngArray[] {\n let coords = [];\n itinerary.legs.forEach(leg => {\n const legCoords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map((c: number[]) => [c[1], c[0]]);\n coords = [...coords, ...legCoords];\n });\n return coords;\n}\n\n/**\n * Return a coords object that encloses the given leg's geometry.\n */\nexport function getLegBounds(leg: Leg): number[] {\n const coords = polyline\n .toGeoJSON(leg.legGeometry.points)\n .coordinates.map(c => [c[1], c[0]]);\n\n // in certain cases, there might be zero-length coordinates in the leg\n // geometry. In these cases, build us an array of coordinates using the from\n // and to data of the leg.\n if (coords.length === 0) {\n coords.push([leg.from.lat, leg.from.lon], [leg.to.lat, leg.to.lon]);\n }\n return coords;\n}\n\n/* Returns an interpolated lat-lon at a specified distance along a leg */\n\nexport function legLocationAtDistance(leg: Leg, distance: number): number[] {\n if (!leg.legGeometry) return null;\n\n try {\n const line = polyline.toGeoJSON(leg.legGeometry.points);\n const pt = turfAlong(line, distance, { units: \"meters\" });\n if (pt && pt.geometry && pt.geometry.coordinates) {\n return [pt.geometry.coordinates[1], pt.geometry.coordinates[0]];\n }\n } catch (e) {\n // FIXME handle error!\n }\n\n return null;\n}\n\n/* Returns an interpolated elevation at a specified distance along a leg */\n\nexport function legElevationAtDistance(\n points: number[][],\n distance: number\n): number {\n // Iterate through the combined elevation profile\n let traversed = 0;\n // If first point distance is not zero, insert starting point at zero with\n // null elevation. Encountering this value should trigger the warning below.\n if (points[0][0] > 0) {\n points.unshift([0, null]);\n }\n for (let i = 1; i < points.length; i++) {\n const start = points[i - 1];\n const elevDistanceSpan = points[i][0] - start[0];\n if (distance >= traversed && distance <= traversed + elevDistanceSpan) {\n // Distance falls within this point and the previous one;\n // compute & return iterpolated elevation value\n if (start[1] === null) {\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n }\n const pct = (distance - traversed) / elevDistanceSpan;\n const elevSpan = points[i][1] - start[1];\n return start[1] + elevSpan * pct;\n }\n traversed += elevDistanceSpan;\n }\n console.warn(\n \"Elevation value does not exist for distance.\",\n distance,\n traversed\n );\n return null;\n}\n\n// Iterate through the steps, building the array of elevation points and\n// keeping track of the minimum and maximum elevations reached\nexport function getElevationProfile(\n steps: Step[],\n unitConversion = 1\n): ElevationProfile {\n let minElev = 100000;\n let maxElev = -100000;\n let traversed = 0;\n let gain = 0;\n let loss = 0;\n let previous = null;\n const points = [];\n steps.forEach(step => {\n if (!step.elevation || step.elevation.length === 0) {\n traversed += step.distance;\n return;\n }\n for (let i = 0; i < step.elevation.length; i++) {\n const elev = step.elevation[i];\n if (previous) {\n const diff = (elev.second - previous.second) * unitConversion;\n if (diff > 0) gain += diff;\n else loss += diff;\n }\n if (i === 0 && elev.first !== 0) {\n // console.warn(`No elevation data available for step ${stepIndex}-${i} at beginning of segment`, elev)\n }\n const convertedElevation = elev.second * unitConversion;\n if (convertedElevation < minElev) minElev = convertedElevation;\n if (convertedElevation > maxElev) maxElev = convertedElevation;\n points.push([traversed + elev.first, elev.second]);\n // Insert \"filler\" point if the last point in elevation profile does not\n // reach the full distance of the step.\n if (i === step.elevation.length - 1 && elev.first !== step.distance) {\n // points.push([traversed + step.distance, elev.second])\n }\n previous = elev;\n }\n traversed += step.distance;\n });\n return { maxElev, minElev, points, traversed, gain, loss };\n}\n\n/**\n * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.\n *\n * @param {string} text The text to be rendered.\n * @param {string} font The css font descriptor that text is to be rendered with (e.g. \"bold 14px verdana\").\n *\n * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393\n */\nexport function getTextWidth(text: string, font = \"22px Arial\"): number {\n // Create custom type for function including re-used canvas object\n type GetTextWidth = typeof getTextWidth & { canvas: HTMLCanvasElement };\n\n // re-use canvas object for better performance\n const canvas =\n (getTextWidth as GetTextWidth).canvas ||\n ((getTextWidth as GetTextWidth).canvas = document.createElement(\"canvas\"));\n const context = canvas.getContext(\"2d\");\n context.font = font;\n const metrics = context.measureText(text);\n return metrics.width;\n}\n\n/**\n * Get the configured company object for the given network string if the company\n * has been defined in the provided companies array config.\n */\nexport function getCompanyForNetwork(\n networkString: string,\n companies: Company[] = []\n): Company {\n const company = companies.find(co => co.id === networkString);\n if (!company) {\n console.warn(\n `No company found in config.yml that matches rented vehicle network: ${networkString}`,\n companies\n );\n }\n return company;\n}\n\n/**\n * Get a string label to display from a list of vehicle rental networks.\n *\n * @param {Array<string>} networks A list of network ids.\n * @param {Array<object>} [companies=[]] An optional list of the companies config.\n * @return {string} A label for use in presentation on a website.\n */\nexport function getCompaniesLabelFromNetworks(\n networks: string[],\n companies: Company[] = []\n): string {\n return networks\n .map(network => getCompanyForNetwork(network, companies))\n .filter(co => !!co)\n .map(co => co.label)\n .join(\"/\");\n}\n\nexport function getTNCLocation(leg: Leg, type: string): string {\n const location = leg[type];\n return `${location.lat.toFixed(5)},${location.lon.toFixed(5)}`;\n}\n\nexport function calculatePhysicalActivity(\n itinerary: Itinerary\n): {\n bikeDuration: number;\n caloriesBurned: number;\n walkDuration: number;\n} {\n let walkDuration = 0;\n let bikeDuration = 0;\n itinerary.legs.forEach(leg => {\n if (leg.mode.startsWith(\"WALK\")) walkDuration += leg.duration;\n if (leg.mode.startsWith(\"BICYCLE\")) bikeDuration += leg.duration;\n });\n const caloriesBurned =\n (walkDuration / 3600) * 280 + (bikeDuration / 3600) * 290;\n return {\n bikeDuration,\n caloriesBurned,\n walkDuration\n };\n}\n\nexport function calculateTncFares(itinerary) {\n // TODO: don't rely on deprecated methods!\n // At the moment this is safe as none of these exported variables contain strings\n const { maxTNCFare, minTNCFare, tncCurrencyCode } = calculateFares(\n itinerary,\n true\n );\n return { maxTNCFare, minTNCFare, tncCurrencyCode };\n}\n"],"file":"itinerary.js"}
|
package/lib/map.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Company, Itinerary, LatLngArray, Leg, Location, TransitiveData, UserPosition } from "@opentripplanner/types";
|
|
2
|
+
import { coordsToString, getDetailText, latlngToString } from "./deprecated";
|
|
3
|
+
export { coordsToString, getDetailText, latlngToString };
|
|
4
|
+
export declare function currentPositionToLocation(currentPosition: UserPosition): Location;
|
|
5
|
+
export declare function stringToCoords(str: string): number[];
|
|
6
|
+
export declare function constructLocation(latlng: {
|
|
7
|
+
lat: number;
|
|
8
|
+
lng: number;
|
|
9
|
+
}): Location;
|
|
10
|
+
export declare function formatStoredPlaceName(location: Location, withDetails?: boolean): string;
|
|
11
|
+
export declare function matchLatLon(location1: Location, location2: Location): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Converts an OTP itinerary object to a transtive.js itinerary object.
|
|
14
|
+
* @param {*} itin Required OTP itinerary (see @opentripplanner/core-utils/types#itineraryType) to convert.
|
|
15
|
+
* @param {*} companies Optional list of companies, used for labeling vehicle rental locations.
|
|
16
|
+
* @param {*} getRouteLabel Optional function that takes an itinerary leg (see @opentripplanner/core-utils/types#legType)
|
|
17
|
+
* and returns a string representing the route label to display for that leg.
|
|
18
|
+
* @returns An itinerary in the transitive.js format.
|
|
19
|
+
*/
|
|
20
|
+
export declare function itineraryToTransitive(itin: Itinerary, companies: Company[], getRouteLabel: (leg: Leg) => string, disableFlexArc: boolean): TransitiveData;
|
|
21
|
+
declare type TransitivePlaceRaw = {
|
|
22
|
+
place_id: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function isBikeshareStation(place: TransitivePlaceRaw): boolean;
|
|
25
|
+
export declare function isEScooterStation(place: TransitivePlaceRaw): boolean;
|
|
26
|
+
export declare function isCarWalkTransition(place: TransitivePlaceRaw): boolean;
|
|
27
|
+
export declare function isValidLat(lat: number): boolean;
|
|
28
|
+
export declare function isValidLng(lng: number): boolean;
|
|
29
|
+
export declare function isValidLatLng(arr: LatLngArray): boolean;
|
|
30
|
+
//# sourceMappingURL=map.d.ts.map
|