@office-open/core 0.4.6 → 0.5.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/README.md +11 -11
- package/dist/archive.mjs +1 -135
- package/dist/chart/index.d.mts +2 -2
- package/dist/chart/index.mjs +1 -611
- package/dist/drawingml/index.d.mts +1 -1
- package/dist/drawingml/index.mjs +1 -3800
- package/dist/id-generators-Dd0w7vti.mjs +1 -0
- package/dist/{_chunks/index-hmJg8TDw.d.mts → index-DqdJoWmh.d.mts} +1 -1
- package/dist/{_chunks/index-B3rs5exK.d.mts → index-rASwxHbF.d.mts} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -424
- package/dist/smartart/index.d.mts +1 -1
- package/dist/smartart/index.mjs +1 -2
- package/dist/smartart-C-ZIRmWU.mjs +1 -0
- package/dist/values.d.mts +1 -1
- package/dist/values.mjs +1 -371
- package/dist/xml-components-Csq7gWPd.mjs +1 -0
- package/package.json +5 -5
- package/dist/_chunks/id-generators-Ch07cHW1.mjs +0 -72
- package/dist/_chunks/smartart-D_qXltR5.mjs +0 -336
- package/dist/_chunks/xml-components-CN6syVNr.mjs +0 -381
- /package/dist/{_chunks/values-COMdgNmb.d.mts → values-CIh0bdS1.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -30,14 +30,14 @@ $ pnpm add @office-open/core
|
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
32
|
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
OnOffElement,
|
|
34
|
+
StringValueElement,
|
|
35
|
+
BuilderElement,
|
|
36
|
+
StringContainer,
|
|
37
|
+
hexColorValue,
|
|
38
|
+
decimalNumber,
|
|
39
|
+
convertMillimetersToTwip,
|
|
40
|
+
uniqueNumericIdCreator,
|
|
41
41
|
} from "@office-open/core";
|
|
42
42
|
|
|
43
43
|
// CT_OnOff — dynamic namespace prefix per XSD spec
|
|
@@ -49,9 +49,9 @@ new OnOffElement("m:hideBot", false);
|
|
|
49
49
|
|
|
50
50
|
// Builder with attributes + children
|
|
51
51
|
new BuilderElement({
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
name: "w:r",
|
|
53
|
+
attributes: { lang: { key: "xml:lang", value: "en-US" } },
|
|
54
|
+
children: [new StringContainer("w:t", "Hello")],
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
// Value validators
|
package/dist/archive.mjs
CHANGED
|
@@ -1,135 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { strFromU8, strToU8, unzipSync, zipSync } from "fflate";
|
|
3
|
-
//#region src/archive.ts
|
|
4
|
-
const XML_PARSE_OPTIONS = {
|
|
5
|
-
nativeTypeAttributes: true,
|
|
6
|
-
captureSpacesBetweenElements: true
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* Unzip an OOXML file (.docx, .pptx) into a Map of path → Uint8Array.
|
|
10
|
-
*/
|
|
11
|
-
function unzipToMap(data) {
|
|
12
|
-
const entries = unzipSync(data);
|
|
13
|
-
const map = /* @__PURE__ */ new Map();
|
|
14
|
-
for (const [path, bytes] of Object.entries(entries)) map.set(path, bytes);
|
|
15
|
-
return map;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Read a file from the zip as a UTF-8 string.
|
|
19
|
-
*/
|
|
20
|
-
function readTextFromZip(zip, path) {
|
|
21
|
-
const data = zip.get(path);
|
|
22
|
-
if (data === void 0) return void 0;
|
|
23
|
-
return strFromU8(data);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Parse an XML file from the zip into an Element tree.
|
|
27
|
-
*/
|
|
28
|
-
function readXmlFromZip(zip, path) {
|
|
29
|
-
const text = readTextFromZip(zip, path);
|
|
30
|
-
if (text === void 0) return void 0;
|
|
31
|
-
return xml2js(text, XML_PARSE_OPTIONS).elements?.find((e) => e.type === "element");
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Read a binary file from the zip.
|
|
35
|
-
*/
|
|
36
|
-
function readBinaryFromZip(zip, path) {
|
|
37
|
-
return zip.get(path);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Parse all XML files in the zip into Element trees.
|
|
41
|
-
* Skips media files, binary files, and the main document/presentation file.
|
|
42
|
-
*/
|
|
43
|
-
function readAllXmlParts(zip, options) {
|
|
44
|
-
const parts = {};
|
|
45
|
-
const skip = new Set(options?.skipPaths ?? []);
|
|
46
|
-
for (const path of zip.keys()) {
|
|
47
|
-
if (skip.has(path)) continue;
|
|
48
|
-
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;
|
|
49
|
-
const el = readXmlFromZip(zip, path);
|
|
50
|
-
if (el) parts[path] = el;
|
|
51
|
-
}
|
|
52
|
-
return parts;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* List all files in the zip matching a prefix.
|
|
56
|
-
*/
|
|
57
|
-
function listFiles(zip, prefix) {
|
|
58
|
-
const result = [];
|
|
59
|
-
for (const path of zip.keys()) if (path.startsWith(prefix)) result.push(path);
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Convert Uint8Array to base64 string.
|
|
64
|
-
*/
|
|
65
|
-
function uint8ToBase64(data) {
|
|
66
|
-
const chunkSize = 8192;
|
|
67
|
-
let binary = "";
|
|
68
|
-
for (let i = 0; i < data.length; i += chunkSize) {
|
|
69
|
-
const chunk = data.subarray(i, Math.min(i + chunkSize, data.length));
|
|
70
|
-
binary += String.fromCharCode(...chunk);
|
|
71
|
-
}
|
|
72
|
-
return btoa(binary);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Determine image type from file extension.
|
|
76
|
-
*/
|
|
77
|
-
function getImageType(fileName) {
|
|
78
|
-
const ext = fileName.split(".").pop()?.toLowerCase() ?? "";
|
|
79
|
-
if ([
|
|
80
|
-
"png",
|
|
81
|
-
"jpg",
|
|
82
|
-
"jpeg",
|
|
83
|
-
"gif",
|
|
84
|
-
"bmp",
|
|
85
|
-
"tif",
|
|
86
|
-
"tiff",
|
|
87
|
-
"ico",
|
|
88
|
-
"emf",
|
|
89
|
-
"wmf",
|
|
90
|
-
"svg"
|
|
91
|
-
].includes(ext)) return ext === "jpeg" ? "jpg" : ext;
|
|
92
|
-
return "png";
|
|
93
|
-
}
|
|
94
|
-
function parseRels(zip, path) {
|
|
95
|
-
const xml = readXmlFromZip(zip, path);
|
|
96
|
-
if (!xml) return [];
|
|
97
|
-
const result = [];
|
|
98
|
-
for (const rel of xml.elements ?? []) {
|
|
99
|
-
if (rel.name !== "Relationship") continue;
|
|
100
|
-
const id = attr(rel, "Id");
|
|
101
|
-
const target = attr(rel, "Target");
|
|
102
|
-
const type = attr(rel, "Type");
|
|
103
|
-
const targetMode = attr(rel, "TargetMode");
|
|
104
|
-
if (id && target) result.push({
|
|
105
|
-
id,
|
|
106
|
-
target,
|
|
107
|
-
type: type ?? "",
|
|
108
|
-
...targetMode ? { targetMode } : {}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
function findRel(rels, id) {
|
|
114
|
-
return rels.find((r) => r.id === id);
|
|
115
|
-
}
|
|
116
|
-
function findRelsByType(rels, typeSubstring) {
|
|
117
|
-
return rels.filter((r) => r.type.includes(typeSubstring));
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Zip a map of path → Uint8Array/string into a ZIP buffer.
|
|
121
|
-
* XML strings are auto-encoded to UTF-8 bytes.
|
|
122
|
-
*/
|
|
123
|
-
function zipToBuffer(files) {
|
|
124
|
-
const entries = {};
|
|
125
|
-
for (const [path, data] of files) entries[path] = typeof data === "string" ? strToU8(data) : data;
|
|
126
|
-
return zipSync(entries);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Serialize an Element tree to an XML string.
|
|
130
|
-
*/
|
|
131
|
-
function elementToXml(el) {
|
|
132
|
-
return js2xml(el);
|
|
133
|
-
}
|
|
134
|
-
//#endregion
|
|
135
|
-
export { elementToXml, findRel, findRelsByType, getImageType, listFiles, parseRels, readAllXmlParts, readBinaryFromZip, readTextFromZip, readXmlFromZip, uint8ToBase64, unzipToMap, zipToBuffer };
|
|
1
|
+
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};
|
package/dist/chart/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as XmlComponent } from "../
|
|
1
|
+
import { O as XmlComponent } from "../index-DqdJoWmh.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/chart/axes.d.ts
|
|
4
4
|
/**
|
|
@@ -71,7 +71,7 @@ interface IChartTypeOptions {
|
|
|
71
71
|
readonly series: readonly IChartSeriesData[];
|
|
72
72
|
readonly categories: readonly string[];
|
|
73
73
|
}
|
|
74
|
-
declare const createChartType: (options: IChartTypeOptions) =>
|
|
74
|
+
declare const createChartType: (options: IChartTypeOptions) => BarChart | LineChart | PieChart | AreaChart | ScatterChart;
|
|
75
75
|
//#endregion
|
|
76
76
|
//#region src/chart/chart-space.d.ts
|
|
77
77
|
interface IChartSpaceOptions {
|