@portel/csv 1.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/CHANGELOG.md +25 -0
- package/FORMAT.md +199 -0
- package/LICENSE +21 -0
- package/README.md +408 -0
- package/dist/cells.d.ts +22 -0
- package/dist/cells.d.ts.map +1 -0
- package/dist/cells.js +69 -0
- package/dist/cells.js.map +1 -0
- package/dist/charts.d.ts +9 -0
- package/dist/charts.d.ts.map +1 -0
- package/dist/charts.js +41 -0
- package/dist/charts.js.map +1 -0
- package/dist/csv.d.ts +8 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +38 -0
- package/dist/csv.js.map +1 -0
- package/dist/engine.d.ts +80 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +505 -0
- package/dist/engine.js.map +1 -0
- package/dist/format.d.ts +15 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +62 -0
- package/dist/format.js.map +1 -0
- package/dist/formulas.d.ts +33 -0
- package/dist/formulas.d.ts.map +1 -0
- package/dist/formulas.js +247 -0
- package/dist/formulas.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/query.d.ts +9 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +47 -0
- package/dist/query.js.map +1 -0
- package/dist/table.d.ts +16 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +94 -0
- package/dist/table.js.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +59 -0
package/dist/cells.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cell addressing — A1 notation, column naming, range resolution.
|
|
3
|
+
*/
|
|
4
|
+
/** Convert a 0-based column index to a letter name (0 → A, 25 → Z, 26 → AA). */
|
|
5
|
+
export function numberToColumnName(num) {
|
|
6
|
+
let result = '';
|
|
7
|
+
num++;
|
|
8
|
+
while (num > 0) {
|
|
9
|
+
num--;
|
|
10
|
+
result = String.fromCharCode(65 + (num % 26)) + result;
|
|
11
|
+
num = Math.floor(num / 26);
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
/** Convert a column letter name to a 0-based index (A → 0, Z → 25, AA → 26). */
|
|
16
|
+
export function columnNameToNumber(name) {
|
|
17
|
+
let result = 0;
|
|
18
|
+
for (let i = 0; i < name.length; i++) {
|
|
19
|
+
result = result * 26 + (name.toUpperCase().charCodeAt(i) - 64);
|
|
20
|
+
}
|
|
21
|
+
return result - 1;
|
|
22
|
+
}
|
|
23
|
+
/** Parse an A1-style cell reference into row/col indices (both 0-based). */
|
|
24
|
+
export function cellToIndex(cell) {
|
|
25
|
+
const match = cell.match(/^([A-Za-z]+)(\d+)$/);
|
|
26
|
+
if (!match)
|
|
27
|
+
throw new Error(`Invalid cell reference: ${cell}`);
|
|
28
|
+
return {
|
|
29
|
+
col: columnNameToNumber(match[1]),
|
|
30
|
+
row: parseInt(match[2]) - 1,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Parse a range reference into start/end row/col indices.
|
|
35
|
+
* Supports cell ranges (A1:C3) and column-only ranges (A:C).
|
|
36
|
+
* For column-only ranges, `maxRow` determines the end row.
|
|
37
|
+
*/
|
|
38
|
+
export function rangeToIndices(range, maxRow) {
|
|
39
|
+
const colMatch = range.match(/^([A-Za-z]+):([A-Za-z]+)$/);
|
|
40
|
+
if (colMatch) {
|
|
41
|
+
return {
|
|
42
|
+
startCol: columnNameToNumber(colMatch[1]),
|
|
43
|
+
startRow: 0,
|
|
44
|
+
endCol: columnNameToNumber(colMatch[2]),
|
|
45
|
+
endRow: Math.max(maxRow, 0),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const parts = range.split(':');
|
|
49
|
+
if (parts.length !== 2)
|
|
50
|
+
throw new Error(`Invalid range: ${range}`);
|
|
51
|
+
const start = cellToIndex(parts[0]);
|
|
52
|
+
const end = cellToIndex(parts[1]);
|
|
53
|
+
return { startRow: start.row, startCol: start.col, endRow: end.row, endCol: end.col };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Resolve a column name or letter to a 0-based index.
|
|
57
|
+
* Tries exact header match first, then case-insensitive, then letter conversion.
|
|
58
|
+
*/
|
|
59
|
+
export function resolveColumnIndex(name, headers) {
|
|
60
|
+
const headerIdx = headers.indexOf(name);
|
|
61
|
+
if (headerIdx !== -1)
|
|
62
|
+
return headerIdx;
|
|
63
|
+
const lowerName = name.toLowerCase();
|
|
64
|
+
const ciIdx = headers.findIndex(h => h.toLowerCase() === lowerName);
|
|
65
|
+
if (ciIdx !== -1)
|
|
66
|
+
return ciIdx;
|
|
67
|
+
return columnNameToNumber(name);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=cells.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cells.js","sourceRoot":"","sources":["../src/cells.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,gFAAgF;AAChF,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,GAAG,EAAE,CAAC;IACN,OAAO,GAAG,GAAG,CAAC,EAAE,CAAC;QACf,GAAG,EAAE,CAAC;QACN,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;QACvD,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAA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AE,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC;AACxF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,OAAiB;IAChE,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,SAAS,KAAK,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACvC,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,CAAC;IACpE,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/B,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
|
package/dist/charts.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visual formula parsing — PIE, BAR, LINE, SPARKLINE, GAUGE chart descriptors.
|
|
3
|
+
*/
|
|
4
|
+
import type { ChartDescriptor } from './types.js';
|
|
5
|
+
import { isVisualFormula, type FormulaContext } from './formulas.js';
|
|
6
|
+
export { isVisualFormula };
|
|
7
|
+
/** Parse a visual formula and return a ChartDescriptor with resolved data. */
|
|
8
|
+
export declare function parseVisualFormula(formula: string, row: number, col: number, ctx: FormulaContext): ChartDescriptor | null;
|
|
9
|
+
//# sourceMappingURL=charts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charts.d.ts","sourceRoot":"","sources":["../src/charts.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EAAoB,eAAe,EAAgD,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAGrI,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,8EAA8E;AAC9E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,cAAc,GAAG,eAAe,GAAG,IAAI,CAoCzH"}
|
package/dist/charts.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visual formula parsing — PIE, BAR, LINE, SPARKLINE, GAUGE chart descriptors.
|
|
3
|
+
*/
|
|
4
|
+
import { numberToColumnName } from './cells.js';
|
|
5
|
+
import { splitFormulaArgs, isVisualFormula, resolveRangeToStrings, resolveRangeToNumbers } from './formulas.js';
|
|
6
|
+
// Re-export isVisualFormula for convenience
|
|
7
|
+
export { isVisualFormula };
|
|
8
|
+
/** Parse a visual formula and return a ChartDescriptor with resolved data. */
|
|
9
|
+
export function parseVisualFormula(formula, row, col, ctx) {
|
|
10
|
+
const match = formula.trim().match(/^([A-Z]+)\s*\((.+)\)$/i);
|
|
11
|
+
if (!match)
|
|
12
|
+
return null;
|
|
13
|
+
const type = match[1].toUpperCase();
|
|
14
|
+
const argsStr = match[2];
|
|
15
|
+
const args = splitFormulaArgs(argsStr);
|
|
16
|
+
const cellRef = numberToColumnName(col) + (row + 1);
|
|
17
|
+
if (type === 'SPARKLINE') {
|
|
18
|
+
const values = resolveRangeToNumbers(args[0]?.trim(), ctx);
|
|
19
|
+
return { cell: cellRef, type: 'sparkline', valueRange: args[0]?.trim(), resolvedLabels: [], resolvedValues: values };
|
|
20
|
+
}
|
|
21
|
+
if (type === 'GAUGE') {
|
|
22
|
+
const val = resolveRangeToNumbers(args[0]?.trim(), ctx);
|
|
23
|
+
const min = args[1] ? parseFloat(args[1].trim()) : 0;
|
|
24
|
+
const max = args[2] ? parseFloat(args[2].trim()) : 100;
|
|
25
|
+
return { cell: cellRef, type: 'gauge', resolvedLabels: [], resolvedValues: val, min, max };
|
|
26
|
+
}
|
|
27
|
+
// PIE, BAR, LINE: (labelRange, valueRange)
|
|
28
|
+
const labelRange = args[0]?.trim();
|
|
29
|
+
const valueRange = args[1]?.trim();
|
|
30
|
+
const labels = labelRange ? resolveRangeToStrings(labelRange, ctx) : [];
|
|
31
|
+
const values = valueRange ? resolveRangeToNumbers(valueRange, ctx) : [];
|
|
32
|
+
return {
|
|
33
|
+
cell: cellRef,
|
|
34
|
+
type: type.toLowerCase(),
|
|
35
|
+
labelRange,
|
|
36
|
+
valueRange,
|
|
37
|
+
resolvedLabels: labels,
|
|
38
|
+
resolvedValues: values,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=charts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"charts.js","sourceRoot":"","sources":["../src/charts.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAqB,EAAE,qBAAqB,EAAuB,MAAM,eAAe,CAAC;AAErI,4CAA4C;AAC5C,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,8EAA8E;AAC9E,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,GAAW,EAAE,GAAW,EAAE,GAAmB;IAC/F,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC7D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IAExB,MAAM,IAAI,GAAG,KAAK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UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;IACnC,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;IAEnC,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACxE,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,qBAAqB,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAExE,OAAO;QACL,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,IAAI,CAAC,WAAW,EAA4B;QAClD,UAAU;QACV,UAAU;QACV,cAAc,EAAE,MAAM;QACtB,cAAc,EAAE,MAAM;KACvB,CAAC;AACJ,CAAC"}
|
package/dist/csv.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core CSV parsing and escaping — RFC 4180 compatible with formula-aware quoting.
|
|
3
|
+
*/
|
|
4
|
+
/** Escape a value for CSV output. Quotes values containing commas, quotes, newlines, or leading `=`. */
|
|
5
|
+
export declare function escapeCSV(value: string): string;
|
|
6
|
+
/** Parse a single CSV line into an array of trimmed cell values. Handles quoted fields and escaped quotes. */
|
|
7
|
+
export declare function parseCSVLine(line: string): string[];
|
|
8
|
+
//# sourceMappingURL=csv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.d.ts","sourceRoot":"","sources":["../src/csv.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wGAAwG;AACxG,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED,8GAA8G;AAC9G,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAuBnD"}
|
package/dist/csv.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core CSV parsing and escaping — RFC 4180 compatible with formula-aware quoting.
|
|
3
|
+
*/
|
|
4
|
+
/** Escape a value for CSV output. Quotes values containing commas, quotes, newlines, or leading `=`. */
|
|
5
|
+
export function escapeCSV(value) {
|
|
6
|
+
if (value.includes(',') || value.includes('"') || value.includes('\n') || value.startsWith('=')) {
|
|
7
|
+
return '"' + value.replace(/"/g, '""') + '"';
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
/** Parse a single CSV line into an array of trimmed cell values. Handles quoted fields and escaped quotes. */
|
|
12
|
+
export function parseCSVLine(line) {
|
|
13
|
+
const result = [];
|
|
14
|
+
let current = '';
|
|
15
|
+
let inQuotes = false;
|
|
16
|
+
for (let i = 0; i < line.length; i++) {
|
|
17
|
+
const char = line[i];
|
|
18
|
+
if (char === '"') {
|
|
19
|
+
if (inQuotes && line[i + 1] === '"') {
|
|
20
|
+
current += '"';
|
|
21
|
+
i++;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
inQuotes = !inQuotes;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (char === ',' && !inQuotes) {
|
|
28
|
+
result.push(current.trim());
|
|
29
|
+
current = '';
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
current += char;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
result.push(current.trim());
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=csv.js.map
|
package/dist/csv.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csv.js","sourceRoot":"","sources":["../src/csv.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wGAAwG;AACxG,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CA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ateful CSV engine composing all modules.
|
|
3
|
+
*
|
|
4
|
+
* Pure library class: no file I/O, no async, no side effects.
|
|
5
|
+
* The photon wraps this with load/save/emit/watch.
|
|
6
|
+
*/
|
|
7
|
+
import type { ColumnMeta, CsvEngineOptions, ToCsvOptions, EngineSnapshot, QueryResult, SqlResult, SchemaColumn } from './types.js';
|
|
8
|
+
export declare class CsvEngine {
|
|
9
|
+
private cells;
|
|
10
|
+
private headers;
|
|
11
|
+
private columnMeta;
|
|
12
|
+
private hasFormatRow;
|
|
13
|
+
private metaCustomized;
|
|
14
|
+
private _rowCount;
|
|
15
|
+
private _colCount;
|
|
16
|
+
constructor(options?: CsvEngineOptions);
|
|
17
|
+
/** Create an engine from CSV text. */
|
|
18
|
+
static fromCSV(csvText: string): CsvEngine;
|
|
19
|
+
private _loadFromCSV;
|
|
20
|
+
get rowCount(): number;
|
|
21
|
+
get colCount(): number;
|
|
22
|
+
getHeaders(): string[];
|
|
23
|
+
getColumnMeta(): ColumnMeta[];
|
|
24
|
+
getRawCell(row: number, col: number): string;
|
|
25
|
+
getCells(): string[][];
|
|
26
|
+
getHasFormatRow(): boolean;
|
|
27
|
+
getMetaCustomized(): boolean;
|
|
28
|
+
/** Evaluate a single cell, resolving formulas. */
|
|
29
|
+
evaluate(row: number, col: number): string;
|
|
30
|
+
/** Evaluate all cells, returning a grid of computed values. */
|
|
31
|
+
evaluateAll(): string[][];
|
|
32
|
+
/** Set a single cell value. */
|
|
33
|
+
set(cell: string, value: string): void;
|
|
34
|
+
/** Add a row using column name → value mapping. */
|
|
35
|
+
add(values: Record<string, string>): number;
|
|
36
|
+
/** Remove a row (1-indexed). */
|
|
37
|
+
remove(row: number): void;
|
|
38
|
+
/** Update fields in a row (1-indexed). */
|
|
39
|
+
update(row: number, values: Record<string, string>): string[];
|
|
40
|
+
/** Batch-append rows. Each row is an array of values or a column→value object. */
|
|
41
|
+
push(rows: (string[] | Record<string, string>)[]): number;
|
|
42
|
+
/** Fill a range with a repeating pattern of values. */
|
|
43
|
+
fill(range: string, pattern: string): void;
|
|
44
|
+
/** Clear all cells or a specific range. */
|
|
45
|
+
clear(range?: string): void;
|
|
46
|
+
/** Resize the grid. */
|
|
47
|
+
resize(rows?: number, cols?: number): void;
|
|
48
|
+
/** Rename a column header. */
|
|
49
|
+
rename(column: string, name: string): string;
|
|
50
|
+
/** Sort rows by a column. */
|
|
51
|
+
sort(column: string, order?: string): void;
|
|
52
|
+
/** Set column formatting. */
|
|
53
|
+
format(column: string, opts: {
|
|
54
|
+
align?: string;
|
|
55
|
+
type?: string;
|
|
56
|
+
width?: number;
|
|
57
|
+
wrap?: boolean;
|
|
58
|
+
}): void;
|
|
59
|
+
/** Filter rows by a simple condition string. */
|
|
60
|
+
query(where: string, limit?: number): QueryResult;
|
|
61
|
+
/** Run a SQL query. Requires alasql as a peer dependency. */
|
|
62
|
+
sql(queryStr: string): SqlResult;
|
|
63
|
+
/** Serialize to CSV text. */
|
|
64
|
+
toCSV(options?: ToCsvOptions): string;
|
|
65
|
+
/** Convert to array of typed objects, with auto-coercion for numeric columns. */
|
|
66
|
+
toObjects(): Record<string, any>[];
|
|
67
|
+
/** Format as an ASCII markdown table. */
|
|
68
|
+
toTable(range?: string): string;
|
|
69
|
+
/** Get a full engine state snapshot for UI rendering. */
|
|
70
|
+
snapshot(message?: string): EngineSnapshot;
|
|
71
|
+
/** Get column schema with type detection. */
|
|
72
|
+
schema(): SchemaColumn[];
|
|
73
|
+
/** Load CSV data from text (replaces current state). */
|
|
74
|
+
loadCSV(csvText: string): void;
|
|
75
|
+
/** Append parsed CSV rows, skipping headers and format rows. */
|
|
76
|
+
appendCSVLines(lines: string[]): number;
|
|
77
|
+
private _ensureCapacity;
|
|
78
|
+
private _formulaContext;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"A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