@any-routing/core 0.0.1 → 1.0.0-rc.1

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.
Files changed (45) hide show
  1. package/README.md +5 -1
  2. package/eslint.config.mjs +24 -0
  3. package/package.json +7 -28
  4. package/project.json +21 -0
  5. package/src/index.ts +4 -0
  6. package/src/lib/core.model.ts +209 -0
  7. package/src/lib/core.ts +572 -0
  8. package/src/lib/data-providers/errors/unauthorized.ts +6 -0
  9. package/src/lib/data-providers/index.ts +39 -0
  10. package/src/lib/utils/dispatcher.ts +37 -0
  11. package/src/lib/utils/{random.js → random.ts} +0 -1
  12. package/src/lib/utils/requester.ts +41 -0
  13. package/tsconfig.json +23 -0
  14. package/tsconfig.lib.json +28 -0
  15. package/tsconfig.spec.json +28 -0
  16. package/vite.config.mts +59 -0
  17. package/src/index.d.ts +0 -4
  18. package/src/index.js +0 -5
  19. package/src/index.js.map +0 -1
  20. package/src/lib/data-providers/errors/index.js +0 -2
  21. package/src/lib/data-providers/errors/index.js.map +0 -1
  22. package/src/lib/data-providers/errors/unauthorized.d.ts +0 -6
  23. package/src/lib/data-providers/errors/unauthorized.js +0 -8
  24. package/src/lib/data-providers/errors/unauthorized.js.map +0 -1
  25. package/src/lib/data-providers/index.d.ts +0 -44
  26. package/src/lib/data-providers/index.js +0 -2
  27. package/src/lib/data-providers/index.js.map +0 -1
  28. package/src/lib/libre-routing.d.ts +0 -41
  29. package/src/lib/libre-routing.js +0 -208
  30. package/src/lib/libre-routing.js.map +0 -1
  31. package/src/lib/libre-routing.model.d.ts +0 -103
  32. package/src/lib/libre-routing.model.js +0 -27
  33. package/src/lib/libre-routing.model.js.map +0 -1
  34. package/src/lib/utils/dispatcher.d.ts +0 -7
  35. package/src/lib/utils/dispatcher.js +0 -25
  36. package/src/lib/utils/dispatcher.js.map +0 -1
  37. package/src/lib/utils/index.js +0 -4
  38. package/src/lib/utils/index.js.map +0 -1
  39. package/src/lib/utils/random.d.ts +0 -1
  40. package/src/lib/utils/random.js.map +0 -1
  41. package/src/lib/utils/requester.d.ts +0 -11
  42. package/src/lib/utils/requester.js +0 -44
  43. package/src/lib/utils/requester.js.map +0 -1
  44. /package/src/lib/data-providers/errors/{index.d.ts → index.ts} +0 -0
  45. /package/src/lib/utils/{index.d.ts → index.ts} +0 -0
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs",
5
+ "forceConsistentCasingInFileNames": true,
6
+ "strict": true,
7
+ "importHelpers": true,
8
+ "noImplicitOverride": true,
9
+ "noImplicitReturns": true,
10
+ "noFallthroughCasesInSwitch": true,
11
+ "noPropertyAccessFromIndexSignature": true
12
+ },
13
+ "files": [],
14
+ "include": [],
15
+ "references": [
16
+ {
17
+ "path": "./tsconfig.lib.json"
18
+ },
19
+ {
20
+ "path": "./tsconfig.spec.json"
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "declaration": true,
6
+ "types": [
7
+ "node",
8
+ "vite/client"
9
+ ]
10
+ },
11
+ "include": [
12
+ "src/**/*.ts"
13
+ ],
14
+ "exclude": [
15
+ "vite.config.ts",
16
+ "vite.config.mts",
17
+ "vitest.config.ts",
18
+ "vitest.config.mts",
19
+ "src/**/*.test.ts",
20
+ "src/**/*.spec.ts",
21
+ "src/**/*.test.tsx",
22
+ "src/**/*.spec.tsx",
23
+ "src/**/*.test.js",
24
+ "src/**/*.spec.js",
25
+ "src/**/*.test.jsx",
26
+ "src/**/*.spec.jsx"
27
+ ]
28
+ }
@@ -0,0 +1,28 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "types": [
6
+ "vitest/globals",
7
+ "vitest/importMeta",
8
+ "vite/client",
9
+ "node",
10
+ "vitest"
11
+ ]
12
+ },
13
+ "include": [
14
+ "vite.config.ts",
15
+ "vite.config.mts",
16
+ "vitest.config.ts",
17
+ "vitest.config.mts",
18
+ "src/**/*.test.ts",
19
+ "src/**/*.spec.ts",
20
+ "src/**/*.test.tsx",
21
+ "src/**/*.spec.tsx",
22
+ "src/**/*.test.js",
23
+ "src/**/*.spec.js",
24
+ "src/**/*.test.jsx",
25
+ "src/**/*.spec.jsx",
26
+ "src/**/*.d.ts"
27
+ ]
28
+ }
@@ -0,0 +1,59 @@
1
+ /// <reference types='vitest' />
2
+ import { defineConfig } from 'vite';
3
+ import dts from 'vite-plugin-dts';
4
+ import * as path from 'path';
5
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
6
+ import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
7
+
8
+ export default defineConfig(() => ({
9
+ root: import.meta.dirname,
10
+ cacheDir: '../../node_modules/.vite/libs/core',
11
+ plugins: [
12
+ nxViteTsPaths(),
13
+ nxCopyAssetsPlugin(['*.md']),
14
+ dts({
15
+ entryRoot: 'src',
16
+ tsconfigPath: path.join(import.meta.dirname, 'tsconfig.lib.json'),
17
+ pathsToAliases: false,
18
+ }),
19
+ ],
20
+ // Uncomment this if you are using workers.
21
+ // worker: {
22
+ // plugins: () => [ nxViteTsPaths() ],
23
+ // },
24
+ // Configuration for building your library.
25
+ // See: https://vite.dev/guide/build.html#library-mode
26
+ build: {
27
+ outDir: '../../dist/libs/core',
28
+ emptyOutDir: true,
29
+ reportCompressedSize: true,
30
+ commonjsOptions: {
31
+ transformMixedEsModules: true,
32
+ },
33
+ lib: {
34
+ // Could also be a dictionary or array of multiple entry points.
35
+ entry: 'src/index.ts',
36
+ name: 'here-data-providerx',
37
+ fileName: 'index',
38
+ // Change this to the formats you want to support.
39
+ // Don't forget to update your package.json as well.
40
+ formats: ['es' as const],
41
+ },
42
+ rolldownOptions: {
43
+ // External packages that should not be bundled into your library.
44
+ external: [],
45
+ },
46
+ },
47
+ test: {
48
+ name: 'here-data-providerx',
49
+ watch: false,
50
+ globals: true,
51
+ environment: 'node',
52
+ include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
53
+ reporters: ['default'],
54
+ coverage: {
55
+ reportsDirectory: '../coverage/apps/playground/libs/core',
56
+ provider: 'v8' as const,
57
+ },
58
+ },
59
+ }));
package/src/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './lib/libre-routing';
2
- export * from './lib/data-providers';
3
- export * from './lib/libre-routing.model';
4
- export * from './lib/utils';
package/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- export * from './lib/libre-routing';
2
- export * from './lib/data-providers';
3
- export * from './lib/libre-routing.model';
4
- export * from './lib/utils';
5
- //# sourceMappingURL=index.js.map
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/core/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './unauthorized';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/data-providers/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare class UnauthorizedError {
2
- readonly response: any;
3
- readonly code = 401;
4
- readonly message = "Unauthorized";
5
- constructor(response: any);
6
- }
@@ -1,8 +0,0 @@
1
- export class UnauthorizedError {
2
- constructor(response) {
3
- this.response = response;
4
- this.code = 401;
5
- this.message = 'Unauthorized';
6
- }
7
- }
8
- //# sourceMappingURL=unauthorized.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unauthorized.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/data-providers/errors/unauthorized.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,iBAAiB;IAI5B,YAA4B,QAAa;QAAb,aAAQ,GAAR,QAAQ,CAAK;QAHzB,SAAI,GAAG,GAAG,CAAC;QACX,YAAO,GAAG,cAAc,CAAC;IAEG,CAAC;CAC9C"}
@@ -1,44 +0,0 @@
1
- import type { BBox, FeatureCollection, Geometry, LineString } from '@turf/helpers';
2
- import { Waypoint, LngLatPosition, Mode } from '../libre-routing.model';
3
- export interface AnyRoutingDataProvider {
4
- request: (waypoints: Waypoint[], opts: RequestOptions) => Promise<AnyRoutingDataResponse>;
5
- destroy(): void;
6
- hasPendingRequests(): Promise<boolean>;
7
- abortAllRequests(): void;
8
- }
9
- export interface RequestOptions {
10
- mode: Mode;
11
- }
12
- export interface AnyRoutingDataResponse {
13
- rawResponse: any;
14
- routesShapeGeojson: FeatureCollection<Geometry, {
15
- routeId: number;
16
- waypoint: number;
17
- }>;
18
- routes: RouteSummary[];
19
- selectedRouteId?: number | null;
20
- routesShapeBounds?: BBox;
21
- version: number;
22
- latest: boolean;
23
- mode: Mode;
24
- }
25
- export type RoutePath = LngLatPosition[];
26
- export interface RouteSummary {
27
- id: number;
28
- label?: string;
29
- path: RoutePath;
30
- durationTime: number;
31
- arriveTime: Date;
32
- departureTime: Date;
33
- distance: number;
34
- cost?: number;
35
- waypoints: {
36
- lat: number;
37
- lng: number;
38
- }[];
39
- shape: FeatureCollection<LineString, {
40
- routeId: number;
41
- waypoint: number;
42
- }>;
43
- }
44
- export * from './errors';
@@ -1,2 +0,0 @@
1
- export * from './errors';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/data-providers/index.ts"],"names":[],"mappings":"AAyCA,cAAc,UAAU,CAAC"}
@@ -1,41 +0,0 @@
1
- import { AnyRoutingDataResponse, RouteSummary } from './data-providers';
2
- import { AnyRoutingEventsMap, AnyRoutingOptions, AnyRoutingState, Waypoint as InputWaypoint, InternalWaypoint, RecalculateOptions, Mode } from './libre-routing.model';
3
- export declare class AnyRouting<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> {
4
- private readonly dispatcher;
5
- private _options;
6
- private _plugins;
7
- private _initialState;
8
- private _state;
9
- get options(): AnyRoutingOptions;
10
- get data(): R;
11
- get state(): AnyRoutingState<R>;
12
- get dataProvider(): import("./data-providers").AnyRoutingDataProvider;
13
- get selectedRouteId(): number | undefined | null;
14
- private get waypoints();
15
- constructor(options: AnyRoutingOptions);
16
- initialize(): void;
17
- onRemove(): void;
18
- setMode(mode: Mode): void;
19
- setWaypoints(waypoints: InputWaypoint[]): void;
20
- getWaypoint(waypointId: number): InternalWaypoint;
21
- recalculateRoute(opts?: RecalculateOptions & Record<string, any>): Promise<R | undefined>;
22
- on<E extends keyof AnyRoutingEventsMap>(event: E, callback: (event: AnyRoutingEventsMap[E]) => void): void;
23
- off<E extends keyof AnyRoutingEventsMap>(event: E, callback: (event: AnyRoutingEventsMap[E]) => void): void;
24
- selectRoute(routeId: number): void;
25
- reset(): void;
26
- getUniqueName(name: string): string;
27
- syncWaypointsPositions(waypoints: RouteSummary['waypoints']): InternalWaypoint[];
28
- setState({ waypoints, data, routesShapeGeojson, selectedRouteId, }: {
29
- waypoints?: InputWaypoint[];
30
- data?: R;
31
- routesShapeGeojson?: R['routesShapeGeojson'];
32
- selectedRouteId?: number | null;
33
- }): void;
34
- private initPlugins;
35
- private detachPlugins;
36
- private resolvePlugin;
37
- private _setState;
38
- private _patchState;
39
- private transformToInternalWaypoints;
40
- private fire;
41
- }
@@ -1,208 +0,0 @@
1
- import { __awaiter } from "tslib";
2
- import { Dispatcher } from './utils/dispatcher';
3
- import { randomId } from './utils/random';
4
- import { InternalWaypointC, } from './libre-routing.model';
5
- import { featureCollection } from '@turf/helpers';
6
- export class AnyRouting {
7
- get options() {
8
- return this._options;
9
- }
10
- get data() {
11
- return this._state.data;
12
- }
13
- get state() {
14
- return this._state;
15
- }
16
- get dataProvider() {
17
- return this.options.dataProvider;
18
- }
19
- get selectedRouteId() {
20
- return this._state.selectedRouteId;
21
- }
22
- get waypoints() {
23
- return this._state.waypoints;
24
- }
25
- constructor(options) {
26
- var _a;
27
- this.dispatcher = new Dispatcher();
28
- this._plugins = [];
29
- this._initialState = {
30
- waypoints: [],
31
- data: undefined,
32
- loading: false,
33
- selectedRouteId: undefined,
34
- mode: 'default',
35
- routesShapeGeojson: undefined,
36
- };
37
- this._state = Object.assign({}, this._initialState);
38
- this._options = Object.assign({ uniqueKey: randomId() }, options);
39
- this._plugins = (_a = options.plugins) !== null && _a !== void 0 ? _a : [];
40
- }
41
- initialize() {
42
- this.initPlugins();
43
- }
44
- onRemove() {
45
- var _a;
46
- this.detachPlugins();
47
- (_a = this.options.dataProvider) === null || _a === void 0 ? void 0 : _a.destroy();
48
- }
49
- setMode(mode) {
50
- this._patchState({ mode });
51
- }
52
- setWaypoints(waypoints) {
53
- const internalWaypoints = this.transformToInternalWaypoints(waypoints);
54
- this._patchState({ waypoints: internalWaypoints });
55
- this.fire('waypointsChanged', { waypoints: this.state.waypoints });
56
- }
57
- getWaypoint(waypointId) {
58
- return this._state.waypoints[waypointId];
59
- }
60
- recalculateRoute(opts = {}) {
61
- var _a;
62
- return __awaiter(this, void 0, void 0, function* () {
63
- if (this.waypoints.length < 2)
64
- return;
65
- if (!this.options.dataProvider) {
66
- throw new Error('No data provider');
67
- }
68
- this.fire('calculationStarted', {
69
- mode: this.state.mode,
70
- waypoints: this.waypoints,
71
- recalculateOptions: opts,
72
- });
73
- if (opts.dropPendingRequests) {
74
- yield this.options.dataProvider.abortAllRequests();
75
- }
76
- let patchState = {};
77
- if (!this._state.loading) {
78
- patchState = Object.assign(Object.assign({}, patchState), { loading: true });
79
- }
80
- this._patchState(patchState);
81
- if ('loading' in patchState) {
82
- this.fire('loadingChanged', { loading: true });
83
- }
84
- try {
85
- const data = (yield this.options.dataProvider.request(this._state.waypoints, {
86
- mode: this.state.mode,
87
- }));
88
- let patchState = {
89
- data,
90
- selectedRouteId: data.selectedRouteId,
91
- routesShapeGeojson: data.routesShapeGeojson,
92
- };
93
- let waypointsUpdated = false;
94
- if (opts.syncWaypoints !== false && this.options.waypointsSyncStrategy === 'toPath') {
95
- const syncedWaypoints = this.syncWaypointsPositions(data.routes[0].waypoints);
96
- patchState = Object.assign(Object.assign({}, patchState), { waypoints: syncedWaypoints });
97
- waypointsUpdated = true;
98
- }
99
- this._patchState(patchState);
100
- this.fire('routesFound', {
101
- mode: this.state.mode,
102
- waypoints: this._state.waypoints,
103
- data,
104
- recalculateOptions: opts,
105
- });
106
- if (waypointsUpdated) {
107
- this.fire('waypointsChanged', { waypoints: this.state.waypoints });
108
- }
109
- return this._state.data;
110
- }
111
- catch (e) {
112
- this.fire('calculationError', { error: e, recalculateOptions: opts });
113
- throw e;
114
- }
115
- finally {
116
- if (this._state.loading && (((_a = this.data) === null || _a === void 0 ? void 0 : _a.latest) || !(yield this.dataProvider.hasPendingRequests()))) {
117
- this._patchState({ loading: false });
118
- this.fire('loadingChanged', { loading: false });
119
- }
120
- }
121
- });
122
- }
123
- on(event, callback) {
124
- this.dispatcher.on(event, callback);
125
- }
126
- off(event, callback) {
127
- this.dispatcher.off(event, callback);
128
- }
129
- selectRoute(routeId) {
130
- if (!this.data) {
131
- return;
132
- }
133
- const features = this.data.routesShapeGeojson.features.map((feature) => {
134
- return Object.assign(Object.assign({}, feature), { properties: Object.assign(Object.assign({}, feature.properties), { selected: feature.properties.routeId === routeId }) });
135
- });
136
- this._patchState({
137
- selectedRouteId: routeId,
138
- data: Object.assign(Object.assign({}, this._state.data), { routesShapeGeojson: featureCollection(features), selectedRouteId: routeId }),
139
- routesShapeGeojson: featureCollection(features),
140
- });
141
- this.fire('routeSelected', {
142
- route: this.data.routes[routeId],
143
- routeId: routeId,
144
- });
145
- }
146
- reset() {
147
- this._setState(Object.assign({}, this._initialState), 'external');
148
- }
149
- getUniqueName(name) {
150
- return `${name}-${this.options.uniqueKey}`;
151
- }
152
- syncWaypointsPositions(waypoints) {
153
- const newWaypoints = waypoints.map((waypoint, index) => (Object.assign(Object.assign({}, this._state.waypoints[index]), { position: this._state.waypoints[index].position, mappedPosition: waypoint, properties: this._state.waypoints[index].properties })));
154
- return newWaypoints;
155
- }
156
- setState({ waypoints, data, routesShapeGeojson, selectedRouteId, }) {
157
- let newState = Object.assign({}, this._state);
158
- if (waypoints) {
159
- const internalWaypoints = this.transformToInternalWaypoints(waypoints);
160
- newState = Object.assign(Object.assign({}, newState), { waypoints: internalWaypoints });
161
- }
162
- if (routesShapeGeojson) {
163
- newState = Object.assign(Object.assign({}, newState), { routesShapeGeojson });
164
- }
165
- if (data) {
166
- newState = Object.assign(Object.assign({}, newState), { data, routesShapeGeojson: data.routesShapeGeojson });
167
- }
168
- if (selectedRouteId != null) {
169
- newState = Object.assign(Object.assign({}, newState), { selectedRouteId });
170
- }
171
- if (data || waypoints || routesShapeGeojson || selectedRouteId != null) {
172
- this._setState(newState, 'external');
173
- }
174
- }
175
- initPlugins() {
176
- this._plugins.forEach((plugin) => this.resolvePlugin(plugin).onAdd(this));
177
- }
178
- detachPlugins() {
179
- this._plugins.forEach((plugin) => this.resolvePlugin(plugin).onRemove(this));
180
- }
181
- resolvePlugin(plugin) {
182
- if (typeof plugin === 'function') {
183
- return new plugin({});
184
- }
185
- return plugin;
186
- }
187
- _setState(newState, source = 'internal', updatedKeys) {
188
- this._state = newState;
189
- this.fire('stateUpdated', {
190
- source,
191
- updatedProperties: updatedKeys !== null && updatedKeys !== void 0 ? updatedKeys : Object.keys(this.state),
192
- });
193
- }
194
- _patchState(patchState, source = 'internal') {
195
- if (Object.keys(patchState).length === 0) {
196
- return;
197
- }
198
- this._setState(Object.assign(Object.assign({}, this._state), patchState), source, Object.keys(patchState));
199
- }
200
- transformToInternalWaypoints(waypoints) {
201
- return waypoints.map((waypoint, index) => InternalWaypointC.fromWaypoint(waypoint, { index, isFirst: index === 0, isLast: index === waypoints.length - 1 }));
202
- }
203
- fire(event, data) {
204
- //@ts-ignore
205
- this.dispatcher.fire(event, Object.assign(Object.assign({}, data), { state: this.state, eventName: event }));
206
- }
207
- }
208
- //# sourceMappingURL=libre-routing.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"libre-routing.js","sourceRoot":"","sources":["../../../../../packages/core/src/lib/libre-routing.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EASL,iBAAiB,GAGlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,OAAO,UAAU;IAiBrB,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;IACnC,CAAC;IAED,IAAW,eAAe;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;IACrC,CAAC;IAED,IAAY,SAAS;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IAED,YAAY,OAA0B;;QAxCrB,eAAU,GAAG,IAAI,UAAU,EAAuB,CAAC;QAG5D,aAAQ,GAAoB,EAAE,CAAC;QAE/B,kBAAa,GAAuB;YAC1C,SAAS,EAAE,EAAE;YACb,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,eAAe,EAAE,SAAS;YAC1B,IAAI,EAAE,SAAS;YACf,kBAAkB,EAAE,SAAS;SAC9B,CAAC;QAEM,WAA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G,CAAC;CACF"}
@@ -1,103 +0,0 @@
1
- import { AnyRoutingDataProvider, AnyRoutingDataResponse, RouteSummary } from './data-providers';
2
- import type { AnyRouting } from './libre-routing';
3
- export type LngLatPosition = [number, number];
4
- export type WaypointPosition = {
5
- lat: number;
6
- lng: number;
7
- };
8
- export type Mode = 'default' | 'drag';
9
- export type BaseEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = {
10
- state: AnyRoutingState<R>;
11
- eventName: keyof MessagePortEventMap;
12
- };
13
- export type CalculationStartedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
14
- waypoints: InternalWaypoint[];
15
- recalculateOptions: RecalculateOptions;
16
- mode: Mode;
17
- };
18
- export type CalculationErrorEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
19
- error: Error;
20
- recalculateOptions: RecalculateOptions;
21
- };
22
- export type RoutesFoundEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
23
- waypoints: InternalWaypoint[];
24
- data: R;
25
- mode: Mode;
26
- recalculateOptions: RecalculateOptions;
27
- };
28
- export type RouteSelectedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
29
- routeId: number;
30
- route: RouteSummary;
31
- };
32
- export type WaypointsChangedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
33
- waypoints: InternalWaypoint[];
34
- };
35
- export type LoadingChangedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
36
- loading: boolean;
37
- };
38
- export type StateUpdateSource = 'internal' | 'external';
39
- export type StateUpdatedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
40
- state: AnyRoutingState<R>;
41
- source: StateUpdateSource;
42
- updatedProperties: Array<keyof AnyRoutingState<R>>;
43
- };
44
- export interface AnyRoutingEventsMap {
45
- calculationStarted: CalculationStartedEvent;
46
- calculationError: CalculationErrorEvent;
47
- routesFound: RoutesFoundEvent;
48
- routeSelected: RouteSelectedEvent;
49
- waypointsChanged: WaypointsChangedEvent;
50
- loadingChanged: LoadingChangedEvent;
51
- stateUpdated: StateUpdatedEvent;
52
- }
53
- export type AnyRoutingEvents = keyof AnyRoutingEventsMap;
54
- export type InternalWaypointProperties = {
55
- index: number;
56
- isFirst: boolean;
57
- isLast: boolean;
58
- };
59
- export type AnyRoutingState<DataType = AnyRoutingDataResponse> = {
60
- data: DataType | undefined;
61
- waypoints: InternalWaypoint[];
62
- loading: boolean;
63
- selectedRouteId: number | undefined | null;
64
- mode: Mode;
65
- routesShapeGeojson?: AnyRoutingDataResponse['routesShapeGeojson'];
66
- };
67
- export interface InternalWaypoint {
68
- index: number;
69
- position: WaypointPosition;
70
- mappedPosition?: WaypointPosition;
71
- originalPosition: WaypointPosition;
72
- originalMappedPosition?: WaypointPosition;
73
- properties: InternalWaypointProperties & Record<string, any>;
74
- }
75
- export declare function isWaypointPositionEqual(posA: WaypointPosition, posB: WaypointPosition): boolean;
76
- export declare class InternalWaypointC {
77
- static isChanged(waypoint: InternalWaypoint): boolean;
78
- static isPositionChanged(waypoint: InternalWaypoint): boolean;
79
- static isMappedPositionChanged(waypoint: InternalWaypoint): boolean;
80
- static fromWaypoint(waypoint: Waypoint, props: InternalWaypointProperties): InternalWaypoint;
81
- }
82
- export interface Waypoint {
83
- position: WaypointPosition;
84
- mappedPosition?: WaypointPosition;
85
- properties?: Record<string, string | boolean | number>;
86
- }
87
- export type PluginFactory = AnyRoutingPlugin | (new (...args: any[]) => AnyRoutingPlugin);
88
- export type AnyRoutingOptions = {
89
- dataProvider: AnyRoutingDataProvider;
90
- plugins?: PluginFactory[];
91
- uniqueKey?: string;
92
- waypointsSyncStrategy: 'none' | 'toPath' | 'geocodeFirst';
93
- };
94
- export interface AnyRoutingPlugin {
95
- onAdd(AnyRouting: AnyRouting<any>): void;
96
- onRemove(AnyRouting: AnyRouting<any>): void;
97
- }
98
- export interface RecalculateOptions {
99
- fitViewToData?: boolean;
100
- clearMap?: boolean;
101
- dropPendingRequests?: boolean;
102
- syncWaypoints?: boolean;
103
- }
@@ -1,27 +0,0 @@
1
- export function isWaypointPositionEqual(posA, posB) {
2
- return posA.lat === posB.lat && posA.lng === posB.lng;
3
- }
4
- export class InternalWaypointC {
5
- static isChanged(waypoint) {
6
- return !this.isPositionChanged(waypoint) || !this.isMappedPositionChanged(waypoint);
7
- }
8
- static isPositionChanged(waypoint) {
9
- return !isWaypointPositionEqual(waypoint.originalPosition, waypoint.position);
10
- }
11
- static isMappedPositionChanged(waypoint) {
12
- return (!!waypoint.originalMappedPosition &&
13
- !!waypoint.mappedPosition &&
14
- !isWaypointPositionEqual(waypoint.originalMappedPosition, waypoint.mappedPosition));
15
- }
16
- static fromWaypoint(waypoint, props) {
17
- return {
18
- index: props.index,
19
- originalPosition: waypoint.position,
20
- position: waypoint.position,
21
- originalMappedPosition: waypoint.mappedPosition,
22
- mappedPosition: waypoint.mappedPosition,
23
- properties: Object.assign(Object.assign({}, props), (waypoint.properties || {})),
24
- };
25
- }
26
- }
27
- //# sourceMappingURL=libre-routing.model.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"libre-routing.model.js","sourceRoot":"","sources":["../../../../../packages/core/src/lib/libre-routing.model.ts"],"names":[],"mappings":"AAyFA,MAAM,UAAU,uBAAuB,CAAC,IAAsB,EAAE,IAAsB;IACpF,OAAO,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,CAAC;AACxD,CAAC;AAED,MAAM,OAAO,iBAAiB;IACrB,MAAM,CAAC,SAAS,CAAC,QAA0B;QAChD,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IACtF,CAAC;IAEM,MAAM,CAAC,iBAAiB,CAAC,QAA0B;QACxD,OAAO,CAAC,uBAAuB,CAAC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChF,CAAC;IAEM,MAAM,CAAC,uBAAuB,CAAC,QAA0B;QAC9D,OAAO,CACL,CAAC,CAAC,QAAQ,CAAC,sBAAsB;YACjC,CAAC,CAAC,QAAQ,CAAC,cAAc;YACzB,CAAC,uBAAuB,CAAC,QAAQ,CAAC,sBAAsB,EAAE,QAAQ,CAAC,cAAc,CAAC,CACnF,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,QAAkB,EAAE,KAAiC;QAC9E,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,gBAAgB,EAAE,QAAQ,CAAC,QAAQ;YACnC,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,sBAAsB,EAAE,QAAQ,CAAC,cAAc;YAC/C,cAAc,EAAE,QAAQ,CAAC,cAAc;YACvC,UAAU,kCAAO,KAAK,GAAK,CAAC,QAAQ,CAAC,UAAU,IAAI,EAAE,CAAC,CAAE;SACzD,CAAC;IACJ,CAAC;CACF"}
@@ -1,7 +0,0 @@
1
- export declare class Dispatcher<EventMap extends object> {
2
- private callbacks;
3
- fire<E extends keyof EventMap>(event: E, data: EventMap[E]): void;
4
- on<E extends keyof EventMap>(event: E, callback: (event: EventMap[E]) => void): void;
5
- off<E extends keyof EventMap>(event: E, callback: (event: EventMap[E]) => void): void;
6
- private getEventCallbacks;
7
- }