Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@office-open/core

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@office-open/core - npm Package Compare versions

Comparing version
0.4.6
to
0.5.0
+1
dist/id-generators-Dd0w7vti.mjs
import e from"hash.js";import{customAlphabet as t,nanoid as n}from"nanoid/non-secure";const r=e=>Math.floor(e/25.4*72*20),i=e=>Math.floor(e*72*20),a=e=>Math.round(e*9525),o=e=>Math.round(e/9525),s=e=>Math.round(e*914400),c=e=>e/914400,l=e=>Math.round(e*12700),u=e=>e/12700,d=(e=0)=>{let t=e;return()=>++t},f=()=>n().toLowerCase(),p=t=>e.sha1().update(t instanceof ArrayBuffer?new Uint8Array(t):t).digest(`hex`),m=e=>t(`1234567890abcdef`,e)(),h=()=>`${m(8)}-${m(4)}-${m(4)}-${m(4)}-${m(12)}`;export{c as a,s as c,a as d,l as f,h as i,i as l,f as n,o,d as r,u as s,p as t,r as u};
import { r as PositiveUniversalMeasure } from "./values-CIh0bdS1.mjs";
import { Element } from "@office-open/xml";
//#region src/xml-components/types.d.ts
/**
* XML-serializable object types for OOXML document generation.
*
* @module
*/
/**
* Attributes for an XML element.
*/
type IXmlAttribute = Readonly<Record<string, string | number | boolean>>;
/**
* Object that can be serialized to XML.
*/
type IXmlableObject = Readonly<Record<string, any>>;
//#endregion
//#region src/xml-components/base.d.ts
/**
* Context object passed through the XML tree during serialization.
*
* @typeParam TFileData - The type of the root file data object (format-specific)
*/
interface IContext<TFileData = unknown> {
/** The root file data object being serialized (format-specific). */
readonly fileData?: TFileData;
/** Current traversal stack of components (mutable for performance). */
readonly stack: IXmlableObject[];
}
/**
* Abstract base class for all XML components.
*/
declare abstract class BaseXmlComponent {
/** The XML element name for this component (e.g., "w:p" for paragraph). */
protected readonly rootKey: string;
constructor(rootKey: string);
/**
* Prepares this component for XML serialization.
*
* @param context - The serialization context
* @returns The XML-serializable object, or undefined to exclude from output
*/
abstract prepForXml(context: IContext): IXmlableObject | undefined;
}
//#endregion
//#region src/xml-components/component.d.ts
/**
* Empty object singleton used for empty XML elements.
*
* @internal
*/
declare const EMPTY_OBJECT: {};
/**
* Base class for all XML components in OOXML documents.
*/
declare abstract class XmlComponent extends BaseXmlComponent {
/**
* Array of child components, text nodes, and attributes.
*/
root: (BaseXmlComponent | IXmlableObject | string)[];
constructor(rootKey: string);
/**
* Prepares this component and its children for XML serialization.
*/
prepForXml(context: IContext): IXmlableObject | undefined;
/**
* Direct XML serialization. Override in subclasses for zero-allocation output.
* Default falls back to prepForXml() + xml().
*/
toXml(context: IContext): string;
/**
* @deprecated Internal use only.
*/
addChildElement(child: BaseXmlComponent | string): XmlComponent;
}
/**
* XML component that is excluded from output if it has no meaningful content.
*/
declare abstract class IgnoreIfEmptyXmlComponent extends XmlComponent {
private readonly includeIfEmpty;
constructor(rootKey: string, includeIfEmpty?: boolean);
prepForXml(context: IContext): IXmlableObject | undefined;
}
//#endregion
//#region src/xml-components/attributes.d.ts
/**
* Maps TypeScript property names to their XML attribute names.
*/
type AttributeMap<T> = Record<keyof T, string>;
/**
* Simple attribute data as a key-value record.
*/
type AttributeData = Record<string, boolean | number | string>;
/**
* Structured attribute payload with explicit key-value mapping.
*/
type AttributePayload<T> = { readonly [P in keyof T]: {
readonly key: string;
readonly value: T[P];
} };
/**
* Base class for creating XML attributes with automatic name mapping.
*/
declare abstract class XmlAttributeComponent<T extends Record<string, any>> extends BaseXmlComponent {
private readonly root;
/** Optional mapping from property names to XML attribute names. */
protected readonly xmlKeys?: AttributeMap<T>;
constructor(root: T);
prepForXml(_: IContext): IXmlableObject;
}
/**
* Next-generation attribute component with explicit key-value pairs.
*/
declare class NextAttributeComponent<T> extends BaseXmlComponent {
private readonly root;
constructor(root: AttributePayload<T>);
prepForXml(_: IContext): IXmlableObject;
}
//#endregion
//#region src/xml-components/elements.d.ts
/**
* Build a CT_OnOff XML object without allocating any XmlComponent.
* `val=true` returns a frozen singleton (cached per name).
*/
declare function onOffObj(name: string, val?: boolean | undefined): IXmlableObject;
/**
* Build a CT_HpsMeasure XML object (half-point size) without allocation.
*/
declare function hpsMeasureObj(name: string, val: number | PositiveUniversalMeasure): IXmlableObject;
/**
* Build a CT_String XML object (string value attribute) without allocation.
*/
declare function stringValObj(name: string, val: string): IXmlableObject;
/**
* Build a numeric value attribute XML object without allocation.
*/
declare function numberValObj(name: string, val: number): IXmlableObject;
/**
* Build a string enum value attribute XML object without allocation.
*/
declare function stringEnumValObj<T extends string>(name: string, val: T): IXmlableObject;
/**
* Build an element wrapping a text string without allocation.
*/
declare function stringContainerObj(name: string, val: string): IXmlableObject;
/**
* XML element representing a boolean on/off value (CT_OnOff).
* @deprecated Use `onOffObj()` for hot-path code.
*/
declare class OnOffElement extends XmlComponent {
constructor(name: string, val?: boolean | undefined);
}
/**
* XML element representing a half-point size measurement (CT_HpsMeasure).
* @deprecated Use `hpsMeasureObj()` for hot-path code.
*/
declare class HpsMeasureElement extends XmlComponent {
constructor(name: string, val: number | PositiveUniversalMeasure);
}
/**
* XML element representing an empty element (CT_Empty).
*/
declare class EmptyElement extends XmlComponent {}
/**
* XML element with a string value attribute (CT_String).
* @deprecated Use `stringValObj()` for hot-path code.
*/
declare class StringValueElement extends XmlComponent {
constructor(name: string, val: string);
}
/**
* XML element with a numeric value attribute.
* @deprecated Use `numberValObj()` for hot-path code.
*/
declare class NumberValueElement extends XmlComponent {
constructor(name: string, val: number);
}
/**
* XML element with a string enum value attribute.
* @deprecated Use `stringEnumValObj()` for hot-path code.
*/
declare class StringEnumValueElement<T extends string> extends XmlComponent {
constructor(name: string, val: T);
}
/**
* XML element containing text content.
* @deprecated Use `stringContainerObj()` for hot-path code.
*/
declare class StringContainer extends XmlComponent {
constructor(name: string, val: string);
}
/**
* Flexible XML element builder with explicit attribute and child configuration.
*/
declare class BuilderElement<T = {}> extends XmlComponent {
constructor({
name,
attributes,
children
}: {
readonly name: string;
readonly attributes?: AttributePayload<T>;
readonly children?: readonly (BaseXmlComponent | string)[];
});
}
/**
* Creates a NextAttributeComponent with explicit XML attribute keys.
*/
declare const chartAttr: (attrs: Record<string, string | number | boolean>) => BaseXmlComponent;
/**
* Wraps a component in a named XmlComponent element.
*/
declare function wrapEl(elementName: string, child: BaseXmlComponent): XmlComponent;
//#endregion
//#region src/xml-components/imported.d.ts
/**
* Converts an xml-js Element into an XmlComponent tree.
*/
declare const convertToXmlComponent: (element: Element) => ImportedXmlComponent | string | undefined;
/**
* XML component representing imported XML content.
*/
declare class ImportedXmlComponent extends XmlComponent {
protected _sourceXml?: string;
static fromXmlString(importedContent: string): ImportedXmlComponent;
get sourceXml(): string | undefined;
toXml(_context: IContext): string;
constructor(rootKey: string, _attr?: any);
push(xmlComponent: XmlComponent | string): void;
}
/**
* Represents attributes for imported root elements.
*/
declare class ImportedRootElementAttributes extends XmlComponent {
private readonly _attr;
constructor(_attr: any);
prepForXml(_: IContext): IXmlableObject;
}
//#endregion
//#region src/xml-components/initializable.d.ts
/**
* XML component that can be initialized from another component.
*/
declare abstract class InitializableXmlComponent extends XmlComponent {
constructor(rootKey: string, initComponent?: XmlComponent);
}
//#endregion
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 };
import { O as XmlComponent } from "./index-DqdJoWmh.mjs";
//#region src/smartart/categories.d.ts
/** Layout ID → OOXML category type */
declare const LAYOUT_CATEGORIES: Record<string, string>;
/** Style ID → OOXML category type */
declare const STYLE_CATEGORIES: Record<string, string>;
/** Color ID → OOXML category type */
declare const COLOR_CATEGORIES: Record<string, string>;
//#endregion
//#region src/smartart/built-in-definitions.d.ts
/**
* Returns layout XML. Full XML for "default", minimal stub for others.
* Stub has no layoutNode so PowerPoint falls back to built-in definitions
* based on the uniqueId / loTypeId in the data model.
*/
declare function getLayoutXml(layoutId: string): string;
/**
* Returns style stub XML with the given uniqueId.
*/
declare function getStyleXml(styleId: string): string;
/**
* Returns color stub XML with the given uniqueId.
*/
declare function getColorXml(colorId: string): string;
/** Minimal drawing cache for SmartArt (Office apps auto-regenerate this on open) */
declare const DEFAULT_DRAWING_XML: string;
//#endregion
//#region src/smartart/data-model/connection.d.ts
/**
* dgm:cxn — SmartArt data model connection (edge).
*/
declare class Connection extends XmlComponent {
constructor(modelId: string, srcId: string, destId: string, type?: string, srcOrd?: number, destOrd?: number, parTransId?: string, sibTransId?: string);
}
//#endregion
//#region src/smartart/data-model/data-model.d.ts
/**
* CT_DataModel — the complete data model for a SmartArt diagram.
*/
declare class DataModel extends XmlComponent {
constructor(points: readonly XmlComponent[], connections: readonly Connection[]);
}
//#endregion
//#region src/smartart/data-model/point.d.ts
/**
* dgm:pt — SmartArt data model point (node).
*/
declare class Point extends XmlComponent {
constructor(modelId: string, text: string, type?: string);
}
/**
* Transition point (parTrans or sibTrans) — no text body, references a connection.
*/
declare class TransPoint extends XmlComponent {
constructor(modelId: string, type: string, cxnId: string);
}
//#endregion
//#region src/smartart/smartart-collection.d.ts
interface ISmartArtData {
readonly key: string;
readonly dataModel: DataModel;
readonly layout: string;
readonly style: string;
readonly color: string;
}
/**
* Manages SmartArt parts in a document.
*/
declare class SmartArtCollection {
private readonly map;
constructor();
addSmartArt(key: string, data: ISmartArtData): void;
get Array(): readonly ISmartArtData[];
}
//#endregion
//#region src/smartart/tree-to-model.d.ts
interface ITreeNode {
readonly text: string;
readonly children?: readonly ITreeNode[];
}
/**
* Creates a DataModel from tree nodes with layout/style/color settings.
*/
declare const createDataModel: (nodes: readonly ITreeNode[], layout?: string, style?: string, color?: string) => DataModel;
//#endregion
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 };
import{T as e,p as t}from"./xml-components-Csq7gWPd.mjs";const n={default:`list`,list1:`list`,list2:`list`,vList2:`list`,hList1:`list`,pList1:`list`,process1:`process`,process2:`process`,process3:`process`,process4:`process`,chevron1:`process`,chevron2:`process`,arrow1:`process`,arrow2:`process`,cycle1:`cycle`,cycle2:`cycle`,cycle3:`cycle`,cycle4:`cycle`,cycle5:`cycle`,hierarchy1:`hier`,hierarchy2:`hier`,hierarchy3:`hier`,hierarchy4:`hier`,orgChart1:`hier`,pyramid1:`pyramid`,pyramid2:`pyramid`,pyramid3:`pyramid`,matrix1:`matrix`,matrix2:`matrix`,matrix3:`matrix`,radial1:`rel`,radial2:`rel`,radial3:`rel`,venn1:`rel`,funnel1:`rel`,balance1:`rel`,gear1:`rel`,constOrg1:`rel`,oppId1:`rel`},r={simple1:`simple`,simple2:`simple`,simple3:`simple`,simple4:`simple`,simple5:`simple`,moderate1:`moderate`,moderate2:`moderate`,moderate3:`moderate`,moderate4:`moderate`,polished1:`polished`,polished2:`polished`,polished3:`polished`,polished4:`polished`,professional1:`professional`,professional2:`professional`,professional3:`professional`,professional4:`professional`,cartoon1:`cartoon`,cartoon2:`cartoon`,cartoon3:`cartoon`,cartoon4:`cartoon`,powdery1:`powdery`,powdery2:`powdery`,powdery3:`powdery`,powdery4:`powdery`,burnt1:`burnt`,burnt2:`burnt`,burnt3:`burnt`,burnt4:`burnt`},i={accent1_2:`accent1`,accent2_2:`accent2`,accent3_2:`accent3`,accent4_2:`accent4`,accent5_2:`accent5`,accent6_2:`accent6`,colorful1:`colorful`,colorful2:`colorful`,colorful3:`colorful`,colorful4:`colorful`,dark1:`dark`,dark2:`dark`,primary1:`primary`,primary2:`primary`,gray1:`gray`,gray2:`gray`},a=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`;function o(e){if(e===`default`)return a+`<dgm:layoutDef xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" uniqueId="urn:microsoft.com/office/officeart/2005/8/layout/default"><dgm:title val=""/><dgm:desc val=""/><dgm:catLst><dgm:cat type="list" pri="400"/></dgm:catLst><dgm:sampData><dgm:dataModel><dgm:ptLst><dgm:pt modelId="0" type="doc"/><dgm:pt modelId="1"><dgm:prSet phldr="1"/></dgm:pt><dgm:pt modelId="2"><dgm:prSet phldr="1"/></dgm:pt><dgm:pt modelId="3"><dgm:prSet phldr="1"/></dgm:pt><dgm:pt modelId="4"><dgm:prSet phldr="1"/></dgm:pt><dgm:pt modelId="5"><dgm:prSet phldr="1"/></dgm:pt></dgm:ptLst><dgm:cxnLst><dgm:cxn modelId="6" srcId="0" destId="1" srcOrd="0" destOrd="0"/><dgm:cxn modelId="7" srcId="0" destId="2" srcOrd="1" destOrd="0"/><dgm:cxn modelId="8" srcId="0" destId="3" srcOrd="2" destOrd="0"/><dgm:cxn modelId="9" srcId="0" destId="4" srcOrd="3" destOrd="0"/><dgm:cxn modelId="10" srcId="0" destId="5" srcOrd="4" destOrd="0"/></dgm:cxnLst><dgm:bg/><dgm:whole/></dgm:dataModel></dgm:sampData><dgm:styleData><dgm:dataModel><dgm:ptLst><dgm:pt modelId="0" type="doc"/><dgm:pt modelId="1"/><dgm:pt modelId="2"/></dgm:ptLst><dgm:cxnLst><dgm:cxn modelId="3" srcId="0" destId="1" srcOrd="0" destOrd="0"/><dgm:cxn modelId="4" srcId="0" destId="2" srcOrd="1" destOrd="0"/></dgm:cxnLst><dgm:bg/><dgm:whole/></dgm:dataModel></dgm:styleData><dgm:clrData><dgm:dataModel><dgm:ptLst><dgm:pt modelId="0" type="doc"/><dgm:pt modelId="1"/><dgm:pt modelId="2"/><dgm:pt modelId="3"/><dgm:pt modelId="4"/><dgm:pt modelId="5"/><dgm:pt modelId="6"/></dgm:ptLst><dgm:cxnLst><dgm:cxn modelId="7" srcId="0" destId="1" srcOrd="0" destOrd="0"/><dgm:cxn modelId="8" srcId="0" destId="2" srcOrd="1" destOrd="0"/><dgm:cxn modelId="9" srcId="0" destId="3" srcOrd="2" destOrd="0"/><dgm:cxn modelId="10" srcId="0" destId="4" srcOrd="3" destOrd="0"/><dgm:cxn modelId="11" srcId="0" destId="5" srcOrd="4" destOrd="0"/><dgm:cxn modelId="12" srcId="0" destId="6" srcOrd="5" destOrd="0"/></dgm:cxnLst><dgm:bg/><dgm:whole/></dgm:dataModel></dgm:clrData><dgm:layoutNode name="diagram"><dgm:varLst><dgm:dir/><dgm:resizeHandles val="exact"/></dgm:varLst><dgm:choose name="Name0"><dgm:if name="Name1" func="var" arg="dir" op="equ" val="norm"><dgm:alg type="snake"><dgm:param type="grDir" val="tL"/><dgm:param type="flowDir" val="row"/><dgm:param type="contDir" val="sameDir"/><dgm:param type="off" val="ctr"/></dgm:alg></dgm:if><dgm:else name="Name2"><dgm:alg type="snake"><dgm:param type="grDir" val="tR"/><dgm:param type="flowDir" val="row"/><dgm:param type="contDir" val="sameDir"/><dgm:param type="off" val="ctr"/></dgm:alg></dgm:else></dgm:choose><dgm:shape xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:blip=""><dgm:adjLst/></dgm:shape><dgm:presOf/><dgm:constrLst><dgm:constr type="w" for="ch" forName="node" refType="w"/><dgm:constr type="h" for="ch" forName="node" refType="w" refFor="ch" refForName="node" fact="0.6"/><dgm:constr type="w" for="ch" forName="sibTrans" refType="w" refFor="ch" refForName="node" fact="0.1"/><dgm:constr type="sp" refType="w" refFor="ch" refForName="sibTrans"/><dgm:constr type="primFontSz" for="ch" forName="node" op="equ" val="65"/></dgm:constrLst><dgm:ruleLst/><dgm:forEach name="Name3" axis="ch" ptType="node"><dgm:layoutNode name="node"><dgm:varLst><dgm:bulletEnabled val="1"/></dgm:varLst><dgm:alg type="tx"/><dgm:shape type="rect" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:blip=""><dgm:adjLst/></dgm:shape><dgm:presOf axis="desOrSelf" ptType="node"/><dgm:constrLst><dgm:constr type="lMarg" refType="primFontSz" fact="0.3"/><dgm:constr type="rMarg" refType="primFontSz" fact="0.3"/><dgm:constr type="tMarg" refType="primFontSz" fact="0.3"/><dgm:constr type="bMarg" refType="primFontSz" fact="0.3"/></dgm:constrLst><dgm:ruleLst><dgm:rule type="primFontSz" val="5" fact="NaN" max="NaN"/></dgm:ruleLst></dgm:layoutNode><dgm:forEach name="Name4" axis="followSib" ptType="sibTrans" cnt="1"><dgm:layoutNode name="sibTrans"><dgm:alg type="sp"/><dgm:shape xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:blip=""><dgm:adjLst/></dgm:shape><dgm:presOf/><dgm:constrLst/><dgm:ruleLst/></dgm:layoutNode></dgm:forEach></dgm:layoutNode></dgm:layoutDef>`;let t=n[e]??`list`;return a+`<dgm:layoutDef xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" uniqueId="urn:microsoft.com/office/officeart/2005/8/layout/`+e+`"><dgm:title val=""/><dgm:desc val=""/><dgm:catLst><dgm:cat type="`+t+`" pri="400"/></dgm:catLst><dgm:sampData><dgm:dataModel><dgm:ptLst><dgm:pt modelId="0" type="doc"/><dgm:pt modelId="1"><dgm:prSet phldr="1"/></dgm:pt><dgm:pt modelId="2"><dgm:prSet phldr="1"/></dgm:pt></dgm:ptLst><dgm:cxnLst><dgm:cxn modelId="3" srcId="0" destId="1" srcOrd="0" destOrd="0"/><dgm:cxn modelId="4" srcId="0" destId="2" srcOrd="1" destOrd="0"/></dgm:cxnLst><dgm:bg/><dgm:whole/></dgm:dataModel></dgm:sampData></dgm:layoutDef>`}function s(e){let t=r[e]??`simple`;return a+`<dgm:styleDef xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" uniqueId="urn:microsoft.com/office/officeart/2005/8/quickstyle/`+e+`"><dgm:title val=""/><dgm:desc val=""/><dgm:catLst><dgm:cat type="`+t+`" pri="10100"/></dgm:catLst><dgm:scene3d><a:camera prst="orthographicFront"/><a:lightRig rig="threePt" dir="t"/></dgm:scene3d></dgm:styleDef>`}function c(e){let t=i[e]??`accent1`;return a+`<dgm:colorsDef xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" uniqueId="urn:microsoft.com/office/officeart/2005/8/colors/`+e+`"><dgm:title val=""/><dgm:desc val=""/><dgm:catLst><dgm:cat type="`+t+`" pri="11200"/></dgm:catLst></dgm:colorsDef>`}const l=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><dsp:drawing xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><dsp:spTree><dsp:nvGrpSpPr><dsp:cNvPr id="0" name=""/><dsp:cNvGrpSpPr/></dsp:nvGrpSpPr><dsp:grpSpPr/></dsp:spTree></dsp:drawing>`;var u=class extends e{constructor(e,n,r,i,a=0,o=0,s,c){super(`dgm:cxn`);let l={modelId:e,srcId:n,destId:r,srcOrd:a,destOrd:o};i&&(l.type=i),s&&(l.parTransId=s),c&&(l.sibTransId=c),this.root.push(t(l))}},d=class extends e{constructor(n,r){super(`dgm:dataModel`),this.root.push(t({"xmlns:a":`http://schemas.openxmlformats.org/drawingml/2006/main`,"xmlns:dgm":`http://schemas.openxmlformats.org/drawingml/2006/diagram`}));let i=new class extends e{constructor(){super(`dgm:ptLst`)}};for(let e of n)i.root.push(e);this.root.push(i);let a=new class extends e{constructor(){super(`dgm:cxnLst`)}};for(let e of r)a.root.push(e);this.root.push(a),this.root.push(new f(`dgm:bg`)),this.root.push(new f(`dgm:whole`))}},f=class extends e{constructor(e){super(e)}},p=class extends e{constructor(e,n,r=`node`){super(`dgm:pt`),this.root.push(t({modelId:e,type:r})),this.root.push(new g(n))}},m=class extends e{constructor(e,n,r){super(`dgm:pt`),this.root.push(t({modelId:e,type:n,cxnId:r})),this.root.push(new h(`dgm:spPr`))}},h=class extends e{constructor(e){super(e)}},g=class extends e{constructor(t){super(`dgm:t`),this.root.push(new h(`a:bodyPr`)),this.root.push(new h(`a:lstStyle`));let n=new h(`a:p`);if(t){let r=new class extends e{constructor(){super(`a:t`)}};r.root.push(t);let i=new class extends e{constructor(){super(`a:r`)}};i.root.push(r),n.root.push(i)}this.root.push(n)}},_=class{map;constructor(){this.map=new Map}addSmartArt(e,t){this.map.set(e,t)}get Array(){return[...this.map.values()]}};function v(a,o,s){let c=new class extends e{constructor(){super(`dgm:pt`)}};c.root.push(t({modelId:0,type:`doc`}));let l=new class extends e{constructor(){super(`dgm:prSet`)}};return l.root.push(t({loTypeId:`urn:microsoft.com/office/officeart/2005/8/layout/${a}`,loCatId:n[a]??`list`,qsTypeId:`urn:microsoft.com/office/officeart/2005/8/quickstyle/${o}`,qsCatId:r[o]??`simple`,csTypeId:`urn:microsoft.com/office/officeart/2005/8/colors/${s}`,csCatId:i[s]??`accent1`,phldr:`0`})),c.root.push(l),c.root.push(new b(`dgm:spPr`)),c.root.push(y()),c}function y(){let t=new class extends e{constructor(){super(`dgm:t`)}};return t.root.push(new b(`a:bodyPr`)),t.root.push(new b(`a:lstStyle`)),t.root.push(new b(`a:p`)),t}var b=class extends e{constructor(e){super(e)}};function x(){return`{${crypto.randomUUID().toUpperCase()}}`}const S=(e,t=`default`,n=`simple1`,r=`accent1_2`)=>{let i=[],a=[];i.push(v(t,n,r));for(let t=0;t<e.length;t++){let n=(e,t,r)=>{let o=x(),s=x(),c=x(),l=x();if(i.push(new m(s,`parTrans`,l)),i.push(new m(c,`sibTrans`,l)),i.push(new p(o,e.text)),a.push(new u(s,t,o,void 0,r,0,s,c)),e.children)for(let t=0;t<e.children.length;t++)n(e.children[t],o,t)};n(e[t],`0`,t)}return new d(i,a)};export{d as a,c,i as d,n as f,m as i,o as l,_ as n,u as o,r as p,p as r,l as s,S as t,s as u};
//#region src/values.d.ts
/**
* Runtime validation and type conversion functions for OOXML specification values.
*
* This module provides runtime checks and cleanup for value types in the OOXML spec
* that aren't easily expressed through the TypeScript type system alone. These
* validators help prevent silent failures and corrupted documents by enforcing
* spec-compliant values at runtime.
*
* @module
*/
/**
* A measurement value with optional sign and unit suffix.
*
* Supports units: mm (millimeters), cm (centimeters), in (inches),
* pt (points), pc (picas), pi (picas).
*
* Pattern: `-?[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)`
*
* @example
* ```typescript
* const measure: UniversalMeasure = "10.5mm";
* const negative: UniversalMeasure = "-5pt";
* ```
*/
type UniversalMeasure = `${"-" | ""}${number}${"mm" | "cm" | "in" | "pt" | "pc" | "pi"}`;
/**
* A positive measurement value with unit suffix.
*
* Same as UniversalMeasure but restricted to positive values only.
*
* Reference: ST_PositiveUniversalMeasure in OOXML specification
*
* @example
* ```typescript
* const measure: PositiveUniversalMeasure = "10.5mm";
* ```
*/
type PositiveUniversalMeasure = `${number}${"mm" | "cm" | "in" | "pt" | "pc" | "pi"}`;
/**
* A percentage value with optional sign.
*
* Pattern: `-?[0-9]+(\.[0-9]+)?%`
*
* Reference: ST_Percentage in OOXML specification
*
* @example
* ```typescript
* const percent: Percentage = "50%";
* const negative: Percentage = "-10.5%";
* ```
*/
type Percentage = `${"-" | ""}${number}%`;
/**
* A positive percentage value.
*
* Same as Percentage but restricted to positive values only.
*
* Reference: ST_PositivePercentage in OOXML specification
*
* @example
* ```typescript
* const percent: PositivePercentage = "50%";
* ```
*/
type PositivePercentage = `${number}%`;
/**
* A relative measurement value using em or ex units.
*
* Used in VML text boxes for font-relative measurements.
*
* @example
* ```typescript
* const measure: RelativeMeasure = "2em";
* const negative: RelativeMeasure = "-0.5ex";
* ```
*/
type RelativeMeasure = `${"-" | ""}${number}${"em" | "ex"}`;
/**
* Validates and converts a number to an integer (decimal number).
*
* Reference: ST_DecimalNumber in OOXML specification
*
* @param val - The number to validate and convert
* @returns The floored integer value
* @throws Error if the value is NaN
*
* @example
* ```typescript
* const num = decimalNumber(10.7); // Returns 10
* const negative = decimalNumber(-5.3); // Returns -5
* ```
*/
declare const decimalNumber: (val: number) => number;
/**
* Validates and converts a number to a positive integer (unsigned decimal number).
*
* Reference: ST_UnsignedDecimalNumber in OOXML specification
*
* @param val - The number to validate and convert
* @returns The floored positive integer value
* @throws Error if the value is NaN or negative
*
* @example
* ```typescript
* const num = unsignedDecimalNumber(10.7); // Returns 10
* const invalid = unsignedDecimalNumber(-5); // Throws Error
* ```
*/
declare const unsignedDecimalNumber: (val: number) => number;
/**
* Validates and normalizes a hexadecimal binary value.
*
* The xsd:hexBinary type represents binary data as a sequence of binary octets
* using hexadecimal encoding, where each binary octet is a two-character
* hexadecimal number. Both lowercase and uppercase letters A-F are permitted.
*
* @param val - The hexadecimal string to validate
* @param length - The expected length in bytes (not characters)
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid hex string of the expected length
*
* @example
* ```typescript
* hexBinary("0FB8", 2); // Valid: 2 bytes = 4 characters
* hexBinary("ABC", 2); // Invalid: wrong length
* ```
*/
declare const hexBinary: (val: string, length: number) => string;
/**
* Validates a long hexadecimal number (4 bytes / 8 characters).
*
* Reference: ST_LongHexNumber in OOXML specification
*
* @param val - The hexadecimal string to validate
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid 8-character hex string
*
* @example
* ```typescript
* const hex = longHexNumber("ABCD1234"); // Valid
* ```
*/
declare const longHexNumber: (val: string) => string;
/**
* Validates a short hexadecimal number (2 bytes / 4 characters).
*
* Reference: ST_ShortHexNumber in OOXML specification
*
* @param val - The hexadecimal string to validate
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid 4-character hex string
*
* @example
* ```typescript
* const hex = shortHexNumber("AB12"); // Valid
* ```
*/
declare const shortHexNumber: (val: string) => string;
/**
* Validates a single-byte hexadecimal number (1 byte / 2 characters).
*
* Reference: ST_UcharHexNumber in OOXML specification
*
* @param val - The hexadecimal string to validate
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid 2-character hex string
*
* @example
* ```typescript
* const hex = uCharHexNumber("FF"); // Valid
* ```
*/
declare const uCharHexNumber: (val: string) => string;
/**
* Normalizes a universal measure value by parsing and reformatting.
*
* Ensures the numeric portion is properly formatted while preserving the unit.
*
* Reference: ST_UniversalMeasure in OOXML specification
*
* @param val - The universal measure string to normalize
* @returns The normalized universal measure
*
* @example
* ```typescript
* const measure = universalMeasureValue("10.500mm"); // Returns "10.5mm"
* ```
*/
declare const universalMeasureValue: (val: UniversalMeasure) => UniversalMeasure;
/**
* Validates and normalizes a positive universal measure value.
*
* Reference: ST_PositiveUniversalMeasure in OOXML specification
*
* @param val - The positive universal measure string to validate
* @returns The normalized positive universal measure
* @throws Error if the value is negative
*
* @example
* ```typescript
* const measure = positiveUniversalMeasureValue("10.5mm"); // Valid
* const invalid = positiveUniversalMeasureValue("-5mm"); // Throws Error
* ```
*/
declare const positiveUniversalMeasureValue: (val: PositiveUniversalMeasure) => PositiveUniversalMeasure;
/**
* Validates and normalizes a hexadecimal color value.
*
* Accepts either "auto" or a 6-character RGB hex value (with or without # prefix).
* The # prefix is commonly used but technically invalid in OOXML, so it is stripped
* for strict compliance.
*
* Reference: ST_HexColor in OOXML specification
*
* @param val - The color value to validate ("auto" or hex color)
* @returns The normalized color value
* @throws Error if the hex color is invalid
*
* @example
* ```typescript
* const color1 = hexColorValue("auto"); // Returns "auto"
* const color2 = hexColorValue("FF0000"); // Returns "FF0000"
* const color3 = hexColorValue("#00FF00"); // Returns "00FF00" (# stripped)
* ```
*/
declare const hexColorValue: (val: string) => string;
/**
* Validates a signed TWIP measurement value.
*
* Accepts either a universal measure string or a numeric TWIP value.
*
* Reference: ST_SignedTwipsMeasure in OOXML specification
*
* @param val - The measurement value (universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const measure1 = signedTwipsMeasureValue("10mm");
* const measure2 = signedTwipsMeasureValue(1440); // 1 inch in TWIP
* ```
*/
declare const signedTwipsMeasureValue: (val: UniversalMeasure | number) => UniversalMeasure | number;
/**
* Validates a half-point (HPS) measurement value.
*
* Accepts either a positive universal measure string or a positive number.
* HPS (half-points) are commonly used for font sizes.
*
* Reference: ST_HpsMeasure in OOXML specification
*
* @param val - The measurement value (positive universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const fontSize1 = hpsMeasureValue("12pt");
* const fontSize2 = hpsMeasureValue(24); // 12pt in half-points
* ```
*/
declare const hpsMeasureValue: (val: PositiveUniversalMeasure | number) => string | number;
/**
* Validates a signed half-point (HPS) measurement value.
*
* Accepts either a universal measure string or a numeric value.
*
* Reference: ST_SignedHpsMeasure in OOXML specification
*
* @param val - The measurement value (universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const spacing1 = signedHpsMeasureValue("6pt");
* const spacing2 = signedHpsMeasureValue(-12); // Negative spacing
* ```
*/
declare const signedHpsMeasureValue: (val: UniversalMeasure | number) => string | number;
/**
* Validates a positive TWIP measurement value.
*
* Accepts either a positive universal measure string or a positive number.
*
* Reference: ST_TwipsMeasure in OOXML specification
*
* @param val - The measurement value (positive universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const width1 = twipsMeasureValue("25.4mm");
* const width2 = twipsMeasureValue(1440); // 1 inch in TWIP
* ```
*/
declare const twipsMeasureValue: (val: PositiveUniversalMeasure | number) => PositiveUniversalMeasure | number;
/**
* Normalizes a percentage value by parsing and reformatting.
*
* Reference: ST_Percentage in OOXML specification
*
* @param val - The percentage string to normalize
* @returns The normalized percentage
*
* @example
* ```typescript
* const percent = percentageValue("50.000%"); // Returns "50%"
* ```
*/
declare const percentageValue: (val: Percentage) => Percentage;
/**
* Validates a measurement value that can be expressed as a number, percentage, or universal measure.
*
* Reference: ST_MeasurementOrPercent in OOXML specification
*
* @param val - The measurement value (number, percentage, or universal measure)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const measure1 = measurementOrPercentValue(100); // Unqualified number
* const measure2 = measurementOrPercentValue("50%"); // Percentage
* const measure3 = measurementOrPercentValue("10mm"); // Universal measure
* ```
*/
declare const measurementOrPercentValue: (val: number | Percentage | UniversalMeasure) => number | UniversalMeasure | Percentage;
/**
* Validates an eighth-point measurement value.
*
* Eighth-points are used for fine-grained measurements in text formatting.
*
* Reference: ST_EighthPointMeasure in OOXML specification
*
* @param val - The measurement value in eighth-points
* @returns The validated positive integer value
*
* @example
* ```typescript
* const measure = eighthPointMeasureValue(16); // 2 points
* ```
*/
declare const eighthPointMeasureValue: (val: number) => number;
/**
* Validates a point measurement value.
*
* Reference: ST_PointMeasure in OOXML specification
*
* @param val - The measurement value in points
* @returns The validated positive integer value
*
* @example
* ```typescript
* const fontSize = pointMeasureValue(12); // 12pt
* ```
*/
declare const pointMeasureValue: (val: number) => number;
/**
* Converts a JavaScript Date object to an ISO 8601 date-time string.
*
* The format is CCYY-MM-DDThh:mm:ss.sssZ where T is a literal and Z indicates UTC.
* This matches the xsd:dateTime format required by OOXML.
*
* Reference: ST_DateTime in OOXML specification
*
* @param val - The Date object to convert
* @returns An ISO 8601 formatted date-time string
*
* @example
* ```typescript
* const now = new Date();
* const timestamp = dateTimeValue(now); // Returns "2024-01-15T10:30:00.000Z"
* ```
*/
declare const dateTimeValue: (val: Date) => string;
/**
* Theme color values used throughout OOXML for referencing document theme colors.
*
* Reference: ST_ThemeColor in OOXML specification
*
* @publicApi
*/
declare const ThemeColor: {
readonly DARK1: "dark1";
readonly LIGHT1: "light1";
readonly DARK2: "dark2";
readonly LIGHT2: "light2";
readonly ACCENT1: "accent1";
readonly ACCENT2: "accent2";
readonly ACCENT3: "accent3";
readonly ACCENT4: "accent4";
readonly ACCENT5: "accent5";
readonly ACCENT6: "accent6";
readonly HYPERLINK: "hyperlink";
readonly FOLLOWED_HYPERLINK: "followedHyperlink";
readonly NONE: "none";
readonly BACKGROUND1: "background1";
readonly TEXT1: "text1";
readonly BACKGROUND2: "background2";
readonly TEXT2: "text2";
};
/**
* Theme font values used for referencing document theme fonts.
*
* Reference: ST_Theme in OOXML specification
*
* @publicApi
*/
declare const ThemeFont: {
readonly MAJOR_EAST_ASIA: "majorEastAsia";
readonly MAJOR_BIDI: "majorBidi";
readonly MAJOR_ASCII: "majorAscii";
readonly MAJOR_H_ANSI: "majorHAnsi";
readonly MINOR_EAST_ASIA: "minorEastAsia";
readonly MINOR_BIDI: "minorBidi";
readonly MINOR_ASCII: "minorAscii";
readonly MINOR_H_ANSI: "minorHAnsi";
};
//#endregion
export { uCharHexNumber as C, twipsMeasureValue as S, unsignedDecimalNumber as T, pointMeasureValue as _, ThemeColor as a, signedHpsMeasureValue as b, dateTimeValue as c, hexBinary as d, hexColorValue as f, percentageValue as g, measurementOrPercentValue as h, RelativeMeasure as i, decimalNumber as l, longHexNumber as m, PositivePercentage as n, ThemeFont as o, hpsMeasureValue as p, PositiveUniversalMeasure as r, UniversalMeasure as s, Percentage as t, eighthPointMeasureValue as u, positiveUniversalMeasureValue as v, universalMeasureValue as w, signedTwipsMeasureValue as x, shortHexNumber as y };
import{hpsMeasureValue as e}from"./values.mjs";import{xml as t,xml2js as n}from"@office-open/xml";var r=class{rootKey;constructor(e){this.rootKey=e}};const i=Object.seal({});var a=class extends r{root;constructor(e){super(e),this.root=[]}prepForXml(e){e.stack.push(this);let t=[];for(let n of this.root)if(n instanceof r){let r=n.prepForXml(e);r!==void 0&&t.push(r)}else t.push(n);return e.stack.pop(),{[this.rootKey]:t.length?t.length===1&&t[0]&&typeof t[0]==`object`&&`_attr`in t[0]?t[0]:t:i}}toXml(e){let n=this.prepForXml(e);return n?t(n):``}addChildElement(e){return this.root.push(e),this}},o=class extends a{includeIfEmpty;constructor(e,t){super(e),this.includeIfEmpty=t}prepForXml(e){let t=super.prepForXml(e);if(this.includeIfEmpty||t&&(typeof t[this.rootKey]!=`object`||Object.keys(t[this.rootKey]).length))return t}},s=class extends r{xmlKeys;constructor(e){super(`_attr`),this.root=e}prepForXml(e){let t={};return Object.entries(this.root).forEach(([e,n])=>{if(n!==void 0){let r=this.xmlKeys&&this.xmlKeys[e]||e;t[r]=n}}),{_attr:t}}},c=class extends r{constructor(e){super(`_attr`),this.root=e}prepForXml(e){return{_attr:Object.values(this.root).filter(({value:e})=>e!==void 0).reduce((e,{key:t,value:n})=>({...e,[t]:n}),{})}}};const l=new Map;function u(e,t=!0){if(t===!0){let t=l.get(e);return t||(t=Object.freeze({[e]:Object.freeze({})}),l.set(e,t)),t}let n=e.split(`:`)[0];return{[e]:{_attr:{[`${n}:val`]:t}}}}function d(t,n){let r=t.split(`:`)[0];return{[t]:{_attr:{[`${r}:val`]:e(n)}}}}function f(e,t){let n=e.split(`:`)[0];return{[e]:{_attr:{[`${n}:val`]:t}}}}function p(e,t){let n=e.split(`:`)[0];return{[e]:{_attr:{[`${n}:val`]:t}}}}function m(e,t){let n=e.split(`:`)[0];return{[e]:{_attr:{[`${n}:val`]:t}}}}function h(e,t){return{[e]:[t]}}var g=class extends a{constructor(e,t=!0){super(e),t!==!0&&this.root.push(new c({val:{key:`${e.split(`:`)[0]}:val`,value:t}}))}},_=class extends a{constructor(t,n){super(t);let r=t.split(`:`)[0];this.root.push(new c({val:{key:`${r}:val`,value:e(n)}}))}},v=class extends a{},y=class extends a{constructor(e,t){super(e);let n=e.split(`:`)[0];this.root.push(new c({val:{key:`${n}:val`,value:t}}))}},b=class extends a{constructor(e,t){super(e);let n=e.split(`:`)[0];this.root.push(new c({val:{key:`${n}:val`,value:t}}))}},x=class extends a{constructor(e,t){super(e);let n=e.split(`:`)[0];this.root.push(new c({val:{key:`${n}:val`,value:t}}))}},S=class extends a{constructor(e,t){super(e),this.root.push(t)}},C=class extends a{constructor({name:e,attributes:t,children:n}){super(e),t&&this.root.push(new c(t)),n&&this.root.push(...n)}};const w=e=>new c(Object.fromEntries(Object.entries(e).map(([e,t])=>[e,{key:e,value:t}])));function T(e,t){let n=new class extends a{constructor(e){super(e)}}(e);return n.root.push(t),n}const E=e=>{switch(e.type){case void 0:case`element`:{let t=new O(e.name,e.attributes),n=e.elements||[];for(let e of n){let n=E(e);n!==void 0&&t.push(n)}return t}case`text`:return e.text;default:return}};var D=class extends s{},O=class extends a{_sourceXml;static fromXmlString(e){let t=n(e,{compact:!1}),r=E(t.elements?.[0]??t);return r._sourceXml=e,r}get sourceXml(){return this._sourceXml}toXml(e){return this._sourceXml??super.toXml(e)}constructor(e,t){super(e),t&&this.root.push(new D(t))}push(e){this.root.push(e)}},k=class extends a{constructor(e){super(``),this._attr=e}prepForXml(e){return{_attr:this._attr}}},A=class extends a{constructor(e,t){super(e),t instanceof a&&(this.root=t.root)}};export{i as C,r as E,s as S,a as T,h as _,C as a,T as b,b as c,x as d,y as f,u as g,p as h,E as i,g as l,d as m,k as n,v as o,w as p,O as r,_ as s,A as t,S as u,m as v,o as w,c as x,f as y};
+1
-135

