@genomdev/office-core
The parts only Word, Excel and PowerPoint need: OPC, DrawingML, Office Art, OLE2, the Excel formula language
327 exported symbols across 6 entry points
@genomdev/office-core— 211 exports@genomdev/office-core/ole— 20 exports@genomdev/office-core/formula— 69 exports@genomdev/office-core/media— 10 exports@genomdev/office-core/view— 7 exports@genomdev/office-core/testing— 10 exports
@genomdev/office-core
Classes
Resolves package parts into URLs usable by `<img>` and CSS, and owns their lifetime. Two problems are solved here that every naive implementation gets wrong. First, leaks: an object URL is a document-lifetime handle to the underlying blob. A viewer that creates one per image render and never revokes it keeps every version of every image alive for as long as the page lives. The resolver hands out URLs and revokes all of them on {@link dispose}. Second, duplication: the same image is routinely referenced from many places (a logo in a header repeated on every page). Caching by part name means the bytes are inflated once and the browser decodes one image instead of dozens. How a URL is minted is not decided here — see {@link MediaUrlFactory}. That indirection is what lets this class, which sits under every parser, be loaded on a server.
An OPC package (Open Packaging Conventions, ECMA-376 part 2). The shared container of docx, xlsx and pptx: a ZIP archive in which `[Content_Types].xml` assigns MIME types to parts and `.rels` files link parts to each other. Parsing this layer is identical for all three formats, so it lives apart from the format-specific packages.
Functions
Fills in what a shape leaves to the theme. What the shape states itself always wins: `p:style` is the default, and `p:spPr` is the override. A shape that turns its fill off states that too, and `filled: false` is respected rather than overwritten.
A chart, as the table it is. The single largest thing this package does that the alternatives do not, and the reason is not cleverness — it is that the parser already has the numbers. `c:chartSpace` stores every series with its cached values and its category labels, because that is how a chart survives being opened on a machine that cannot reach the workbook it came from. To every other extractor in this space a chart is a picture and a picture is a hole, so the figures behind a quarterly report's headline are simply absent from the text. One converter for all three formats, because `c:chartSpace` is the same part in a document, a workbook and a deck.
The first record of a type among a record's immediate children.
The colour inside a container such as `a:solidFill` or `a:fillRef`.
Excel column width in "characters" converted to pixels. Excel measures width in multiples of the width of the "0" glyph of the Normal style font and adds 5 pixels of cell padding (MS-OI29500, Column Width): `px = trunc(width * mdw) + 5`, where `mdw` is the digit width in pixels (7 for the default Calibri 11pt). This is where Excel's well-known default comes from: 8.43 characters is exactly 64 pixels.
Data URIs: work everywhere, cost a third more memory, need no revoking.
Object URLs where the host has them, data URIs otherwise.
Determines the concrete OOXML format from the type of the main part. This is the refinement the core cannot make: docx, xlsx and pptx are the same ZIP with the same signature, and only `[Content_Types].xml` tells them apart. File extensions are unreliable — renamed files turn up constantly — so the decision is made from the contents.
SmartArt, as the nesting it draws. A diagram is stored twice over: as the data it was built from and as the shapes the application laid out. The shapes are what the viewer draws, and they carry the words — so the text comes out of the drawing, and the nesting out of the frames it puts them in.
Eighths of a point: the unit of `w:sz` on border elements.
Base64, by hand. `btoa` is a browser function and `Buffer` is a Node one, and this package has a hard rule against needing either. Three bytes to four characters is twenty lines and no dependency; the alternative is a runtime check on the hot path of every image in a workbook.
A fill as a CSS background. A gradient becomes a gradient, a pattern becomes a repeating one — CSS has no hatch, and a striped background at the right density and angle reads as the same texture — and a picture returns nothing, because the caller has to resolve the part before it can name a URL.
Reads whichever fill a shape's properties carry. The five are alternatives in the schema and the first one found wins, which is also what the schema says: a shape has one fill.
Every record of a type, at any depth.
Reads `p:spPr`/`xdr:spPr`: what shape the shape is. `a:prstGeom` names one of the specification's shapes and adjusts it; `a:custGeom` writes the outline out. Both are read here, into one type, so that a slide and a worksheet describe an arrow the same way and the renderer that draws one draws the other.
The path a geometry describes, or nothing when it is one CSS handles. A zero-sized box has no path: a shape whose frame the file never stated would otherwise produce `M 0 0 Z`, which paints a dot at the corner of the slide.
`a:gray`: the colour rendered in shades of grey, by perceived brightness.
Infers an image MIME type from its magic bytes. `[Content_Types].xml` usually declares media types, but files written by third-party generators often omit the entry for an extension, and a blob with the wrong type simply fails to render.
Half-points: the unit Word uses for font sizes (`w:sz w:val="24"` is 12pt).
Whether a preset is one this library can draw.
`a:inv`: every channel inverted.
The three shapes CSS draws better than an SVG path would. A rectangle is a div, a rounded rectangle is a border-radius, and an ellipse is a fifty-per-cent one. Those three are 2 568 of the corpus's 4 311 shapes, and routing them through a path would trade working code for a redraw.
Whether a font is a symbol font, whose every byte means a glyph. A document writes a Wingdings character either as the raw byte or as `0xF000` plus it, and both mean the same picture — so the private-use range is not the test for whether a character needs mapping. The *font* is. `de-2b4d48b05715` bullets its lists with `<w:lvlText w:val="è"/>` in Wingdings, a plain `U+00E8`, and Word draws the arrow the font has there.
Image types that no browser can render natively.
Loads the drawing behind a diagram.
Every letter of an equation, in reading order; for a text extractor.
Applies the `hueMod`/`hueOff` hue rotation of DrawingML; both wrap.
Applies the `lumMod`/`lumOff` luminance modulation used by DrawingML themes. Word writes theme colour variations this way, e.g. "Accent 1, lighter 40%" becomes `lumMod 60000` + `lumOff 40000` (values are thousandths of a percent).
Applies the `satMod`/`satOff` saturation modulation of DrawingML. The other half of the pair Office writes for a theme variation. Every theme Word ships states its fills as a scheme colour with both a luminance and a saturation modifier on it — a heading colour is `accent1` at 110% saturation and 75% luminance — and applying only the first paints a colour that is the right lightness and visibly the wrong intensity.
Normalises a part name: no leading slash, forward slashes only.
Object URLs: a handle to the bytes, revoked on dispose. Returns `undefined` where the host has no `URL.createObjectURL`, so a caller that specifically wants object URLs can tell that it did not get them rather than discovering it later through memory that never comes back.
A pull parser that canonicalises Strict namespaces to Transitional.
`a:ln`: the width, the dash pattern and the colour it is stroked with.
Reads a sequence of records. Stops at the first header it cannot believe rather than continuing, because a wrong length here does not lose one record — it puts the reader in the middle of somebody's pixel data, where every eight bytes look like a header.
Parses a whole chart part.
Parses the drawing Word cached for a SmartArt diagram. The part is a flat shape tree with absolute geometry, so it needs no knowledge of the diagram algorithm that produced it.
Reads `m:oMath` or `m:oMathPara`: the equation, whole.
The same rule for a part read as a tree. Both halves of the reader need it and only the streaming half had it. A slide, a layout, a master and a theme are all read into trees, so a Strict deck arrived with every element in `http://purl.oclc.org/ooxml/…` and every lookup against `NS_PRESENTATION` returned nothing: 87 decks of the corpus — the whole `O14ISOStrict` half of Microsoft's own test set — rendered as no slides at all, and reported not as an error but as an empty presentation. The relationships were already canonicalised, which is why the packages opened and the failure looked like a parse and not like a namespace.
Reads a theme part whole.
Inverse of {@link columnWidthToPixels}.
Builds the outline of a preset shape.
The preset's name, whichever of the two forms the look carries.
The text rectangle of a preset geometry: where a shape's words go. Every preset in ECMA-376 Part 1 §20.1.10.56 states an `a:rect` beside its outline, and it is not the frame: an ellipse keeps its text inside the square inscribed in it, a diamond inside the middle quarter, a triangle off its point. Laid out across the frame instead, the words of a round badge run to the very edge of its box and break at other places — `educational- 195ca7de1415` heads its sheet with `2. 2. DÔKAZY EXISTENCIE BOHA` in a circle and Word breaks it on four lines where the frame held three. The formulas are the specification's `presetShapeDefinitions.xml`, with the default adjust values it states. A preset not listed here keeps the frame, which is what it had before and what most of them are.
Reads the colour inside a container such as `a:solidFill`. Every colour model shares one shape: an element that names the colour, with the transforms applied to it as its children.
Reads document metadata from `docProps/core.xml`, `app.xml` and `custom.xml`. Parsing is identical for docx, xlsx and pptx because this is part of OPC, not of any specific format. All three parts are optional: files produced by third-party generators frequently omit them, and their absence must not stop the document from opening.
Reads `a:prstGeom` or `a:custGeom` from a stream. The DOM reader in `element.ts` answers the same question for the formats that parse a drawing into a tree first. A document does not: `word/document.xml` is read once, in order, and so the shape of a shape has to be taken as it goes past. The parser must be positioned on the geometry element itself; it is consumed whole.
Reads `a:ln`: width, dash pattern and the colour it is stroked with.
An axis-aligned rectangle path, the fallback for an unknown preset.
Path of a part's `.rels` file: `word/document.xml` → `word/_rels/document.xml.rels`.
One `.rels` part, as the package format states it.
Turns a DrawingML colour into CSS. The transforms are applied in the order they were written, because they compose: SmartArt colour lists shift hue, saturation and luminance together to derive one node's colour from the previous one, and applying them in a fixed order of our own choosing produces a different palette.
Resolves a relationship target relative to its owning part. Targets come both absolute (`/word/media/image1.png`) and relative (`../media/image1.png`); both forms appear in files written by real Word.
Excel row heights are expressed in points.
Darkening (`shade`): mixes towards black, in linear light as {@link tint}. Probe `drawing-tint-shade`: `4F81BD` at `a:shade val="40000"` is `31547D` in Word, `20344C` by the sRGB product. The duotone of `educational- 39666b1eceab`'s pictures — `accent1` shaded to 45% — was drawn a navy where Word draws a mid blue.
A shadow as CSS. The file states a distance and a direction; CSS wants two offsets, so the angle is resolved into them. The blur radius is DrawingML's, which is twice what CSS calls one — a `blurRad` of 40 000 EMUs is a soft edge four pixels wide, not eight.
Reads `a:effectLst`: what the shape does beyond its own outline. Only the shadow, and only the first one: a shape may state a glow, a reflection and a soft edge as well, and of the corpus's 1 044 effect lists 784 hold a shadow while three hold a glow. The shadow is what shows.
The declarations that draw a shape. The geometry is honoured as far as CSS can take it: a rectangle is a rectangle, rounded corners are a radius, an ellipse is a radius of half. Everything else is drawn as its bounding rectangle — which the corpus says is a fair trade, since of the 2 862 shapes in it 2 827 are plain rectangles and 34 are rounded ones.
All three property tables of a shape, merged in the order they override.
Reads `p:style`, `xdr:style` or `wps:style`: how the theme paints the shape. The element is in the format's own namespace but everything inside it is DrawingML, which is why one reader serves all three.
True when the host can mint object URLs.
The code a symbol font's character was written as, from what it was mapped to. The inverse of {@link mapSymbolCharacter}, for whoever holds the mapped text and needs the glyph back — a painter drawing the bullet the font draws rather than the character it stands for. A private-use character is its own code; a byte the table does not map is kept as the byte, so it is its own code too.
The shape a symbol font draws for a code, or nothing. The code as a document writes it: the byte, or `0xF000` plus it, which mean the same glyph.
Builds a lookup from a theme part. The pairs are aliases: `tx1` is `dk1` and `bg1` is `lt1`, which is how a chart and a cell can name the same colour differently.
The colour of the theme entry a fill reference names.
The line of the theme entry a line reference names.
`w:themeShade`: WordprocessingML's darkening, which is not DrawingML's. [MS-OI29500] §2.1.72 a says so outright — "The standard specifies an algorithm for themeShade calculations that is **different from themeShade calculations in other subclauses**" — and then gives it: convert the colour to HSL, multiply the **luminance**, convert back. {@link shade} above is the DrawingML operation, a mix towards black in RGB, and the two are not close: the specification's own example, `accent2` = `C0504D` at `w:themeShade="BF"`, comes out `943634` by luminance and `A94543` by DrawingML's linear-light mix. The arithmetic is Word's own, on integers of 0..255 rather than on the unit interval, because that is what reproduces the example to the byte: hue and saturation rounded, luminance **truncated** — `C0504D` has a luminance of exactly 134.5 and Word takes 134 — the shade applied as `L × themeShade / 255` and rounded, and the conversion back rounded. The tint example of §2.1.72 c, `4F81BD` at `w:themeTint="99"`, comes out `95B2D7` here against the `95B3D7` printed there: **one unit of green**, on a boundary where the conversion back lands on 178.48. No arrangement of rounding over both examples was found that answers each of them exactly, and a unit of 255 in one channel is below what a reader can see; the RGB mix it replaces is out by tens.
`w:themeTint`: the same, lightening. `L' = L × themeTint / 255 + (255 − themeTint)`, which is the luminance moved that share of the way to white. See {@link themeShade} for why this is not {@link tint}.
Lightening (`tint` in DrawingML): mixes towards white, **in linear light**. Not in sRGB. Probe `drawing-tint-shade` fills a square of `4F81BD` at `a:tint val="40000"` and Word paints `D0D8E8`, where the sRGB mix would be `B9CDE5`; black at half a tint comes out `BCBCBC`, not `808080`. LibreOffice's `oox` reads it the same way, by way of its `crgb` model.
A twips measurement as a {@link Length}, converted to points on the way.
The picture a legacy embedded object was saved with, out of the VML drawing that holds it. An embedded object — a worksheet, a document, a chart of another application — is drawn by its own program, which no reader has. What every reader draws instead is the picture of it the file was saved with. Modern files put that picture where it can be found, in the `mc:Fallback` beside the object. Older ones do not: the object carries an `spid` and nothing else, and the picture is a VML shape of that id in a separate drawing part, related to the slide. That is not a historical curiosity. Of the 146 embedded objects in the presentation corpus, 45 are of this shape, and every one of them has the picture in the VML — so a reader that stops at `mc:Fallback` draws a third of the embedded objects it meets as nothing at all. Worth 121 lines of the 134389 the corpus compares, against a ceiling of about a thousand, and the gap between those two numbers has a cause worth knowing: PowerPoint does not always draw these as text either. `npoi/45541_Footer` embeds a slide whose preview holds a hundred words; PowerPoint's own export rasterises it and writes two. Drawing the preview is right for a reader — the words are on the screen and can be selected — and the reference happens not to reward it.
Interfaces
One entry of a shape's property table. The table is two lists in one record, and that is the whole subtlety of it. First a fixed-size array of (identifier, value) pairs; then, appended after the array in the same order, the payloads of whichever of those pairs said their value was a length rather than a value. Reading only the array gives a shape whose picture is "eighteen bytes" instead of a picture.
One record: its header, and either its bytes or its children.
One `c:*Chart` inside the plot area.
One value of a series, with the point it belongs to.
The text of one part of a chart, `c:txPr/a:pPr/a:defRPr`. A chart states its type sizes rather than inheriting them from the page: an axis whose labels are 9pt says so, and drawing them at the renderer's own default is a chart whose every label is the wrong size — which is what `long_legendentry` measures as 13.33px against Word's 12.
`a:custGeom`: one or more outlines, each in its own coordinate space.
One transform applied to a colour, `a:lumMod` and its siblings. Kept as a list rather than resolved fields because the transforms compose in document order, and SmartArt relies on that: a colour list shifts hue, saturation and luminance together to spread one accent colour across the nodes of a diagram.
A position and size in EMU, with the rotation applied about its centre.
What shape a shape is: a named preset with its adjustments, or an outline written out point by point. The two are alternatives in the file (`a:prstGeom` or `a:custGeom`) and are kept as alternatives here. The preset's name matters even when the renderer cannot draw it — a `rect` is a div and needs no path at all — so the name is carried rather than resolved at parse time.
One end of a line: an arrowhead, a diamond, an oval, and how big.
A run of text inside a diagram shape. Properties come from `a:rPr`.
`a:outerShdw`: the shadow a shape casts. Stated as a distance and a direction rather than as two offsets, because that is how a drawing application asks for one: "ten points, down and to the right". Seven hundred and eighty-four shapes of the corpus cast one, and a panel drawn without its shadow sits flat against the slide behind it.
The box a shape is drawn in, in pixels.
Mints and releases URLs for media parts.
What Word puts in `fcDggInfo`. The drawing group first — which holds the store every picture in the document lives in — and then up to two drawings, one for the body and one for the headers. Each is introduced by a single byte saying which it is, and that byte is the thing to trust: documents exist whose two drawings are in the other order, and reading them by position puts the header's shapes in the body.
Everything a preset needs to produce its path.
A relationship between package parts (`.rels`).
The look of a shape, as much of it as the format states. Every field is optional because the formats state different amounts: a spreadsheet shape carries text insets and a wrap flag, a slide shape carries neither, and both carry a geometry, a fill and an outline.
Where a shape's outline is drawn and how it is painted.
`p:style`: the four references a shape is painted by.
One `a:fillRef`/`a:lnRef`/`a:effectRef`/`a:fontRef`.
One bullet: its advance and the path that draws it, in thousandths of an em.
The whole theme, not just its colours. A shape rarely states how it is painted. It states a *reference* — "the second fill of the theme, in accent 1" — and the theme's `a:fmtScheme` holds the three fills, the three lines and the three effect sets that every shape in the deck is drawn from. Thirty per cent of the corpus's slides have shapes like that, and without the format scheme they are drawn with no fill at all, which is how a SmartArt diagram comes out as invisible text on white.
One entry of the theme's fill list. Every colour in it is `phClr` — the placeholder the referring shape fills in — carrying the transforms that make the entry what it is: the "moderate" fill is the shape's own colour tinted and lightened. Only the first colour is kept, because a gradient drawn as its first stop is much closer than a gradient drawn as nothing.
Type aliases
`c:grouping`, which decides whether values stack.
How the marks of one plot are laid out.
Where the legend goes, `c:legendPos`.
How a shape is filled, when a flat colour is not the answer. `a:solidFill` is one of five, and the other four were all drawn as nothing: a gradient panel, a hatched box, a shape filled with a photograph and a shape explicitly filled with nothing came out identical — unpainted.
One node of an equation; a sequence of them is an equation.
How a chart finds out what a theme slot is worth.
Values
The record types this reader acts on. Everything else is walked past.
Property identifiers this reader acts on.
The blips, by the record type each picture format is stored under.
Content types of main parts; used to identify the document format.
Eighths of a point: the unit of border widths in WordprocessingML.
An empty theme, for the documents that carry none.
EMUs per centimetre.
English Metric Units: 914400 per inch. The base unit of DrawingML.
EMUs per point: 914400 / 72.
Named `ST_HighlightColor` values from WordprocessingML.
OPC package parts: content types and relationships.
Document metadata.
DrawingML — shared graphics for all three formats.
SmartArt: the diagram definition, and the shapes Word laid out from it. The definition namespace is part of the standard, but the laid-out result is not: Word writes it under a Microsoft namespace as an extension. That drawing is what makes SmartArt viewable at all without reimplementing the diagram layout algorithms, so a reader that ignores extension parts renders nothing.
Markup Compatibility and Extensibility: `mc:AlternateContent` fallbacks.
Office Math Markup Language, used for equations.
The `r:id` reference namespace used inside document parts.
PresentationML — pptx.
SpreadsheetML — xlsx.
The two namespaces Excel's own extensions live in. Everything added after the schema was published — sparklines, the newer conditional formats, slicers — is written inside an `extLst` under these, so that a reader of the published schema steps over what it cannot know.
VML: the legacy vector format still emitted by Word for text boxes and shapes.
Word 2006 extensions, which carry a text box's content in a strict file. The namespace's usual load is key mappings and mail-merge state in `settings.xml`, where it is written `wne:`. It has one other use, and it is not one a reader can skip: [MS-OI29500] §2.1.1779 b says that a strict file saved by Word puts the `txbxContent` of a VML text box inside an `mc:Choice`, and writes it in *this* namespace rather than in WordprocessingML. Matching the element on `NS_WORDPROCESSING` alone loses the text of every text box in such a file, silently.
Word 2010+ extensions, where later features such as `w14:` live.
Word 2016's comment and list identities, `w16cid:`. A `w:numId` is a position in this document's table and changes when lists are merged; `w16cid:durableId` is the identity that does not.
Shapes and text boxes as Word has written them since 2010. These appear only inside `mc:AlternateContent`, paired with a VML fallback for readers that predate them. The modern branch is the one that carries the text of a text box as ordinary WordprocessingML.
WordprocessingML — docx.
The reserved `xml:` namespace, needed for `xml:space="preserve"`.
Relationship types used to locate the key parts of a document.
Twentieths of a point: 1440 per inch. The unit of WordprocessingML.
@genomdev/office-core/ole
Classes
Functions
The code page implied by a font's character set.
The code page implied by a language identifier. The fallback when nothing else says: a document with no font table, or a run whose font declares the default character set. Only the primary language — the low ten bits of the LID — decides.
Decodes eight-bit text in the given code page. Unknown pages fall back to 1252.
Whether a code page has a decoder of its own rather than the 1252 fallback.
Reads every section of a property set stream.
The Windows code page the file's own metadata was written in. Worth asking because it is the ANSI code page of the machine that saved the document, and that is what the document's eight-bit text is in. A document whose language says English and whose characters are Cyrillic is not a contradiction — the language identifier describes the *typing*, the code page describes the *bytes* — and this is the only field that states the latter outright. Two kinds of answer are refused rather than returned. Unicode, because a property set may be UTF-8 while the body of the document is not; and Macintosh, because a document saved by Word for Mac has MacRoman metadata and a Windows-encoded body, and taking the first answer for the second turns every quotation mark into an accented letter.
Reads both summary streams and maps them onto the common metadata shape. Absent streams are not an error: a document produced by something other than Word often has neither, and a file with no author is still a file.
Interfaces
One entry of the directory: a stream, a storage, or the root of the tree.
One section of a property set, keyed by property id.
Type aliases
What a directory entry describes.
A value read out of a property set.
Values
`DocumentSummaryInformation` property ids.
Anything above this is a marker rather than a sector number.
Stream names, spelled with the control character that really starts them.
`SummaryInformation` property ids.
@genomdev/office-core/formula
Classes
An Excel error value. Interned, so identity comparison works.
A reference. Kept as a value in its own right rather than resolved to numbers on sight, because a dozen functions care *where* their argument is and not only what is in it: `ROW`, `COLUMN`, `OFFSET`, `INDEX` (which returns a reference), `CELL`, `ISREF`, and every function whose criteria argument is a range. More than one area happens through the union operator: `SUM((A1:A5,C1:C5))`.
Functions
Builds a matrix of the given shape.
The format code of a built-in id, or `undefined` when the id is not reserved.
Compares two scalars the way `<` and `MATCH` do. Returns a negative number, zero or a positive number. Blanks are compared as the zero or empty text of whatever they meet, which is why `A1=0` and `A1=""` are both true when A1 is empty.
Compiles a `COUNTIF`-style criterion. The grammar: an optional comparison operator, then a value. Without an operator it is equality — and equality against text applies wildcards, which is why `COUNTIF(A:A,"a*")` counts everything beginning with an `a`.
Compiles a format code, or returns the cached compilation.
A constant node's value, for the few places that only accept constants.
The inverse: a `Date` as the serial number Excel would store for it.
A workbook context with nothing in it, for evaluating a bare expression.
The first error anywhere in a value, which is what propagates.
Excel's `General`. Not "the number as JavaScript prints it": Excel keeps about eleven significant digits and falls back to scientific notation outside a fixed range, which is why `0.1 + 0.2` shows as `0.3` in a spreadsheet and as something longer in a console.
A number as `General` renders it. Fifteen significant digits, which is the precision Excel keeps and the reason a spreadsheet shows `0.3` where a console shows the rounding error.
Formats a value the way Excel would with the given code. `code` is the format string, not the id: resolving an id through the workbook's `numFmts` and the built-in table happens in the style layer, which is the only place that knows both.
Looks up an indexed colour, falling back to the default palette.
Whether a format code shows a date or a time rather than a number.
Whether the code contains a text section, which is what makes it apply to strings.
Reads a matrix with Excel's broadcast rules: a single row or column repeats.
Strips the `_xlfn.` prefix. Functions added after 2007 are stored with it so that older versions fail predictably instead of silently. `_xlfn.IFS` and `IFS` are the same function and the library should only have to know one name. The `_xlws.` prefix, for worksheet-only functions, works the same way.
Text that Excel accepts as a number. Deliberately stricter than `Number()`: `"1e5"` and `"0x10"` are numbers to JavaScript and text to Excel, and `""` is zero to `Number()` and an error here. Percentages, leading currency symbols and thousands separators are accepted, because Excel accepts them.
Rounds the way a spreadsheet does: half away from zero, at a decimal place.
Converts a serial number to a JavaScript `Date` in UTC.
Converts a serial number to calendar parts. Returns `undefined` for values Excel itself refuses to show as a date: negative serials in the 1900 system produce `#####`, not a date before the epoch.
The single value a cell shows for a computed result.
Coerces to a number, as an arithmetic operator would.
Coerces to text. A number becomes what `General` would show, not what JavaScript prints: concatenating 0.1 + 0.2 must produce `0.3`, not `0.30000000000000004`.
Excel's wildcards: `*` any run, `?` one character, `~` escapes either. Returns `undefined` when the text holds no wildcard at all, so the caller can take the cheaper equality path.
Interfaces
One rectangular area of a sheet, zero-based and inclusive.
One argument of a function call, evaluated on demand.
Where a formula lives. Every relative reference is resolved against it.
Whole and fractional parts of a serial number, in calendar terms.
The result of formatting a value with a format code.
A reference as written, before it is resolved against a workbook.
A table, for structured references.
Type aliases
Everything a formula can evaluate to.
A rectangular block of values, row-major. Arrays in Excel are always 2D.
A single value: a number, text, a logical, an error, or a blank.
Values
How many modules the library is built from. Reading it keeps them alive.
The function library. Modules add to it as they are imported.
Automatic colour: whatever the window text colour is.
The window background colour.
The legacy indexed colour palette. Before themes, a workbook referred to colours by index into a 56-entry table that lived in the file (`<indexedColors>`) and, when it did not, was assumed to be this one. Files still arrive with `indexed="10"` on a font, and number format codes still say `[Color 10]`, so the default table has to be here even though nothing has written it deliberately in twenty years. Indices 0-7 repeat as 8-15: the first eight are the "system" colours and the second eight are the same colours in the user-editable part of the palette. Index 64 is "automatic" — the window text colour — and 65 the window background; both are resolved by the renderer rather than by a table.
Enums
@genomdev/office-core/media
Functions
Decodes a packed DIB — header, palette and bits in one run of bytes.
The picture a store entry names, wherever it is. Three places, in the order they occur. Beside the entry as a child record; inside the entry's own bytes after its header and name — both of which some writers produce — and, in nearly every document Word saved, at the offset the entry states into the delay stream.
True when an Office Art record is a picture rather than something else.
Converts a metafile into an SVG document.
Reads every picture the document's store lists. The store holds one entry per picture and, in Word, almost never the picture itself: the entry carries an offset into a *delay stream*, and the delay stream is `WordDocument`. So the pictures sit among the text, in the one place a reader of the drawing layer would not think to look, and a store that appears to hold nothing is the normal case rather than an empty document. The position is taken from the entry rather than from a running count of what was found, because an entry may name a picture that is not in the file at all — Word writes one for a picture linked from elsewhere — and the shapes count those too.
Interfaces
Device-independent bitmaps, as a metafile carries them. A DIB is what Windows called an image before there were image formats: a header, a palette when the depth needs one, and rows of pixels stored bottom to top and padded to a multiple of four bytes. Every bitmap inside an EMF or a WMF is one of these, so reading them is the difference between a diagram with its screenshots and a diagram with holes. The two headers that occur are the ancient `BITMAPCOREHEADER` and the `BITMAPINFOHEADER` everything since 1995 writes; both are read, because a metafile pasted from a twenty-year-old document really does contain the first.
A picture, as the store holds it.
@genomdev/office-core/view
Functions
Renders a chart part into an element of the given frame size.
Draws an equation into one inline box.
The shape's outline as an SVG, for the geometries CSS cannot draw. Returned rather than appended so that the caller decides where it goes; every viewer puts it behind the shape's text, which the browser lays out in the shape's own box. The path is painted with the shape's own fill and line. A path the file marks as unfilled — a brace, a connector, a freehand squiggle — is stroked only, whatever fill the shape carries, because filling it would blot the slide.
Interfaces
What drawing a chart needs from the application around it. Two things and no more: a document to create elements in, and the theme's answer for a colour slot. Deliberately this narrow — the renderer used to take the Word view's whole render context, and that is the only reason it could not be used from a spreadsheet.
A piece of a chart's text and the box the drawing put it in.
What drawing a diagram needs from the application around it. The same three things a chart needs and one more: SmartArt names its typefaces by scheme slot rather than by name, so a host that has a theme has to be asked. Deliberately this narrow — the renderer used to take the Word view's whole render context, and that is the only reason a workbook could not use it.
@genomdev/office-core/testing
Functions
Builds a minimal Word document from the contents of `w:body`.
Builds a valid OPC package in memory. Format parser tests must run against a real ZIP archive rather than XML smuggled past the container, otherwise the entire archive-reading and relationship-resolution layer — exactly where things break most often — is left untested.
Wraps numbering definitions into a complete `numbering.xml` part.
Wraps style definitions into a complete `styles.xml` part.
Interfaces
Extra parts and relationships to include in a generated docx.
Description of an OPC package to build.
One relationship. `targetMode` matters more than it looks: a hyperlink to the web is external and is kept as written, while an internal target is a path resolved against the owning part. A test that omits it gets a URL resolved as a file path.
A ZIP archive builder for tests. Simpler and more reliable than keeping binary fixtures in the repository: a test states the compression method, the archive comment and the set of parts itself, and therefore exercises exactly the reader branch it was written for.