@office-open/core 0.6.0 → 0.6.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.
package/README.md CHANGED
@@ -96,15 +96,15 @@ gen(); // → 1, 2, 3, ...
96
96
 
97
97
  | Operation | hz |
98
98
  | ----------------------------- | ----- |
99
- | `decimalNumber` | ~21M |
99
+ | `decimalNumber` | ~20M |
100
100
  | `hexColorValue` (6-char hex) | ~13M |
101
- | `uniqueNumericIdCreator` | ~21M |
102
- | `uniqueId` (nanoid) | ~3.3M |
103
- | `uniqueUuid` | ~2M |
104
- | `OnOffElement (true)` | ~13M |
105
- | `OnOffElement (false)` | ~1.7M |
106
- | `BuilderElement` (attributes) | ~2M |
107
- | `BuilderElement` (children) | ~2.3M |
101
+ | `uniqueNumericIdCreator` | ~20M |
102
+ | `uniqueId` (nanoid) | ~3.2M |
103
+ | `uniqueUuid` | ~1.8M |
104
+ | `onOffObj` (true) | ~19M |
105
+ | `onOffObj` (false) | ~3.4M |
106
+ | `BuilderElement` (attributes) | ~5M |
107
+ | `BuilderElement` (children) | ~3.9M |
108
108
 
109
109
  ## License
110
110
 
@@ -1,4 +1,4 @@
1
- import { O as XmlComponent } from "../index-DqdJoWmh.mjs";
1
+ import { C as XmlComponent } from "../index-mjYQ4KiG.mjs";
2
2
 
3
3
  //#region src/chart/axes.d.ts
4
4
  /**
@@ -15,70 +15,70 @@ declare class ValAx extends XmlComponent {
15
15
  }
16
16
  //#endregion
17
17
  //#region src/chart/chart-types/area-chart.d.ts
18
- interface IAreaChartOptions {
18
+ interface AreaChartOptions {
19
19
  readonly categories: readonly string[];
20
- readonly series: readonly IChartSeriesData[];
20
+ readonly series: readonly ChartSeriesData[];
21
21
  }
22
22
  declare class AreaChart extends XmlComponent {
23
- constructor(options: IAreaChartOptions);
23
+ constructor(options: AreaChartOptions);
24
24
  }
25
25
  //#endregion
26
26
  //#region src/chart/chart-types/bar-chart.d.ts
27
- interface IBarChartOptions {
27
+ interface BarChartOptions {
28
28
  readonly barDirection: "col" | "bar";
29
29
  readonly categories: readonly string[];
30
- readonly series: readonly IChartSeriesData[];
30
+ readonly series: readonly ChartSeriesData[];
31
31
  }
32
32
  declare class BarChart extends XmlComponent {
33
- constructor(options: IBarChartOptions);
33
+ constructor(options: BarChartOptions);
34
34
  }
35
35
  //#endregion
36
36
  //#region src/chart/chart-types/line-chart.d.ts
37
- interface ILineChartOptions {
37
+ interface LineChartOptions {
38
38
  readonly categories: readonly string[];
39
- readonly series: readonly IChartSeriesData[];
39
+ readonly series: readonly ChartSeriesData[];
40
40
  }
41
41
  declare class LineChart extends XmlComponent {
42
- constructor(options: ILineChartOptions);
42
+ constructor(options: LineChartOptions);
43
43
  }
44
44
  //#endregion
45
45
  //#region src/chart/chart-types/pie-chart.d.ts
46
- interface IPieChartOptions {
46
+ interface PieChartOptions {
47
47
  readonly categories: readonly string[];
48
- readonly series: readonly IChartSeriesData[];
48
+ readonly series: readonly ChartSeriesData[];
49
49
  }
50
50
  declare class PieChart extends XmlComponent {
51
- constructor(options: IPieChartOptions);
51
+ constructor(options: PieChartOptions);
52
52
  }
53
53
  //#endregion
54
54
  //#region src/chart/chart-types/scatter-chart.d.ts
55
- interface IScatterChartOptions {
55
+ interface ScatterChartOptions {
56
56
  readonly categories: readonly string[];
57
- readonly series: readonly IChartSeriesData[];
57
+ readonly series: readonly ChartSeriesData[];
58
58
  }
59
59
  declare class ScatterChart extends XmlComponent {
60
- constructor(options: IScatterChartOptions);
60
+ constructor(options: ScatterChartOptions);
61
61
  }
62
62
  //#endregion
63
63
  //#region src/chart/create-chart-type.d.ts
64
- interface IChartSeriesData {
64
+ interface ChartSeriesData {
65
65
  readonly name: string;
66
66
  readonly values: readonly number[];
67
67
  }
68
68
  type ChartType = "column" | "bar" | "line" | "pie" | "area" | "scatter";
69
- interface IChartTypeOptions {
69
+ interface ChartTypeOptions {
70
70
  readonly type: ChartType;
71
- readonly series: readonly IChartSeriesData[];
71
+ readonly series: readonly ChartSeriesData[];
72
72
  readonly categories: readonly string[];
73
73
  }
74
- declare const createChartType: (options: IChartTypeOptions) => AreaChart | BarChart | LineChart | PieChart | ScatterChart;
74
+ declare const createChartType: (options: ChartTypeOptions) => BarChart | LineChart | PieChart | AreaChart | ScatterChart;
75
75
  //#endregion
76
76
  //#region src/chart/chart-space.d.ts
77
- interface IChartSpaceOptions {
77
+ interface ChartSpaceOptions {
78
78
  readonly title?: string;
79
79
  readonly type: ChartType;
80
80
  readonly categories: readonly string[];
81
- readonly series: readonly IChartSeriesData[];
81
+ readonly series: readonly ChartSeriesData[];
82
82
  readonly showLegend?: boolean;
83
83
  readonly style?: number;
84
84
  }
@@ -86,19 +86,19 @@ interface IChartSpaceOptions {
86
86
  * c:chartSpace — root element for chart XML parts.
87
87
  */
88
88
  declare class ChartSpace extends XmlComponent {
89
- constructor(options: IChartSpaceOptions);
89
+ constructor(options: ChartSpaceOptions);
90
90
  }
91
91
  //#endregion
92
92
  //#region src/chart/chart-collection.d.ts
