@office-open/core 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{index-3uVYzs32.d.mts → index-BV1I7g5r.d.mts} +8 -0
- package/dist/_chunks/{xml-components-DazgCiyL.mjs → xml-components-CN6syVNr.mjs} +19 -2
- package/dist/chart/index.d.mts +1 -1
- package/dist/chart/index.mjs +1 -1
- package/dist/drawingml/index.d.mts +1 -1
- package/dist/drawingml/index.mjs +1 -1
- package/dist/index.d.mts +58 -3
- package/dist/index.mjs +117 -13
- package/dist/smartart/index.d.mts +1 -1
- package/dist/smartart/index.mjs +1 -1
- package/package.json +2 -2
|
@@ -64,6 +64,11 @@ declare abstract class XmlComponent extends BaseXmlComponent {
|
|
|
64
64
|
* Prepares this component and its children for XML serialization.
|
|
65
65
|
*/
|
|
66
66
|
prepForXml(context: IContext): IXmlableObject | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Direct XML serialization. Override in subclasses for zero-allocation output.
|
|
69
|
+
* Default falls back to prepForXml() + xml().
|
|
70
|
+
*/
|
|
71
|
+
toXml(context: IContext): string;
|
|
67
72
|
/**
|
|
68
73
|
* @deprecated Internal use only.
|
|
69
74
|
*/
|
|
@@ -217,7 +222,10 @@ declare const convertToXmlComponent: (element: Element) => ImportedXmlComponent
|
|
|
217
222
|
* XML component representing imported XML content.
|
|
218
223
|
*/
|
|
219
224
|
declare class ImportedXmlComponent extends XmlComponent {
|
|
225
|
+
protected _sourceXml?: string;
|
|
220
226
|
static fromXmlString(importedContent: string): ImportedXmlComponent;
|
|
227
|
+
get sourceXml(): string | undefined;
|
|
228
|
+
toXml(_context: IContext): string;
|
|
221
229
|
constructor(rootKey: string, _attr?: any);
|
|
222
230
|
push(xmlComponent: XmlComponent | string): void;
|
|
223
231
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { hpsMeasureValue } from "../values.mjs";
|
|
2
|
-
import { xml2js } from "@office-open/xml";
|
|
2
|
+
import { xml, xml2js } from "@office-open/xml";
|
|
3
3
|
//#region src/xml-components/base.ts
|
|
4
4
|
/**
|
|
5
5
|
* Abstract base class for all XML components.
|
|
@@ -50,6 +50,14 @@ var XmlComponent = class extends BaseXmlComponent {
|
|
|
50
50
|
return { [this.rootKey]: children.length ? children.length === 1 && children[0] && typeof children[0] === "object" && "_attr" in children[0] ? children[0] : children : EMPTY_OBJECT };
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
+
* Direct XML serialization. Override in subclasses for zero-allocation output.
|
|
54
|
+
* Default falls back to prepForXml() + xml().
|
|
55
|
+
*/
|
|
56
|
+
toXml(context) {
|
|
57
|
+
const obj = this.prepForXml(context);
|
|
58
|
+
return obj ? xml(obj) : "";
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
53
61
|
* @deprecated Internal use only.
|
|
54
62
|
*/
|
|
55
63
|
addChildElement(child) {
|
|
@@ -320,9 +328,18 @@ var ImportedXmlComponentAttributes = class extends XmlAttributeComponent {};
|
|
|
320
328
|
* XML component representing imported XML content.
|
|
321
329
|
*/
|
|
322
330
|
var ImportedXmlComponent = class extends XmlComponent {
|
|
331
|
+
_sourceXml;
|
|
323
332
|
static fromXmlString(importedContent) {
|
|
324
333
|
const xmlObj = xml2js(importedContent, { compact: false });
|
|
325
|
-
|
|
334
|
+
const component = convertToXmlComponent(xmlObj.elements?.[0] ?? xmlObj);
|
|
335
|
+
component._sourceXml = importedContent;
|
|
336
|
+
return component;
|
|
337
|
+
}
|
|
338
|
+
get sourceXml() {
|
|
339
|
+
return this._sourceXml;
|
|
340
|
+
}
|
|
341
|
+
toXml(_context) {
|
|
342
|
+
return this._sourceXml ?? super.toXml(_context);
|
|
326
343
|
}
|
|
327
344
|
constructor(rootKey, _attr) {
|
|
328
345
|
super(rootKey);
|
package/dist/chart/index.d.mts
CHANGED
package/dist/chart/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as XmlComponent, b as wrapEl, o as EmptyElement, p as chartAttr } from "../_chunks/xml-components-
|
|
1
|
+
import { T as XmlComponent, b as wrapEl, o as EmptyElement, p as chartAttr } from "../_chunks/xml-components-CN6syVNr.mjs";
|
|
2
2
|
//#region src/chart/chart-collection.ts
|
|
3
3
|
var ChartCollection = class {
|
|
4
4
|
map;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as XmlComponent, T as XmlAttributeComponent, a as BuilderElement } from "../_chunks/index-
|
|
1
|
+
import { O as XmlComponent, T as XmlAttributeComponent, a as BuilderElement } from "../_chunks/index-BV1I7g5r.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/drawingml/color/color-transform.d.ts
|
|
4
4
|
/**
|
package/dist/drawingml/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as XmlAttributeComponent, T as XmlComponent, a as BuilderElement } from "../_chunks/xml-components-
|
|
1
|
+
import { S as XmlAttributeComponent, T as XmlComponent, a as BuilderElement } from "../_chunks/xml-components-CN6syVNr.mjs";
|
|
2
2
|
import { d as convertPixelsToEmu, t as hashedId } from "../_chunks/id-generators-Ch07cHW1.mjs";
|
|
3
3
|
//#region src/drawingml/color/color-transform.ts
|
|
4
4
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Relationship, elementToXml, findRel, findRelsByType, getImageType, listFiles, parseRels, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, uint8ToBase64, unzipToMap, zipToBuffer } from "./archive.mjs";
|
|
2
|
-
import { A as IContext, C as AttributePayload, D as IgnoreIfEmptyXmlComponent, E as EMPTY_OBJECT, M as IXmlableObject, O as XmlComponent, S as AttributeMap, T as XmlAttributeComponent, _ as stringContainerObj, a as BuilderElement, b as wrapEl, c as NumberValueElement, d as StringEnumValueElement, f as StringValueElement, g as onOffObj, h as numberValObj, i as convertToXmlComponent, j as IXmlAttribute, k as BaseXmlComponent, l as OnOffElement, m as hpsMeasureObj, n as ImportedRootElementAttributes, o as EmptyElement, p as chartAttr, r as ImportedXmlComponent, s as HpsMeasureElement, t as InitializableXmlComponent, u as StringContainer, v as stringEnumValObj, w as NextAttributeComponent, x as AttributeData, y as stringValObj } from "./_chunks/index-
|
|
2
|
+
import { A as IContext, C as AttributePayload, D as IgnoreIfEmptyXmlComponent, E as EMPTY_OBJECT, M as IXmlableObject, O as XmlComponent, S as AttributeMap, T as XmlAttributeComponent, _ as stringContainerObj, a as BuilderElement, b as wrapEl, c as NumberValueElement, d as StringEnumValueElement, f as StringValueElement, g as onOffObj, h as numberValObj, i as convertToXmlComponent, j as IXmlAttribute, k as BaseXmlComponent, l as OnOffElement, m as hpsMeasureObj, n as ImportedRootElementAttributes, o as EmptyElement, p as chartAttr, r as ImportedXmlComponent, s as HpsMeasureElement, t as InitializableXmlComponent, u as StringContainer, v as stringEnumValObj, w as NextAttributeComponent, x as AttributeData, y as stringValObj } from "./_chunks/index-BV1I7g5r.mjs";
|
|
3
3
|
import { C as universalMeasureValue, S as uCharHexNumber, _ as positiveUniversalMeasureValue, a as ThemeColor, b as signedTwipsMeasureValue, c as dateTimeValue, d as hexColorValue, f as hpsMeasureValue, g as pointMeasureValue, h as percentageValue, i as RelativeMeasure, l as decimalNumber, m as measurementOrPercentValue, n as PositivePercentage, o as ThemeFont, p as longHexNumber, r as PositiveUniversalMeasure, s as UniversalMeasure, t as Percentage, u as eighthPointMeasureValue, v as shortHexNumber, w as unsignedDecimalNumber, x as twipsMeasureValue, y as signedHpsMeasureValue } from "./_chunks/values-BrGywpRh.mjs";
|
|
4
4
|
import { COLOR_CATEGORIES, Connection, DataModel, ISmartArtData, ITreeNode, LAYOUT_CATEGORIES, Point, STYLE_CATEGORIES, SmartArtCollection, TransPoint, createDataModel } from "./smartart/index.mjs";
|
|
5
5
|
import { Element } from "@office-open/xml";
|
|
@@ -83,10 +83,35 @@ interface OutputByType {
|
|
|
83
83
|
readonly nodebuffer: Buffer;
|
|
84
84
|
}
|
|
85
85
|
type OutputType = keyof OutputByType;
|
|
86
|
+
declare const OoxmlMimeType: {
|
|
87
|
+
readonly DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
88
|
+
readonly PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
89
|
+
};
|
|
90
|
+
declare const convertOutput: <T extends OutputType>(data: Uint8Array, type: T, mimeType?: string) => OutputByType[T];
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/packer.d.ts
|
|
93
|
+
/**
|
|
94
|
+
* Shared packer utilities for OOXML document generation.
|
|
95
|
+
*
|
|
96
|
+
* @module
|
|
97
|
+
*/
|
|
98
|
+
interface IXmlifyedFile {
|
|
99
|
+
readonly path: string;
|
|
100
|
+
readonly data: string | Uint8Array;
|
|
101
|
+
}
|
|
102
|
+
declare const PrettifyType: {
|
|
103
|
+
readonly NONE: "";
|
|
104
|
+
readonly WITH_2_BLANKS: " ";
|
|
105
|
+
readonly WITH_4_BLANKS: " ";
|
|
106
|
+
readonly WITH_TAB: "\t";
|
|
107
|
+
};
|
|
108
|
+
declare const convertPrettifyType: (prettify?: boolean | (typeof PrettifyType)[keyof typeof PrettifyType]) => (typeof PrettifyType)[keyof typeof PrettifyType] | undefined;
|
|
86
109
|
//#endregion
|
|
87
110
|
//#region src/opc/app-properties.d.ts
|
|
88
|
-
declare class AppProperties extends
|
|
111
|
+
declare class AppProperties extends ImportedXmlComponent {
|
|
112
|
+
private static instance;
|
|
89
113
|
constructor();
|
|
114
|
+
prepForXml(): Readonly<Record<string, any>> | undefined;
|
|
90
115
|
}
|
|
91
116
|
//#endregion
|
|
92
117
|
//#region src/opc/relationships.d.ts
|
|
@@ -108,6 +133,7 @@ declare class Relationships extends BaseXmlComponent {
|
|
|
108
133
|
*/
|
|
109
134
|
declare class Formatter {
|
|
110
135
|
format<T extends IContext = IContext>(input: BaseXmlComponent, context?: T): IXmlableObject;
|
|
136
|
+
formatToXml(input: XmlComponent, context: IContext, declaration?: boolean): string;
|
|
111
137
|
}
|
|
112
138
|
//#endregion
|
|
113
139
|
//#region src/core-properties.d.ts
|
|
@@ -153,4 +179,33 @@ declare class RawPassthrough extends BaseXmlComponent {
|
|
|
153
179
|
prepForXml(_context: IContext): IXmlableObject;
|
|
154
180
|
}
|
|
155
181
|
//#endregion
|
|
156
|
-
|
|
182
|
+
//#region src/placeholder.d.ts
|
|
183
|
+
/**
|
|
184
|
+
* Placeholder detection and replacement utilities for compiler post-processing.
|
|
185
|
+
*
|
|
186
|
+
* Both DOCX and PPTX compilers use placeholder tokens (e.g. `{chart:key}`)
|
|
187
|
+
* in XML strings to defer relationship ID assignment. This module provides
|
|
188
|
+
* fast pre-check utilities and shared replacement functions.
|
|
189
|
+
*/
|
|
190
|
+
type IdFormat = "rId" | "plain";
|
|
191
|
+
declare const formatId: (offset: number, index: number, style: IdFormat) => string;
|
|
192
|
+
declare function escapeRegex(str: string): string;
|
|
193
|
+
declare function hasPlaceholders(xml: string): boolean;
|
|
194
|
+
declare function collectPlaceholderKeys(xml: string, prefix: string): string[];
|
|
195
|
+
declare function replaceImagePlaceholders(xml: string, mediaData: readonly {
|
|
196
|
+
readonly fileName: string;
|
|
197
|
+
}[], offset: number, idFormat?: IdFormat): string;
|
|
198
|
+
declare function getReferencedMedia(xml: string, mediaArray: readonly {
|
|
199
|
+
readonly fileName: string;
|
|
200
|
+
}[]): readonly {
|
|
201
|
+
readonly fileName: string;
|
|
202
|
+
}[];
|
|
203
|
+
declare function replaceChartPlaceholders(xml: string, chartKeys: readonly string[], offset: number, idFormat?: IdFormat): string;
|
|
204
|
+
interface SmartArtRelOptions {
|
|
205
|
+
readonly pathPrefix: string;
|
|
206
|
+
readonly styleRelType: RelationshipType;
|
|
207
|
+
}
|
|
208
|
+
declare function replaceSmartArtPlaceholders(xml: string, keys: readonly string[], dataOffset: number, idFormat?: IdFormat): string;
|
|
209
|
+
declare function addSmartArtRelationships(keys: readonly string[], addRel: (id: number, type: RelationshipType, target: string, targetMode?: string) => void, baseOffset: number, globalStartIndex: number, options: SmartArtRelOptions): void;
|
|
210
|
+
//#endregion
|
|
211
|
+
export { AppProperties, AttributeData, AttributeMap, AttributePayload, BaseXmlComponent, BuilderElement, COLOR_CATEGORIES, Connection, CoreProperties, DataModel, EMPTY_OBJECT, EmptyElement, Formatter, HpsMeasureElement, IContext, ISmartArtData, ITreeNode, IXmlAttribute, IXmlableObject, IXmlifyedFile, IdFormat, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, LAYOUT_CATEGORIES, MixedChildren, NextAttributeComponent, NumberValueElement, OnOffElement, OoxmlMimeType, OutputByType, OutputType, Percentage, Point, PositivePercentage, PositiveUniversalMeasure, PrettifyType, RawElement, RawPassthrough, Relationship, type RelationshipType, Relationships, RelativeMeasure, STYLE_CATEGORIES, SmartArtCollection, SmartArtRelOptions, StringContainer, StringEnumValueElement, StringValueElement, TargetModeType, ThemeColor, ThemeFont, TransPoint, UniqueNumericIdCreator, UniversalMeasure, XmlAttributeComponent, XmlComponent, addSmartArtRelationships, chartAttr, collectPlaceholderKeys, convertEmuToInches, convertEmuToPixels, convertEmuToPoints, convertInchesToEmu, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertPixelsToEmu, convertPointsToEmu, convertPrettifyType, convertToXmlComponent, createDataModel, dateTimeValue, decimalNumber, eighthPointMeasureValue, elementToXml, escapeRegex, findRel, findRelsByType, formatId, getImageType, getReferencedMedia, hasPlaceholders, hashedId, hexColorValue, hpsMeasureObj, hpsMeasureValue, isRaw, listFiles, longHexNumber, measurementOrPercentValue, numberValObj, onOffObj, parseCoreProperties, 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 };
|
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,53 @@
|
|
|
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-
|
|
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";
|
|
2
2
|
import { ThemeColor, ThemeFont, dateTimeValue, decimalNumber, eighthPointMeasureValue, hexColorValue, hpsMeasureValue, longHexNumber, measurementOrPercentValue, percentageValue, pointMeasureValue, positiveUniversalMeasureValue, shortHexNumber, signedHpsMeasureValue, signedTwipsMeasureValue, twipsMeasureValue, uCharHexNumber, universalMeasureValue, unsignedDecimalNumber } from "./values.mjs";
|
|
3
3
|
import { a as convertEmuToInches, c as convertInchesToEmu, d as convertPixelsToEmu, f as convertPointsToEmu, i as uniqueUuid, l as convertInchesToTwip, n as uniqueId, o as convertEmuToPixels, r as uniqueNumericIdCreator, s as convertEmuToPoints, t as hashedId, u as convertMillimetersToTwip } from "./_chunks/id-generators-Ch07cHW1.mjs";
|
|
4
4
|
import { COLOR_CATEGORIES, Connection, DataModel, LAYOUT_CATEGORIES, Point, STYLE_CATEGORIES, SmartArtCollection, TransPoint, createDataModel } from "./smartart/index.mjs";
|
|
5
5
|
import { elementToXml, findRel, findRelsByType, getImageType, listFiles, parseRels, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, uint8ToBase64, unzipToMap, zipToBuffer } from "./archive.mjs";
|
|
6
6
|
import { textOf } from "@office-open/xml";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
import { strFromU8 } from "fflate";
|
|
8
|
+
//#region src/output-type.ts
|
|
9
|
+
/**
|
|
10
|
+
* Output type definitions for OOXML document export.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
const OoxmlMimeType = {
|
|
15
|
+
DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
16
|
+
PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
13
17
|
};
|
|
14
|
-
|
|
18
|
+
const convertOutput = (data, type, mimeType = OoxmlMimeType.DOCX) => {
|
|
19
|
+
switch (type) {
|
|
20
|
+
case "nodebuffer": return Buffer.from(data);
|
|
21
|
+
case "blob": return new Blob([data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)], { type: mimeType });
|
|
22
|
+
case "arraybuffer": return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
|
|
23
|
+
case "uint8array": return data;
|
|
24
|
+
case "base64": return btoa(strFromU8(data, true));
|
|
25
|
+
case "string":
|
|
26
|
+
case "text":
|
|
27
|
+
case "binarystring": return strFromU8(data, true);
|
|
28
|
+
case "array": return [...data];
|
|
29
|
+
default: return data;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/packer.ts
|
|
34
|
+
const PrettifyType = {
|
|
35
|
+
NONE: "",
|
|
36
|
+
WITH_2_BLANKS: " ",
|
|
37
|
+
WITH_4_BLANKS: " ",
|
|
38
|
+
WITH_TAB: " "
|
|
39
|
+
};
|
|
40
|
+
const convertPrettifyType = (prettify) => prettify === true ? PrettifyType.WITH_2_BLANKS : prettify === false ? void 0 : prettify;
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/opc/app-properties.ts
|
|
43
|
+
const APP_PROPS_XML = "<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\" xmlns:vt=\"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes\"/>";
|
|
44
|
+
var AppProperties = class AppProperties extends ImportedXmlComponent {
|
|
45
|
+
static instance = ImportedXmlComponent.fromXmlString(APP_PROPS_XML);
|
|
15
46
|
constructor() {
|
|
16
47
|
super("Properties");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}));
|
|
48
|
+
}
|
|
49
|
+
prepForXml() {
|
|
50
|
+
return AppProperties.instance.prepForXml({ stack: [] });
|
|
21
51
|
}
|
|
22
52
|
};
|
|
23
53
|
//#endregion
|
|
@@ -57,6 +87,7 @@ var Relationships = class extends BaseXmlComponent {
|
|
|
57
87
|
};
|
|
58
88
|
//#endregion
|
|
59
89
|
//#region src/formatter.ts
|
|
90
|
+
const XML_DECL = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
|
|
60
91
|
/**
|
|
61
92
|
* Converts an XmlComponent tree into a serializable XML object.
|
|
62
93
|
*/
|
|
@@ -66,6 +97,10 @@ var Formatter = class {
|
|
|
66
97
|
if (output) return output;
|
|
67
98
|
throw new Error("XMLComponent did not format correctly");
|
|
68
99
|
}
|
|
100
|
+
formatToXml(input, context, declaration) {
|
|
101
|
+
const str = input.toXml(context);
|
|
102
|
+
return declaration ? XML_DECL + str : str;
|
|
103
|
+
}
|
|
69
104
|
};
|
|
70
105
|
//#endregion
|
|
71
106
|
//#region src/core-properties.ts
|
|
@@ -157,4 +192,73 @@ var RawPassthrough = class extends BaseXmlComponent {
|
|
|
157
192
|
}
|
|
158
193
|
};
|
|
159
194
|
//#endregion
|
|
160
|
-
|
|
195
|
+
//#region src/placeholder.ts
|
|
196
|
+
const formatId = (offset, index, style) => style === "rId" ? `rId${offset + index}` : `${offset + index}`;
|
|
197
|
+
function escapeRegex(str) {
|
|
198
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
199
|
+
}
|
|
200
|
+
function hasPlaceholders(xml) {
|
|
201
|
+
return xml.includes("{");
|
|
202
|
+
}
|
|
203
|
+
function collectPlaceholderKeys(xml, prefix) {
|
|
204
|
+
const keys = [];
|
|
205
|
+
const search = `{${prefix}`;
|
|
206
|
+
let pos = 0;
|
|
207
|
+
while ((pos = xml.indexOf(search, pos)) !== -1) {
|
|
208
|
+
const keyStart = pos + search.length;
|
|
209
|
+
const keyEnd = xml.indexOf("}", keyStart);
|
|
210
|
+
if (keyEnd === -1) break;
|
|
211
|
+
const key = xml.substring(keyStart, keyEnd);
|
|
212
|
+
if (key.length > 0 && !keys.includes(key)) keys.push(key);
|
|
213
|
+
pos = keyEnd + 1;
|
|
214
|
+
}
|
|
215
|
+
return keys;
|
|
216
|
+
}
|
|
217
|
+
function replaceImagePlaceholders(xml, mediaData, offset, idFormat = "rId") {
|
|
218
|
+
let result = xml;
|
|
219
|
+
mediaData.forEach((image, i) => {
|
|
220
|
+
result = result.replace(new RegExp(`\\{${escapeRegex(image.fileName)}\\}`, "g"), formatId(offset, i, idFormat));
|
|
221
|
+
});
|
|
222
|
+
return result;
|
|
223
|
+
}
|
|
224
|
+
function getReferencedMedia(xml, mediaArray) {
|
|
225
|
+
return mediaArray.filter((image) => xml.includes(`{${image.fileName}}`));
|
|
226
|
+
}
|
|
227
|
+
function replaceChartPlaceholders(xml, chartKeys, offset, idFormat = "rId") {
|
|
228
|
+
let result = xml;
|
|
229
|
+
chartKeys.forEach((key, i) => {
|
|
230
|
+
result = result.replace(new RegExp(`\\{chart:${escapeRegex(key)}\\}`, "g"), formatId(offset, i, idFormat));
|
|
231
|
+
});
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
function replaceSmartArtPlaceholders(xml, keys, dataOffset, idFormat = "rId") {
|
|
235
|
+
let result = xml;
|
|
236
|
+
const count = keys.length;
|
|
237
|
+
const loOffset = dataOffset + count;
|
|
238
|
+
const qsOffset = loOffset + count;
|
|
239
|
+
const csOffset = qsOffset + count;
|
|
240
|
+
keys.forEach((key, i) => {
|
|
241
|
+
result = result.replace(new RegExp(`\\{smartart:${escapeRegex(key)}\\}`, "g"), formatId(dataOffset, i, idFormat));
|
|
242
|
+
result = result.replace(new RegExp(`\\{smartart-lo:${escapeRegex(key)}\\}`, "g"), formatId(loOffset, i, idFormat));
|
|
243
|
+
result = result.replace(new RegExp(`\\{smartart-qs:${escapeRegex(key)}\\}`, "g"), formatId(qsOffset, i, idFormat));
|
|
244
|
+
result = result.replace(new RegExp(`\\{smartart-cs:${escapeRegex(key)}\\}`, "g"), formatId(csOffset, i, idFormat));
|
|
245
|
+
});
|
|
246
|
+
return result;
|
|
247
|
+
}
|
|
248
|
+
function addSmartArtRelationships(keys, addRel, baseOffset, globalStartIndex, options) {
|
|
249
|
+
const { pathPrefix, styleRelType } = options;
|
|
250
|
+
const count = keys.length;
|
|
251
|
+
const loOffset = baseOffset + count;
|
|
252
|
+
const qsOffset = loOffset + count;
|
|
253
|
+
const csOffset = qsOffset + count;
|
|
254
|
+
keys.forEach((_key, i) => {
|
|
255
|
+
const gi = globalStartIndex + i;
|
|
256
|
+
addRel(baseOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramData", `${pathPrefix}diagrams/data${gi + 1}.xml`);
|
|
257
|
+
addRel(loOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramLayout", `${pathPrefix}diagrams/layout${gi + 1}.xml`);
|
|
258
|
+
addRel(qsOffset + i, styleRelType, `${pathPrefix}diagrams/quickStyle${gi + 1}.xml`);
|
|
259
|
+
addRel(csOffset + i, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/diagramColors", `${pathPrefix}diagrams/colors${gi + 1}.xml`);
|
|
260
|
+
addRel(csOffset + count + i, "http://schemas.microsoft.com/office/2007/relationships/diagramDrawing", `${pathPrefix}diagrams/drawing${gi + 1}.xml`);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
//#endregion
|
|
264
|
+
export { AppProperties, BaseXmlComponent, BuilderElement, COLOR_CATEGORIES, Connection, DataModel, EMPTY_OBJECT, EmptyElement, Formatter, HpsMeasureElement, IgnoreIfEmptyXmlComponent, ImportedRootElementAttributes, ImportedXmlComponent, InitializableXmlComponent, LAYOUT_CATEGORIES, NextAttributeComponent, NumberValueElement, OnOffElement, OoxmlMimeType, Point, PrettifyType, RawPassthrough, Relationships, STYLE_CATEGORIES, SmartArtCollection, StringContainer, StringEnumValueElement, StringValueElement, TargetModeType, ThemeColor, ThemeFont, TransPoint, XmlAttributeComponent, XmlComponent, addSmartArtRelationships, chartAttr, collectPlaceholderKeys, convertEmuToInches, convertEmuToPixels, convertEmuToPoints, convertInchesToEmu, convertInchesToTwip, convertMillimetersToTwip, convertOutput, convertPixelsToEmu, convertPointsToEmu, convertPrettifyType, convertToXmlComponent, createDataModel, dateTimeValue, decimalNumber, eighthPointMeasureValue, elementToXml, escapeRegex, findRel, findRelsByType, formatId, getImageType, getReferencedMedia, hasPlaceholders, hashedId, hexColorValue, hpsMeasureObj, hpsMeasureValue, isRaw, listFiles, longHexNumber, measurementOrPercentValue, numberValObj, onOffObj, parseCoreProperties, 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 };
|
package/dist/smartart/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { T as XmlComponent, p as chartAttr } from "../_chunks/xml-components-
|
|
1
|
+
import { T as XmlComponent, p as chartAttr } from "../_chunks/xml-components-CN6syVNr.mjs";
|
|
2
2
|
//#region src/smartart/categories.ts
|
|
3
3
|
/** Layout ID → OOXML category type */
|
|
4
4
|
const LAYOUT_CATEGORIES = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@office-open/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Shared OOXML infrastructure: XmlComponent, value validators, unit converters",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"core",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"fflate": "0.8.2",
|
|
60
60
|
"hash.js": "1.1.7",
|
|
61
61
|
"nanoid": "5.1.9",
|
|
62
|
-
"@office-open/xml": "0.3.
|
|
62
|
+
"@office-open/xml": "0.3.3"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"dev": "basis build --stub",
|