@loaders.gl/excel 4.4.2 → 5.0.0-alpha.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 (44) hide show
  1. package/dist/bundled.d.ts +3 -0
  2. package/dist/bundled.d.ts.map +1 -0
  3. package/dist/bundled.js +5 -0
  4. package/dist/bundled.js.map +1 -0
  5. package/dist/dist.dev.js +31603 -17938
  6. package/dist/dist.min.js +44 -37
  7. package/dist/excel-format.d.ts +2 -0
  8. package/dist/excel-format.d.ts.map +1 -1
  9. package/dist/excel-format.js +2 -0
  10. package/dist/excel-format.js.map +1 -1
  11. package/dist/excel-loader-with-parser.d.ts +60 -0
  12. package/dist/excel-loader-with-parser.d.ts.map +1 -0
  13. package/dist/excel-loader-with-parser.js +29 -0
  14. package/dist/excel-loader-with-parser.js.map +1 -0
  15. package/dist/excel-loader.d.ts +40 -14
  16. package/dist/excel-loader.d.ts.map +1 -1
  17. package/dist/excel-loader.js +11 -13
  18. package/dist/excel-loader.js.map +1 -1
  19. package/dist/excel-worker.js +30628 -16797
  20. package/dist/index.cjs +175 -43
  21. package/dist/index.cjs.map +4 -4
  22. package/dist/index.d.ts +3 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/lib/convert-excel-rows-to-arrow.d.ts +11 -0
  27. package/dist/lib/convert-excel-rows-to-arrow.d.ts.map +1 -0
  28. package/dist/lib/convert-excel-rows-to-arrow.js +72 -0
  29. package/dist/lib/convert-excel-rows-to-arrow.js.map +1 -0
  30. package/dist/unbundled.d.ts +3 -0
  31. package/dist/unbundled.d.ts.map +1 -0
  32. package/dist/unbundled.js +5 -0
  33. package/dist/unbundled.js.map +1 -0
  34. package/dist/workers/excel-worker.js +2 -2
  35. package/dist/workers/excel-worker.js.map +1 -1
  36. package/package.json +15 -5
  37. package/src/bundled.ts +9 -0
  38. package/src/excel-format.ts +2 -0
  39. package/src/excel-loader-with-parser.ts +51 -0
  40. package/src/excel-loader.ts +21 -21
  41. package/src/index.ts +5 -1
  42. package/src/lib/convert-excel-rows-to-arrow.ts +83 -0
  43. package/src/unbundled.ts +6 -0
  44. package/src/workers/excel-worker.ts +2 -2
package/dist/index.cjs CHANGED
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
6
11
  var __export = (target, all) => {
7
12
  for (var name in all)
8
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,34 +20,39 @@ var __copyProps = (to, from, except, desc) => {
15
20
  }
16
21
  return to;
17
22
  };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
18
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
32
 
20
- // dist/index.js
21
- var dist_exports = {};
22
- __export(dist_exports, {
23
- ExcelFormat: () => ExcelFormat,
24
- ExcelLoader: () => ExcelLoader,
25
- ExcelWorkerLoader: () => ExcelWorkerLoader
26
- });
27
- module.exports = __toCommonJS(dist_exports);
28
-
29
33
  // dist/excel-format.js
30
- var ExcelFormat = {
31
- name: "Excel",
32
- id: "excel",
33
- module: "excel",
34
- extensions: ["xls", "xlsb", "xlsm", "xlsx"],
35
- mimeTypes: [
36
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
37
- "application/vnd.ms-excel"
38
- ],
39
- category: "table",
40
- binary: true
41
- };
34
+ var ExcelFormat;
35
+ var init_excel_format = __esm({
36
+ "dist/excel-format.js"() {
37
+ "use strict";
38
+ ExcelFormat = {
39
+ name: "Excel",
40
+ id: "excel",
41
+ module: "excel",
42
+ encoding: "zip",
43
+ format: "excel",
44
+ extensions: ["xls", "xlsb", "xlsm", "xlsx"],
45
+ mimeTypes: [
46
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
47
+ "application/vnd.ms-excel"
48
+ ],
49
+ category: "table",
50
+ binary: true
51
+ };
52
+ }
53
+ });
42
54
 
43
55
  // dist/lib/parse-excel.js
44
- var import_xlsx = require("xlsx");
45
- var dataTableNamesMap = {};
46
56
  function parseExcel(arrayBuffer, options) {
47
57
  var _a, _b, _c;
48
58
  const dataUrl = "dummy";
@@ -65,28 +75,150 @@ function parseExcel(arrayBuffer, options) {
65
75
  }
66
76
  return dataRows;
67
77
  }
78
+ var import_xlsx, dataTableNamesMap;
79
+ var init_parse_excel = __esm({
80
+ "dist/lib/parse-excel.js"() {
81
+ "use strict";
82
+ import_xlsx = require("xlsx");
83
+ dataTableNamesMap = {};
84
+ }
85
+ });
68
86
 