93
- interface IChartData {
93
+ interface ChartData {
94
94
  readonly key: string;
95
95
  readonly chartSpace: XmlComponent;
96
96
  }
97
97
  declare class ChartCollection {
98
98
  private readonly map;
99
99
  constructor();
100
- addChart(key: string, chartData: IChartData): void;
101
- get Array(): readonly IChartData[];
100
+ addChart(key: string, chartData: ChartData): void;
101
+ get Array(): readonly ChartData[];
102
102
  }
103
103
  //#endregion
104
104
  //#region src/chart/series/series-data.d.ts
@@ -110,4 +110,4 @@ declare class ChartTitle extends XmlComponent {
110
110
  constructor(title: string);
111
111
  }
112
112
  //#endregion
113
- export { AreaChart, BarChart, CatAx, ChartCollection, ChartSpace, ChartTitle, ChartType, IChartData, IChartSeriesData, IChartSpaceOptions, IChartTypeOptions, LineChart, PieChart, ScatterChart, ValAx, createChartType, createNumRef, createStrRef };
113
+ export { AreaChart, BarChart, CatAx, ChartCollection, ChartData, ChartSeriesData, ChartSpace, ChartSpaceOptions, ChartTitle, ChartType, ChartTypeOptions, LineChart, PieChart, ScatterChart, ValAx, createChartType, createNumRef, createStrRef };
@@ -1,4 +1,4 @@
1
- import { T as XmlComponent, a as BuilderElement, b as wrapEl, o as EmptyElement, p as chartAttr } from "../xml-components-CJKrtCSG.mjs";
1
+ import { a as BuilderElement, b as XmlComponent, c as chartAttr, h as wrapEl, o as EmptyElement } from "../xml-components-CADgke8j.mjs";
2
2
  //#region src/chart/axes.ts
3
3
  /**
4
4
  * c:scaling — axis scaling configuration (minOccurs=1 in EG_AxShared).
@@ -1,4 +1,4 @@
1
- import { O as XmlComponent, T as XmlAttributeComponent, a as BuilderElement } from "../index-DqdJoWmh.mjs";
1
+ import { C as XmlComponent, a as BuilderElement } from "../index-mjYQ4KiG.mjs";
2
2
 
3
3
  //#region src/drawingml/color/color-transform.d.ts
4
4
  /**
@@ -880,7 +880,7 @@ declare const createTileInfo: (options?: TileOptions) => BuilderElement<{}>;
880
880
  /**
881
881
  * Gradient stop position (0-100000, representing 0%-100%).
882
882
  */
883
- interface IGradientStop {
883
+ interface GradientStop {
884
884
  /** Position of the color stop (0-100000) */
885
885
  readonly position: number;
886
886
  /** Color at this stop */
@@ -982,7 +982,7 @@ type GradientShadeOptions = LinearShadeOptions | PathShadeOptions;
982
982
  */
983
983
  interface GradientFillOptions {
984
984
  /** Gradient color stops (minimum 2) */
985
- readonly stops: readonly IGradientStop[];
985
+ readonly stops: readonly GradientStop[];
986
986
  /** Shade type (linear or path) */
987
987
  readonly shade?: GradientShadeOptions;
988
988
  /**
@@ -1009,7 +1009,7 @@ interface GradientFillOptions {
1009
1009
  * createGradientStop({ position: 100000, color: { value: "0000FF" } });
1010
1010
  * ```
1011
1011
  */
1012
- declare const createGradientStop: (stop: IGradientStop) => XmlComponent;
1012
+ declare const createGradientStop: (stop: GradientStop) => XmlComponent;
1013
1013
  /**
1014
1014
  * Creates a gradient fill element.
1015
1015
  *
@@ -2646,27 +2646,6 @@ declare class PresetGeometry extends XmlComponent {
2646
2646
  constructor(options?: PresetGeometryOptions);
2647
2647
  }
2648
2648
  //#endregion
2649
- //#region src/drawingml/geometry/preset-geometry-attributes.d.ts
2650
- /**
2651
- * Attributes for preset geometry.
2652
- *
2653
- * Defines the shape type identifier for a preset geometry.
2654
- *
2655
- * ## XSD Schema
2656
- * ```xml
2657
- * <xsd:attribute name="prst" type="ST_ShapeType" use="required"/>
2658
- * ```
2659
- *
2660
- * @internal
2661
- */
2662
- declare class PresetGeometryAttributes extends XmlAttributeComponent<{
2663
- /** Preset shape type (e.g., "rect", "ellipse", "triangle") */readonly prst?: string;
2664
- }> {
2665
- protected readonly xmlKeys: {
2666
- prst: string;
2667
- };
2668
- }
2669
- //#endregion
2670
2649
  //#region src/drawingml/geometry/custom-geometry.d.ts
2671
2650
  /**
2672
2651
  * Path fill mode (ST_PathFillMode).
@@ -3087,7 +3066,7 @@ declare const createGroupTransform2D: (options: GroupTransform2DOptions, element
3087
3066
  /**
3088
3067
  * Internal media data transformation with both pixel and EMU values.
3089
3068
  */
3090
- interface IMediaDataTransformation {
3069
+ interface MediaDataTransformation {
3091
3070
  readonly offset?: {
3092
3071
  readonly pixels: {
3093
3072
  readonly x: number;
@@ -3120,7 +3099,7 @@ interface IMediaDataTransformation {
3120
3099
  *
3121
3100
  * Specifies how an image should be transformed when displayed in the document.
3122
3101
  */
3123
- interface IMediaTransformation {
3102
+ interface MediaTransformation {
3124
3103
  readonly offset?: {
3125
3104
  readonly top?: number;
3126
3105
  readonly left?: number;
@@ -3143,6 +3122,6 @@ interface IMediaTransformation {
3143
3122
  * @param options - User-facing transformation in pixels
3144
3123
  * @returns Internal transformation data with both pixel and EMU values
3145
3124
  */
3146
- declare const createTransformation: (options: IMediaTransformation) => IMediaDataTransformation;
3125
+ declare const createTransformation: (options: MediaTransformation) => MediaDataTransformation;
3147
3126
  //#endregion
3148
- export { type BackdropOptions, type BevelOptions, BevelPresetType, BlendMode, type BlipEffectsOptions, type BlipFillConfigOptions, type BlipFillMediaData, type BlipFillOptions, type BlipOptions, type BlurEffectOptions, type CameraOptions, type ColorTransformOptions, CompoundLine, type ConnectionSite, type CustomGeometryOptions, type DashStop, type EffectContainerType, type EffectDagOptions, type EffectListOptions, type FillOptions, type FillOverlayEffectOptions, type GeomRect, type GeometryGuide, type GlowEffectOptions, type GradientFillOptions, type GradientShadeOptions, type GradientStopOptions, type GroupTransform2DOptions, type HslColorOptions, type IGradientStop, type IMediaDataTransformation, type IMediaTransformation, type InnerShadowEffectOptions, type LightRigOptions, LineCap, LineEndLength, type LineEndOptions, LineEndType, LineEndWidth, LineJoin, type LinearShadeOptions, type OuterShadowEffectOptions, type OutlineFillProperties, type OutlineOptions, type PathCommand, type PathFillMode, type PathOptions, type PathShadeOptions, PathShadeType, type PatternFillOptions, PenAlignment, type Point3D, PresetColor, type PresetColorOptions, PresetDash, PresetGeometry, PresetGeometryAttributes, type PresetGeometryOptions, PresetMaterialType, PresetPattern, type PresetShadowEffectOptions, PresetShadowVal, RectAlignment, type ReflectionEffectOptions, type RelativeRect, type RgbColorOptions, type ScRgbColorOptions, type Scene3DOptions, SchemeColor, type SchemeColorOptions, type Shape3DOptions, type SolidFillOptions, type SourceRectangleOptions, type SphereCoords, Stretch, SystemColor, type SystemColorOptions, TileAlignment, TileFlipMode, type TileOptions, type Transform2DOptions, type Vector3D, buildFill, createAdjustmentValues, createBevel, createBlip, createBlipEffects, createBlipFill, createBottomBevel, createColorElement, createColorTransforms, createCustomDash, createCustomGeometry, createEffectDag, createEffectList, createExtentionList, createFillOverlayEffect, createGlowEffect, createGradientFill, createGradientStop, createGroupFill, createGroupTransform2D, createHslColor, createInnerShadowEffect, createLineEnd, createNoFill, createOuterShadowEffect, createOutline, createPatternFill, createPresetColor, createPresetShadowEffect, createReflectionEffect, createRgbColor, createScRgbColor, createScene3D, createSchemeColor, createShape3D, createSoftEdgeEffect, createSolidFill, createSourceRectangle, createSystemColor, createTileInfo, createTransform2D, createTransformation, extractBlipFillMedia };
3127
+ export { type BackdropOptions, type BevelOptions, BevelPresetType, BlendMode, type BlipEffectsOptions, type BlipFillConfigOptions, type BlipFillMediaData, type BlipFillOptions, type BlipOptions, type BlurEffectOptions, type CameraOptions, type ColorTransformOptions, CompoundLine, type ConnectionSite, type CustomGeometryOptions, type DashStop, type EffectContainerType, type EffectDagOptions, type EffectListOptions, type FillOptions, type FillOverlayEffectOptions, type GeomRect, type GeometryGuide, type GlowEffectOptions, type GradientFillOptions, type GradientShadeOptions, type GradientStop, type GradientStopOptions, type GroupTransform2DOptions, type HslColorOptions, type InnerShadowEffectOptions, type LightRigOptions, LineCap, LineEndLength, type LineEndOptions, LineEndType, LineEndWidth, LineJoin, type LinearShadeOptions, type MediaDataTransformation, type MediaTransformation, type OuterShadowEffectOptions, type OutlineFillProperties, type OutlineOptions, type PathCommand, type PathFillMode, type PathOptions, type PathShadeOptions, PathShadeType, type PatternFillOptions, PenAlignment, type Point3D, PresetColor, type PresetColorOptions, PresetDash, PresetGeometry, type PresetGeometryOptions, PresetMaterialType, PresetPattern, type PresetShadowEffectOptions, PresetShadowVal, RectAlignment, type ReflectionEffectOptions, type RelativeRect, type RgbColorOptions, type ScRgbColorOptions, type Scene3DOptions, SchemeColor, type SchemeColorOptions, type Shape3DOptions, type SolidFillOptions, type SourceRectangleOptions, type SphereCoords, Stretch, SystemColor, type SystemColorOptions, TileAlignment, TileFlipMode, type TileOptions, type Transform2DOptions, type Vector3D, buildFill, createAdjustmentValues, createBevel, createBlip, createBlipEffects, createBlipFill, createBottomBevel, createColorElement, createColorTransforms, createCustomDash, createCustomGeometry, createEffectDag, createEffectList, createExtentionList, createFillOverlayEffect, createGlowEffect, createGradientFill, createGradientStop, createGroupFill, createGroupTransform2D, createHslColor, createInnerShadowEffect, createLineEnd, createNoFill, createOuterShadowEffect, createOutline, createPatternFill, createPresetColor, createPresetShadowEffect, createReflectionEffect, createRgbColor, createScRgbColor, createScene3D, createSchemeColor, createShape3D, createSoftEdgeEffect, createSolidFill, createSourceRectangle, createSystemColor, createTileInfo, createTransform2D, createTransformation, extractBlipFillMedia };
@@ -1,4 +1,4 @@
1
- import { S as XmlAttributeComponent, T as XmlComponent, a as BuilderElement } from "../xml-components-CJKrtCSG.mjs";
1
+ import { a as BuilderElement, b as XmlComponent } from "../xml-components-CADgke8j.mjs";
2
2
  import { d as convertPixelsToEmu, t as hashedId } from "../id-generators-CM3u923a.mjs";
3
3
  //#region src/drawingml/color/color-transform.ts
4
4
  /**
@@ -3208,30 +3208,6 @@ const createAdjustmentValues = (guides) => {
3208
3208
  });
3209
3209
  };
3210
3210
  //#endregion
3211
- //#region src/drawingml/geometry/preset-geometry-attributes.ts
3212
- /**
3213
- * Preset geometry attributes for DrawingML shapes.
3214
- *
3215
- * This module defines the shape type attribute for preset geometries.
3216
- *
3217
- * @module
3218
- */
3219
- /**
3220
- * Attributes for preset geometry.
3221
- *
3222
- * Defines the shape type identifier for a preset geometry.
3223
- *
3224
- * ## XSD Schema
3225
- * ```xml
3226
- * <xsd:attribute name="prst" type="ST_ShapeType" use="required"/>
3227
- * ```
3228
- *
3229
- * @internal
3230
- */
3231
- var PresetGeometryAttributes = class extends XmlAttributeComponent {
3232
- xmlKeys = { prst: "prst" };
3233
- };
3234
- //#endregion
3235
3211
  //#region src/drawingml/geometry/preset-geometry.ts
3236
3212
  /**
3237
3213
  * Preset geometry module for DrawingML shapes.
@@ -3275,7 +3251,7 @@ var PresetGeometryAttributes = class extends XmlAttributeComponent {
3275
3251
  var PresetGeometry = class extends XmlComponent {
3276
3252
  constructor(options) {
3277
3253
  super("a:prstGeom");
3278
- this.root.push(new PresetGeometryAttributes({ prst: options?.preset ?? "rect" }));
3254
+ this.root.push({ _attr: { prst: options?.preset ?? "rect" } });
3279
3255
  this.root.push(createAdjustmentValues(options?.adjustmentValues));
3280
3256
  }
3281
3257
  };
@@ -3915,4 +3891,4 @@ const createTransformation = (options) => ({
3915
3891
  rotation: options.rotation ? options.rotation * 6e4 : void 0
3916
3892
  });
3917
3893
  //#endregion
3918
- export { BevelPresetType, BlendMode, CompoundLine, LineCap, LineEndLength, LineEndType, LineEndWidth, LineJoin, PathShadeType, PenAlignment, PresetColor, PresetDash, PresetGeometry, PresetGeometryAttributes, PresetMaterialType, PresetPattern, PresetShadowVal, RectAlignment, SchemeColor, Stretch, SystemColor, TileAlignment, TileFlipMode, buildFill, createAdjustmentValues, createBevel, createBlip, createBlipEffects, createBlipFill, createBottomBevel, createColorElement, createColorTransforms, createCustomDash, createCustomGeometry, createEffectDag, createEffectList, createExtentionList, createFillOverlayEffect, createGlowEffect, createGradientFill, createGradientStop, createGroupFill, createGroupTransform2D, createHslColor, createInnerShadowEffect, createLineEnd, createNoFill, createOuterShadowEffect, createOutline, createPatternFill, createPresetColor, createPresetShadowEffect, createReflectionEffect, createRgbColor, createScRgbColor, createScene3D, createSchemeColor, createShape3D, createSoftEdgeEffect, createSolidFill, createSourceRectangle, createSystemColor, createTileInfo, createTransform2D, createTransformation, extractBlipFillMedia };
3894
+ export { BevelPresetType, BlendMode, CompoundLine, LineCap, LineEndLength, LineEndType, LineEndWidth, LineJoin, PathShadeType, PenAlignment, PresetColor, PresetDash, PresetGeometry, PresetMaterialType, PresetPattern, PresetShadowVal, RectAlignment, SchemeColor, Stretch, SystemColor, TileAlignment, TileFlipMode, buildFill, createAdjustmentValues, createBevel, createBlip, createBlipEffects, createBlipFill, createBottomBevel, createColorElement, createColorTransforms, createCustomDash, createCustomGeometry, createEffectDag, createEffectList, createExtentionList, createFillOverlayEffect, createGlowEffect, createGradientFill, createGradientStop, createGroupFill, createGroupTransform2D, createHslColor, createInnerShadowEffect, createLineEnd, createNoFill, createOuterShadowEffect, createOutline, createPatternFill, createPresetColor, createPresetShadowEffect, createReflectionEffect, createRgbColor, createScRgbColor, createScene3D, createSchemeColor, createShape3D, createSoftEdgeEffect, createSolidFill, createSourceRectangle, createSystemColor, createTileInfo, createTransform2D, createTransformation, extractBlipFillMedia };
@@ -1,4 +1,4 @@
1
- import { O as XmlComponent } from "./index-DqdJoWmh.mjs";
1
+ import { C as XmlComponent } from "./index-mjYQ4KiG.mjs";
2
2
 
3
3
  //#region src/smartart/categories.d.ts
4
4
  /** Layout ID → OOXML category type */
@@ -57,7 +57,7 @@ declare class TransPoint extends XmlComponent {
57
57
  }
58
58
  //#endregion
59
59
  //#region src/smartart/smartart-collection.d.ts
60
- interface ISmartArtData {
60
+ interface SmartArtData {
61
61
  readonly key: string;
62
62
  readonly dataModel: DataModel;
63
63
  readonly layout: string;
@@ -70,18 +70,18 @@ interface ISmartArtData {
70
70
  declare class SmartArtCollection {
71
71
  private readonly map;
72
72
  constructor();
73
- addSmartArt(key: string, data: ISmartArtData): void;
74
- get Array(): readonly ISmartArtData[];
73
+ addSmartArt(key: string, data: SmartArtData): void;
74
+ get Array(): readonly SmartArtData[];
75
75
  }
76
76
  //#endregion
77
77
  //#region src/smartart/tree-to-model.d.ts
78
- interface ITreeNode {
78
+ interface TreeNode {
79
79
  readonly text: string;
80
- readonly children?: readonly ITreeNode[];
80
+ readonly children?: readonly TreeNode[];
81
81
  }
82
82
  /**
83
83
  * Creates a DataModel from tree nodes with layout/style/color settings.
84
84
  */
85
- declare const createDataModel: (nodes: readonly ITreeNode[], layout?: string, style?: string, color?: string) => DataModel;
85
+ declare const createDataModel: (nodes: readonly TreeNode[], layout?: string, style?: string, color?: string) => DataModel;
86
86
  //#endregion
87
- export { Point as a, Connection as c, getLayoutXml as d, getStyleXml as f, STYLE_CATEGORIES as h, SmartArtCollection as i, DEFAULT_DRAWING_XML as l, LAYOUT_CATEGORIES as m, createDataModel as n, TransPoint as o, COLOR_CATEGORIES as p, ISmartArtData as r, DataModel as s, ITreeNode as t, getColorXml as u };
87
+ export { Point as a, Connection as c, getLayoutXml as d, getStyleXml as f, STYLE_CATEGORIES as h, SmartArtData as i, DEFAULT_DRAWING_XML as l, LAYOUT_CATEGORIES as m, createDataModel as n, TransPoint as o, COLOR_CATEGORIES as p, SmartArtCollection as r, DataModel as s, TreeNode as t, getColorXml as u };
@@ -22,7 +22,7 @@ type IXmlableObject = Readonly<Record<string, any>>;
22
22
  *
23
23
  * @typeParam TFileData - The type of the root file data object (format-specific)
24
24
  */
25
- interface IContext<TFileData = unknown> {
25
+ interface Context<TFileData = unknown> {
26
26
  /** The root file data object being serialized (format-specific). */
27
27
  readonly fileData?: TFileData;
28
28
  /** Current traversal stack of components (mutable for performance). */
@@ -41,7 +41,7 @@ declare abstract class BaseXmlComponent {
41
41
  * @param context - The serialization context
42
42
  * @returns The XML-serializable object, or undefined to exclude from output
43
43
  */
44
- abstract prepForXml(context: IContext): IXmlableObject | undefined;
44
+ abstract prepForXml(context: Context): IXmlableObject | undefined;
45
45
  }
46
46
  //#endregion
47
47
  //#region src/xml-components/component.d.ts
@@ -63,12 +63,12 @@ declare abstract class XmlComponent extends BaseXmlComponent {
63
63
  /**
64
64
  * Prepares this component and its children for XML serialization.
65
65
  */
66
- prepForXml(context: IContext): IXmlableObject | undefined;
66
+ prepForXml(context: Context): IXmlableObject | undefined;
67
67
  /**
68
68
  * Direct XML serialization. Override in subclasses for zero-allocation output.
69
69
  * Default falls back to prepForXml() + xml().
70
70
  */
71
- toXml(context: IContext): string;
71
+ toXml(context: Context): string;
72
72
  /**
73
73
  * @deprecated Internal use only.
74
74
  */
@@ -80,7 +80,7 @@ declare abstract class XmlComponent extends BaseXmlComponent {
80
80
  declare abstract class IgnoreIfEmptyXmlComponent extends XmlComponent {
81
81
  private readonly includeIfEmpty;
82
82
  constructor(rootKey: string, includeIfEmpty?: boolean);
83
- prepForXml(context: IContext): IXmlableObject | undefined;
83
+ prepForXml(context: Context): IXmlableObject | undefined;
84
84
  }
85
85
  //#endregion
86
86
  //#region src/xml-components/attributes.d.ts
@@ -107,7 +107,7 @@ declare abstract class XmlAttributeComponent<T extends Record<string, any>> exte
107
107
  /** Optional mapping from property names to XML attribute names. */
108
108
  protected readonly xmlKeys?: AttributeMap<T>;
109
109
  constructor(root: T);
110
- prepForXml(_: IContext): IXmlableObject;
110
+ prepForXml(_: Context): IXmlableObject;
111
111
  }
112
112
  /**
113
113
  * Next-generation attribute component with explicit key-value pairs.
@@ -115,10 +115,14 @@ declare abstract class XmlAttributeComponent<T extends Record<string, any>> exte
115
115
  declare class NextAttributeComponent<T> extends BaseXmlComponent {
116
116
  private readonly root;
117
117
  constructor(root: AttributePayload<T>);
118
- prepForXml(_: IContext): IXmlableObject;
118
+ prepForXml(_: Context): IXmlableObject;
119
119
  }
120
120
  //#endregion
121
121
  //#region src/xml-components/elements.d.ts
122
+ /**
123
+ * Build an XML element with arbitrary attributes, filtering out undefined values.
124
+ */
125
+ declare function attrObj(name: string, attrs: Record<string, string | number | boolean | undefined>): IXmlableObject;
122
126
  /**
123
127
  * Build a CT_OnOff XML object without allocating any XmlComponent.
124
128
  * `val=true` returns a frozen singleton (cached per name).
@@ -144,52 +148,10 @@ declare function stringEnumValObj<T extends string>(name: string, val: T): IXmla
144
148
  * Build an element wrapping a text string without allocation.
145
149
  */
146
150
  declare function stringContainerObj(name: string, val: string): IXmlableObject;
147
- /**
148
- * XML element representing a boolean on/off value (CT_OnOff).
149
- * @deprecated Use `onOffObj()` for hot-path code.
150
- */
151
- declare class OnOffElement extends XmlComponent {
152
- constructor(name: string, val?: boolean | undefined);
153
- }
154
- /**
155
- * XML element representing a half-point size measurement (CT_HpsMeasure).
156
- * @deprecated Use `hpsMeasureObj()` for hot-path code.
157
- */
158
- declare class HpsMeasureElement extends XmlComponent {
159
- constructor(name: string, val: number | PositiveUniversalMeasure);
160
- }
161
151
  /**
162
152
  * XML element representing an empty element (CT_Empty).
163
153
  */
164
154
  declare class EmptyElement extends XmlComponent {}
165
- /**
166
- * XML element with a string value attribute (CT_String).
167
- * @deprecated Use `stringValObj()` for hot-path code.
168
- */
169
- declare class StringValueElement extends XmlComponent {
170
- constructor(name: string, val: string);
171
- }
172
- /**
173
- * XML element with a numeric value attribute.
174
- * @deprecated Use `numberValObj()` for hot-path code.
175
- */
176
- declare class NumberValueElement extends XmlComponent {
177
- constructor(name: string, val: number);
178
- }
179
- /**
180
- * XML element with a string enum value attribute.
181
- * @deprecated Use `stringEnumValObj()` for hot-path code.
182
- */
183
- declare class StringEnumValueElement<T extends string> extends XmlComponent {
184
- constructor(name: string, val: T);
185
- }
186
- /**
187
- * XML element containing text content.
188
- * @deprecated Use `stringContainerObj()` for hot-path code.
189
- */
190
- declare class StringContainer extends XmlComponent {
191
- constructor(name: string, val: string);
192
- }
193
155
  /**
194
156
  * Flexible XML element builder with explicit attribute and child configuration.
195
157
  */
@@ -201,7 +163,7 @@ declare class BuilderElement<T = {}> extends XmlComponent {
201
163
  }: {
202
164
  readonly name: string;
203
165
  readonly attributes?: AttributePayload<T>;
204
- readonly children?: readonly (BaseXmlComponent | string)[];
166
+ readonly children?: readonly (BaseXmlComponent | IXmlableObject | string)[];
205
167
  });
206
168
  }
207
169
  /**
@@ -225,7 +187,7 @@ declare class ImportedXmlComponent extends XmlComponent {
225
187
  protected _sourceXml?: string;
226
188
  static fromXmlString(importedContent: string): ImportedXmlComponent;
227
189
  get sourceXml(): string | undefined;
228
- toXml(_context: IContext): string;
190
+ toXml(_context: Context): string;
229
191
  constructor(rootKey: string, _attr?: any);
230
192
  push(xmlComponent: XmlComponent | string): void;
231
193
  }
@@ -235,7 +197,7 @@ declare class ImportedXmlComponent extends XmlComponent {
235
197
  declare class ImportedRootElementAttributes extends XmlComponent {
236
198
  private readonly _attr;
237
199
  constructor(_attr: any);
238
- prepForXml(_: IContext): IXmlableObject;
200
+ prepForXml(_: Context): IXmlableObject;
239
201
  }
240
202
  //#endregion
241
203
  //#region src/xml-components/initializable.d.ts
@@ -246,4 +208,4 @@ declare abstract class InitializableXmlComponent extends XmlComponent {
246
208
  constructor(rootKey: string, initComponent?: XmlComponent);
247
209
  }
248
210
  //#endregion
249
- export { IContext as A, AttributePayload as C, IgnoreIfEmptyXmlComponent as D, EMPTY_OBJECT as E, IXmlableObject as M, XmlComponent as O, AttributeMap as S, XmlAttributeComponent as T, stringContainerObj as _, BuilderElement as a, wrapEl as b, NumberValueElement as c, StringEnumValueElement as d, StringValueElement as f, onOffObj as g, numberValObj as h, convertToXmlComponent as i, IXmlAttribute as j, BaseXmlComponent as k, OnOffElement as l, hpsMeasureObj as m, ImportedRootElementAttributes as n, EmptyElement as o, chartAttr as p, ImportedXmlComponent as r, HpsMeasureElement as s, InitializableXmlComponent as t, StringContainer as u, stringEnumValObj as v, NextAttributeComponent as w, AttributeData as x, stringValObj as y };
211
+ export { XmlComponent as C, IXmlableObject as D, IXmlAttribute as E, IgnoreIfEmptyXmlComponent as S, Context as T, AttributeMap as _, BuilderElement as a, XmlAttributeComponent as b, chartAttr as c, onOffObj as d, stringContainerObj as f, AttributeData as g, wrapEl as h, convertToXmlComponent as i, hpsMeasureObj as l, stringValObj as m, ImportedRootElementAttributes as n, EmptyElement as o, stringEnumValObj as p, ImportedXmlComponent as r, attrObj as s, InitializableXmlComponent as t, numberValObj as u, AttributePayload as v, BaseXmlComponent as w, EMPTY_OBJECT as x, NextAttributeComponent as y };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,10 @@
1
1
  import { Relationship, elementToXml, findRel, findRelsByType, getImageType, listFiles, parseRels, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, uint8ToBase64, unzipToMap, zipToBuffer } from "./archive.mjs";
2
- import { A as IContext, C as AttributePayload, D as IgnoreIfEmptyXmlComponent, E as EMPTY_OBJECT, M as IXmlableObject, O as XmlComponent, S as AttributeMap, T as XmlAttributeComponent, _ as stringContainerObj, a as BuilderElement, b as wrapEl, c as NumberValueElement, d as StringEnumValueElement, f as StringValueElement, g as onOffObj, h as numberValObj, i as convertToXmlComponent, j as IXmlAttribute, k as BaseXmlComponent, l as OnOffElement, m as hpsMeasureObj, n as ImportedRootElementAttributes, o as EmptyElement, p as chartAttr, r as ImportedXmlComponent, s as HpsMeasureElement, t as InitializableXmlComponent, u as StringContainer, v as stringEnumValObj, w as NextAttributeComponent, x as AttributeData, y as stringValObj } from "./index-DqdJoWmh.mjs";
2
+ import { C as XmlComponent, D as IXmlableObject, E as IXmlAttribute, S as IgnoreIfEmptyXmlComponent, T as Context, _ as AttributeMap, a as BuilderElement, b as XmlAttributeComponent, c as chartAttr, d as onOffObj, f as stringContainerObj, g as AttributeData, h as wrapEl, i as convertToXmlComponent, l as hpsMeasureObj, m as stringValObj, n as ImportedRootElementAttributes, o as EmptyElement, p as stringEnumValObj, r as ImportedXmlComponent, s as attrObj, t as InitializableXmlComponent, u as numberValObj, v as AttributePayload, w as BaseXmlComponent, x as EMPTY_OBJECT, y as NextAttributeComponent } from "./index-mjYQ4KiG.mjs";
3
3
  import { C as uCharHexNumber, S as twipsMeasureValue, T as unsignedDecimalNumber, _ as pointMeasureValue, a as ThemeColor, b as signedHpsMeasureValue, c as dateTimeValue, d as hexBinary, f as hexColorValue, g as percentageValue, h as measurementOrPercentValue, i as RelativeMeasure, l as decimalNumber, m as longHexNumber, n as PositivePercentage, o as ThemeFont, p as hpsMeasureValue, r as PositiveUniversalMeasure, s as UniversalMeasure, t as Percentage, u as eighthPointMeasureValue, v as positiveUniversalMeasureValue, w as universalMeasureValue, x as signedTwipsMeasureValue, y as shortHexNumber } from "./values-CIh0bdS1.mjs";
4
- import { a as Point, c as Connection, d as getLayoutXml, f as getStyleXml, h as STYLE_CATEGORIES, i as SmartArtCollection, l as DEFAULT_DRAWING_XML, m as LAYOUT_CATEGORIES, n as createDataModel, o as TransPoint, p as COLOR_CATEGORIES, r as ISmartArtData, s as DataModel, t as ITreeNode, u as getColorXml } from "./index-rASwxHbF.mjs";
4
+ import { a as Point, c as Connection, d as getLayoutXml, f as getStyleXml, h as STYLE_CATEGORIES, i as SmartArtData, l as DEFAULT_DRAWING_XML, m as LAYOUT_CATEGORIES, n as createDataModel, o as TransPoint, p as COLOR_CATEGORIES, r as SmartArtCollection, s as DataModel, t as TreeNode, u as getColorXml } from "./index-DVqYs1vv.mjs";
5
5
  import { Element } from "@office-open/xml";
6
+ import { ZipOptions, Zippable, Zippable as Zippable$1, strFromU8, unzipSync } from "fflate";
7
+ import { Readable } from "stream";
6
8
 
7
9
  //#region src/converters.d.ts
8
10
  /**
@@ -90,12 +92,7 @@ declare const OoxmlMimeType: {
90
92
  declare const convertOutput: <T extends OutputType>(data: Uint8Array, type: T, mimeType?: string) => OutputByType[T];
91
93
  //#endregion
92
94
  //#region src/packer.d.ts
93
- /**
94
- * Shared packer utilities for OOXML document generation.
95
- *
96
- * @module
97
- */
98
- interface IXmlifyedFile {
95
+ interface XmlifyedFile {
99
96
  readonly path: string;
100
97
  readonly data: string | Uint8Array;
101
98
  }
@@ -106,6 +103,90 @@ declare const PrettifyType: {
106
103
  readonly WITH_TAB: "\t";
107
104
  };
108
105
  declare const convertPrettifyType: (prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]) => (typeof PrettifyType)[keyof typeof PrettifyType] | undefined;
106
+ /** Default DEFLATE compression level matching Microsoft Office behavior. */
107
+ declare const ZIP_DEFLATE_LEVEL = 6;
108
+ /** STORE level for already-compressed media formats (JPEG, PNG, GIF, etc.). */
109
+ declare const ZIP_STORED_LEVEL = 0;
110
+ /**
111
+ * Asynchronously compress files and convert to the requested output format.
112
+ *
113
+ * Uses fflate Web Workers for non-blocking DEFLATE compression.
114
+ * XML entries use DEFLATE by default; media entries should explicitly set
115
+ * `{ level: ZIP_STORED_LEVEL }` to avoid redundant compression.
116
+ */
117
+ declare const zipAndConvert: <T extends OutputType>(files: Zippable$1, type: T, mimeType: string, level?: number) => Promise<OutputByType[T]>;
118
+ /**
119
+ * Synchronously compress files and convert to the requested output format.
120
+ *
121
+ * Uses synchronous DEFLATE compression for maximum throughput.
122
+ * Blocks the event loop — prefer {@link zipAndConvert} in server contexts.
123
+ */
124
+ declare const zipSyncAndConvert: <T extends OutputType>(files: Zippable$1, type: T, mimeType: string, level?: number) => OutputByType[T];
125
+ /**
126
+ * Create a Node.js Readable stream from compressed file entries.
127
+ *
128
+ * Uses fflate's AsyncZipDeflate for non-blocking DEFLATE compression via
129
+ * Web Workers. STORED entries (media) pass through synchronously.
130
+ * Chunks are emitted asynchronously as each file's compression completes.
131
+ */
132
+ declare const createZipStream: (files: Zippable$1) => Readable;
133
+ type PrettifyValue = (typeof PrettifyType)[keyof typeof PrettifyType];
134
+ /**
135
+ * Compile function provided by each package to convert a file object into a Zippable map.
136
+ */
137
+ type CompileFn<TFile> = (file: TFile, prettify?: PrettifyValue, overrides?: readonly XmlifyedFile[]) => Zippable$1;
138
+ /**
139
+ * Packer interface returned by {@link createPacker}.
140
+ *
141
+ * Async methods use fflate Web Workers for non-blocking compression.
142
+ * Sync methods use synchronous compression for maximum throughput in
143
+ * CLI scripts and build tools.
144
+ */
145
+ interface Packer<TFile> {
146
+ /** Compile file to Zippable map (synchronous). */
147
+ compile: CompileFn<TFile>;
148
+ /** Generic async output — returns the requested OutputType. */
149
+ pack<T extends OutputType>(file: TFile, type: T, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Promise<OutputByType[T]>;
150
+ /** Generic sync output — returns the requested OutputType. */
151
+ packSync<T extends OutputType>(file: TFile, type: T, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): OutputByType[T];
152
+ /** Async → `Promise<Uint8Array>` (like `Response.bytes()`). */
153
+ toBytes(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Promise<Uint8Array>;
154
+ /** Sync → `Uint8Array`. */
155
+ toBytesSync(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Uint8Array;
156
+ /** Async → `Promise<string>` (raw ZIP content as string). */
157
+ toString(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Promise<string>;
158
+ /** Sync → `string`. */
159
+ toStringSync(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): string;
160
+ /** Async → `Promise<Buffer>` (Node.js). */
161
+ toBuffer(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Promise<Buffer>;
162
+ /** Sync → `Buffer` (Node.js). */
163
+ toBufferSync(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Buffer;
164
+ /** Async → `Promise<string>` (base64-encoded). */
165
+ toBase64String(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Promise<string>;
166
+ /** Sync → `string` (base64-encoded). */
167
+ toBase64StringSync(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): string;
168
+ /** Async → `Promise<Blob>` (browser). */
169
+ toBlob(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Promise<Blob>;
170
+ /** Sync → `Blob`. */
171
+ toBlobSync(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Blob;
172
+ /** Async → `Promise<ArrayBuffer>`. */
173
+ toArrayBuffer(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Promise<ArrayBuffer>;
174
+ /** Sync → `ArrayBuffer`. */
175
+ toArrayBufferSync(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): ArrayBuffer;
176
+ /** Streaming output via Node.js Readable (truly async, uses Web Workers). */
177
+ toStream(file: TFile, prettify?: boolean | PrettifyValue, overrides?: readonly XmlifyedFile[]): Readable;
178
+ }
179
+ /**
180
+ * Create a Packer object with all output format methods.
181
+ *
182
+ * Centralises the ZIP → convert pipeline and the streaming implementation
183
+ * so that each OOXML package only needs to provide a `compile` function and
184
+ * a MIME type.
185
+ */
186
+ declare const createPacker: <TFile>(options: {
187
+ readonly compile: CompileFn<TFile>;
188
+ readonly mimeType: string;
189
+ }) => Packer<TFile>;
109
190
  //#endregion
110
191
  //#region src/opc/app-properties.d.ts
111
192
  declare class AppProperties extends ImportedXmlComponent {
@@ -124,7 +205,7 @@ declare class Relationships extends BaseXmlComponent {
124
205
  constructor();
125
206
  addRelationship(id: number | string, type: RelationshipType, target: string, targetMode?: (typeof TargetModeType)[keyof typeof TargetModeType]): void;
126
207
  get RelationshipCount(): number;
127
- prepForXml(_context: IContext): IXmlableObject;
208
+ prepForXml(_context: Context): IXmlableObject;
128
209
  }
129
210
  //#endregion
130
211
  //#region src/opc/content-types.d.ts
@@ -144,25 +225,14 @@ interface OverrideAttributes {
144
225
  * Creates an Override element mapping a specific part path to a MIME content type.
145
226
  */
146
227
  declare const createOverride: (contentType: string, partName?: string) => XmlComponent;
147
- /**
148
- * Attributes for the Types (Content Types) root element.
149
- * Declares the XML namespace for the content types part.
150
- */
151
- declare class ContentTypeAttributes extends XmlAttributeComponent<{
152
- readonly xmlns?: string;
153
- }> {
154
- protected readonly xmlKeys: {
155
- xmlns: string;
156
- };
157
- }
158
228
  //#endregion
159
229
  //#region src/formatter.d.ts
160
230
  /**
161
231
  * Converts an XmlComponent tree into a serializable XML object.
162
232
  */
163
233
  declare class Formatter {
164
- format<T extends IContext = IContext>(input: BaseXmlComponent, context?: T): IXmlableObject;
165
- formatToXml(input: XmlComponent, context: IContext, declaration?: boolean): string;
234
+ format<T extends Context = Context>(input: BaseXmlComponent, context?: T): IXmlableObject;
235
+ formatToXml(input: XmlComponent, context: Context, declaration?: boolean): string;
166
236
  }
167
237
  //#endregion
168
238
  //#region src/core-properties.d.ts
@@ -244,7 +314,7 @@ declare function elementToCompact(el: Element): IXmlableObject;
244
314
  declare class RawPassthrough extends BaseXmlComponent {
245
315
  private readonly element;
246
316
  constructor(element: Element);
247
- prepForXml(_context: IContext): IXmlableObject;
317
+ prepForXml(_context: Context): IXmlableObject;
248
318
  }
249
319
  //#endregion
250
320
  //#region src/placeholder.d.ts
@@ -276,4 +346,4 @@ interface SmartArtRelOptions {
276
346
  declare function replaceSmartArtPlaceholders(xml: string, keys: readonly string[], dataOffset: number, idFormat?: IdFormat): string;
277
347
  declare function addSmartArtRelationships(keys: readonly string[], addRel: (id: number, type: RelationshipType, target: string, targetMode?: string) => void, baseOffset: number, globalStartIndex: number, options: SmartArtRelOptions): void;
278
348
  //#endregion
279
- export { AppProperties, AttributeData, AttributeMap, AttributePayload, BaseXmlComponent, BuilderElement, COLOR_CATEGORIES, Connection, ContentTypeAttributes, CoreProperties, DEFAULT_DRAWING_XML, DataModel, type DefaultAttributes, EMPTY_OBJECT, EmptyElement, Formatter, HpsMeasureElement, IContext, ISmartArtData, ITreeNode, IXmlAttribute, IXmlableObject, IXmlifyedFile, IdFormat, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, LAYOUT_CATEGORIES, NextAttributeComponent, NumberValueElement, OnOffElement, OoxmlMimeType, OutputByType, OutputType, type OverrideAttributes, ParsedDocument, Percentage, Point, PositivePercentage, PositiveUniversalMeasure, PrettifyType, RawPassthrough, Relationship, type RelationshipType, Relationships, RelativeMeasure, STYLE_CATEGORIES, SmartArtCollection, SmartArtRelOptions, StringContainer, StringEnumValueElement, StringValueElement, TargetModeType, ThemeColor, ThemeFont, TransPoint, UniqueNumericIdCreator, UniversalMeasure, XmlAttributeComponent, XmlComponent, addSmartArtRelationships, buildCorePropertiesXml, chartAttr, collectPlaceholderKeys, convertEmuToInches, convertEmuToPixels, convertEmuToPoints, convertInchesToEmu, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertPixelsToEmu, convertPointsToEmu, convertPrettifyType, convertToXmlComponent, createDataModel, createDefault, createOverride, dateTimeValue, decimalNumber, eighthPointMeasureValue, elementToCompact, elementToXml, escapeRegex, findRel, findRelsByType, formatId, getColorXml, getImageType, getLayoutXml, getReferencedMedia, getStyleXml, hasPlaceholders, hashedId, hexBinary, hexColorValue, hpsMeasureObj, hpsMeasureValue, listFiles, longHexNumber, measurementOrPercentValue, numberValObj, onOffObj, parseArchive, parseCoreProperties, parseCorePropsElement, parseRels, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, stringContainerObj, stringEnumValObj, stringValObj, twipsMeasureValue, uCharHexNumber, uint8ToBase64, uniqueId, uniqueNumericIdCreator, uniqueUuid, universalMeasureValue, unsignedDecimalNumber, unzipToMap, wrapEl, zipToBuffer };
349
+ export { AppProperties, AttributeData, AttributeMap, AttributePayload, BaseXmlComponent, BuilderElement, COLOR_CATEGORIES, CompileFn, Connection, Context, CoreProperties, DEFAULT_DRAWING_XML, DataModel, type DefaultAttributes, EMPTY_OBJECT, EmptyElement, Formatter, IXmlAttribute, IXmlableObject, IdFormat, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, LAYOUT_CATEGORIES, NextAttributeComponent, OoxmlMimeType, OutputByType, OutputType, type OverrideAttributes, Packer, ParsedDocument, Percentage, Point, PositivePercentage, PositiveUniversalMeasure, PrettifyType, RawPassthrough, Relationship, type RelationshipType, Relationships, RelativeMeasure, STYLE_CATEGORIES, SmartArtCollection, SmartArtData, SmartArtRelOptions, TargetModeType, ThemeColor, ThemeFont, TransPoint, TreeNode, UniqueNumericIdCreator, UniversalMeasure, XmlAttributeComponent, XmlComponent, XmlifyedFile, ZIP_DEFLATE_LEVEL, ZIP_STORED_LEVEL, type ZipOptions, type Zippable, addSmartArtRelationships, attrObj, buildCorePropertiesXml, chartAttr, collectPlaceholderKeys, convertEmuToInches, convertEmuToPixels, convertEmuToPoints, convertInchesToEmu, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertPixelsToEmu, convertPointsToEmu, convertPrettifyType, convertToXmlComponent, createDataModel, createDefault, createOverride, createPacker, createZipStream, dateTimeValue, decimalNumber, eighthPointMeasureValue, elementToCompact, elementToXml, escapeRegex, findRel, findRelsByType, formatId, getColorXml, getImageType, getLayoutXml, getReferencedMedia, getStyleXml, hasPlaceholders, hashedId, hexBinary, hexColorValue, hpsMeasureObj, hpsMeasureValue, listFiles, longHexNumber, measurementOrPercentValue, numberValObj, onOffObj, parseArchive, parseCoreProperties, parseCorePropsElement, parseRels, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, strFromU8, stringContainerObj, stringEnumValObj, stringValObj, twipsMeasureValue, uCharHexNumber, uint8ToBase64, uniqueId, uniqueNumericIdCreator, uniqueUuid, universalMeasureValue, unsignedDecimalNumber, unzipSync, unzipToMap, wrapEl, zipAndConvert, zipSyncAndConvert, zipToBuffer };
package/dist/index.mjs CHANGED
@@ -1,10 +1,11 @@
1
- import { C as EMPTY_OBJECT, E as BaseXmlComponent, S as XmlAttributeComponent, T as XmlComponent, _ as stringContainerObj, a as BuilderElement, b as wrapEl, c as NumberValueElement, d as StringEnumValueElement, f as StringValueElement, g as onOffObj, h as numberValObj, i as convertToXmlComponent, l as OnOffElement, m as hpsMeasureObj, n as ImportedRootElementAttributes, o as EmptyElement, p as chartAttr, r as ImportedXmlComponent, s as HpsMeasureElement, t as InitializableXmlComponent, u as StringContainer, v as stringEnumValObj, w as IgnoreIfEmptyXmlComponent, x as NextAttributeComponent, y as stringValObj } from "./xml-components-CJKrtCSG.mjs";
1
+ import { _ as XmlAttributeComponent, a as BuilderElement, b as XmlComponent, c as chartAttr, d as onOffObj, f as stringContainerObj, g as NextAttributeComponent, h as wrapEl, i as convertToXmlComponent, l as hpsMeasureObj, m as stringValObj, n as ImportedRootElementAttributes, o as EmptyElement, p as stringEnumValObj, r as ImportedXmlComponent, s as attrObj, t as InitializableXmlComponent, u as numberValObj, v as EMPTY_OBJECT, x as BaseXmlComponent, y as IgnoreIfEmptyXmlComponent } from "./xml-components-CADgke8j.mjs";
2
2
  import { ThemeColor, ThemeFont, dateTimeValue, decimalNumber, eighthPointMeasureValue, hexBinary, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, twipsMeasureValue, uCharHexNumber, universalMeasureValue, unsignedDecimalNumber } from "./values.mjs";
3
3
  import { a as convertEmuToInches, c as convertInchesToEmu, d as convertPixelsToEmu, f as convertPointsToEmu, i as uniqueUuid, l as convertInchesToTwip, n as uniqueId, o as convertEmuToPixels, r as uniqueNumericIdCreator, s as convertEmuToPoints, t as hashedId, u as convertMillimetersToTwip } from "./id-generators-CM3u923a.mjs";
4
- import { a as DataModel, c as getColorXml, d as COLOR_CATEGORIES, f as LAYOUT_CATEGORIES, i as TransPoint, l as getLayoutXml, n as SmartArtCollection, o as Connection, p as STYLE_CATEGORIES, r as Point, s as DEFAULT_DRAWING_XML, t as createDataModel, u as getStyleXml } from "./smartart-CdBk8E0n.mjs";
4
+ import { a as DataModel, c as getColorXml, d as COLOR_CATEGORIES, f as LAYOUT_CATEGORIES, i as TransPoint, l as getLayoutXml, n as SmartArtCollection, o as Connection, p as STYLE_CATEGORIES, r as Point, s as DEFAULT_DRAWING_XML, t as createDataModel, u as getStyleXml } from "./smartart-CwzSHTBd.mjs";
5
5
  import { elementToXml, findRel, findRelsByType, getImageType, listFiles, parseRels, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, uint8ToBase64, unzipToMap, zipToBuffer } from "./archive.mjs";
6
6
  import { js2xml, textOf, xml2js } from "@office-open/xml";
7
- import { strFromU8, strToU8 } from "fflate";
7
+ import { AsyncZipDeflate, Zip, ZipPassThrough, strFromU8, strFromU8 as strFromU8$1, strToU8, unzipSync, zip, zipSync } from "fflate";
8
+ import { Readable } from "stream";
8
9
  //#region src/output-type.ts
9
10
  /**
10
11
  * Output type definitions for OOXML document export.
@@ -21,16 +22,21 @@ const convertOutput = (data, type, mimeType = OoxmlMimeType.DOCX) => {
21
22
  case "blob": return new Blob([data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)], { type: mimeType });
22
23
  case "arraybuffer": return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
23
24
  case "uint8array": return data;
24
- case "base64": return btoa(strFromU8(data, true));
25
+ case "base64": return btoa(strFromU8$1(data, true));
25
26
  case "string":
26
27
  case "text":
27
- case "binarystring": return strFromU8(data, true);
28
+ case "binarystring": return strFromU8$1(data, true);
28
29
  case "array": return [...data];
29
30
  default: return data;
30
31
  }
31
32
  };
32
33
  //#endregion
33
34
  //#region src/packer.ts
35
+ /**
36
+ * Shared packer utilities for OOXML document generation.
37
+ *
38
+ * @module
39
+ */
34
40
  const PrettifyType = {
35
41
  NONE: "",
36
42
  WITH_2_BLANKS: " ",
@@ -38,6 +44,123 @@ const PrettifyType = {
38
44
  WITH_TAB: " "
39
45
  };
40
46
  const convertPrettifyType = (prettify) => prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? void 0 : prettify;
47
+ /** Default DEFLATE compression level matching Microsoft Office behavior. */
48
+ const ZIP_DEFLATE_LEVEL = 6;
49
+ /** STORE level for already-compressed media formats (JPEG, PNG, GIF, etc.). */
50
+ const ZIP_STORED_LEVEL = 0;
51
+ /**
52
+ * Asynchronously compress files and convert to the requested output format.
53
+ *
54
+ * Uses fflate Web Workers for non-blocking DEFLATE compression.
55
+ * XML entries use DEFLATE by default; media entries should explicitly set
56
+ * `{ level: ZIP_STORED_LEVEL }` to avoid redundant compression.
57
+ */
58
+ const zipAndConvert = async (files, type, mimeType, level = 6) => {
59
+ return convertOutput(await new Promise((resolve, reject) => {
60
+ zip(files, { level }, (err, data) => {
61
+ if (err) reject(err);
62
+ else resolve(data);
63
+ });
64
+ }), type, mimeType);
65
+ };
66
+ /**
67
+ * Synchronously compress files and convert to the requested output format.
68
+ *
69
+ * Uses synchronous DEFLATE compression for maximum throughput.
70
+ * Blocks the event loop — prefer {@link zipAndConvert} in server contexts.
71
+ */
72
+ const zipSyncAndConvert = (files, type, mimeType, level = 6) => {
73
+ return convertOutput(zipSync(files, { level }), type, mimeType);
74
+ };
75
+ /**
76
+ * Create a Node.js Readable stream from compressed file entries.
77
+ *
78
+ * Uses fflate's AsyncZipDeflate for non-blocking DEFLATE compression via
79
+ * Web Workers. STORED entries (media) pass through synchronously.
80
+ * Chunks are emitted asynchronously as each file's compression completes.
81
+ */
82
+ const createZipStream = (files) => {
83
+ const stream = new Readable({ read() {} });
84
+ try {
85
+ const zip = new Zip((err, chunk, final) => {
86
+ if (err) {
87
+ stream.destroy(err);
88
+ return;
89
+ }
90
+ if (!stream.destroyed) stream.push(Buffer.from(chunk));
91
+ if (final) stream.push(null);
92
+ });
93
+ for (const [name, data] of Object.entries(files)) {
94
+ const raw = Array.isArray(data) ? data[0] : data;
95
+ const level = Array.isArray(data) ? data[1].level ?? 6 : 6;
96
+ const entry = level === 0 ? new ZipPassThrough(name) : new AsyncZipDeflate(name, { level });
97
+ zip.add(entry);
98
+ entry.push(raw, true);
99
+ }
100
+ zip.end();
101
+ } catch (err) {
102
+ stream.destroy(err instanceof Error ? err : new Error(String(err)));
103
+ }
104
+ return stream;
105
+ };
106
+ /**
107
+ * Create a Packer object with all output format methods.
108
+ *
109
+ * Centralises the ZIP → convert pipeline and the streaming implementation
110
+ * so that each OOXML package only needs to provide a `compile` function and
111
+ * a MIME type.
112
+ */
113
+ const createPacker = (options) => {
114
+ const { compile, mimeType } = options;
115
+ const compileFiles = (file, prettify, overrides = []) => compile(file, convertPrettifyType(prettify), overrides);
116
+ const pack = async (file, type, prettify, overrides) => {
117
+ return zipAndConvert(compileFiles(file, prettify, overrides), type, mimeType);
118
+ };
119
+ const toBytes = (file, prettify, overrides) => pack(file, "uint8array", prettify, overrides);
120
+ const toString = (file, prettify, overrides) => pack(file, "string", prettify, overrides);
121
+ const toBuffer = (file, prettify, overrides) => pack(file, "nodebuffer", prettify, overrides);
122
+ const toBase64String = (file, prettify, overrides) => pack(file, "base64", prettify, overrides);
123
+ const toBlob = (file, prettify, overrides) => pack(file, "blob", prettify, overrides);
124
+ const toArrayBuffer = (file, prettify, overrides) => pack(file, "arraybuffer", prettify, overrides);
125
+ const packSync = (file, type, prettify, overrides) => {
126
+ return zipSyncAndConvert(compileFiles(file, prettify, overrides), type, mimeType);
127
+ };
128
+ const toBytesSync = (file, prettify, overrides) => packSync(file, "uint8array", prettify, overrides);
129
+ const toStringSync = (file, prettify, overrides) => packSync(file, "string", prettify, overrides);
130
+ const toBufferSync = (file, prettify, overrides) => packSync(file, "nodebuffer", prettify, overrides);
131
+ const toBase64StringSync = (file, prettify, overrides) => packSync(file, "base64", prettify, overrides);
132
+ const toBlobSync = (file, prettify, overrides) => packSync(file, "blob", prettify, overrides);
133
+ const toArrayBufferSync = (file, prettify, overrides) => packSync(file, "arraybuffer", prettify, overrides);
134
+ const toStream = (file, prettify, overrides) => {
135
+ let files;
136
+ try {
137
+ files = compileFiles(file, prettify, overrides);
138
+ } catch (err) {
139
+ const errorStream = new Readable({ read() {} });
140
+ errorStream.destroy(err instanceof Error ? err : new Error(String(err)));
141
+ return errorStream;
142
+ }
143
+ return createZipStream(files);
144
+ };
145
+ return {
146
+ compile,
147
+ pack,
148
+ packSync,
149
+ toBytes,
150
+ toBytesSync,
151
+ toString,
152
+ toStringSync,
153
+ toBuffer,
154
+ toBufferSync,
155
+ toBase64String,
156
+ toBase64StringSync,
157
+ toBlob,
158
+ toBlobSync,
159
+ toArrayBuffer,
160
+ toArrayBufferSync,
161
+ toStream
162
+ };
163
+ };
41
164
  //#endregion
42
165
  //#region src/opc/app-properties.ts
43
166
  const APP_PROPS_XML = "<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\"/>";
@@ -129,13 +252,6 @@ const createOverride = (contentType, partName) => new BuilderElement({
129
252
  },
130
253
  name: "Override"
131
254
  });
132
- /**
133
- * Attributes for the Types (Content Types) root element.
134
- * Declares the XML namespace for the content types part.
135
- */
136
- var ContentTypeAttributes = class extends XmlAttributeComponent {
137
- xmlKeys = { xmlns: "xmlns" };
138
- };
139
255
  //#endregion
140
256
  //#region src/formatter.ts
141
257
  const XML_DECL = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
@@ -259,7 +375,7 @@ var ParsedDocument = class {
259
375
  get(path) {
260
376
  const modData = this.modified.get(path);
261
377
  if (modData) {
262
- const wrapper = xml2js(strFromU8(modData), XML_PARSE_OPTIONS);
378
+ const wrapper = xml2js(strFromU8$1(modData), XML_PARSE_OPTIONS);
263
379
  this.wrapperCache.set(path, wrapper);
264
380
  return wrapper.elements?.find((e) => e.type === "element");
265
381
  }
@@ -267,7 +383,7 @@ var ParsedDocument = class {
267
383
  if (data === void 0) return void 0;
268
384
  const cached = this.wrapperCache.get(path);
269
385
  if (cached) return cached.elements?.find((e) => e.type === "element");
270
- const wrapper = xml2js(strFromU8(data), XML_PARSE_OPTIONS);
386
+ const wrapper = xml2js(strFromU8$1(data), XML_PARSE_OPTIONS);
271
387
  this.wrapperCache.set(path, wrapper);
272
388
  return wrapper.elements?.find((e) => e.type === "element");
273
389
  }
@@ -333,7 +449,7 @@ function elementToCompact(el) {
333
449
  const inner = {};
334
450
  if (el.attributes && Object.keys(el.attributes).length > 0) inner._attributes = el.attributes;
335
451
  if (el.cdata) inner._cdata = el.cdata;
336
- else if (el.text != null) inner._text = el.text;
452
+ else if (el.text !== null && el.text !== void 0) inner._text = el.text;
337
453
  if (el.elements) for (const child of el.elements) {
338
454
  const key = child.name ?? "_unknown";
339
455
  const compactChild = elementToCompact(child);
@@ -429,4 +545,4 @@ function addSmartArtRelationships(keys, addRel, baseOffset, globalStartIndex, op
429
545
  });
430
546
  }
431
547
  //#endregion
432
- export { AppProperties, BaseXmlComponent, BuilderElement, COLOR_CATEGORIES, Connection, ContentTypeAttributes, DEFAULT_DRAWING_XML, DataModel, EMPTY_OBJECT, EmptyElement, Formatter, HpsMeasureElement, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, LAYOUT_CATEGORIES, NextAttributeComponent, NumberValueElement, OnOffElement, OoxmlMimeType, ParsedDocument, Point, PrettifyType, RawPassthrough, Relationships, STYLE_CATEGORIES, SmartArtCollection, StringContainer, StringEnumValueElement, StringValueElement, TargetModeType, ThemeColor, ThemeFont, TransPoint, XmlAttributeComponent, XmlComponent, addSmartArtRelationships, buildCorePropertiesXml, chartAttr, collectPlaceholderKeys, convertEmuToInches, convertEmuToPixels, convertEmuToPoints, convertInchesToEmu, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertPixelsToEmu, convertPointsToEmu, convertPrettifyType, convertToXmlComponent, createDataModel, createDefault, createOverride, dateTimeValue, decimalNumber, eighthPointMeasureValue, elementToCompact, elementToXml, escapeRegex, findRel, findRelsByType, formatId, getColorXml, getImageType, getLayoutXml, getReferencedMedia, getStyleXml, hasPlaceholders, hashedId, hexBinary, hexColorValue, hpsMeasureObj, hpsMeasureValue, listFiles, longHexNumber, measurementOrPercentValue, numberValObj, onOffObj, parseArchive, parseCoreProperties, parseCorePropsElement, parseRels, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, stringContainerObj, stringEnumValObj, stringValObj, twipsMeasureValue, uCharHexNumber, uint8ToBase64, uniqueId, uniqueNumericIdCreator, uniqueUuid, universalMeasureValue, unsignedDecimalNumber, unzipToMap, wrapEl, zipToBuffer };
548
+ export { AppProperties, BaseXmlComponent, BuilderElement, COLOR_CATEGORIES, Connection, DEFAULT_DRAWING_XML, DataModel, EMPTY_OBJECT, EmptyElement, Formatter, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, LAYOUT_CATEGORIES, NextAttributeComponent, OoxmlMimeType, ParsedDocument, Point, PrettifyType, RawPassthrough, Relationships, STYLE_CATEGORIES, SmartArtCollection, TargetModeType, ThemeColor, ThemeFont, TransPoint, XmlAttributeComponent, XmlComponent, ZIP_DEFLATE_LEVEL, ZIP_STORED_LEVEL, addSmartArtRelationships, attrObj, buildCorePropertiesXml, chartAttr, collectPlaceholderKeys, convertEmuToInches, convertEmuToPixels, convertEmuToPoints, convertInchesToEmu, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertPixelsToEmu, convertPointsToEmu, convertPrettifyType, convertToXmlComponent, createDataModel, createDefault, createOverride, createPacker, createZipStream, dateTimeValue, decimalNumber, eighthPointMeasureValue, elementToCompact, elementToXml, escapeRegex, findRel, findRelsByType, formatId, getColorXml, getImageType, getLayoutXml, getReferencedMedia, getStyleXml, hasPlaceholders, hashedId, hexBinary, hexColorValue, hpsMeasureObj, hpsMeasureValue, listFiles, longHexNumber, measurementOrPercentValue, numberValObj, onOffObj, parseArchive, parseCoreProperties, parseCorePropsElement, parseRels, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, replaceChartPlaceholders, replaceImagePlaceholders, replaceSmartArtPlaceholders, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, strFromU8, stringContainerObj, stringEnumValObj, stringValObj, twipsMeasureValue, uCharHexNumber, uint8ToBase64, uniqueId, uniqueNumericIdCreator, uniqueUuid, universalMeasureValue, unsignedDecimalNumber, unzipSync, unzipToMap, wrapEl, zipAndConvert, zipSyncAndConvert, zipToBuffer };
@@ -1,2 +1,2 @@
1
- import { a as Point, c as Connection, d as getLayoutXml, f as getStyleXml, h as STYLE_CATEGORIES, i as SmartArtCollection, l as DEFAULT_DRAWING_XML, m as LAYOUT_CATEGORIES, n as createDataModel, o as TransPoint, p as COLOR_CATEGORIES, r as ISmartArtData, s as DataModel, t as ITreeNode, u as getColorXml } from "../index-rASwxHbF.mjs";
2
- export { COLOR_CATEGORIES, Connection, DEFAULT_DRAWING_XML, DataModel, ISmartArtData, ITreeNode, LAYOUT_CATEGORIES, Point, STYLE_CATEGORIES, SmartArtCollection, TransPoint, createDataModel, getColorXml, getLayoutXml, getStyleXml };
1
+ import { a as Point, c as Connection, d as getLayoutXml, f as getStyleXml, h as STYLE_CATEGORIES, i as SmartArtData, l as DEFAULT_DRAWING_XML, m as LAYOUT_CATEGORIES, n as createDataModel, o as TransPoint, p as COLOR_CATEGORIES, r as SmartArtCollection, s as DataModel, t as TreeNode, u as getColorXml } from "../index-DVqYs1vv.mjs";
2
+ export { COLOR_CATEGORIES, Connection, DEFAULT_DRAWING_XML, DataModel, LAYOUT_CATEGORIES, Point, STYLE_CATEGORIES, SmartArtCollection, SmartArtData, TransPoint, TreeNode, createDataModel, getColorXml, getLayoutXml, getStyleXml };
@@ -1,2 +1,2 @@
1
- import { a as DataModel, c as getColorXml, d as COLOR_CATEGORIES, f as LAYOUT_CATEGORIES, i as TransPoint, l as getLayoutXml, n as SmartArtCollection, o as Connection, p as STYLE_CATEGORIES, r as Point, s as DEFAULT_DRAWING_XML, t as createDataModel, u as getStyleXml } from "../smartart-CdBk8E0n.mjs";
1
+ import { a as DataModel, c as getColorXml, d as COLOR_CATEGORIES, f as LAYOUT_CATEGORIES, i as TransPoint, l as getLayoutXml, n as SmartArtCollection, o as Connection, p as STYLE_CATEGORIES, r as Point, s as DEFAULT_DRAWING_XML, t as createDataModel, u as getStyleXml } from "../smartart-CwzSHTBd.mjs";
2
2
  export { COLOR_CATEGORIES, Connection, DEFAULT_DRAWING_XML, DataModel, LAYOUT_CATEGORIES, Point, STYLE_CATEGORIES, SmartArtCollection, TransPoint, createDataModel, getColorXml, getLayoutXml, getStyleXml };
@@ -1,4 +1,4 @@
1
- import { T as XmlComponent, p as chartAttr } from "./xml-components-CJKrtCSG.mjs";
1
+ import { b as XmlComponent, c as chartAttr } from "./xml-components-CADgke8j.mjs";
2
2
  //#region src/smartart/categories.ts
3
3
  /** Layout ID → OOXML category type */
4
4
  const LAYOUT_CATEGORIES = {
@@ -34,7 +34,7 @@ var XmlComponent = class extends BaseXmlComponent {
34
34
  root;
35
35
  constructor(rootKey) {
36
36
  super(rootKey);
37
- this.root = new Array();
37
+ this.root = [];
38
38
  }
39
39
  /**
40
40
  * Prepares this component and its children for XML serialization.
@@ -117,10 +117,13 @@ var NextAttributeComponent = class extends BaseXmlComponent {
117
117
  this.root = root;
118
118
  }
119
119
  prepForXml(_) {
120
- return { _attr: Object.values(this.root).filter(({ value }) => value !== void 0).reduce((acc, { key, value }) => ({
121
- ...acc,
122
- [key]: value
123
- }), {}) };
120
+ const attrs = {};
121
+ const values = Object.values(this.root);
122
+ for (let i = 0; i < values.length; i++) {
123
+ const { key, value } = values[i];
124
+ if (value !== void 0) attrs[key] = value;
125
+ }
126
+ return { _attr: attrs };
124
127
  }
125
128
  };
126
129
  //#endregion
@@ -130,6 +133,14 @@ var NextAttributeComponent = class extends BaseXmlComponent {
130
133
  *
131
134
  * @module
132
135
  */
136
+ /**
137
+ * Build an XML element with arbitrary attributes, filtering out undefined values.
138
+ */
139
+ function attrObj(name, attrs) {
140
+ const filtered = {};
141
+ for (const [key, val] of Object.entries(attrs)) if (val !== void 0) filtered[key] = val;
142
+ return { [name]: { _attr: filtered } };
143
+ }
133
144
  const ON_OFF_TRUE_CACHE = /* @__PURE__ */ new Map();
134
145
  /**
135
146
  * Build a CT_OnOff XML object without allocating any XmlComponent.
@@ -182,95 +193,24 @@ function stringContainerObj(name, val) {
182
193
  return { [name]: [val] };
183
194
  }
184
195
  /**
185
- * XML element representing a boolean on/off value (CT_OnOff).
186
- * @deprecated Use `onOffObj()` for hot-path code.
187
- */
188
- var OnOffElement = class extends XmlComponent {
189
- constructor(name, val = true) {
190
- super(name);
191
- if (val !== true) this.root.push(new NextAttributeComponent({ val: {
192
- key: `${name.split(":")[0]}:val`,
193
- value: val
194
- } }));
195
- }
196
- };
197
- /**
198
- * XML element representing a half-point size measurement (CT_HpsMeasure).
199
- * @deprecated Use `hpsMeasureObj()` for hot-path code.
200
- */
201
- var HpsMeasureElement = class extends XmlComponent {
202
- constructor(name, val) {
203
- super(name);
204
- const ns = name.split(":")[0];
205
- this.root.push(new NextAttributeComponent({ val: {
206
- key: `${ns}:val`,
207
- value: hpsMeasureValue(val)
208
- } }));
209
- }
210
- };
211
- /**
212
196
  * XML element representing an empty element (CT_Empty).
213
197
  */
214
198
  var EmptyElement = class extends XmlComponent {};
215
199
  /**
216
- * XML element with a string value attribute (CT_String).
217
- * @deprecated Use `stringValObj()` for hot-path code.
218
- */
219
- var StringValueElement = class extends XmlComponent {
220
- constructor(name, val) {
221
- super(name);
222
- const ns = name.split(":")[0];
223
- this.root.push(new NextAttributeComponent({ val: {
224
- key: `${ns}:val`,
225
- value: val
226
- } }));
227
- }
228
- };
229
- /**
230
- * XML element with a numeric value attribute.
231
- * @deprecated Use `numberValObj()` for hot-path code.
232
- */
233
- var NumberValueElement = class extends XmlComponent {
234
- constructor(name, val) {
235
- super(name);
236
- const ns = name.split(":")[0];
237
- this.root.push(new NextAttributeComponent({ val: {
238
- key: `${ns}:val`,
239
- value: val
240
- } }));
241
- }
242
- };
243
- /**
244
- * XML element with a string enum value attribute.
245
- * @deprecated Use `stringEnumValObj()` for hot-path code.
246
- */
247
- var StringEnumValueElement = class extends XmlComponent {
248
- constructor(name, val) {
249
- super(name);
250
- const ns = name.split(":")[0];
251
- this.root.push(new NextAttributeComponent({ val: {
252
- key: `${ns}:val`,
253
- value: val
254
- } }));
255
- }
256
- };
257
- /**
258
- * XML element containing text content.
259
- * @deprecated Use `stringContainerObj()` for hot-path code.
260
- */
261
- var StringContainer = class extends XmlComponent {
262
- constructor(name, val) {
263
- super(name);
264
- this.root.push(val);
265
- }
266
- };
267
- /**
268
200
  * Flexible XML element builder with explicit attribute and child configuration.
269
201
  */
270
202
  var BuilderElement = class extends XmlComponent {
271
203
  constructor({ name, attributes, children }) {
272
204
  super(name);
273
- if (attributes) this.root.push(new NextAttributeComponent(attributes));
205
+ if (attributes) {
206
+ const attrs = {};
207
+ const vals = Object.values(attributes);
208
+ for (let i = 0; i < vals.length; i++) {
209
+ const { key, value } = vals[i];
210
+ if (value !== void 0) attrs[key] = value;
211
+ }
212
+ this.root.push({ _attr: attrs });
213
+ }
274
214
  if (children) this.root.push(...children);
275
215
  }
276
216
  };
@@ -320,11 +260,6 @@ const convertToXmlComponent = (element) => {
320
260
  }
321
261
  };
322
262
  /**
323
- * Internal attribute component for imported XML elements.
324
- * @internal
325
- */
326
- var ImportedXmlComponentAttributes = class extends XmlAttributeComponent {};
327
- /**
328
263
  * XML component representing imported XML content.
329
264
  */
330
265
  var ImportedXmlComponent = class extends XmlComponent {
@@ -343,7 +278,7 @@ var ImportedXmlComponent = class extends XmlComponent {
343
278
  }
344
279
  constructor(rootKey, _attr) {
345
280
  super(rootKey);
346
- if (_attr) this.root.push(new ImportedXmlComponentAttributes(_attr));
281
+ if (_attr) this.root.push({ _attr });
347
282
  }
348
283
  push(xmlComponent) {
349
284
  this.root.push(xmlComponent);
@@ -378,4 +313,4 @@ var InitializableXmlComponent = class extends XmlComponent {
378
313
  }
379
314
  };
380
315
  //#endregion
381
- export { EMPTY_OBJECT as C, BaseXmlComponent as E, XmlAttributeComponent as S, XmlComponent as T, stringContainerObj as _, BuilderElement as a, wrapEl as b, NumberValueElement as c, StringEnumValueElement as d, StringValueElement as f, onOffObj as g, numberValObj as h, convertToXmlComponent as i, OnOffElement as l, hpsMeasureObj as m, ImportedRootElementAttributes as n, EmptyElement as o, chartAttr as p, ImportedXmlComponent as r, HpsMeasureElement as s, InitializableXmlComponent as t, StringContainer as u, stringEnumValObj as v, IgnoreIfEmptyXmlComponent as w, NextAttributeComponent as x, stringValObj as y };
316
+ export { XmlAttributeComponent as _, BuilderElement as a, XmlComponent as b, chartAttr as c, onOffObj as d, stringContainerObj as f, NextAttributeComponent as g, wrapEl as h, convertToXmlComponent as i, hpsMeasureObj as l, stringValObj as m, ImportedRootElementAttributes as n, EmptyElement as o, stringEnumValObj as p, ImportedXmlComponent as r, attrObj as s, InitializableXmlComponent as t, numberValObj as u, EMPTY_OBJECT as v, BaseXmlComponent as x, IgnoreIfEmptyXmlComponent as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@office-open/core",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Shared OOXML infrastructure: XmlComponent, value validators, unit converters",
5
5
  "keywords": [
6
6
  "core",
@@ -59,12 +59,12 @@
59
59
  "fflate": "0.8.3",
60
60
  "hash.js": "1.1.7",
61
61
  "nanoid": "5.1.11",
62
- "@office-open/xml": "0.6.0"
62
+ "@office-open/xml": "0.6.2"
63
63
  },
64
64
  "scripts": {
65
65
  "dev": "basis build --stub",
66
66
  "build": "vp pack",
67
67
  "test": "vp test run --coverage",
68
- "test:ci": "vp test run --coverage"
68
+ "check": "vp check --fix"
69
69
  }
70
70
  }