trackswap 0.0.14 → 0.0.15
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 +32 -32
- package/dist/FIT/encoder.d.ts +2 -2
- package/dist/FIT/types/sport.d.ts +1 -1
- package/dist/FIT/types.d.ts +1 -1
- package/dist/TCX/converters.d.ts +3 -3
- package/dist/TCX/encoder.d.ts +3 -3
- package/dist/TCX/types.d.ts +8 -8
- package/dist/TrackSwap.d.ts +12 -12
- package/dist/index.cjs +10 -10
- package/dist/index.js +16 -16
- package/dist/types.d.ts +103 -84
- package/package.json +1 -1
- package/dist/sport/base.d.ts +0 -64
- package/dist/sport/converters.d.ts +0 -34
- package/dist/sport/encoders.d.ts +0 -34
- package/dist/sport/index.d.ts +0 -17
- package/dist/sport/processor.d.ts +0 -19
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ const convertedBuffer = await trackSwap.convertFile(
|
|
|
69
69
|
const parsedData = await trackSwap.parseFile(buffer);
|
|
70
70
|
|
|
71
71
|
// 🏃♂️ 解析并转换为统一的运动数据格式
|
|
72
|
-
const sportData = await trackSwap.
|
|
72
|
+
const sportData = await trackSwap.parseToActivity(buffer);
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
## 📖 详细使用指南
|
|
@@ -140,14 +140,14 @@ const result = await trackSwap.convertFile(sourceBuffer, 'fit', 'gpx');
|
|
|
140
140
|
|
|
141
141
|
```typescript
|
|
142
142
|
// 转换为统一的运动数据格式
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
143
|
+
const gpxActivity = await trackSwap.convertGPXToActivity(gpxData);
|
|
144
|
+
const fitActivity = await trackSwap.convertFITToActivity(fitData);
|
|
145
|
+
const tcxActivity = await trackSwap.convertTCXToActivity(tcxData);
|
|
146
146
|
|
|
147
147
|
// 从统一格式转换回具体格式
|
|
148
|
-
const gpxData = await trackSwap.
|
|
149
|
-
const fitData = await trackSwap.
|
|
150
|
-
const tcxData = await trackSwap.
|
|
148
|
+
const gpxData = await trackSwap.convertActivityToGPX(sportData);
|
|
149
|
+
const fitData = await trackSwap.convertActivityToFIT(sportData);
|
|
150
|
+
const tcxData = await trackSwap.convertActivityToTCX(sportData);
|
|
151
151
|
```
|
|
152
152
|
|
|
153
153
|
### 3. 智能解析
|
|
@@ -162,8 +162,8 @@ const parsedData = await trackSwap.parseFile(buffer);
|
|
|
162
162
|
const parsedData = await trackSwap.parseFile(buffer, 'gpx'); // 指定格式
|
|
163
163
|
|
|
164
164
|
// 🏃♂️ 解析为统一格式
|
|
165
|
-
const sportData = await trackSwap.
|
|
166
|
-
const sportData = await trackSwap.
|
|
165
|
+
const sportData = await trackSwap.parseToActivity(buffer);
|
|
166
|
+
const sportData = await trackSwap.parseToActivity(buffer, 'fit'); // 指定格式
|
|
167
167
|
```
|
|
168
168
|
|
|
169
169
|
## 🔧 API 参考
|
|
@@ -180,7 +180,7 @@ const sportData = await trackSwap.parseToSport(buffer, 'fit'); // 指定格式
|
|
|
180
180
|
| `parseTCX(buffer)` | 解析 TCX Buffer | `Buffer` | `Promise<TCXFileType>` |
|
|
181
181
|
| `parseTCXString(xml)` | 解析 TCX 字符串 | `string` | `Promise<TCXFileType>` |
|
|
182
182
|
| `parseFile(buffer, type?)` | 统一解析方法 | `Buffer, string?` | `Promise<GPX11Type \| FITFileType \| TCXFileType>` |
|
|
183
|
-
| `
|
|
183
|
+
| `parseToActivity(buffer, type?)` | 解析为统一格式 | `Buffer, string?` | `Promise<ActivityType>` |
|
|
184
184
|
|
|
185
185
|
#### 编码方法
|
|
186
186
|
|
|
@@ -198,19 +198,19 @@ const sportData = await trackSwap.parseToSport(buffer, 'fit'); // 指定格式
|
|
|
198
198
|
| 方法 | 说明 | 参数 | 返回值 |
|
|
199
199
|
|------|------|------|--------|
|
|
200
200
|
| `convertFile(buffer, target, source?)` | 统一转换方法 | `Buffer, string, string?` | `Promise<Buffer>` |
|
|
201
|
-
| `
|
|
202
|
-
| `
|
|
203
|
-
| `
|
|
204
|
-
| `
|
|
205
|
-
| `
|
|
206
|
-
| `
|
|
201
|
+
| `convertGPXToActivity(data)` | GPX → Activity | `GPX11Type` | `Promise<ActivityType>` |
|
|
202
|
+
| `convertFITToActivity(data)` | FIT → Activity | `FITFileType` | `Promise<ActivityType>` |
|
|
203
|
+
| `convertTCXToActivity(data)` | TCX → Activity | `TCXFileType` | `Promise<ActivityType>` |
|
|
204
|
+
| `convertActivityToGPX(data)` | Activity → GPX | `ActivityType` | `Promise<GPX11Type>` |
|
|
205
|
+
| `convertActivityToFIT(data)` | Activity → FIT | `ActivityType` | `Promise<FITFileType>` |
|
|
206
|
+
| `convertActivityToTCX(data)` | Activity → TCX | `ActivityType` | `Promise<TCXFileType>` |
|
|
207
207
|
|
|
208
208
|
#### 工具方法
|
|
209
209
|
|
|
210
210
|
| 方法 | 说明 | 参数 | 返回值 |
|
|
211
211
|
|------|------|------|--------|
|
|
212
212
|
| `detectFormat(buffer)` | 检测文件格式 | `Buffer` | `'gpx' \| 'fit' \| 'tcx' \| 'unknown'` |
|
|
213
|
-
| `
|
|
213
|
+
| `getActivityProcessor()` | 获取运动处理器 | - | `ActivityProcessor` |
|
|
214
214
|
| `destroy()` | 清理资源 | - | `Promise<void>` |
|
|
215
215
|
|
|
216
216
|
## 🌟 实际应用示例
|
|
@@ -262,7 +262,7 @@ async function analyzeTrack(buffer: Buffer) {
|
|
|
262
262
|
console.log(`文件格式: ${format}`);
|
|
263
263
|
|
|
264
264
|
// 📊 转换为统一格式进行分析
|
|
265
|
-
const sportData = await trackSwap.
|
|
265
|
+
const sportData = await trackSwap.parseToActivity(buffer);
|
|
266
266
|
|
|
267
267
|
// 分析数据
|
|
268
268
|
const analysis = {
|
|
@@ -285,27 +285,27 @@ async function analyzeTrack(buffer: Buffer) {
|
|
|
285
285
|
```typescript
|
|
286
286
|
async function mergeMultiFormatTracks(files: { buffer: Buffer, name: string }[]) {
|
|
287
287
|
const trackSwap = new TrackSwap();
|
|
288
|
-
const
|
|
288
|
+
const allActivityData: ActivityType[] = [];
|
|
289
289
|
|
|
290
290
|
// 🔄 将所有格式转换为统一格式
|
|
291
291
|
for (const file of files) {
|
|
292
292
|
try {
|
|
293
|
-
const sportData = await trackSwap.
|
|
293
|
+
const sportData = await trackSwap.parseToActivity(file.buffer);
|
|
294
294
|
sportData.metadata = { ...sportData.metadata, originalFile: file.name };
|
|
295
|
-
|
|
295
|
+
allActivityData.push(sportData);
|
|
296
296
|
} catch (error) {
|
|
297
297
|
console.error(`解析失败: ${file.name}`, error);
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
// 融合数据逻辑
|
|
302
|
-
const mergedData =
|
|
302
|
+
const mergedData = mergeActivityData(allActivityData);
|
|
303
303
|
|
|
304
304
|
// 输出为不同格式
|
|
305
305
|
const results = {
|
|
306
|
-
gpx: await trackSwap.
|
|
307
|
-
fit: await trackSwap.
|
|
308
|
-
tcx: await trackSwap.
|
|
306
|
+
gpx: await trackSwap.convertActivityToGPX(mergedData),
|
|
307
|
+
fit: await trackSwap.convertActivityToFIT(mergedData),
|
|
308
|
+
tcx: await trackSwap.convertActivityToTCX(mergedData)
|
|
309
309
|
};
|
|
310
310
|
|
|
311
311
|
await trackSwap.destroy();
|
|
@@ -327,17 +327,17 @@ TrackSwap 采用模块化架构,核心组件包括:
|
|
|
327
327
|
│ │ • GPXDecoder/Encoder - GPX 文件处理 │ │
|
|
328
328
|
│ │ • FITDecoder/Encoder - FIT 文件处理 │ │
|
|
329
329
|
│ │ • TCXDecoder/Encoder - TCX 文件处理 │ │
|
|
330
|
-
│ │ •
|
|
330
|
+
│ │ • ActivityProcessor - 统一格式转换处理 │ │
|
|
331
331
|
│ └─────────────────────────────────────────────────────────┘ │
|
|
332
332
|
│ │
|
|
333
333
|
│ 🔄 转换引擎 │
|
|
334
334
|
│ ┌─────────────────────────────────────────────────────────┐ │
|
|
335
|
-
│ │ •
|
|
336
|
-
│ │ •
|
|
337
|
-
│ │ •
|
|
338
|
-
│ │ •
|
|
339
|
-
│ │ •
|
|
340
|
-
│ │ •
|
|
335
|
+
│ │ • GPXToActivityConverter - GPX → ActivityType │ │
|
|
336
|
+
│ │ • FITToActivityConverter - FIT → ActivityType │ │
|
|
337
|
+
│ │ • TCXToActivityConverter - TCX → ActivityType │ │
|
|
338
|
+
│ │ • ActivityToGPXEncoder - ActivityType → GPX │ │
|
|
339
|
+
│ │ • ActivityToFITEncoder - ActivityType → FIT │ │
|
|
340
|
+
│ │ • ActivityToTCXEncoder - ActivityType → TCX │ │
|
|
341
341
|
│ └─────────────────────────────────────────────────────────┘ │
|
|
342
342
|
│ │
|
|
343
343
|
│ 🎯 统一接口 │
|
package/dist/FIT/encoder.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FITFileType } from "./types.js";
|
|
2
2
|
export interface FITEncoderOptions {
|
|
3
3
|
compact?: boolean;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
defaultActivity?: string;
|
|
5
|
+
defaultSubActivity?: string;
|
|
6
6
|
}
|
|
7
7
|
export declare class FITEncoder {
|
|
8
8
|
private localNum;
|
package/dist/FIT/types.d.ts
CHANGED
package/dist/TCX/converters.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TokenAST } from "../types.js";
|
|
2
2
|
import { BaseTCXConverter } from "./base.js";
|
|
3
|
-
import { TCXContext, ActivityType, ActivityLapType, TrackType, TrackpointType, PositionType, ActivityListType,
|
|
3
|
+
import { TCXContext, ActivityType, ActivityLapType, TrackType, TrackpointType, PositionType, ActivityListType, MultiActivitySessionType, AbstractSourceType } from "./types.js";
|
|
4
4
|
export declare class PositionConverter extends BaseTCXConverter {
|
|
5
5
|
name: string;
|
|
6
6
|
supportedTags: string[];
|
|
@@ -33,10 +33,10 @@ export declare class ActivityListConverter extends BaseTCXConverter {
|
|
|
33
33
|
supportedTags: string[];
|
|
34
34
|
convert(ast: TokenAST, context: TCXContext): ActivityListType | undefined;
|
|
35
35
|
}
|
|
36
|
-
export declare class
|
|
36
|
+
export declare class MultiActivitySessionConverter extends BaseTCXConverter {
|
|
37
37
|
name: string;
|
|
38
38
|
supportedTags: string[];
|
|
39
|
-
convert(ast: TokenAST, context: TCXContext):
|
|
39
|
+
convert(ast: TokenAST, context: TCXContext): MultiActivitySessionType | undefined;
|
|
40
40
|
}
|
|
41
41
|
export declare class AbstractSourceConverter extends BaseTCXConverter {
|
|
42
42
|
name: string;
|
package/dist/TCX/encoder.d.ts
CHANGED
|
@@ -20,9 +20,9 @@ export declare class TCXEncoder {
|
|
|
20
20
|
private buildTrackpoint;
|
|
21
21
|
private buildPosition;
|
|
22
22
|
private buildCadence;
|
|
23
|
-
private
|
|
24
|
-
private
|
|
25
|
-
private
|
|
23
|
+
private buildMultiActivitySession;
|
|
24
|
+
private buildFirstActivity;
|
|
25
|
+
private buildNextActivity;
|
|
26
26
|
private buildWorkouts;
|
|
27
27
|
private buildCourses;
|
|
28
28
|
private buildAuthor;
|
package/dist/TCX/types.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export interface HistoryType {
|
|
|
75
75
|
Running?: HistoryFolderType;
|
|
76
76
|
Biking?: HistoryFolderType;
|
|
77
77
|
Other?: HistoryFolderType;
|
|
78
|
-
|
|
78
|
+
MultiActivity?: HistoryFolderType;
|
|
79
79
|
Extensions?: ExtensionsType;
|
|
80
80
|
}
|
|
81
81
|
export interface HistoryFolderType {
|
|
@@ -94,10 +94,10 @@ export interface WeekType {
|
|
|
94
94
|
}
|
|
95
95
|
export interface ActivityListType {
|
|
96
96
|
Activity?: ActivityType[];
|
|
97
|
-
|
|
97
|
+
MultiActivitySession?: MultiActivitySessionType[];
|
|
98
98
|
}
|
|
99
99
|
export interface ActivityType {
|
|
100
|
-
|
|
100
|
+
Activity?: "Other" | "Running" | "Biking";
|
|
101
101
|
Id: string;
|
|
102
102
|
Lap: ActivityLapType[];
|
|
103
103
|
Notes?: string;
|
|
@@ -144,16 +144,16 @@ export interface CadenceType {
|
|
|
144
144
|
export interface HeartRateInBeatsPerMinuteType {
|
|
145
145
|
Value: number;
|
|
146
146
|
}
|
|
147
|
-
export interface
|
|
147
|
+
export interface MultiActivitySessionType {
|
|
148
148
|
Id?: string;
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
FirstActivity?: FirstActivityType;
|
|
150
|
+
NextActivity?: NextActivityType[];
|
|
151
151
|
Notes?: string;
|
|
152
152
|
}
|
|
153
|
-
export interface
|
|
153
|
+
export interface FirstActivityType {
|
|
154
154
|
Activity?: ActivityType;
|
|
155
155
|
}
|
|
156
|
-
export interface
|
|
156
|
+
export interface NextActivityType {
|
|
157
157
|
Transition?: ActivityLapType;
|
|
158
158
|
Activity?: ActivityType;
|
|
159
159
|
}
|
package/dist/TrackSwap.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { FITDecoder, FITEncoder } from "./FIT/index.js";
|
|
|
4
4
|
import { FITFileType } from "./FIT/types.js";
|
|
5
5
|
import { TCXDecoder, TCXEncoder } from "./TCX/index.js";
|
|
6
6
|
import { TCXFileType } from "./TCX/types.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { ActivityProcessor } from "./activity/processor.js";
|
|
8
|
+
import { FileType } from "./types.js";
|
|
9
9
|
export declare class TrackSwap {
|
|
10
10
|
private gpxDecoder;
|
|
11
11
|
private gpxEncoder;
|
|
@@ -13,7 +13,7 @@ export declare class TrackSwap {
|
|
|
13
13
|
private fitEncoder;
|
|
14
14
|
private tcxDecoder;
|
|
15
15
|
private tcxEncoder;
|
|
16
|
-
private
|
|
16
|
+
private activityProcessor;
|
|
17
17
|
constructor();
|
|
18
18
|
parseGPX(buffer: Buffer): Promise<GPX11Type | undefined>;
|
|
19
19
|
parseGPXString(xmlString: string): Promise<GPX11Type | undefined>;
|
|
@@ -22,21 +22,21 @@ export declare class TrackSwap {
|
|
|
22
22
|
parseFIT(buffer: Buffer): Promise<FITFileType>;
|
|
23
23
|
encodeFIT(fitData: FITFileType): Promise<Buffer>;
|
|
24
24
|
encodeFITCourse(fitData: FITFileType): Promise<Buffer>;
|
|
25
|
-
parseTCX(buffer: Buffer): Promise<TCXFileType>;
|
|
26
25
|
parseTCXString(xmlString: string): Promise<TCXFileType>;
|
|
26
|
+
parseTCX(buffer: Buffer): Promise<TCXFileType>;
|
|
27
27
|
encodeTCX(tcxData: TCXFileType): Promise<Buffer>;
|
|
28
28
|
encodeTCXString(tcxData: TCXFileType): Promise<string>;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
convertGPXToActivity(gpxData: GPX11Type): Promise<FileType>;
|
|
30
|
+
convertFITToActivity(fitData: FITFileType): Promise<FileType>;
|
|
31
|
+
convertTCXToActivity(tcxData: TCXFileType): Promise<FileType>;
|
|
32
|
+
convertActivityToGPX(file: FileType): Promise<GPX11Type>;
|
|
33
|
+
convertActivityToFIT(file: FileType): Promise<FITFileType>;
|
|
34
|
+
convertActivityToTCX(file: FileType): Promise<TCXFileType>;
|
|
35
35
|
convertFile(sourceFile: Buffer, targetType: "gpx" | "fit" | "tcx", sourceType?: "gpx" | "fit" | "tcx"): Promise<Buffer>;
|
|
36
36
|
detectFormat(buffer: Buffer): "gpx" | "fit" | "tcx" | "unknown";
|
|
37
37
|
parseFile(buffer: Buffer, sourceType?: "gpx" | "fit" | "tcx"): Promise<GPX11Type | FITFileType | TCXFileType>;
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
parseToActivity(buffer: Buffer, sourceType?: "gpx" | "fit" | "tcx"): Promise<FileType>;
|
|
39
|
+
getActivityProcessor(): ActivityProcessor;
|
|
40
40
|
getGPXDecoder(): GPXDecoder;
|
|
41
41
|
getGPXEncoder(): GPXEncoder;
|
|
42
42
|
getFITDecoder(): FITDecoder;
|