@@ -1,135 +0,1 @@

import { attr, js2xml, xml2js } from "@office-open/xml";
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
//#region src/archive.ts
const XML_PARSE_OPTIONS = {
nativeTypeAttributes: true,
captureSpacesBetweenElements: true
};
/**
* Unzip an OOXML file (.docx, .pptx) into a Map of path → Uint8Array.
*/
function unzipToMap(data) {
const entries = unzipSync(data);
const map = /* @__PURE__ */ new Map();
for (const [path, bytes] of Object.entries(entries)) map.set(path, bytes);
return map;
}
/**
* Read a file from the zip as a UTF-8 string.
*/
function readTextFromZip(zip, path) {
const data = zip.get(path);
if (data === void 0) return void 0;
return strFromU8(data);
}
/**
* Parse an XML file from the zip into an Element tree.
*/
function readXmlFromZip(zip, path) {
const text = readTextFromZip(zip, path);
if (text === void 0) return void 0;
return xml2js(text, XML_PARSE_OPTIONS).elements?.find((e) => e.type === "element");
}
/**
* Read a binary file from the zip.
*/
function readBinaryFromZip(zip, path) {
return zip.get(path);
}
/**
* Parse all XML files in the zip into Element trees.
* Skips media files, binary files, and the main document/presentation file.
*/
function readAllXmlParts(zip, options) {
const parts = {};
const skip = new Set(options?.skipPaths ?? []);
for (const path of zip.keys()) {
if (skip.has(path)) continue;
if (path.startsWith("word/media/") || path.startsWith("ppt/media/") || path.startsWith("xl/media/") || path.endsWith(".png") || path.endsWith(".jpg") || path.endsWith(".jpeg") || path.endsWith(".gif") || path.endsWith(".bmp") || path.endsWith(".tif") || path.endsWith(".tiff") || path.endsWith(".emf") || path.endsWith(".wmf") || path.endsWith(".svg") || path.endsWith(".wav") || path.endsWith(".mp3") || path.endsWith(".mp4") || path.endsWith(".avi") || path.endsWith(".wmv") || path.endsWith(".thmx") || path.endsWith(".bin")) continue;
const el = readXmlFromZip(zip, path);
if (el) parts[path] = el;
}
return parts;
}
/**
* List all files in the zip matching a prefix.
*/
function listFiles(zip, prefix) {
const result = [];
for (const path of zip.keys()) if (path.startsWith(prefix)) result.push(path);
return result;
}
/**
* Convert Uint8Array to base64 string.
*/
function uint8ToBase64(data) {
const chunkSize = 8192;
let binary = "";
for (let i = 0; i < data.length; i += chunkSize) {
const chunk = data.subarray(i, Math.min(i + chunkSize, data.length));
binary += String.fromCharCode(...chunk);
}
return btoa(binary);
}
/**
* Determine image type from file extension.
*/
function getImageType(fileName) {
const ext = fileName.split(".").pop()?.toLowerCase() ?? "";
if ([
"png",
"jpg",
"jpeg",
"gif",
"bmp",
"tif",
"tiff",
"ico",
"emf",
"wmf",
"svg"
].includes(ext)) return ext === "jpeg" ? "jpg" : ext;
return "png";
}
function parseRels(zip, path) {
const xml = readXmlFromZip(zip, path);
if (!xml) return [];
const result = [];
for (const rel of xml.elements ?? []) {
if (rel.name !== "Relationship") continue;
const id = attr(rel, "Id");
const target = attr(rel, "Target");
const type = attr(rel, "Type");
const targetMode = attr(rel, "TargetMode");
if (id && target) result.push({
id,
target,
type: type ?? "",
...targetMode ? { targetMode } : {}
});
}
return result;
}
function findRel(rels, id) {
return rels.find((r) => r.id === id);
}
function findRelsByType(rels, typeSubstring) {
return rels.filter((r) => r.type.includes(typeSubstring));
}
/**
* Zip a map of path → Uint8Array/string into a ZIP buffer.
* XML strings are auto-encoded to UTF-8 bytes.
*/
function zipToBuffer(files) {
const entries = {};
for (const [path, data] of files) entries[path] = typeof data === "string" ? strToU8(data) : data;
return zipSync(entries);
}
/**
* Serialize an Element tree to an XML string.
*/
function elementToXml(el) {
return js2xml(el);
}
//#endregion
export { elementToXml, findRel, findRelsByType, getImageType, listFiles, parseRels, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, uint8ToBase64, unzipToMap, zipToBuffer };
import{attr as e,js2xml as t,xml2js as n}from"@office-open/xml";import{strFromU8 as r,strToU8 as i,unzipSync as a,zipSync as o}from"fflate";const s={nativeTypeAttributes:!0,captureSpacesBetweenElements:!0};function c(e){let t=a(e),n=new Map;for(let[e,r]of Object.entries(t))n.set(e,r);return n}function l(e,t){let n=e.get(t);if(n!==void 0)return r(n)}function u(e,t){let r=l(e,t);if(r!==void 0)return n(r,s).elements?.find(e=>e.type===`element`)}function d(e,t){return e.get(t)}function f(e,t){let n={},r=new Set(t?.skipPaths??[]);for(let t of e.keys()){if(r.has(t)||t.startsWith(`word/media/`)||t.startsWith(`ppt/media/`)||t.startsWith(`xl/media/`)||t.endsWith(`.png`)||t.endsWith(`.jpg`)||t.endsWith(`.jpeg`)||t.endsWith(`.gif`)||t.endsWith(`.bmp`)||t.endsWith(`.tif`)||t.endsWith(`.tiff`)||t.endsWith(`.emf`)||t.endsWith(`.wmf`)||t.endsWith(`.svg`)||t.endsWith(`.wav`)||t.endsWith(`.mp3`)||t.endsWith(`.mp4`)||t.endsWith(`.avi`)||t.endsWith(`.wmv`)||t.endsWith(`.thmx`)||t.endsWith(`.bin`))continue;let i=u(e,t);i&&(n[t]=i)}return n}function p(e,t){let n=[];for(let r of e.keys())r.startsWith(t)&&n.push(r);return n}function m(e){let t=8192,n=``;for(let r=0;r<e.length;r+=t){let i=e.subarray(r,Math.min(r+t,e.length));n+=String.fromCharCode(...i)}return btoa(n)}function h(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return[`png`,`jpg`,`jpeg`,`gif`,`bmp`,`tif`,`tiff`,`ico`,`emf`,`wmf`,`svg`].includes(t)?t===`jpeg`?`jpg`:t:`png`}function g(t,n){let r=u(t,n);if(!r)return[];let i=[];for(let t of r.elements??[]){if(t.name!==`Relationship`)continue;let n=e(t,`Id`),r=e(t,`Target`),a=e(t,`Type`),o=e(t,`TargetMode`);n&&r&&i.push({id:n,target:r,type:a??``,...o?{targetMode:o}:{}})}return i}function _(e,t){return e.find(e=>e.id===t)}function v(e,t){return e.filter(e=>e.type.includes(t))}function y(e){let t={};for(let[n,r]of e)t[n]=typeof r==`string`?i(r):r;return o(t)}function b(e){return t(e)}export{b as elementToXml,_ as findRel,v as findRelsByType,h as getImageType,p as listFiles,g as parseRels,f as readAllXmlParts,d as readBinaryFromZip,l as readTextFromZip,u as readXmlFromZip,m as uint8ToBase64,c as unzipToMap,y as zipToBuffer};

