@a3s-lab/office 0.28.0 → 0.30.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 +126 -3
- package/dist/0~1403.js +1 -1
- package/dist/0~4980.js +1 -1
- package/dist/0~7048.js +1 -1
- package/dist/{0~7043.js → 0~7231.js} +400 -242
- package/dist/{0~5093.js → 0~7360.js} +293 -53
- package/dist/0~7614.js +1 -1
- package/dist/0~document-editor.js +1535 -102
- package/dist/0~presentation-editor.js +1 -1
- package/dist/0~spreadsheet-editor.js +184 -36
- package/dist/0~work-docx-export.js +437 -11
- package/dist/0~work-docx-import.js +32 -7
- package/dist/0~work-office-diagnostics.js +170 -7
- package/dist/0~work-pptx-export.js +1 -1
- package/dist/0~work-pptx-import.js +1 -1
- package/dist/0~work-presentation-charts.js +1 -1
- package/dist/1544.js +14 -2
- package/dist/4104.js +31 -8
- package/dist/4121.js +3448 -0
- package/dist/6282.js +558 -1688
- package/dist/8715.js +1 -1
- package/dist/core.js +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/features/work/editors/document-command-catalog.d.ts +27 -0
- package/dist/internal/features/work/editors/document-font-dialog-model.d.ts +8 -2
- package/dist/internal/features/work/editors/document-font-dialog-run-border-model.d.ts +24 -0
- package/dist/internal/features/work/editors/document-font-dialog-run-border-section.d.ts +10 -0
- package/dist/internal/features/work/editors/document-font-dialog-run-shading-model.d.ts +23 -0
- package/dist/internal/features/work/editors/document-font-dialog-run-shading-section.d.ts +8 -0
- package/dist/internal/features/work/editors/document-page-chrome-ribbon.d.ts +2 -1
- package/dist/internal/features/work/editors/document-proofing-dialog-model.d.ts +22 -0
- package/dist/internal/features/work/editors/document-proofing-dialog.d.ts +7 -0
- package/dist/internal/features/work/editors/document-table-of-contents-dialog.d.ts +10 -0
- package/dist/internal/features/work/editors/document-toolbar.d.ts +3 -1
- package/dist/internal/features/work/editors/spreadsheet-data-validation.d.ts +7 -1
- package/dist/internal/features/work/editors/use-document-insert-commands.d.ts +2 -0
- package/dist/internal/features/work/work-document-character-formatting.d.ts +12 -0
- package/dist/internal/features/work/work-document-format-changes.d.ts +7 -0
- package/dist/internal/features/work/work-document-highlight.d.ts +9 -0
- package/dist/internal/features/work/work-document-outline.d.ts +1 -0
- package/dist/internal/features/work/work-document-paragraph-shading.d.ts +6 -0
- package/dist/internal/features/work/work-document-proofing.d.ts +19 -0
- package/dist/internal/features/work/work-document-run-border.d.ts +11 -0
- package/dist/internal/features/work/work-document-run-shading.d.ts +12 -0
- package/dist/internal/features/work/work-document-table-of-contents-node.d.ts +18 -0
- package/dist/internal/features/work/work-document-table-of-contents.d.ts +51 -0
- package/dist/internal/features/work/work-document-word-line-metrics.d.ts +4 -0
- package/dist/internal/features/work/work-docx-field-instructions.d.ts +1 -1
- package/dist/internal/features/work/work-docx-import.d.ts +3 -1
- package/dist/internal/features/work/work-docx-proofing-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-proofing.d.ts +38 -0
- package/dist/internal/features/work/work-docx-run-border-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-run-border-export.d.ts +17 -0
- package/dist/internal/features/work/work-docx-run-border.d.ts +20 -0
- package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +9 -0
- package/dist/internal/features/work/work-docx-run-shading-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-run-shading-export.d.ts +17 -0
- package/dist/internal/features/work/work-docx-run-shading.d.ts +20 -0
- package/dist/internal/features/work/work-docx-table-of-contents-export.d.ts +11 -0
- package/dist/internal/features/work/work-docx-table-of-contents-import.d.ts +15 -0
- package/dist/internal/features/work/work-spreadsheet-data-validation.d.ts +7 -0
- package/dist/internal/features/work/work-types.d.ts +9 -0
- package/dist/internal/kernel/office-kernel-protocol.d.ts +1 -0
- package/dist/office-kernel.wasm +0 -0
- package/dist/styles.css +339 -1
- package/docs/latest/en/browser-editor-architecture.md +72 -1
- package/package.json +15 -2
- package/dist/5184.js +0 -662
- package/dist/9424.js +0 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import jszip from "jszip";
|
|
2
|
-
import { serializeUtf8Xml, directChildren, xmlNamespacePrefix, parseXml, firstDescendant, decodeXmlBytes, directChild, descendants, attribute as work_ooxml_package_attribute } from "./
|
|
2
|
+
import { serializeUtf8Xml, directChildren, xmlNamespacePrefix, normalizeDocumentLanguageTag, parseXml, firstDescendant, decodeXmlBytes, directChild, descendants, normalizeDocumentProofingLanguages, attribute as work_ooxml_package_attribute } from "./4121.js";
|
|
3
3
|
import { normalizeDocumentEmphasisMark, normalizeDocumentCharacterScalePercent, documentCitationStyle, normalizeDocumentKerningThresholdHalfPoints, normalizeDocumentCharacterPositionHalfPoints, normalizeDocumentCharacterSpacingTwips, normalizeDocumentTabStops, createDocumentBibliography, documentCitationStyleDetails } from "./6282.js";
|
|
4
4
|
const BIBLIOGRAPHY_NAMESPACE = 'http://schemas.openxmlformats.org/officeDocument/2006/bibliography';
|
|
5
5
|
const CUSTOM_XML_NAMESPACE = 'http://schemas.openxmlformats.org/officeDocument/2006/customXml';
|
|
@@ -1011,6 +1011,404 @@ function docxEmphasisMarkRunOptions(value) {
|
|
|
1011
1011
|
type: emphasisMark
|
|
1012
1012
|
};
|
|
1013
1013
|
}
|
|
1014
|
+
const WORD_THEME_COLOR_KEYS = new Map([
|
|
1015
|
+
[
|
|
1016
|
+
'dark1',
|
|
1017
|
+
'dk1'
|
|
1018
|
+
],
|
|
1019
|
+
[
|
|
1020
|
+
'light1',
|
|
1021
|
+
'lt1'
|
|
1022
|
+
],
|
|
1023
|
+
[
|
|
1024
|
+
'dark2',
|
|
1025
|
+
'dk2'
|
|
1026
|
+
],
|
|
1027
|
+
[
|
|
1028
|
+
'light2',
|
|
1029
|
+
'lt2'
|
|
1030
|
+
],
|
|
1031
|
+
[
|
|
1032
|
+
'background1',
|
|
1033
|
+
'lt1'
|
|
1034
|
+
],
|
|
1035
|
+
[
|
|
1036
|
+
'text1',
|
|
1037
|
+
'dk1'
|
|
1038
|
+
],
|
|
1039
|
+
[
|
|
1040
|
+
'background2',
|
|
1041
|
+
'lt2'
|
|
1042
|
+
],
|
|
1043
|
+
[
|
|
1044
|
+
'text2',
|
|
1045
|
+
'dk2'
|
|
1046
|
+
],
|
|
1047
|
+
[
|
|
1048
|
+
'hyperlink',
|
|
1049
|
+
'hlink'
|
|
1050
|
+
],
|
|
1051
|
+
[
|
|
1052
|
+
'followedhyperlink',
|
|
1053
|
+
'folhlink'
|
|
1054
|
+
]
|
|
1055
|
+
]);
|
|
1056
|
+
const DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES = new Map([
|
|
1057
|
+
[
|
|
1058
|
+
'background1',
|
|
1059
|
+
'bg1'
|
|
1060
|
+
],
|
|
1061
|
+
[
|
|
1062
|
+
'text1',
|
|
1063
|
+
't1'
|
|
1064
|
+
],
|
|
1065
|
+
[
|
|
1066
|
+
'background2',
|
|
1067
|
+
'bg2'
|
|
1068
|
+
],
|
|
1069
|
+
[
|
|
1070
|
+
'text2',
|
|
1071
|
+
't2'
|
|
1072
|
+
],
|
|
1073
|
+
[
|
|
1074
|
+
'accent1',
|
|
1075
|
+
'accent1'
|
|
1076
|
+
],
|
|
1077
|
+
[
|
|
1078
|
+
'accent2',
|
|
1079
|
+
'accent2'
|
|
1080
|
+
],
|
|
1081
|
+
[
|
|
1082
|
+
'accent3',
|
|
1083
|
+
'accent3'
|
|
1084
|
+
],
|
|
1085
|
+
[
|
|
1086
|
+
'accent4',
|
|
1087
|
+
'accent4'
|
|
1088
|
+
],
|
|
1089
|
+
[
|
|
1090
|
+
'accent5',
|
|
1091
|
+
'accent5'
|
|
1092
|
+
],
|
|
1093
|
+
[
|
|
1094
|
+
'accent6',
|
|
1095
|
+
'accent6'
|
|
1096
|
+
],
|
|
1097
|
+
[
|
|
1098
|
+
'hyperlink',
|
|
1099
|
+
'hyperlink'
|
|
1100
|
+
],
|
|
1101
|
+
[
|
|
1102
|
+
'followedhyperlink',
|
|
1103
|
+
'followedHyperlink'
|
|
1104
|
+
]
|
|
1105
|
+
]);
|
|
1106
|
+
const WORD_COLOR_SCHEME_INDEXES = new Set([
|
|
1107
|
+
'dark1',
|
|
1108
|
+
'light1',
|
|
1109
|
+
'dark2',
|
|
1110
|
+
'light2',
|
|
1111
|
+
'accent1',
|
|
1112
|
+
'accent2',
|
|
1113
|
+
'accent3',
|
|
1114
|
+
'accent4',
|
|
1115
|
+
'accent5',
|
|
1116
|
+
'accent6',
|
|
1117
|
+
'hyperlink',
|
|
1118
|
+
'followedHyperlink'
|
|
1119
|
+
]);
|
|
1120
|
+
const WORDPROCESSING_NAMESPACES = new Set([
|
|
1121
|
+
'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
|
|
1122
|
+
'http://purl.oclc.org/ooxml/wordprocessingml/main'
|
|
1123
|
+
]);
|
|
1124
|
+
const MAX_COLOR_MAPPING_DEPTH = 16;
|
|
1125
|
+
function createDocxThemeResolver(themeDocument, settingsDocument) {
|
|
1126
|
+
const colorMapping = docxColorSchemeMapping(settingsDocument);
|
|
1127
|
+
if (!themeDocument) return {
|
|
1128
|
+
colors: new Map(),
|
|
1129
|
+
colorMapping,
|
|
1130
|
+
fonts: new Map()
|
|
1131
|
+
};
|
|
1132
|
+
const fonts = new Map();
|
|
1133
|
+
const fontScheme = firstDescendant(themeDocument, 'fontScheme');
|
|
1134
|
+
addThemeFontFamily(fonts, 'major', fontScheme ? directChild(fontScheme, 'majorFont') : void 0);
|
|
1135
|
+
addThemeFontFamily(fonts, 'minor', fontScheme ? directChild(fontScheme, 'minorFont') : void 0);
|
|
1136
|
+
const colors = new Map();
|
|
1137
|
+
const colorScheme = firstDescendant(themeDocument, 'clrScheme');
|
|
1138
|
+
if (colorScheme) for (const entry of directChildren(colorScheme)){
|
|
1139
|
+
const color = themeColorValue(directChildren(entry)[0]);
|
|
1140
|
+
if (color) colors.set(entry.localName.toLowerCase(), color);
|
|
1141
|
+
}
|
|
1142
|
+
return {
|
|
1143
|
+
colors,
|
|
1144
|
+
colorMapping,
|
|
1145
|
+
fonts
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
function resolveDocxThemeResolver(source) {
|
|
1149
|
+
return isDocxThemeResolver(source) ? source : createDocxThemeResolver(source);
|
|
1150
|
+
}
|
|
1151
|
+
function docxThemeFont(resolver, key) {
|
|
1152
|
+
return key ? resolver.fonts.get(key.trim().toLowerCase()) : void 0;
|
|
1153
|
+
}
|
|
1154
|
+
function docxThemeColor(resolver, key, tint, shade) {
|
|
1155
|
+
const sourceKey = key?.trim().toLowerCase();
|
|
1156
|
+
const mappedKey = sourceKey ? mappedWordThemeColorKey(sourceKey, resolver.colorMapping) : void 0;
|
|
1157
|
+
const colorKey = mappedKey ? WORD_THEME_COLOR_KEYS.get(mappedKey) ?? mappedKey : void 0;
|
|
1158
|
+
const color = colorKey ? resolver.colors.get(colorKey) : void 0;
|
|
1159
|
+
if (!color) return;
|
|
1160
|
+
const channels = [
|
|
1161
|
+
Number.parseInt(color.slice(0, 2), 16),
|
|
1162
|
+
Number.parseInt(color.slice(2, 4), 16),
|
|
1163
|
+
Number.parseInt(color.slice(4, 6), 16)
|
|
1164
|
+
];
|
|
1165
|
+
const shadeFactor = hexFactor(shade);
|
|
1166
|
+
const tintFactor = hexFactor(tint);
|
|
1167
|
+
const transformed = channels.map((channel)=>{
|
|
1168
|
+
const shaded = void 0 === shadeFactor ? channel : channel * shadeFactor;
|
|
1169
|
+
const tinted = void 0 === tintFactor ? shaded : shaded + (255 - shaded) * tintFactor;
|
|
1170
|
+
return Math.max(0, Math.min(255, Math.round(tinted)));
|
|
1171
|
+
});
|
|
1172
|
+
return transformed.map((channel)=>channel.toString(16).padStart(2, '0')).join('');
|
|
1173
|
+
}
|
|
1174
|
+
function docxColorSchemeMapping(settingsDocument) {
|
|
1175
|
+
const root = settingsDocument?.documentElement;
|
|
1176
|
+
if (!root || 'settings' !== root.localName || !WORDPROCESSING_NAMESPACES.has(root.namespaceURI ?? '')) return new Map();
|
|
1177
|
+
const candidates = directChildren(root, 'clrSchemeMapping').filter((element)=>element.namespaceURI === root.namespaceURI);
|
|
1178
|
+
if (1 !== candidates.length) return new Map();
|
|
1179
|
+
return parseDocxColorSchemeMappingElement(candidates[0]) ?? new Map();
|
|
1180
|
+
}
|
|
1181
|
+
function parseDocxColorSchemeMappingElement(element) {
|
|
1182
|
+
const namespace = element?.namespaceURI ?? '';
|
|
1183
|
+
if (!element || 'clrSchemeMapping' !== element.localName || !WORDPROCESSING_NAMESPACES.has(namespace) || directChildren(element).length || Array.from(element.childNodes).some((node)=>node.nodeType === Node.TEXT_NODE && node.textContent?.trim())) return null;
|
|
1184
|
+
const semanticsByAttribute = new Map(Array.from(DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES).map(([semantic, attributeName])=>[
|
|
1185
|
+
attributeName,
|
|
1186
|
+
semantic
|
|
1187
|
+
]));
|
|
1188
|
+
const mapping = new Map();
|
|
1189
|
+
for (const item of Array.from(element.attributes)){
|
|
1190
|
+
if (item.namespaceURI === XMLNS_NAMESPACE || 'xmlns' === item.name || item.name.startsWith('xmlns:')) continue;
|
|
1191
|
+
const attributeName = xmlAttributeLocalName(item);
|
|
1192
|
+
const semantic = semanticsByAttribute.get(attributeName);
|
|
1193
|
+
const value = item.value.trim();
|
|
1194
|
+
if (xmlAttributeNamespace(element, item) !== namespace || !semantic || mapping.has(semantic) || !WORD_COLOR_SCHEME_INDEXES.has(value)) return null;
|
|
1195
|
+
mapping.set(semantic, value);
|
|
1196
|
+
}
|
|
1197
|
+
return mapping;
|
|
1198
|
+
}
|
|
1199
|
+
function mappedWordThemeColorKey(source, mapping) {
|
|
1200
|
+
let current = source;
|
|
1201
|
+
const visited = new Set();
|
|
1202
|
+
for(let depth = 0; depth < MAX_COLOR_MAPPING_DEPTH; depth += 1){
|
|
1203
|
+
if (visited.has(current)) break;
|
|
1204
|
+
visited.add(current);
|
|
1205
|
+
const next = mapping?.get(current)?.toLowerCase();
|
|
1206
|
+
if (!next || next === current) return current;
|
|
1207
|
+
current = next;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
function addThemeFontFamily(fonts, prefix, family) {
|
|
1211
|
+
if (!family) return;
|
|
1212
|
+
const latin = typeface(directChild(family, 'latin'));
|
|
1213
|
+
const eastAsia = typeface(directChild(family, 'ea')) || scriptTypeface(family, [
|
|
1214
|
+
'Hans',
|
|
1215
|
+
'Hant',
|
|
1216
|
+
'Jpan',
|
|
1217
|
+
'Hang'
|
|
1218
|
+
]) || latin;
|
|
1219
|
+
const complex = typeface(directChild(family, 'cs')) || latin;
|
|
1220
|
+
if (latin) {
|
|
1221
|
+
fonts.set(`${prefix}ascii`, latin);
|
|
1222
|
+
fonts.set(`${prefix}hansi`, latin);
|
|
1223
|
+
}
|
|
1224
|
+
if (eastAsia) fonts.set(`${prefix}eastasia`, eastAsia);
|
|
1225
|
+
if (complex) fonts.set(`${prefix}bidi`, complex);
|
|
1226
|
+
}
|
|
1227
|
+
function scriptTypeface(family, scripts) {
|
|
1228
|
+
const fonts = directChildren(family, 'font');
|
|
1229
|
+
for (const script of scripts){
|
|
1230
|
+
const font = fonts.find((candidate)=>drawingAttribute(candidate, "script") === script);
|
|
1231
|
+
const value = font ? typeface(font) : void 0;
|
|
1232
|
+
if (value) return value;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
function typeface(element) {
|
|
1236
|
+
const value = element ? drawingAttribute(element, 'typeface')?.trim() : void 0;
|
|
1237
|
+
return value || void 0;
|
|
1238
|
+
}
|
|
1239
|
+
function themeColorValue(element) {
|
|
1240
|
+
if (!element) return;
|
|
1241
|
+
const value = 'sysClr' === element.localName ? drawingAttribute(element, 'lastClr') : drawingAttribute(element, 'val');
|
|
1242
|
+
return value && /^[0-9a-f]{6}$/i.test(value) ? value.toLowerCase() : void 0;
|
|
1243
|
+
}
|
|
1244
|
+
function drawingAttribute(element, name) {
|
|
1245
|
+
return work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `a:${name}`);
|
|
1246
|
+
}
|
|
1247
|
+
function hexFactor(value) {
|
|
1248
|
+
if (!value || !/^[0-9a-f]{2}$/i.test(value)) return;
|
|
1249
|
+
return Number.parseInt(value, 16) / 255;
|
|
1250
|
+
}
|
|
1251
|
+
function isDocxThemeResolver(source) {
|
|
1252
|
+
return Boolean(source && 'colors' in source && source.colors instanceof Map && 'fonts' in source && source.fonts instanceof Map);
|
|
1253
|
+
}
|
|
1254
|
+
const LANGUAGE_ATTRIBUTES = new Map([
|
|
1255
|
+
[
|
|
1256
|
+
'val',
|
|
1257
|
+
'latin'
|
|
1258
|
+
],
|
|
1259
|
+
[
|
|
1260
|
+
'eastAsia',
|
|
1261
|
+
'eastAsia'
|
|
1262
|
+
],
|
|
1263
|
+
[
|
|
1264
|
+
'bidi',
|
|
1265
|
+
'bidi'
|
|
1266
|
+
]
|
|
1267
|
+
]);
|
|
1268
|
+
function inspectDocxProofingLanguages(properties) {
|
|
1269
|
+
if (!properties) return {
|
|
1270
|
+
status: 'absent',
|
|
1271
|
+
spoofedCount: 0
|
|
1272
|
+
};
|
|
1273
|
+
const matches = directChildren(properties, 'lang');
|
|
1274
|
+
if (!matches.length) return {
|
|
1275
|
+
status: 'absent',
|
|
1276
|
+
spoofedCount: 0
|
|
1277
|
+
};
|
|
1278
|
+
const native = matches.filter((element)=>isWordElement(element));
|
|
1279
|
+
const spoofedCount = matches.length - native.length;
|
|
1280
|
+
if (1 !== matches.length || 1 !== native.length) return {
|
|
1281
|
+
status: 'invalid',
|
|
1282
|
+
spoofedCount
|
|
1283
|
+
};
|
|
1284
|
+
const element = native[0];
|
|
1285
|
+
if (!element || element.childNodes.length) return {
|
|
1286
|
+
status: 'invalid',
|
|
1287
|
+
spoofedCount
|
|
1288
|
+
};
|
|
1289
|
+
const languages = {};
|
|
1290
|
+
for (const attribute of Array.from(element.attributes)){
|
|
1291
|
+
if (work_docx_proofing_isNamespaceDeclaration(attribute)) continue;
|
|
1292
|
+
const name = wordAttributeLocalName(element, attribute);
|
|
1293
|
+
const slot = name ? LANGUAGE_ATTRIBUTES.get(name) : void 0;
|
|
1294
|
+
if (!slot) return {
|
|
1295
|
+
status: 'invalid',
|
|
1296
|
+
spoofedCount
|
|
1297
|
+
};
|
|
1298
|
+
const language = normalizeDocumentLanguageTag(attribute.value);
|
|
1299
|
+
if (!language) return {
|
|
1300
|
+
status: 'invalid',
|
|
1301
|
+
spoofedCount
|
|
1302
|
+
};
|
|
1303
|
+
languages[slot] = language;
|
|
1304
|
+
}
|
|
1305
|
+
return Object.keys(languages).length ? {
|
|
1306
|
+
status: 'valid',
|
|
1307
|
+
value: languages,
|
|
1308
|
+
spoofedCount
|
|
1309
|
+
} : {
|
|
1310
|
+
status: 'invalid',
|
|
1311
|
+
spoofedCount
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
function inspectDocxNoProof(properties) {
|
|
1315
|
+
if (!properties) return {
|
|
1316
|
+
status: 'absent',
|
|
1317
|
+
spoofedCount: 0
|
|
1318
|
+
};
|
|
1319
|
+
const matches = directChildren(properties, 'noProof');
|
|
1320
|
+
if (!matches.length) return {
|
|
1321
|
+
status: 'absent',
|
|
1322
|
+
spoofedCount: 0
|
|
1323
|
+
};
|
|
1324
|
+
const native = matches.filter((element)=>isWordElement(element));
|
|
1325
|
+
const spoofedCount = matches.length - native.length;
|
|
1326
|
+
if (1 !== matches.length || 1 !== native.length) return {
|
|
1327
|
+
status: 'invalid',
|
|
1328
|
+
spoofedCount
|
|
1329
|
+
};
|
|
1330
|
+
const element = native[0];
|
|
1331
|
+
if (!element || element.childNodes.length) return {
|
|
1332
|
+
status: 'invalid',
|
|
1333
|
+
spoofedCount
|
|
1334
|
+
};
|
|
1335
|
+
const attributes = Array.from(element.attributes).filter((attribute)=>!work_docx_proofing_isNamespaceDeclaration(attribute));
|
|
1336
|
+
if (attributes.length > 1 || attributes.some((attribute)=>'val' !== wordAttributeLocalName(element, attribute))) return {
|
|
1337
|
+
status: 'invalid',
|
|
1338
|
+
spoofedCount
|
|
1339
|
+
};
|
|
1340
|
+
if (!attributes.length) return {
|
|
1341
|
+
status: 'valid',
|
|
1342
|
+
value: true,
|
|
1343
|
+
spoofedCount
|
|
1344
|
+
};
|
|
1345
|
+
const value = onOffValue(attributes[0]?.value);
|
|
1346
|
+
return void 0 === value ? {
|
|
1347
|
+
status: 'invalid',
|
|
1348
|
+
spoofedCount
|
|
1349
|
+
} : {
|
|
1350
|
+
status: 'valid',
|
|
1351
|
+
value,
|
|
1352
|
+
spoofedCount
|
|
1353
|
+
};
|
|
1354
|
+
}
|
|
1355
|
+
function resolveDocxProofing(propertySources) {
|
|
1356
|
+
let languages;
|
|
1357
|
+
let noProof;
|
|
1358
|
+
let invalidCount = 0;
|
|
1359
|
+
let spoofedCount = 0;
|
|
1360
|
+
for (const properties of propertySources){
|
|
1361
|
+
const languageInspection = inspectDocxProofingLanguages(properties);
|
|
1362
|
+
spoofedCount += languageInspection.spoofedCount;
|
|
1363
|
+
if ('valid' === languageInspection.status) languages = {
|
|
1364
|
+
...languages,
|
|
1365
|
+
...languageInspection.value
|
|
1366
|
+
};
|
|
1367
|
+
else if ('invalid' === languageInspection.status) invalidCount += 1;
|
|
1368
|
+
const noProofInspection = inspectDocxNoProof(properties);
|
|
1369
|
+
spoofedCount += noProofInspection.spoofedCount;
|
|
1370
|
+
if ('valid' === noProofInspection.status) noProof = noProofInspection.value;
|
|
1371
|
+
else if ('invalid' === noProofInspection.status) invalidCount += 1;
|
|
1372
|
+
}
|
|
1373
|
+
return {
|
|
1374
|
+
languages,
|
|
1375
|
+
noProof,
|
|
1376
|
+
invalidCount,
|
|
1377
|
+
spoofedCount
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
function documentProofingLanguageDocxOptions(source) {
|
|
1381
|
+
const languages = normalizeDocumentProofingLanguages(source);
|
|
1382
|
+
if (!languages) return;
|
|
1383
|
+
return {
|
|
1384
|
+
...languages.latin ? {
|
|
1385
|
+
value: languages.latin
|
|
1386
|
+
} : {},
|
|
1387
|
+
...languages.eastAsia ? {
|
|
1388
|
+
eastAsia: languages.eastAsia
|
|
1389
|
+
} : {},
|
|
1390
|
+
...languages.bidi ? {
|
|
1391
|
+
bidirectional: languages.bidi
|
|
1392
|
+
} : {}
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
function isWordElement(element) {
|
|
1396
|
+
return DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? '');
|
|
1397
|
+
}
|
|
1398
|
+
function work_docx_proofing_isNamespaceDeclaration(attribute) {
|
|
1399
|
+
return 'xmlns' === attribute.name || 'xmlns' === attribute.prefix || 'http://www.w3.org/2000/xmlns/' === attribute.namespaceURI;
|
|
1400
|
+
}
|
|
1401
|
+
function wordAttributeLocalName(element, attribute) {
|
|
1402
|
+
if (attribute.namespaceURI === element.namespaceURI) return attribute.localName;
|
|
1403
|
+
const prefix = element.prefix ?? element.tagName.split(':')[0];
|
|
1404
|
+
const lexicalPrefix = prefix ? `${prefix}:` : '';
|
|
1405
|
+
return null === attribute.namespaceURI && lexicalPrefix && attribute.name.startsWith(lexicalPrefix) ? attribute.name.slice(lexicalPrefix.length) : null;
|
|
1406
|
+
}
|
|
1407
|
+
function onOffValue(source) {
|
|
1408
|
+
const value = source?.trim().toLowerCase();
|
|
1409
|
+
if ('1' === value || 'true' === value || 'on' === value) return true;
|
|
1410
|
+
if ('0' === value || 'false' === value || 'off' === value) return false;
|
|
1411
|
+
}
|
|
1014
1412
|
function paragraphAlignment(element, docx) {
|
|
1015
1413
|
const alignment = element.style.textAlign;
|
|
1016
1414
|
if ('center' === alignment) return docx.AlignmentType.CENTER;
|
|
@@ -1339,244 +1737,4 @@ function isParagraphPartRoot(root, path) {
|
|
|
1339
1737
|
const expected = /^word\/header\d*\.xml$/i.test(path) ? 'hdr' : /^word\/footer\d*\.xml$/i.test(path) ? 'ftr' : /^word\/footnotes\.xml$/i.test(path) ? 'footnotes' : /^word\/endnotes\.xml$/i.test(path) ? 'endnotes' : 'document';
|
|
1340
1738
|
return root.localName === expected && DOCX_WORDPROCESSING_NAMESPACES.has(root.namespaceURI ?? '');
|
|
1341
1739
|
}
|
|
1342
|
-
|
|
1343
|
-
[
|
|
1344
|
-
'dark1',
|
|
1345
|
-
'dk1'
|
|
1346
|
-
],
|
|
1347
|
-
[
|
|
1348
|
-
'light1',
|
|
1349
|
-
'lt1'
|
|
1350
|
-
],
|
|
1351
|
-
[
|
|
1352
|
-
'dark2',
|
|
1353
|
-
'dk2'
|
|
1354
|
-
],
|
|
1355
|
-
[
|
|
1356
|
-
'light2',
|
|
1357
|
-
'lt2'
|
|
1358
|
-
],
|
|
1359
|
-
[
|
|
1360
|
-
'background1',
|
|
1361
|
-
'lt1'
|
|
1362
|
-
],
|
|
1363
|
-
[
|
|
1364
|
-
'text1',
|
|
1365
|
-
'dk1'
|
|
1366
|
-
],
|
|
1367
|
-
[
|
|
1368
|
-
'background2',
|
|
1369
|
-
'lt2'
|
|
1370
|
-
],
|
|
1371
|
-
[
|
|
1372
|
-
'text2',
|
|
1373
|
-
'dk2'
|
|
1374
|
-
],
|
|
1375
|
-
[
|
|
1376
|
-
'hyperlink',
|
|
1377
|
-
'hlink'
|
|
1378
|
-
],
|
|
1379
|
-
[
|
|
1380
|
-
'followedhyperlink',
|
|
1381
|
-
'folhlink'
|
|
1382
|
-
]
|
|
1383
|
-
]);
|
|
1384
|
-
const DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES = new Map([
|
|
1385
|
-
[
|
|
1386
|
-
'background1',
|
|
1387
|
-
'bg1'
|
|
1388
|
-
],
|
|
1389
|
-
[
|
|
1390
|
-
'text1',
|
|
1391
|
-
't1'
|
|
1392
|
-
],
|
|
1393
|
-
[
|
|
1394
|
-
'background2',
|
|
1395
|
-
'bg2'
|
|
1396
|
-
],
|
|
1397
|
-
[
|
|
1398
|
-
'text2',
|
|
1399
|
-
't2'
|
|
1400
|
-
],
|
|
1401
|
-
[
|
|
1402
|
-
'accent1',
|
|
1403
|
-
'accent1'
|
|
1404
|
-
],
|
|
1405
|
-
[
|
|
1406
|
-
'accent2',
|
|
1407
|
-
'accent2'
|
|
1408
|
-
],
|
|
1409
|
-
[
|
|
1410
|
-
'accent3',
|
|
1411
|
-
'accent3'
|
|
1412
|
-
],
|
|
1413
|
-
[
|
|
1414
|
-
'accent4',
|
|
1415
|
-
'accent4'
|
|
1416
|
-
],
|
|
1417
|
-
[
|
|
1418
|
-
'accent5',
|
|
1419
|
-
'accent5'
|
|
1420
|
-
],
|
|
1421
|
-
[
|
|
1422
|
-
'accent6',
|
|
1423
|
-
'accent6'
|
|
1424
|
-
],
|
|
1425
|
-
[
|
|
1426
|
-
'hyperlink',
|
|
1427
|
-
'hyperlink'
|
|
1428
|
-
],
|
|
1429
|
-
[
|
|
1430
|
-
'followedhyperlink',
|
|
1431
|
-
'followedHyperlink'
|
|
1432
|
-
]
|
|
1433
|
-
]);
|
|
1434
|
-
const WORD_COLOR_SCHEME_INDEXES = new Set([
|
|
1435
|
-
'dark1',
|
|
1436
|
-
'light1',
|
|
1437
|
-
'dark2',
|
|
1438
|
-
'light2',
|
|
1439
|
-
'accent1',
|
|
1440
|
-
'accent2',
|
|
1441
|
-
'accent3',
|
|
1442
|
-
'accent4',
|
|
1443
|
-
'accent5',
|
|
1444
|
-
'accent6',
|
|
1445
|
-
'hyperlink',
|
|
1446
|
-
'followedHyperlink'
|
|
1447
|
-
]);
|
|
1448
|
-
const WORDPROCESSING_NAMESPACES = new Set([
|
|
1449
|
-
'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
|
|
1450
|
-
'http://purl.oclc.org/ooxml/wordprocessingml/main'
|
|
1451
|
-
]);
|
|
1452
|
-
const MAX_COLOR_MAPPING_DEPTH = 16;
|
|
1453
|
-
function createDocxThemeResolver(themeDocument, settingsDocument) {
|
|
1454
|
-
const colorMapping = docxColorSchemeMapping(settingsDocument);
|
|
1455
|
-
if (!themeDocument) return {
|
|
1456
|
-
colors: new Map(),
|
|
1457
|
-
colorMapping,
|
|
1458
|
-
fonts: new Map()
|
|
1459
|
-
};
|
|
1460
|
-
const fonts = new Map();
|
|
1461
|
-
const fontScheme = firstDescendant(themeDocument, 'fontScheme');
|
|
1462
|
-
addThemeFontFamily(fonts, 'major', fontScheme ? directChild(fontScheme, 'majorFont') : void 0);
|
|
1463
|
-
addThemeFontFamily(fonts, 'minor', fontScheme ? directChild(fontScheme, 'minorFont') : void 0);
|
|
1464
|
-
const colors = new Map();
|
|
1465
|
-
const colorScheme = firstDescendant(themeDocument, 'clrScheme');
|
|
1466
|
-
if (colorScheme) for (const entry of directChildren(colorScheme)){
|
|
1467
|
-
const color = themeColorValue(directChildren(entry)[0]);
|
|
1468
|
-
if (color) colors.set(entry.localName.toLowerCase(), color);
|
|
1469
|
-
}
|
|
1470
|
-
return {
|
|
1471
|
-
colors,
|
|
1472
|
-
colorMapping,
|
|
1473
|
-
fonts
|
|
1474
|
-
};
|
|
1475
|
-
}
|
|
1476
|
-
function resolveDocxThemeResolver(source) {
|
|
1477
|
-
return isDocxThemeResolver(source) ? source : createDocxThemeResolver(source);
|
|
1478
|
-
}
|
|
1479
|
-
function docxThemeFont(resolver, key) {
|
|
1480
|
-
return key ? resolver.fonts.get(key.trim().toLowerCase()) : void 0;
|
|
1481
|
-
}
|
|
1482
|
-
function docxThemeColor(resolver, key, tint, shade) {
|
|
1483
|
-
const sourceKey = key?.trim().toLowerCase();
|
|
1484
|
-
const mappedKey = sourceKey ? mappedWordThemeColorKey(sourceKey, resolver.colorMapping) : void 0;
|
|
1485
|
-
const colorKey = mappedKey ? WORD_THEME_COLOR_KEYS.get(mappedKey) ?? mappedKey : void 0;
|
|
1486
|
-
const color = colorKey ? resolver.colors.get(colorKey) : void 0;
|
|
1487
|
-
if (!color) return;
|
|
1488
|
-
const channels = [
|
|
1489
|
-
Number.parseInt(color.slice(0, 2), 16),
|
|
1490
|
-
Number.parseInt(color.slice(2, 4), 16),
|
|
1491
|
-
Number.parseInt(color.slice(4, 6), 16)
|
|
1492
|
-
];
|
|
1493
|
-
const shadeFactor = hexFactor(shade);
|
|
1494
|
-
const tintFactor = hexFactor(tint);
|
|
1495
|
-
const transformed = channels.map((channel)=>{
|
|
1496
|
-
const shaded = void 0 === shadeFactor ? channel : channel * shadeFactor;
|
|
1497
|
-
const tinted = void 0 === tintFactor ? shaded : shaded + (255 - shaded) * tintFactor;
|
|
1498
|
-
return Math.max(0, Math.min(255, Math.round(tinted)));
|
|
1499
|
-
});
|
|
1500
|
-
return transformed.map((channel)=>channel.toString(16).padStart(2, '0')).join('');
|
|
1501
|
-
}
|
|
1502
|
-
function docxColorSchemeMapping(settingsDocument) {
|
|
1503
|
-
const root = settingsDocument?.documentElement;
|
|
1504
|
-
if (!root || 'settings' !== root.localName || !WORDPROCESSING_NAMESPACES.has(root.namespaceURI ?? '')) return new Map();
|
|
1505
|
-
const candidates = directChildren(root, 'clrSchemeMapping').filter((element)=>element.namespaceURI === root.namespaceURI);
|
|
1506
|
-
if (1 !== candidates.length) return new Map();
|
|
1507
|
-
return parseDocxColorSchemeMappingElement(candidates[0]) ?? new Map();
|
|
1508
|
-
}
|
|
1509
|
-
function parseDocxColorSchemeMappingElement(element) {
|
|
1510
|
-
const namespace = element?.namespaceURI ?? '';
|
|
1511
|
-
if (!element || 'clrSchemeMapping' !== element.localName || !WORDPROCESSING_NAMESPACES.has(namespace) || directChildren(element).length || Array.from(element.childNodes).some((node)=>node.nodeType === Node.TEXT_NODE && node.textContent?.trim())) return null;
|
|
1512
|
-
const semanticsByAttribute = new Map(Array.from(DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES).map(([semantic, attributeName])=>[
|
|
1513
|
-
attributeName,
|
|
1514
|
-
semantic
|
|
1515
|
-
]));
|
|
1516
|
-
const mapping = new Map();
|
|
1517
|
-
for (const item of Array.from(element.attributes)){
|
|
1518
|
-
if (item.namespaceURI === XMLNS_NAMESPACE || 'xmlns' === item.name || item.name.startsWith('xmlns:')) continue;
|
|
1519
|
-
const attributeName = xmlAttributeLocalName(item);
|
|
1520
|
-
const semantic = semanticsByAttribute.get(attributeName);
|
|
1521
|
-
const value = item.value.trim();
|
|
1522
|
-
if (xmlAttributeNamespace(element, item) !== namespace || !semantic || mapping.has(semantic) || !WORD_COLOR_SCHEME_INDEXES.has(value)) return null;
|
|
1523
|
-
mapping.set(semantic, value);
|
|
1524
|
-
}
|
|
1525
|
-
return mapping;
|
|
1526
|
-
}
|
|
1527
|
-
function mappedWordThemeColorKey(source, mapping) {
|
|
1528
|
-
let current = source;
|
|
1529
|
-
const visited = new Set();
|
|
1530
|
-
for(let depth = 0; depth < MAX_COLOR_MAPPING_DEPTH; depth += 1){
|
|
1531
|
-
if (visited.has(current)) break;
|
|
1532
|
-
visited.add(current);
|
|
1533
|
-
const next = mapping?.get(current)?.toLowerCase();
|
|
1534
|
-
if (!next || next === current) return current;
|
|
1535
|
-
current = next;
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
function addThemeFontFamily(fonts, prefix, family) {
|
|
1539
|
-
if (!family) return;
|
|
1540
|
-
const latin = typeface(directChild(family, 'latin'));
|
|
1541
|
-
const eastAsia = typeface(directChild(family, 'ea')) || scriptTypeface(family, [
|
|
1542
|
-
'Hans',
|
|
1543
|
-
'Hant',
|
|
1544
|
-
'Jpan',
|
|
1545
|
-
'Hang'
|
|
1546
|
-
]) || latin;
|
|
1547
|
-
const complex = typeface(directChild(family, 'cs')) || latin;
|
|
1548
|
-
if (latin) {
|
|
1549
|
-
fonts.set(`${prefix}ascii`, latin);
|
|
1550
|
-
fonts.set(`${prefix}hansi`, latin);
|
|
1551
|
-
}
|
|
1552
|
-
if (eastAsia) fonts.set(`${prefix}eastasia`, eastAsia);
|
|
1553
|
-
if (complex) fonts.set(`${prefix}bidi`, complex);
|
|
1554
|
-
}
|
|
1555
|
-
function scriptTypeface(family, scripts) {
|
|
1556
|
-
const fonts = directChildren(family, 'font');
|
|
1557
|
-
for (const script of scripts){
|
|
1558
|
-
const font = fonts.find((candidate)=>drawingAttribute(candidate, "script") === script);
|
|
1559
|
-
const value = font ? typeface(font) : void 0;
|
|
1560
|
-
if (value) return value;
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
function typeface(element) {
|
|
1564
|
-
const value = element ? drawingAttribute(element, 'typeface')?.trim() : void 0;
|
|
1565
|
-
return value || void 0;
|
|
1566
|
-
}
|
|
1567
|
-
function themeColorValue(element) {
|
|
1568
|
-
if (!element) return;
|
|
1569
|
-
const value = 'sysClr' === element.localName ? drawingAttribute(element, 'lastClr') : drawingAttribute(element, 'val');
|
|
1570
|
-
return value && /^[0-9a-f]{6}$/i.test(value) ? value.toLowerCase() : void 0;
|
|
1571
|
-
}
|
|
1572
|
-
function drawingAttribute(element, name) {
|
|
1573
|
-
return work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `a:${name}`);
|
|
1574
|
-
}
|
|
1575
|
-
function hexFactor(value) {
|
|
1576
|
-
if (!value || !/^[0-9a-f]{2}$/i.test(value)) return;
|
|
1577
|
-
return Number.parseInt(value, 16) / 255;
|
|
1578
|
-
}
|
|
1579
|
-
function isDocxThemeResolver(source) {
|
|
1580
|
-
return Boolean(source && 'colors' in source && source.colors instanceof Map && 'fonts' in source && source.fonts instanceof Map);
|
|
1581
|
-
}
|
|
1582
|
-
export { DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES, DOCX_WORDPROCESSING_NAMESPACES, DocxParagraphDefaultCollapsedPatchCollector, STRICT_WORDPROCESSING_NAMESPACE, XMLNS_NAMESPACE, XML_NAMESPACE, assertXmlRoot, cloneXmlElement, createDocxThemeResolver, cssColorToHex, cssFontFamily, cssFontSize, dataBoolean, docxCharacterPositionHalfPointsFromProperties, docxCharacterPositionValue, docxCharacterScalePercentFromProperties, docxCharacterScaleValue, docxCharacterSpacingTwipsFromProperties, docxCharacterSpacingValue, docxEmphasisMarkRunOptions, docxKerningThresholdValue, docxThemeColor, docxThemeFont, domDirection, hasNonWhitespaceXmlText, inspectDocxEmphasisMark, inspectDocxKerningThresholdHalfPoints, mergeDocxIgnorableExtensions, mergeDocxIgnorableExtensionsAtPairs, paragraphAlignment, paragraphBidirectional, paragraphDirectionOptions, paragraphIndent, paragraphPaginationOptions, paragraphSpacingOptions, paragraphTabStops, parseBoundedDocxInteger, parseDocxColorSchemeMappingElement, parseDocxParagraphDefaultCollapsed, parseDocxTwipsMeasure, patchDocxBibliography, patchDocxExplicitZeroCharacterSpacing, patchDocxExplicitZeroKerningThresholds, patchDocxParagraphDefaultCollapsed, readDocxBibliography, resolveDocxEmphasisMark, resolveDocxKerningThresholdHalfPoints, resolveDocxThemeResolver, xmlAttributeLocalName, xmlAttributeNamespace, xmlDeclaredPrefix, xmlNamespaceUri };
|
|
1740
|
+
export { DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES, DOCX_WORDPROCESSING_NAMESPACES, DocxParagraphDefaultCollapsedPatchCollector, STRICT_WORDPROCESSING_NAMESPACE, XMLNS_NAMESPACE, XML_NAMESPACE, assertXmlRoot, cloneXmlElement, createDocxThemeResolver, cssColorToHex, cssFontFamily, cssFontSize, dataBoolean, documentProofingLanguageDocxOptions, docxCharacterPositionHalfPointsFromProperties, docxCharacterPositionValue, docxCharacterScalePercentFromProperties, docxCharacterScaleValue, docxCharacterSpacingTwipsFromProperties, docxCharacterSpacingValue, docxEmphasisMarkRunOptions, docxKerningThresholdValue, docxThemeColor, docxThemeFont, domDirection, hasNonWhitespaceXmlText, inspectDocxEmphasisMark, inspectDocxKerningThresholdHalfPoints, inspectDocxNoProof, inspectDocxProofingLanguages, mergeDocxIgnorableExtensions, mergeDocxIgnorableExtensionsAtPairs, paragraphAlignment, paragraphBidirectional, paragraphDirectionOptions, paragraphIndent, paragraphPaginationOptions, paragraphSpacingOptions, paragraphTabStops, parseBoundedDocxInteger, parseDocxColorSchemeMappingElement, parseDocxParagraphDefaultCollapsed, parseDocxTwipsMeasure, patchDocxBibliography, patchDocxExplicitZeroCharacterSpacing, patchDocxExplicitZeroKerningThresholds, patchDocxParagraphDefaultCollapsed, readDocxBibliography, resolveDocxEmphasisMark, resolveDocxKerningThresholdHalfPoints, resolveDocxProofing, resolveDocxThemeResolver, xmlAttributeLocalName, xmlAttributeNamespace, xmlDeclaredPrefix, xmlNamespaceUri };
|