@opencraw/office-reader 0.0.2

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 (34) hide show
  1. package/README.md +201 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.esm.js +6 -0
  4. package/dist/pptx.d.ts +1 -0
  5. package/dist/pptx.esm.js +5 -0
  6. package/dist/read-pptx.use-case.esm.js +591 -0
  7. package/dist/read-source.client.esm.js +289 -0
  8. package/dist/read-xlsx.use-case.esm.js +381 -0
  9. package/dist/src/index.d.ts +9 -0
  10. package/dist/src/ooxml-package/index.d.ts +7 -0
  11. package/dist/src/ooxml-package/ooxml-package.client.d.ts +47 -0
  12. package/dist/src/ooxml-package/relationships.mapper.d.ts +27 -0
  13. package/dist/src/ooxml-package/xml-walk.algorithm.d.ts +37 -0
  14. package/dist/src/presentation/chart.mapper.d.ts +13 -0
  15. package/dist/src/presentation/deck.model.d.ts +56 -0
  16. package/dist/src/presentation/index.d.ts +6 -0
  17. package/dist/src/presentation/notes.mapper.d.ts +9 -0
  18. package/dist/src/presentation/placeholder-geometry.mapper.d.ts +53 -0
  19. package/dist/src/presentation/read-pptx.use-case.d.ts +32 -0
  20. package/dist/src/presentation/slide.mapper.d.ts +24 -0
  21. package/dist/src/read-error/index.d.ts +3 -0
  22. package/dist/src/read-error/office-read.error.d.ts +29 -0
  23. package/dist/src/source-bytes/index.d.ts +3 -0
  24. package/dist/src/source-bytes/read-source.client.d.ts +18 -0
  25. package/dist/src/spreadsheet/cell-value.algorithm.d.ts +47 -0
  26. package/dist/src/spreadsheet/index.d.ts +6 -0
  27. package/dist/src/spreadsheet/number-formats.mapper.d.ts +10 -0
  28. package/dist/src/spreadsheet/read-xlsx.use-case.d.ts +27 -0
  29. package/dist/src/spreadsheet/shared-strings.mapper.d.ts +10 -0
  30. package/dist/src/spreadsheet/workbook.model.d.ts +35 -0
  31. package/dist/src/spreadsheet/worksheet.mapper.d.ts +23 -0
  32. package/dist/xlsx.d.ts +1 -0
  33. package/dist/xlsx.esm.js +5 -0
  34. package/package.json +77 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * How much a package may inflate to. fflate sizes each entry by the size its