@@ -1,2 +0,2 @@

import { O as XmlComponent } from "../_chunks/index-hmJg8TDw.mjs";
import { O as XmlComponent } from "../index-DqdJoWmh.mjs";

@@ -74,3 +74,3 @@ //#region src/chart/axes.d.ts

}
declare const createChartType: (options: IChartTypeOptions) => AreaChart | ScatterChart | BarChart | LineChart | PieChart;
declare const createChartType: (options: IChartTypeOptions) => BarChart | LineChart | PieChart | AreaChart | ScatterChart;
//#endregion

@@ -77,0 +77,0 @@ //#region src/chart/chart-space.d.ts

@@ -1,611 +0,1 @@

import { T as XmlComponent, a as BuilderElement, b as wrapEl, o as EmptyElement, p as chartAttr } from "../_chunks/xml-components-CN6syVNr.mjs";
//#region src/chart/axes.ts
/**
* c:scaling — axis scaling configuration (minOccurs=1 in EG_AxShared).
*/
var Scaling = class extends XmlComponent {
constructor() {
super("c:scaling");
this.root.push(wrapEl("c:orientation", chartAttr({ val: "minMax" })));
}
};
/**
* c:catAx — category axis.
*/
var CatAx = class extends XmlComponent {
constructor(axId, crossAx) {
super("c:catAx");
this.root.push(wrapEl("c:axId", chartAttr({ val: axId })));
this.root.push(new Scaling());
this.root.push(wrapEl("c:delete", chartAttr({ val: 0 })));
this.root.push(wrapEl("c:axPos", chartAttr({ val: "b" })));
this.root.push(wrapEl("c:auto", chartAttr({ val: 1 })));
this.root.push(wrapEl("c:lblOffset", chartAttr({ val: 100 })));
this.root.push(wrapEl("c:noMultiLvlLbl", chartAttr({ val: 0 })));
this.root.push(wrapEl("c:crossAx", chartAttr({ val: crossAx })));
this.root.push(wrapEl("c:crosses", chartAttr({ val: "autoZero" })));
}
};
/**
* c:valAx — value axis.
*/
var ValAx = class extends XmlComponent {
constructor(axId, crossAx) {
super("c:valAx");
this.root.push(wrapEl("c:axId", chartAttr({ val: axId })));
this.root.push(new Scaling());
this.root.push(wrapEl("c:delete", chartAttr({ val: 0 })));
this.root.push(wrapEl("c:axPos", chartAttr({ val: "l" })));
this.root.push(wrapEl("c:numFmt", chartAttr({
formatCode: "General",
sourceLinked: 1
})));
this.root.push(wrapEl("c:crossAx", chartAttr({ val: crossAx })));
this.root.push(wrapEl("c:crosses", chartAttr({ val: "autoZero" })));
this.root.push(new BuilderElement({ name: "c:spPr" }));
}
};
//#endregion
//#region src/chart/series/series-data.ts
const createStrRef = (values) => {
return new StrRef(typeof values === "string" ? [values] : values);
};
const createNumRef = (values) => new NumRef(values);
var StrRef = class extends XmlComponent {
constructor(values) {
super("c:strRef");
this.root.push(new EmptyElement("c:f"));
this.root.push(new StrCache(values));
}
};
var StrCache = class extends XmlComponent {
constructor(values) {
super("c:strCache");
this.root.push(wrapEl("c:ptCount", chartAttr({ val: values.length })));
for (let i = 0; i < values.length; i++) this.root.push(new StrPt(i, values[i]));
}
};
var StrPt = class extends XmlComponent {
constructor(index, value) {
super("c:pt");
this.root.push(chartAttr({ idx: index }));
this.root.push(new StringValue("c:v", value));
}
};
var NumRef = class extends XmlComponent {
constructor(values) {
super("c:numRef");
this.root.push(new EmptyElement("c:f"));
this.root.push(new NumCache(values));
}
};
var NumCache = class extends XmlComponent {
constructor(values) {
super("c:numCache");
this.root.push(wrapEl("c:ptCount", chartAttr({ val: values.length })));
this.root.push(new FormatCode("General"));
for (let i = 0; i < values.length; i++) this.root.push(new NumPt(i, values[i]));
}
};
var NumPt = class extends XmlComponent {
constructor(index, value) {
super("c:pt");
this.root.push(chartAttr({ idx: index }));
this.root.push(new StringValue("c:v", String(value)));
}
};
var FormatCode = class extends XmlComponent {
constructor(code) {
super("c:formatCode");
this.root.push(code);
}
};
var StringValue = class extends XmlComponent {
constructor(name, val) {
super(name);
this.root.push(val);
}
};
//#endregion
//#region src/chart/chart-types/area-chart.ts
var AreaChart = class extends XmlComponent {
constructor(options) {
super("c:areaChart");
this.root.push(wrapEl("c:grouping", chartAttr({ val: "standard" })));
for (let i = 0; i < options.series.length; i++) this.root.push(new AreaSeries(i, options.series[i], options.categories));
this.root.push(wrapEl("c:axId", chartAttr({ val: 10 })));
this.root.push(wrapEl("c:axId", chartAttr({ val: 20 })));
}
};
var AreaSeries = class extends XmlComponent {
constructor(index, series, categories) {
super("c:ser");
this.root.push(wrapEl("c:idx", chartAttr({ val: index })));
this.root.push(wrapEl("c:order", chartAttr({ val: index })));
this.root.push(new SeriesTx$4(series.name));
this.root.push(new SeriesCat$4(categories));
this.root.push(new SeriesVal$4(series.values));
this.root.push(new EmptyElement("c:spPr"));
}
};
var SeriesTx$4 = class extends XmlComponent {
constructor(name) {
super("c:tx");
this.root.push(createStrRef(name));
}
};
var SeriesCat$4 = class extends XmlComponent {
constructor(categories) {
super("c:cat");
this.root.push(createStrRef(categories));
}
};
var SeriesVal$4 = class extends XmlComponent {
constructor(values) {
super("c:val");
this.root.push(createNumRef(values));
}
};
//#endregion
//#region src/chart/chart-types/bar-chart.ts
var BarChart = class extends XmlComponent {
constructor(options) {
super("c:barChart");
this.root.push(wrapEl("c:barDir", chartAttr({ val: options.barDirection })));
this.root.push(wrapEl("c:grouping", chartAttr({ val: "clustered" })));
for (let i = 0; i < options.series.length; i++) this.root.push(new BarSeries(i, options.series[i], options.categories));
this.root.push(wrapEl("c:axId", chartAttr({ val: 10 })));
this.root.push(wrapEl("c:axId", chartAttr({ val: 20 })));
}
};
var BarSeries = class extends XmlComponent {
constructor(index, series, categories) {
super("c:ser");
this.root.push(wrapEl("c:idx", chartAttr({ val: index })));
this.root.push(wrapEl("c:order", chartAttr({ val: index })));
this.root.push(new SeriesTx$3(series.name));
this.root.push(new SeriesCat$3(categories));
this.root.push(new SeriesVal$3(series.values));
this.root.push(new EmptyElement("c:spPr"));
}
};
var SeriesTx$3 = class extends XmlComponent {
constructor(name) {
super("c:tx");
this.root.push(createStrRef(name));
}
};
var SeriesCat$3 = class extends XmlComponent {
constructor(categories) {
super("c:cat");
this.root.push(createStrRef(categories));
}
};
var SeriesVal$3 = class extends XmlComponent {
constructor(values) {
super("c:val");
this.root.push(createNumRef(values));
}
};
//#endregion
//#region src/chart/chart-types/line-chart.ts
var LineChart = class extends XmlComponent {
constructor(options) {
super("c:lineChart");
this.root.push(wrapEl("c:grouping", chartAttr({ val: "standard" })));
for (let i = 0; i < options.series.length; i++) this.root.push(new LineSeries(i, options.series[i], options.categories));
this.root.push(wrapEl("c:axId", chartAttr({ val: 10 })));
this.root.push(wrapEl("c:axId", chartAttr({ val: 20 })));
}
};
var LineSeries = class extends XmlComponent {
constructor(index, series, categories) {
super("c:ser");
this.root.push(wrapEl("c:idx", chartAttr({ val: index })));
this.root.push(wrapEl("c:order", chartAttr({ val: index })));
this.root.push(new SeriesTx$2(series.name));
this.root.push(new SeriesCat$2(categories));
this.root.push(new SeriesVal$2(series.values));
this.root.push(new EmptyElement("c:spPr"));
}
};
var SeriesTx$2 = class extends XmlComponent {
constructor(name) {
super("c:tx");
this.root.push(createStrRef(name));
}
};
var SeriesCat$2 = class extends XmlComponent {
constructor(categories) {
super("c:cat");
this.root.push(createStrRef(categories));
}
};
var SeriesVal$2 = class extends XmlComponent {
constructor(values) {
super("c:val");
this.root.push(createNumRef(values));
}
};
//#endregion
//#region src/chart/chart-types/pie-chart.ts
var PieChart = class extends XmlComponent {
constructor(options) {
super("c:pieChart");
this.root.push(wrapEl("c:varyColors", chartAttr({ val: true })));
for (let i = 0; i < options.series.length; i++) this.root.push(new PieSeries(i, options.series[i], options.categories));
}
};
var PieSeries = class extends XmlComponent {
constructor(index, series, categories) {
super("c:ser");
this.root.push(wrapEl("c:idx", chartAttr({ val: index })));
this.root.push(wrapEl("c:order", chartAttr({ val: index })));
this.root.push(new SeriesTx$1(series.name));
this.root.push(new SeriesCat$1(categories));
this.root.push(new SeriesVal$1(series.values));
this.root.push(new EmptyElement("c:spPr"));
}
};
var SeriesTx$1 = class extends XmlComponent {
constructor(name) {
super("c:tx");
this.root.push(createStrRef(name));
}
};
var SeriesCat$1 = class extends XmlComponent {
constructor(categories) {
super("c:cat");
this.root.push(createStrRef(categories));
}
};
var SeriesVal$1 = class extends XmlComponent {
constructor(values) {
super("c:val");
this.root.push(createNumRef(values));
}
};
//#endregion
//#region src/chart/chart-types/scatter-chart.ts
var ScatterChart = class extends XmlComponent {
constructor(options) {
super("c:scatterChart");
this.root.push(wrapEl("c:scatterStyle", chartAttr({ val: "line" })));
for (let i = 0; i < options.series.length; i++) this.root.push(new ScatterSeries(i, options.series[i], options.categories));
this.root.push(wrapEl("c:axId", chartAttr({ val: 10 })));
this.root.push(wrapEl("c:axId", chartAttr({ val: 20 })));
}
};
var ScatterSeries = class extends XmlComponent {
constructor(index, series, categories) {
super("c:ser");
this.root.push(wrapEl("c:idx", chartAttr({ val: index })));
this.root.push(wrapEl("c:order", chartAttr({ val: index })));
this.root.push(new SeriesTx(series.name));
this.root.push(new SeriesCat(categories));
this.root.push(new SeriesVal(series.values));
this.root.push(new EmptyElement("c:spPr"));
this.root.push(new EmptyElement("c:size"));
}
};
var SeriesTx = class extends XmlComponent {
constructor(name) {
super("c:tx");
this.root.push(createStrRef(name));
}
};
var SeriesCat = class extends XmlComponent {
constructor(categories) {
super("c:cat");
this.root.push(createStrRef(categories));
}
};
var SeriesVal = class extends XmlComponent {
constructor(values) {
super("c:val");
this.root.push(createNumRef(values));
}
};
//#endregion
//#region src/chart/create-chart-type.ts
const createChartType = (options) => {
switch (options.type) {
case "column":
case "bar": return new BarChart({
barDirection: options.type === "column" ? "col" : "bar",
categories: options.categories,
series: options.series
});
case "line": return new LineChart({
categories: options.categories,
series: options.series
});
case "pie": return new PieChart({
categories: options.categories,
series: options.series
});
case "area": return new AreaChart({
categories: options.categories,
series: options.series
});
case "scatter": return new ScatterChart({
categories: options.categories,
series: options.series
});
default: throw new Error(`Unsupported chart type: ${options.type}`);
}
};
//#endregion
//#region src/chart/title.ts
var ChartTitle = class extends XmlComponent {
constructor(title) {
super("c:title");
this.root.push(new TitleTx(title));
this.root.push(new TitleOverlay());
}
};
var TitleTx = class extends XmlComponent {
constructor(title) {
super("c:tx");
const rich = new class extends XmlComponent {
constructor() {
super("c:rich");
}
}();
rich["root"].push(new class extends XmlComponent {
constructor() {
super("a:bodyPr");
}
}());
rich["root"].push(new class extends XmlComponent {
constructor() {
super("a:lstStyle");
}
}());
const p = new class extends XmlComponent {
constructor() {
super("a:p");
}
}();
const r = new class extends XmlComponent {
constructor() {
super("a:r");
}
}();
r["root"].push(new class extends XmlComponent {
constructor() {
super("a:t");
this.root.push(title);
}
}());
p["root"].push(r);
rich["root"].push(p);
this.root.push(rich);
}
};
var TitleOverlay = class extends XmlComponent {
constructor() {
super("c:overlay");
this.root.push(chartAttr({ val: 0 }));
}
};
//#endregion
//#region src/chart/chart-space.ts
/**
* ChartSpace — root element for chart XML parts (c:chartSpace).
*
* Full XSD-compliant implementation with all optional elements.
*
* @module
*/
/**
* c:chartSpace — root element for chart XML parts.
*/
var ChartSpace = class extends XmlComponent {
constructor(options) {
super("c:chartSpace");
this.root.push(chartAttr({
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
"xmlns:c": "http://schemas.openxmlformats.org/drawingml/2006/chart",
"xmlns:r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
}));
this.root.push(wrapEl("c:date1904", chartAttr({ val: 0 })));
this.root.push(wrapEl("c:lang", chartAttr({ val: "en-US" })));
this.root.push(wrapEl("c:roundedCorners", chartAttr({ val: 0 })));
const chart = new ChartContainer();
if (options.title) chart["root"].push(new ChartTitle(options.title));
chart["root"].push(wrapEl("c:autoTitleDeleted", chartAttr({ val: 0 })));
const plotArea = new PlotArea();
plotArea["root"].push(new BuilderElement({ name: "c:layout" }));
plotArea["root"].push(createChartType({
categories: options.categories,
series: options.series,
type: options.type
}));
if (options.type !== "pie") if (options.type === "scatter") {
plotArea["root"].push(new ValAx(10, 20));
plotArea["root"].push(new ValAx(20, 10));
} else {
plotArea["root"].push(new CatAx(10, 20));
plotArea["root"].push(new ValAx(20, 10));
}
chart["root"].push(plotArea);
if (options.showLegend !== false) chart["root"].push(createLegend());
this.root.push(chart);
this.root.push(createChartSpPr());
this.root.push(createChartTxPr());
if (options.style !== void 0) this.root.push(new ChartStyle(options.style));
}
};
var ChartContainer = class extends XmlComponent {
constructor() {
super("c:chart");
}
};
var PlotArea = class extends XmlComponent {
constructor() {
super("c:plotArea");
}
};
function createLegend() {
const legend = new class extends XmlComponent {
constructor() {
super("c:legend");
}
}();
legend["root"].push(wrapEl("c:legendPos", chartAttr({ val: "b" })));
legend["root"].push(new BuilderElement({ name: "c:layout" }));
legend["root"].push(wrapEl("c:overlay", chartAttr({ val: 0 })));
legend["root"].push(createNoFillSpPr());
legend["root"].push(createTxPr());
return legend;
}
function createNoFillSpPr() {
const spPr = new class extends XmlComponent {
constructor() {
super("c:spPr");
}
}();
spPr["root"].push(new class extends XmlComponent {
constructor() {
super("a:noFill");
}
}());
spPr["root"].push(new class extends XmlComponent {
constructor() {
super("a:ln");
this.root.push(new class extends XmlComponent {
constructor() {
super("a:noFill");
}
}());
}
}());
spPr["root"].push(new BuilderElement({ name: "a:effectLst" }));
return spPr;
}
function createChartSpPr() {
const spPr = new class extends XmlComponent {
constructor() {
super("c:spPr");
}
}();
spPr["root"].push(new class extends XmlComponent {
constructor() {
super("a:noFill");
}
}());
spPr["root"].push(new class extends XmlComponent {
constructor() {
super("a:ln");
this.root.push(new class extends XmlComponent {
constructor() {
super("a:noFill");
}
}());
}
}());
spPr["root"].push(new BuilderElement({ name: "a:effectLst" }));
return spPr;
}
function createChartTxPr() {
const txPr = new class extends XmlComponent {
constructor() {
super("c:txPr");
}
}();
txPr["root"].push(new BuilderElement({ name: "a:bodyPr" }));
txPr["root"].push(new BuilderElement({ name: "a:lstStyle" }));
txPr["root"].push(createTextParagraph());
return txPr;
}
function createTxPr() {
const txPr = new class extends XmlComponent {
constructor() {
super("c:txPr");
}
}();
txPr["root"].push(createBodyPr());
txPr["root"].push(new BuilderElement({ name: "a:lstStyle" }));
txPr["root"].push(createTextParagraph());
return txPr;
}
function createBodyPr() {
return new BuilderElement({
name: "a:bodyPr",
attributes: {
rot: {
key: "rot",
value: "0"
},
spcFirstLastPara: {
key: "spcFirstLastPara",
value: "1"
},
vertOverflow: {
key: "vertOverflow",
value: "ellipsis"
},
vert: {
key: "vert",
value: "horz"
},
wrap: {
key: "wrap",
value: "square"
},
anchor: {
key: "anchor",
value: "ctr"
},
anchorCtr: {
key: "anchorCtr",
value: "1"
}
}
});
}
function createTextParagraph() {
const p = new class extends XmlComponent {
constructor() {
super("a:p");
}
}();
const pPr = new class extends XmlComponent {
constructor() {
super("a:pPr");
}
}();
pPr["root"].push(new BuilderElement({ name: "a:defRPr" }));
p["root"].push(pPr);
p["root"].push(new BuilderElement({
name: "a:endParaRPr",
attributes: { lang: {
key: "lang",
value: "en-US"
} }
}));
return p;
}
var ChartStyle = class extends XmlComponent {
constructor(val) {
super("c:style");
this.root.push(chartAttr({ val: String(val) }));
}
};
//#endregion
//#region src/chart/chart-collection.ts
var ChartCollection = class {
map;
constructor() {
this.map = /* @__PURE__ */ new Map();
}
addChart(key, chartData) {
this.map.set(key, chartData);
}
get Array() {
return [...this.map.values()];
}
};
//#endregion
export { AreaChart, BarChart, CatAx, ChartCollection, ChartSpace, ChartTitle, LineChart, PieChart, ScatterChart, ValAx, createChartType, createNumRef, createStrRef };
import{T as e,a as t,b as n,o as r,p as i}from"../xml-components-Csq7gWPd.mjs";var a=class extends e{constructor(){super(`c:scaling`),this.root.push(n(`c:orientation`,i({val:`minMax`})))}},o=class extends e{constructor(e,t){super(`c:catAx`),this.root.push(n(`c:axId`,i({val:e}))),this.root.push(new a),this.root.push(n(`c:delete`,i({val:0}))),this.root.push(n(`c:axPos`,i({val:`b`}))),this.root.push(n(`c:auto`,i({val:1}))),this.root.push(n(`c:lblOffset`,i({val:100}))),this.root.push(n(`c:noMultiLvlLbl`,i({val:0}))),this.root.push(n(`c:crossAx`,i({val:t}))),this.root.push(n(`c:crosses`,i({val:`autoZero`})))}},s=class extends e{constructor(e,r){super(`c:valAx`),this.root.push(n(`c:axId`,i({val:e}))),this.root.push(new a),this.root.push(n(`c:delete`,i({val:0}))),this.root.push(n(`c:axPos`,i({val:`l`}))),this.root.push(n(`c:numFmt`,i({formatCode:`General`,sourceLinked:1}))),this.root.push(n(`c:crossAx`,i({val:r}))),this.root.push(n(`c:crosses`,i({val:`autoZero`}))),this.root.push(new t({name:`c:spPr`}))}};const c=e=>new u(typeof e==`string`?[e]:e),l=e=>new p(e);var u=class extends e{constructor(e){super(`c:strRef`),this.root.push(new r(`c:f`)),this.root.push(new d(e))}},d=class extends e{constructor(e){super(`c:strCache`),this.root.push(n(`c:ptCount`,i({val:e.length})));for(let t=0;t<e.length;t++)this.root.push(new f(t,e[t]))}},f=class extends e{constructor(e,t){super(`c:pt`),this.root.push(i({idx:e})),this.root.push(new _(`c:v`,t))}},p=class extends e{constructor(e){super(`c:numRef`),this.root.push(new r(`c:f`)),this.root.push(new m(e))}},m=class extends e{constructor(e){super(`c:numCache`),this.root.push(n(`c:ptCount`,i({val:e.length}))),this.root.push(new g(`General`));for(let t=0;t<e.length;t++)this.root.push(new h(t,e[t]))}},h=class extends e{constructor(e,t){super(`c:pt`),this.root.push(i({idx:e})),this.root.push(new _(`c:v`,String(t)))}},g=class extends e{constructor(e){super(`c:formatCode`),this.root.push(e)}},_=class extends e{constructor(e,t){super(e),this.root.push(t)}},v=class extends e{constructor(e){super(`c:areaChart`),this.root.push(n(`c:grouping`,i({val:`standard`})));for(let t=0;t<e.series.length;t++)this.root.push(new y(t,e.series[t],e.categories));this.root.push(n(`c:axId`,i({val:10}))),this.root.push(n(`c:axId`,i({val:20})))}},y=class extends e{constructor(e,t,a){super(`c:ser`),this.root.push(n(`c:idx`,i({val:e}))),this.root.push(n(`c:order`,i({val:e}))),this.root.push(new ee(t.name)),this.root.push(new b(a)),this.root.push(new x(t.values)),this.root.push(new r(`c:spPr`))}},ee=class extends e{constructor(e){super(`c:tx`),this.root.push(c(e))}},b=class extends e{constructor(e){super(`c:cat`),this.root.push(c(e))}},x=class extends e{constructor(e){super(`c:val`),this.root.push(l(e))}},S=class extends e{constructor(e){super(`c:barChart`),this.root.push(n(`c:barDir`,i({val:e.barDirection}))),this.root.push(n(`c:grouping`,i({val:`clustered`})));for(let t=0;t<e.series.length;t++)this.root.push(new C(t,e.series[t],e.categories));this.root.push(n(`c:axId`,i({val:10}))),this.root.push(n(`c:axId`,i({val:20})))}},C=class extends e{constructor(e,t,a){super(`c:ser`),this.root.push(n(`c:idx`,i({val:e}))),this.root.push(n(`c:order`,i({val:e}))),this.root.push(new w(t.name)),this.root.push(new T(a)),this.root.push(new E(t.values)),this.root.push(new r(`c:spPr`))}},w=class extends e{constructor(e){super(`c:tx`),this.root.push(c(e))}},T=class extends e{constructor(e){super(`c:cat`),this.root.push(c(e))}},E=class extends e{constructor(e){super(`c:val`),this.root.push(l(e))}},D=class extends e{constructor(e){super(`c:lineChart`),this.root.push(n(`c:grouping`,i({val:`standard`})));for(let t=0;t<e.series.length;t++)this.root.push(new O(t,e.series[t],e.categories));this.root.push(n(`c:axId`,i({val:10}))),this.root.push(n(`c:axId`,i({val:20})))}},O=class extends e{constructor(e,t,a){super(`c:ser`),this.root.push(n(`c:idx`,i({val:e}))),this.root.push(n(`c:order`,i({val:e}))),this.root.push(new k(t.name)),this.root.push(new A(a)),this.root.push(new j(t.values)),this.root.push(new r(`c:spPr`))}},k=class extends e{constructor(e){super(`c:tx`),this.root.push(c(e))}},A=class extends e{constructor(e){super(`c:cat`),this.root.push(c(e))}},j=class extends e{constructor(e){super(`c:val`),this.root.push(l(e))}},M=class extends e{constructor(e){super(`c:pieChart`),this.root.push(n(`c:varyColors`,i({val:!0})));for(let t=0;t<e.series.length;t++)this.root.push(new N(t,e.series[t],e.categories))}},N=class extends e{constructor(e,t,a){super(`c:ser`),this.root.push(n(`c:idx`,i({val:e}))),this.root.push(n(`c:order`,i({val:e}))),this.root.push(new P(t.name)),this.root.push(new te(a)),this.root.push(new F(t.values)),this.root.push(new r(`c:spPr`))}},P=class extends e{constructor(e){super(`c:tx`),this.root.push(c(e))}},te=class extends e{constructor(e){super(`c:cat`),this.root.push(c(e))}},F=class extends e{constructor(e){super(`c:val`),this.root.push(l(e))}},I=class extends e{constructor(e){super(`c:scatterChart`),this.root.push(n(`c:scatterStyle`,i({val:`line`})));for(let t=0;t<e.series.length;t++)this.root.push(new L(t,e.series[t],e.categories));this.root.push(n(`c:axId`,i({val:10}))),this.root.push(n(`c:axId`,i({val:20})))}},L=class extends e{constructor(e,t,a){super(`c:ser`),this.root.push(n(`c:idx`,i({val:e}))),this.root.push(n(`c:order`,i({val:e}))),this.root.push(new R(t.name)),this.root.push(new z(a)),this.root.push(new B(t.values)),this.root.push(new r(`c:spPr`)),this.root.push(new r(`c:size`))}},R=class extends e{constructor(e){super(`c:tx`),this.root.push(c(e))}},z=class extends e{constructor(e){super(`c:cat`),this.root.push(c(e))}},B=class extends e{constructor(e){super(`c:val`),this.root.push(l(e))}};const V=e=>{switch(e.type){case`column`:case`bar`:return new S({barDirection:e.type===`column`?`col`:`bar`,categories:e.categories,series:e.series});case`line`:return new D({categories:e.categories,series:e.series});case`pie`:return new M({categories:e.categories,series:e.series});case`area`:return new v({categories:e.categories,series:e.series});case`scatter`:return new I({categories:e.categories,series:e.series});default:throw Error(`Unsupported chart type: ${e.type}`)}};var H=class extends e{constructor(e){super(`c:title`),this.root.push(new U(e)),this.root.push(new W)}},U=class extends e{constructor(t){super(`c:tx`);let n=new class extends e{constructor(){super(`c:rich`)}};n.root.push(new class extends e{constructor(){super(`a:bodyPr`)}}),n.root.push(new class extends e{constructor(){super(`a:lstStyle`)}});let r=new class extends e{constructor(){super(`a:p`)}},i=new class extends e{constructor(){super(`a:r`)}};i.root.push(new class extends e{constructor(){super(`a:t`),this.root.push(t)}}),r.root.push(i),n.root.push(r),this.root.push(n)}},W=class extends e{constructor(){super(`c:overlay`),this.root.push(i({val:0}))}},G=class extends e{constructor(e){super(`c:chartSpace`),this.root.push(i({"xmlns:a":`http://schemas.openxmlformats.org/drawingml/2006/main`,"xmlns:c":`http://schemas.openxmlformats.org/drawingml/2006/chart`,"xmlns:r":`http://schemas.openxmlformats.org/officeDocument/2006/relationships`})),this.root.push(n(`c:date1904`,i({val:0}))),this.root.push(n(`c:lang`,i({val:`en-US`}))),this.root.push(n(`c:roundedCorners`,i({val:0})));let r=new K;e.title&&r.root.push(new H(e.title)),r.root.push(n(`c:autoTitleDeleted`,i({val:0})));let a=new q;a.root.push(new t({name:`c:layout`})),a.root.push(V({categories:e.categories,series:e.series,type:e.type})),e.type!==`pie`&&(e.type===`scatter`?(a.root.push(new s(10,20)),a.root.push(new s(20,10))):(a.root.push(new o(10,20)),a.root.push(new s(20,10)))),r.root.push(a),e.showLegend!==!1&&r.root.push(J()),this.root.push(r),this.root.push(X()),this.root.push(Z()),e.style!==void 0&&this.root.push(new re(e.style))}},K=class extends e{constructor(){super(`c:chart`)}},q=class extends e{constructor(){super(`c:plotArea`)}};function J(){let r=new class extends e{constructor(){super(`c:legend`)}};return r.root.push(n(`c:legendPos`,i({val:`b`}))),r.root.push(new t({name:`c:layout`})),r.root.push(n(`c:overlay`,i({val:0}))),r.root.push(Y()),r.root.push(Q()),r}function Y(){let n=new class extends e{constructor(){super(`c:spPr`)}};return n.root.push(new class extends e{constructor(){super(`a:noFill`)}}),n.root.push(new class extends e{constructor(){super(`a:ln`),this.root.push(new class extends e{constructor(){super(`a:noFill`)}})}}),n.root.push(new t({name:`a:effectLst`})),n}function X(){let n=new class extends e{constructor(){super(`c:spPr`)}};return n.root.push(new class extends e{constructor(){super(`a:noFill`)}}),n.root.push(new class extends e{constructor(){super(`a:ln`),this.root.push(new class extends e{constructor(){super(`a:noFill`)}})}}),n.root.push(new t({name:`a:effectLst`})),n}function Z(){let n=new class extends e{constructor(){super(`c:txPr`)}};return n.root.push(new t({name:`a:bodyPr`})),n.root.push(new t({name:`a:lstStyle`})),n.root.push($()),n}function Q(){let n=new class extends e{constructor(){super(`c:txPr`)}};return n.root.push(ne()),n.root.push(new t({name:`a:lstStyle`})),n.root.push($()),n}function ne(){return new t({name:`a:bodyPr`,attributes:{rot:{key:`rot`,value:`0`},spcFirstLastPara:{key:`spcFirstLastPara`,value:`1`},vertOverflow:{key:`vertOverflow`,value:`ellipsis`},vert:{key:`vert`,value:`horz`},wrap:{key:`wrap`,value:`square`},anchor:{key:`anchor`,value:`ctr`},anchorCtr:{key:`anchorCtr`,value:`1`}}})}function $(){let n=new class extends e{constructor(){super(`a:p`)}},r=new class extends e{constructor(){super(`a:pPr`)}};return r.root.push(new t({name:`a:defRPr`})),n.root.push(r),n.root.push(new t({name:`a:endParaRPr`,attributes:{lang:{key:`lang`,value:`en-US`}}})),n}var re=class extends e{constructor(e){super(`c:style`),this.root.push(i({val:String(e)}))}},ie=class{map;constructor(){this.map=new Map}addChart(e,t){this.map.set(e,t)}get Array(){return[...this.map.values()]}};export{v as AreaChart,S as BarChart,o as CatAx,ie as ChartCollection,G as ChartSpace,H as ChartTitle,D as LineChart,M as PieChart,I as ScatterChart,s as ValAx,V as createChartType,l as createNumRef,c as createStrRef};
import { Relationship, elementToXml, findRel, findRelsByType, getImageType, listFiles, parseRels, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, uint8ToBase64, unzipToMap, zipToBuffer } from "./archive.mjs";
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 "./_chunks/index-hmJg8TDw.mjs";
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 "./_chunks/values-COMdgNmb.mjs";
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 "./_chunks/index-B3rs5exK.mjs";
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";
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";
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";
import { Element } from "@office-open/xml";

