@any-routing/here-data-provider 0.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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # here-data-provider
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test here-data-provider` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@any-routing/here-data-provider",
3
+ "version": "0.0.0",
4
+ "private": false,
5
+ "dependencies": {
6
+ "@liberty-rider/flexpolyline": "0.1.0",
7
+ "@turf/bbox": "6.5.0",
8
+ "@turf/helpers": "6.5.0",
9
+ "comlink": "4.3.1",
10
+ "simplify-js": "1.2.4"
11
+ },
12
+ "peerDependencies": {
13
+ "@any-routing/core": "^0.0.0",
14
+ "tslib": "2.5.0"
15
+ },
16
+ "main": "./src/index.js",
17
+ "types": "./src/index.d.ts"
18
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/here-data-provider';
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/here-data-provider';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/here-data-provider/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,58 @@
1
+ import type { AnyRoutingDataProvider, AnyRoutingDataResponse, RequestOptions, RouteSummary, LngLatPosition, Waypoint } from '@any-routing/core';
2
+ export type SelectRouteStrategy = 'fastest' | 'shortest' | 'cheapest' | 'none';
3
+ export type RouteExcludeNoticeDefinitions = {
4
+ [key in 'critical' | 'info']?: string[] | 'all';
5
+ };
6
+ export type TurnByTurnAction = {
7
+ action: 'arrive' | 'turn' | 'depart';
8
+ duration: number;
9
+ length: number;
10
+ position: {
11
+ lat: number;
12
+ lng: number;
13
+ };
14
+ offset: number;
15
+ };
16
+ export type RoutePath = LngLatPosition[];
17
+ export interface HereRouteSummary extends RouteSummary {
18
+ turnByTurnActions: TurnByTurnAction[];
19
+ shapePath: RoutePath;
20
+ rawRoute: any;
21
+ }
22
+ export interface HereRoutingData extends AnyRoutingDataResponse {
23
+ routes: HereRouteSummary[];
24
+ }
25
+ export type Options = {
26
+ alternatives?: number;
27
+ worker?: boolean;
28
+ apiKey: string;
29
+ baseUrl?: string;
30
+ selectRouteStrategy?: SelectRouteStrategy;
31
+ spans?: string[];
32
+ return?: string[];
33
+ currency?: string;
34
+ transportMode?: string;
35
+ queryParams?: Record<string, any>;
36
+ requestParams?: RequestInit;
37
+ routeExcludeNotice?: RouteExcludeNoticeDefinitions;
38
+ shapePolylinePrecision?: number;
39
+ generateRouteName?: boolean;
40
+ buildUrl?: (ctx: {
41
+ waypoints: Waypoint[];
42
+ options: Options & RequestOptions;
43
+ }, url: string) => string;
44
+ };
45
+ export declare class HereProvider implements AnyRoutingDataProvider {
46
+ private worker?;
47
+ private executorAPI;
48
+ private options;
49
+ constructor(options: Options);
50
+ destroy(): void;
51
+ request(waypoints: any, opts: RequestOptions): Promise<HereRoutingData>;
52
+ abortAllRequests(): void;
53
+ setOption<T extends keyof Options>(optionKey: T, value: Options[T]): void;
54
+ hasPendingRequests(): Promise<boolean>;
55
+ private buildUrl;
56
+ private serializeWaypoints;
57
+ private formatWp;
58
+ }
@@ -0,0 +1,84 @@
1
+ import { __awaiter } from "tslib";
2
+ import { wrap } from 'comlink';
3
+ import { HereExecutor } from './here.executor';
4
+ const defaultOptions = {
5
+ baseUrl: 'https://router.hereapi.com/v8/routes',
6
+ transportMode: 'car',
7
+ worker: true,
8
+ alternatives: 2,
9
+ shapePolylinePrecision: 0.0000065,
10
+ generateRouteName: false,
11
+ routeExcludeNotice: {
12
+ critical: 'all',
13
+ },
14
+ };
15
+ export class HereProvider {
16
+ constructor(options) {
17
+ this.options = Object.assign(Object.assign({}, defaultOptions), options);
18
+ if (this.options.worker === true) {
19
+ this.worker = new Worker(new URL('./here.worker', import.meta.url), {
20
+ type: 'module',
21
+ });
22
+ // @ts-ignore
23
+ this.executorAPI = wrap(this.worker);
24
+ }
25
+ else {
26
+ this.executorAPI = new HereExecutor();
27
+ }
28
+ }
29
+ destroy() {
30
+ if (this.worker) {
31
+ this.worker.terminate();
32
+ }
33
+ }
34
+ request(waypoints, opts) {
35
+ const url = this.buildUrl(waypoints, Object.assign(Object.assign({}, this.options), opts));
36
+ return this.executorAPI.request(Object.assign(Object.assign({ url }, this.options), opts));
37
+ }
38
+ abortAllRequests() {
39
+ return this.executorAPI.abortAllRequests();
40
+ }
41
+ setOption(optionKey, value) {
42
+ this.options[optionKey] = value;
43
+ }
44
+ hasPendingRequests() {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ return this.executorAPI.hasPendingRequests();
47
+ });
48
+ }
49
+ buildUrl(waypoints, opts) {
50
+ var _a;
51
+ const start = waypoints[0].position;
52
+ const end = waypoints[waypoints.length - 1].position;
53
+ const spans = this.options.spans ? this.options.spans.join(',') : null;
54
+ const Return = opts.mode === 'drag'
55
+ ? 'polyline,summary'
56
+ : [...(this.options.return || []), 'polyline', 'summary', 'routeLabels'].join(',');
57
+ const qpObj = Object.assign({ apiKey: this.options.apiKey, origin: this.formatWp(start), destination: this.formatWp(end), transportMode: this.options.transportMode || '', spans, return: Return, alternatives: opts.mode === 'default' ? (_a = opts === null || opts === void 0 ? void 0 : opts.alternatives) !== null && _a !== void 0 ? _a : 0 : 0, currency: this.options.currency || undefined }, this.options.queryParams);
58
+ if (this.options.selectRouteStrategy === 'cheapest' && !qpObj.return.includes('tolls')) {
59
+ qpObj.return += ',tolls';
60
+ }
61
+ const queryParams = Object.keys(qpObj).reduce((acc, key) => {
62
+ if (qpObj[key]) {
63
+ acc[key] = qpObj[key];
64
+ }
65
+ return acc;
66
+ }, {});
67
+ let qp = new URLSearchParams(queryParams).toString();
68
+ if (waypoints.length > 2) {
69
+ qp += `&${this.serializeWaypoints(waypoints)}`;
70
+ }
71
+ const url = `${this.options.baseUrl}?${qp}`;
72
+ return this.options.buildUrl ? this.options.buildUrl({ waypoints, options: opts }, url) : url;
73
+ }
74
+ serializeWaypoints(waypoints) {
75
+ return waypoints
76
+ .slice(1, waypoints.length - 1)
77
+ .map((w) => `via=${this.formatWp(w.position)}`)
78
+ .join('&');
79
+ }
80
+ formatWp({ lat, lng }) {
81
+ return `${lat},${lng}`;
82
+ }
83
+ }
84
+ //# sourceMappingURL=here-data-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"here-data-provider.js","sourceRoot":"","sources":["../../../../../packages/here-data-provider/src/lib/here-data-provider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAwD/C,MAAM,cAAc,GAAqB;IACvC,OAAO,EAAE,sCAAsC;IAC/C,aAAa,EAAE,KAAK;IACpB,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,CAAC;IACf,sBAAsB,EAAE,SAAS;IACjC,iBAAiB,EAAE,KAAK;IACxB,kBAAkB,EAAE;QAClB,QAAQ,EAAE,KAAK;KAChB;CACF,CAAC;AAEF,MAAM,OAAO,YAAY;IAKvB,YAAY,OAAgB;QAC1B,IAAI,CAAC,OAAO,mCAAQ,cAAc,GAAK,OAAO,CAAE,CAAC;QAEjD,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,IAAI,EAAE;YAChC,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,eAAe,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBAClE,IAAI,EAAE,QAAQ;aACf,CAAC,CAAC;YAEH,aAAa;YACb,IAAI,CAAC,WAAW,GAAG,IAAI,CAAe,IAAI,CAAC,MAAM,CAAC,CAAC;SACpD;aAAM;YACL,IAAI,CAAC,WAA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AAI,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC;SAChD;QAED,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;QAE5C,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAChG,CAAC;IAEO,kBAAkB,CAAC,SAA6B;QACtD,OAAO,SAAS;aACb,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;aAC9B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;aAC9C,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IAEO,QAAQ,CAAC,EAAE,GAAG,EAAE,GAAG,EAAoB;QAC7C,OAAO,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,12 @@
1
+ import { HereRoutingData, Options } from '..';
2
+ import { Mode } from '@any-routing/core';
3
+ export declare class HereExecutor {
4
+ private readonly requester;
5
+ request(opts: {
6
+ url: string;
7
+ mode: Mode;
8
+ } & Options): Promise<HereRoutingData>;
9
+ hasPendingRequests(): boolean;
10
+ abortAllRequests(): void;
11
+ }
12
+ export declare function posIsDiff(posA: any, posB: any): boolean;
@@ -0,0 +1,152 @@
1
+ import { __awaiter } from "tslib";
2
+ import { decode } from '@liberty-rider/flexpolyline';
3
+ import * as simplify from 'simplify-js';
4
+ import bbox from '@turf/bbox';
5
+ import { featureCollection, lineString } from '@turf/helpers';
6
+ import { Requester, UnauthorizedError } from '@any-routing/core';
7
+ import { selectRouteByStrategy } from './utils/select-route-strategy';
8
+ export class HereExecutor {
9
+ constructor() {
10
+ this.requester = new Requester();
11
+ }
12
+ request(opts) {
13
+ return __awaiter(this, void 0, void 0, function* () {
14
+ try {
15
+ const data = yield this.requester.request(opts.url, Object.assign({ method: 'POST', headers: {
16
+ Accept: 'application/json',
17
+ 'Content-Type': 'application/json',
18
+ }, body: JSON.stringify({}) }, opts.requestParams));
19
+ if (!data.routes ||
20
+ data.routes.length === 0 ||
21
+ (opts.routeExcludeNotice && violatedResponseNotices(data, opts.routeExcludeNotice))) {
22
+ throw new Error('No routes found');
23
+ }
24
+ const routesSummary = data.routes.map((route, index) => summaryRoutes(route, index, opts.shapePolylinePrecision));
25
+ const selectedRouteId = selectRouteByStrategy(routesSummary, opts.selectRouteStrategy);
26
+ const features = routesSummary.reduce((acc, c) => {
27
+ return [
28
+ ...acc,
29
+ ...c.shape.features.map((f) => (Object.assign(Object.assign({}, f), { properties: Object.assign(Object.assign({}, f.properties), { selected: selectedRouteId === f.properties.routeId }) }))),
30
+ ];
31
+ }, []);
32
+ const FC = featureCollection(features);
33
+ return {
34
+ routesShapeBounds: bbox(FC),
35
+ rawResponse: data,
36
+ routes: routesSummary,
37
+ selectedRouteId,
38
+ routesShapeGeojson: FC,
39
+ version: performance.now(),
40
+ latest: !this.requester.hasPendingRequests,
41
+ mode: opts.mode,
42
+ };
43
+ }
44
+ catch (error) {
45
+ if (error instanceof Response) {
46
+ const response = error;
47
+ const body = yield response.json();
48
+ if (response.status === 401) {
49
+ throw new UnauthorizedError(body);
50
+ }
51
+ }
52
+ throw error;
53
+ }
54
+ });
55
+ }
56
+ hasPendingRequests() {
57
+ return this.requester.hasPendingRequests;
58
+ }
59
+ abortAllRequests() {
60
+ this.requester.abortAllRequests();
61
+ }
62
+ }
63
+ const summaryRoutes = (route, routeId, precision) => {
64
+ const { distance, cost, durationTime, waypoints, path, shape, shapePath, turnByTurnActions } = route.sections.reduce((acc, section, index) => {
65
+ var _a, _b, _c;
66
+ const cost = (section.tolls || []).reduce((costAcc, toll) => (toll.fares || []).forEach((fare) => (costAcc += (fare.convertedPrice || fare.price).value)), 0);
67
+ const durationTime = ((_a = section.summary) === null || _a === void 0 ? void 0 : _a.duration) || 0;
68
+ const waypoints = [];
69
+ if (section.departure.place.originalLocation) {
70
+ //@ts-ignore
71
+ waypoints.push(section.departure.place.location);
72
+ }
73
+ // Push departure location
74
+ if (section.arrival.place.originalLocation &&
75
+ ((route.sections.length >= 2 && index === route.sections.length - 1) || route.sections.length === 1)) {
76
+ //@ts-ignore
77
+ waypoints.push(section.arrival.place.location);
78
+ }
79
+ const path = decodePolyline(section.polyline);
80
+ const shapePath = simplifyPath(path, precision);
81
+ const turnByTurnActions = (section.turnByTurnActions || []).map((action) => {
82
+ const [lat, lng] = path[action.offset];
83
+ return Object.assign(Object.assign({}, action), { position: { lat, lng } });
84
+ });
85
+ const shape = lineString(shapePath, {
86
+ waypoint: acc.waypointIndex,
87
+ routeId,
88
+ });
89
+ return {
90
+ distance: acc.distance + ((_b = section.summary) === null || _b === void 0 ? void 0 : _b.length) || 0,
91
+ durationTime: acc.durationTime + durationTime,
92
+ cost: acc.cost + cost,
93
+ waypoints: [...acc.waypoints, ...waypoints],
94
+ path: [...acc.path, ...path],
95
+ turnByTurnActions,
96
+ shape: featureCollection([...(((_c = acc.shape) === null || _c === void 0 ? void 0 : _c.features) || []), shape]),
97
+ shapePath: [...acc.shapePath, ...shapePath],
98
+ waypointIndex: section.type === 'vehicle' && route.sections[index + 1] && route.sections[index + 1].type === 'vehicle'
99
+ ? acc.waypointIndex + 1
100
+ : acc.waypointIndex,
101
+ };
102
+ }, {
103
+ distance: 0,
104
+ cost: 0,
105
+ waypoints: [],
106
+ path: [],
107
+ durationTime: 0,
108
+ turnByTurnActions: [],
109
+ shape: null,
110
+ shapePath: [],
111
+ waypointIndex: 0,
112
+ });
113
+ return {
114
+ durationTime,
115
+ distance,
116
+ cost,
117
+ path,
118
+ arriveTime: new Date(route.sections[route.sections.length - 1].arrival.time),
119
+ departureTime: new Date(route.sections[0].departure.time),
120
+ id: routeId,
121
+ waypoints,
122
+ label: route.routeLabels ? route.routeLabels.map((l) => l.name.value).join(', ') : undefined,
123
+ shape,
124
+ turnByTurnActions,
125
+ shapePath,
126
+ rawRoute: route,
127
+ };
128
+ };
129
+ const violatedResponseNotices = (data, routeExcludeNotice) => {
130
+ if (violatedNotices(data.notices || [], routeExcludeNotice)) {
131
+ return true;
132
+ }
133
+ return (data.routes || []).some((route) => (route.sections || []).some((section) => violatedNotices(section.notices || [], routeExcludeNotice)));
134
+ };
135
+ const violatedNotices = (notices, routeExcludeNotice) => {
136
+ return notices.some((notice) => {
137
+ const definition = routeExcludeNotice[notice.severity];
138
+ return definition && (definition === 'all' || definition.includes(notice.code));
139
+ });
140
+ };
141
+ export function posIsDiff(posA, posB) {
142
+ const { lat: latA, lng: lngA } = posA;
143
+ const { lat: latB, lng: lngB } = posB;
144
+ return latA.toFixed(6) !== latB.toFixed(6) || lngA.toFixed(6) !== lngB.toFixed(6);
145
+ }
146
+ function decodePolyline(polyline) {
147
+ return decode(polyline).polyline;
148
+ }
149
+ function simplifyPath(path, precision) {
150
+ return simplify(path.map(([x, y]) => ({ x, y })), precision, true).map((p) => [+p.y.toFixed(6), +p.x.toFixed(6)]);
151
+ }
152
+ //# sourceMappingURL=here.executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"here.executor.js","sourceRoot":"","sources":["../../../../../packages/here-data-provider/src/lib/here.executor.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AACrD,OAAO,KAAK,QAAQ,MAAM,aAAa,CAAC;AACxC,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAA6B,MAAM,eAAe,CAAC;AAGzF,OAAO,EAAQ,SAAS,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAA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EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { expose } from 'comlink';
2
+ import { HereExecutor } from './here.executor';
3
+ const executor = new HereExecutor();
4
+ expose(executor);
5
+ //# sourceMappingURL=here.worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"here.worker.js","sourceRoot":"","sources":["../../../../../packages/here-data-provider/src/lib/here.worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,QAAQ,GAAG,IAAI,YAAY,EAAE,CAAC;AAEpC,MAAM,CAAC,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { RouteSummary } from '@any-routing/core';
2
+ import type { SelectRouteStrategy } from '../here-data-provider';
3
+ export declare function selectRouteByStrategy(summaryRoutes: RouteSummary[], strategy?: SelectRouteStrategy): number;
@@ -0,0 +1,28 @@
1
+ export function selectRouteByStrategy(summaryRoutes, strategy) {
2
+ if (strategy === 'fastest') {
3
+ const fastest = summaryRoutes.reduce(function (prev, current) {
4
+ return (prev === null || prev === void 0 ? void 0 : prev.arriveTime.valueOf()) < (current === null || current === void 0 ? void 0 : current.arriveTime.valueOf()) ? prev : current;
5
+ });
6
+ return fastest === null || fastest === void 0 ? void 0 : fastest.id;
7
+ }
8
+ else if (strategy === 'shortest') {
9
+ const shortest = summaryRoutes.reduce(function (prev, current) {
10
+ return (prev === null || prev === void 0 ? void 0 : prev.distance) < (current === null || current === void 0 ? void 0 : current.distance) ? prev : current;
11
+ });
12
+ return shortest === null || shortest === void 0 ? void 0 : shortest.id;
13
+ }
14
+ else if (strategy === 'cheapest') {
15
+ const cheapest = summaryRoutes
16
+ .filter((s) => s.cost != null)
17
+ .reduce(function (prev, current) {
18
+ //@ts-ignore
19
+ return (prev === null || prev === void 0 ? void 0 : prev.cost) < (current === null || current === void 0 ? void 0 : current.cost) ? prev : current;
20
+ });
21
+ return cheapest === null || cheapest === void 0 ? void 0 : cheapest.id;
22
+ }
23
+ else if (strategy === 'none') {
24
+ return null;
25
+ }
26
+ return 0;
27
+ }
28
+ //# sourceMappingURL=select-route-strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"select-route-strategy.js","sourceRoot":"","sources":["../../../../../../packages/here-data-provider/src/lib/utils/select-route-strategy.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,qBAAqB,CAAC,aAA6B,EAAE,QAA8B;IACjG,IAAI,QAAQ,KAAK,SAAS,EAAE;QAC1B,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,OAAO;YAC1D,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,CAAC,OAAO,EAAE,KAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAC,OAAO,EAAE,CAAA,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;QACrF,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,EAAE,CAAC;KACpB;SAAM,IAAI,QAAQ,KAAK,UAAU,EAAE;QAClC,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,OAAO;YAC3D,OAAO,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,KAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,CAAA,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;QAC7D,CAAC,CAAC,CAAC;QAEH,OAAO,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,CAAC;KACrB;SAAM,IAAI,QAAQ,KAA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