3
+ * zip header declares, and never inflates past it: a header that lies about a
4
+ * bomb gets a truncated entry, not gigabytes. Capping the declared sizes is
5
+ * therefore enough.
6
+ */
7
+ export interface PackageLimits {
8
+ /** Bytes one entry may declare. Default 256 MiB. */
9
+ entryBytes?: number;
10
+ /** Bytes the entries read from one file may declare together. Default 512 MiB. */
11
+ totalBytes?: number;
12
+ }
13
+ /** An Office Open XML package: a zip of XML parts, read part by part. */
14
+ export declare class OoxmlPackage {
15
+ private readonly bytes;
16
+ private readonly entries;
17
+ private readonly limits;
18
+ /**
19
+ * Opens a package, refusing what is not one with the reason: a legacy or
20
+ * password-protected Office file (both are OLE compound files), an
21
+ * OpenDocument file, anything else that is not a zip.
22
+ *
23
+ * @param bytes - The file.
24
+ * @param limits - How much it may inflate to.
25
+ * @returns The package; no part is inflated yet.
26
+ * @throws OfficeReadError
27
+ */
28
+ static open(bytes: Uint8Array, limits?: PackageLimits): OoxmlPackage;
29
+ private declared;
30
+ /**
31
+ * Entries by part key: part names are case-insensitive (OPC), and some
32
+ * generators store `xl\\sharedstrings.xml` for `xl/sharedStrings.xml`.
33
+ */
34
+ private constructor();
35
+ /** The names of every part, as stored. */
36
+ get names(): string[];
37
+ has(name: string): boolean;
38
+ /**
39
+ * Inflates one part as UTF-8 text.
40
+ *
41
+ * @param name - The part, as stored (`xl/workbook.xml`).
42
+ * @returns The text; empty when the part is missing.
43
+ * @throws OfficeReadError: `too-large` past the limits, `malformed` when the part does not inflate.
44
+ */
45
+ text(name: string): string;
46
+ }
47
+ //# sourceMappingURL=ooxml-package.client.d.ts.map
@@ -0,0 +1,27 @@
1
+ import type { OoxmlPackage } from './ooxml-package.client.js';
2
+ /** A link from one part to another, from the part's `_rels/<part>.rels`. */
3
+ export interface Relationship {
4
+ id: string;
5
+ /** The type's last segment (`worksheet`, `sharedStrings`, `slide`): the transitional and strict namespaces differ only before it. */
6
+ type: string;
7
+ /** The target part's name within the package (`xl/worksheets/sheet1.xml`). */
8
+ target: string;
9
+ }
10
+ /**
11
+ * The relationships of a part, targets resolved to part names. External
12
+ * targets (hyperlinks) are left out.
13
+ *
14
+ * @param pkg - The package.
15
+ * @param part - The part (`xl/workbook.xml`), or `''` for the package's own.
16
+ * @returns The relationships by id.
17
+ */
18
+ export declare function relationshipsOf(pkg: OoxmlPackage, part: string): Map<string, Relationship>;
19
+ /**
20
+ * The first relationship of a type.
21
+ *
22
+ * @param relationships - A part's relationships.
23
+ * @param type - The type's last segment.
24
+ * @returns It, or `undefined`.
25
+ */
26
+ export declare function relationshipOfType(relationships: ReadonlyMap<string, Relationship>, type: string): Relationship | undefined;
27
+ //# sourceMappingURL=relationships.mapper.d.ts.map
@@ -0,0 +1,37 @@
1
+ /** Callbacks for {@link walkXml}; element names arrive without their namespace prefix. */
2
+ export interface XmlHandlers {
3
+ open?: (name: string, attributes: Record<string, string>) => void;
4
+ text?: (text: string) => void;
5
+ close?: (name: string) => void;
6
+ }
7
+ /**
8
+ * Walks an XML part as a stream of events, never building a tree, so a sheet
9
+ * of a million cells costs its text, not a DOM. htmlparser2 does no DTD
10
+ * processing: entities a document declares are not expanded (no "billion
11
+ * laughs") and no external entity is fetched (no XXE); only the XML built-ins
12
+ * and numeric references decode.
13
+ *
14
+ * Element names lose their prefix (`x:c`, `p:sp` → `c`, `sp`): generators
15
+ * choose prefixes freely. Attributes keep theirs; read a namespaced one with
16
+ * {@link namespacedAttribute}.
17
+ *
18
+ * @param xml - The part's text.
19
+ * @param handlers - What to do on each event.
20
+ */
21
+ export declare function walkXml(xml: string, handlers: XmlHandlers): void;
22
+ /**
23
+ * An attribute in a namespace whatever its prefix (`r:id`, `ns1:id`).
24
+ *
25
+ * @param attributes - The element's attributes.
26
+ * @param name - The local name (`id`).
27
+ * @returns The value, or `undefined`.
28
+ */
29
+ export declare function namespacedAttribute(attributes: Record<string, string>, name: string): string | undefined;
30
+ /**
31
+ * Whether an XML boolean attribute is on (`1`, `true`, `on`).
32
+ *
33
+ * @param value - The attribute's value.
34
+ * @returns Whether it is set.
35
+ */
36
+ export declare function isOn(value: string | undefined): boolean;
37
+ //# sourceMappingURL=xml-walk.algorithm.d.ts.map
@@ -0,0 +1,13 @@
1
+ import type { ValueMode } from '../spreadsheet/index.js';
2
+ import type { SlideChart } from './deck.model.js';
3
+ /**
4
+ * Reads a chart part: its type, title and series, from the values the chart
5
+ * caches next to its formulas (`c:strCache`, `c:numCache`), so the embedded
6
+ * workbook is never needed.
7
+ *
8
+ * @param xml - The chart part.
9
+ * @param mode - `typed`: values as numbers (`null` where missing); `text`: as text.
10
+ * @returns The chart.
11
+ */
12
+ export declare function readChart(xml: string, mode: ValueMode): SlideChart<number | null | string>;
13
+ //# sourceMappingURL=chart.mapper.d.ts.map
@@ -0,0 +1,56 @@
1
+ import type { Sheet } from '../spreadsheet/index.js';
2
+ /** A text box on a slide, in points from the slide's top-left corner. */
3
+ export interface SlideShape {
4
+ x: number;
5
+ y: number;
6
+ width: number;
7
+ height: number;
8
+ /** Its paragraphs joined by line breaks. */
9
+ text: string;
10
+ /** The placeholder it fills (`title`, `body`, `subTitle`…), when it fills one. */
11
+ placeholder?: string;
12
+ }
13
+ /** One series of a chart, from the values the chart keeps with it (its cache). */
14
+ export interface ChartSeries<Value = number | null> {
15
+ name: string;
16
+ categories: string[];
17
+ /** One per category; `typed`: numbers, `null` where a point is missing; `text`: shortest round-trip text, `''` where missing. */
18
+ values: Value[];
19
+ }
20
+ /** A chart on a slide. */
21
+ export interface SlideChart<Value = number | null> {
22
+ /** `bar`, `line`, `pie`, `area`, `scatter`, `doughnut`… (the chart element's name without `Chart`). */
23
+ type: string;
24
+ title?: string;
25
+ series: ChartSeries<Value>[];
26
+ }
27
+ /** One slide. */
28
+ export interface Slide<Value = number | null> {
29
+ /** Its position in the presentation, from 1. */
30
+ number: number;
31
+ /** The text of its title placeholder. */
32
+ title?: string;
33
+ /** Hidden in a slideshow. */
34
+ hidden: boolean;
35
+ /** Its text boxes in reading order (top to bottom, left to right); slide numbers, dates and footers left out. */
36
+ shapes: SlideShape[];
37
+ /** Its tables, as sheets: `name` is `table 1`, `table 2`…; merged cells in `merges`. */
38
+ tables: Sheet<string>[];
39
+ charts: SlideChart<Value>[];
40
+ /** The speaker notes. */
41
+ notes: string;
42
+ }
43
+ /** A presentation read into slides. */
44
+ export interface Deck<Value = number | null> {
45
+ /** The slide size, in points. */
46
+ width: number;
47
+ height: number;
48
+ slides: Slide<Value>[];
49
+ }
50
+ /** Which slides to read: numbers (from 1), a pattern on titles, or a test. */
51
+ export type SlideFilter = number[] | RegExp | ((slide: {
52
+ number: number;
53
+ title: string;
54
+ hidden: boolean;
55
+ }) => boolean);
56
+ //# sourceMappingURL=deck.model.d.ts.map
@@ -0,0 +1,6 @@
1
+ export { readPptx } from './read-pptx.use-case.js';
2
+ export type { ReadPptxOptions } from './read-pptx.use-case.js';
3
+ export type { Deck, Slide, SlideShape, SlideChart, ChartSeries, SlideFilter } from './deck.model.js';
4
+ export { OfficeReadError } from '../read-error/index.js';
5
+ export type { OfficeReadErrorCode } from '../read-error/index.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The speaker notes of a notes-slide part: the text of its body placeholder
3
+ * (the slide image and the slide number placeholders are left out).
4
+ *
5
+ * @param xml - The notes-slide part.
6
+ * @returns The notes, paragraphs joined by line breaks.
7
+ */
8
+ export declare function readNotes(xml: string): string;
9
+ //# sourceMappingURL=notes.mapper.d.ts.map
@@ -0,0 +1,53 @@
1
+ /** A rectangle in EMU (English Metric Units: 12 700 per point). */
2
+ export interface Box {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ /** Which placeholder a shape fills. */
9
+ export interface PlaceholderKey {
10
+ type: string;
11
+ idx?: string;
12
+ }
13
+ /** Where a layout or a master puts its placeholders. */
14
+ export interface PlaceholderBoxes {
15
+ byIdx: Map<string, Box>;
16
+ byType: Map<string, Box>;
17
+ }
18
+ /**
19
+ * The positioned placeholders of a slide layout or master. A slide's title or
20
+ * body usually carries no position of its own: it inherits it from the
21
+ * placeholder with the same index in its layout, else the same type, else the
22
+ * master's.
23
+ *
24
+ * @param xml - The layout or master part.
25
+ * @returns Its placeholder boxes.
26
+ */
27
+ export declare function placeholderBoxes(xml: string): PlaceholderBoxes;
28
+ /**
29
+ * Where an unpositioned placeholder sits: its layout's placeholder with the
30
+ * same index, else the same type, else the master's of that type.
31
+ *
32
+ * @param key - The placeholder.
33
+ * @param layout - The slide's layout.
34
+ * @param master - The layout's master.
35
+ * @returns The box, or `undefined` when neither places it.
36
+ */
37
+ export declare function inheritedBox(key: PlaceholderKey, layout: PlaceholderBoxes, master: PlaceholderBoxes): Box | undefined;
38
+ /**
39
+ * Reads `a:off` and `a:ext` into a box.
40
+ *
41
+ * @param name - The element's local name.
42
+ * @param attributes - Its attributes.
43
+ * @param box - The box to fill.
44
+ */
45
+ export declare function readGeometry(name: string, attributes: Record<string, string>, box: Partial<Box>): void;
46
+ /**
47
+ * Whether a box has all four numbers.
48
+ *
49
+ * @param box - A box being read.
50
+ * @returns Whether it is complete.
51
+ */
52
+ export declare function isBox(box: Partial<Box> | undefined): box is Box;
53
+ //# sourceMappingURL=placeholder-geometry.mapper.d.ts.map
@@ -0,0 +1,32 @@
1
+ import type { PackageLimits } from '../ooxml-package/index.js';
2
+ import type { OfficeSource } from '../source-bytes/index.js';
3
+ import type { ValueMode } from '../spreadsheet/index.js';
4
+ import type { Deck, SlideFilter } from './deck.model.js';
5
+ /** How to read a presentation. */
6
+ export interface ReadPptxOptions {
7
+ /** Which slides to read; default all. */
8
+ slides?: SlideFilter;
9
+ /** `typed` (default): chart values as numbers; `text`: as text. */
10
+ values?: ValueMode;
11
+ /** Read speaker notes; default true. */
12
+ notes?: boolean;
13
+ /** Read charts; default true. */
14
+ charts?: boolean;
15
+ /** How much the file may inflate to. */
16
+ limits?: PackageLimits;
17
+ }
18
+ /**
19
+ * Reads a `.pptx` presentation (also `.pptm`, `.ppsx`): every slide's text
20
+ * boxes with their positions, its tables, its charts' data and its notes.
21
+ * Slides come in presentation order, not file order.
22
+ *
23
+ * @param source - A path, bytes, a Blob or a stream (see {@link OfficeSource}).
24
+ * @param options - Which slides, which value mode, what to leave out, which limits.
25
+ * @returns The deck.
26
+ * @throws OfficeReadError for a file that is not a readable presentation: `legacy-format` (`.ppt`), `encrypted`, `unsupported-format` (`.odp`), `not-pptx`, `too-large`…
27
+ */
28
+ export declare function readPptx(source: OfficeSource, options: ReadPptxOptions & {
29
+ values: 'text';
30
+ }): Promise<Deck<string>>;
31
+ export declare function readPptx(source: OfficeSource, options?: ReadPptxOptions): Promise<Deck>;
32
+ //# sourceMappingURL=read-pptx.use-case.d.ts.map
@@ -0,0 +1,24 @@
1
+ import type { Sheet } from '../spreadsheet/index.js';
2
+ import type { SlideShape } from './deck.model.js';
3
+ import type { Box, PlaceholderKey } from './placeholder-geometry.mapper.js';
4
+ /** What a slide part holds, before its charts and notes are read. */
5
+ export interface SlideContent {
6
+ title?: string;
7
+ hidden: boolean;
8
+ shapes: SlideShape[];
9
+ tables: Sheet<string>[];
10
+ /** The relationship ids of its charts. */
11
+ chartIds: string[];
12
+ }
13
+ /**
14
+ * Reads a slide part: its text boxes with their positions (group transforms
15
+ * applied; a placeholder without a position of its own takes the one
16
+ * `placeholderBox` gives), its tables with their merged cells, the ids of its
17
+ * charts, its title and whether it is hidden.
18
+ *
19
+ * @param xml - The slide part.
20
+ * @param placeholderBox - Where an unpositioned placeholder sits (from the layout and master).
21
+ * @returns The content.
22
+ */
23
+ export declare function readSlide(xml: string, placeholderBox: (key: PlaceholderKey) => Box | undefined): SlideContent;
24
+ //# sourceMappingURL=slide.mapper.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { OfficeReadError } from './office-read.error.js';
2
+ export type { OfficeReadErrorCode } from './office-read.error.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,29 @@
1
+ /** Why a file could not be read. */
2
+ export type OfficeReadErrorCode =
3
+ /** The source is not something bytes can be read from (an `http:` URL, a number…). */
4
+ 'bad-source' |
5
+ /** The bytes are not a zip package, nor a legacy Office file. */
6
+ 'not-zip' |
7
+ /** An entry, or the entries read together, declare more bytes than the limits allow. */
8
+ 'too-large' |
9
+ /** A legacy binary Office file (`.xls`, `.ppt`, `.doc`). */
10
+ 'legacy-format' |
11
+ /** A password-protected Office file. */
12
+ 'encrypted' |
13
+ /** An OpenDocument file (`.ods`, `.odp`). */
14
+ 'unsupported-format' |
15
+ /** A zip package that is not a spreadsheet. */
16
+ 'not-xlsx' |
17
+ /** A zip package that is not a presentation. */
18
+ 'not-pptx' |
19
+ /** A part the package needs is missing or malformed. */
20
+ 'malformed';
21
+ /** A file `office-reader` cannot read, with a `code` to branch on and a message that says what to do. */
22
+ export declare class OfficeReadError extends Error {
23
+ readonly code: OfficeReadErrorCode;
24
+ readonly name = "OfficeReadError";
25
+ constructor(code: OfficeReadErrorCode, message: string, options?: {
26
+ cause?: unknown;
27
+ });
28
+ }
29
+ //# sourceMappingURL=office-read.error.d.ts.map
@@ -0,0 +1,3 @@
1
+ export { readSource } from './read-source.client.js';
2
+ export type { OfficeSource } from './read-source.client.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Where a file comes from: a path or a `file:` URL (Node only), bytes in any
3
+ * binary form, a `Blob` or `File`, a web `ReadableStream`, or any async
4
+ * iterable of chunks (Node streams included). A string is always a path.
5
+ */
6
+ export type OfficeSource = string | URL | Uint8Array | ArrayBuffer | ArrayBufferView | Blob | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
7
+ /**
8
+ * Reads a source into one `Uint8Array`. Only a path or a `file:` URL touches
9
+ * the file system, through a dynamic import, so the package runs in browsers,
10
+ * workers and edge runtimes too. Fetching is the caller's job: an `http:` URL
11
+ * is refused.
12
+ *
13
+ * @param source - The file.
14
+ * @returns Its bytes.
15
+ * @throws OfficeReadError (`bad-source`) for anything else.
16
+ */
17
+ export declare function readSource(source: OfficeSource): Promise<Uint8Array>;
18
+ //# sourceMappingURL=read-source.client.d.ts.map
@@ -0,0 +1,47 @@
1
+ import type { CellValue, ValueMode } from './workbook.model.js';
2
+ /** A cell as the sheet stores it. */
3
+ export interface StoredCell {
4
+ /** The `t` attribute: `n` (default), `s`, `str`, `inlineStr`, `b`, `e`, `d`. */
5
+ type: string;
6
+ /** The `<v>` text, or the inline string. */
7
+ value: string;
8
+ /** How its number format reads it. */
9
+ format: NumberFormatKind;
10
+ }
11
+ /** What a number format makes of a number: a date, a time of day, or a plain number. */
12
+ export type NumberFormatKind = 'number' | 'date' | 'time';
13
+ /** What reading a cell needs besides the cell. */
14
+ export interface CellContext {
15
+ sharedStrings: readonly string[];
16
+ date1904: boolean;
17
+ }
18
+ /**
19
+ * A stored cell as a typed value.
20
+ *
21
+ * @param cell - The cell.
22
+ * @param context - Shared strings and the date system.
23
+ * @returns The value; `null` for an empty cell.
24
+ */
25
+ export declare function typedValue(cell: StoredCell, context: CellContext): CellValue;
26
+ /**
27
+ * A stored cell as canonical text: numbers in their shortest round-trip form
28
+ * (`78.6`, not `78.599999999999994`), dates as ISO (`2026-06-01`, or
29
+ * `2026-06-01T09:30:00` with a time, `09:30:00` for a time of day), booleans
30
+ * as `true`/`false`, errors as written, `''` when empty. Display formats are
31
+ * not applied: a percentage stays a fraction (`0.125`).
32
+ *
33
+ * @param cell - The cell.
34
+ * @param context - Shared strings and the date system.
35
+ * @returns The text.
36
+ */
37
+ export declare function textValue(cell: StoredCell, context: CellContext): string;
38
+ /**
39
+ * Reads a cell in the mode asked for.
40
+ *
41
+ * @param cell - The cell.
42
+ * @param context - Shared strings and the date system.
43
+ * @param mode - `typed` or `text`.
44
+ * @returns The value.
45
+ */
46
+ export declare function cellValue(cell: StoredCell, context: CellContext, mode: ValueMode): CellValue;
47
+ //# sourceMappingURL=cell-value.algorithm.d.ts.map
@@ -0,0 +1,6 @@
1
+ export { readXlsx } from './read-xlsx.use-case.js';
2
+ export type { ReadXlsxOptions } from './read-xlsx.use-case.js';
3
+ export type { CellValue, Sheet, Workbook, ValueMode, SheetFilter } from './workbook.model.js';
4
+ export { OfficeReadError } from '../read-error/index.js';
5
+ export type { OfficeReadErrorCode } from '../read-error/index.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,10 @@
1
+ import type { NumberFormatKind } from './cell-value.algorithm.js';
2
+ /**
3
+ * What each cell style (`s`, an index into `cellXfs`) makes of a number, from
4
+ * `styles.xml`: only dates and times need telling apart from numbers.
5
+ *
6
+ * @param stylesXml - The styles part; empty when the workbook has none.
7
+ * @returns The kind per style index.
8
+ */
9
+ export declare function formatKinds(stylesXml: string): NumberFormatKind[];
10
+ //# sourceMappingURL=number-formats.mapper.d.ts.map
@@ -0,0 +1,27 @@
1
+ import type { PackageLimits } from '../ooxml-package/index.js';
2
+ import type { OfficeSource } from '../source-bytes/index.js';
3
+ import type { SheetFilter, ValueMode, Workbook } from './workbook.model.js';
4
+ /** How to read a workbook. */
5
+ export interface ReadXlsxOptions {
6
+ /** Which sheets to read; default all. Unselected sheets are never inflated. */
7
+ sheets?: SheetFilter;
8
+ /** `typed` (default): numbers, booleans, dates as values; `text`: every cell as canonical text. */
9
+ values?: ValueMode;
10
+ /** How much the file may inflate to. */
11
+ limits?: PackageLimits;
12
+ }
13
+ /**
14
+ * Reads an `.xlsx` (or `.xlsm`) workbook: every worksheet's cells, with the
15
+ * merged ranges and hidden rows a person would see. Formulas give their
16
+ * cached value; nothing is evaluated. Display formats are not applied.
17
+ *
18
+ * @param source - A path, bytes, a Blob or a stream (see {@link OfficeSource}).
19
+ * @param options - Which sheets, which value mode, which limits.
20
+ * @returns The workbook.
21
+ * @throws OfficeReadError for a file that is not a readable workbook: `legacy-format` (`.xls`), `encrypted`, `unsupported-format` (`.ods`), `not-xlsx`, `too-large`…
22
+ */
23
+ export declare function readXlsx(source: OfficeSource, options: ReadXlsxOptions & {
24
+ values: 'text';
25
+ }): Promise<Workbook<string>>;
26
+ export declare function readXlsx(source: OfficeSource, options?: ReadXlsxOptions): Promise<Workbook>;
27
+ //# sourceMappingURL=read-xlsx.use-case.d.ts.map
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The shared string table: the text of every `<si>`, rich-text runs joined.
3
+ * Phonetic guides (`<rPh>`, the furigana over Japanese text) are not part of
4
+ * the text and are left out.
5
+ *
6
+ * @param xml - The shared strings part; empty when the workbook has none.
7
+ * @returns The strings, by index.
8
+ */
9
+ export declare function sharedStrings(xml: string): string[];
10
+ //# sourceMappingURL=shared-strings.mapper.d.ts.map
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A cell as `values: 'typed'` reads it: text, a number, a boolean, a date
3
+ * (a `Date` holding the wall-clock time as UTC: spreadsheets have no time
4
+ * zones), `null` when empty, or an error (`#DIV/0!`).
5
+ */
6
+ export type CellValue = string | number | boolean | Date | null | {
7
+ error: string;
8
+ };
9
+ /** One worksheet: its cells as stored, plus what a person sees differently (hidden rows, merged ranges). */
10
+ export interface Sheet<Cell = CellValue> {
11
+ name: string;
12
+ /** Hidden or very hidden in the workbook. */
13
+ hidden: boolean;
14
+ /** Top to bottom from row 1; each row runs to its last stored cell (rows can be ragged). */
15
+ rows: Cell[][];
16
+ /** Hidden rows, 0-based. */
17
+ hiddenRows: number[];
18
+ /** Merged ranges as A1 references (`B10:B13`); a range's value sits in its top-left cell only, as the file stores it. */
19
+ merges: string[];
20
+ }
21
+ /** A workbook read into sheets. */
22
+ export interface Workbook<Cell = CellValue> {
23
+ /** Whether the workbook counts dates from 1904 (old Mac Excel) instead of 1900. */
24
+ date1904: boolean;
25
+ /** The worksheets, in workbook order (chart sheets are left out). */
26
+ sheets: Sheet<Cell>[];
27
+ }
28
+ /** `typed`: numbers, booleans, dates as values; `text`: every cell as canonical text. */
29
+ export type ValueMode = 'typed' | 'text';
30
+ /** Which sheets to read: a name, a pattern, or a test. Unselected sheets are never inflated. */
31
+ export type SheetFilter = string | RegExp | ((sheet: {
32
+ name: string;
33
+ hidden: boolean;
34
+ }) => boolean);
35
+ //# sourceMappingURL=workbook.model.d.ts.map
@@ -0,0 +1,23 @@
1
+ import type { CellContext, NumberFormatKind } from './cell-value.algorithm.js';
2
+ import type { CellValue, ValueMode } from './workbook.model.js';
3
+ /** A worksheet part, read. */
4
+ export interface WorksheetContent {
5
+ rows: CellValue[][];
6
+ hiddenRows: number[];
7
+ merges: string[];
8
+ }
9
+ /**
10
+ * Reads a worksheet part as a stream: rows of cells (formulas give their
11
+ * cached value, never evaluated), hidden rows and merged ranges. A row or a
12
+ * cell without its reference (some generators leave `r` out) follows the one
13
+ * before it.
14
+ *
15
+ * @param xml - The worksheet part.
16
+ * @param context - Shared strings, number format kinds and the date system.
17
+ * @param mode - `typed` or `text`.
18
+ * @returns The content.
19
+ */
20
+ export declare function readWorksheet(xml: string, context: CellContext & {
21
+ formats: readonly NumberFormatKind[];
22
+ }, mode: ValueMode): WorksheetContent;
23
+ //# sourceMappingURL=worksheet.mapper.d.ts.map
package/dist/xlsx.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/spreadsheet/index.js";
@@ -0,0 +1,5 @@
1
+ export { r as readXlsx } from './read-xlsx.use-case.esm.js';
2
+ export { O as OfficeReadError } from './read-source.client.esm.js';
3
+ import 'fflate';
4
+ import 'htmlparser2';
5
+ //# sourceMappingURL=xlsx.esm.js.map
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@opencraw/office-reader",
3
+ "version": "0.0.2",
4
+ "type": "module",
5
+ "main": "./dist/index.esm.js",
6
+ "module": "./dist/index.esm.js",
7
+ "types": "./dist/src/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": {
11
+ "types": "./dist/src/index.d.ts",
12
+ "import": "./dist/index.esm.js",
13
+ "default": "./dist/index.esm.js"
14
+ },
15
+ "./xlsx": {
16
+ "types": "./dist/src/spreadsheet/index.d.ts",
17
+ "import": "./dist/xlsx.esm.js",
18
+ "default": "./dist/xlsx.esm.js"
19
+ },
20
+ "./pptx": {
21
+ "types": "./dist/src/presentation/index.d.ts",
22
+ "import": "./dist/pptx.esm.js",
23
+ "default": "./dist/pptx.esm.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "!**/*.tsbuildinfo",
29
+ "!**/*.d.ts.map",
30
+ "!**/*.js.map"
31
+ ],
32
+ "dependencies": {
33
+ "fflate": "^0.8.3",
34
+ "htmlparser2": "^10.1.0"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "description": "Reads Office files (.xlsx workbooks, .pptx presentations) into plain objects: cells with merged ranges and hidden rows, slides with positioned text, tables and chart data. No Node built-ins beyond reading a path: runs in Node, browsers, workers and edge runtimes.",
40
+ "license": "MIT",
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/russoedu/open.craw.git",
44
+ "directory": "packages/office-reader"
45
+ },
46
+ "keywords": [
47
+ "xlsx",
48
+ "excel",
49
+ "spreadsheet",
50
+ "pptx",
51
+ "powerpoint",
52
+ "presentation",
53
+ "office",
54
+ "ooxml",
55
+ "reader",
56
+ "parser",
57
+ "json"
58
+ ],
59
+ "engines": {
60
+ "node": ">=20"
61
+ },
62
+ "sideEffects": false,
63
+ "nx": {
64
+ "targets": {
65
+ "e2e": {
66
+ "executor": "nx:run-commands",
67
+ "dependsOn": [
68
+ "build"
69
+ ],
70
+ "options": {
71
+ "command": "tsc -p tsconfig.e2e.json && jest --config jest.e2e.config.cts",
72
+ "cwd": "packages/office-reader"
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }