@office-open/core

Shared OOXML infrastructure: XmlComponent, value validators, unit converters, chart types, and SmartArt definitions.
Features
- XmlComponent Framework - Base classes for building OOXML element trees with dynamic namespace support
- Value Validators - Runtime validation for OOXML spec types (ST_HexColor, ST_OnOff, ST_DecimalNumber, etc.)
- Unit Converters - TWIP and EMU conversions (mm/in/pt/px)
- Chart Components - Shared chart types (bar, line, pie, area, scatter) and chart collection for DOCX/PPTX
- SmartArt Components - Data model, tree-to-model converter, collection, and built-in layout/style/color definitions
- ID Generators - Sequential numeric IDs, nanoid, SHA-1 hash, UUID v4
- OOXML Compliance - All types verified against ISO/IEC 29500-4 XSD schemas
Installation
$ npm install @office-open/core
$ pnpm add @office-open/core
Quick Start
import {
OnOffElement,
StringValueElement,
BuilderElement,
StringContainer,
hexColorValue,
decimalNumber,
convertMillimetersToTwip,
uniqueNumericIdCreator,
} from "@office-open/core";
new OnOffElement("w:b", false);
new OnOffElement("m:hideBot", false);
new BuilderElement({
name: "w:r",
attributes: { lang: { key: "xml:lang", value: "en-US" } },
children: [new StringContainer("w:t", "Hello")],
});
hexColorValue("#FF0000");
hexColorValue("auto");
decimalNumber(10.7);
convertMillimetersToTwip(25.4);
convertPixelsToEmu(100);
convertInchesToEmu(1);
convertPointsToEmu(12);
const gen = uniqueNumericIdCreator();
gen();
OOXML Schema Compliance
ThemeColor | ST_ThemeColor (17 values) |
ThemeFont | ST_Theme (8 values) |
UniversalMeasure | ST_UniversalMeasure (mm, cm, in, pt, pc, pi) |
Percentage | ST_Percentage |
hexColorValue | ST_HexColor (auto + 3-byte hexBinary) |
OnOffElement | CT_OnOff (dynamic namespace prefix) |
HpsMeasureElement | CT_HpsMeasure |
StringValueElement | CT_String |
Exports
@office-open/core | XmlComponent, validators, converters, ID generators |
@office-open/core/values | Validators + ThemeColor/ThemeFont only |
@office-open/core/chart | Chart types, series data, chart collection, title |
@office-open/core/smartart | SmartArt data model, tree-to-model, definitions |
Benchmark
decimalNumber | ~21M |
hexColorValue (6-char hex) | ~13M |
uniqueNumericIdCreator | ~21M |
uniqueId (nanoid) | ~3.3M |
uniqueUuid | ~2M |
OnOffElement (true) | ~13M |
OnOffElement (false) | ~1.7M |
BuilderElement (attributes) | ~2M |
BuilderElement (children) | ~2.3M |
License