odf.js 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { Alignment, AlignmentSchema, Box, Color, LayoutMetadata, Margins, PageSize } from "document-content-model";
2
3
  //#region src/model/node.d.ts
3
4
  declare const AttributeSchema: z.ZodObject<{
4
5
  name: z.ZodString;
@@ -348,6 +349,7 @@ declare function txt(value: string): XmlText;
348
349
  //#endregion
349
350
  //#region src/xml/entities.d.ts
350
351
  declare function encodeXmlText(value: string): string;
352
+ declare function decodeXmlText(value: string): string;
351
353
  //#endregion
352
354
  //#region src/manifest.d.ts
353
355
  declare const ManifestEntrySchema: z.ZodObject<{
@@ -386,4 +388,140 @@ declare function syncManifest(pkg: Package, options?: BuildManifestOptions): voi
386
388
  declare function validateManifest(pkg: Package): ManifestProblem[];
387
389
  declare function setDocumentMediaType(pkg: Package, mediaType: string, version?: string): void;
388
390
  //#endregion
389
- export { type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type BuildManifestOptions, type ImageFormat, MANIFEST_PART, MIMETYPE_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, ODF_NAMESPACES, type OdfExtension, type OdfNamespacePrefix, type Package, PackageSchema, type Part, PartSchema, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, type ZipEntry, base64ToBytes, buildManifest, buildXml, bytesToBase64, decodePackage, el, encodePackage, encodeXmlText, isXmlNode, mediaTypeForExtension, packageCodec, parsePackage, parseXml, readManifest, readMimetype, serializePackage, setDocumentMediaType, sniffImageFormat, syncManifest, txt, unzipPackage, validateManifest, writeManifest, writeMimetype, xmlCodec, xmlnsAttributes, zipPackage };
391
+ //#region src/typed/shared/units.d.ts
392
+ type LengthUnit = 'cm' | 'mm' | 'in' | 'pt' | 'pc' | 'px';
393
+ declare function parseOdfLength(value: string): number | undefined;
394
+ declare function formatOdfLength(pt: number, unit?: LengthUnit): string;
395
+ //#endregion
396
+ //#region src/styles/properties.d.ts
397
+ declare const StylePropertiesSchema: z.ZodObject<{
398
+ bold: z.ZodOptional<z.ZodBoolean>;
399
+ italic: z.ZodOptional<z.ZodBoolean>;
400
+ underline: z.ZodOptional<z.ZodBoolean>;
401
+ strike: z.ZodOptional<z.ZodBoolean>;
402
+ fontFamily: z.ZodOptional<z.ZodString>;
403
+ sizePt: z.ZodOptional<z.ZodNumber>;
404
+ color: z.ZodOptional<z.ZodObject<{
405
+ r: z.ZodNumber;
406
+ g: z.ZodNumber;
407
+ b: z.ZodNumber;
408
+ }, z.core.$strip>>;
409
+ alignment: z.ZodOptional<z.ZodEnum<{
410
+ left: "left";
411
+ center: "center";
412
+ right: "right";
413
+ justify: "justify";
414
+ }>>;
415
+ spacingBeforePt: z.ZodOptional<z.ZodNumber>;
416
+ spacingAfterPt: z.ZodOptional<z.ZodNumber>;
417
+ lineSpacing: z.ZodOptional<z.ZodNumber>;
418
+ indentLeftPt: z.ZodOptional<z.ZodNumber>;
419
+ indentFirstLinePt: z.ZodOptional<z.ZodNumber>;
420
+ }, z.core.$strip>;
421
+ type StyleProperties = z.infer<typeof StylePropertiesSchema>;
422
+ interface ParsedProperties {
423
+ properties: Partial<StyleProperties>;
424
+ hasUnknown: boolean;
425
+ }
426
+ declare const parseLength: typeof parseOdfLength;
427
+ declare function formatPt(valuePt: number): string;
428
+ declare function formatPercentageMultiplier(multiplier: number): string;
429
+ declare function parseTextProperties(element: XmlElement): ParsedProperties;
430
+ declare function parseParagraphProperties(element: XmlElement): ParsedProperties;
431
+ declare function parseStyleElementProperties(styleElement: XmlElement): {
432
+ properties: StyleProperties;
433
+ hasUnknown: boolean;
434
+ };
435
+ declare function textPropertiesToAttributes(properties: StyleProperties): Attribute[];
436
+ declare function paragraphPropertiesToAttributes(properties: StyleProperties): Attribute[];
437
+ //#endregion
438
+ //#region src/styles/serialize.d.ts
439
+ declare function buildStylePropertyElements(properties: StyleProperties): XmlElement[];
440
+ declare function canonicalPropertiesString(properties: StyleProperties): string;
441
+ //#endregion
442
+ //#region src/styles/registry.d.ts
443
+ declare const STYLE_FAMILIES: readonly ["paragraph", "text", "table", "table-column", "table-row", "table-cell", "graphic"];
444
+ type StyleFamily = (typeof STYLE_FAMILIES)[number];
445
+ declare function isStyleFamily(value: string): value is StyleFamily;
446
+ interface InternRequest {
447
+ properties: StyleProperties;
448
+ family: StyleFamily;
449
+ parentStyleName?: string;
450
+ }
451
+ interface OtherPartRef {
452
+ pkg: Package;
453
+ partPath: string;
454
+ }
455
+ interface StyleRegistryOptions {
456
+ otherPart?: OtherPartRef;
457
+ additionalReservedNames?: readonly string[];
458
+ }
459
+ declare class StyleRegistry {
460
+ private readonly automaticStyles;
461
+ private readonly prefixes;
462
+ private readonly reservedByFamily;
463
+ private readonly knownStyles;
464
+ private readonly fingerprintToName;
465
+ private readonly nameToFingerprint;
466
+ private readonly familyCounters;
467
+ private constructor();
468
+ static forPart(pkg: Package, partPath: string, options?: StyleRegistryOptions): StyleRegistry;
469
+ fingerprint(request: InternRequest): string;
470
+ intern(request: InternRequest): string;
471
+ private mintName;
472
+ names(): readonly string[];
473
+ gc(referenced: ReadonlySet<string>): number;
474
+ }
475
+ //#endregion
476
+ //#region src/styles/span.d.ts
477
+ declare function ensureSpan(paragraph: XmlElement, start: number, end: number, styleName: string): XmlElement;
478
+ //#endregion
479
+ //#region src/xml/query.d.ts
480
+ declare function rootElement(nodes: readonly XmlNode[]): XmlElement | undefined;
481
+ declare function findChildElement(nodes: readonly XmlNode[], tag: string): XmlElement | undefined;
482
+ declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
483
+ declare function attrValue(element: XmlElement, name: string): string | undefined;
484
+ //#endregion
485
+ //#region src/typed/shared/a1.d.ts
486
+ declare function columnIndexToLetters(index: number): string;
487
+ declare function cellReference(columnIndex: number, rowIndex: number): string;
488
+ declare class TableCursor {
489
+ private columnCursor;
490
+ private rowCursor;
491
+ get columnIndex(): number;
492
+ get rowIndex(): number;
493
+ nextCell(repeatCount?: number): string;
494
+ nextRow(repeatCount?: number): void;
495
+ }
496
+ //#endregion
497
+ //#region src/typed/shared/color.d.ts
498
+ declare function parseOdfColor(value: string): Color | undefined;
499
+ declare function formatOdfColor(color: Color): string;
500
+ //#endregion
501
+ //#region src/typed/shared/geometry.d.ts
502
+ declare function parsePageSize(pageLayoutProperties: XmlElement): PageSize | undefined;
503
+ declare function parseMargins(pageLayoutProperties: XmlElement): Margins | undefined;
504
+ declare function parseBox(element: XmlElement): Box | undefined;
505
+ //#endregion
506
+ //#region src/typed/shared/text.d.ts
507
+ declare function getOdfSpaceCount(element: XmlElement): number;
508
+ declare function measureOdfNodeLength(node: XmlNode): number;
509
+ declare function sumOdfNodeLength(nodes: readonly XmlNode[]): number;
510
+ declare function decodeOdfText(container: XmlElement): string;
511
+ //#endregion
512
+ //#region src/typed/shared/cascade.d.ts
513
+ interface CascadeDiagnostic {
514
+ severity: 'warning';
515
+ message: string;
516
+ }
517
+ interface StyleCascadeResult {
518
+ properties: StyleProperties;
519
+ diagnostics: CascadeDiagnostic[];
520
+ }
521
+ declare function resolveStyle(styleName: string | undefined, family: StyleFamily, pkg: Package): StyleCascadeResult;
522
+ //#endregion
523
+ //#region src/typed/shared/metadata.d.ts
524
+ declare const META_PART = "meta.xml";
525
+ declare function readOdfMetadata(pkg: Package): LayoutMetadata;
526
+ //#endregion
527
+ export { type Alignment, AlignmentSchema, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type BuildManifestOptions, type CascadeDiagnostic, type ImageFormat, type InternRequest, type LengthUnit, MANIFEST_PART, META_PART, MIMETYPE_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, ODF_NAMESPACES, type OdfExtension, type OdfNamespacePrefix, type OtherPartRef, type Package, PackageSchema, type ParsedProperties, type Part, PartSchema, STYLE_FAMILIES, type StyleCascadeResult, type StyleFamily, type StyleProperties, StylePropertiesSchema, StyleRegistry, type StyleRegistryOptions, TableCursor, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, type ZipEntry, attrValue, base64ToBytes, buildManifest, buildStylePropertyElements, buildXml, bytesToBase64, canonicalPropertiesString, cellReference, childrenWithTag, columnIndexToLetters, decodeOdfText, decodePackage, decodeXmlText, el, encodePackage, encodeXmlText, ensureSpan, findChildElement, formatOdfColor, formatOdfLength, formatPercentageMultiplier, formatPt, getOdfSpaceCount, isStyleFamily, isXmlNode, measureOdfNodeLength, mediaTypeForExtension, packageCodec, paragraphPropertiesToAttributes, parseBox, parseLength, parseMargins, parseOdfColor, parseOdfLength, parsePackage, parsePageSize, parseParagraphProperties, parseStyleElementProperties, parseTextProperties, parseXml, readManifest, readMimetype, readOdfMetadata, resolveStyle, rootElement, serializePackage, setDocumentMediaType, sniffImageFormat, sumOdfNodeLength, syncManifest, textPropertiesToAttributes, txt, unzipPackage, validateManifest, writeManifest, writeMimetype, xmlCodec, xmlnsAttributes, zipPackage };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { Alignment, AlignmentSchema, Box, Color, LayoutMetadata, Margins, PageSize } from "document-content-model";
2
3
  //#region src/model/node.d.ts
3
4
  declare const AttributeSchema: z.ZodObject<{
4
5
  name: z.ZodString;
@@ -348,6 +349,7 @@ declare function txt(value: string): XmlText;
348
349
  //#endregion
349
350
  //#region src/xml/entities.d.ts
350
351
  declare function encodeXmlText(value: string): string;
352
+ declare function decodeXmlText(value: string): string;
351
353
  //#endregion
352
354
  //#region src/manifest.d.ts
353
355
  declare const ManifestEntrySchema: z.ZodObject<{
@@ -386,4 +388,140 @@ declare function syncManifest(pkg: Package, options?: BuildManifestOptions): voi
386
388
  declare function validateManifest(pkg: Package): ManifestProblem[];
387
389
  declare function setDocumentMediaType(pkg: Package, mediaType: string, version?: string): void;
388
390
  //#endregion
389
- export { type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type BuildManifestOptions, type ImageFormat, MANIFEST_PART, MIMETYPE_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, ODF_NAMESPACES, type OdfExtension, type OdfNamespacePrefix, type Package, PackageSchema, type Part, PartSchema, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, type ZipEntry, base64ToBytes, buildManifest, buildXml, bytesToBase64, decodePackage, el, encodePackage, encodeXmlText, isXmlNode, mediaTypeForExtension, packageCodec, parsePackage, parseXml, readManifest, readMimetype, serializePackage, setDocumentMediaType, sniffImageFormat, syncManifest, txt, unzipPackage, validateManifest, writeManifest, writeMimetype, xmlCodec, xmlnsAttributes, zipPackage };
391
+ //#region src/typed/shared/units.d.ts
392
+ type LengthUnit = 'cm' | 'mm' | 'in' | 'pt' | 'pc' | 'px';
393
+ declare function parseOdfLength(value: string): number | undefined;
394
+ declare function formatOdfLength(pt: number, unit?: LengthUnit): string;
395
+ //#endregion
396
+ //#region src/styles/properties.d.ts
397
+ declare const StylePropertiesSchema: z.ZodObject<{
398
+ bold: z.ZodOptional<z.ZodBoolean>;
399
+ italic: z.ZodOptional<z.ZodBoolean>;
400
+ underline: z.ZodOptional<z.ZodBoolean>;
401
+ strike: z.ZodOptional<z.ZodBoolean>;
402
+ fontFamily: z.ZodOptional<z.ZodString>;
403
+ sizePt: z.ZodOptional<z.ZodNumber>;
404
+ color: z.ZodOptional<z.ZodObject<{
405
+ r: z.ZodNumber;
406
+ g: z.ZodNumber;
407
+ b: z.ZodNumber;
408
+ }, z.core.$strip>>;
409
+ alignment: z.ZodOptional<z.ZodEnum<{
410
+ left: "left";
411
+ center: "center";
412
+ right: "right";
413
+ justify: "justify";
414
+ }>>;
415
+ spacingBeforePt: z.ZodOptional<z.ZodNumber>;
416
+ spacingAfterPt: z.ZodOptional<z.ZodNumber>;
417
+ lineSpacing: z.ZodOptional<z.ZodNumber>;
418
+ indentLeftPt: z.ZodOptional<z.ZodNumber>;
419
+ indentFirstLinePt: z.ZodOptional<z.ZodNumber>;
420
+ }, z.core.$strip>;
421
+ type StyleProperties = z.infer<typeof StylePropertiesSchema>;
422
+ interface ParsedProperties {
423
+ properties: Partial<StyleProperties>;
424
+ hasUnknown: boolean;
425
+ }
426
+ declare const parseLength: typeof parseOdfLength;
427
+ declare function formatPt(valuePt: number): string;
428
+ declare function formatPercentageMultiplier(multiplier: number): string;
429
+ declare function parseTextProperties(element: XmlElement): ParsedProperties;
430
+ declare function parseParagraphProperties(element: XmlElement): ParsedProperties;
431
+ declare function parseStyleElementProperties(styleElement: XmlElement): {
432
+ properties: StyleProperties;
433
+ hasUnknown: boolean;
434
+ };
435
+ declare function textPropertiesToAttributes(properties: StyleProperties): Attribute[];
436
+ declare function paragraphPropertiesToAttributes(properties: StyleProperties): Attribute[];
437
+ //#endregion
438
+ //#region src/styles/serialize.d.ts
439
+ declare function buildStylePropertyElements(properties: StyleProperties): XmlElement[];
440
+ declare function canonicalPropertiesString(properties: StyleProperties): string;
441
+ //#endregion
442
+ //#region src/styles/registry.d.ts
443
+ declare const STYLE_FAMILIES: readonly ["paragraph", "text", "table", "table-column", "table-row", "table-cell", "graphic"];
444
+ type StyleFamily = (typeof STYLE_FAMILIES)[number];
445
+ declare function isStyleFamily(value: string): value is StyleFamily;
446
+ interface InternRequest {
447
+ properties: StyleProperties;
448
+ family: StyleFamily;
449
+ parentStyleName?: string;
450
+ }
451
+ interface OtherPartRef {
452
+ pkg: Package;
453
+ partPath: string;
454
+ }
455
+ interface StyleRegistryOptions {
456
+ otherPart?: OtherPartRef;
457
+ additionalReservedNames?: readonly string[];
458
+ }
459
+ declare class StyleRegistry {
460
+ private readonly automaticStyles;
461
+ private readonly prefixes;
462
+ private readonly reservedByFamily;
463
+ private readonly knownStyles;
464
+ private readonly fingerprintToName;
465
+ private readonly nameToFingerprint;
466
+ private readonly familyCounters;
467
+ private constructor();
468
+ static forPart(pkg: Package, partPath: string, options?: StyleRegistryOptions): StyleRegistry;
469
+ fingerprint(request: InternRequest): string;
470
+ intern(request: InternRequest): string;
471
+ private mintName;
472
+ names(): readonly string[];
473
+ gc(referenced: ReadonlySet<string>): number;
474
+ }
475
+ //#endregion
476
+ //#region src/styles/span.d.ts
477
+ declare function ensureSpan(paragraph: XmlElement, start: number, end: number, styleName: string): XmlElement;
478
+ //#endregion
479
+ //#region src/xml/query.d.ts
480
+ declare function rootElement(nodes: readonly XmlNode[]): XmlElement | undefined;
481
+ declare function findChildElement(nodes: readonly XmlNode[], tag: string): XmlElement | undefined;
482
+ declare function childrenWithTag(element: XmlElement, tag: string): XmlElement[];
483
+ declare function attrValue(element: XmlElement, name: string): string | undefined;
484
+ //#endregion
485
+ //#region src/typed/shared/a1.d.ts
486
+ declare function columnIndexToLetters(index: number): string;
487
+ declare function cellReference(columnIndex: number, rowIndex: number): string;
488
+ declare class TableCursor {
489
+ private columnCursor;
490
+ private rowCursor;
491
+ get columnIndex(): number;
492
+ get rowIndex(): number;
493
+ nextCell(repeatCount?: number): string;
494
+ nextRow(repeatCount?: number): void;
495
+ }
496
+ //#endregion
497
+ //#region src/typed/shared/color.d.ts
498
+ declare function parseOdfColor(value: string): Color | undefined;
499
+ declare function formatOdfColor(color: Color): string;
500
+ //#endregion
501
+ //#region src/typed/shared/geometry.d.ts
502
+ declare function parsePageSize(pageLayoutProperties: XmlElement): PageSize | undefined;
503
+ declare function parseMargins(pageLayoutProperties: XmlElement): Margins | undefined;
504
+ declare function parseBox(element: XmlElement): Box | undefined;
505
+ //#endregion
506
+ //#region src/typed/shared/text.d.ts
507
+ declare function getOdfSpaceCount(element: XmlElement): number;
508
+ declare function measureOdfNodeLength(node: XmlNode): number;
509
+ declare function sumOdfNodeLength(nodes: readonly XmlNode[]): number;
510
+ declare function decodeOdfText(container: XmlElement): string;
511
+ //#endregion
512
+ //#region src/typed/shared/cascade.d.ts
513
+ interface CascadeDiagnostic {
514
+ severity: 'warning';
515
+ message: string;
516
+ }
517
+ interface StyleCascadeResult {
518
+ properties: StyleProperties;
519
+ diagnostics: CascadeDiagnostic[];
520
+ }
521
+ declare function resolveStyle(styleName: string | undefined, family: StyleFamily, pkg: Package): StyleCascadeResult;
522
+ //#endregion
523
+ //#region src/typed/shared/metadata.d.ts
524
+ declare const META_PART = "meta.xml";
525
+ declare function readOdfMetadata(pkg: Package): LayoutMetadata;
526
+ //#endregion
527
+ export { type Alignment, AlignmentSchema, type Attribute, AttributeSchema, type BinaryPart, BinaryPartSchema, type BuildManifestOptions, type CascadeDiagnostic, type ImageFormat, type InternRequest, type LengthUnit, MANIFEST_PART, META_PART, MIMETYPE_PART, type Manifest, type ManifestEntry, ManifestEntrySchema, type ManifestProblem, ManifestProblemSchema, ManifestSchema, ODF_MEDIA_TYPES, ODF_NAMESPACES, type OdfExtension, type OdfNamespacePrefix, type OtherPartRef, type Package, PackageSchema, type ParsedProperties, type Part, PartSchema, STYLE_FAMILIES, type StyleCascadeResult, type StyleFamily, type StyleProperties, StylePropertiesSchema, StyleRegistry, type StyleRegistryOptions, TableCursor, type XmlCdata, XmlCdataSchema, type XmlComment, XmlCommentSchema, type XmlDeclaration, XmlDeclarationSchema, type XmlElement, XmlElementSchema, type XmlNode, XmlNodeSchema, type XmlPart, XmlPartSchema, type XmlPi, XmlPiSchema, type XmlText, XmlTextSchema, type ZipEntry, attrValue, base64ToBytes, buildManifest, buildStylePropertyElements, buildXml, bytesToBase64, canonicalPropertiesString, cellReference, childrenWithTag, columnIndexToLetters, decodeOdfText, decodePackage, decodeXmlText, el, encodePackage, encodeXmlText, ensureSpan, findChildElement, formatOdfColor, formatOdfLength, formatPercentageMultiplier, formatPt, getOdfSpaceCount, isStyleFamily, isXmlNode, measureOdfNodeLength, mediaTypeForExtension, packageCodec, paragraphPropertiesToAttributes, parseBox, parseLength, parseMargins, parseOdfColor, parseOdfLength, parsePackage, parsePageSize, parseParagraphProperties, parseStyleElementProperties, parseTextProperties, parseXml, readManifest, readMimetype, readOdfMetadata, resolveStyle, rootElement, serializePackage, setDocumentMediaType, sniffImageFormat, sumOdfNodeLength, syncManifest, textPropertiesToAttributes, txt, unzipPackage, validateManifest, writeManifest, writeMimetype, xmlCodec, xmlnsAttributes, zipPackage };