@opentabs-dev/opentabs-plugin-microsoft-word 0.0.74
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 +159 -0
- package/dist/adapter.iife.js +15874 -0
- package/dist/adapter.iife.js.map +7 -0
- package/dist/docx-utils.d.ts +63 -0
- package/dist/docx-utils.d.ts.map +1 -0
- package/dist/docx-utils.js +370 -0
- package/dist/docx-utils.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/microsoft-word-api.d.ts +17 -0
- package/dist/microsoft-word-api.d.ts.map +1 -0
- package/dist/microsoft-word-api.js +142 -0
- package/dist/microsoft-word-api.js.map +1 -0
- package/dist/tools/append-to-document.d.ts +8 -0
- package/dist/tools/append-to-document.d.ts.map +1 -0
- package/dist/tools/append-to-document.js +26 -0
- package/dist/tools/append-to-document.js.map +1 -0
- package/dist/tools/copy-item.d.ts +9 -0
- package/dist/tools/copy-item.d.ts.map +1 -0
- package/dist/tools/copy-item.js +69 -0
- package/dist/tools/copy-item.js.map +1 -0
- package/dist/tools/create-document.d.ts +20 -0
- package/dist/tools/create-document.d.ts.map +1 -0
- package/dist/tools/create-document.js +73 -0
- package/dist/tools/create-document.js.map +1 -0
- package/dist/tools/create-folder.d.ts +20 -0
- package/dist/tools/create-folder.d.ts.map +1 -0
- package/dist/tools/create-folder.js +30 -0
- package/dist/tools/create-folder.js.map +1 -0
- package/dist/tools/create-sharing-link.d.ts +22 -0
- package/dist/tools/create-sharing-link.d.ts.map +1 -0
- package/dist/tools/create-sharing-link.js +31 -0
- package/dist/tools/create-sharing-link.js.map +1 -0
- package/dist/tools/delete-item.d.ts +7 -0
- package/dist/tools/delete-item.d.ts.map +1 -0
- package/dist/tools/delete-item.js +24 -0
- package/dist/tools/delete-item.js.map +1 -0
- package/dist/tools/delete-permission.d.ts +8 -0
- package/dist/tools/delete-permission.d.ts.map +1 -0
- package/dist/tools/delete-permission.js +23 -0
- package/dist/tools/delete-permission.js.map +1 -0
- package/dist/tools/docx-edit-helpers.d.ts +10 -0
- package/dist/tools/docx-edit-helpers.d.ts.map +1 -0
- package/dist/tools/docx-edit-helpers.js +103 -0
- package/dist/tools/docx-edit-helpers.js.map +1 -0
- package/dist/tools/get-active-document.d.ts +18 -0
- package/dist/tools/get-active-document.d.ts.map +1 -0
- package/dist/tools/get-active-document.js +50 -0
- package/dist/tools/get-active-document.js.map +1 -0
- package/dist/tools/get-current-user.d.ts +9 -0
- package/dist/tools/get-current-user.d.ts.map +1 -0
- package/dist/tools/get-current-user.js +23 -0
- package/dist/tools/get-current-user.js.map +1 -0
- package/dist/tools/get-document-text.d.ts +8 -0
- package/dist/tools/get-document-text.d.ts.map +1 -0
- package/dist/tools/get-document-text.js +87 -0
- package/dist/tools/get-document-text.js.map +1 -0
- package/dist/tools/get-drive.d.ts +15 -0
- package/dist/tools/get-drive.d.ts.map +1 -0
- package/dist/tools/get-drive.js +19 -0
- package/dist/tools/get-drive.js.map +1 -0
- package/dist/tools/get-file-content.d.ts +8 -0
- package/dist/tools/get-file-content.d.ts.map +1 -0
- package/dist/tools/get-file-content.js +74 -0
- package/dist/tools/get-file-content.js.map +1 -0
- package/dist/tools/get-item.d.ts +19 -0
- package/dist/tools/get-item.d.ts.map +1 -0
- package/dist/tools/get-item.js +25 -0
- package/dist/tools/get-item.js.map +1 -0
- package/dist/tools/get-preview-url.d.ts +7 -0
- package/dist/tools/get-preview-url.d.ts.map +1 -0
- package/dist/tools/get-preview-url.js +22 -0
- package/dist/tools/get-preview-url.js.map +1 -0
- package/dist/tools/list-children.d.ts +21 -0
- package/dist/tools/list-children.d.ts.map +1 -0
- package/dist/tools/list-children.js +33 -0
- package/dist/tools/list-children.js.map +1 -0
- package/dist/tools/list-permissions.d.ts +13 -0
- package/dist/tools/list-permissions.d.ts.map +1 -0
- package/dist/tools/list-permissions.js +23 -0
- package/dist/tools/list-permissions.js.map +1 -0
- package/dist/tools/list-recent-documents.d.ts +19 -0
- package/dist/tools/list-recent-documents.d.ts.map +1 -0
- package/dist/tools/list-recent-documents.js +27 -0
- package/dist/tools/list-recent-documents.js.map +1 -0
- package/dist/tools/list-shared-with-me.d.ts +19 -0
- package/dist/tools/list-shared-with-me.d.ts.map +1 -0
- package/dist/tools/list-shared-with-me.js +28 -0
- package/dist/tools/list-shared-with-me.js.map +1 -0
- package/dist/tools/list-versions.d.ts +11 -0
- package/dist/tools/list-versions.d.ts.map +1 -0
- package/dist/tools/list-versions.js +23 -0
- package/dist/tools/list-versions.js.map +1 -0
- package/dist/tools/move-item.d.ts +20 -0
- package/dist/tools/move-item.d.ts.map +1 -0
- package/dist/tools/move-item.js +27 -0
- package/dist/tools/move-item.js.map +1 -0
- package/dist/tools/rename-item.d.ts +20 -0
- package/dist/tools/rename-item.d.ts.map +1 -0
- package/dist/tools/rename-item.js +27 -0
- package/dist/tools/rename-item.js.map +1 -0
- package/dist/tools/replace-text-in-document.d.ts +10 -0
- package/dist/tools/replace-text-in-document.d.ts.map +1 -0
- package/dist/tools/replace-text-in-document.js +31 -0
- package/dist/tools/replace-text-in-document.js.map +1 -0
- package/dist/tools/restore-version.d.ts +8 -0
- package/dist/tools/restore-version.d.ts.map +1 -0
- package/dist/tools/restore-version.js +23 -0
- package/dist/tools/restore-version.js.map +1 -0
- package/dist/tools/schemas.d.ts +155 -0
- package/dist/tools/schemas.d.ts.map +1 -0
- package/dist/tools/schemas.js +90 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/search-files.d.ts +20 -0
- package/dist/tools/search-files.d.ts.map +1 -0
- package/dist/tools/search-files.js +29 -0
- package/dist/tools/search-files.js.map +1 -0
- package/dist/tools/update-document.d.ts +8 -0
- package/dist/tools/update-document.d.ts.map +1 -0
- package/dist/tools/update-document.js +26 -0
- package/dist/tools/update-document.js.map +1 -0
- package/dist/tools/update-file-content.d.ts +21 -0
- package/dist/tools/update-file-content.d.ts.map +1 -0
- package/dist/tools/update-file-content.js +66 -0
- package/dist/tools/update-file-content.js.map +1 -0
- package/dist/tools/upload-file.d.ts +21 -0
- package/dist/tools/upload-file.d.ts.map +1 -0
- package/dist/tools/upload-file.js +64 -0
- package/dist/tools/upload-file.js.map +1 -0
- package/dist/tools.json +1940 -0
- package/package.json +55 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for reading and creating .docx files in the browser.
|
|
3
|
+
*
|
|
4
|
+
* A .docx file is a ZIP archive containing OOXML parts:
|
|
5
|
+
* [Content_Types].xml — content type declarations
|
|
6
|
+
* _rels/.rels — relationship mappings
|
|
7
|
+
* word/document.xml — the actual document content
|
|
8
|
+
*
|
|
9
|
+
* Text is stored in <w:t> elements within <w:r> (run) within <w:p> (paragraph) nodes.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Extract a file entry from a ZIP archive by name.
|
|
13
|
+
* Handles both STORE (uncompressed) and DEFLATE (compressed) entries.
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractZipEntry(zipBytes: Uint8Array, filename: string): Promise<string | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Extract plain text paragraphs from OOXML document.xml content.
|
|
18
|
+
* Returns an array of paragraph strings.
|
|
19
|
+
*/
|
|
20
|
+
export declare function extractTextFromDocumentXml(xml: string): string[];
|
|
21
|
+
/** A raw entry extracted from a ZIP archive. Binary data is preserved as-is. */
|
|
22
|
+
export interface ZipEntry {
|
|
23
|
+
name: string;
|
|
24
|
+
data: Uint8Array;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Extract all entries from a ZIP archive, decompressing DEFLATE entries.
|
|
28
|
+
* Returns raw byte data for each entry (to preserve binary entries like images).
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractAllZipEntries(zipBytes: Uint8Array): Promise<ZipEntry[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Rebuild a ZIP archive from entries, replacing one entry's content.
|
|
33
|
+
* All entries are stored uncompressed (STORE method).
|
|
34
|
+
*/
|
|
35
|
+
export declare function rebuildZip(entries: ZipEntry[]): Uint8Array;
|
|
36
|
+
/** Escape text for use inside OOXML <w:t> elements. */
|
|
37
|
+
export declare function escapeXml(text: string): string;
|
|
38
|
+
/** Build OOXML paragraph elements from plain text strings. */
|
|
39
|
+
export declare function textToParagraphXml(paragraphs: string[]): string;
|
|
40
|
+
/**
|
|
41
|
+
* Append paragraphs to an existing document.xml string.
|
|
42
|
+
* Inserts new <w:p> elements before the closing </w:body> tag.
|
|
43
|
+
*/
|
|
44
|
+
export declare function appendParagraphsToXml(existingXml: string, paragraphs: string[]): string;
|
|
45
|
+
/**
|
|
46
|
+
* Replace all document body content with new paragraphs, preserving
|
|
47
|
+
* the XML declaration and document wrapper attributes.
|
|
48
|
+
*/
|
|
49
|
+
export declare function replaceBodyContent(existingXml: string, paragraphs: string[]): string;
|
|
50
|
+
/**
|
|
51
|
+
* Perform find-and-replace on text within <w:t> elements in document.xml.
|
|
52
|
+
* Replaces all occurrences of `find` with `replace` within each text run.
|
|
53
|
+
*/
|
|
54
|
+
export declare function replaceTextInXml(xml: string, find: string, replace: string): {
|
|
55
|
+
xml: string;
|
|
56
|
+
count: number;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Build a minimal valid .docx file (ZIP archive) from an array of text paragraphs.
|
|
60
|
+
* Uses STORE (no compression) for simplicity and reliability.
|
|
61
|
+
*/
|
|
62
|
+
export declare function buildDocx(paragraphs: string[]): Uint8Array;
|
|
63
|
+
//# sourceMappingURL=docx-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docx-utils.d.ts","sourceRoot":"","sources":["../src/docx-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAiBH;;;GAGG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA6BpG;AA4BD;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAmBhE;AAED,gFAAgF;AAChF,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CA8BpF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,UAAU,CAE1D;AAED,uDAAuD;AACvD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAE/D;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CASvF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAapF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAiB3G;AAgBD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,UAAU,CAoC1D"}
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for reading and creating .docx files in the browser.
|
|
3
|
+
*
|
|
4
|
+
* A .docx file is a ZIP archive containing OOXML parts:
|
|
5
|
+
* [Content_Types].xml — content type declarations
|
|
6
|
+
* _rels/.rels — relationship mappings
|
|
7
|
+
* word/document.xml — the actual document content
|
|
8
|
+
*
|
|
9
|
+
* Text is stored in <w:t> elements within <w:r> (run) within <w:p> (paragraph) nodes.
|
|
10
|
+
*/
|
|
11
|
+
/** Read a little-endian uint16 from a byte array. */
|
|
12
|
+
function readUint16LE(data, offset) {
|
|
13
|
+
return (data[offset] ?? 0) | ((data[offset + 1] ?? 0) << 8);
|
|
14
|
+
}
|
|
15
|
+
/** Read a little-endian uint32 from a byte array. */
|
|
16
|
+
function readUint32LE(data, offset) {
|
|
17
|
+
return ((data[offset] ?? 0) |
|
|
18
|
+
((data[offset + 1] ?? 0) << 8) |
|
|
19
|
+
((data[offset + 2] ?? 0) << 16) |
|
|
20
|
+
(((data[offset + 3] ?? 0) << 24) >>> 0));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extract a file entry from a ZIP archive by name.
|
|
24
|
+
* Handles both STORE (uncompressed) and DEFLATE (compressed) entries.
|
|
25
|
+
*/
|
|
26
|
+
export async function extractZipEntry(zipBytes, filename) {
|
|
27
|
+
let offset = 0;
|
|
28
|
+
while (offset < zipBytes.length - 30) {
|
|
29
|
+
// Local file header signature: PK\x03\x04
|
|
30
|
+
if (readUint32LE(zipBytes, offset) !== 0x04034b50) {
|
|
31
|
+
offset++;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const compressionMethod = readUint16LE(zipBytes, offset + 8);
|
|
35
|
+
const compressedSize = readUint32LE(zipBytes, offset + 18);
|
|
36
|
+
const nameLen = readUint16LE(zipBytes, offset + 26);
|
|
37
|
+
const extraLen = readUint16LE(zipBytes, offset + 28);
|
|
38
|
+
const name = new TextDecoder().decode(zipBytes.slice(offset + 30, offset + 30 + nameLen));
|
|
39
|
+
const dataStart = offset + 30 + nameLen + extraLen;
|
|
40
|
+
const rawData = zipBytes.slice(dataStart, dataStart + compressedSize);
|
|
41
|
+
if (name === filename) {
|
|
42
|
+
if (compressionMethod === 8) {
|
|
43
|
+
return decompressDeflateRaw(rawData);
|
|
44
|
+
}
|
|
45
|
+
// STORE (method 0) — uncompressed
|
|
46
|
+
return new TextDecoder().decode(rawData);
|
|
47
|
+
}
|
|
48
|
+
offset += 30 + nameLen + extraLen + compressedSize;
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
/** Decompress a DEFLATE-raw buffer using the browser DecompressionStream API. */
|
|
53
|
+
async function decompressDeflateRaw(data) {
|
|
54
|
+
const ds = new DecompressionStream('deflate-raw');
|
|
55
|
+
const writer = ds.writable.getWriter();
|
|
56
|
+
// Copy into a fresh ArrayBuffer to satisfy the BufferSource type constraint
|
|
57
|
+
const copy = new Uint8Array(data.length);
|
|
58
|
+
copy.set(data);
|
|
59
|
+
writer.write(copy);
|
|
60
|
+
writer.close();
|
|
61
|
+
const reader = ds.readable.getReader();
|
|
62
|
+
const chunks = [];
|
|
63
|
+
for (;;) {
|
|
64
|
+
const { done, value } = await reader.read();
|
|
65
|
+
if (done)
|
|
66
|
+
break;
|
|
67
|
+
chunks.push(value);
|
|
68
|
+
}
|
|
69
|
+
const totalLen = chunks.reduce((s, c) => s + c.length, 0);
|
|
70
|
+
const result = new Uint8Array(totalLen);
|
|
71
|
+
let pos = 0;
|
|
72
|
+
for (const chunk of chunks) {
|
|
73
|
+
result.set(chunk, pos);
|
|
74
|
+
pos += chunk.length;
|
|
75
|
+
}
|
|
76
|
+
return new TextDecoder().decode(result);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Extract plain text paragraphs from OOXML document.xml content.
|
|
80
|
+
* Returns an array of paragraph strings.
|
|
81
|
+
*/
|
|
82
|
+
export function extractTextFromDocumentXml(xml) {
|
|
83
|
+
const paraBlocks = xml.split(/<\/w:p>/);
|
|
84
|
+
const paragraphs = [];
|
|
85
|
+
for (const block of paraBlocks) {
|
|
86
|
+
const texts = [];
|
|
87
|
+
const regex = /<w:t[^>]*>([\s\S]*?)<\/w:t>/g;
|
|
88
|
+
let match = regex.exec(block);
|
|
89
|
+
while (match !== null) {
|
|
90
|
+
texts.push(match[1] ?? '');
|
|
91
|
+
match = regex.exec(block);
|
|
92
|
+
}
|
|
93
|
+
const paraText = texts.join('');
|
|
94
|
+
if (paraText) {
|
|
95
|
+
paragraphs.push(paraText);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return paragraphs;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Extract all entries from a ZIP archive, decompressing DEFLATE entries.
|
|
102
|
+
* Returns raw byte data for each entry (to preserve binary entries like images).
|
|
103
|
+
*/
|
|
104
|
+
export async function extractAllZipEntries(zipBytes) {
|
|
105
|
+
const entries = [];
|
|
106
|
+
let offset = 0;
|
|
107
|
+
while (offset < zipBytes.length - 30) {
|
|
108
|
+
if (readUint32LE(zipBytes, offset) !== 0x04034b50) {
|
|
109
|
+
offset++;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const compressionMethod = readUint16LE(zipBytes, offset + 8);
|
|
113
|
+
const compressedSize = readUint32LE(zipBytes, offset + 18);
|
|
114
|
+
const nameLen = readUint16LE(zipBytes, offset + 26);
|
|
115
|
+
const extraLen = readUint16LE(zipBytes, offset + 28);
|
|
116
|
+
const name = new TextDecoder().decode(zipBytes.slice(offset + 30, offset + 30 + nameLen));
|
|
117
|
+
const dataStart = offset + 30 + nameLen + extraLen;
|
|
118
|
+
const rawData = zipBytes.slice(dataStart, dataStart + compressedSize);
|
|
119
|
+
let data;
|
|
120
|
+
if (compressionMethod === 8) {
|
|
121
|
+
const text = await decompressDeflateRaw(rawData);
|
|
122
|
+
data = new TextEncoder().encode(text);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
data = rawData;
|
|
126
|
+
}
|
|
127
|
+
entries.push({ name, data });
|
|
128
|
+
offset += 30 + nameLen + extraLen + compressedSize;
|
|
129
|
+
}
|
|
130
|
+
return entries;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Rebuild a ZIP archive from entries, replacing one entry's content.
|
|
134
|
+
* All entries are stored uncompressed (STORE method).
|
|
135
|
+
*/
|
|
136
|
+
export function rebuildZip(entries) {
|
|
137
|
+
return createZipFromBinary(entries);
|
|
138
|
+
}
|
|
139
|
+
/** Escape text for use inside OOXML <w:t> elements. */
|
|
140
|
+
export function escapeXml(text) {
|
|
141
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
142
|
+
}
|
|
143
|
+
/** Build OOXML paragraph elements from plain text strings. */
|
|
144
|
+
export function textToParagraphXml(paragraphs) {
|
|
145
|
+
return paragraphs.map(text => `<w:p><w:r><w:t xml:space="preserve">${escapeXml(text)}</w:t></w:r></w:p>`).join('');
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Append paragraphs to an existing document.xml string.
|
|
149
|
+
* Inserts new <w:p> elements before the closing </w:body> tag.
|
|
150
|
+
*/
|
|
151
|
+
export function appendParagraphsToXml(existingXml, paragraphs) {
|
|
152
|
+
const newContent = textToParagraphXml(paragraphs);
|
|
153
|
+
// Insert before </w:body>
|
|
154
|
+
const bodyCloseIdx = existingXml.lastIndexOf('</w:body>');
|
|
155
|
+
if (bodyCloseIdx === -1) {
|
|
156
|
+
// Malformed — wrap in a body
|
|
157
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body>${newContent}</w:body></w:document>`;
|
|
158
|
+
}
|
|
159
|
+
return existingXml.slice(0, bodyCloseIdx) + newContent + existingXml.slice(bodyCloseIdx);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Replace all document body content with new paragraphs, preserving
|
|
163
|
+
* the XML declaration and document wrapper attributes.
|
|
164
|
+
*/
|
|
165
|
+
export function replaceBodyContent(existingXml, paragraphs) {
|
|
166
|
+
const newContent = textToParagraphXml(paragraphs);
|
|
167
|
+
// Find <w:body...> opening and </w:body> closing
|
|
168
|
+
const bodyOpenMatch = existingXml.match(/<w:body[^>]*>/);
|
|
169
|
+
const bodyCloseIdx = existingXml.lastIndexOf('</w:body>');
|
|
170
|
+
if (!bodyOpenMatch || bodyCloseIdx === -1) {
|
|
171
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body>${newContent}</w:body></w:document>`;
|
|
172
|
+
}
|
|
173
|
+
const bodyOpenEnd = (bodyOpenMatch.index ?? 0) + bodyOpenMatch[0].length;
|
|
174
|
+
return existingXml.slice(0, bodyOpenEnd) + newContent + existingXml.slice(bodyCloseIdx);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Perform find-and-replace on text within <w:t> elements in document.xml.
|
|
178
|
+
* Replaces all occurrences of `find` with `replace` within each text run.
|
|
179
|
+
*/
|
|
180
|
+
export function replaceTextInXml(xml, find, replace) {
|
|
181
|
+
let count = 0;
|
|
182
|
+
const escaped = escapeXml(find);
|
|
183
|
+
const escapedReplace = escapeXml(replace);
|
|
184
|
+
// Replace within <w:t> content — match each <w:t>...</w:t> and replace inside
|
|
185
|
+
const result = xml.replace(/(<w:t[^>]*>)([\s\S]*?)(<\/w:t>)/g, (_match, open, content, close) => {
|
|
186
|
+
if (!content.includes(escaped))
|
|
187
|
+
return _match;
|
|
188
|
+
const parts = content.split(escaped);
|
|
189
|
+
count += parts.length - 1;
|
|
190
|
+
return open + parts.join(escapedReplace) + close;
|
|
191
|
+
});
|
|
192
|
+
return { xml: result, count };
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Compute CRC-32 for a byte array (used by ZIP format).
|
|
196
|
+
*/
|
|
197
|
+
function crc32(data) {
|
|
198
|
+
let crc = 0xffffffff;
|
|
199
|
+
for (let i = 0; i < data.length; i++) {
|
|
200
|
+
crc ^= data[i] ?? 0;
|
|
201
|
+
for (let j = 0; j < 8; j++) {
|
|
202
|
+
crc = (crc >>> 1) ^ (crc & 1 ? 0xedb88320 : 0);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Build a minimal valid .docx file (ZIP archive) from an array of text paragraphs.
|
|
209
|
+
* Uses STORE (no compression) for simplicity and reliability.
|
|
210
|
+
*/
|
|
211
|
+
export function buildDocx(paragraphs) {
|
|
212
|
+
const contentTypes = [
|
|
213
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
214
|
+
'<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">',
|
|
215
|
+
'<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>',
|
|
216
|
+
'<Default Extension="xml" ContentType="application/xml"/>',
|
|
217
|
+
'<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>',
|
|
218
|
+
'</Types>',
|
|
219
|
+
].join('');
|
|
220
|
+
const rels = [
|
|
221
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
222
|
+
'<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">',
|
|
223
|
+
'<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>',
|
|
224
|
+
'</Relationships>',
|
|
225
|
+
].join('');
|
|
226
|
+
const escapedParagraphs = paragraphs.map(text => {
|
|
227
|
+
const escaped = text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
228
|
+
return `<w:p><w:r><w:t xml:space="preserve">${escaped}</w:t></w:r></w:p>`;
|
|
229
|
+
});
|
|
230
|
+
const documentXml = [
|
|
231
|
+
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',
|
|
232
|
+
'<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">',
|
|
233
|
+
'<w:body>',
|
|
234
|
+
...escapedParagraphs,
|
|
235
|
+
'</w:body>',
|
|
236
|
+
'</w:document>',
|
|
237
|
+
].join('');
|
|
238
|
+
return createZip([
|
|
239
|
+
['[Content_Types].xml', contentTypes],
|
|
240
|
+
['_rels/.rels', rels],
|
|
241
|
+
['word/document.xml', documentXml],
|
|
242
|
+
]);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Create a ZIP archive from an array of [filename, textContent] entries.
|
|
246
|
+
* Uses STORE method (no compression).
|
|
247
|
+
*/
|
|
248
|
+
function createZip(files) {
|
|
249
|
+
const encoder = new TextEncoder();
|
|
250
|
+
const localParts = [];
|
|
251
|
+
const centralParts = [];
|
|
252
|
+
let offset = 0;
|
|
253
|
+
for (const [name, content] of files) {
|
|
254
|
+
const nameBytes = encoder.encode(name);
|
|
255
|
+
const contentBytes = encoder.encode(content);
|
|
256
|
+
const crc = crc32(contentBytes);
|
|
257
|
+
// Local file header (30 bytes) + name + content
|
|
258
|
+
const local = new Uint8Array(30 + nameBytes.length + contentBytes.length);
|
|
259
|
+
const lv = new DataView(local.buffer);
|
|
260
|
+
lv.setUint32(0, 0x04034b50, true);
|
|
261
|
+
lv.setUint16(4, 20, true);
|
|
262
|
+
lv.setUint16(8, 0, true); // STORE
|
|
263
|
+
lv.setUint32(14, crc, true);
|
|
264
|
+
lv.setUint32(18, contentBytes.length, true);
|
|
265
|
+
lv.setUint32(22, contentBytes.length, true);
|
|
266
|
+
lv.setUint16(26, nameBytes.length, true);
|
|
267
|
+
local.set(nameBytes, 30);
|
|
268
|
+
local.set(contentBytes, 30 + nameBytes.length);
|
|
269
|
+
localParts.push(local);
|
|
270
|
+
// Central directory entry (46 bytes) + name
|
|
271
|
+
const central = new Uint8Array(46 + nameBytes.length);
|
|
272
|
+
const cv = new DataView(central.buffer);
|
|
273
|
+
cv.setUint32(0, 0x02014b50, true);
|
|
274
|
+
cv.setUint16(4, 20, true);
|
|
275
|
+
cv.setUint16(6, 20, true);
|
|
276
|
+
cv.setUint16(10, 0, true); // STORE
|
|
277
|
+
cv.setUint32(16, crc, true);
|
|
278
|
+
cv.setUint32(20, contentBytes.length, true);
|
|
279
|
+
cv.setUint32(24, contentBytes.length, true);
|
|
280
|
+
cv.setUint16(28, nameBytes.length, true);
|
|
281
|
+
cv.setUint32(42, offset, true);
|
|
282
|
+
central.set(nameBytes, 46);
|
|
283
|
+
centralParts.push(central);
|
|
284
|
+
offset += local.length;
|
|
285
|
+
}
|
|
286
|
+
const centralDirSize = centralParts.reduce((s, c) => s + c.length, 0);
|
|
287
|
+
const endRecord = new Uint8Array(22);
|
|
288
|
+
const ev = new DataView(endRecord.buffer);
|
|
289
|
+
ev.setUint32(0, 0x06054b50, true);
|
|
290
|
+
ev.setUint16(8, files.length, true);
|
|
291
|
+
ev.setUint16(10, files.length, true);
|
|
292
|
+
ev.setUint32(12, centralDirSize, true);
|
|
293
|
+
ev.setUint32(16, offset, true);
|
|
294
|
+
const total = offset + centralDirSize + 22;
|
|
295
|
+
const result = new Uint8Array(total);
|
|
296
|
+
let pos = 0;
|
|
297
|
+
for (const part of localParts) {
|
|
298
|
+
result.set(part, pos);
|
|
299
|
+
pos += part.length;
|
|
300
|
+
}
|
|
301
|
+
for (const part of centralParts) {
|
|
302
|
+
result.set(part, pos);
|
|
303
|
+
pos += part.length;
|
|
304
|
+
}
|
|
305
|
+
result.set(endRecord, pos);
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Create a ZIP archive from binary entries (ZipEntry[]).
|
|
310
|
+
* Used by rebuildZip to repackage a modified .docx.
|
|
311
|
+
*/
|
|
312
|
+
function createZipFromBinary(entries) {
|
|
313
|
+
const encoder = new TextEncoder();
|
|
314
|
+
const localParts = [];
|
|
315
|
+
const centralParts = [];
|
|
316
|
+
let offset = 0;
|
|
317
|
+
for (const entry of entries) {
|
|
318
|
+
const nameBytes = encoder.encode(entry.name);
|
|
319
|
+
const contentBytes = entry.data;
|
|
320
|
+
const crc = crc32(contentBytes);
|
|
321
|
+
const local = new Uint8Array(30 + nameBytes.length + contentBytes.length);
|
|
322
|
+
const lv = new DataView(local.buffer);
|
|
323
|
+
lv.setUint32(0, 0x04034b50, true);
|
|
324
|
+
lv.setUint16(4, 20, true);
|
|
325
|
+
lv.setUint16(8, 0, true); // STORE
|
|
326
|
+
lv.setUint32(14, crc, true);
|
|
327
|
+
lv.setUint32(18, contentBytes.length, true);
|
|
328
|
+
lv.setUint32(22, contentBytes.length, true);
|
|
329
|
+
lv.setUint16(26, nameBytes.length, true);
|
|
330
|
+
local.set(nameBytes, 30);
|
|
331
|
+
local.set(contentBytes, 30 + nameBytes.length);
|
|
332
|
+
localParts.push(local);
|
|
333
|
+
const central = new Uint8Array(46 + nameBytes.length);
|
|
334
|
+
const cv = new DataView(central.buffer);
|
|
335
|
+
cv.setUint32(0, 0x02014b50, true);
|
|
336
|
+
cv.setUint16(4, 20, true);
|
|
337
|
+
cv.setUint16(6, 20, true);
|
|
338
|
+
cv.setUint16(10, 0, true); // STORE
|
|
339
|
+
cv.setUint32(16, crc, true);
|
|
340
|
+
cv.setUint32(20, contentBytes.length, true);
|
|
341
|
+
cv.setUint32(24, contentBytes.length, true);
|
|
342
|
+
cv.setUint16(28, nameBytes.length, true);
|
|
343
|
+
cv.setUint32(42, offset, true);
|
|
344
|
+
central.set(nameBytes, 46);
|
|
345
|
+
centralParts.push(central);
|
|
346
|
+
offset += local.length;
|
|
347
|
+
}
|
|
348
|
+
const centralDirSize = centralParts.reduce((s, c) => s + c.length, 0);
|
|
349
|
+
const endRecord = new Uint8Array(22);
|
|
350
|
+
const ev = new DataView(endRecord.buffer);
|
|
351
|
+
ev.setUint32(0, 0x06054b50, true);
|
|
352
|
+
ev.setUint16(8, entries.length, true);
|
|
353
|
+
ev.setUint16(10, entries.length, true);
|
|
354
|
+
ev.setUint32(12, centralDirSize, true);
|
|
355
|
+
ev.setUint32(16, offset, true);
|
|
356
|
+
const total = offset + centralDirSize + 22;
|
|
357
|
+
const result = new Uint8Array(total);
|
|
358
|
+
let pos = 0;
|
|
359
|
+
for (const part of localParts) {
|
|
360
|
+
result.set(part, pos);
|
|
361
|
+
pos += part.length;
|
|
362
|
+
}
|
|
363
|
+
for (const part of centralParts) {
|
|
364
|
+
result.set(part, pos);
|
|
365
|
+
pos += part.length;
|
|
366
|
+
}
|
|
367
|
+
result.set(endRecord, pos);
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=docx-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docx-utils.js","sourceRoot":"","sources":["../src/docx-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,qDAAqD;AACrD,SAAS,YAAY,CAAC,IAAgB,EAAE,MAAc;IACpD,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,qDAAqD;AACrD,SAAS,YAAY,CAAC,IAAgB,EAAE,MAAc;IACpD,OAAO,CACL,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CACxC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,QAAoB,EAAE,QAAgB;IAC1E,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,OAAO,MAAM,GAAG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AC1C,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IAClC,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtC,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACvC,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC;IACvC,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAE/B,MAAM,KAAK,GAAG,MAAM,GAAG,cAAc,GAAG,EAAE,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACtB,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACtB,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IACD,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAC3B,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OpenTabsPlugin } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
import type { ToolDefinition } from '@opentabs-dev/plugin-sdk';
|
|
3
|
+
declare class MicrosoftWordPlugin extends OpenTabsPlugin {
|
|
4
|
+
readonly name = "microsoft-word";
|
|
5
|
+
readonly description = "OpenTabs plugin for Microsoft Word Online";
|
|
6
|
+
readonly displayName = "Microsoft Word";
|
|
7
|
+
readonly urlPatterns: string[];
|
|
8
|
+
readonly homepage = "https://word.cloud.microsoft";
|
|
9
|
+
readonly tools: ToolDefinition[];
|
|
10
|
+
isReady(): Promise<boolean>;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: MicrosoftWordPlugin;
|
|
13
|
+
export default _default;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AA8B/D,cAAM,mBAAoB,SAAQ,cAAc;IAC9C,QAAQ,CAAC,IAAI,oBAAoB;IACjC,QAAQ,CAAC,WAAW,+CAA+C;IACnE,SAAkB,WAAW,oBAAoB;IACjD,QAAQ,CAAC,WAAW,WAAkC;IACtD,SAAkB,QAAQ,kCAAkC;IAC5D,QAAQ,CAAC,KAAK,EAAE,cAAc,EAAE,CAkC9B;IAEI,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;CAIlC;;AAED,wBAAyC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { OpenTabsPlugin } from '@opentabs-dev/plugin-sdk';
|
|
2
|
+
import { isAuthenticated, waitForAuth } from './microsoft-word-api.js';
|
|
3
|
+
import { appendToDocument } from './tools/append-to-document.js';
|
|
4
|
+
import { copyItem } from './tools/copy-item.js';
|
|
5
|
+
import { createDocument } from './tools/create-document.js';
|
|
6
|
+
import { createFolder } from './tools/create-folder.js';
|
|
7
|
+
import { createSharingLink } from './tools/create-sharing-link.js';
|
|
8
|
+
import { deleteItem } from './tools/delete-item.js';
|
|
9
|
+
import { deletePermission } from './tools/delete-permission.js';
|
|
10
|
+
import { getActiveDocument } from './tools/get-active-document.js';
|
|
11
|
+
import { getCurrentUser } from './tools/get-current-user.js';
|
|
12
|
+
import { getDocumentText } from './tools/get-document-text.js';
|
|
13
|
+
import { getDrive } from './tools/get-drive.js';
|
|
14
|
+
import { getFileContent } from './tools/get-file-content.js';
|
|
15
|
+
import { getItem } from './tools/get-item.js';
|
|
16
|
+
import { getPreviewUrl } from './tools/get-preview-url.js';
|
|
17
|
+
import { listChildren } from './tools/list-children.js';
|
|
18
|
+
import { listPermissions } from './tools/list-permissions.js';
|
|
19
|
+
import { listRecentDocuments } from './tools/list-recent-documents.js';
|
|
20
|
+
import { listSharedWithMe } from './tools/list-shared-with-me.js';
|
|
21
|
+
import { listVersions } from './tools/list-versions.js';
|
|
22
|
+
import { moveItem } from './tools/move-item.js';
|
|
23
|
+
import { renameItem } from './tools/rename-item.js';
|
|
24
|
+
import { replaceTextInDocument } from './tools/replace-text-in-document.js';
|
|
25
|
+
import { restoreVersion } from './tools/restore-version.js';
|
|
26
|
+
import { searchFiles } from './tools/search-files.js';
|
|
27
|
+
import { updateDocument } from './tools/update-document.js';
|
|
28
|
+
import { updateFileContent } from './tools/update-file-content.js';
|
|
29
|
+
import { uploadFile } from './tools/upload-file.js';
|
|
30
|
+
class MicrosoftWordPlugin extends OpenTabsPlugin {
|
|
31
|
+
name = 'microsoft-word';
|
|
32
|
+
description = 'OpenTabs plugin for Microsoft Word Online';
|
|
33
|
+
displayName = 'Microsoft Word';
|
|
34
|
+
urlPatterns = ['*://word.cloud.microsoft/*'];
|
|
35
|
+
homepage = 'https://word.cloud.microsoft';
|
|
36
|
+
tools = [
|
|
37
|
+
// Account
|
|
38
|
+
getCurrentUser,
|
|
39
|
+
// Drive
|
|
40
|
+
getDrive,
|
|
41
|
+
// Documents — the core document editing tools
|
|
42
|
+
getActiveDocument,
|
|
43
|
+
getDocumentText,
|
|
44
|
+
createDocument,
|
|
45
|
+
updateDocument,
|
|
46
|
+
appendToDocument,
|
|
47
|
+
replaceTextInDocument,
|
|
48
|
+
getFileContent,
|
|
49
|
+
// Files
|
|
50
|
+
listRecentDocuments,
|
|
51
|
+
listChildren,
|
|
52
|
+
getItem,
|
|
53
|
+
searchFiles,
|
|
54
|
+
createFolder,
|
|
55
|
+
uploadFile,
|
|
56
|
+
updateFileContent,
|
|
57
|
+
renameItem,
|
|
58
|
+
moveItem,
|
|
59
|
+
copyItem,
|
|
60
|
+
deleteItem,
|
|
61
|
+
listSharedWithMe,
|
|
62
|
+
getPreviewUrl,
|
|
63
|
+
// Sharing
|
|
64
|
+
createSharingLink,
|
|
65
|
+
listPermissions,
|
|
66
|
+
deletePermission,
|
|
67
|
+
// Versions
|
|
68
|
+
listVersions,
|
|
69
|
+
restoreVersion,
|
|
70
|
+
];
|
|
71
|
+
async isReady() {
|
|
72
|
+
if (isAuthenticated())
|
|
73
|
+
return true;
|
|
74
|
+
return waitForAuth();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export default new MicrosoftWordPlugin();
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,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;QACjC,UAAU;QACV,cAAc;QACd,QAAQ;QACR,QAAQ;QACR,8CAA8C;QAC9C,iBAAiB;QACjB,eAAe;QACf,cAAc;QACd,cAAc;QACd,gBAAgB;QAChB,qBAAqB;QACrB,cAAc;QACd,QAAQ;QACR,mBAAmB;QACnB,YAAY;QACZ,OAAO;QACP,WAAW;QACX,YAAY;QACZ,UAAU;QACV,iBAAiB;QACjB,UAAU;QACV,QAAQ;QACR,QAAQ;QACR,UAAU;QACV,gBAAgB;QAChB,aAAa;QACb,UAAU;QACV,iBAAiB;QACjB,eAAe;QACf,gBAAgB;QAChB,WAAW;QACX,YAAY;QACZ,cAAc;KACf,CAAC;IAEF,KAAK,CAAC,OAAO;QACX,IAAI,eAAe,EAAE;YAAE,OAAO,IAAI,CAAC;QACnC,OAAO,WAAW,EAAE,CAAC;IACvB,CAAC;CACF;AAED,eAAe,IAAI,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the raw Graph API access token.
|
|
3
|
+
* Used by tools that need raw fetch (non-JSON body uploads).
|
|
4
|
+
*/
|
|
5
|
+
export declare const getGraphToken: () => string;
|
|
6
|
+
export declare const isAuthenticated: () => boolean;
|
|
7
|
+
export declare const waitForAuth: () => Promise<boolean>;
|
|
8
|
+
/**
|
|
9
|
+
* Make an authenticated request to the Microsoft Graph API.
|
|
10
|
+
* Handles JSON responses, error classification, and token invalidation.
|
|
11
|
+
*/
|
|
12
|
+
export declare const api: <T>(endpoint: string, options?: {
|
|
13
|
+
method?: string;
|
|
14
|
+
body?: unknown;
|
|
15
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
16
|
+
}) => Promise<T>;
|
|
17
|
+
//# sourceMappingURL=microsoft-word-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"microsoft-word-api.d.ts","sourceRoot":"","sources":["../src/microsoft-word-api.ts"],"names":[],"mappings":"AA0EA;;;GAGG;AACH,eAAO,MAAM,aAAa,QAAO,MAIhC,CAAC;AAEF,eAAO,MAAM,eAAe,QAAO,OAA6B,CAAC;AAEjE,eAAO,MAAM,WAAW,QAAO,OAAO,CAAC,OAAO,CAI3C,CAAC;AAEJ;;;GAGG;AACH,eAAO,MAAM,GAAG,GAAU,CAAC,EACzB,UAAU,MAAM,EAChB,UAAS;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,CAAC;CAC1D,KACL,OAAO,CAAC,CAAC,CA2EX,CAAC"}
|