@a3s-lab/office 0.38.1 → 0.40.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 +18 -4
- package/dist/{0~7240.js → 0~2330.js} +897 -641
- package/dist/0~5024.js +240 -240
- package/dist/0~7828.js +51 -29
- package/dist/0~document-editor.js +1 -0
- package/dist/0~presentation-editor.js +264 -118
- package/dist/0~work-docx-export.js +1023 -922
- package/dist/0~work-docx-import.js +13 -4
- package/dist/0~work-office-diagnostics.js +96 -94
- package/dist/0~work-pptx-import.js +1 -1
- package/dist/0~work-presentation-transition.js +38 -0
- package/dist/4121.js +42 -9
- package/dist/4174.js +497 -233
- package/dist/4560.js +124 -9
- package/dist/internal/features/work/editors/presentation-animation-panel.d.ts +9 -7
- package/dist/internal/features/work/editors/presentation-command-types.d.ts +10 -10
- package/dist/internal/features/work/editors/presentation-slide-canvas.d.ts +6 -4
- package/dist/internal/features/work/editors/use-presentation-animation-commands.d.ts +7 -7
- package/dist/internal/features/work/work-document-format-change-tracking.d.ts +1 -1
- package/dist/internal/features/work/work-document-numbering-change-tracking.d.ts +7 -0
- package/dist/internal/features/work/work-document-numbering-changes.d.ts +29 -0
- package/dist/internal/features/work/work-docx-import.d.ts +7 -5
- package/dist/internal/features/work/work-docx-list-export.d.ts +1 -0
- package/dist/internal/features/work/work-docx-numbering-change-export.d.ts +13 -0
- package/dist/internal/features/work/work-docx-numbering-change-import.d.ts +17 -0
- package/dist/internal/features/work/work-presentation-animation.d.ts +6 -2
- package/dist/internal/features/work/work-presentation-clipboard.d.ts +0 -5
- package/dist/internal/features/work/work-types.d.ts +8 -4
- package/dist/office-kernel.wasm +0 -0
- package/dist/styles.css +162 -26
- package/package.json +8 -5
- package/dist/0~5809.js +0 -123
package/dist/0~5024.js
CHANGED
|
@@ -895,6 +895,246 @@ function escapeFieldValue(value) {
|
|
|
895
895
|
function unescapeFieldValue(value) {
|
|
896
896
|
return value.replace(/\\([\\":])/g, '$1');
|
|
897
897
|
}
|
|
898
|
+
const WORD_THEME_COLOR_KEYS = new Map([
|
|
899
|
+
[
|
|
900
|
+
'dark1',
|
|
901
|
+
'dk1'
|
|
902
|
+
],
|
|
903
|
+
[
|
|
904
|
+
'light1',
|
|
905
|
+
'lt1'
|
|
906
|
+
],
|
|
907
|
+
[
|
|
908
|
+
'dark2',
|
|
909
|
+
'dk2'
|
|
910
|
+
],
|
|
911
|
+
[
|
|
912
|
+
'light2',
|
|
913
|
+
'lt2'
|
|
914
|
+
],
|
|
915
|
+
[
|
|
916
|
+
'background1',
|
|
917
|
+
'lt1'
|
|
918
|
+
],
|
|
919
|
+
[
|
|
920
|
+
'text1',
|
|
921
|
+
'dk1'
|
|
922
|
+
],
|
|
923
|
+
[
|
|
924
|
+
'background2',
|
|
925
|
+
'lt2'
|
|
926
|
+
],
|
|
927
|
+
[
|
|
928
|
+
'text2',
|
|
929
|
+
'dk2'
|
|
930
|
+
],
|
|
931
|
+
[
|
|
932
|
+
'hyperlink',
|
|
933
|
+
'hlink'
|
|
934
|
+
],
|
|
935
|
+
[
|
|
936
|
+
'followedhyperlink',
|
|
937
|
+
'folhlink'
|
|
938
|
+
]
|
|
939
|
+
]);
|
|
940
|
+
const DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES = new Map([
|
|
941
|
+
[
|
|
942
|
+
'background1',
|
|
943
|
+
'bg1'
|
|
944
|
+
],
|
|
945
|
+
[
|
|
946
|
+
'text1',
|
|
947
|
+
't1'
|
|
948
|
+
],
|
|
949
|
+
[
|
|
950
|
+
'background2',
|
|
951
|
+
'bg2'
|
|
952
|
+
],
|
|
953
|
+
[
|
|
954
|
+
'text2',
|
|
955
|
+
't2'
|
|
956
|
+
],
|
|
957
|
+
[
|
|
958
|
+
'accent1',
|
|
959
|
+
'accent1'
|
|
960
|
+
],
|
|
961
|
+
[
|
|
962
|
+
'accent2',
|
|
963
|
+
'accent2'
|
|
964
|
+
],
|
|
965
|
+
[
|
|
966
|
+
'accent3',
|
|
967
|
+
'accent3'
|
|
968
|
+
],
|
|
969
|
+
[
|
|
970
|
+
'accent4',
|
|
971
|
+
'accent4'
|
|
972
|
+
],
|
|
973
|
+
[
|
|
974
|
+
'accent5',
|
|
975
|
+
'accent5'
|
|
976
|
+
],
|
|
977
|
+
[
|
|
978
|
+
'accent6',
|
|
979
|
+
'accent6'
|
|
980
|
+
],
|
|
981
|
+
[
|
|
982
|
+
'hyperlink',
|
|
983
|
+
'hyperlink'
|
|
984
|
+
],
|
|
985
|
+
[
|
|
986
|
+
'followedhyperlink',
|
|
987
|
+
'followedHyperlink'
|
|
988
|
+
]
|
|
989
|
+
]);
|
|
990
|
+
const WORD_COLOR_SCHEME_INDEXES = new Set([
|
|
991
|
+
'dark1',
|
|
992
|
+
'light1',
|
|
993
|
+
'dark2',
|
|
994
|
+
'light2',
|
|
995
|
+
'accent1',
|
|
996
|
+
'accent2',
|
|
997
|
+
'accent3',
|
|
998
|
+
'accent4',
|
|
999
|
+
'accent5',
|
|
1000
|
+
'accent6',
|
|
1001
|
+
'hyperlink',
|
|
1002
|
+
'followedHyperlink'
|
|
1003
|
+
]);
|
|
1004
|
+
const WORDPROCESSING_NAMESPACES = new Set([
|
|
1005
|
+
'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
|
|
1006
|
+
'http://purl.oclc.org/ooxml/wordprocessingml/main'
|
|
1007
|
+
]);
|
|
1008
|
+
const MAX_COLOR_MAPPING_DEPTH = 16;
|
|
1009
|
+
function createDocxThemeResolver(themeDocument, settingsDocument) {
|
|
1010
|
+
const colorMapping = docxColorSchemeMapping(settingsDocument);
|
|
1011
|
+
if (!themeDocument) return {
|
|
1012
|
+
colors: new Map(),
|
|
1013
|
+
colorMapping,
|
|
1014
|
+
fonts: new Map()
|
|
1015
|
+
};
|
|
1016
|
+
const fonts = new Map();
|
|
1017
|
+
const fontScheme = firstDescendant(themeDocument, 'fontScheme');
|
|
1018
|
+
addThemeFontFamily(fonts, 'major', fontScheme ? directChild(fontScheme, 'majorFont') : void 0);
|
|
1019
|
+
addThemeFontFamily(fonts, 'minor', fontScheme ? directChild(fontScheme, 'minorFont') : void 0);
|
|
1020
|
+
const colors = new Map();
|
|
1021
|
+
const colorScheme = firstDescendant(themeDocument, 'clrScheme');
|
|
1022
|
+
if (colorScheme) for (const entry of directChildren(colorScheme)){
|
|
1023
|
+
const color = themeColorValue(directChildren(entry)[0]);
|
|
1024
|
+
if (color) colors.set(entry.localName.toLowerCase(), color);
|
|
1025
|
+
}
|
|
1026
|
+
return {
|
|
1027
|
+
colors,
|
|
1028
|
+
colorMapping,
|
|
1029
|
+
fonts
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
function resolveDocxThemeResolver(source) {
|
|
1033
|
+
return isDocxThemeResolver(source) ? source : createDocxThemeResolver(source);
|
|
1034
|
+
}
|
|
1035
|
+
function docxThemeFont(resolver, key) {
|
|
1036
|
+
return key ? resolver.fonts.get(key.trim().toLowerCase()) : void 0;
|
|
1037
|
+
}
|
|
1038
|
+
function docxThemeColor(resolver, key, tint, shade) {
|
|
1039
|
+
const sourceKey = key?.trim().toLowerCase();
|
|
1040
|
+
const mappedKey = sourceKey ? mappedWordThemeColorKey(sourceKey, resolver.colorMapping) : void 0;
|
|
1041
|
+
const colorKey = mappedKey ? WORD_THEME_COLOR_KEYS.get(mappedKey) ?? mappedKey : void 0;
|
|
1042
|
+
const color = colorKey ? resolver.colors.get(colorKey) : void 0;
|
|
1043
|
+
if (!color) return;
|
|
1044
|
+
const channels = [
|
|
1045
|
+
Number.parseInt(color.slice(0, 2), 16),
|
|
1046
|
+
Number.parseInt(color.slice(2, 4), 16),
|
|
1047
|
+
Number.parseInt(color.slice(4, 6), 16)
|
|
1048
|
+
];
|
|
1049
|
+
const shadeFactor = hexFactor(shade);
|
|
1050
|
+
const tintFactor = hexFactor(tint);
|
|
1051
|
+
const transformed = channels.map((channel)=>{
|
|
1052
|
+
const shaded = void 0 === shadeFactor ? channel : channel * shadeFactor;
|
|
1053
|
+
const tinted = void 0 === tintFactor ? shaded : shaded + (255 - shaded) * tintFactor;
|
|
1054
|
+
return Math.max(0, Math.min(255, Math.round(tinted)));
|
|
1055
|
+
});
|
|
1056
|
+
return transformed.map((channel)=>channel.toString(16).padStart(2, '0')).join('');
|
|
1057
|
+
}
|
|
1058
|
+
function docxColorSchemeMapping(settingsDocument) {
|
|
1059
|
+
const root = settingsDocument?.documentElement;
|
|
1060
|
+
if (!root || 'settings' !== root.localName || !WORDPROCESSING_NAMESPACES.has(root.namespaceURI ?? '')) return new Map();
|
|
1061
|
+
const candidates = directChildren(root, 'clrSchemeMapping').filter((element)=>element.namespaceURI === root.namespaceURI);
|
|
1062
|
+
if (1 !== candidates.length) return new Map();
|
|
1063
|
+
return parseDocxColorSchemeMappingElement(candidates[0]) ?? new Map();
|
|
1064
|
+
}
|
|
1065
|
+
function parseDocxColorSchemeMappingElement(element) {
|
|
1066
|
+
const namespace = element?.namespaceURI ?? '';
|
|
1067
|
+
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;
|
|
1068
|
+
const semanticsByAttribute = new Map(Array.from(DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES).map(([semantic, attributeName])=>[
|
|
1069
|
+
attributeName,
|
|
1070
|
+
semantic
|
|
1071
|
+
]));
|
|
1072
|
+
const mapping = new Map();
|
|
1073
|
+
for (const item of Array.from(element.attributes)){
|
|
1074
|
+
if (item.namespaceURI === XMLNS_NAMESPACE || 'xmlns' === item.name || item.name.startsWith('xmlns:')) continue;
|
|
1075
|
+
const attributeName = xmlAttributeLocalName(item);
|
|
1076
|
+
const semantic = semanticsByAttribute.get(attributeName);
|
|
1077
|
+
const value = item.value.trim();
|
|
1078
|
+
if (xmlAttributeNamespace(element, item) !== namespace || !semantic || mapping.has(semantic) || !WORD_COLOR_SCHEME_INDEXES.has(value)) return null;
|
|
1079
|
+
mapping.set(semantic, value);
|
|
1080
|
+
}
|
|
1081
|
+
return mapping;
|
|
1082
|
+
}
|
|
1083
|
+
function mappedWordThemeColorKey(source, mapping) {
|
|
1084
|
+
let current = source;
|
|
1085
|
+
const visited = new Set();
|
|
1086
|
+
for(let depth = 0; depth < MAX_COLOR_MAPPING_DEPTH; depth += 1){
|
|
1087
|
+
if (visited.has(current)) break;
|
|
1088
|
+
visited.add(current);
|
|
1089
|
+
const next = mapping?.get(current)?.toLowerCase();
|
|
1090
|
+
if (!next || next === current) return current;
|
|
1091
|
+
current = next;
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
function addThemeFontFamily(fonts, prefix, family) {
|
|
1095
|
+
if (!family) return;
|
|
1096
|
+
const latin = typeface(directChild(family, 'latin'));
|
|
1097
|
+
const eastAsia = typeface(directChild(family, 'ea')) || scriptTypeface(family, [
|
|
1098
|
+
'Hans',
|
|
1099
|
+
'Hant',
|
|
1100
|
+
'Jpan',
|
|
1101
|
+
'Hang'
|
|
1102
|
+
]) || latin;
|
|
1103
|
+
const complex = typeface(directChild(family, 'cs')) || latin;
|
|
1104
|
+
if (latin) {
|
|
1105
|
+
fonts.set(`${prefix}ascii`, latin);
|
|
1106
|
+
fonts.set(`${prefix}hansi`, latin);
|
|
1107
|
+
}
|
|
1108
|
+
if (eastAsia) fonts.set(`${prefix}eastasia`, eastAsia);
|
|
1109
|
+
if (complex) fonts.set(`${prefix}bidi`, complex);
|
|
1110
|
+
}
|
|
1111
|
+
function scriptTypeface(family, scripts) {
|
|
1112
|
+
const fonts = directChildren(family, 'font');
|
|
1113
|
+
for (const script of scripts){
|
|
1114
|
+
const font = fonts.find((candidate)=>drawingAttribute(candidate, "script") === script);
|
|
1115
|
+
const value = font ? typeface(font) : void 0;
|
|
1116
|
+
if (value) return value;
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
function typeface(element) {
|
|
1120
|
+
const value = element ? drawingAttribute(element, 'typeface')?.trim() : void 0;
|
|
1121
|
+
return value || void 0;
|
|
1122
|
+
}
|
|
1123
|
+
function themeColorValue(element) {
|
|
1124
|
+
if (!element) return;
|
|
1125
|
+
const value = 'sysClr' === element.localName ? drawingAttribute(element, 'lastClr') : drawingAttribute(element, 'val');
|
|
1126
|
+
return value && /^[0-9a-f]{6}$/i.test(value) ? value.toLowerCase() : void 0;
|
|
1127
|
+
}
|
|
1128
|
+
function drawingAttribute(element, name) {
|
|
1129
|
+
return work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `a:${name}`);
|
|
1130
|
+
}
|
|
1131
|
+
function hexFactor(value) {
|
|
1132
|
+
if (!value || !/^[0-9a-f]{2}$/i.test(value)) return;
|
|
1133
|
+
return Number.parseInt(value, 16) / 255;
|
|
1134
|
+
}
|
|
1135
|
+
function isDocxThemeResolver(source) {
|
|
1136
|
+
return Boolean(source && 'colors' in source && source.colors instanceof Map && 'fonts' in source && source.fonts instanceof Map);
|
|
1137
|
+
}
|
|
898
1138
|
const STRICT_WORDPROCESSING_NAMESPACE = 'http://purl.oclc.org/ooxml/wordprocessingml/main';
|
|
899
1139
|
const UNIVERSAL_TWIP_RATIOS = {
|
|
900
1140
|
mm: [
|
|
@@ -1346,246 +1586,6 @@ function docxEmphasisMarkRunOptions(value) {
|
|
|
1346
1586
|
type: emphasisMark
|
|
1347
1587
|
};
|
|
1348
1588
|
}
|
|
1349
|
-
const WORD_THEME_COLOR_KEYS = new Map([
|
|
1350
|
-
[
|
|
1351
|
-
'dark1',
|
|
1352
|
-
'dk1'
|
|
1353
|
-
],
|
|
1354
|
-
[
|
|
1355
|
-
'light1',
|
|
1356
|
-
'lt1'
|
|
1357
|
-
],
|
|
1358
|
-
[
|
|
1359
|
-
'dark2',
|
|
1360
|
-
'dk2'
|
|
1361
|
-
],
|
|
1362
|
-
[
|
|
1363
|
-
'light2',
|
|
1364
|
-
'lt2'
|
|
1365
|
-
],
|
|
1366
|
-
[
|
|
1367
|
-
'background1',
|
|
1368
|
-
'lt1'
|
|
1369
|
-
],
|
|
1370
|
-
[
|
|
1371
|
-
'text1',
|
|
1372
|
-
'dk1'
|
|
1373
|
-
],
|
|
1374
|
-
[
|
|
1375
|
-
'background2',
|
|
1376
|
-
'lt2'
|
|
1377
|
-
],
|
|
1378
|
-
[
|
|
1379
|
-
'text2',
|
|
1380
|
-
'dk2'
|
|
1381
|
-
],
|
|
1382
|
-
[
|
|
1383
|
-
'hyperlink',
|
|
1384
|
-
'hlink'
|
|
1385
|
-
],
|
|
1386
|
-
[
|
|
1387
|
-
'followedhyperlink',
|
|
1388
|
-
'folhlink'
|
|
1389
|
-
]
|
|
1390
|
-
]);
|
|
1391
|
-
const DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES = new Map([
|
|
1392
|
-
[
|
|
1393
|
-
'background1',
|
|
1394
|
-
'bg1'
|
|
1395
|
-
],
|
|
1396
|
-
[
|
|
1397
|
-
'text1',
|
|
1398
|
-
't1'
|
|
1399
|
-
],
|
|
1400
|
-
[
|
|
1401
|
-
'background2',
|
|
1402
|
-
'bg2'
|
|
1403
|
-
],
|
|
1404
|
-
[
|
|
1405
|
-
'text2',
|
|
1406
|
-
't2'
|
|
1407
|
-
],
|
|
1408
|
-
[
|
|
1409
|
-
'accent1',
|
|
1410
|
-
'accent1'
|
|
1411
|
-
],
|
|
1412
|
-
[
|
|
1413
|
-
'accent2',
|
|
1414
|
-
'accent2'
|
|
1415
|
-
],
|
|
1416
|
-
[
|
|
1417
|
-
'accent3',
|
|
1418
|
-
'accent3'
|
|
1419
|
-
],
|
|
1420
|
-
[
|
|
1421
|
-
'accent4',
|
|
1422
|
-
'accent4'
|
|
1423
|
-
],
|
|
1424
|
-
[
|
|
1425
|
-
'accent5',
|
|
1426
|
-
'accent5'
|
|
1427
|
-
],
|
|
1428
|
-
[
|
|
1429
|
-
'accent6',
|
|
1430
|
-
'accent6'
|
|
1431
|
-
],
|
|
1432
|
-
[
|
|
1433
|
-
'hyperlink',
|
|
1434
|
-
'hyperlink'
|
|
1435
|
-
],
|
|
1436
|
-
[
|
|
1437
|
-
'followedhyperlink',
|
|
1438
|
-
'followedHyperlink'
|
|
1439
|
-
]
|
|
1440
|
-
]);
|
|
1441
|
-
const WORD_COLOR_SCHEME_INDEXES = new Set([
|
|
1442
|
-
'dark1',
|
|
1443
|
-
'light1',
|
|
1444
|
-
'dark2',
|
|
1445
|
-
'light2',
|
|
1446
|
-
'accent1',
|
|
1447
|
-
'accent2',
|
|
1448
|
-
'accent3',
|
|
1449
|
-
'accent4',
|
|
1450
|
-
'accent5',
|
|
1451
|
-
'accent6',
|
|
1452
|
-
'hyperlink',
|
|
1453
|
-
'followedHyperlink'
|
|
1454
|
-
]);
|
|
1455
|
-
const WORDPROCESSING_NAMESPACES = new Set([
|
|
1456
|
-
'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
|
|
1457
|
-
'http://purl.oclc.org/ooxml/wordprocessingml/main'
|
|
1458
|
-
]);
|
|
1459
|
-
const MAX_COLOR_MAPPING_DEPTH = 16;
|
|
1460
|
-
function createDocxThemeResolver(themeDocument, settingsDocument) {
|
|
1461
|
-
const colorMapping = docxColorSchemeMapping(settingsDocument);
|
|
1462
|
-
if (!themeDocument) return {
|
|
1463
|
-
colors: new Map(),
|
|
1464
|
-
colorMapping,
|
|
1465
|
-
fonts: new Map()
|
|
1466
|
-
};
|
|
1467
|
-
const fonts = new Map();
|
|
1468
|
-
const fontScheme = firstDescendant(themeDocument, 'fontScheme');
|
|
1469
|
-
addThemeFontFamily(fonts, 'major', fontScheme ? directChild(fontScheme, 'majorFont') : void 0);
|
|
1470
|
-
addThemeFontFamily(fonts, 'minor', fontScheme ? directChild(fontScheme, 'minorFont') : void 0);
|
|
1471
|
-
const colors = new Map();
|
|
1472
|
-
const colorScheme = firstDescendant(themeDocument, 'clrScheme');
|
|
1473
|
-
if (colorScheme) for (const entry of directChildren(colorScheme)){
|
|
1474
|
-
const color = themeColorValue(directChildren(entry)[0]);
|
|
1475
|
-
if (color) colors.set(entry.localName.toLowerCase(), color);
|
|
1476
|
-
}
|
|
1477
|
-
return {
|
|
1478
|
-
colors,
|
|
1479
|
-
colorMapping,
|
|
1480
|
-
fonts
|
|
1481
|
-
};
|
|
1482
|
-
}
|
|
1483
|
-
function resolveDocxThemeResolver(source) {
|
|
1484
|
-
return isDocxThemeResolver(source) ? source : createDocxThemeResolver(source);
|
|
1485
|
-
}
|
|
1486
|
-
function docxThemeFont(resolver, key) {
|
|
1487
|
-
return key ? resolver.fonts.get(key.trim().toLowerCase()) : void 0;
|
|
1488
|
-
}
|
|
1489
|
-
function docxThemeColor(resolver, key, tint, shade) {
|
|
1490
|
-
const sourceKey = key?.trim().toLowerCase();
|
|
1491
|
-
const mappedKey = sourceKey ? mappedWordThemeColorKey(sourceKey, resolver.colorMapping) : void 0;
|
|
1492
|
-
const colorKey = mappedKey ? WORD_THEME_COLOR_KEYS.get(mappedKey) ?? mappedKey : void 0;
|
|
1493
|
-
const color = colorKey ? resolver.colors.get(colorKey) : void 0;
|
|
1494
|
-
if (!color) return;
|
|
1495
|
-
const channels = [
|
|
1496
|
-
Number.parseInt(color.slice(0, 2), 16),
|
|
1497
|
-
Number.parseInt(color.slice(2, 4), 16),
|
|
1498
|
-
Number.parseInt(color.slice(4, 6), 16)
|
|
1499
|
-
];
|
|
1500
|
-
const shadeFactor = hexFactor(shade);
|
|
1501
|
-
const tintFactor = hexFactor(tint);
|
|
1502
|
-
const transformed = channels.map((channel)=>{
|
|
1503
|
-
const shaded = void 0 === shadeFactor ? channel : channel * shadeFactor;
|
|
1504
|
-
const tinted = void 0 === tintFactor ? shaded : shaded + (255 - shaded) * tintFactor;
|
|
1505
|
-
return Math.max(0, Math.min(255, Math.round(tinted)));
|
|
1506
|
-
});
|
|
1507
|
-
return transformed.map((channel)=>channel.toString(16).padStart(2, '0')).join('');
|
|
1508
|
-
}
|
|
1509
|
-
function docxColorSchemeMapping(settingsDocument) {
|
|
1510
|
-
const root = settingsDocument?.documentElement;
|
|
1511
|
-
if (!root || 'settings' !== root.localName || !WORDPROCESSING_NAMESPACES.has(root.namespaceURI ?? '')) return new Map();
|
|
1512
|
-
const candidates = directChildren(root, 'clrSchemeMapping').filter((element)=>element.namespaceURI === root.namespaceURI);
|
|
1513
|
-
if (1 !== candidates.length) return new Map();
|
|
1514
|
-
return parseDocxColorSchemeMappingElement(candidates[0]) ?? new Map();
|
|
1515
|
-
}
|
|
1516
|
-
function parseDocxColorSchemeMappingElement(element) {
|
|
1517
|
-
const namespace = element?.namespaceURI ?? '';
|
|
1518
|
-
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;
|
|
1519
|
-
const semanticsByAttribute = new Map(Array.from(DOCX_COLOR_SCHEME_MAPPING_ATTRIBUTES).map(([semantic, attributeName])=>[
|
|
1520
|
-
attributeName,
|
|
1521
|
-
semantic
|
|
1522
|
-
]));
|
|
1523
|
-
const mapping = new Map();
|
|
1524
|
-
for (const item of Array.from(element.attributes)){
|
|
1525
|
-
if (item.namespaceURI === XMLNS_NAMESPACE || 'xmlns' === item.name || item.name.startsWith('xmlns:')) continue;
|
|
1526
|
-
const attributeName = xmlAttributeLocalName(item);
|
|
1527
|
-
const semantic = semanticsByAttribute.get(attributeName);
|
|
1528
|
-
const value = item.value.trim();
|
|
1529
|
-
if (xmlAttributeNamespace(element, item) !== namespace || !semantic || mapping.has(semantic) || !WORD_COLOR_SCHEME_INDEXES.has(value)) return null;
|
|
1530
|
-
mapping.set(semantic, value);
|
|
1531
|
-
}
|
|
1532
|
-
return mapping;
|
|
1533
|
-
}
|
|
1534
|
-
function mappedWordThemeColorKey(source, mapping) {
|
|
1535
|
-
let current = source;
|
|
1536
|
-
const visited = new Set();
|
|
1537
|
-
for(let depth = 0; depth < MAX_COLOR_MAPPING_DEPTH; depth += 1){
|
|
1538
|
-
if (visited.has(current)) break;
|
|
1539
|
-
visited.add(current);
|
|
1540
|
-
const next = mapping?.get(current)?.toLowerCase();
|
|
1541
|
-
if (!next || next === current) return current;
|
|
1542
|
-
current = next;
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
function addThemeFontFamily(fonts, prefix, family) {
|
|
1546
|
-
if (!family) return;
|
|
1547
|
-
const latin = typeface(directChild(family, 'latin'));
|
|
1548
|
-
const eastAsia = typeface(directChild(family, 'ea')) || scriptTypeface(family, [
|
|
1549
|
-
'Hans',
|
|
1550
|
-
'Hant',
|
|
1551
|
-
'Jpan',
|
|
1552
|
-
'Hang'
|
|
1553
|
-
]) || latin;
|
|
1554
|
-
const complex = typeface(directChild(family, 'cs')) || latin;
|
|
1555
|
-
if (latin) {
|
|
1556
|
-
fonts.set(`${prefix}ascii`, latin);
|
|
1557
|
-
fonts.set(`${prefix}hansi`, latin);
|
|
1558
|
-
}
|
|
1559
|
-
if (eastAsia) fonts.set(`${prefix}eastasia`, eastAsia);
|
|
1560
|
-
if (complex) fonts.set(`${prefix}bidi`, complex);
|
|
1561
|
-
}
|
|
1562
|
-
function scriptTypeface(family, scripts) {
|
|
1563
|
-
const fonts = directChildren(family, 'font');
|
|
1564
|
-
for (const script of scripts){
|
|
1565
|
-
const font = fonts.find((candidate)=>drawingAttribute(candidate, "script") === script);
|
|
1566
|
-
const value = font ? typeface(font) : void 0;
|
|
1567
|
-
if (value) return value;
|
|
1568
|
-
}
|
|
1569
|
-
}
|
|
1570
|
-
function typeface(element) {
|
|
1571
|
-
const value = element ? drawingAttribute(element, 'typeface')?.trim() : void 0;
|
|
1572
|
-
return value || void 0;
|
|
1573
|
-
}
|
|
1574
|
-
function themeColorValue(element) {
|
|
1575
|
-
if (!element) return;
|
|
1576
|
-
const value = 'sysClr' === element.localName ? drawingAttribute(element, 'lastClr') : drawingAttribute(element, 'val');
|
|
1577
|
-
return value && /^[0-9a-f]{6}$/i.test(value) ? value.toLowerCase() : void 0;
|
|
1578
|
-
}
|
|
1579
|
-
function drawingAttribute(element, name) {
|
|
1580
|
-
return work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `a:${name}`);
|
|
1581
|
-
}
|
|
1582
|
-
function hexFactor(value) {
|
|
1583
|
-
if (!value || !/^[0-9a-f]{2}$/i.test(value)) return;
|
|
1584
|
-
return Number.parseInt(value, 16) / 255;
|
|
1585
|
-
}
|
|
1586
|
-
function isDocxThemeResolver(source) {
|
|
1587
|
-
return Boolean(source && 'colors' in source && source.colors instanceof Map && 'fonts' in source && source.fonts instanceof Map);
|
|
1588
|
-
}
|
|
1589
1589
|
const LANGUAGE_ATTRIBUTES = new Map([
|
|
1590
1590
|
[
|
|
1591
1591
|
'val',
|