69
- // dist/excel-loader.js
70
- var VERSION = true ? "4.4.2" : "latest";
71
- var ExcelWorkerLoader = {
72
- ...ExcelFormat,
73
- dataType: null,
74
- batchType: null,
75
- version: VERSION,
76
- worker: true,
77
- options: {
78
- excel: {
79
- shape: "object-row-table",
80
- sheet: void 0
81
- // Load default Sheet
87
+ // dist/lib/convert-excel-rows-to-arrow.js
88
+ function convertExcelRowsToArrowTable(rows) {
89
+ const table = rows.length > 0 ? (0, import_schema_utils.makeTableFromData)(rows) : { shape: "object-row-table", schema: { fields: [], metadata: {} }, data: rows };
90
+ const schema = deducePrimitiveAwareSchema(table);
91
+ if (table.data.length === 0 || schema.fields.length === 0) {
92
+ return {
93
+ shape: "arrow-table",
94
+ schema,
95
+ data: new arrow.Table(new arrow.Schema([]))
96
+ };
97
+ }
98
+ const arrowTableBuilder = new import_schema_utils.ArrowTableBuilder(schema);
99
+ for (const row of table.data) {
100
+ arrowTableBuilder.addObjectRow(row);
101
+ }
102
+ return arrowTableBuilder.finishTable();
103
+ }
104
+ function deducePrimitiveAwareSchema(table) {
105
+ const fields = table.schema.fields.map((field) => {
106
+ if (field.type === "float32") {
107
+ return { ...field, type: "float64" };
108
+ }
109
+ if (field.type !== "null") {
110
+ return field;
111
+ }
112
+ for (const row of table.data) {
113
+ const type = getDataTypeFromPrimitive(row[field.name]);
114
+ if (type !== "null") {
115
+ return { ...field, type };
116
+ }
82
117
  }
118
+ return field;
119
+ });
120
+ return { ...table.schema, fields };
121
+ }
122
+ function getDataTypeFromPrimitive(value) {
123
+ switch (typeof value) {
124
+ case "number":
125
+ return "float64";
126
+ case "boolean":
127
+ return "bool";
128
+ case "string":
129
+ return "utf8";
130
+ default:
131
+ return value instanceof Date ? "date-millisecond" : "null";
83
132
  }
84
- };
85
- var ExcelLoader = {
86
- ...ExcelWorkerLoader,
87
- async parse(arrayBuffer, options) {
88
- const data = parseExcel(arrayBuffer, options);
89
- return { shape: "object-row-table", data };
133
+ }
134
+ var import_schema_utils, arrow;
135
+ var init_convert_excel_rows_to_arrow = __esm({
136
+ "dist/lib/convert-excel-rows-to-arrow.js"() {
137
+ "use strict";
138
+ import_schema_utils = require("@loaders.gl/schema-utils");
139
+ arrow = __toESM(require("apache-arrow"), 1);
90
140
  }
91
- };
141
+ });
142
+
143
+ // dist/excel-loader-with-parser.js
144
+ var excel_loader_with_parser_exports = {};
145
+ __export(excel_loader_with_parser_exports, {
146
+ ExcelLoaderWithParser: () => ExcelLoaderWithParser,
147
+ ExcelWorkerLoaderWithParser: () => ExcelWorkerLoaderWithParser
148
+ });
149
+ var _ExcelWorkerLoaderPreload, ExcelWorkerLoaderMetadataWithoutPreload, _ExcelLoaderPreload, ExcelLoaderMetadataWithoutPreload, ExcelWorkerLoaderWithParser, ExcelLoaderWithParser;
150
+ var init_excel_loader_with_parser = __esm({
151
+ "dist/excel-loader-with-parser.js"() {
152
+ "use strict";
153
+ init_parse_excel();
154
+ init_convert_excel_rows_to_arrow();
155
+ init_excel_loader();
156
+ init_excel_loader();
157
+ ({ preload: _ExcelWorkerLoaderPreload, ...ExcelWorkerLoaderMetadataWithoutPreload } = ExcelWorkerLoader);
158
+ ({ preload: _ExcelLoaderPreload, ...ExcelLoaderMetadataWithoutPreload } = ExcelLoader);
159
+ ExcelWorkerLoaderWithParser = {
160
+ ...ExcelWorkerLoaderMetadataWithoutPreload
161
+ };
162
+ ExcelLoaderWithParser = {
163
+ ...ExcelLoaderMetadataWithoutPreload,
164
+ async parse(arrayBuffer, options) {
165
+ var _a;
166
+ const excelOptions = {
167
+ ...options,
168
+ excel: { ...ExcelLoaderWithParser.options.excel, ...options == null ? void 0 : options.excel }
169
+ };
170
+ const rows = parseExcel(arrayBuffer, excelOptions);
171
+ if (((_a = excelOptions.excel) == null ? void 0 : _a.shape) === "arrow-table") {
172
+ return convertExcelRowsToArrowTable(rows);
173
+ }
174
+ return { shape: "object-row-table", data: rows };
175
+ }
176
+ };
177
+ }
178
+ });
179
+
180
+ // dist/excel-loader.js
181
+ async function preload() {
182
+ const { ExcelLoaderWithParser: ExcelLoaderWithParser2 } = await Promise.resolve().then(() => (init_excel_loader_with_parser(), excel_loader_with_parser_exports));
183
+ return ExcelLoaderWithParser2;
184
+ }
185
+ var VERSION, ExcelWorkerLoader, ExcelLoader;
186
+ var init_excel_loader = __esm({
187
+ "dist/excel-loader.js"() {
188
+ "use strict";
189
+ init_excel_format();
190
+ VERSION = true ? "5.0.0-alpha.1" : "latest";
191
+ ExcelWorkerLoader = {
192
+ ...ExcelFormat,
193
+ dataType: null,
194
+ batchType: null,
195
+ version: VERSION,
196
+ worker: true,
197
+ options: {
198
+ excel: {
199
+ shape: "object-row-table",
200
+ sheet: void 0
201
+ // Load default Sheet
202
+ }
203
+ },
204
+ preload
205
+ };
206
+ ExcelLoader = {
207
+ ...ExcelWorkerLoader,
208
+ preload
209
+ };
210
+ }
211
+ });
212
+
213
+ // dist/index.js
214
+ var dist_exports = {};
215
+ __export(dist_exports, {
216
+ ExcelFormat: () => ExcelFormat,
217
+ ExcelLoader: () => ExcelLoader,
218
+ ExcelWorkerLoader: () => ExcelWorkerLoader
219
+ });
220
+ module.exports = __toCommonJS(dist_exports);
221
+ init_excel_format();
222
+ init_excel_loader();
223
+ init_excel_loader();
92
224
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.ts", "../src/excel-format.ts", "../src/lib/parse-excel.ts", "../src/excel-loader.ts"],
4
- "sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// Excel Loader\n\nexport {ExcelFormat} from './excel-format';\nexport type {ExcelLoaderOptions} from './excel-loader';\nexport {ExcelLoader, ExcelWorkerLoader} from './excel-loader';\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Format} from '@loaders.gl/loader-utils';\n\n/**\n * Excel files\n */\nexport const ExcelFormat = {\n name: 'Excel',\n id: 'excel',\n module: 'excel',\n extensions: ['xls', 'xlsb', 'xlsm', 'xlsx'],\n mimeTypes: [\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n 'application/vnd.ms-excel'\n ],\n category: 'table',\n binary: true\n} as const satisfies Format;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {ExcelLoaderOptions} from '../excel-loader';\nimport {utils, read} from 'xlsx';\n// import {convertToArrayRow} from '@loaders.gl/schema';\n\n// local table names cache with dataUrl/tableNames array key/values\nconst dataTableNamesMap = {};\n\n/**\n * Gets local or remote Excel file data.\n * @param arrayBuffer Loaded data\n * @param options Data parse options.\n */\nexport function parseExcel(\n arrayBuffer: ArrayBuffer,\n options?: ExcelLoaderOptions\n): {[key: string]: unknown}[] {\n const dataUrl = 'dummy';\n // const dataFileType: string = dataUrl.substr(dataUrl.lastIndexOf('.')); // file extension\n\n // create Excel 'workbook'\n const workbook = read(arrayBuffer, {\n type: 'array'\n // cellDates: true\n });\n\n // load data sheets\n let dataRows: {[key: string]: unknown}[] = [];\n dataTableNamesMap[dataUrl] = [];\n if (workbook.SheetNames.length > 0) {\n if (workbook.SheetNames.length > 1) {\n // cache sheet names\n dataTableNamesMap[dataUrl] = workbook.SheetNames;\n // eslint-ignore-next-line\n // console.debug(`getData(): file: sheetNames:`, workbook.SheetNames);\n }\n\n // determine spreadsheet to load\n let sheetName = workbook.SheetNames[0];\n if (options?.excel?.sheet && workbook.SheetNames.indexOf(options?.excel?.sheet) >= 0) {\n // reset to requested table name\n sheetName = options?.excel?.sheet;\n }\n\n // get worksheet data row objects array\n const worksheet = workbook.Sheets[sheetName];\n dataRows = utils.sheet_to_json(worksheet);\n\n // const headers = dataRows.length ? Object.keys(dataRows[0]) : [];\n // if (options?.excel?.type === 'array-row-table') {\n // dataRows = dataRows.map(row => convertToArrayRow(row, headers))\n // }\n }\n\n return dataRows;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {ObjectRowTable} from '@loaders.gl/schema';\nimport {parseExcel} from './lib/parse-excel';\nimport {ExcelFormat} from './excel-format';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type ExcelLoaderOptions = LoaderOptions & {\n /** Options for ExcelLoader */\n excel?: {\n /** Format of returned data */\n shape?: /* 'array-row-table' | */ 'object-row-table';\n /** Specify which sheet to load, if omitted loads default sheet */\n sheet?: string;\n /** Override the URL to the worker bundle (by default loads from unpkg.com) */\n workerUrl?: string;\n };\n};\n\n/**\n * Worker Loader for Excel files\n */\nexport const ExcelWorkerLoader = {\n ...ExcelFormat,\n dataType: null as unknown as ObjectRowTable,\n batchType: null as never,\n version: VERSION,\n worker: true,\n options: {\n excel: {\n shape: 'object-row-table',\n sheet: undefined // Load default Sheet\n }\n }\n} as const satisfies Loader<ObjectRowTable, never, ExcelLoaderOptions>;\n\n/**\n * Loader for Excel files\n */\nexport const ExcelLoader = {\n ...ExcelWorkerLoader,\n async parse(arrayBuffer: ArrayBuffer, options?: ExcelLoaderOptions): Promise<ObjectRowTable> {\n const data = parseExcel(arrayBuffer, options);\n return {shape: 'object-row-table', data};\n }\n} as const satisfies LoaderWithParser<ObjectRowTable, never, ExcelLoaderOptions>;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;ACSO,IAAM,cAAc;EACzB,MAAM;EACN,IAAI;EACJ,QAAQ;EACR,YAAY,CAAC,OAAO,QAAQ,QAAQ,MAAM;EAC1C,WAAW;IACT;IACA;;EAEF,UAAU;EACV,QAAQ;;;;ACdV,kBAA0B;AAI1B,IAAM,oBAAoB,CAAA;AAOpB,SAAU,WACd,aACA,SAA4B;AAlB9B;AAoBE,QAAM,UAAU;AAIhB,QAAM,eAAW,kBAAK,aAAa;IACjC,MAAM;;GAEP;AAGD,MAAI,WAAuC,CAAA;AAC3C,oBAAkB,OAAO,IAAI,CAAA;AAC7B,MAAI,SAAS,WAAW,SAAS,GAAG;AAClC,QAAI,SAAS,WAAW,SAAS,GAAG;AAElC,wBAAkB,OAAO,IAAI,SAAS;IAGxC;AAGA,QAAI,YAAY,SAAS,WAAW,CAAC;AACrC,UAAI,wCAAS,UAAT,mBAAgB,UAAS,SAAS,WAAW,SAAQ,wCAAS,UAAT,mBAAgB,KAAK,KAAK,GAAG;AAEpF,mBAAY,wCAAS,UAAT,mBAAgB;IAC9B;AAGA,UAAM,YAAY,SAAS,OAAO,SAAS;AAC3C,eAAW,kBAAM,cAAc,SAAS;EAM1C;AAEA,SAAO;AACT;;;AC/CA,IAAM,UAAU,OAAoC,UAAe;AAiB5D,IAAM,oBAAoB;EAC/B,GAAG;EACH,UAAU;EACV,WAAW;EACX,SAAS;EACT,QAAQ;EACR,SAAS;IACP,OAAO;MACL,OAAO;MACP,OAAO;;;;;AAQN,IAAM,cAAc;EACzB,GAAG;EACH,MAAM,MAAM,aAA0B,SAA4B;AAChE,UAAM,OAAO,WAAW,aAAa,OAAO;AAC5C,WAAO,EAAC,OAAO,oBAAoB,KAAI;EACzC;;",
6
- "names": []
3
+ "sources": ["../src/excel-format.ts", "../src/lib/parse-excel.ts", "../src/lib/convert-excel-rows-to-arrow.ts", "../src/excel-loader-with-parser.ts", "../src/excel-loader.ts", "../src/index.ts"],
4
+ "sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Format} from '@loaders.gl/loader-utils';\n\n/**\n * Excel files\n */\nexport const ExcelFormat = {\n name: 'Excel',\n id: 'excel',\n module: 'excel',\n encoding: 'zip',\n format: 'excel',\n extensions: ['xls', 'xlsb', 'xlsm', 'xlsx'],\n mimeTypes: [\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n 'application/vnd.ms-excel'\n ],\n category: 'table',\n binary: true\n} as const satisfies Format;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {ExcelLoaderOptions} from '../excel-loader';\nimport {utils, read} from 'xlsx';\n// import {convertToArrayRow} from '@loaders.gl/schema';\n\n// local table names cache with dataUrl/tableNames array key/values\nconst dataTableNamesMap = {};\n\n/**\n * Gets local or remote Excel file data.\n * @param arrayBuffer Loaded data\n * @param options Data parse options.\n */\nexport function parseExcel(\n arrayBuffer: ArrayBuffer,\n options?: ExcelLoaderOptions\n): {[key: string]: unknown}[] {\n const dataUrl = 'dummy';\n // const dataFileType: string = dataUrl.substr(dataUrl.lastIndexOf('.')); // file extension\n\n // create Excel 'workbook'\n const workbook = read(arrayBuffer, {\n type: 'array'\n // cellDates: true\n });\n\n // load data sheets\n let dataRows: {[key: string]: unknown}[] = [];\n dataTableNamesMap[dataUrl] = [];\n if (workbook.SheetNames.length > 0) {\n if (workbook.SheetNames.length > 1) {\n // cache sheet names\n dataTableNamesMap[dataUrl] = workbook.SheetNames;\n // eslint-ignore-next-line\n // console.debug(`getData(): file: sheetNames:`, workbook.SheetNames);\n }\n\n // determine spreadsheet to load\n let sheetName = workbook.SheetNames[0];\n if (options?.excel?.sheet && workbook.SheetNames.indexOf(options?.excel?.sheet) >= 0) {\n // reset to requested table name\n sheetName = options?.excel?.sheet;\n }\n\n // get worksheet data row objects array\n const worksheet = workbook.Sheets[sheetName];\n dataRows = utils.sheet_to_json(worksheet);\n\n // const headers = dataRows.length ? Object.keys(dataRows[0]) : [];\n // if (options?.excel?.type === 'array-row-table') {\n // dataRows = dataRows.map(row => convertToArrayRow(row, headers))\n // }\n }\n\n return dataRows;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {ArrowTable, DataType, Field, ObjectRowTable, Schema} from '@loaders.gl/schema';\nimport {ArrowTableBuilder, makeTableFromData} from '@loaders.gl/schema-utils';\nimport * as arrow from 'apache-arrow';\n\n/**\n * Converts parsed Excel rows to an Arrow table, including empty sheets.\n *\n * @param rows - Parsed Excel rows keyed by worksheet column name.\n * @returns A loaders.gl Arrow table with one Apache Arrow column per row property.\n */\nexport function convertExcelRowsToArrowTable(rows: {[key: string]: unknown}[]): ArrowTable {\n const table: ObjectRowTable =\n rows.length > 0\n ? makeTableFromData(rows)\n : {shape: 'object-row-table', schema: {fields: [], metadata: {}}, data: rows};\n const schema = deducePrimitiveAwareSchema(table);\n\n if (table.data.length === 0 || schema.fields.length === 0) {\n return {\n shape: 'arrow-table',\n schema,\n data: new arrow.Table(new arrow.Schema([]))\n };\n }\n\n const arrowTableBuilder = new ArrowTableBuilder(schema);\n for (const row of table.data) {\n arrowTableBuilder.addObjectRow(row);\n }\n return arrowTableBuilder.finishTable();\n}\n\n/**\n * Deduces a schema that handles primitive numbers and booleans in Excel rows.\n *\n * @param table - Object-row table produced from parsed Excel rows.\n * @returns A schema with primitive values promoted from `null` to Arrow-compatible types.\n */\nfunction deducePrimitiveAwareSchema(table: ObjectRowTable): Schema {\n const fields = table.schema!.fields.map((field): Field => {\n if (field.type === 'float32') {\n return {...field, type: 'float64'};\n }\n\n if (field.type !== 'null') {\n return field;\n }\n\n for (const row of table.data) {\n const type = getDataTypeFromPrimitive(row[field.name]);\n if (type !== 'null') {\n return {...field, type};\n }\n }\n\n return field;\n });\n\n return {...table.schema!, fields};\n}\n\n/**\n * Deduces a loaders.gl data type from primitive spreadsheet cell values.\n *\n * @param value - Spreadsheet cell value.\n * @returns The matching loaders.gl data type, or `null` for unsupported values.\n */\nfunction getDataTypeFromPrimitive(value: unknown): DataType {\n switch (typeof value) {\n case 'number':\n return 'float64';\n case 'boolean':\n return 'bool';\n case 'string':\n return 'utf8';\n default:\n return value instanceof Date ? 'date-millisecond' : 'null';\n }\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {ArrowTable, ObjectRowTable} from '@loaders.gl/schema';\nimport {parseExcel} from './lib/parse-excel';\nimport {convertExcelRowsToArrowTable} from './lib/convert-excel-rows-to-arrow';\nimport {ExcelWorkerLoader as ExcelWorkerLoaderMetadata} from './excel-loader';\nimport {ExcelLoader as ExcelLoaderMetadata} from './excel-loader';\n\nconst {preload: _ExcelWorkerLoaderPreload, ...ExcelWorkerLoaderMetadataWithoutPreload} =\n ExcelWorkerLoaderMetadata;\nconst {preload: _ExcelLoaderPreload, ...ExcelLoaderMetadataWithoutPreload} = ExcelLoaderMetadata;\n\n/** Options for parsing Excel worksheets. */\nexport type ExcelLoaderOptions = LoaderOptions & {\n /** Options for ExcelLoaderWithParser */\n excel?: {\n /** Selects row-table output or Apache Arrow output. */\n shape?: /* 'array-row-table' | */ 'object-row-table' | 'arrow-table';\n /** Specify which sheet to load, if omitted loads default sheet. */\n sheet?: string;\n /** Override the URL to the worker bundle (by default loads from unpkg.com). */\n workerUrl?: string;\n };\n};\n\n/** Worker loader for Excel files. */\nexport const ExcelWorkerLoaderWithParser = {\n ...ExcelWorkerLoaderMetadataWithoutPreload\n} as const satisfies Loader<ObjectRowTable | ArrowTable, never, ExcelLoaderOptions>;\n\n/** Loader for Excel files. */\nexport const ExcelLoaderWithParser = {\n ...ExcelLoaderMetadataWithoutPreload,\n async parse(\n arrayBuffer: ArrayBuffer,\n options?: ExcelLoaderOptions\n ): Promise<ObjectRowTable | ArrowTable> {\n const excelOptions = {\n ...options,\n excel: {...ExcelLoaderWithParser.options.excel, ...options?.excel}\n } as ExcelLoaderOptions;\n const rows = parseExcel(arrayBuffer, excelOptions);\n if (excelOptions.excel?.shape === 'arrow-table') {\n return convertExcelRowsToArrowTable(rows);\n }\n return {shape: 'object-row-table', data: rows};\n }\n} as const satisfies LoaderWithParser<ObjectRowTable | ArrowTable, never, ExcelLoaderOptions>;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {ArrowTable, ObjectRowTable} from '@loaders.gl/schema';\nimport {ExcelFormat} from './excel-format';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/** Options for parsing Excel worksheets. */\nexport type ExcelLoaderOptions = LoaderOptions & {\n /** Options for ExcelLoader */\n excel?: {\n /** Selects row-table output or Apache Arrow output. */\n shape?: /* 'array-row-table' | */ 'object-row-table' | 'arrow-table';\n /** Specify which sheet to load, if omitted loads default sheet. */\n sheet?: string;\n /** Override the URL to the worker bundle (by default loads from unpkg.com). */\n workerUrl?: string;\n };\n};\n\n/** Preloads the parser-bearing Excel loader implementation. */\nasync function preload() {\n const {ExcelLoaderWithParser} = await import('./excel-loader-with-parser');\n return ExcelLoaderWithParser;\n}\n\n/** Metadata-only worker loader for Excel files. */\nexport const ExcelWorkerLoader = {\n ...ExcelFormat,\n dataType: null as unknown as ObjectRowTable | ArrowTable,\n batchType: null as never,\n version: VERSION,\n worker: true,\n options: {\n excel: {\n shape: 'object-row-table',\n sheet: undefined // Load default Sheet\n }\n },\n preload\n} as const satisfies Loader<ObjectRowTable | ArrowTable, never, ExcelLoaderOptions>;\n\n/** Metadata-only loader for Excel files. */\nexport const ExcelLoader = {\n ...ExcelWorkerLoader,\n preload\n} as const satisfies Loader<ObjectRowTable | ArrowTable, never, ExcelLoaderOptions>;\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\n// Excel Loader\n\nexport {ExcelFormat} from './excel-format';\nexport type {ExcelLoaderOptions} from './excel-loader';\nexport {ExcelLoader} from './excel-loader';\n\n// DEPRECATED EXPORTS\n/** @deprecated Use ExcelLoader. */\nexport {ExcelWorkerLoader} from './excel-loader';\n"],
5
+ "mappings": "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",
6
+ "names": ["ExcelLoaderWithParser"]
7
7
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export { ExcelFormat } from "./excel-format.js";
2
2
  export type { ExcelLoaderOptions } from "./excel-loader.js";
3
- export { ExcelLoader, ExcelWorkerLoader } from "./excel-loader.js";
3
+ export { ExcelLoader } from "./excel-loader.js";
4
+ /** @deprecated Use ExcelLoader. */
5
+ export { ExcelWorkerLoader } from "./excel-loader.js";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAC3C,YAAY,EAAC,kBAAkB,EAAC,0BAAuB;AACvD,OAAO,EAAC,WAAW,EAAE,iBAAiB,EAAC,0BAAuB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAC3C,YAAY,EAAC,kBAAkB,EAAC,0BAAuB;AACvD,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAG3C,mCAAmC;AACnC,OAAO,EAAC,iBAAiB,EAAC,0BAAuB"}
package/dist/index.js CHANGED
@@ -3,5 +3,8 @@
3
3
  // Copyright (c) vis.gl contributors
4
4
  // Excel Loader
5
5
  export { ExcelFormat } from "./excel-format.js";
6
- export { ExcelLoader, ExcelWorkerLoader } from "./excel-loader.js";
6
+ export { ExcelLoader } from "./excel-loader.js";
7
+ // DEPRECATED EXPORTS
8
+ /** @deprecated Use ExcelLoader. */
9
+ export { ExcelWorkerLoader } from "./excel-loader.js";
7
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,eAAe;AAEf,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAE3C,OAAO,EAAC,WAAW,EAAE,iBAAiB,EAAC,0BAAuB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAEpC,eAAe;AAEf,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAE3C,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAE3C,qBAAqB;AACrB,mCAAmC;AACnC,OAAO,EAAC,iBAAiB,EAAC,0BAAuB"}
@@ -0,0 +1,11 @@
1
+ import type { ArrowTable } from '@loaders.gl/schema';
2
+ /**
3
+ * Converts parsed Excel rows to an Arrow table, including empty sheets.
4
+ *
5
+ * @param rows - Parsed Excel rows keyed by worksheet column name.
6
+ * @returns A loaders.gl Arrow table with one Apache Arrow column per row property.
7
+ */
8
+ export declare function convertExcelRowsToArrowTable(rows: {
9
+ [key: string]: unknown;
10
+ }[]): ArrowTable;
11
+ //# sourceMappingURL=convert-excel-rows-to-arrow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-excel-rows-to-arrow.d.ts","sourceRoot":"","sources":["../../src/lib/convert-excel-rows-to-arrow.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAA0C,MAAM,oBAAoB,CAAC;AAI5F;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,EAAE,GAAG,UAAU,CAoBzF"}
@@ -0,0 +1,72 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { ArrowTableBuilder, makeTableFromData } from '@loaders.gl/schema-utils';
5
+ import * as arrow from 'apache-arrow';
6
+ /**
7
+ * Converts parsed Excel rows to an Arrow table, including empty sheets.
8
+ *
9
+ * @param rows - Parsed Excel rows keyed by worksheet column name.
10
+ * @returns A loaders.gl Arrow table with one Apache Arrow column per row property.
11
+ */
12
+ export function convertExcelRowsToArrowTable(rows) {
13
+ const table = rows.length > 0
14
+ ? makeTableFromData(rows)
15
+ : { shape: 'object-row-table', schema: { fields: [], metadata: {} }, data: rows };
16
+ const schema = deducePrimitiveAwareSchema(table);
17
+ if (table.data.length === 0 || schema.fields.length === 0) {
18
+ return {
19
+ shape: 'arrow-table',
20
+ schema,
21
+ data: new arrow.Table(new arrow.Schema([]))
22
+ };
23
+ }
24
+ const arrowTableBuilder = new ArrowTableBuilder(schema);
25
+ for (const row of table.data) {
26
+ arrowTableBuilder.addObjectRow(row);
27
+ }
28
+ return arrowTableBuilder.finishTable();
29
+ }
30
+ /**
31
+ * Deduces a schema that handles primitive numbers and booleans in Excel rows.
32
+ *
33
+ * @param table - Object-row table produced from parsed Excel rows.
34
+ * @returns A schema with primitive values promoted from `null` to Arrow-compatible types.
35
+ */
36
+ function deducePrimitiveAwareSchema(table) {
37
+ const fields = table.schema.fields.map((field) => {
38
+ if (field.type === 'float32') {
39
+ return { ...field, type: 'float64' };
40
+ }
41
+ if (field.type !== 'null') {
42
+ return field;
43
+ }
44
+ for (const row of table.data) {
45
+ const type = getDataTypeFromPrimitive(row[field.name]);
46
+ if (type !== 'null') {
47
+ return { ...field, type };
48
+ }
49
+ }
50
+ return field;
51
+ });
52
+ return { ...table.schema, fields };
53
+ }
54
+ /**
55
+ * Deduces a loaders.gl data type from primitive spreadsheet cell values.
56
+ *
57
+ * @param value - Spreadsheet cell value.
58
+ * @returns The matching loaders.gl data type, or `null` for unsupported values.
59
+ */
60
+ function getDataTypeFromPrimitive(value) {
61
+ switch (typeof value) {
62
+ case 'number':
63
+ return 'float64';
64
+ case 'boolean':
65
+ return 'bool';
66
+ case 'string':
67
+ return 'utf8';
68
+ default:
69
+ return value instanceof Date ? 'date-millisecond' : 'null';
70
+ }
71
+ }
72
+ //# sourceMappingURL=convert-excel-rows-to-arrow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convert-excel-rows-to-arrow.js","sourceRoot":"","sources":["../../src/lib/convert-excel-rows-to-arrow.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,iBAAiB,EAAE,iBAAiB,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAAC,IAAgC;IAC3E,MAAM,KAAK,GACT,IAAI,CAAC,MAAM,GAAG,CAAC;QACb,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC;QACzB,CAAC,CAAC,EAAC,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,EAAC,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAC,EAAE,IAAI,EAAE,IAAI,EAAC,CAAC;IAClF,MAAM,MAAM,GAAG,0BAA0B,CAAC,KAAK,CAAC,CAAC;IAEjD,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1D,OAAO;YACL,KAAK,EAAE,aAAa;YACpB,MAAM;YACN,IAAI,EAAE,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SAC5C,CAAC;IACJ,CAAC;IAED,MAAM,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACxD,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QAC7B,iBAAiB,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,iBAAiB,CAAC,WAAW,EAAE,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,SAAS,0BAA0B,CAAC,KAAqB;IACvD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAS,EAAE;QACvD,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,EAAC,GAAG,KAAK,EAAE,IAAI,EAAE,SAAS,EAAC,CAAC;QACrC,CAAC;QAED,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YAC7B,MAAM,IAAI,GAAG,wBAAwB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YACvD,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACpB,OAAO,EAAC,GAAG,KAAK,EAAE,IAAI,EAAC,CAAC;YAC1B,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;IAEH,OAAO,EAAC,GAAG,KAAK,CAAC,MAAO,EAAE,MAAM,EAAC,CAAC;AACpC,CAAC;AAED;;;;;GAKG;AACH,SAAS,wBAAwB,CAAC,KAAc;IAC9C,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC;QACnB,KAAK,SAAS;YACZ,OAAO,MAAM,CAAC;QAChB,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC;QAChB;YACE,OAAO,KAAK,YAAY,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/D,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { ExcelLoaderOptions } from "./excel-loader.js";
2
+ export { ExcelLoader, ExcelWorkerLoader } from "./excel-loader.js";
3
+ //# sourceMappingURL=unbundled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unbundled.d.ts","sourceRoot":"","sources":["../src/unbundled.ts"],"names":[],"mappings":"AAIA,YAAY,EAAC,kBAAkB,EAAC,0BAAuB;AACvD,OAAO,EAAC,WAAW,EAAE,iBAAiB,EAAC,0BAAuB"}
@@ -0,0 +1,5 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ export { ExcelLoader, ExcelWorkerLoader } from "./excel-loader.js";
5
+ //# sourceMappingURL=unbundled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unbundled.js","sourceRoot":"","sources":["../src/unbundled.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,WAAW,EAAE,iBAAiB,EAAC,0BAAuB"}
@@ -1,4 +1,4 @@
1
1
  import { createLoaderWorker } from '@loaders.gl/loader-utils';
2
- import { ExcelLoader } from "../index.js";
3
- createLoaderWorker(ExcelLoader);
2
+ import { ExcelLoaderWithParser } from "../excel-loader-with-parser.js";
3
+ createLoaderWorker(ExcelLoaderWithParser);
4
4
  //# sourceMappingURL=excel-worker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"excel-worker.js","sourceRoot":"","sources":["../../src/workers/excel-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAC,WAAW,EAAC,oBAAiB;AAErC,kBAAkB,CAAC,WAAW,CAAC,CAAC"}
1
+ {"version":3,"file":"excel-worker.js","sourceRoot":"","sources":["../../src/workers/excel-worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAC,qBAAqB,EAAC,uCAAoC;AAElE,kBAAkB,CAAC,qBAAqB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/excel",
3
- "version": "4.4.2",
3
+ "version": "5.0.0-alpha.1",
4
4
  "description": "Framework-independent loader for Excel files",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,6 +30,14 @@
30
30
  "import": "./dist/index.js",
31
31
  "require": "./dist/index.cjs"
32
32
  },
33
+ "./unbundled": {
34
+ "types": "./dist/unbundled.d.ts",
35
+ "import": "./dist/unbundled.js"
36
+ },
37
+ "./bundled": {
38
+ "types": "./dist/bundled.d.ts",
39
+ "import": "./dist/bundled.js"
40
+ },
33
41
  "./excel-worker.js": {
34
42
  "import": "./dist/excel-worker.js"
35
43
  }
@@ -47,12 +55,14 @@
47
55
  "build-worker": "esbuild src/workers/excel-worker.ts --bundle --outfile=dist/excel-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
48
56
  },
49
57
  "dependencies": {
50
- "@loaders.gl/loader-utils": "4.4.2",
51
- "@loaders.gl/schema": "4.4.2",
58
+ "@loaders.gl/loader-utils": "5.0.0-alpha.1",
59
+ "@loaders.gl/schema": "5.0.0-alpha.1",
60
+ "@loaders.gl/schema-utils": "5.0.0-alpha.1",
61
+ "apache-arrow": ">= 17.0.0",
52
62
  "xlsx": "^0.18.5"
53
63
  },
54
64
  "peerDependencies": {
55
- "@loaders.gl/core": "~4.4.0"
65
+ "@loaders.gl/core": "~5.0.0-alpha.0"
56
66
  },
57
- "gitHead": "1c9649781db0403dbf7c3f1224bbeec77bd812eb"
67
+ "gitHead": "77a55028e8204e09df1258f10cb61ed35353b258"
58
68
  }
package/src/bundled.ts ADDED
@@ -0,0 +1,9 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ export type {ExcelLoaderOptions} from './excel-loader-with-parser';
6
+ export {
7
+ ExcelLoaderWithParser as ExcelLoader,
8
+ ExcelWorkerLoaderWithParser as ExcelWorkerLoader
9
+ } from './excel-loader-with-parser';
@@ -11,6 +11,8 @@ export const ExcelFormat = {
11
11
  name: 'Excel',
12
12
  id: 'excel',
13
13
  module: 'excel',
14
+ encoding: 'zip',
15
+ format: 'excel',
14
16
  extensions: ['xls', 'xlsb', 'xlsm', 'xlsx'],
15
17
  mimeTypes: [
16
18
  'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
@@ -0,0 +1,51 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+
5
+ import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
6
+ import type {ArrowTable, ObjectRowTable} from '@loaders.gl/schema';
7
+ import {parseExcel} from './lib/parse-excel';
8
+ import {convertExcelRowsToArrowTable} from './lib/convert-excel-rows-to-arrow';
9
+ import {ExcelWorkerLoader as ExcelWorkerLoaderMetadata} from './excel-loader';
10
+ import {ExcelLoader as ExcelLoaderMetadata} from './excel-loader';
11
+
12
+ const {preload: _ExcelWorkerLoaderPreload, ...ExcelWorkerLoaderMetadataWithoutPreload} =
13
+ ExcelWorkerLoaderMetadata;
14
+ const {preload: _ExcelLoaderPreload, ...ExcelLoaderMetadataWithoutPreload} = ExcelLoaderMetadata;
15
+
16
+ /** Options for parsing Excel worksheets. */
17
+ export type ExcelLoaderOptions = LoaderOptions & {
18
+ /** Options for ExcelLoaderWithParser */
19
+ excel?: {
20
+ /** Selects row-table output or Apache Arrow output. */
21
+ shape?: /* 'array-row-table' | */ 'object-row-table' | 'arrow-table';
22
+ /** Specify which sheet to load, if omitted loads default sheet. */
23
+ sheet?: string;
24
+ /** Override the URL to the worker bundle (by default loads from unpkg.com). */
25
+ workerUrl?: string;
26
+ };
27
+ };
28
+
29
+ /** Worker loader for Excel files. */
30
+ export const ExcelWorkerLoaderWithParser = {
31
+ ...ExcelWorkerLoaderMetadataWithoutPreload
32
+ } as const satisfies Loader<ObjectRowTable | ArrowTable, never, ExcelLoaderOptions>;
33
+
34
+ /** Loader for Excel files. */
35
+ export const ExcelLoaderWithParser = {
36
+ ...ExcelLoaderMetadataWithoutPreload,
37
+ async parse(
38
+ arrayBuffer: ArrayBuffer,
39
+ options?: ExcelLoaderOptions
40
+ ): Promise<ObjectRowTable | ArrowTable> {
41
+ const excelOptions = {
42
+ ...options,
43
+ excel: {...ExcelLoaderWithParser.options.excel, ...options?.excel}
44
+ } as ExcelLoaderOptions;
45
+ const rows = parseExcel(arrayBuffer, excelOptions);
46
+ if (excelOptions.excel?.shape === 'arrow-table') {
47
+ return convertExcelRowsToArrowTable(rows);
48
+ }
49
+ return {shape: 'object-row-table', data: rows};
50
+ }
51
+ } as const satisfies LoaderWithParser<ObjectRowTable | ArrowTable, never, ExcelLoaderOptions>;
@@ -2,33 +2,37 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
 
5
- import type {Loader, LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
6
- import type {ObjectRowTable} from '@loaders.gl/schema';
7
- import {parseExcel} from './lib/parse-excel';
5
+ import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';
6
+ import type {ArrowTable, ObjectRowTable} from '@loaders.gl/schema';
8
7
  import {ExcelFormat} from './excel-format';
9
8
 
10
9
  // __VERSION__ is injected by babel-plugin-version-inline
11
10
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
12
11
  const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
13
12
 
13
+ /** Options for parsing Excel worksheets. */
14
14
  export type ExcelLoaderOptions = LoaderOptions & {
15
15
  /** Options for ExcelLoader */
16
16
  excel?: {
17
- /** Format of returned data */
18
- shape?: /* 'array-row-table' | */ 'object-row-table';
19
- /** Specify which sheet to load, if omitted loads default sheet */
17
+ /** Selects row-table output or Apache Arrow output. */
18
+ shape?: /* 'array-row-table' | */ 'object-row-table' | 'arrow-table';
19
+ /** Specify which sheet to load, if omitted loads default sheet. */
20
20
  sheet?: string;
21
- /** Override the URL to the worker bundle (by default loads from unpkg.com) */
21
+ /** Override the URL to the worker bundle (by default loads from unpkg.com). */
22
22
  workerUrl?: string;
23
23
  };
24
24
  };
25
25
 
26
- /**
27
- * Worker Loader for Excel files
28
- */
26
+ /** Preloads the parser-bearing Excel loader implementation. */
27
+ async function preload() {
28
+ const {ExcelLoaderWithParser} = await import('./excel-loader-with-parser');
29
+ return ExcelLoaderWithParser;
30
+ }
31
+
32
+ /** Metadata-only worker loader for Excel files. */
29
33
  export const ExcelWorkerLoader = {
30
34
  ...ExcelFormat,
31
- dataType: null as unknown as ObjectRowTable,
35
+ dataType: null as unknown as ObjectRowTable | ArrowTable,
32
36
  batchType: null as never,
33
37
  version: VERSION,
34
38
  worker: true,
@@ -37,16 +41,12 @@ export const ExcelWorkerLoader = {
37
41
  shape: 'object-row-table',
38
42
  sheet: undefined // Load default Sheet
39
43
  }
40
- }
41
- } as const satisfies Loader<ObjectRowTable, never, ExcelLoaderOptions>;
44
+ },
45
+ preload
46
+ } as const satisfies Loader<ObjectRowTable | ArrowTable, never, ExcelLoaderOptions>;
42
47
 
43
- /**
44
- * Loader for Excel files
45
- */
48
+ /** Metadata-only loader for Excel files. */
46
49
  export const ExcelLoader = {
47
50
  ...ExcelWorkerLoader,
48
- async parse(arrayBuffer: ArrayBuffer, options?: ExcelLoaderOptions): Promise<ObjectRowTable> {
49
- const data = parseExcel(arrayBuffer, options);
50
- return {shape: 'object-row-table', data};
51
- }
52
- } as const satisfies LoaderWithParser<ObjectRowTable, never, ExcelLoaderOptions>;
51
+ preload
52
+ } as const satisfies Loader<ObjectRowTable | ArrowTable, never, ExcelLoaderOptions>;