@opentripplanner/core-utils 15.0.0 → 16.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/index.js +3 -0
- package/esm/index.js.map +1 -1
- package/esm/itinerary.js +95 -78
- package/esm/itinerary.js.map +1 -1
- package/esm/map.js +2 -2
- package/esm/map.js.map +1 -1
- package/esm/query-gen.js +9 -5
- package/esm/query-gen.js.map +1 -1
- package/esm/route.js +26 -20
- package/esm/route.js.map +1 -1
- package/esm/storage.js +4 -1
- package/esm/storage.js.map +1 -1
- package/esm/time.js +6 -5
- package/esm/time.js.map +1 -1
- package/esm/ui.js +4 -2
- package/esm/ui.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/itinerary.d.ts +17 -11
- package/lib/itinerary.d.ts.map +1 -1
- package/lib/itinerary.js +89 -84
- package/lib/itinerary.js.map +1 -1
- package/lib/map.d.ts +2 -2
- package/lib/map.d.ts.map +1 -1
- package/lib/map.js +1 -1
- package/lib/map.js.map +1 -1
- package/lib/query-gen.d.ts +1 -19
- package/lib/query-gen.d.ts.map +1 -1
- package/lib/query-gen.js +9 -5
- package/lib/query-gen.js.map +1 -1
- package/lib/route.d.ts +10 -8
- package/lib/route.d.ts.map +1 -1
- package/lib/route.js +22 -16
- package/lib/route.js.map +1 -1
- package/lib/storage.d.ts +1 -1
- package/lib/storage.d.ts.map +1 -1
- package/lib/storage.js +4 -1
- package/lib/storage.js.map +1 -1
- package/lib/time.d.ts +3 -1
- package/lib/time.d.ts.map +1 -1
- package/lib/time.js +5 -4
- package/lib/time.js.map +1 -1
- package/lib/ui.d.ts.map +1 -1
- package/lib/ui.js +4 -2
- package/lib/ui.js.map +1 -1
- package/package.json +9 -7
- package/src/__tests__/itinerary.ts +55 -5
- package/src/index.ts +3 -0
- package/src/itinerary.ts +134 -97
- package/src/map.ts +5 -3
- package/src/query-gen.ts +15 -9
- package/src/route.ts +65 -38
- package/src/storage.ts +8 -2
- package/src/time.ts +7 -6
- package/src/ui.ts +8 -6
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
package/esm/ui.js
CHANGED
|
@@ -14,9 +14,11 @@ export function enableScrollForSelector(selector) {
|
|
|
14
14
|
|
|
15
15
|
function isOverlayTotallyScrolled() {
|
|
16
16
|
// https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#Problems_and_solutions
|
|
17
|
+
if (!overlay) return false;
|
|
17
18
|
return overlay.scrollHeight - overlay.scrollTop <= overlay.clientHeight;
|
|
18
19
|
}
|
|
19
20
|
function disableRubberBand(event) {
|
|
21
|
+
if (!overlay || clientY === null) return;
|
|
20
22
|
var clientYDelta = event.targetTouches[0].clientY - clientY;
|
|
21
23
|
if (overlay.scrollTop === 0 && clientYDelta > 0) {
|
|
22
24
|
// element is at the top of its scroll
|
|
@@ -27,13 +29,13 @@ export function enableScrollForSelector(selector) {
|
|
|
27
29
|
event.preventDefault();
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
overlay.addEventListener("touchstart", function (event) {
|
|
32
|
+
overlay === null || overlay === void 0 || overlay.addEventListener("touchstart", function (event) {
|
|
31
33
|
if (event.targetTouches.length === 1) {
|
|
32
34
|
// detect single touch
|
|
33
35
|
clientY = event.targetTouches[0].clientY;
|
|
34
36
|
}
|
|
35
37
|
}, false);
|
|
36
|
-
overlay.addEventListener("touchmove", function (event) {
|
|
38
|
+
overlay === null || overlay === void 0 || overlay.addEventListener("touchmove", function (event) {
|
|
37
39
|
if (event.targetTouches.length === 1) {
|
|
38
40
|
// detect single touch
|
|
39
41
|
disableRubberBand(event);
|
package/esm/ui.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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<HTMLElement>(selector);\n let clientY: number | null = 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 if (!overlay) return false;\n return overlay.scrollHeight - overlay.scrollTop <= overlay.clientHeight;\n }\n\n function disableRubberBand(event: TouchEvent) {\n if (!overlay || clientY === null) return;\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 (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 (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;EAC7D,IAAII,OAAsB,GAAG,IAAI,CAAC,CAAC;;EAEnC,SAASC,wBAAwBA,CAAA,EAAY;IAC3C;IACA,IAAI,CAACJ,OAAO,EAAE,OAAO,KAAK;IAC1B,OAAOA,OAAO,CAACK,YAAY,GAAGL,OAAO,CAACM,SAAS,IAAIN,OAAO,CAACO,YAAY;EACzE;EAEA,SAASC,iBAAiBA,CAACC,KAAiB,EAAE;IAC5C,IAAI,CAACT,OAAO,IAAIG,OAAO,KAAK,IAAI,EAAE;IAClC,IAAMO,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,aAAPA,OAAO,eAAPA,OAAO,CAAEa,gBAAgB,CACvB,YAAY,EACZ,UAACJ,KAAiB,EAAK;IACrB,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,aAAPA,OAAO,eAAPA,OAAO,CAAEa,gBAAgB,CACvB,WAAW,EACX,UAACJ,KAAiB,EAAK;IACrB,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/index.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAO7B,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;AAC3B,OAAO,KAAK,QAAQ,MAAM,aAAa,CAAC;AACxC,OAAO,YAAY,MAAM,YAAY,CAAC;AAEtC,QAAA,MAAM,IAAI;;;;;;;;;;;CAWT,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC;AACxB,eAAe,IAAI,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -23,6 +23,12 @@ var ui = _interopRequireWildcard(require("./ui"));
|
|
|
23
23
|
var queryGen = _interopRequireWildcard(require("./query-gen"));
|
|
24
24
|
var _suspense = _interopRequireDefault(require("./suspense"));
|
|
25
25
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
26
|
+
// @ts-expect-error not typed
|
|
27
|
+
|
|
28
|
+
// @ts-expect-error not typed
|
|
29
|
+
|
|
30
|
+
// @ts-expect-error not typed
|
|
31
|
+
|
|
26
32
|
const core = {
|
|
27
33
|
itinerary,
|
|
28
34
|
map,
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["itinerary","_interopRequireWildcard","require","map","profile","query","queryParams","route","storage","time","ui","queryGen","_suspense","_interopRequireDefault","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","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"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,GAAA,GAAAF,uBAAA,CAAAC,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","names":["itinerary","_interopRequireWildcard","require","map","profile","query","queryParams","route","storage","time","ui","queryGen","_suspense","_interopRequireDefault","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","core","_default","exports"],"sources":["../src/index.ts"],"sourcesContent":["import * as itinerary from \"./itinerary\";\nimport * as map from \"./map\";\n// @ts-expect-error not typed\nimport * as profile from \"./profile\";\n// @ts-expect-error not typed\nimport * as query from \"./query\";\n// @ts-expect-error not typed\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"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,GAAA,GAAAF,uBAAA,CAAAC,OAAA;AAEA,IAAAE,OAAA,GAA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,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAXtC;;AAEA;;AAEA;;AASA,MAAMkB,IAAI,GAAG;EACXjC,SAAS;EACTG,GAAG;EACHC,OAAO;EACPC,KAAK;EACLM,QAAQ;EACRL,WAAW;EACXC,KAAK;EACLC,OAAO;EACPC,IAAI;EACJC;AACF,CAAC;AAAC,IAAAwB,QAAA,GAAAC,OAAA,CAAAX,OAAA,GAGaS,IAAI","ignoreList":[]}
|
package/lib/itinerary.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare function containsGeometry(place: Place): boolean;
|
|
|
23
23
|
export declare function endsWithGeometry(leg: Leg): boolean;
|
|
24
24
|
export declare function startsWithGeometry(leg: Leg): boolean;
|
|
25
25
|
export declare function legContainsGeometry(leg: Leg): boolean;
|
|
26
|
-
export declare function isAdvanceBookingRequired(info
|
|
26
|
+
export declare function isAdvanceBookingRequired(info?: FlexBookingInfo): boolean;
|
|
27
27
|
export declare function legDropoffRequiresAdvanceBooking(leg: Leg): boolean;
|
|
28
28
|
/**
|
|
29
29
|
* The two rules checked by the above two functions are the only values
|
|
@@ -72,14 +72,20 @@ export declare function toSentenceCase(str: string): string;
|
|
|
72
72
|
/**
|
|
73
73
|
* Derive the company string based on mode and network associated with leg.
|
|
74
74
|
*/
|
|
75
|
-
export declare function getCompanyFromLeg(leg
|
|
75
|
+
export declare function getCompanyFromLeg(leg?: Leg): string | null;
|
|
76
76
|
export declare function getItineraryBounds(itinerary: ItineraryOnlyLegsRequired): LatLngArray[];
|
|
77
77
|
/**
|
|
78
78
|
* Return a coords object that encloses the given leg's geometry.
|
|
79
79
|
*/
|
|
80
80
|
export declare function getLegBounds(leg: Leg): number[][];
|
|
81
|
-
export declare function legLocationAtDistance(leg: Leg, distance: number):
|
|
82
|
-
|
|
81
|
+
export declare function legLocationAtDistance(leg: Leg, distance: number): LatLngArray | undefined | null;
|
|
82
|
+
/**
|
|
83
|
+
* Returns an interpolated elevation at a specified distance along a leg
|
|
84
|
+
* @param points - The points of the elevation profile. Each point is a tuple of [distance, elevation].
|
|
85
|
+
* @param distance - The distance along the leg to interpolate the elevation at
|
|
86
|
+
* @returns The interpolated elevation at the specified distance
|
|
87
|
+
*/
|
|
88
|
+
export declare function legElevationAtDistance(points: [number, number][], distance: number): number | undefined;
|
|
83
89
|
export declare function mapOldElevationComponentToNew(oldElev: {
|
|
84
90
|
first: number;
|
|
85
91
|
second: number;
|
|
@@ -98,7 +104,7 @@ export declare function getTextWidth(text: string, font?: string): number;
|
|
|
98
104
|
* Get the configured company object for the given network string if the company
|
|
99
105
|
* has been defined in the provided companies array config.
|
|
100
106
|
*/
|
|
101
|
-
export declare function getCompanyForNetwork(networkString: string, companies?: Company[]): Company;
|
|
107
|
+
export declare function getCompanyForNetwork(networkString: string, companies?: Company[]): Company | undefined;
|
|
102
108
|
/**
|
|
103
109
|
* Get a string label to display from a list of vehicle rental networks. Returns
|
|
104
110
|
* empty string if no networks provided.
|
|
@@ -108,7 +114,7 @@ export declare function getCompanyForNetwork(networkString: string, companies?:
|
|
|
108
114
|
* @return {string} A label for use in presentation on a website.
|
|
109
115
|
*/
|
|
110
116
|
export declare function getCompaniesLabelFromNetworks(networks?: string[] | string, companies?: Company[]): string;
|
|
111
|
-
export declare function getTNCLocation(leg: Leg, type:
|
|
117
|
+
export declare function getTNCLocation(leg: Pick<Leg, "from" | "to">, type: "from" | "to"): string;
|
|
112
118
|
export declare function calculatePhysicalActivity(itinerary: ItineraryOnlyLegsRequired): {
|
|
113
119
|
bikeDuration: number;
|
|
114
120
|
caloriesBurned: number;
|
|
@@ -152,7 +158,7 @@ export declare const zeroDollars: (currency: Currency) => Money;
|
|
|
152
158
|
* all the information needed, but the other fields are kept to
|
|
153
159
|
* make the transition to Fares V2 less jarring.
|
|
154
160
|
*/
|
|
155
|
-
export declare function getLegCost(leg: Leg, mediumId?: string | null, riderCategoryId?: string | null, seenFareIds?: string[]): {
|
|
161
|
+
export declare function getLegCost(leg: Leg, mediumId?: string | null, riderCategoryId?: string | null, seenFareIds?: string[] | null): {
|
|
156
162
|
alternateFareProducts?: AppliedFareProduct[];
|
|
157
163
|
appliedFareProduct?: AppliedFareProduct;
|
|
158
164
|
isDependent?: boolean;
|
|
@@ -167,15 +173,15 @@ export declare function getLegCost(leg: Leg, mediumId?: string | null, riderCate
|
|
|
167
173
|
* @param seenFareIds List of fare product IDs that have already been seen on prev legs.
|
|
168
174
|
* @returns Money object for the total itinerary cost.
|
|
169
175
|
*/
|
|
170
|
-
export declare function getItineraryCost(legs: Leg[], mediumId?: string | string[] | null, riderCategoryId?: string | string[] | null): Money | undefined;
|
|
171
|
-
export declare const convertGraphQLResponseToLegacy: (leg: any) =>
|
|
176
|
+
export declare function getItineraryCost(legs: Leg[], mediumId?: string | (string | null)[] | null, riderCategoryId?: string | (string | null)[] | null): Money | undefined;
|
|
177
|
+
export declare const convertGraphQLResponseToLegacy: (leg: any) => Leg;
|
|
172
178
|
/** Extracts the route number for a leg returned from OTP1 or OTP2. */
|
|
173
179
|
export declare const getLegRouteShortName: (leg: Pick<Leg, "route" | "routeShortName">) => string | null;
|
|
174
180
|
/** Extract the route long name for a leg returned from OTP1 or OTP2. */
|
|
175
|
-
export declare const getLegRouteLongName: (leg: Pick<Leg, "route" | "routeLongName">) => string |
|
|
181
|
+
export declare const getLegRouteLongName: (leg: Pick<Leg, "route" | "routeLongName">) => string | undefined;
|
|
176
182
|
/**
|
|
177
183
|
* Returns the route short name, or the route long name if no short name is provided.
|
|
178
184
|
* This is happens with Seattle area streetcars and ferries.
|
|
179
185
|
*/
|
|
180
|
-
export declare const getLegRouteName: (leg: Pick<Leg, "route" | "routeLongName" | "routeShortName">) => string;
|
|
186
|
+
export declare const getLegRouteName: (leg: Pick<Leg, "route" | "routeLongName" | "routeShortName">) => string | undefined;
|
|
181
187
|
//# sourceMappingURL=itinerary.d.ts.map
|
package/lib/itinerary.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"itinerary.d.ts","sourceRoot":"","sources":["../src/itinerary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"itinerary.d.ts","sourceRoot":"","sources":["../src/itinerary.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,EAClB,OAAO,EACP,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,yBAAyB,EAEzB,eAAe,EACf,yBAAyB,EACzB,WAAW,EACX,GAAG,EACH,cAAc,EACd,KAAK,EACL,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,OAAO,EACR,MAAM,wBAAwB,CAAC;AAIhC,eAAO,MAAM,YAAY,UAQxB,CAAC;AAEF;;;GAGG;AAEH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAOxD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAE9C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAEvD;AACD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAKxD;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAItD;AACD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAElD;AACD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAEpD;AACD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAErD;AACD,wBAAgB,wBAAwB,CAAC,IAAI,CAAC,EAAE,eAA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C,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,EAC5C,eAAe,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,GAClD,KAAK,GAAG,SAAS,CA6EnB;AAiBD,eAAO,MAAM,8BAA8B,GAAI,KAAK,GAAG,KAAG,GAiCxD,CAAC;AAEH,sEAAsE;AACtE,eAAO,MAAM,oBAAoB,GAC/B,KAAK,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,gBAAgB,CAAC,KACzC,MAAM,GAAG,IAMX,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,mBAAmB,GAC9B,KAAK,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,CAAC,KACxC,MAAM,GAAG,SAIX,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,IAAI,CAAC,GAAG,EAAE,OAAO,GAAG,eAAe,GAAG,gBAAgB,CAAC,KAC3D,MAAM,GAAG,SAEX,CAAC"}
|
package/lib/itinerary.js
CHANGED
|
@@ -103,10 +103,11 @@ function legContainsGeometry(leg) {
|
|
|
103
103
|
}
|
|
104
104
|
function isAdvanceBookingRequired(info) {
|
|
105
105
|
var _info$latestBookingTi;
|
|
106
|
-
|
|
106
|
+
const daysPrior = info === null || info === void 0 || (_info$latestBookingTi = info.latestBookingTime) === null || _info$latestBookingTi === void 0 ? void 0 : _info$latestBookingTi.daysPrior;
|
|
107
|
+
return typeof daysPrior === "number" && daysPrior > 0;
|
|
107
108
|
}
|
|
108
109
|
function legDropoffRequiresAdvanceBooking(leg) {
|
|
109
|
-
return isAdvanceBookingRequired(leg
|
|
110
|
+
return isAdvanceBookingRequired(leg.dropOffBookingInfo);
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
/**
|
|
@@ -199,6 +200,7 @@ function hasRental(modesStr) {
|
|
|
199
200
|
return modesStr.split(",").some(mode => mode.indexOf("_RENT") > -1);
|
|
200
201
|
}
|
|
201
202
|
function getMapColor(mode) {
|
|
203
|
+
// @ts-expect-error this is not typed
|
|
202
204
|
mode = mode || this.get("mode");
|
|
203
205
|
if (mode === "WALK") return "#444";
|
|
204
206
|
if (mode === "BICYCLE") return "#0073e5";
|
|
@@ -234,14 +236,15 @@ function getCompanyFromLeg(leg) {
|
|
|
234
236
|
rentedVehicle,
|
|
235
237
|
rideHailingEstimate
|
|
236
238
|
} = leg;
|
|
239
|
+
const firstNetwork = Array.isArray(from.networks) && from.networks.length > 0 ? from.networks[0] : null;
|
|
237
240
|
if (mode === "CAR" && rentedCar) {
|
|
238
|
-
return
|
|
241
|
+
return firstNetwork;
|
|
239
242
|
}
|
|
240
243
|
if (mode === "CAR" && rideHailingEstimate) {
|
|
241
244
|
return rideHailingEstimate.provider.id;
|
|
242
245
|
}
|
|
243
|
-
if (mode === "BICYCLE" && rentedBike
|
|
244
|
-
return
|
|
246
|
+
if (mode === "BICYCLE" && rentedBike) {
|
|
247
|
+
return firstNetwork;
|
|
245
248
|
}
|
|
246
249
|
if (from.rentalVehicle) {
|
|
247
250
|
return from.rentalVehicle.network;
|
|
@@ -249,16 +252,16 @@ function getCompanyFromLeg(leg) {
|
|
|
249
252
|
if ((_from$vehicleRentalSt = from.vehicleRentalStation) !== null && _from$vehicleRentalSt !== void 0 && _from$vehicleRentalSt.rentalNetwork) {
|
|
250
253
|
return from.vehicleRentalStation.rentalNetwork.networkId;
|
|
251
254
|
}
|
|
252
|
-
if ((mode === "MICROMOBILITY" || mode === "SCOOTER") && rentedVehicle
|
|
253
|
-
return
|
|
255
|
+
if ((mode === "MICROMOBILITY" || mode === "SCOOTER") && rentedVehicle) {
|
|
256
|
+
return firstNetwork;
|
|
254
257
|
}
|
|
255
258
|
return null;
|
|
256
259
|
}
|
|
257
260
|
function getItineraryBounds(itinerary) {
|
|
258
|
-
|
|
261
|
+
const coords = [];
|
|
259
262
|
itinerary.legs.forEach(leg => {
|
|
260
263
|
const legCoords = _polyline.default.toGeoJSON(leg.legGeometry.points).coordinates.map(c => [c[1], c[0]]);
|
|
261
|
-
coords
|
|
264
|
+
coords.push(...legCoords);
|
|
262
265
|
});
|
|
263
266
|
return coords;
|
|
264
267
|
}
|
|
@@ -279,51 +282,46 @@ function getLegBounds(leg) {
|
|
|
279
282
|
}
|
|
280
283
|
|
|
281
284
|
/* Returns an interpolated lat-lon at a specified distance along a leg */
|
|
282
|
-
|
|
283
285
|
function legLocationAtDistance(leg, distance) {
|
|
284
|
-
if (!leg.legGeometry) return
|
|
286
|
+
if (!leg.legGeometry) return undefined;
|
|
285
287
|
try {
|
|
288
|
+
var _pt$geometry;
|
|
286
289
|
const line = _polyline.default.toGeoJSON(leg.legGeometry.points);
|
|
287
290
|
const pt = (0, _along.default)(line, distance, {
|
|
288
291
|
units: "meters"
|
|
289
292
|
});
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
// FIXME handle error!
|
|
293
|
+
const coords = pt === null || pt === void 0 || (_pt$geometry = pt.geometry) === null || _pt$geometry === void 0 ? void 0 : _pt$geometry.coordinates;
|
|
294
|
+
return [coords[1], coords[0]];
|
|
295
|
+
} catch {
|
|
296
|
+
// This is designed to catch the toGeoJSON from throwing if the geometry is not in the correct format
|
|
295
297
|
}
|
|
296
298
|
return null;
|
|
297
299
|
}
|
|
298
300
|
|
|
299
|
-
|
|
301
|
+
/**
|
|
302
|
+
* Returns an interpolated elevation at a specified distance along a leg
|
|
303
|
+
* @param points - The points of the elevation profile. Each point is a tuple of [distance, elevation].
|
|
304
|
+
* @param distance - The distance along the leg to interpolate the elevation at
|
|
305
|
+
* @returns The interpolated elevation at the specified distance
|
|
306
|
+
*/
|
|
300
307
|
|
|
301
308
|
function legElevationAtDistance(points, distance) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const start = points[i - 1];
|
|
311
|
-
const elevDistanceSpan = points[i][0] - start[0];
|
|
312
|
-
if (distance >= traversed && distance <= traversed + elevDistanceSpan) {
|
|
313
|
-
// Distance falls within this point and the previous one;
|
|
314
|
-
// compute & return interpolated elevation value
|
|
315
|
-
if (start[1] === null) {
|
|
316
|
-
console.warn("Elevation value does not exist for distance.", distance, traversed);
|
|
317
|
-
return null;
|
|
318
|
-
}
|
|
319
|
-
const pct = (distance - traversed) / elevDistanceSpan;
|
|
320
|
-
const elevSpan = points[i][1] - start[1];
|
|
321
|
-
return start[1] + elevSpan * pct;
|
|
309
|
+
const elevation = points.reduce((acc, point, index) => {
|
|
310
|
+
const prevPoint = points[index - 1];
|
|
311
|
+
// at the first index there is no previous point
|
|
312
|
+
if (!prevPoint) return acc;
|
|
313
|
+
const [pointDistance, pointElevation] = point;
|
|
314
|
+
const [prevPointDistance, prevPointElevation] = prevPoint;
|
|
315
|
+
if (distance >= prevPointDistance && distance <= pointDistance) {
|
|
316
|
+
return prevPointElevation + (pointElevation - prevPointElevation) * (distance - prevPointDistance) / (pointDistance - prevPointDistance);
|
|
322
317
|
}
|
|
323
|
-
|
|
318
|
+
return acc;
|
|
319
|
+
}, undefined);
|
|
320
|
+
if (elevation === undefined) {
|
|
321
|
+
console.warn("Elevation value does not exist for distance.", distance);
|
|
322
|
+
return undefined;
|
|
324
323
|
}
|
|
325
|
-
|
|
326
|
-
return null;
|
|
324
|
+
return elevation;
|
|
327
325
|
}
|
|
328
326
|
function mapOldElevationComponentToNew(oldElev) {
|
|
329
327
|
return {
|
|
@@ -396,6 +394,7 @@ function getTextWidth(text, font = "22px Arial") {
|
|
|
396
394
|
// reuse canvas object for better performance
|
|
397
395
|
const canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
|
|
398
396
|
const context = canvas.getContext("2d");
|
|
397
|
+
if (!context) return 0;
|
|
399
398
|
context.font = font;
|
|
400
399
|
const metrics = context.measureText(text);
|
|
401
400
|
return metrics.width;
|
|
@@ -450,21 +449,16 @@ function calculatePhysicalActivity(itinerary) {
|
|
|
450
449
|
* It is assumed that the same currency is used for all TNC legs.
|
|
451
450
|
*/
|
|
452
451
|
function calculateTncFares(itinerary) {
|
|
453
|
-
return itinerary.legs.filter(leg => leg.mode === "CAR" && leg.rideHailingEstimate).reduce(({
|
|
454
|
-
maxTNCFare,
|
|
455
|
-
minTNCFare
|
|
456
|
-
}, {
|
|
457
|
-
rideHailingEstimate
|
|
458
|
-
}) => {
|
|
452
|
+
return itinerary.legs.filter(leg => leg.mode === "CAR" && leg.rideHailingEstimate !== undefined).reduce((acc, leg) => {
|
|
459
453
|
const {
|
|
460
454
|
minPrice,
|
|
461
455
|
maxPrice
|
|
462
|
-
} = rideHailingEstimate;
|
|
456
|
+
} = leg.rideHailingEstimate;
|
|
463
457
|
return {
|
|
464
458
|
// Assumes a single currency for entire itinerary.
|
|
465
459
|
currencyCode: minPrice.currency.code,
|
|
466
|
-
maxTNCFare: maxTNCFare + maxPrice.amount,
|
|
467
|
-
minTNCFare: minTNCFare + minPrice.amount
|
|
460
|
+
maxTNCFare: acc.maxTNCFare + maxPrice.amount,
|
|
461
|
+
minTNCFare: acc.minTNCFare + minPrice.amount
|
|
468
462
|
};
|
|
469
463
|
}, {
|
|
470
464
|
currencyCode: null,
|
|
@@ -562,7 +556,7 @@ const zeroDollars = currency => ({
|
|
|
562
556
|
amount: 0,
|
|
563
557
|
currency
|
|
564
558
|
});
|
|
565
|
-
|
|
559
|
+
exports.zeroDollars = zeroDollars;
|
|
566
560
|
/**
|
|
567
561
|
* Extracts useful data from the fare products on a leg, such as the leg cost and transfer info.
|
|
568
562
|
* @param leg Leg with Fares v2 information
|
|
@@ -574,7 +568,6 @@ const zeroDollars = currency => ({
|
|
|
574
568
|
* all the information needed, but the other fields are kept to
|
|
575
569
|
* make the transition to Fares V2 less jarring.
|
|
576
570
|
*/
|
|
577
|
-
exports.zeroDollars = zeroDollars;
|
|
578
571
|
function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
579
572
|
if (!leg.fareProducts) return {
|
|
580
573
|
price: undefined
|
|
@@ -592,16 +585,19 @@ function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
|
592
585
|
return productRiderCategoryId === riderCategoryId && productMediaId === mediumId && (// Make sure there's a price
|
|
593
586
|
// Some fare products don't have a price at all.
|
|
594
587
|
product === null || product === void 0 ? void 0 : product.price);
|
|
588
|
+
})
|
|
589
|
+
// Make sure there's a price
|
|
590
|
+
// Some fare products don't have a price at all.
|
|
591
|
+
.filter(fare => {
|
|
592
|
+
var _fare$product;
|
|
593
|
+
return ((_fare$product = fare.product) === null || _fare$product === void 0 ? void 0 : _fare$product.price) !== undefined;
|
|
595
594
|
}).map(fare => {
|
|
596
|
-
const alreadySeen = (seenFareIds === null || seenFareIds === void 0 ? void 0 : seenFareIds.indexOf(fare.id)) > -1;
|
|
597
|
-
const {
|
|
598
|
-
currency
|
|
599
|
-
} = fare.product.price;
|
|
595
|
+
const alreadySeen = !!seenFareIds && (seenFareIds === null || seenFareIds === void 0 ? void 0 : seenFareIds.indexOf(fare.id)) > -1;
|
|
600
596
|
return {
|
|
601
597
|
id: fare.id,
|
|
602
598
|
product: {
|
|
603
599
|
...fare.product,
|
|
604
|
-
legPrice: alreadySeen ? zeroDollars(currency) : fare.product.price
|
|
600
|
+
legPrice: alreadySeen && fare.product.price ? zeroDollars(fare.product.price.currency) : fare.product.price
|
|
605
601
|
}
|
|
606
602
|
};
|
|
607
603
|
}).sort((a, b) => {
|
|
@@ -633,34 +629,40 @@ function getLegCost(leg, mediumId, riderCategoryId, seenFareIds) {
|
|
|
633
629
|
* @returns Money object for the total itinerary cost.
|
|
634
630
|
*/
|
|
635
631
|
function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
636
|
-
// TODO: Better input type handling
|
|
637
632
|
if (Array.isArray(mediumId) || Array.isArray(riderCategoryId)) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
currency: null
|
|
645
|
-
};
|
|
646
|
-
for (let i = 0; i < mediumId.length; i++) {
|
|
647
|
-
const newCost = getItineraryCost(legs, mediumId[i], riderCategoryId[i]);
|
|
648
|
-
if (newCost) {
|
|
649
|
-
var _total, _total$currency;
|
|
650
|
-
total = {
|
|
651
|
-
amount: ((_total = total) === null || _total === void 0 ? void 0 : _total.amount) + ((newCost === null || newCost === void 0 ? void 0 : newCost.amount) || 0),
|
|
652
|
-
currency: (_total$currency = total.currency) !== null && _total$currency !== void 0 ? _total$currency : newCost === null || newCost === void 0 ? void 0 : newCost.currency
|
|
653
|
-
};
|
|
633
|
+
// TODO: Better input type handling
|
|
634
|
+
if (Array.isArray(mediumId) && Array.isArray(riderCategoryId)) {
|
|
635
|
+
var _total$currency;
|
|
636
|
+
if (mediumId.length !== riderCategoryId.length) {
|
|
637
|
+
console.warn("Invalid input types, only using first item. medium id list and rider category list must have same number of items");
|
|
638
|
+
return getItineraryCost(legs, mediumId[0], riderCategoryId[0]);
|
|
654
639
|
}
|
|
640
|
+
const total = mediumId.reduce((acc, currentMediumId, index) => {
|
|
641
|
+
var _newCost$currency;
|
|
642
|
+
const newCost = getItineraryCost(legs, currentMediumId, riderCategoryId[index]);
|
|
643
|
+
if (!newCost) return acc;
|
|
644
|
+
return {
|
|
645
|
+
amount: acc.amount + (newCost.amount || 0),
|
|
646
|
+
currency: acc.currency.code !== "" ? acc.currency : (_newCost$currency = newCost.currency) !== null && _newCost$currency !== void 0 ? _newCost$currency : acc.currency
|
|
647
|
+
};
|
|
648
|
+
}, {
|
|
649
|
+
amount: 0,
|
|
650
|
+
currency: {
|
|
651
|
+
code: "",
|
|
652
|
+
digits: 0
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
if (!((_total$currency = total.currency) !== null && _total$currency !== void 0 && _total$currency.code)) return undefined;
|
|
656
|
+
return total;
|
|
655
657
|
}
|
|
656
|
-
|
|
657
|
-
return
|
|
658
|
+
console.warn("Invalid input types, only using first item. medium id list and rider category list must have same number of items");
|
|
659
|
+
return undefined;
|
|
658
660
|
}
|
|
659
661
|
const legCosts = legs
|
|
660
662
|
// Only legs with fares (no walking legs)
|
|
661
663
|
.filter(leg => {
|
|
662
664
|
var _leg$fareProducts;
|
|
663
|
-
return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) > 0;
|
|
665
|
+
return ((_leg$fareProducts = leg.fareProducts) === null || _leg$fareProducts === void 0 ? void 0 : _leg$fareProducts.length) && leg.fareProducts.length > 0;
|
|
664
666
|
})
|
|
665
667
|
// Get the leg cost object of each leg
|
|
666
668
|
.reduce((acc, leg) => {
|
|
@@ -673,6 +675,7 @@ function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
|
673
675
|
productUseId
|
|
674
676
|
} = getLegCost(leg, mediumId, riderCategoryId, acc.seenIds);
|
|
675
677
|
if (!appliedFareProduct) return acc;
|
|
678
|
+
if (!productUseId) return acc;
|
|
676
679
|
return {
|
|
677
680
|
legCosts: [...acc.legCosts, appliedFareProduct],
|
|
678
681
|
seenIds: [...acc.seenIds, productUseId]
|
|
@@ -683,15 +686,17 @@ function getItineraryCost(legs, mediumId, riderCategoryId) {
|
|
|
683
686
|
}).legCosts.map(lc => lc.legPrice);
|
|
684
687
|
if (legCosts.length === 0) return undefined;
|
|
685
688
|
// Calculate the total
|
|
686
|
-
return legCosts.reduce((prev, cur) => {
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
}, {
|
|
689
|
+
return legCosts.reduce((prev, cur) => ({
|
|
690
|
+
amount: prev.amount + (cur === null || cur === void 0 ? void 0 : cur.amount) || 0,
|
|
691
|
+
currency: prev.currency.code !== "" ? prev.currency : cur.currency
|
|
692
|
+
}),
|
|
693
|
+
// eslint-disable-next-line prettier/prettier -- old eslint doesn't know satisfies
|
|
694
|
+
{
|
|
693
695
|
amount: 0,
|
|
694
|
-
currency:
|
|
696
|
+
currency: {
|
|
697
|
+
code: "",
|
|
698
|
+
digits: 0
|
|
699
|
+
}
|
|
695
700
|
});
|
|
696
701
|
}
|
|
697
702
|
const pickupDropoffTypeToOtp1 = otp2Type => {
|