@office-open/core 0.9.7 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chart/index.d.mts +1 -1
- package/dist/descriptor/index.d.mts +2 -2
- package/dist/descriptor/index.mjs +2 -2
- package/dist/descriptor-BdWTH1vv.mjs +444 -0
- package/dist/drawingml/index.d.mts +2 -2
- package/dist/drawingml/index.mjs +2 -2
- package/dist/{index-DMw7eid7.d.mts → index-BEQ12eyX.d.mts} +42 -42
- package/dist/{index-eu1aFQCm.d.mts → index-CsQP7Cl4.d.mts} +36 -36
- package/dist/index-DEeO4sOq.d.mts +239 -0
- package/dist/index-L82O3q6V.d.mts +170 -0
- package/dist/{index-CDYC3mxJ.d.mts → index-pvj6gDsT.d.mts} +832 -179
- package/dist/{index-4hjRdzMU.d.mts → index-vEeWkbm5.d.mts} +20 -20
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +4 -4
- package/dist/patch/index.d.mts +2 -2
- package/dist/patch/index.mjs +2 -2
- package/dist/{patch-ilNZTQmG.mjs → patch-DocIv0Sn.mjs} +125 -3
- package/dist/smartart/index.d.mts +1 -1
- package/dist/{src-DlZssiRY.mjs → src-CXdJt0WZ.mjs} +1214 -263
- package/dist/theme/index.d.mts +1 -1
- package/package.json +2 -2
- package/dist/descriptor-DcQm32dg.mjs +0 -71
- package/dist/index-C4r2WLEy.d.mts +0 -73
- package/dist/index-DmPBJwSk.d.mts +0 -127
package/dist/theme/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as ColorSchemeOptions, i as createThemeXml, n as DEFAULT_COLORS, o as FontSchemeOptions, r as buildThemeXml, s as ThemeOptions, t as themeDesc } from "../index-
|
|
1
|
+
import { a as ColorSchemeOptions, i as createThemeXml, n as DEFAULT_COLORS, o as FontSchemeOptions, r as buildThemeXml, s as ThemeOptions, t as themeDesc } from "../index-vEeWkbm5.mjs";
|
|
2
2
|
export { type ColorSchemeOptions, DEFAULT_COLORS, type FontSchemeOptions, type ThemeOptions, buildThemeXml, createThemeXml, themeDesc };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@office-open/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Shared OOXML infrastructure — XML components, validators, converters, charts, and SmartArt",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"core",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@noble/hashes": "2.2.0",
|
|
68
68
|
"fflate": "0.8.3",
|
|
69
|
-
"@office-open/xml": "0.
|
|
69
|
+
"@office-open/xml": "0.10.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"dev": "basis build --stub",
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
//#region src/descriptor/runtime.ts
|
|
2
|
-
/**
|
|
3
|
-
* Serialize an Options object to an XML string using its descriptor.
|
|
4
|
-
* Returns `undefined` when an optional element should be omitted.
|
|
5
|
-
*/
|
|
6
|
-
function stringify(desc, value, ctx) {
|
|
7
|
-
return desc.stringify(value, ctx);
|
|
8
|
-
}
|
|
9
|
-
/** Parse an XML Element into an Options object using its descriptor. */
|
|
10
|
-
function parse(desc, el, ctx) {
|
|
11
|
-
return desc.parse(el, ctx);
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/descriptor/helpers.ts
|
|
15
|
-
/**
|
|
16
|
-
* OOXML-specific encode/decode helpers for descriptors.
|
|
17
|
-
*
|
|
18
|
-
* XML traversal helpers (findChild, etc.) are in @office-open/xml utils.
|
|
19
|
-
* This file only contains OOXML value encoding/decoding.
|
|
20
|
-
*
|
|
21
|
-
* @module
|
|
22
|
-
*/
|
|
23
|
-
/** Encode boolean for CT_OnOff: true → omit val, false → "0". */
|
|
24
|
-
const boolEncode = (v) => {
|
|
25
|
-
if (v === void 0) return void 0;
|
|
26
|
-
return v ? void 0 : "0";
|
|
27
|
-
};
|
|
28
|
-
/** Decode CT_OnOff: absent or "true"/"1" → true, "0"/"false" → false. */
|
|
29
|
-
const boolDecode = (raw) => raw !== "0" && raw !== "false";
|
|
30
|
-
/** Create an enum encoder from a JS↔XML mapping. */
|
|
31
|
-
const enumEncode = (map) => (v) => {
|
|
32
|
-
if (v === void 0) return void 0;
|
|
33
|
-
return map[v] ?? v;
|
|
34
|
-
};
|
|
35
|
-
/** Create an enum decoder from a JS↔XML mapping (inverted). */
|
|
36
|
-
const enumDecode = (map) => {
|
|
37
|
-
const inv = invertRecord(map);
|
|
38
|
-
return (raw) => inv[raw] ?? raw;
|
|
39
|
-
};
|
|
40
|
-
function invertRecord(map) {
|
|
41
|
-
const result = {};
|
|
42
|
-
for (const key of Object.keys(map)) result[map[key]] = key;
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/descriptor/registry.ts
|
|
47
|
-
var DescriptorRegistry = class DescriptorRegistry {
|
|
48
|
-
static _map = /* @__PURE__ */ new Map();
|
|
49
|
-
/** Register a descriptor with its XML tag. */
|
|
50
|
-
static register(tag, desc) {
|
|
51
|
-
DescriptorRegistry._map.set(tag, desc);
|
|
52
|
-
}
|
|
53
|
-
/** Look up a descriptor by XML tag. */
|
|
54
|
-
static get(tag) {
|
|
55
|
-
return DescriptorRegistry._map.get(tag);
|
|
56
|
-
}
|
|
57
|
-
/** Get all registered tags. */
|
|
58
|
-
static tags() {
|
|
59
|
-
return new Set(DescriptorRegistry._map.keys());
|
|
60
|
-
}
|
|
61
|
-
/** Check if a tag is registered. */
|
|
62
|
-
static has(tag) {
|
|
63
|
-
return DescriptorRegistry._map.has(tag);
|
|
64
|
-
}
|
|
65
|
-
/** Get the number of registered descriptors. */
|
|
66
|
-
static get size() {
|
|
67
|
-
return DescriptorRegistry._map.size;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
//#endregion
|
|
71
|
-
export { enumEncode as a, enumDecode as i, boolDecode as n, parse as o, boolEncode as r, stringify as s, DescriptorRegistry as t };
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Element } from "@office-open/xml";
|
|
2
|
-
|
|
3
|
-
//#region src/descriptor/context.d.ts
|
|
4
|
-
/** Context passed during stringify (write path). */
|
|
5
|
-
interface WriteContext {
|
|
6
|
-
/** Register a relationship and return its rId. */
|
|
7
|
-
addRelationship(type: string, target: string, mode?: string): string;
|
|
8
|
-
/** Add a media file and return its reference. */
|
|
9
|
-
addMedia(data: Uint8Array, type: string): string;
|
|
10
|
-
}
|
|
11
|
-
/** Context passed during parse (parse path). */
|
|
12
|
-
interface ReadContext {
|
|
13
|
-
/** Resolve a relationship rId to its target path. */
|
|
14
|
-
resolveRelationship(rId: string): string | undefined;
|
|
15
|
-
/** Get a parsed XML part by path. */
|
|
16
|
-
getPart(path: string): Element | undefined;
|
|
17
|
-
/** Get raw binary data (images, media, etc.) by path. */
|
|
18
|
-
getRaw(path: string): Uint8Array | undefined;
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/descriptor/types.d.ts
|
|
22
|
-
/** Custom descriptor — hand-written stringify/parse for an OOXML part. */
|
|
23
|
-
interface CustomDescriptor<T, Ctx = WriteContext> {
|
|
24
|
-
readonly kind: "custom";
|
|
25
|
-
stringify(value: T, ctx: Ctx): string | undefined;
|
|
26
|
-
parse(el: Element, ctx: ReadContext): T;
|
|
27
|
-
}
|
|
28
|
-
/** Alias for "any descriptor" — retained for call-site readability. */
|
|
29
|
-
type Descriptor<T> = CustomDescriptor<T>;
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/descriptor/runtime.d.ts
|
|
32
|
-
/**
|
|
33
|
-
* Serialize an Options object to an XML string using its descriptor.
|
|
34
|
-
* Returns `undefined` when an optional element should be omitted.
|
|
35
|
-
*/
|
|
36
|
-
declare function stringify$1<T>(desc: CustomDescriptor<T>, value: T, ctx: WriteContext): string | undefined;
|
|
37
|
-
/** Parse an XML Element into an Options object using its descriptor. */
|
|
38
|
-
declare function parse<T>(desc: CustomDescriptor<T>, el: Element, ctx: ReadContext): T;
|
|
39
|
-
//#endregion
|
|
40
|
-
//#region src/descriptor/helpers.d.ts
|
|
41
|
-
/**
|
|
42
|
-
* OOXML-specific encode/decode helpers for descriptors.
|
|
43
|
-
*
|
|
44
|
-
* XML traversal helpers (findChild, etc.) are in @office-open/xml utils.
|
|
45
|
-
* This file only contains OOXML value encoding/decoding.
|
|
46
|
-
*
|
|
47
|
-
* @module
|
|
48
|
-
*/
|
|
49
|
-
/** Encode boolean for CT_OnOff: true → omit val, false → "0". */
|
|
50
|
-
declare const boolEncode: (v: boolean | undefined) => string | undefined;
|
|
51
|
-
/** Decode CT_OnOff: absent or "true"/"1" → true, "0"/"false" → false. */
|
|
52
|
-
declare const boolDecode: (raw: string) => boolean;
|
|
53
|
-
/** Create an enum encoder from a JS↔XML mapping. */
|
|
54
|
-
declare const enumEncode: (map: Record<string, string>) => (v: string | undefined) => string | undefined;
|
|
55
|
-
/** Create an enum decoder from a JS↔XML mapping (inverted). */
|
|
56
|
-
declare const enumDecode: (map: Record<string, string>) => (raw: string) => string;
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/descriptor/registry.d.ts
|
|
59
|
-
declare class DescriptorRegistry {
|
|
60
|
-
private static readonly _map;
|
|
61
|
-
/** Register a descriptor with its XML tag. */
|
|
62
|
-
static register(tag: string, desc: Descriptor<any>): void;
|
|
63
|
-
/** Look up a descriptor by XML tag. */
|
|
64
|
-
static get(tag: string): Descriptor<any> | undefined;
|
|
65
|
-
/** Get all registered tags. */
|
|
66
|
-
static tags(): ReadonlySet<string>;
|
|
67
|
-
/** Check if a tag is registered. */
|
|
68
|
-
static has(tag: string): boolean;
|
|
69
|
-
/** Get the number of registered descriptors. */
|
|
70
|
-
static get size(): number;
|
|
71
|
-
}
|
|
72
|
-
//#endregion
|
|
73
|
-
export { enumEncode as a, CustomDescriptor as c, WriteContext as d, enumDecode as i, Descriptor as l, boolDecode as n, parse as o, boolEncode as r, stringify$1 as s, DescriptorRegistry as t, ReadContext as u };
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { Element } from "@office-open/xml";
|
|
2
|
-
|
|
3
|
-
//#region src/patch/xml-namespace.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Namespace configuration for XML patch operations.
|
|
6
|
-
*
|
|
7
|
-
* Parameterises element names so the same patch algorithm works for both
|
|
8
|
-
* DOCX (`w:*`) and PPTX (`a:*`) documents.
|
|
9
|
-
*/
|
|
10
|
-
interface XmlNamespaceConfig {
|
|
11
|
-
readonly paragraph: string;
|
|
12
|
-
readonly run: string;
|
|
13
|
-
readonly text: string;
|
|
14
|
-
readonly runProperties: string;
|
|
15
|
-
}
|
|
16
|
-
declare const DOCX_NS: XmlNamespaceConfig;
|
|
17
|
-
declare const PPTX_NS: XmlNamespaceConfig;
|
|
18
|
-
//#endregion
|
|
19
|
-
//#region src/patch/xml-replacer.d.ts
|
|
20
|
-
interface ReplacerConfig {
|
|
21
|
-
readonly ns: XmlNamespaceConfig;
|
|
22
|
-
readonly formatChild: (child: unknown, context: unknown) => Element[];
|
|
23
|
-
readonly preserveSpace?: boolean;
|
|
24
|
-
}
|
|
25
|
-
interface ReplacerResult {
|
|
26
|
-
readonly element: Element;
|
|
27
|
-
readonly didFindOccurrence: boolean;
|
|
28
|
-
}
|
|
29
|
-
declare function createReplacer(config: ReplacerConfig): ({
|
|
30
|
-
json,
|
|
31
|
-
patch,
|
|
32
|
-
patchText,
|
|
33
|
-
context,
|
|
34
|
-
keepOriginalStyles
|
|
35
|
-
}: {
|
|
36
|
-
readonly json: Element;
|
|
37
|
-
readonly patch: {
|
|
38
|
-
readonly type: string;
|
|
39
|
-
readonly children: readonly unknown[];
|
|
40
|
-
};
|
|
41
|
-
readonly patchText: string;
|
|
42
|
-
readonly context: unknown;
|
|
43
|
-
readonly keepOriginalStyles?: boolean;
|
|
44
|
-
}) => ReplacerResult;
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/patch/run-renderer.d.ts
|
|
47
|
-
interface ElementWrapper {
|
|
48
|
-
readonly element: Element;
|
|
49
|
-
readonly index: number;
|
|
50
|
-
readonly parent: ElementWrapper | undefined;
|
|
51
|
-
}
|
|
52
|
-
interface RenderedParagraphNode {
|
|
53
|
-
readonly text: string;
|
|
54
|
-
readonly runs: readonly RenderedRunNode[];
|
|
55
|
-
readonly index: number;
|
|
56
|
-
readonly pathToParagraph: readonly number[];
|
|
57
|
-
}
|
|
58
|
-
interface StartAndEnd {
|
|
59
|
-
readonly start: number;
|
|
60
|
-
readonly end: number;
|
|
61
|
-
}
|
|
62
|
-
type IParts = {
|
|
63
|
-
readonly text: string;
|
|
64
|
-
readonly index: number;
|
|
65
|
-
} & StartAndEnd;
|
|
66
|
-
type RenderedRunNode = {
|
|
67
|
-
readonly text: string;
|
|
68
|
-
readonly parts: readonly IParts[];
|
|
69
|
-
readonly index: number;
|
|
70
|
-
} & StartAndEnd;
|
|
71
|
-
declare function createRunRenderer(ns: XmlNamespaceConfig): (node: ElementWrapper) => RenderedParagraphNode;
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/patch/xml-traverser.d.ts
|
|
74
|
-
declare function createTraverser(ns: XmlNamespaceConfig): {
|
|
75
|
-
traverse: (node: Element) => readonly RenderedParagraphNode[];
|
|
76
|
-
findLocationOfText: (node: Element, text: string) => readonly RenderedParagraphNode[];
|
|
77
|
-
};
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/patch/paragraph-token-replacer.d.ts
|
|
80
|
-
declare function createTokenReplacer(createTextElementContents: (text: string) => Element[], options?: {
|
|
81
|
-
readonly preserveSpace?: boolean;
|
|
82
|
-
}): ({
|
|
83
|
-
paragraphElement,
|
|
84
|
-
renderedParagraph,
|
|
85
|
-
originalText,
|
|
86
|
-
replacementText
|
|
87
|
-
}: {
|
|
88
|
-
readonly paragraphElement: Element;
|
|
89
|
-
readonly renderedParagraph: RenderedParagraphNode;
|
|
90
|
-
readonly originalText: string;
|
|
91
|
-
readonly replacementText: string;
|
|
92
|
-
}) => Element;
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region src/patch/paragraph-split-inject.d.ts
|
|
95
|
-
declare class TokenNotFoundError extends Error {
|
|
96
|
-
constructor(token: string);
|
|
97
|
-
}
|
|
98
|
-
declare function createSplitInject(ns: XmlNamespaceConfig, createTextElementContents: (text: string) => Element[], options?: {
|
|
99
|
-
readonly preserveSpace?: boolean;
|
|
100
|
-
}): {
|
|
101
|
-
findRunElementIndexWithToken: (paragraphElement: Element, token: string) => number;
|
|
102
|
-
splitRunElement: (runElement: Element, token: string) => {
|
|
103
|
-
readonly left: Element;
|
|
104
|
-
readonly right: Element;
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/patch/xml-patch-utils.d.ts
|
|
109
|
-
declare const toJson: (xmlData: string) => Element;
|
|
110
|
-
/**
|
|
111
|
-
* Creates the inner content of a text element (`w:t` / `a:t`).
|
|
112
|
-
*
|
|
113
|
-
* Returns `[{ type: "text", text }]` for non-empty text, `[]` for empty.
|
|
114
|
-
* The `xml:space` attribute is handled separately by `patchSpaceAttribute`.
|
|
115
|
-
*/
|
|
116
|
-
declare const createTextElementContents: (text: string) => Element[];
|
|
117
|
-
declare const patchSpaceAttribute: (element: Element) => Element;
|
|
118
|
-
declare const getFirstLevelElements: (relationships: Element, id: string) => Element[];
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/patch/content-types-manager.d.ts
|
|
121
|
-
declare const appendContentType: (element: Element, contentType: string, extension: string) => void;
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region src/patch/relationship-manager.d.ts
|
|
124
|
-
declare const getNextRelationshipIndex: (relationships: Element) => number;
|
|
125
|
-
declare const appendRelationship: (relationships: Element, id: number | string, type: string, target: string, targetMode?: string) => readonly Element[];
|
|
126
|
-
//#endregion
|
|
127
|
-
export { PPTX_NS as _, getFirstLevelElements as a, TokenNotFoundError as c, createTraverser as d, RenderedParagraphNode as f, DOCX_NS as g, createReplacer as h, createTextElementContents as i, createSplitInject as l, ReplacerConfig as m, getNextRelationshipIndex as n, patchSpaceAttribute as o, createRunRenderer as p, appendContentType as r, toJson as s, appendRelationship as t, createTokenReplacer as u, XmlNamespaceConfig as v };
|