@@ -6,0 +6,0 @@

@@ -1,424 +0,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 "./_chunks/xml-components-CN6syVNr.mjs";
import { ThemeColor, ThemeFont, dateTimeValue, decimalNumber, eighthPointMeasureValue, hexBinary, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, twipsMeasureValue, uCharHexNumber, universalMeasureValue, unsignedDecimalNumber } from "./values.mjs";
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 "./_chunks/id-generators-Ch07cHW1.mjs";
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 "./_chunks/smartart-D_qXltR5.mjs";
import { elementToXml, findRel, findRelsByType, getImageType, listFiles, parseRels, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, uint8ToBase64, unzipToMap, zipToBuffer } from "./archive.mjs";
import { js2xml, textOf, xml2js } from "@office-open/xml";
import { strFromU8, strToU8 } from "fflate";
//#region src/output-type.ts
/**
* Output type definitions for OOXML document export.
*
* @module
*/
const OoxmlMimeType = {
DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
};
const convertOutput = (data, type, mimeType = OoxmlMimeType.DOCX) => {
switch (type) {
case "nodebuffer": return Buffer.from(data);
case "blob": return new Blob([data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)], { type: mimeType });
case "arraybuffer": return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
case "uint8array": return data;
case "base64": return btoa(strFromU8(data, true));
case "string":
case "text":
case "binarystring": return strFromU8(data, true);
case "array": return [...data];
default: return data;
}
};
//#endregion
//#region src/packer.ts
const PrettifyType = {
NONE: "",
WITH_2_BLANKS: " ",
WITH_4_BLANKS: " ",
WITH_TAB: " "
};
const convertPrettifyType = (prettify) => prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? void 0 : prettify;
//#endregion
//#region src/opc/app-properties.ts
const APP_PROPS_XML = "<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\"/>";
var AppProperties = class AppProperties extends ImportedXmlComponent {
static instance = ImportedXmlComponent.fromXmlString(APP_PROPS_XML);
constructor() {
super("Properties");
}
prepForXml() {
return AppProperties.instance.prepForXml({ stack: [] });
}
};
//#endregion
//#region src/opc/relationships.ts
const TargetModeType = { EXTERNAL: "External" };
const RELS_ATTRS = { _attr: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" } };
var Relationships = class extends BaseXmlComponent {
entries = [];
constructor() {
super("Relationships");
}
addRelationship(id, type, target, targetMode) {
this.entries.push({
id: `rId${id}`,
type,
target,
targetMode
});
}
get RelationshipCount() {
return this.entries.length;
}
prepForXml(_context) {
const children = [RELS_ATTRS];
for (const e of this.entries) {
const attrs = {
Id: e.id,
Type: e.type,
Target: e.target
};
if (e.targetMode) attrs.TargetMode = e.targetMode;
children.push({ Relationship: { _attr: attrs } });
}
if (children.length === 1 && "_attr" in children[0]) return { Relationships: children[0] };
return { Relationships: children };
}
};
//#endregion
//#region src/opc/content-types.ts
/**
* Content Types components for OPC (Open Packaging Convention).
*
* Provides Default and Override elements used in [Content_Types].xml
* to map file extensions and part paths to MIME content types.
*
* Reference: ECMA-376 Part 2, Section 10.1
*
* @module
*/
/**
* Creates a Default element mapping a file extension to a MIME content type.
*/
const createDefault = (contentType, extension) => new BuilderElement({
attributes: {
contentType: {
key: "ContentType",
value: contentType
},
extension: {
key: "Extension",
value: extension
}
},
name: "Default"
});
/**
* Creates an Override element mapping a specific part path to a MIME content type.
*/
const createOverride = (contentType, partName) => new BuilderElement({
attributes: {
contentType: {
key: "ContentType",
value: contentType
},
partName: {
key: "PartName",
value: partName
}
},
name: "Override"
});
/**
* Attributes for the Types (Content Types) root element.
* Declares the XML namespace for the content types part.
*/
var ContentTypeAttributes = class extends XmlAttributeComponent {
xmlKeys = { xmlns: "xmlns" };
};
//#endregion
//#region src/formatter.ts
const XML_DECL = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
/**
* Converts an XmlComponent tree into a serializable XML object.
*/
var Formatter = class {
format(input, context = { stack: [] }) {
const output = input.prepForXml(context);
if (output) return output;
throw new Error("XMLComponent did not format correctly");
}
formatToXml(input, context, declaration) {
const str = input.toXml(context);
return declaration ? XML_DECL + str : str;
}
};
//#endregion
//#region src/core-properties.ts
const FIELD_MAP = [
{
name: "dc:title",
key: "title"
},
{
name: "dc:subject",
key: "subject"
},
{
name: "dc:creator",
key: "creator"
},
{
name: "dc:description",
key: "description"
},
{
name: "cp:keywords",
key: "keywords"
},
{
name: "cp:lastModifiedBy",
key: "lastModifiedBy"
}
];
function parseCoreProperties(zip) {
const xml = readXmlFromZip(zip, "docProps/core.xml");
if (!xml) return {};
const props = {};
for (const field of FIELD_MAP) {
const el = xml.elements?.find((e) => e.name === field.name);
const value = textOf(el) || void 0;
if (value) props[field.key] = value;
}
const revEl = xml.elements?.find((e) => e.name === "cp:revision");
if (revEl) {
const rev = textOf(revEl);
if (rev) {
const n = Number(rev);
if (!isNaN(n)) props.revision = rev;
}
}
return props;
}
const CORE_PROPS_NS = Object.freeze({ _attr: Object.freeze({
"xmlns:cp": "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
"xmlns:dc": "http://purl.org/dc/elements/1.1/",
"xmlns:dcmitype": "http://purl.org/dc/dcmitype/",
"xmlns:dcterms": "http://purl.org/dc/terms/",
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance"
}) });
const W3CDTF_ATTR = Object.freeze({ _attr: Object.freeze({ "xsi:type": "dcterms:W3CDTF" }) });
/**
* Build a cp:coreProperties XML object from metadata.
*
* Shared by docx and pptx to avoid duplicating namespace declarations
* and Dublin Core property construction.
*/
function buildCorePropertiesXml(opts) {
const children = [CORE_PROPS_NS];
if (opts.title) children.push({ "dc:title": [opts.title] });
if (opts.subject) children.push({ "dc:subject": [opts.subject] });
if (opts.creator) children.push({ "dc:creator": [opts.creator] });
if (opts.keywords) children.push({ "cp:keywords": [opts.keywords] });
if (opts.description) children.push({ "dc:description": [opts.description] });
if (opts.lastModifiedBy) children.push({ "cp:lastModifiedBy": [opts.lastModifiedBy] });
if (opts.revision) children.push({ "cp:revision": [String(opts.revision)] });
const now = (/* @__PURE__ */ new Date()).toISOString();
children.push({ "dcterms:created": [W3CDTF_ATTR, now] });
children.push({ "dcterms:modified": [W3CDTF_ATTR, now] });
return { "cp:coreProperties": children };
}
//#endregion
//#region src/parser.ts
const XML_PARSE_OPTIONS = {
nativeTypeAttributes: true,
captureSpacesBetweenElements: true
};
/**
* Parsed OOXML document backed by an unzipped ZIP map.
*
* Provides unstorage-style API (get/set/getRaw/setRaw/remove/has/keys)
* for reading and modifying individual parts, then serializing back to a ZIP buffer.
*/
var ParsedDocument = class {
zip;
modified = /* @__PURE__ */ new Map();
wrapperCache = /* @__PURE__ */ new Map();
constructor(zip) {
this.zip = zip;
}
/** Read an XML part as an Element tree. */
get(path) {
const modData = this.modified.get(path);
if (modData) {
const wrapper = xml2js(strFromU8(modData), XML_PARSE_OPTIONS);
this.wrapperCache.set(path, wrapper);
return wrapper.elements?.find((e) => e.type === "element");
}
const data = this.zip.get(path);
if (data === void 0) return void 0;
const cached = this.wrapperCache.get(path);
if (cached) return cached.elements?.find((e) => e.type === "element");
const wrapper = xml2js(strFromU8(data), XML_PARSE_OPTIONS);
this.wrapperCache.set(path, wrapper);
return wrapper.elements?.find((e) => e.type === "element");
}
/** Write an XML part (Element → XML string). */
set(path, element) {
const wrapper = this.wrapperCache.get(path);
const xml = js2xml(wrapper ? {
...wrapper,
elements: [{
...element,
type: "element"
}]
} : { elements: [{
...element,
type: "element"
}] });
this.modified.set(path, strToU8(xml));
}
/** Read raw binary data (images, media, etc.). */
getRaw(path) {
return this.modified.get(path) ?? this.zip.get(path);
}
/** Write raw binary data. */
setRaw(path, data) {
this.modified.set(path, data);
this.wrapperCache.delete(path);
}
/** Remove a part. Returns true if it existed. */
remove(path) {
this.wrapperCache.delete(path);
return this.modified.delete(path) || this.zip.delete(path);
}
/** Check if a part exists. */
has(path) {
return this.modified.has(path) || this.zip.has(path);
}
/** List all paths matching an optional prefix. */
keys(prefix) {
const all = /* @__PURE__ */ new Set();
for (const key of this.zip.keys()) if (!prefix || key.startsWith(prefix)) all.add(key);
for (const key of this.modified.keys()) if (!prefix || key.startsWith(prefix)) all.add(key);
return [...all];
}
/** Serialize back to a ZIP buffer, merging original zip + modifications. */
save() {
const files = /* @__PURE__ */ new Map();
for (const [path, data] of this.zip) if (!this.modified.has(path)) files.set(path, data);
for (const [path, data] of this.modified) files.set(path, data);
return zipToBuffer(files);
}
};
/** Parse an OOXML file (.docx, .pptx) into a ParsedDocument. */
function parseDocument(data) {
return new ParsedDocument(unzipToMap(data));
}
//#endregion
//#region src/raw-passthrough.ts
/**
* Convert an Element tree to xml-js compact format (IXmlableObject).
* Always wraps in a named key so the element name is preserved even for empty elements.
*/
function elementToCompact(el) {
const inner = {};
if (el.attributes && Object.keys(el.attributes).length > 0) inner._attributes = el.attributes;
if (el.cdata) inner._cdata = el.cdata;
else if (el.text != null) inner._text = el.text;
if (el.elements) for (const child of el.elements) {
const key = child.name ?? "_unknown";
const compactChild = elementToCompact(child);
if (inner[key]) {
if (!Array.isArray(inner[key])) inner[key] = [inner[key]];
inner[key].push(compactChild);
} else inner[key] = compactChild;
}
const name = el.name ?? "unknown";
if (Object.keys(inner).length === 0) return { [name]: {} };
return { [name]: inner };
}
/**
* Thin wrapper that passes a raw Element tree through the XML serialization pipeline.
* Used to include parsed-but-unrecognized XML in generated documents.
*/
var RawPassthrough = class extends BaseXmlComponent {
constructor(element) {
super(element.name ?? "unknown");
this.element = element;
}
prepForXml(_context) {
return elementToCompact(this.element);
}
};
//#endregion
//#region src/placeholder.ts
const formatId = (offset, index, style) => style === "rId" ? `rId${offset + index}` : `${offset + index}`;
function escapeRegex(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function hasPlaceholders(xml) {
return xml.includes("{");
}
function collectPlaceholderKeys(xml, prefix) {
const keys = [];
const search = `{${prefix}`;
let pos = 0;
while ((pos = xml.indexOf(search, pos)) !== -1) {
const keyStart = pos + search.length;
const keyEnd = xml.indexOf("}", keyStart);
if (keyEnd === -1) break;
const key = xml.substring(keyStart, keyEnd);
if (key.length > 0 && !keys.includes(key)) keys.push(key);
pos = keyEnd + 1;
}
return keys;
}
function replaceImagePlaceholders(xml, mediaData, offset, idFormat = "rId") {
let result = xml;
mediaData.forEach((image, i) => {
result = result.replace(new RegExp(`\\{${escapeRegex(image.fileName)}\\}`, "g"), formatId(offset, i, idFormat));
});
return result;
}
function getReferencedMedia(xml, mediaArray) {
return mediaArray.filter((image) => xml.includes(`{${image.fileName}}`));
}
function replaceChartPlaceholders(xml, chartKeys, offset, idFormat = "rId") {
let result = xml;
chartKeys.forEach((key, i) => {
result = result.replace(new RegExp(`\\{chart:${escapeRegex(key)}\\}`, "g"), formatId(offset, i, idFormat));
});
return result;
}
function replaceSmartArtPlaceholders(xml, keys, dataOffset, idFormat = "rId") {
let result = xml;
const count = keys.length;
const loOffset = dataOffset + count;
const qsOffset = loOffset + count;
const csOffset = qsOffset + count;
keys.forEach((key, i) => {
result = result.replace(new RegExp(`\\{smartart:${escapeRegex(key)}\\}`, "g"), formatId(dataOffset, i, idFormat));
result = result.replace(new RegExp(`\\{smartart-lo:${escapeRegex(key)}\\}`, "g"), formatId(loOffset, i, idFormat));
result = result.replace(new RegExp(`\\{smartart-qs:${escapeRegex(key)}\\}`, "g"), formatId(qsOffset, i, idFormat));
result = result.replace(new RegExp(`\\{smartart-cs:${escapeRegex(key)}\\}`, "g"), formatId(csOffset, i, idFormat));
});
return result;
}
function addSmartArtRelationships(keys, addRel, baseOffset, globalStartIndex, options) {
const { pathPrefix, styleRelType } = options;
const count = keys.length;
const loOffset = baseOffset + count;
const qsOffset = loOffset + count;
const csOffset = qsOffset + count;
keys.forEach((_key, i) => {
const gi = globalStartIndex + i;
addRel(baseOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramData", `${pathPrefix}diagrams/data${gi + 1}.xml`);
addRel(loOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramLayout", `${pathPrefix}diagrams/layout${gi + 1}.xml`);
addRel(qsOffset + i, styleRelType, `${pathPrefix}diagrams/quickStyle${gi + 1}.xml`);
addRel(csOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramColors", `${pathPrefix}diagrams/colors${gi + 1}.xml`);
addRel(csOffset + count + i, "http://schemas.microsoft.com/office/2007/relationships/diagramDrawing", `${pathPrefix}diagrams/drawing${gi + 1}.xml`);
});
}
//#endregion
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, parseCoreProperties, parseDocument, 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 };
import{C as e,E as t,S as n,T as r,_ as i,a,b as o,c as s,d as c,f as l,g as u,h as d,i as ee,l as te,m as ne,n as re,o as ie,p as ae,r as f,s as oe,t as se,u as ce,v as le,w as ue,x as de,y as fe}from"./xml-components-Csq7gWPd.mjs";import{ThemeColor as pe,ThemeFont as me,dateTimeValue as he,decimalNumber as p,eighthPointMeasureValue as m,hexBinary as h,hexColorValue as g,hpsMeasureValue as _,longHexNumber as v,measurementOrPercentValue as y,percentageValue as b,pointMeasureValue as x,positiveUniversalMeasureValue as S,shortHexNumber as C,signedHpsMeasureValue as w,signedTwipsMeasureValue as T,twipsMeasureValue as E,uCharHexNumber as D,universalMeasureValue as O,unsignedDecimalNumber as k}from"./values.mjs";import{a as A,c as j,d as M,f as N,i as P,l as F,n as I,o as L,r as R,s as ge,t as _e,u as ve}from"./id-generators-Dd0w7vti.mjs";import{a as ye,c as be,d as xe,f as Se,i as Ce,l as we,n as Te,o as Ee,p as De,r as Oe,s as ke,t as Ae,u as z}from"./smartart-C-ZIRmWU.mjs";import{elementToXml as je,findRel as Me,findRelsByType as Ne,getImageType as Pe,listFiles as Fe,parseRels as Ie,readAllXmlParts as Le,readBinaryFromZip as Re,readTextFromZip as ze,readXmlFromZip as B,uint8ToBase64 as Be,unzipToMap as V,zipToBuffer as H}from"./archive.mjs";import{js2xml as Ve,textOf as U,xml2js as W}from"@office-open/xml";import{strFromU8 as G,strToU8 as He}from"fflate";const K={DOCX:`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,PPTX:`application/vnd.openxmlformats-officedocument.presentationml.presentation`},Ue=(e,t,n=K.DOCX)=>{switch(t){case`nodebuffer`:return Buffer.from(e);case`blob`:return new Blob([e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)],{type:n});case`arraybuffer`:return e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);case`uint8array`:return e;case`base64`:return btoa(G(e,!0));case`string`:case`text`:case`binarystring`:return G(e,!0);case`array`:return[...e];default:return e}},q={NONE:``,WITH_2_BLANKS:` `,WITH_4_BLANKS:` `,WITH_TAB:` `},We=e=>e===!0?q.WITH_2_BLANKS:e===!1?void 0:e;var Ge=class e extends f{static instance=f.fromXmlString(`<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"/>`);constructor(){super(`Properties`)}prepForXml(){return e.instance.prepForXml({stack:[]})}};const Ke={EXTERNAL:`External`},qe={_attr:{xmlns:`http://schemas.openxmlformats.org/package/2006/relationships`}};var Je=class extends t{entries=[];constructor(){super(`Relationships`)}addRelationship(e,t,n,r){this.entries.push({id:`rId${e}`,type:t,target:n,targetMode:r})}get RelationshipCount(){return this.entries.length}prepForXml(e){let t=[qe];for(let e of this.entries){let n={Id:e.id,Type:e.type,Target:e.target};e.targetMode&&(n.TargetMode=e.targetMode),t.push({Relationship:{_attr:n}})}return t.length===1&&`_attr`in t[0]?{Relationships:t[0]}:{Relationships:t}}};const Ye=(e,t)=>new a({attributes:{contentType:{key:`ContentType`,value:e},extension:{key:`Extension`,value:t}},name:`Default`}),Xe=(e,t)=>new a({attributes:{contentType:{key:`ContentType`,value:e},partName:{key:`PartName`,value:t}},name:`Override`});var Ze=class extends n{xmlKeys={xmlns:`xmlns`}},Qe=class{format(e,t={stack:[]}){let n=e.prepForXml(t);if(n)return n;throw Error(`XMLComponent did not format correctly`)}formatToXml(e,t,n){let r=e.toXml(t);return n?`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>`+r:r}};const $e=[{name:`dc:title`,key:`title`},{name:`dc:subject`,key:`subject`},{name:`dc:creator`,key:`creator`},{name:`dc:description`,key:`description`},{name:`cp:keywords`,key:`keywords`},{name:`cp:lastModifiedBy`,key:`lastModifiedBy`}];function et(e){let t=B(e,`docProps/core.xml`);if(!t)return{};let n={};for(let e of $e){let r=t.elements?.find(t=>t.name===e.name),i=U(r)||void 0;i&&(n[e.key]=i)}let r=t.elements?.find(e=>e.name===`cp:revision`);if(r){let e=U(r);if(e){let t=Number(e);isNaN(t)||(n.revision=e)}}return n}const tt=Object.freeze({_attr:Object.freeze({"xmlns:cp":`http://schemas.openxmlformats.org/package/2006/metadata/core-properties`,"xmlns:dc":`http://purl.org/dc/elements/1.1/`,"xmlns:dcmitype":`http://purl.org/dc/dcmitype/`,"xmlns:dcterms":`http://purl.org/dc/terms/`,"xmlns:xsi":`http://www.w3.org/2001/XMLSchema-instance`})}),J=Object.freeze({_attr:Object.freeze({"xsi:type":`dcterms:W3CDTF`})});function nt(e){let t=[tt];e.title&&t.push({"dc:title":[e.title]}),e.subject&&t.push({"dc:subject":[e.subject]}),e.creator&&t.push({"dc:creator":[e.creator]}),e.keywords&&t.push({"cp:keywords":[e.keywords]}),e.description&&t.push({"dc:description":[e.description]}),e.lastModifiedBy&&t.push({"cp:lastModifiedBy":[e.lastModifiedBy]}),e.revision&&t.push({"cp:revision":[String(e.revision)]});let n=new Date().toISOString();return t.push({"dcterms:created":[J,n]}),t.push({"dcterms:modified":[J,n]}),{"cp:coreProperties":t}}const Y={nativeTypeAttributes:!0,captureSpacesBetweenElements:!0};var X=class{zip;modified=new Map;wrapperCache=new Map;constructor(e){this.zip=e}get(e){let t=this.modified.get(e);if(t){let n=W(G(t),Y);return this.wrapperCache.set(e,n),n.elements?.find(e=>e.type===`element`)}let n=this.zip.get(e);if(n===void 0)return;let r=this.wrapperCache.get(e);if(r)return r.elements?.find(e=>e.type===`element`);let i=W(G(n),Y);return this.wrapperCache.set(e,i),i.elements?.find(e=>e.type===`element`)}set(e,t){let n=this.wrapperCache.get(e),r=Ve(n?{...n,elements:[{...t,type:`element`}]}:{elements:[{...t,type:`element`}]});this.modified.set(e,He(r))}getRaw(e){return this.modified.get(e)??this.zip.get(e)}setRaw(e,t){this.modified.set(e,t),this.wrapperCache.delete(e)}remove(e){return this.wrapperCache.delete(e),this.modified.delete(e)||this.zip.delete(e)}has(e){return this.modified.has(e)||this.zip.has(e)}keys(e){let t=new Set;for(let n of this.zip.keys())(!e||n.startsWith(e))&&t.add(n);for(let n of this.modified.keys())(!e||n.startsWith(e))&&t.add(n);return[...t]}save(){let e=new Map;for(let[t,n]of this.zip)this.modified.has(t)||e.set(t,n);for(let[t,n]of this.modified)e.set(t,n);return H(e)}};function rt(e){return new X(V(e))}function Z(e){let t={};if(e.attributes&&Object.keys(e.attributes).length>0&&(t._attributes=e.attributes),e.cdata?t._cdata=e.cdata:e.text!=null&&(t._text=e.text),e.elements)for(let n of e.elements){let e=n.name??`_unknown`,r=Z(n);t[e]?(Array.isArray(t[e])||(t[e]=[t[e]]),t[e].push(r)):t[e]=r}let n=e.name??`unknown`;return Object.keys(t).length===0?{[n]:{}}:{[n]:t}}var it=class extends t{constructor(e){super(e.name??`unknown`),this.element=e}prepForXml(e){return Z(this.element)}};const Q=(e,t,n)=>n===`rId`?`rId${e+t}`:`${e+t}`;function $(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function at(e){return e.includes(`{`)}function ot(e,t){let n=[],r=`{${t}`,i=0;for(;(i=e.indexOf(r,i))!==-1;){let t=i+r.length,a=e.indexOf(`}`,t);if(a===-1)break;let o=e.substring(t,a);o.length>0&&!n.includes(o)&&n.push(o),i=a+1}return n}function st(e,t,n,r=`rId`){let i=e;return t.forEach((e,t)=>{i=i.replace(RegExp(`\\{${$(e.fileName)}\\}`,`g`),Q(n,t,r))}),i}function ct(e,t){return t.filter(t=>e.includes(`{${t.fileName}}`))}function lt(e,t,n,r=`rId`){let i=e;return t.forEach((e,t)=>{i=i.replace(RegExp(`\\{chart:${$(e)}\\}`,`g`),Q(n,t,r))}),i}function ut(e,t,n,r=`rId`){let i=e,a=t.length,o=n+a,s=o+a,c=s+a;return t.forEach((e,t)=>{i=i.replace(RegExp(`\\{smartart:${$(e)}\\}`,`g`),Q(n,t,r)),i=i.replace(RegExp(`\\{smartart-lo:${$(e)}\\}`,`g`),Q(o,t,r)),i=i.replace(RegExp(`\\{smartart-qs:${$(e)}\\}`,`g`),Q(s,t,r)),i=i.replace(RegExp(`\\{smartart-cs:${$(e)}\\}`,`g`),Q(c,t,r))}),i}function dt(e,t,n,r,i){let{pathPrefix:a,styleRelType:o}=i,s=e.length,c=n+s,l=c+s,u=l+s;e.forEach((e,i)=>{let d=r+i;t(n+i,`http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramData`,`${a}diagrams/data${d+1}.xml`),t(c+i,`http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramLayout`,`${a}diagrams/layout${d+1}.xml`),t(l+i,o,`${a}diagrams/quickStyle${d+1}.xml`),t(u+i,`http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramColors`,`${a}diagrams/colors${d+1}.xml`),t(u+s+i,`http://schemas.microsoft.com/office/2007/relationships/diagramDrawing`,`${a}diagrams/drawing${d+1}.xml`)})}export{Ge as AppProperties,t as BaseXmlComponent,a as BuilderElement,xe as COLOR_CATEGORIES,Ee as Connection,Ze as ContentTypeAttributes,ke as DEFAULT_DRAWING_XML,ye as DataModel,e as EMPTY_OBJECT,ie as EmptyElement,Qe as Formatter,oe as HpsMeasureElement,ue as IgnoreIfEmptyXmlComponent,re as ImportedRootElementAttributes,f as ImportedXmlComponent,se as InitializableXmlComponent,Se as LAYOUT_CATEGORIES,de as NextAttributeComponent,s as NumberValueElement,te as OnOffElement,K as OoxmlMimeType,X as ParsedDocument,Oe as Point,q as PrettifyType,it as RawPassthrough,Je as Relationships,De as STYLE_CATEGORIES,Te as SmartArtCollection,ce as StringContainer,c as StringEnumValueElement,l as StringValueElement,Ke as TargetModeType,pe as ThemeColor,me as ThemeFont,Ce as TransPoint,n as XmlAttributeComponent,r as XmlComponent,dt as addSmartArtRelationships,nt as buildCorePropertiesXml,ae as chartAttr,ot as collectPlaceholderKeys,A as convertEmuToInches,L as convertEmuToPixels,ge as convertEmuToPoints,j as convertInchesToEmu,F as convertInchesToTwip,ve as convertMillimetersToTwip,Ue as convertOutput,M as convertPixelsToEmu,N as convertPointsToEmu,We as convertPrettifyType,ee as convertToXmlComponent,Ae as createDataModel,Ye as createDefault,Xe as createOverride,he as dateTimeValue,p as decimalNumber,m as eighthPointMeasureValue,Z as elementToCompact,je as elementToXml,$ as escapeRegex,Me as findRel,Ne as findRelsByType,Q as formatId,be as getColorXml,Pe as getImageType,we as getLayoutXml,ct as getReferencedMedia,z as getStyleXml,at as hasPlaceholders,_e as hashedId,h as hexBinary,g as hexColorValue,ne as hpsMeasureObj,_ as hpsMeasureValue,Fe as listFiles,v as longHexNumber,y as measurementOrPercentValue,d as numberValObj,u as onOffObj,et as parseCoreProperties,rt as parseDocument,Ie as parseRels,b as percentageValue,x as pointMeasureValue,S as positiveUniversalMeasureValue,Le as readAllXmlParts,Re as readBinaryFromZip,ze as readTextFromZip,B as readXmlFromZip,lt as replaceChartPlaceholders,st as replaceImagePlaceholders,ut as replaceSmartArtPlaceholders,C as shortHexNumber,w as signedHpsMeasureValue,T as signedTwipsMeasureValue,i as stringContainerObj,le as stringEnumValObj,fe as stringValObj,E as twipsMeasureValue,D as uCharHexNumber,Be as uint8ToBase64,I as uniqueId,R as uniqueNumericIdCreator,P as uniqueUuid,O as universalMeasureValue,k as unsignedDecimalNumber,V as unzipToMap,o as wrapEl,H as zipToBuffer};

@@ -1,2 +0,2 @@

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 "../_chunks/index-B3rs5exK.mjs";
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";
export { COLOR_CATEGORIES, Connection, DEFAULT_DRAWING_XML, DataModel, ISmartArtData, ITreeNode, LAYOUT_CATEGORIES, Point, STYLE_CATEGORIES, SmartArtCollection, TransPoint, createDataModel, getColorXml, getLayoutXml, getStyleXml };

@@ -1,2 +0,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 "../_chunks/smartart-D_qXltR5.mjs";
export { COLOR_CATEGORIES, Connection, DEFAULT_DRAWING_XML, DataModel, LAYOUT_CATEGORIES, Point, STYLE_CATEGORIES, SmartArtCollection, TransPoint, createDataModel, getColorXml, getLayoutXml, getStyleXml };
import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"../smartart-C-ZIRmWU.mjs";export{n as COLOR_CATEGORIES,s as Connection,u as DEFAULT_DRAWING_XML,e as DataModel,r as LAYOUT_CATEGORIES,l as Point,c as STYLE_CATEGORIES,o as SmartArtCollection,i as TransPoint,d as createDataModel,t as getColorXml,a as getLayoutXml,f as getStyleXml};

@@ -1,2 +0,2 @@

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 "./_chunks/values-COMdgNmb.mjs";
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";
export { Percentage, PositivePercentage, PositiveUniversalMeasure, RelativeMeasure, ThemeColor, ThemeFont, UniversalMeasure, dateTimeValue, decimalNumber, eighthPointMeasureValue, hexBinary, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, twipsMeasureValue, uCharHexNumber, universalMeasureValue, unsignedDecimalNumber };

@@ -1,371 +0,1 @@

//#region src/values.ts
/**
* Validates and converts a number to an integer (decimal number).
*
* Reference: ST_DecimalNumber in OOXML specification
*
* @param val - The number to validate and convert
* @returns The floored integer value
* @throws Error if the value is NaN
*
* @example
* ```typescript
* const num = decimalNumber(10.7); // Returns 10
* const negative = decimalNumber(-5.3); // Returns -5
* ```
*/
const decimalNumber = (val) => {
if (isNaN(val)) throw new Error(`Invalid value '${val}' specified. Must be an integer.`);
return Math.floor(val);
};
/**
* Validates and converts a number to a positive integer (unsigned decimal number).
*
* Reference: ST_UnsignedDecimalNumber in OOXML specification
*
* @param val - The number to validate and convert
* @returns The floored positive integer value
* @throws Error if the value is NaN or negative
*
* @example
* ```typescript
* const num = unsignedDecimalNumber(10.7); // Returns 10
* const invalid = unsignedDecimalNumber(-5); // Throws Error
* ```
*/
const unsignedDecimalNumber = (val) => {
const value = decimalNumber(val);
if (value < 0) throw new Error(`Invalid value '${val}' specified. Must be a positive integer.`);
return value;
};
/**
* Validates and normalizes a hexadecimal binary value.
*
* The xsd:hexBinary type represents binary data as a sequence of binary octets
* using hexadecimal encoding, where each binary octet is a two-character
* hexadecimal number. Both lowercase and uppercase letters A-F are permitted.
*
* @param val - The hexadecimal string to validate
* @param length - The expected length in bytes (not characters)
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid hex string of the expected length
*
* @example
* ```typescript
* hexBinary("0FB8", 2); // Valid: 2 bytes = 4 characters
* hexBinary("ABC", 2); // Invalid: wrong length
* ```
*/
const hexBinary = (val, length) => {
const expectedLength = length * 2;
if (val.length !== expectedLength || isNaN(Number(`0x${val}`))) throw new Error(`Invalid hex value '${val}'. Expected ${expectedLength} digit hex value`);
return val;
};
/**
* Validates a long hexadecimal number (4 bytes / 8 characters).
*
* Reference: ST_LongHexNumber in OOXML specification
*
* @param val - The hexadecimal string to validate
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid 8-character hex string
*
* @example
* ```typescript
* const hex = longHexNumber("ABCD1234"); // Valid
* ```
*/
const longHexNumber = (val) => hexBinary(val, 4);
/**
* Validates a short hexadecimal number (2 bytes / 4 characters).
*
* Reference: ST_ShortHexNumber in OOXML specification
*
* @param val - The hexadecimal string to validate
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid 4-character hex string
*
* @example
* ```typescript
* const hex = shortHexNumber("AB12"); // Valid
* ```
*/
const shortHexNumber = (val) => hexBinary(val, 2);
/**
* Validates a single-byte hexadecimal number (1 byte / 2 characters).
*
* Reference: ST_UcharHexNumber in OOXML specification
*
* @param val - The hexadecimal string to validate
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid 2-character hex string
*
* @example
* ```typescript
* const hex = uCharHexNumber("FF"); // Valid
* ```
*/
const uCharHexNumber = (val) => hexBinary(val, 1);
/**
* Normalizes a universal measure value by parsing and reformatting.
*
* Ensures the numeric portion is properly formatted while preserving the unit.
*
* Reference: ST_UniversalMeasure in OOXML specification
*
* @param val - The universal measure string to normalize
* @returns The normalized universal measure
*
* @example
* ```typescript
* const measure = universalMeasureValue("10.500mm"); // Returns "10.5mm"
* ```
*/
const universalMeasureValue = (val) => {
const unit = val.slice(-2);
const amount = val.substring(0, val.length - 2);
return `${Number(amount)}${unit}`;
};
/**
* Validates and normalizes a positive universal measure value.
*
* Reference: ST_PositiveUniversalMeasure in OOXML specification
*
* @param val - The positive universal measure string to validate
* @returns The normalized positive universal measure
* @throws Error if the value is negative
*
* @example
* ```typescript
* const measure = positiveUniversalMeasureValue("10.5mm"); // Valid
* const invalid = positiveUniversalMeasureValue("-5mm"); // Throws Error
* ```
*/
const positiveUniversalMeasureValue = (val) => {
const value = universalMeasureValue(val);
if (parseFloat(value) < 0) throw new Error(`Invalid value '${value}' specified. Expected a positive number.`);
return value;
};
/**
* Validates and normalizes a hexadecimal color value.
*
* Accepts either "auto" or a 6-character RGB hex value (with or without # prefix).
* The # prefix is commonly used but technically invalid in OOXML, so it is stripped
* for strict compliance.
*
* Reference: ST_HexColor in OOXML specification
*
* @param val - The color value to validate ("auto" or hex color)
* @returns The normalized color value
* @throws Error if the hex color is invalid
*
* @example
* ```typescript
* const color1 = hexColorValue("auto"); // Returns "auto"
* const color2 = hexColorValue("FF0000"); // Returns "FF0000"
* const color3 = hexColorValue("#00FF00"); // Returns "00FF00" (# stripped)
* ```
*/
const hexColorValue = (val) => {
if (val === "auto") return val;
return hexBinary(val.charAt(0) === "#" ? val.substring(1) : val, 3);
};
/**
* Validates a signed TWIP measurement value.
*
* Accepts either a universal measure string or a numeric TWIP value.
*
* Reference: ST_SignedTwipsMeasure in OOXML specification
*
* @param val - The measurement value (universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const measure1 = signedTwipsMeasureValue("10mm");
* const measure2 = signedTwipsMeasureValue(1440); // 1 inch in TWIP
* ```
*/
const signedTwipsMeasureValue = (val) => typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val);
/**
* Validates a half-point (HPS) measurement value.
*
* Accepts either a positive universal measure string or a positive number.
* HPS (half-points) are commonly used for font sizes.
*
* Reference: ST_HpsMeasure in OOXML specification
*
* @param val - The measurement value (positive universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const fontSize1 = hpsMeasureValue("12pt");
* const fontSize2 = hpsMeasureValue(24); // 12pt in half-points
* ```
*/
const hpsMeasureValue = (val) => typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val);
/**
* Validates a signed half-point (HPS) measurement value.
*
* Accepts either a universal measure string or a numeric value.
*
* Reference: ST_SignedHpsMeasure in OOXML specification
*
* @param val - The measurement value (universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const spacing1 = signedHpsMeasureValue("6pt");
* const spacing2 = signedHpsMeasureValue(-12); // Negative spacing
* ```
*/
const signedHpsMeasureValue = (val) => typeof val === "string" ? universalMeasureValue(val) : decimalNumber(val);
/**
* Validates a positive TWIP measurement value.
*
* Accepts either a positive universal measure string or a positive number.
*
* Reference: ST_TwipsMeasure in OOXML specification
*
* @param val - The measurement value (positive universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const width1 = twipsMeasureValue("25.4mm");
* const width2 = twipsMeasureValue(1440); // 1 inch in TWIP
* ```
*/
const twipsMeasureValue = (val) => typeof val === "string" ? positiveUniversalMeasureValue(val) : unsignedDecimalNumber(val);
/**
* Normalizes a percentage value by parsing and reformatting.
*
* Reference: ST_Percentage in OOXML specification
*
* @param val - The percentage string to normalize
* @returns The normalized percentage
*
* @example
* ```typescript
* const percent = percentageValue("50.000%"); // Returns "50%"
* ```
*/
const percentageValue = (val) => {
const percent = val.substring(0, val.length - 1);
return `${Number(percent)}%`;
};
/**
* Validates a measurement value that can be expressed as a number, percentage, or universal measure.
*
* Reference: ST_MeasurementOrPercent in OOXML specification
*
* @param val - The measurement value (number, percentage, or universal measure)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const measure1 = measurementOrPercentValue(100); // Unqualified number
* const measure2 = measurementOrPercentValue("50%"); // Percentage
* const measure3 = measurementOrPercentValue("10mm"); // Universal measure
* ```
*/
const measurementOrPercentValue = (val) => {
if (typeof val === "number") return decimalNumber(val);
if (val.slice(-1) === "%") return percentageValue(val);
return universalMeasureValue(val);
};
/**
* Validates an eighth-point measurement value.
*
* Eighth-points are used for fine-grained measurements in text formatting.
*
* Reference: ST_EighthPointMeasure in OOXML specification
*
* @param val - The measurement value in eighth-points
* @returns The validated positive integer value
*
* @example
* ```typescript
* const measure = eighthPointMeasureValue(16); // 2 points
* ```
*/
const eighthPointMeasureValue = unsignedDecimalNumber;
/**
* Validates a point measurement value.
*
* Reference: ST_PointMeasure in OOXML specification
*
* @param val - The measurement value in points
* @returns The validated positive integer value
*
* @example
* ```typescript
* const fontSize = pointMeasureValue(12); // 12pt
* ```
*/
const pointMeasureValue = unsignedDecimalNumber;
/**
* Converts a JavaScript Date object to an ISO 8601 date-time string.
*
* The format is CCYY-MM-DDThh:mm:ss.sssZ where T is a literal and Z indicates UTC.
* This matches the xsd:dateTime format required by OOXML.
*
* Reference: ST_DateTime in OOXML specification
*
* @param val - The Date object to convert
* @returns An ISO 8601 formatted date-time string
*
* @example
* ```typescript
* const now = new Date();
* const timestamp = dateTimeValue(now); // Returns "2024-01-15T10:30:00.000Z"
* ```
*/
const dateTimeValue = (val) => val.toISOString();
/**
* Theme color values used throughout OOXML for referencing document theme colors.
*
* Reference: ST_ThemeColor in OOXML specification
*
* @publicApi
*/
const ThemeColor = {
DARK1: "dark1",
LIGHT1: "light1",
DARK2: "dark2",
LIGHT2: "light2",
ACCENT1: "accent1",
ACCENT2: "accent2",
ACCENT3: "accent3",
ACCENT4: "accent4",
ACCENT5: "accent5",
ACCENT6: "accent6",
HYPERLINK: "hyperlink",
FOLLOWED_HYPERLINK: "followedHyperlink",
NONE: "none",
BACKGROUND1: "background1",
TEXT1: "text1",
BACKGROUND2: "background2",
TEXT2: "text2"
};
/**
* Theme font values used for referencing document theme fonts.
*
* Reference: ST_Theme in OOXML specification
*
* @publicApi
*/
const ThemeFont = {
MAJOR_EAST_ASIA: "majorEastAsia",
MAJOR_BIDI: "majorBidi",
MAJOR_ASCII: "majorAscii",
MAJOR_H_ANSI: "majorHAnsi",
MINOR_EAST_ASIA: "minorEastAsia",
MINOR_BIDI: "minorBidi",
MINOR_ASCII: "minorAscii",
MINOR_H_ANSI: "minorHAnsi"
};
//#endregion
export { ThemeColor, ThemeFont, dateTimeValue, decimalNumber, eighthPointMeasureValue, hexBinary, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, twipsMeasureValue, uCharHexNumber, universalMeasureValue, unsignedDecimalNumber };
const e=e=>{if(isNaN(e))throw Error(`Invalid value '${e}' specified. Must be an integer.`);return Math.floor(e)},t=t=>{let n=e(t);if(n<0)throw Error(`Invalid value '${t}' specified. Must be a positive integer.`);return n},n=(e,t)=>{let n=t*2;if(e.length!==n||isNaN(Number(`0x${e}`)))throw Error(`Invalid hex value '${e}'. Expected ${n} digit hex value`);return e},r=e=>n(e,4),i=e=>n(e,2),a=e=>n(e,1),o=e=>{let t=e.slice(-2),n=e.substring(0,e.length-2);return`${Number(n)}${t}`},s=e=>{let t=o(e);if(parseFloat(t)<0)throw Error(`Invalid value '${t}' specified. Expected a positive number.`);return t},c=e=>e===`auto`?e:n(e.charAt(0)===`#`?e.substring(1):e,3),l=t=>typeof t==`string`?o(t):e(t),u=e=>typeof e==`string`?s(e):t(e),d=t=>typeof t==`string`?o(t):e(t),f=e=>typeof e==`string`?s(e):t(e),p=e=>{let t=e.substring(0,e.length-1);return`${Number(t)}%`},m=t=>typeof t==`number`?e(t):t.slice(-1)===`%`?p(t):o(t),h=t,g=t,_=e=>e.toISOString(),v={DARK1:`dark1`,LIGHT1:`light1`,DARK2:`dark2`,LIGHT2:`light2`,ACCENT1:`accent1`,ACCENT2:`accent2`,ACCENT3:`accent3`,ACCENT4:`accent4`,ACCENT5:`accent5`,ACCENT6:`accent6`,HYPERLINK:`hyperlink`,FOLLOWED_HYPERLINK:`followedHyperlink`,NONE:`none`,BACKGROUND1:`background1`,TEXT1:`text1`,BACKGROUND2:`background2`,TEXT2:`text2`},y={MAJOR_EAST_ASIA:`majorEastAsia`,MAJOR_BIDI:`majorBidi`,MAJOR_ASCII:`majorAscii`,MAJOR_H_ANSI:`majorHAnsi`,MINOR_EAST_ASIA:`minorEastAsia`,MINOR_BIDI:`minorBidi`,MINOR_ASCII:`minorAscii`,MINOR_H_ANSI:`minorHAnsi`};export{v as ThemeColor,y as ThemeFont,_ as dateTimeValue,e as decimalNumber,h as eighthPointMeasureValue,n as hexBinary,c as hexColorValue,u as hpsMeasureValue,r as longHexNumber,m as measurementOrPercentValue,p as percentageValue,g as pointMeasureValue,s as positiveUniversalMeasureValue,i as shortHexNumber,d as signedHpsMeasureValue,l as signedTwipsMeasureValue,f as twipsMeasureValue,a as uCharHexNumber,o as universalMeasureValue,t as unsignedDecimalNumber};
{
"name": "@office-open/core",
"version": "0.4.6",
"version": "0.5.0",
"description": "Shared OOXML infrastructure: XmlComponent, value validators, unit converters",

@@ -59,10 +59,10 @@ "keywords": [

"dependencies": {
"fflate": "0.8.2",
"fflate": "0.8.3",
"hash.js": "1.1.7",
"nanoid": "5.1.9",
"@office-open/xml": "0.4.6"
"nanoid": "5.1.11",
"@office-open/xml": "0.5.0"
},
"scripts": {
"dev": "basis build --stub",
"build": "basis build",
"build": "vp pack",
"test": "vp test run --coverage",

@@ -69,0 +69,0 @@ "test:ci": "vp test run --coverage"

+11
-11

@@ -33,10 +33,10 @@ # @office-open/core

import {
OnOffElement,
StringValueElement,
BuilderElement,
StringContainer,
hexColorValue,
decimalNumber,
convertMillimetersToTwip,
uniqueNumericIdCreator,
OnOffElement,
StringValueElement,
BuilderElement,
StringContainer,
hexColorValue,
decimalNumber,
convertMillimetersToTwip,
uniqueNumericIdCreator,
} from "@office-open/core";

@@ -53,5 +53,5 @@

new BuilderElement({
name: "w:r",
attributes: { lang: { key: "xml:lang", value: "en-US" } },
children: [new StringContainer("w:t", "Hello")],
name: "w:r",
attributes: { lang: { key: "xml:lang", value: "en-US" } },
children: [new StringContainer("w:t", "Hello")],
});

@@ -58,0 +58,0 @@

import hash from "hash.js";
import { customAlphabet, nanoid } from "nanoid/non-secure";
//#region src/converters.ts
/**
* OOXML unit conversion utilities.
*
* @module
*/
/**
* Converts millimeters to TWIP (twentieths of a point).
*/
const convertMillimetersToTwip = (millimeters) => Math.floor(millimeters / 25.4 * 72 * 20);
/**
* Converts inches to TWIP (twentieths of a point).
*/
const convertInchesToTwip = (inches) => Math.floor(inches * 72 * 20);
/**
* Converts pixels to EMU (96 DPI).
*/
const convertPixelsToEmu = (pixels) => Math.round(pixels * 9525);
/**
* Converts EMU to pixels (96 DPI).
*/
const convertEmuToPixels = (emus) => Math.round(emus / 9525);
/**
* Converts inches to EMU.
*/
const convertInchesToEmu = (inches) => Math.round(inches * 914400);
/**
* Converts EMU to inches.
*/
const convertEmuToInches = (emus) => emus / 914400;
/**
* Converts points to EMU.
*/
const convertPointsToEmu = (points) => Math.round(points * 12700);
/**
* Converts EMU to points.
*/
const convertEmuToPoints = (emus) => emus / 12700;
//#endregion
//#region src/id-generators.ts
/**
* Unique ID generation utilities.
*
* @module
*/
/**
* Creates a unique numeric ID generator with sequential numbering.
*/
const uniqueNumericIdCreator = (initial = 0) => {
let currentCount = initial;
return () => ++currentCount;
};
/**
* Generates a unique lowercase alphanumeric ID using nanoid.
*/
const uniqueId = () => nanoid().toLowerCase();
/**
* Generates a SHA-1 hash of the provided data.
*/
const hashedId = (data) => hash.sha1().update(data instanceof ArrayBuffer ? new Uint8Array(data) : data).digest("hex");
/**
* Generates a random hexadecimal string of specified length.
*/
const generateUuidPart = (count) => customAlphabet("1234567890abcdef", count)();
/**
* Generates a UUID v4-style unique identifier.
*/
const uniqueUuid = () => `${generateUuidPart(8)}-${generateUuidPart(4)}-${generateUuidPart(4)}-${generateUuidPart(4)}-${generateUuidPart(12)}`;
//#endregion
export { convertEmuToInches as a, convertInchesToEmu as c, convertPixelsToEmu as d, convertPointsToEmu as f, uniqueUuid as i, convertInchesToTwip as l, uniqueId as n, convertEmuToPixels as o, uniqueNumericIdCreator as r, convertEmuToPoints as s, hashedId as t, convertMillimetersToTwip as u };
import { O as XmlComponent } from "./index-hmJg8TDw.mjs";
//#region src/smartart/categories.d.ts
/** Layout ID → OOXML category type */
declare const LAYOUT_CATEGORIES: Record<string, string>;
/** Style ID → OOXML category type */
declare const STYLE_CATEGORIES: Record<string, string>;
/** Color ID → OOXML category type */
declare const COLOR_CATEGORIES: Record<string, string>;
//#endregion
//#region src/smartart/built-in-definitions.d.ts
/**
* Returns layout XML. Full XML for "default", minimal stub for others.
* Stub has no layoutNode so PowerPoint falls back to built-in definitions
* based on the uniqueId / loTypeId in the data model.
*/
declare function getLayoutXml(layoutId: string): string;
/**
* Returns style stub XML with the given uniqueId.
*/
declare function getStyleXml(styleId: string): string;
/**
* Returns color stub XML with the given uniqueId.
*/
declare function getColorXml(colorId: string): string;
/** Minimal drawing cache for SmartArt (Office apps auto-regenerate this on open) */
declare const DEFAULT_DRAWING_XML: string;
//#endregion
//#region src/smartart/data-model/connection.d.ts
/**
* dgm:cxn — SmartArt data model connection (edge).
*/
declare class Connection extends XmlComponent {
constructor(modelId: string, srcId: string, destId: string, type?: string, srcOrd?: number, destOrd?: number, parTransId?: string, sibTransId?: string);
}
//#endregion
//#region src/smartart/data-model/data-model.d.ts
/**
* CT_DataModel — the complete data model for a SmartArt diagram.
*/
declare class DataModel extends XmlComponent {
constructor(points: readonly XmlComponent[], connections: readonly Connection[]);
}
//#endregion
//#region src/smartart/data-model/point.d.ts
/**
* dgm:pt — SmartArt data model point (node).
*/
declare class Point extends XmlComponent {
constructor(modelId: string, text: string, type?: string);
}
/**
* Transition point (parTrans or sibTrans) — no text body, references a connection.
*/
declare class TransPoint extends XmlComponent {
constructor(modelId: string, type: string, cxnId: string);
}
//#endregion
//#region src/smartart/smartart-collection.d.ts
interface ISmartArtData {
readonly key: string;
readonly dataModel: DataModel;
readonly layout: string;
readonly style: string;
readonly color: string;
}
/**
* Manages SmartArt parts in a document.
*/
declare class SmartArtCollection {
private readonly map;
constructor();
addSmartArt(key: string, data: ISmartArtData): void;
get Array(): readonly ISmartArtData[];
}
//#endregion
//#region src/smartart/tree-to-model.d.ts
interface ITreeNode {
readonly text: string;
readonly children?: readonly ITreeNode[];
}
/**
* Creates a DataModel from tree nodes with layout/style/color settings.
*/
declare const createDataModel: (nodes: readonly ITreeNode[], layout?: string, style?: string, color?: string) => DataModel;
//#endregion
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 };
import { r as PositiveUniversalMeasure } from "./values-COMdgNmb.mjs";
import { Element } from "@office-open/xml";
//#region src/xml-components/types.d.ts
/**
* XML-serializable object types for OOXML document generation.
*
* @module
*/
/**
* Attributes for an XML element.
*/
type IXmlAttribute = Readonly<Record<string, string | number | boolean>>;
/**
* Object that can be serialized to XML.
*/
type IXmlableObject = Readonly<Record<string, any>>;
//#endregion
//#region src/xml-components/base.d.ts
/**
* Context object passed through the XML tree during serialization.
*
* @typeParam TFileData - The type of the root file data object (format-specific)
*/
interface IContext<TFileData = unknown> {
/** The root file data object being serialized (format-specific). */
readonly fileData?: TFileData;
/** Current traversal stack of components (mutable for performance). */
readonly stack: IXmlableObject[];
}
/**
* Abstract base class for all XML components.
*/
declare abstract class BaseXmlComponent {
/** The XML element name for this component (e.g., "w:p" for paragraph). */
protected readonly rootKey: string;
constructor(rootKey: string);
/**
* Prepares this component for XML serialization.
*
* @param context - The serialization context
* @returns The XML-serializable object, or undefined to exclude from output
*/
abstract prepForXml(context: IContext): IXmlableObject | undefined;
}
//#endregion
//#region src/xml-components/component.d.ts
/**
* Empty object singleton used for empty XML elements.
*
* @internal
*/
declare const EMPTY_OBJECT: {};
/**
* Base class for all XML components in OOXML documents.
*/
declare abstract class XmlComponent extends BaseXmlComponent {
/**
* Array of child components, text nodes, and attributes.
*/
root: (BaseXmlComponent | IXmlableObject | string)[];
constructor(rootKey: string);
/**
* Prepares this component and its children for XML serialization.
*/
prepForXml(context: IContext): IXmlableObject | undefined;
/**
* Direct XML serialization. Override in subclasses for zero-allocation output.
* Default falls back to prepForXml() + xml().
*/
toXml(context: IContext): string;
/**
* @deprecated Internal use only.
*/
addChildElement(child: BaseXmlComponent | string): XmlComponent;
}
/**
* XML component that is excluded from output if it has no meaningful content.
*/
declare abstract class IgnoreIfEmptyXmlComponent extends XmlComponent {
private readonly includeIfEmpty;
constructor(rootKey: string, includeIfEmpty?: boolean);
prepForXml(context: IContext): IXmlableObject | undefined;
}
//#endregion
//#region src/xml-components/attributes.d.ts
/**
* Maps TypeScript property names to their XML attribute names.
*/
type AttributeMap<T> = Record<keyof T, string>;
/**
* Simple attribute data as a key-value record.
*/
type AttributeData = Record<string, boolean | number | string>;
/**
* Structured attribute payload with explicit key-value mapping.
*/
type AttributePayload<T> = { readonly [P in keyof T]: {
readonly key: string;
readonly value: T[P];
} };
/**
* Base class for creating XML attributes with automatic name mapping.
*/
declare abstract class XmlAttributeComponent<T extends Record<string, any>> extends BaseXmlComponent {
private readonly root;
/** Optional mapping from property names to XML attribute names. */
protected readonly xmlKeys?: AttributeMap<T>;
constructor(root: T);
prepForXml(_: IContext): IXmlableObject;
}
/**
* Next-generation attribute component with explicit key-value pairs.
*/
declare class NextAttributeComponent<T> extends BaseXmlComponent {
private readonly root;
constructor(root: AttributePayload<T>);
prepForXml(_: IContext): IXmlableObject;
}
//#endregion
//#region src/xml-components/elements.d.ts
/**
* Build a CT_OnOff XML object without allocating any XmlComponent.
* `val=true` returns a frozen singleton (cached per name).
*/
declare function onOffObj(name: string, val?: boolean | undefined): IXmlableObject;
/**
* Build a CT_HpsMeasure XML object (half-point size) without allocation.
*/
declare function hpsMeasureObj(name: string, val: number | PositiveUniversalMeasure): IXmlableObject;
/**
* Build a CT_String XML object (string value attribute) without allocation.
*/
declare function stringValObj(name: string, val: string): IXmlableObject;
/**
* Build a numeric value attribute XML object without allocation.
*/
declare function numberValObj(name: string, val: number): IXmlableObject;
/**
* Build a string enum value attribute XML object without allocation.
*/
declare function stringEnumValObj<T extends string>(name: string, val: T): IXmlableObject;
/**
* Build an element wrapping a text string without allocation.
*/
declare function stringContainerObj(name: string, val: string): IXmlableObject;
/**
* XML element representing a boolean on/off value (CT_OnOff).
* @deprecated Use `onOffObj()` for hot-path code.
*/
declare class OnOffElement extends XmlComponent {
constructor(name: string, val?: boolean | undefined);
}
/**
* XML element representing a half-point size measurement (CT_HpsMeasure).
* @deprecated Use `hpsMeasureObj()` for hot-path code.
*/
declare class HpsMeasureElement extends XmlComponent {
constructor(name: string, val: number | PositiveUniversalMeasure);
}
/**
* XML element representing an empty element (CT_Empty).
*/
declare class EmptyElement extends XmlComponent {}
/**
* XML element with a string value attribute (CT_String).
* @deprecated Use `stringValObj()` for hot-path code.
*/
declare class StringValueElement extends XmlComponent {
constructor(name: string, val: string);
}
/**
* XML element with a numeric value attribute.
* @deprecated Use `numberValObj()` for hot-path code.
*/
declare class NumberValueElement extends XmlComponent {
constructor(name: string, val: number);
}
/**
* XML element with a string enum value attribute.
* @deprecated Use `stringEnumValObj()` for hot-path code.
*/
declare class StringEnumValueElement<T extends string> extends XmlComponent {
constructor(name: string, val: T);
}
/**
* XML element containing text content.
* @deprecated Use `stringContainerObj()` for hot-path code.
*/
declare class StringContainer extends XmlComponent {
constructor(name: string, val: string);
}
/**
* Flexible XML element builder with explicit attribute and child configuration.
*/
declare class BuilderElement<T = {}> extends XmlComponent {
constructor({
name,
attributes,
children
}: {
readonly name: string;
readonly attributes?: AttributePayload<T>;
readonly children?: readonly (BaseXmlComponent | string)[];
});
}
/**
* Creates a NextAttributeComponent with explicit XML attribute keys.
*/
declare const chartAttr: (attrs: Record<string, string | number | boolean>) => BaseXmlComponent;
/**
* Wraps a component in a named XmlComponent element.
*/
declare function wrapEl(elementName: string, child: BaseXmlComponent): XmlComponent;
//#endregion
//#region src/xml-components/imported.d.ts
/**
* Converts an xml-js Element into an XmlComponent tree.
*/
declare const convertToXmlComponent: (element: Element) => ImportedXmlComponent | string | undefined;
/**
* XML component representing imported XML content.
*/
declare class ImportedXmlComponent extends XmlComponent {
protected _sourceXml?: string;
static fromXmlString(importedContent: string): ImportedXmlComponent;
get sourceXml(): string | undefined;
toXml(_context: IContext): string;
constructor(rootKey: string, _attr?: any);
push(xmlComponent: XmlComponent | string): void;
}
/**
* Represents attributes for imported root elements.
*/
declare class ImportedRootElementAttributes extends XmlComponent {
private readonly _attr;
constructor(_attr: any);
prepForXml(_: IContext): IXmlableObject;
}
//#endregion
//#region src/xml-components/initializable.d.ts
/**
* XML component that can be initialized from another component.
*/
declare abstract class InitializableXmlComponent extends XmlComponent {
constructor(rootKey: string, initComponent?: XmlComponent);
}
//#endregion
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 };
import { T as XmlComponent, p as chartAttr } from "./xml-components-CN6syVNr.mjs";
//#region src/smartart/categories.ts
/** Layout ID → OOXML category type */
const LAYOUT_CATEGORIES = {
default: "list",
list1: "list",
list2: "list",
vList2: "list",
hList1: "list",
pList1: "list",
process1: "process",
process2: "process",
process3: "process",
process4: "process",
chevron1: "process",
chevron2: "process",
arrow1: "process",
arrow2: "process",
cycle1: "cycle",
cycle2: "cycle",
cycle3: "cycle",
cycle4: "cycle",
cycle5: "cycle",
hierarchy1: "hier",
hierarchy2: "hier",
hierarchy3: "hier",
hierarchy4: "hier",
orgChart1: "hier",
pyramid1: "pyramid",
pyramid2: "pyramid",
pyramid3: "pyramid",
matrix1: "matrix",
matrix2: "matrix",
matrix3: "matrix",
radial1: "rel",
radial2: "rel",
radial3: "rel",
venn1: "rel",
funnel1: "rel",
balance1: "rel",
gear1: "rel",
constOrg1: "rel",
oppId1: "rel"
};
/** Style ID → OOXML category type */
const STYLE_CATEGORIES = {
simple1: "simple",
simple2: "simple",
simple3: "simple",
simple4: "simple",
simple5: "simple",
moderate1: "moderate",
moderate2: "moderate",
moderate3: "moderate",
moderate4: "moderate",
polished1: "polished",
polished2: "polished",
polished3: "polished",
polished4: "polished",
professional1: "professional",
professional2: "professional",
professional3: "professional",
professional4: "professional",
cartoon1: "cartoon",
cartoon2: "cartoon",
cartoon3: "cartoon",
cartoon4: "cartoon",
powdery1: "powdery",
powdery2: "powdery",
powdery3: "powdery",
powdery4: "powdery",
burnt1: "burnt",
burnt2: "burnt",
burnt3: "burnt",
burnt4: "burnt"
};
/** Color ID → OOXML category type */
const COLOR_CATEGORIES = {
accent1_2: "accent1",
accent2_2: "accent2",
accent3_2: "accent3",
accent4_2: "accent4",
accent5_2: "accent5",
accent6_2: "accent6",
colorful1: "colorful",
colorful2: "colorful",
colorful3: "colorful",
colorful4: "colorful",
dark1: "dark",
dark2: "dark",
primary1: "primary",
primary2: "primary",
gray1: "gray",
gray2: "gray"
};
//#endregion
//#region src/smartart/built-in-definitions.ts
const DGM_NS = "http://schemas.openxmlformats.org/drawingml/2006/diagram";
const XML_DECL = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
/** Full default list layout (urn:microsoft.com/office/officeart/2005/8/layout/default) */
const FULL_DEFAULT_LAYOUT_XML = "<dgm:layoutDef xmlns:dgm=\"" + DGM_NS + "\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" uniqueId=\"urn:microsoft.com/office/officeart/2005/8/layout/default\"><dgm:title val=\"\"/><dgm:desc val=\"\"/><dgm:catLst><dgm:cat type=\"list\" pri=\"400\"/></dgm:catLst><dgm:sampData><dgm:dataModel><dgm:ptLst><dgm:pt modelId=\"0\" type=\"doc\"/><dgm:pt modelId=\"1\"><dgm:prSet phldr=\"1\"/></dgm:pt><dgm:pt modelId=\"2\"><dgm:prSet phldr=\"1\"/></dgm:pt><dgm:pt modelId=\"3\"><dgm:prSet phldr=\"1\"/></dgm:pt><dgm:pt modelId=\"4\"><dgm:prSet phldr=\"1\"/></dgm:pt><dgm:pt modelId=\"5\"><dgm:prSet phldr=\"1\"/></dgm:pt></dgm:ptLst><dgm:cxnLst><dgm:cxn modelId=\"6\" srcId=\"0\" destId=\"1\" srcOrd=\"0\" destOrd=\"0\"/><dgm:cxn modelId=\"7\" srcId=\"0\" destId=\"2\" srcOrd=\"1\" destOrd=\"0\"/><dgm:cxn modelId=\"8\" srcId=\"0\" destId=\"3\" srcOrd=\"2\" destOrd=\"0\"/><dgm:cxn modelId=\"9\" srcId=\"0\" destId=\"4\" srcOrd=\"3\" destOrd=\"0\"/><dgm:cxn modelId=\"10\" srcId=\"0\" destId=\"5\" srcOrd=\"4\" destOrd=\"0\"/></dgm:cxnLst><dgm:bg/><dgm:whole/></dgm:dataModel></dgm:sampData><dgm:styleData><dgm:dataModel><dgm:ptLst><dgm:pt modelId=\"0\" type=\"doc\"/><dgm:pt modelId=\"1\"/><dgm:pt modelId=\"2\"/></dgm:ptLst><dgm:cxnLst><dgm:cxn modelId=\"3\" srcId=\"0\" destId=\"1\" srcOrd=\"0\" destOrd=\"0\"/><dgm:cxn modelId=\"4\" srcId=\"0\" destId=\"2\" srcOrd=\"1\" destOrd=\"0\"/></dgm:cxnLst><dgm:bg/><dgm:whole/></dgm:dataModel></dgm:styleData><dgm:clrData><dgm:dataModel><dgm:ptLst><dgm:pt modelId=\"0\" type=\"doc\"/><dgm:pt modelId=\"1\"/><dgm:pt modelId=\"2\"/><dgm:pt modelId=\"3\"/><dgm:pt modelId=\"4\"/><dgm:pt modelId=\"5\"/><dgm:pt modelId=\"6\"/></dgm:ptLst><dgm:cxnLst><dgm:cxn modelId=\"7\" srcId=\"0\" destId=\"1\" srcOrd=\"0\" destOrd=\"0\"/><dgm:cxn modelId=\"8\" srcId=\"0\" destId=\"2\" srcOrd=\"1\" destOrd=\"0\"/><dgm:cxn modelId=\"9\" srcId=\"0\" destId=\"3\" srcOrd=\"2\" destOrd=\"0\"/><dgm:cxn modelId=\"10\" srcId=\"0\" destId=\"4\" srcOrd=\"3\" destOrd=\"0\"/><dgm:cxn modelId=\"11\" srcId=\"0\" destId=\"5\" srcOrd=\"4\" destOrd=\"0\"/><dgm:cxn modelId=\"12\" srcId=\"0\" destId=\"6\" srcOrd=\"5\" destOrd=\"0\"/></dgm:cxnLst><dgm:bg/><dgm:whole/></dgm:dataModel></dgm:clrData><dgm:layoutNode name=\"diagram\"><dgm:varLst><dgm:dir/><dgm:resizeHandles val=\"exact\"/></dgm:varLst><dgm:choose name=\"Name0\"><dgm:if name=\"Name1\" func=\"var\" arg=\"dir\" op=\"equ\" val=\"norm\"><dgm:alg type=\"snake\"><dgm:param type=\"grDir\" val=\"tL\"/><dgm:param type=\"flowDir\" val=\"row\"/><dgm:param type=\"contDir\" val=\"sameDir\"/><dgm:param type=\"off\" val=\"ctr\"/></dgm:alg></dgm:if><dgm:else name=\"Name2\"><dgm:alg type=\"snake\"><dgm:param type=\"grDir\" val=\"tR\"/><dgm:param type=\"flowDir\" val=\"row\"/><dgm:param type=\"contDir\" val=\"sameDir\"/><dgm:param type=\"off\" val=\"ctr\"/></dgm:alg></dgm:else></dgm:choose><dgm:shape xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:blip=\"\"><dgm:adjLst/></dgm:shape><dgm:presOf/><dgm:constrLst><dgm:constr type=\"w\" for=\"ch\" forName=\"node\" refType=\"w\"/><dgm:constr type=\"h\" for=\"ch\" forName=\"node\" refType=\"w\" refFor=\"ch\" refForName=\"node\" fact=\"0.6\"/><dgm:constr type=\"w\" for=\"ch\" forName=\"sibTrans\" refType=\"w\" refFor=\"ch\" refForName=\"node\" fact=\"0.1\"/><dgm:constr type=\"sp\" refType=\"w\" refFor=\"ch\" refForName=\"sibTrans\"/><dgm:constr type=\"primFontSz\" for=\"ch\" forName=\"node\" op=\"equ\" val=\"65\"/></dgm:constrLst><dgm:ruleLst/><dgm:forEach name=\"Name3\" axis=\"ch\" ptType=\"node\"><dgm:layoutNode name=\"node\"><dgm:varLst><dgm:bulletEnabled val=\"1\"/></dgm:varLst><dgm:alg type=\"tx\"/><dgm:shape type=\"rect\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:blip=\"\"><dgm:adjLst/></dgm:shape><dgm:presOf axis=\"desOrSelf\" ptType=\"node\"/><dgm:constrLst><dgm:constr type=\"lMarg\" refType=\"primFontSz\" fact=\"0.3\"/><dgm:constr type=\"rMarg\" refType=\"primFontSz\" fact=\"0.3\"/><dgm:constr type=\"tMarg\" refType=\"primFontSz\" fact=\"0.3\"/><dgm:constr type=\"bMarg\" refType=\"primFontSz\" fact=\"0.3\"/></dgm:constrLst><dgm:ruleLst><dgm:rule type=\"primFontSz\" val=\"5\" fact=\"NaN\" max=\"NaN\"/></dgm:ruleLst></dgm:layoutNode><dgm:forEach name=\"Name4\" axis=\"followSib\" ptType=\"sibTrans\" cnt=\"1\"><dgm:layoutNode name=\"sibTrans\"><dgm:alg type=\"sp\"/><dgm:shape xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" r:blip=\"\"><dgm:adjLst/></dgm:shape><dgm:presOf/><dgm:constrLst/><dgm:ruleLst/></dgm:layoutNode></dgm:forEach></dgm:layoutNode></dgm:layoutDef>";
/**
* Returns layout XML. Full XML for "default", minimal stub for others.
* Stub has no layoutNode so PowerPoint falls back to built-in definitions
* based on the uniqueId / loTypeId in the data model.
*/
function getLayoutXml(layoutId) {
if (layoutId === "default") return XML_DECL + FULL_DEFAULT_LAYOUT_XML;
const cat = LAYOUT_CATEGORIES[layoutId] ?? "list";
return XML_DECL + "<dgm:layoutDef xmlns:dgm=\"http://schemas.openxmlformats.org/drawingml/2006/diagram\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" uniqueId=\"urn:microsoft.com/office/officeart/2005/8/layout/" + layoutId + "\"><dgm:title val=\"\"/><dgm:desc val=\"\"/><dgm:catLst><dgm:cat type=\"" + cat + "\" pri=\"400\"/></dgm:catLst><dgm:sampData><dgm:dataModel><dgm:ptLst><dgm:pt modelId=\"0\" type=\"doc\"/><dgm:pt modelId=\"1\"><dgm:prSet phldr=\"1\"/></dgm:pt><dgm:pt modelId=\"2\"><dgm:prSet phldr=\"1\"/></dgm:pt></dgm:ptLst><dgm:cxnLst><dgm:cxn modelId=\"3\" srcId=\"0\" destId=\"1\" srcOrd=\"0\" destOrd=\"0\"/><dgm:cxn modelId=\"4\" srcId=\"0\" destId=\"2\" srcOrd=\"1\" destOrd=\"0\"/></dgm:cxnLst><dgm:bg/><dgm:whole/></dgm:dataModel></dgm:sampData></dgm:layoutDef>";
}
/**
* Returns style stub XML with the given uniqueId.
*/
function getStyleXml(styleId) {
const cat = STYLE_CATEGORIES[styleId] ?? "simple";
return XML_DECL + "<dgm:styleDef xmlns:dgm=\"http://schemas.openxmlformats.org/drawingml/2006/diagram\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" uniqueId=\"urn:microsoft.com/office/officeart/2005/8/quickstyle/" + styleId + "\"><dgm:title val=\"\"/><dgm:desc val=\"\"/><dgm:catLst><dgm:cat type=\"" + cat + "\" pri=\"10100\"/></dgm:catLst><dgm:scene3d><a:camera prst=\"orthographicFront\"/><a:lightRig rig=\"threePt\" dir=\"t\"/></dgm:scene3d></dgm:styleDef>";
}
/**
* Returns color stub XML with the given uniqueId.
*/
function getColorXml(colorId) {
const cat = COLOR_CATEGORIES[colorId] ?? "accent1";
return XML_DECL + "<dgm:colorsDef xmlns:dgm=\"http://schemas.openxmlformats.org/drawingml/2006/diagram\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" uniqueId=\"urn:microsoft.com/office/officeart/2005/8/colors/" + colorId + "\"><dgm:title val=\"\"/><dgm:desc val=\"\"/><dgm:catLst><dgm:cat type=\"" + cat + "\" pri=\"11200\"/></dgm:catLst></dgm:colorsDef>";
}
/** Minimal drawing cache for SmartArt (Office apps auto-regenerate this on open) */
const DEFAULT_DRAWING_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><dsp:drawing xmlns:dgm=\"http://schemas.openxmlformats.org/drawingml/2006/diagram\" xmlns:dsp=\"http://schemas.microsoft.com/office/drawing/2008/diagram\" xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><dsp:spTree><dsp:nvGrpSpPr><dsp:cNvPr id=\"0\" name=\"\"/><dsp:cNvGrpSpPr/></dsp:nvGrpSpPr><dsp:grpSpPr/></dsp:spTree></dsp:drawing>";
//#endregion
//#region src/smartart/data-model/connection.ts
/**
* dgm:cxn — SmartArt data model connection (edge).
*/
var Connection = class extends XmlComponent {
constructor(modelId, srcId, destId, type, srcOrd = 0, destOrd = 0, parTransId, sibTransId) {
super("dgm:cxn");
const attrs = {
modelId,
srcId,
destId,
srcOrd,
destOrd
};
if (type) attrs.type = type;
if (parTransId) attrs.parTransId = parTransId;
if (sibTransId) attrs.sibTransId = sibTransId;
this.root.push(chartAttr(attrs));
}
};
//#endregion
//#region src/smartart/data-model/data-model.ts
/**
* CT_DataModel — the complete data model for a SmartArt diagram.
*/
var DataModel = class extends XmlComponent {
constructor(points, connections) {
super("dgm:dataModel");
this.root.push(chartAttr({
"xmlns:a": "http://schemas.openxmlformats.org/drawingml/2006/main",
"xmlns:dgm": "http://schemas.openxmlformats.org/drawingml/2006/diagram"
}));
const ptLst = new class extends XmlComponent {
constructor() {
super("dgm:ptLst");
}
}();
for (const pt of points) ptLst["root"].push(pt);
this.root.push(ptLst);
const cxnLst = new class extends XmlComponent {
constructor() {
super("dgm:cxnLst");
}
}();
for (const cxn of connections) cxnLst["root"].push(cxn);
this.root.push(cxnLst);
this.root.push(new EmptyElement$2("dgm:bg"));
this.root.push(new EmptyElement$2("dgm:whole"));
}
};
var EmptyElement$2 = class extends XmlComponent {
constructor(tag) {
super(tag);
}
};
//#endregion
//#region src/smartart/data-model/point.ts
/**
* dgm:pt — SmartArt data model point (node).
*/
var Point = class extends XmlComponent {
constructor(modelId, text, type = "node") {
super("dgm:pt");
this.root.push(chartAttr({
modelId,
type
}));
this.root.push(new PointText(text));
}
};
/**
* Transition point (parTrans or sibTrans) — no text body, references a connection.
*/
var TransPoint = class extends XmlComponent {
constructor(modelId, type, cxnId) {
super("dgm:pt");
this.root.push(chartAttr({
modelId,
type,
cxnId
}));
this.root.push(new EmptyElement$1("dgm:spPr"));
}
};
var EmptyElement$1 = class extends XmlComponent {
constructor(tag) {
super(tag);
}
};
/**
* dgm:t — text body within a point.
*/
var PointText = class extends XmlComponent {
constructor(text) {
super("dgm:t");
this.root.push(new EmptyElement$1("a:bodyPr"));
this.root.push(new EmptyElement$1("a:lstStyle"));
const p = new EmptyElement$1("a:p");
if (text) {
const t = new class extends XmlComponent {
constructor() {
super("a:t");
}
}();
t["root"].push(text);
const r = new class extends XmlComponent {
constructor() {
super("a:r");
}
}();
r["root"].push(t);
p["root"].push(r);
}
this.root.push(p);
}
};
//#endregion
//#region src/smartart/smartart-collection.ts
/**
* Manages SmartArt parts in a document.
*/
var SmartArtCollection = class {
map;
constructor() {
this.map = /* @__PURE__ */ new Map();
}
addSmartArt(key, data) {
this.map.set(key, data);
}
get Array() {
return [...this.map.values()];
}
};
//#endregion
//#region src/smartart/tree-to-model.ts
function createDocPoint(layout, style, color) {
const pt = new class extends XmlComponent {
constructor() {
super("dgm:pt");
}
}();
pt["root"].push(chartAttr({
modelId: 0,
type: "doc"
}));
const prSet = new class extends XmlComponent {
constructor() {
super("dgm:prSet");
}
}();
prSet["root"].push(chartAttr({
loTypeId: `urn:microsoft.com/office/officeart/2005/8/layout/${layout}`,
loCatId: LAYOUT_CATEGORIES[layout] ?? "list",
qsTypeId: `urn:microsoft.com/office/officeart/2005/8/quickstyle/${style}`,
qsCatId: STYLE_CATEGORIES[style] ?? "simple",
csTypeId: `urn:microsoft.com/office/officeart/2005/8/colors/${color}`,
csCatId: COLOR_CATEGORIES[color] ?? "accent1",
phldr: "0"
}));
pt["root"].push(prSet);
pt["root"].push(new EmptyElement("dgm:spPr"));
pt["root"].push(createEmptyTextBody());
return pt;
}
function createEmptyTextBody() {
const t = new class extends XmlComponent {
constructor() {
super("dgm:t");
}
}();
t["root"].push(new EmptyElement("a:bodyPr"));
t["root"].push(new EmptyElement("a:lstStyle"));
t["root"].push(new EmptyElement("a:p"));
return t;
}
var EmptyElement = class extends XmlComponent {
constructor(tag) {
super(tag);
}
};
function uuid() {
return `{${crypto.randomUUID().toUpperCase()}}`;
}
/**
* Creates a DataModel from tree nodes with layout/style/color settings.
*/
const createDataModel = (nodes, layout = "default", style = "simple1", color = "accent1_2") => {
const points = [];
const connections = [];
points.push(createDocPoint(layout, style, color));
for (let i = 0; i < nodes.length; i++) {
const walk = (node, parentUuid, srcOrd) => {
const nodeUuid = uuid();
const parTransUuid = uuid();
const sibTransUuid = uuid();
const cxnUuid = uuid();
points.push(new TransPoint(parTransUuid, "parTrans", cxnUuid));
points.push(new TransPoint(sibTransUuid, "sibTrans", cxnUuid));
points.push(new Point(nodeUuid, node.text));
connections.push(new Connection(parTransUuid, parentUuid, nodeUuid, void 0, srcOrd, 0, parTransUuid, sibTransUuid));
if (node.children) for (let j = 0; j < node.children.length; j++) walk(node.children[j], nodeUuid, j);
};
walk(nodes[i], "0", i);
}
return new DataModel(points, connections);
};
//#endregion
export { DataModel as a, getColorXml as c, COLOR_CATEGORIES as d, LAYOUT_CATEGORIES as f, TransPoint as i, getLayoutXml as l, SmartArtCollection as n, Connection as o, STYLE_CATEGORIES as p, Point as r, DEFAULT_DRAWING_XML as s, createDataModel as t, getStyleXml as u };
//#region src/values.d.ts
/**
* Runtime validation and type conversion functions for OOXML specification values.
*
* This module provides runtime checks and cleanup for value types in the OOXML spec
* that aren't easily expressed through the TypeScript type system alone. These
* validators help prevent silent failures and corrupted documents by enforcing
* spec-compliant values at runtime.
*
* @module
*/
/**
* A measurement value with optional sign and unit suffix.
*
* Supports units: mm (millimeters), cm (centimeters), in (inches),
* pt (points), pc (picas), pi (picas).
*
* Pattern: `-?[0-9]+(\.[0-9]+)?(mm|cm|in|pt|pc|pi)`
*
* @example
* ```typescript
* const measure: UniversalMeasure = "10.5mm";
* const negative: UniversalMeasure = "-5pt";
* ```
*/
type UniversalMeasure = `${"-" | ""}${number}${"mm" | "cm" | "in" | "pt" | "pc" | "pi"}`;
/**
* A positive measurement value with unit suffix.
*
* Same as UniversalMeasure but restricted to positive values only.
*
* Reference: ST_PositiveUniversalMeasure in OOXML specification
*
* @example
* ```typescript
* const measure: PositiveUniversalMeasure = "10.5mm";
* ```
*/
type PositiveUniversalMeasure = `${number}${"mm" | "cm" | "in" | "pt" | "pc" | "pi"}`;
/**
* A percentage value with optional sign.
*
* Pattern: `-?[0-9]+(\.[0-9]+)?%`
*
* Reference: ST_Percentage in OOXML specification
*
* @example
* ```typescript
* const percent: Percentage = "50%";
* const negative: Percentage = "-10.5%";
* ```
*/
type Percentage = `${"-" | ""}${number}%`;
/**
* A positive percentage value.
*
* Same as Percentage but restricted to positive values only.
*
* Reference: ST_PositivePercentage in OOXML specification
*
* @example
* ```typescript
* const percent: PositivePercentage = "50%";
* ```
*/
type PositivePercentage = `${number}%`;
/**
* A relative measurement value using em or ex units.
*
* Used in VML text boxes for font-relative measurements.
*
* @example
* ```typescript
* const measure: RelativeMeasure = "2em";
* const negative: RelativeMeasure = "-0.5ex";
* ```
*/
type RelativeMeasure = `${"-" | ""}${number}${"em" | "ex"}`;
/**
* Validates and converts a number to an integer (decimal number).
*
* Reference: ST_DecimalNumber in OOXML specification
*
* @param val - The number to validate and convert
* @returns The floored integer value
* @throws Error if the value is NaN
*
* @example
* ```typescript
* const num = decimalNumber(10.7); // Returns 10
* const negative = decimalNumber(-5.3); // Returns -5
* ```
*/
declare const decimalNumber: (val: number) => number;
/**
* Validates and converts a number to a positive integer (unsigned decimal number).
*
* Reference: ST_UnsignedDecimalNumber in OOXML specification
*
* @param val - The number to validate and convert
* @returns The floored positive integer value
* @throws Error if the value is NaN or negative
*
* @example
* ```typescript
* const num = unsignedDecimalNumber(10.7); // Returns 10
* const invalid = unsignedDecimalNumber(-5); // Throws Error
* ```
*/
declare const unsignedDecimalNumber: (val: number) => number;
/**
* Validates and normalizes a hexadecimal binary value.
*
* The xsd:hexBinary type represents binary data as a sequence of binary octets
* using hexadecimal encoding, where each binary octet is a two-character
* hexadecimal number. Both lowercase and uppercase letters A-F are permitted.
*
* @param val - The hexadecimal string to validate
* @param length - The expected length in bytes (not characters)
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid hex string of the expected length
*
* @example
* ```typescript
* hexBinary("0FB8", 2); // Valid: 2 bytes = 4 characters
* hexBinary("ABC", 2); // Invalid: wrong length
* ```
*/
declare const hexBinary: (val: string, length: number) => string;
/**
* Validates a long hexadecimal number (4 bytes / 8 characters).
*
* Reference: ST_LongHexNumber in OOXML specification
*
* @param val - The hexadecimal string to validate
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid 8-character hex string
*
* @example
* ```typescript
* const hex = longHexNumber("ABCD1234"); // Valid
* ```
*/
declare const longHexNumber: (val: string) => string;
/**
* Validates a short hexadecimal number (2 bytes / 4 characters).
*
* Reference: ST_ShortHexNumber in OOXML specification
*
* @param val - The hexadecimal string to validate
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid 4-character hex string
*
* @example
* ```typescript
* const hex = shortHexNumber("AB12"); // Valid
* ```
*/
declare const shortHexNumber: (val: string) => string;
/**
* Validates a single-byte hexadecimal number (1 byte / 2 characters).
*
* Reference: ST_UcharHexNumber in OOXML specification
*
* @param val - The hexadecimal string to validate
* @returns The validated hexadecimal string
* @throws Error if the value is not a valid 2-character hex string
*
* @example
* ```typescript
* const hex = uCharHexNumber("FF"); // Valid
* ```
*/
declare const uCharHexNumber: (val: string) => string;
/**
* Normalizes a universal measure value by parsing and reformatting.
*
* Ensures the numeric portion is properly formatted while preserving the unit.
*
* Reference: ST_UniversalMeasure in OOXML specification
*
* @param val - The universal measure string to normalize
* @returns The normalized universal measure
*
* @example
* ```typescript
* const measure = universalMeasureValue("10.500mm"); // Returns "10.5mm"
* ```
*/
declare const universalMeasureValue: (val: UniversalMeasure) => UniversalMeasure;
/**
* Validates and normalizes a positive universal measure value.
*
* Reference: ST_PositiveUniversalMeasure in OOXML specification
*
* @param val - The positive universal measure string to validate
* @returns The normalized positive universal measure
* @throws Error if the value is negative
*
* @example
* ```typescript
* const measure = positiveUniversalMeasureValue("10.5mm"); // Valid
* const invalid = positiveUniversalMeasureValue("-5mm"); // Throws Error
* ```
*/
declare const positiveUniversalMeasureValue: (val: PositiveUniversalMeasure) => PositiveUniversalMeasure;
/**
* Validates and normalizes a hexadecimal color value.
*
* Accepts either "auto" or a 6-character RGB hex value (with or without # prefix).
* The # prefix is commonly used but technically invalid in OOXML, so it is stripped
* for strict compliance.
*
* Reference: ST_HexColor in OOXML specification
*
* @param val - The color value to validate ("auto" or hex color)
* @returns The normalized color value
* @throws Error if the hex color is invalid
*
* @example
* ```typescript
* const color1 = hexColorValue("auto"); // Returns "auto"
* const color2 = hexColorValue("FF0000"); // Returns "FF0000"
* const color3 = hexColorValue("#00FF00"); // Returns "00FF00" (# stripped)
* ```
*/
declare const hexColorValue: (val: string) => string;
/**
* Validates a signed TWIP measurement value.
*
* Accepts either a universal measure string or a numeric TWIP value.
*
* Reference: ST_SignedTwipsMeasure in OOXML specification
*
* @param val - The measurement value (universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const measure1 = signedTwipsMeasureValue("10mm");
* const measure2 = signedTwipsMeasureValue(1440); // 1 inch in TWIP
* ```
*/
declare const signedTwipsMeasureValue: (val: UniversalMeasure | number) => UniversalMeasure | number;
/**
* Validates a half-point (HPS) measurement value.
*
* Accepts either a positive universal measure string or a positive number.
* HPS (half-points) are commonly used for font sizes.
*
* Reference: ST_HpsMeasure in OOXML specification
*
* @param val - The measurement value (positive universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const fontSize1 = hpsMeasureValue("12pt");
* const fontSize2 = hpsMeasureValue(24); // 12pt in half-points
* ```
*/
declare const hpsMeasureValue: (val: PositiveUniversalMeasure | number) => string | number;
/**
* Validates a signed half-point (HPS) measurement value.
*
* Accepts either a universal measure string or a numeric value.
*
* Reference: ST_SignedHpsMeasure in OOXML specification
*
* @param val - The measurement value (universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const spacing1 = signedHpsMeasureValue("6pt");
* const spacing2 = signedHpsMeasureValue(-12); // Negative spacing
* ```
*/
declare const signedHpsMeasureValue: (val: UniversalMeasure | number) => string | number;
/**
* Validates a positive TWIP measurement value.
*
* Accepts either a positive universal measure string or a positive number.
*
* Reference: ST_TwipsMeasure in OOXML specification
*
* @param val - The measurement value (positive universal measure or number)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const width1 = twipsMeasureValue("25.4mm");
* const width2 = twipsMeasureValue(1440); // 1 inch in TWIP
* ```
*/
declare const twipsMeasureValue: (val: PositiveUniversalMeasure | number) => PositiveUniversalMeasure | number;
/**
* Normalizes a percentage value by parsing and reformatting.
*
* Reference: ST_Percentage in OOXML specification
*
* @param val - The percentage string to normalize
* @returns The normalized percentage
*
* @example
* ```typescript
* const percent = percentageValue("50.000%"); // Returns "50%"
* ```
*/
declare const percentageValue: (val: Percentage) => Percentage;
/**
* Validates a measurement value that can be expressed as a number, percentage, or universal measure.
*
* Reference: ST_MeasurementOrPercent in OOXML specification
*
* @param val - The measurement value (number, percentage, or universal measure)
* @returns The normalized measurement value
*
* @example
* ```typescript
* const measure1 = measurementOrPercentValue(100); // Unqualified number
* const measure2 = measurementOrPercentValue("50%"); // Percentage
* const measure3 = measurementOrPercentValue("10mm"); // Universal measure
* ```
*/
declare const measurementOrPercentValue: (val: number | Percentage | UniversalMeasure) => number | UniversalMeasure | Percentage;
/**
* Validates an eighth-point measurement value.
*
* Eighth-points are used for fine-grained measurements in text formatting.
*
* Reference: ST_EighthPointMeasure in OOXML specification
*
* @param val - The measurement value in eighth-points
* @returns The validated positive integer value
*
* @example
* ```typescript
* const measure = eighthPointMeasureValue(16); // 2 points
* ```
*/
declare const eighthPointMeasureValue: (val: number) => number;
/**
* Validates a point measurement value.
*
* Reference: ST_PointMeasure in OOXML specification
*
* @param val - The measurement value in points
* @returns The validated positive integer value
*
* @example
* ```typescript
* const fontSize = pointMeasureValue(12); // 12pt
* ```
*/
declare const pointMeasureValue: (val: number) => number;
/**
* Converts a JavaScript Date object to an ISO 8601 date-time string.
*
* The format is CCYY-MM-DDThh:mm:ss.sssZ where T is a literal and Z indicates UTC.
* This matches the xsd:dateTime format required by OOXML.
*
* Reference: ST_DateTime in OOXML specification
*
* @param val - The Date object to convert
* @returns An ISO 8601 formatted date-time string
*
* @example
* ```typescript
* const now = new Date();
* const timestamp = dateTimeValue(now); // Returns "2024-01-15T10:30:00.000Z"
* ```
*/
declare const dateTimeValue: (val: Date) => string;
/**
* Theme color values used throughout OOXML for referencing document theme colors.
*
* Reference: ST_ThemeColor in OOXML specification
*
* @publicApi
*/
declare const ThemeColor: {
readonly DARK1: "dark1";
readonly LIGHT1: "light1";
readonly DARK2: "dark2";
readonly LIGHT2: "light2";
readonly ACCENT1: "accent1";
readonly ACCENT2: "accent2";
readonly ACCENT3: "accent3";
readonly ACCENT4: "accent4";
readonly ACCENT5: "accent5";
readonly ACCENT6: "accent6";
readonly HYPERLINK: "hyperlink";
readonly FOLLOWED_HYPERLINK: "followedHyperlink";
readonly NONE: "none";
readonly BACKGROUND1: "background1";
readonly TEXT1: "text1";
readonly BACKGROUND2: "background2";
readonly TEXT2: "text2";
};
/**
* Theme font values used for referencing document theme fonts.
*
* Reference: ST_Theme in OOXML specification
*
* @publicApi
*/
declare const ThemeFont: {
readonly MAJOR_EAST_ASIA: "majorEastAsia";
readonly MAJOR_BIDI: "majorBidi";
readonly MAJOR_ASCII: "majorAscii";
readonly MAJOR_H_ANSI: "majorHAnsi";
readonly MINOR_EAST_ASIA: "minorEastAsia";
readonly MINOR_BIDI: "minorBidi";
readonly MINOR_ASCII: "minorAscii";
readonly MINOR_H_ANSI: "minorHAnsi";
};
//#endregion
export { uCharHexNumber as C, twipsMeasureValue as S, unsignedDecimalNumber as T, pointMeasureValue as _, ThemeColor as a, signedHpsMeasureValue as b, dateTimeValue as c, hexBinary as d, hexColorValue as f, percentageValue as g, measurementOrPercentValue as h, RelativeMeasure as i, decimalNumber as l, longHexNumber as m, PositivePercentage as n, ThemeFont as o, hpsMeasureValue as p, PositiveUniversalMeasure as r, UniversalMeasure as s, Percentage as t, eighthPointMeasureValue as u, positiveUniversalMeasureValue as v, universalMeasureValue as w, signedTwipsMeasureValue as x, shortHexNumber as y };
import { hpsMeasureValue } from "../values.mjs";
import { xml, xml2js } from "@office-open/xml";
//#region src/xml-components/base.ts
/**
* Abstract base class for all XML components.
*/
var BaseXmlComponent = class {
/** The XML element name for this component (e.g., "w:p" for paragraph). */
rootKey;
constructor(rootKey) {
this.rootKey = rootKey;
}
};
//#endregion
//#region src/xml-components/component.ts
/**
* Core XML Component classes for building OOXML element trees.
*
* @module
*/
/**
* Empty object singleton used for empty XML elements.
*
* @internal
*/
const EMPTY_OBJECT = Object.seal({});
/**
* Base class for all XML components in OOXML documents.
*/
var XmlComponent = class extends BaseXmlComponent {
/**
* Array of child components, text nodes, and attributes.
*/
root;
constructor(rootKey) {
super(rootKey);
this.root = new Array();
}
/**
* Prepares this component and its children for XML serialization.
*/
prepForXml(context) {
context.stack.push(this);
const children = [];
for (const comp of this.root) if (comp instanceof BaseXmlComponent) {
const prepared = comp.prepForXml(context);
if (prepared !== void 0) children.push(prepared);
} else children.push(comp);
context.stack.pop();
return { [this.rootKey]: children.length ? children.length === 1 && children[0] && typeof children[0] === "object" && "_attr" in children[0] ? children[0] : children : EMPTY_OBJECT };
}
/**
* Direct XML serialization. Override in subclasses for zero-allocation output.
* Default falls back to prepForXml() + xml().
*/
toXml(context) {
const obj = this.prepForXml(context);
return obj ? xml(obj) : "";
}
/**
* @deprecated Internal use only.
*/
addChildElement(child) {
this.root.push(child);
return this;
}
};
/**
* XML component that is excluded from output if it has no meaningful content.
*/
var IgnoreIfEmptyXmlComponent = class extends XmlComponent {
includeIfEmpty;
constructor(rootKey, includeIfEmpty) {
super(rootKey);
this.includeIfEmpty = includeIfEmpty;
}
prepForXml(context) {
const result = super.prepForXml(context);
if (this.includeIfEmpty) return result;
if (result && (typeof result[this.rootKey] !== "object" || Object.keys(result[this.rootKey]).length)) return result;
}
};
//#endregion
//#region src/xml-components/attributes.ts
/**
* XML attribute components for OOXML document generation.
*
* @module
*/
/**
* Base class for creating XML attributes with automatic name mapping.
*/
var XmlAttributeComponent = class extends BaseXmlComponent {
/** Optional mapping from property names to XML attribute names. */
xmlKeys;
constructor(root) {
super("_attr");
this.root = root;
}
prepForXml(_) {
const attrs = {};
Object.entries(this.root).forEach(([key, value]) => {
if (value !== void 0) {
const newKey = this.xmlKeys && this.xmlKeys[key] || key;
attrs[newKey] = value;
}
});
return { _attr: attrs };
}
};
/**
* Next-generation attribute component with explicit key-value pairs.
*/
var NextAttributeComponent = class extends BaseXmlComponent {
constructor(root) {
super("_attr");
this.root = root;
}
prepForXml(_) {
return { _attr: Object.values(this.root).filter(({ value }) => value !== void 0).reduce((acc, { key, value }) => ({
...acc,
[key]: value
}), {}) };
}
};
//#endregion
//#region src/xml-components/elements.ts
/**
* Simple XML element types for common OOXML patterns.
*
* @module
*/
const ON_OFF_TRUE_CACHE = /* @__PURE__ */ new Map();
/**
* Build a CT_OnOff XML object without allocating any XmlComponent.
* `val=true` returns a frozen singleton (cached per name).
*/
function onOffObj(name, val = true) {
if (val === true) {
let cached = ON_OFF_TRUE_CACHE.get(name);
if (!cached) {
cached = Object.freeze({ [name]: Object.freeze({}) });
ON_OFF_TRUE_CACHE.set(name, cached);
}
return cached;
}
const ns = name.split(":")[0];
return { [name]: { _attr: { [`${ns}:val`]: val } } };
}
/**
* Build a CT_HpsMeasure XML object (half-point size) without allocation.
*/
function hpsMeasureObj(name, val) {
const ns = name.split(":")[0];
return { [name]: { _attr: { [`${ns}:val`]: hpsMeasureValue(val) } } };
}
/**
* Build a CT_String XML object (string value attribute) without allocation.
*/
function stringValObj(name, val) {
const ns = name.split(":")[0];
return { [name]: { _attr: { [`${ns}:val`]: val } } };
}
/**
* Build a numeric value attribute XML object without allocation.
*/
function numberValObj(name, val) {
const ns = name.split(":")[0];
return { [name]: { _attr: { [`${ns}:val`]: val } } };
}
/**
* Build a string enum value attribute XML object without allocation.
*/
function stringEnumValObj(name, val) {
const ns = name.split(":")[0];
return { [name]: { _attr: { [`${ns}:val`]: val } } };
}
/**
* Build an element wrapping a text string without allocation.
*/
function stringContainerObj(name, val) {
return { [name]: [val] };
}
/**
* XML element representing a boolean on/off value (CT_OnOff).
* @deprecated Use `onOffObj()` for hot-path code.
*/
var OnOffElement = class extends XmlComponent {
constructor(name, val = true) {
super(name);
if (val !== true) this.root.push(new NextAttributeComponent({ val: {
key: `${name.split(":")[0]}:val`,
value: val
} }));
}
};
/**
* XML element representing a half-point size measurement (CT_HpsMeasure).
* @deprecated Use `hpsMeasureObj()` for hot-path code.
*/
var HpsMeasureElement = class extends XmlComponent {
constructor(name, val) {
super(name);
const ns = name.split(":")[0];
this.root.push(new NextAttributeComponent({ val: {
key: `${ns}:val`,
value: hpsMeasureValue(val)
} }));
}
};
/**
* XML element representing an empty element (CT_Empty).
*/
var EmptyElement = class extends XmlComponent {};
/**
* XML element with a string value attribute (CT_String).
* @deprecated Use `stringValObj()` for hot-path code.
*/
var StringValueElement = class extends XmlComponent {
constructor(name, val) {
super(name);
const ns = name.split(":")[0];
this.root.push(new NextAttributeComponent({ val: {
key: `${ns}:val`,
value: val
} }));
}
};
/**
* XML element with a numeric value attribute.
* @deprecated Use `numberValObj()` for hot-path code.
*/
var NumberValueElement = class extends XmlComponent {
constructor(name, val) {
super(name);
const ns = name.split(":")[0];
this.root.push(new NextAttributeComponent({ val: {
key: `${ns}:val`,
value: val
} }));
}
};
/**
* XML element with a string enum value attribute.
* @deprecated Use `stringEnumValObj()` for hot-path code.
*/
var StringEnumValueElement = class extends XmlComponent {
constructor(name, val) {
super(name);
const ns = name.split(":")[0];
this.root.push(new NextAttributeComponent({ val: {
key: `${ns}:val`,
value: val
} }));
}
};
/**
* XML element containing text content.
* @deprecated Use `stringContainerObj()` for hot-path code.
*/
var StringContainer = class extends XmlComponent {
constructor(name, val) {
super(name);
this.root.push(val);
}
};
/**
* Flexible XML element builder with explicit attribute and child configuration.
*/
var BuilderElement = class extends XmlComponent {
constructor({ name, attributes, children }) {
super(name);
if (attributes) this.root.push(new NextAttributeComponent(attributes));
if (children) this.root.push(...children);
}
};
/**
* Creates a NextAttributeComponent with explicit XML attribute keys.
*/
const chartAttr = (attrs) => new NextAttributeComponent(Object.fromEntries(Object.entries(attrs).map(([key, value]) => [key, {
key,
value
}])));
/**
* Wraps a component in a named XmlComponent element.
*/
function wrapEl(elementName, child) {
const el = new class extends XmlComponent {
constructor(name) {
super(name);
}
}(elementName);
el["root"].push(child);
return el;
}
//#endregion
//#region src/xml-components/imported.ts
/**
* Imported XML Component module for handling external XML content.
*
* @module
*/
/**
* Converts an xml-js Element into an XmlComponent tree.
*/
const convertToXmlComponent = (element) => {
switch (element.type) {
case void 0:
case "element": {
const xmlComponent = new ImportedXmlComponent(element.name, element.attributes);
const childElements = element.elements || [];
for (const childElm of childElements) {
const child = convertToXmlComponent(childElm);
if (child !== void 0) xmlComponent.push(child);
}
return xmlComponent;
}
case "text": return element.text;
default: return;
}
};
/**
* Internal attribute component for imported XML elements.
* @internal
*/
var ImportedXmlComponentAttributes = class extends XmlAttributeComponent {};
/**
* XML component representing imported XML content.
*/
var ImportedXmlComponent = class extends XmlComponent {
_sourceXml;
static fromXmlString(importedContent) {
const xmlObj = xml2js(importedContent, { compact: false });
const component = convertToXmlComponent(xmlObj.elements?.[0] ?? xmlObj);
component._sourceXml = importedContent;
return component;
}
get sourceXml() {
return this._sourceXml;
}
toXml(_context) {
return this._sourceXml ?? super.toXml(_context);
}
constructor(rootKey, _attr) {
super(rootKey);
if (_attr) this.root.push(new ImportedXmlComponentAttributes(_attr));
}
push(xmlComponent) {
this.root.push(xmlComponent);
}
};
/**
* Represents attributes for imported root elements.
*/
var ImportedRootElementAttributes = class extends XmlComponent {
constructor(_attr) {
super("");
this._attr = _attr;
}
prepForXml(_) {
return { _attr: this._attr };
}
};
//#endregion
//#region src/xml-components/initializable.ts
/**
* Initializable XML Component module.
*
* @module
*/
/**
* XML component that can be initialized from another component.
*/
var InitializableXmlComponent = class extends XmlComponent {
constructor(rootKey, initComponent) {
super(rootKey);
if (initComponent instanceof XmlComponent) this.root = initComponent.root;
}
};
//#endregion
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 };

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display