@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
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { documentRunBorderDomAttributes, normalizeDocumentRunBorder, normalizeDocumentParagraphBorder, serializeDocumentRunBorder, serializeDocumentRunShading, documentIndexEntryHtml, attribute as work_ooxml_package_attribute, documentScriptFontFallbackSlots, documentScriptFontsDomAttributes, documentHighlightFromDocxValue,
|
|
1
|
+
import { documentRunBorderDomAttributes, normalizeDocumentRunBorder, normalizeDocumentParagraphBorder, serializeDocumentRunBorder, serializeDocumentRunShading, documentIndexEntryHtml, attribute as work_ooxml_package_attribute, documentScriptFontFallbackSlots, documentScriptFontsDomAttributes, documentHighlightFromDocxValue, serializeDocxThemeReference, directChildren as work_ooxml_package_directChildren, documentParagraphShadingDomAttributes, documentTableOfContentsHtml, documentParagraphBordersDomAttributes, normalizeDocumentScriptFontHint, normalizeDocumentScriptFonts, DOCUMENT_PARAGRAPH_BORDER_STYLES, normalizeDocumentParagraphBorders as work_document_paragraph_borders_normalizeDocumentParagraphBorders, DOCUMENT_PARAGRAPH_BORDER_EDGES, documentScriptFontFamily, normalizeDocumentThemeFont, normalizeDocumentParagraphId, documentHighlightDomAttributes, descendants, documentIndexHtml, documentHighlightCssColor, xmlNamespacePrefix, normalizeDocumentFontName, documentProofingDomAttributes, work_document_paragraph_shading_DOCUMENT_PARAGRAPH_SHADING_PATTERNS, directChild, documentScriptFontSegments, childPath, parseDocumentTableOfContentsInstruction, documentRunShadingDomAttributes } from "./4121.js";
|
|
2
2
|
import { docxThemeFont, XML_NAMESPACE as work_docx_settings_xml_XML_NAMESPACE, parseDocumentIndexEntryInstruction, resolveDocxProofing, parseDocumentIndexInstruction, DOCX_WORD_2010_NAMESPACE, XMLNS_NAMESPACE as work_docx_settings_xml_XMLNS_NAMESPACE, STRICT_WORDPROCESSING_NAMESPACE, docxCharacterSpacingTwipsFromProperties, parseBoundedDocxInteger, xmlAttributeLocalName, resolveDocxOpenTypeFeatures, docxCharacterScalePercentFromProperties, resolveDocxEmphasisMark, docxCharacterPositionHalfPointsFromProperties, docxThemeColor, parseDocxParagraphDefaultCollapsed, resolveDocxKerningThresholdHalfPoints, resolveDocxThemeResolver as work_docx_theme_resolveDocxThemeResolver, DOCX_WORDPROCESSING_NAMESPACES, xmlAttributeNamespace, parseDocxTwipsMeasure } from "./0~5024.js";
|
|
3
|
-
import { normalizeDocumentEmphasisMark, normalizeDocumentPageBorders, documentCharacterPositionDomAttributes, DOCUMENT_PAGE_BORDER_EDGES, normalizeDocumentTabStops, documentTextCaseFromWordFlags, documentStrikeDomAttributes,
|
|
3
|
+
import { normalizeDocumentEmphasisMark, normalizeDocumentPageBorders, documentCharacterPositionDomAttributes, DOCUMENT_PAGE_BORDER_EDGES, normalizeDocumentTabStops, documentTextCaseFromWordFlags, documentStrikeDomAttributes, serializeDocumentNumberingChange, numberingTypeFromFormat, normalizeDocumentUnderlineColor, documentAutoLineHeight, documentKerningDomAttributes, documentCharacterScaleDomAttributes, serializeDocumentParagraphFormatting, normalizeDocumentPaperSource, documentEquationText, documentLegacyTextEffectsDomAttributes, documentLegacyTextEffectsConflict, documentCharacterSpacingDomAttributes, normalizeDocumentParagraphIndent, normalizeDocumentEquation, documentOpenTypeDomAttributes, renderDocumentAutoLineHeight, documentUnderlineDomAttributes, MAX_DOCUMENT_NUMBERING_START, normalizeDocumentUnderlineStyle, applyDocumentTextCaseStyle, documentHiddenTextDomAttributes, importedDocumentCharacterFormatting, DOCUMENT_LEGACY_TEXT_EFFECT_NAMES, createDocumentEquationElement, normalizeDocumentPageGeometry, serializeDocumentTabStops, documentWordLineHeightFactor, documentEmphasisMarkDomAttributes, normalizeDocumentPageMargins } from "./4174.js";
|
|
4
4
|
function docxCaptionSequenceKind(instruction) {
|
|
5
5
|
const identifier = /^\s*SEQ\s+([^\s\\]+)/i.exec(instruction)?.[1]?.toLowerCase();
|
|
6
6
|
if (!identifier) return null;
|
|
@@ -4302,269 +4302,261 @@ function normalizedTerm(value) {
|
|
|
4302
4302
|
function escapeRegExp(value) {
|
|
4303
4303
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
4304
4304
|
}
|
|
4305
|
-
const
|
|
4306
|
-
const
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4305
|
+
const work_docx_numbering_change_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
4306
|
+
const work_docx_numbering_change_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
4307
|
+
const MAX_NUMBERING_CHANGES = 65536;
|
|
4308
|
+
const NUMBERING_CHANGE_MARKER_PATTERN = /__A3S_WORK_NUMBERING_CHANGE_\d+__/g;
|
|
4309
|
+
const ORIGINAL_SEGMENT_PATTERN = /%([1-9]):([1-9]\d{0,9}):(\d{1,2}):([^%\u0000-\u001f\u007f]{1,32})/gy;
|
|
4310
|
+
function markDocxNumberingChanges(document) {
|
|
4311
|
+
const groups = [];
|
|
4312
|
+
let active;
|
|
4313
|
+
let markerIndex = 0;
|
|
4314
|
+
for (const paragraph of descendants(document, 'p')){
|
|
4315
|
+
if (!isWordElement(paragraph)) {
|
|
4316
|
+
active = void 0;
|
|
4317
|
+
continue;
|
|
4318
|
+
}
|
|
4319
|
+
const change = supportedNumberingChangeInParagraph(paragraph);
|
|
4320
|
+
if (!change || markerIndex >= MAX_NUMBERING_CHANGES) {
|
|
4321
|
+
active = void 0;
|
|
4322
|
+
continue;
|
|
4323
|
+
}
|
|
4324
|
+
const continues = active && continuesGroup(active.change, change);
|
|
4325
|
+
if (!continues) {
|
|
4326
|
+
const group = {
|
|
4327
|
+
markers: [],
|
|
4328
|
+
id: `docx-numbering-change-${change.id}`,
|
|
4329
|
+
author: change.author,
|
|
4330
|
+
date: change.date,
|
|
4331
|
+
start: change.value,
|
|
4332
|
+
level: change.level,
|
|
4333
|
+
format: change.format,
|
|
4334
|
+
suffix: change.suffix
|
|
4335
|
+
};
|
|
4336
|
+
groups.push(group);
|
|
4337
|
+
active = {
|
|
4338
|
+
change,
|
|
4339
|
+
group
|
|
4340
|
+
};
|
|
4341
|
+
}
|
|
4342
|
+
markerIndex += 1;
|
|
4343
|
+
const marker = `__A3S_WORK_NUMBERING_CHANGE_${markerIndex}__`;
|
|
4344
|
+
insertParagraphMarker(document, change.paragraph, change.properties, marker);
|
|
4345
|
+
active?.group.markers.push(marker);
|
|
4346
|
+
if (active) active.change = change;
|
|
4327
4347
|
}
|
|
4328
4348
|
return {
|
|
4329
|
-
|
|
4330
|
-
};
|
|
4331
|
-
}
|
|
4332
|
-
function
|
|
4333
|
-
const
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
const
|
|
4337
|
-
if (!
|
|
4338
|
-
const
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
usedHeadingIndexes.add(headingIndex);
|
|
4342
|
-
const heading = headings[headingIndex];
|
|
4343
|
-
return heading ? {
|
|
4344
|
-
...entry,
|
|
4345
|
-
targetId: heading.targetId
|
|
4346
|
-
} : entry;
|
|
4347
|
-
});
|
|
4348
|
-
const fragment = document.createRange().createContextualFragment(documentTableOfContentsHtml({
|
|
4349
|
-
id: table.id,
|
|
4350
|
-
options: table.options,
|
|
4351
|
-
entries
|
|
4352
|
-
}));
|
|
4353
|
-
const block = work_docx_table_of_contents_import_closestHtmlBlock(text.parentElement);
|
|
4354
|
-
if (block) block.replaceWith(fragment);
|
|
4349
|
+
groups
|
|
4350
|
+
};
|
|
4351
|
+
}
|
|
4352
|
+
function applyImportedDocxNumberingChangeMarkers(document, markers) {
|
|
4353
|
+
const nodesByMarker = numberingMarkerNodes(document.body);
|
|
4354
|
+
const groupsByList = new Map();
|
|
4355
|
+
for (const group of markers.groups){
|
|
4356
|
+
const list = numberingChangeList(group, nodesByMarker);
|
|
4357
|
+
if (!list) continue;
|
|
4358
|
+
const groups = groupsByList.get(list) ?? [];
|
|
4359
|
+
groups.push(group);
|
|
4360
|
+
groupsByList.set(list, groups);
|
|
4355
4361
|
}
|
|
4362
|
+
for (const [list, groups] of groupsByList)if (1 === groups.length && groups[0]) applyNumberingChange(list, groups[0]);
|
|
4363
|
+
for (const nodes of nodesByMarker.values())for (const node of nodes)node.data = node.data.replace(NUMBERING_CHANGE_MARKER_PATTERN, '');
|
|
4364
|
+
document.body.normalize();
|
|
4356
4365
|
}
|
|
4357
|
-
function
|
|
4358
|
-
return markers.
|
|
4366
|
+
function hasImportedDocxNumberingChangeMarkers(markers) {
|
|
4367
|
+
return markers.groups.length > 0;
|
|
4359
4368
|
}
|
|
4360
|
-
function
|
|
4361
|
-
|
|
4362
|
-
return parsed.supported && field.complete && !field.nested && !field.inDeletion && Boolean(work_docx_table_of_contents_import_closestAncestor(field.start, 'sdt'));
|
|
4369
|
+
function isSupportedDocxNumberingChange(change) {
|
|
4370
|
+
return null !== supportedNumberingChange(change);
|
|
4363
4371
|
}
|
|
4364
|
-
function
|
|
4365
|
-
const
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4372
|
+
function supportedNumberingChangeInParagraph(paragraph) {
|
|
4373
|
+
const propertyNodes = directWordChildren(paragraph, 'pPr');
|
|
4374
|
+
if (1 !== propertyNodes.length) return null;
|
|
4375
|
+
const properties = propertyNodes[0];
|
|
4376
|
+
if (!properties) return null;
|
|
4377
|
+
const numberingNodes = directWordChildren(properties, 'numPr');
|
|
4378
|
+
if (1 !== numberingNodes.length) return null;
|
|
4379
|
+
const changes = work_ooxml_package_directChildren(numberingNodes[0], 'numberingChange');
|
|
4380
|
+
if (1 !== changes.length) return null;
|
|
4381
|
+
return supportedNumberingChange(changes[0]);
|
|
4382
|
+
}
|
|
4383
|
+
function supportedNumberingChange(change) {
|
|
4384
|
+
if (!change || 'numberingChange' !== change.localName || !isWordElement(change)) return null;
|
|
4385
|
+
const namespace = change.namespaceURI ?? '';
|
|
4386
|
+
const numbering = change.parentElement;
|
|
4387
|
+
const properties = numbering?.parentElement;
|
|
4388
|
+
const paragraph = properties?.parentElement;
|
|
4389
|
+
if (numbering?.localName !== 'numPr' || numbering.namespaceURI !== namespace || properties?.localName !== 'pPr' || properties.namespaceURI !== namespace || paragraph?.localName !== 'p' || paragraph.namespaceURI !== namespace) return null;
|
|
4390
|
+
const numberingChildren = work_ooxml_package_directChildren(numbering);
|
|
4391
|
+
if (3 !== numberingChildren.length || numberingChildren.some((child)=>child.namespaceURI !== namespace) || 1 !== work_ooxml_package_directChildren(numbering, 'numberingChange').length || 0 !== change.children.length || hasUnsupportedWordAttribute(change)) return null;
|
|
4392
|
+
const levels = directWordChildren(numbering, 'ilvl');
|
|
4393
|
+
const numberingIds = directWordChildren(numbering, 'numId');
|
|
4394
|
+
if (1 !== levels.length || 1 !== numberingIds.length) return null;
|
|
4395
|
+
const level = boundedWordInteger(levels[0], 'val', 0, 8);
|
|
4396
|
+
const numberingId = boundedWordInteger(numberingIds[0], 'val', 0, MAX_DOCUMENT_NUMBERING_START);
|
|
4397
|
+
const id = wordAttribute(change, 'id')?.trim() ?? '';
|
|
4398
|
+
const author = wordAttribute(change, 'author')?.trim() ?? '';
|
|
4399
|
+
const rawDate = wordAttribute(change, 'date');
|
|
4400
|
+
const original = wordAttribute(change, 'original') ?? '';
|
|
4401
|
+
if (null === level || null === numberingId || !/^\+?\d{1,10}$/.test(id) || !author || author.length > 255 || /[\u0000-\u001f\u007f]/.test(author) || null !== rawDate && !Number.isFinite(Date.parse(rawDate))) return null;
|
|
4402
|
+
const definitions = parseOriginalNumbering(original);
|
|
4403
|
+
const definition = definitions?.get(level + 1);
|
|
4404
|
+
if (!definition || definitions?.size !== 1) return null;
|
|
4405
|
+
return {
|
|
4406
|
+
id,
|
|
4407
|
+
author,
|
|
4408
|
+
date: normalizeRevisionDate(rawDate),
|
|
4409
|
+
numberingId,
|
|
4410
|
+
level,
|
|
4411
|
+
...definition,
|
|
4412
|
+
paragraph,
|
|
4413
|
+
properties
|
|
4414
|
+
};
|
|
4387
4415
|
}
|
|
4388
|
-
function
|
|
4389
|
-
if (!
|
|
4390
|
-
const
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4416
|
+
function parseOriginalNumbering(value) {
|
|
4417
|
+
if (!value || value.length > 1024) return null;
|
|
4418
|
+
const definitions = new Map();
|
|
4419
|
+
ORIGINAL_SEGMENT_PATTERN.lastIndex = 0;
|
|
4420
|
+
while(ORIGINAL_SEGMENT_PATTERN.lastIndex < value.length){
|
|
4421
|
+
const match = ORIGINAL_SEGMENT_PATTERN.exec(value);
|
|
4422
|
+
if (!match) return null;
|
|
4423
|
+
const level = Number(match[1]);
|
|
4424
|
+
const number = Number(match[2]);
|
|
4425
|
+
const format = Number(match[3]);
|
|
4426
|
+
const suffix = match[4] ?? '';
|
|
4427
|
+
if (definitions.has(level) || !Number.isSafeInteger(number) || number < 1 || number > MAX_DOCUMENT_NUMBERING_START || !Number.isSafeInteger(format) || format < 0 || format > 4) return null;
|
|
4428
|
+
definitions.set(level, {
|
|
4429
|
+
value: number,
|
|
4430
|
+
format,
|
|
4431
|
+
suffix
|
|
4432
|
+
});
|
|
4433
|
+
}
|
|
4434
|
+
return definitions.size ? definitions : null;
|
|
4435
|
+
}
|
|
4436
|
+
function continuesGroup(previous, current) {
|
|
4437
|
+
return current.numberingId === previous.numberingId && current.level === previous.level && current.author === previous.author && current.date === previous.date && current.format === previous.format && current.suffix === previous.suffix && current.value === previous.value + 1;
|
|
4438
|
+
}
|
|
4439
|
+
function applyNumberingChange(list, change) {
|
|
4440
|
+
const type = numberingTypeFromFormat(change.format);
|
|
4441
|
+
if (void 0 === type) return;
|
|
4442
|
+
const attributes = {
|
|
4443
|
+
start: change.start,
|
|
4444
|
+
type,
|
|
4445
|
+
officeNumberingId: optionalDataset(list, 'officeNumberingId'),
|
|
4446
|
+
officeAbstractNumberingId: optionalDataset(list, 'officeAbstractNumberingId'),
|
|
4447
|
+
officeNumberingLevel: optionalDataset(list, 'officeNumberingLevel') ?? String(change.level),
|
|
4448
|
+
officeNumberingFormat: numberingFormatName(change.format),
|
|
4449
|
+
officeNumberingText: `%${change.level + 1}${change.suffix}`,
|
|
4450
|
+
officeNumberingSuffix: optionalDataset(list, 'officeNumberingSuffix'),
|
|
4451
|
+
officeNumberingAlignment: optionalDataset(list, 'officeNumberingAlignment'),
|
|
4452
|
+
officeNumberingIndentLeft: optionalDataset(list, 'officeNumberingIndentLeft'),
|
|
4453
|
+
officeNumberingIndentRight: optionalDataset(list, 'officeNumberingIndentRight'),
|
|
4454
|
+
officeNumberingIndentStart: optionalDataset(list, 'officeNumberingIndentStart'),
|
|
4455
|
+
officeNumberingIndentEnd: optionalDataset(list, 'officeNumberingIndentEnd'),
|
|
4456
|
+
officeNumberingIndentHanging: optionalDataset(list, 'officeNumberingIndentHanging'),
|
|
4457
|
+
officeNumberingIndentFirstLine: optionalDataset(list, 'officeNumberingIndentFirstLine'),
|
|
4458
|
+
officeNumberingRestartAfterLevel: optionalDataset(list, 'officeNumberingRestartAfterLevel'),
|
|
4459
|
+
level: change.level,
|
|
4460
|
+
originalFormat: change.format,
|
|
4461
|
+
originalSuffix: change.suffix
|
|
4462
|
+
};
|
|
4463
|
+
list.dataset.documentChange = 'true';
|
|
4464
|
+
list.dataset.changeKind = 'numbering';
|
|
4465
|
+
list.dataset.changeId = change.id;
|
|
4466
|
+
list.dataset.changeAuthor = change.author;
|
|
4467
|
+
list.dataset.changeDate = change.date;
|
|
4468
|
+
list.dataset.changeBefore = serializeDocumentNumberingChange(attributes);
|
|
4469
|
+
}
|
|
4470
|
+
function numberingChangeList(group, nodesByMarker) {
|
|
4471
|
+
if (!group.markers.length) return null;
|
|
4472
|
+
const occurrences = group.markers.map((marker)=>nodesByMarker.get(marker));
|
|
4473
|
+
if (occurrences.some((nodes)=>nodes?.length !== 1)) return null;
|
|
4474
|
+
const nodes = occurrences.map((nodes)=>nodes?.[0]).filter(isTextNode);
|
|
4475
|
+
if (nodes.length !== group.markers.length) return null;
|
|
4476
|
+
const items = nodes.map((node)=>node.parentElement?.closest('li'));
|
|
4477
|
+
const lists = items.map((item)=>item?.parentElement);
|
|
4478
|
+
const list = lists[0];
|
|
4479
|
+
if (!(list instanceof HTMLOListElement) || items.some((item)=>!(item instanceof HTMLLIElement)) || lists.some((candidate)=>candidate !== list)) return null;
|
|
4480
|
+
const directItems = Array.from(list.children).filter((child)=>child instanceof HTMLLIElement);
|
|
4481
|
+
const indexes = items.map((item)=>directItems.indexOf(item));
|
|
4482
|
+
const first = indexes[0] ?? -1;
|
|
4483
|
+
return first >= 0 && indexes.every((index, offset)=>index === first + offset) ? list : null;
|
|
4484
|
+
}
|
|
4485
|
+
function numberingMarkerNodes(root) {
|
|
4486
|
+
const result = new Map();
|
|
4487
|
+
for (const node of work_docx_numbering_change_import_textNodes(root))for (const marker of node.data.match(NUMBERING_CHANGE_MARKER_PATTERN) ?? []){
|
|
4488
|
+
const nodes = result.get(marker) ?? [];
|
|
4489
|
+
nodes.push(node);
|
|
4490
|
+
result.set(marker, nodes);
|
|
4491
|
+
}
|
|
4492
|
+
return result;
|
|
4396
4493
|
}
|
|
4397
|
-
function
|
|
4398
|
-
const
|
|
4399
|
-
const
|
|
4400
|
-
const
|
|
4401
|
-
text.
|
|
4494
|
+
function insertParagraphMarker(document, paragraph, properties, marker) {
|
|
4495
|
+
const namespace = paragraph.namespaceURI ?? work_docx_numbering_change_import_WORD_NAMESPACE;
|
|
4496
|
+
const prefix = paragraph.prefix || 'w';
|
|
4497
|
+
const run = document.createElementNS(namespace, `${prefix}:r`);
|
|
4498
|
+
const text = document.createElementNS(namespace, `${prefix}:t`);
|
|
4499
|
+
text.setAttributeNS(work_docx_numbering_change_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
4402
4500
|
text.textContent = marker;
|
|
4403
4501
|
run.append(text);
|
|
4404
|
-
paragraph.
|
|
4405
|
-
return paragraph;
|
|
4406
|
-
}
|
|
4407
|
-
function importedHtmlHeadings(document) {
|
|
4408
|
-
return Array.from(document.body.querySelectorAll('h1,h2,h3,h4,h5,h6,p[data-office-outline-level]')).flatMap((heading, index)=>{
|
|
4409
|
-
const headingLevel = /^H([1-6])$/.exec(heading.tagName)?.[1];
|
|
4410
|
-
const outlineLevel = Number(heading.dataset.officeOutlineLevel);
|
|
4411
|
-
const level = headingLevel ? Number(headingLevel) : Number.isInteger(outlineLevel) && outlineLevel >= 0 && outlineLevel <= 8 ? outlineLevel + 1 : null;
|
|
4412
|
-
if (null === level) return [];
|
|
4413
|
-
const identity = normalizeDocumentParagraphId(heading.dataset.officeParagraphId);
|
|
4414
|
-
return [
|
|
4415
|
-
{
|
|
4416
|
-
title: heading.textContent ?? '',
|
|
4417
|
-
level,
|
|
4418
|
-
targetId: identity ? `heading-${identity.toLowerCase()}` : `heading-imported-${index + 1}`
|
|
4419
|
-
}
|
|
4420
|
-
];
|
|
4421
|
-
});
|
|
4502
|
+
paragraph.insertBefore(run, properties.nextSibling);
|
|
4422
4503
|
}
|
|
4423
|
-
function
|
|
4424
|
-
const
|
|
4425
|
-
|
|
4426
|
-
if (!walker) return nodes;
|
|
4427
|
-
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
4428
|
-
return nodes;
|
|
4504
|
+
function directWordChildren(parent, localName) {
|
|
4505
|
+
const namespace = parent.namespaceURI;
|
|
4506
|
+
return work_ooxml_package_directChildren(parent, localName).filter((element)=>element.namespaceURI === namespace && isWordElement(element));
|
|
4429
4507
|
}
|
|
4430
|
-
function
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
return
|
|
4508
|
+
function boundedWordInteger(element, name, minimum, maximum) {
|
|
4509
|
+
if (!element) return null;
|
|
4510
|
+
const raw = wordAttribute(element, name);
|
|
4511
|
+
if (!raw || !/^\d{1,10}$/.test(raw)) return null;
|
|
4512
|
+
const value = Number(raw);
|
|
4513
|
+
return Number.isSafeInteger(value) && value >= minimum && value <= maximum ? value : null;
|
|
4434
4514
|
}
|
|
4435
|
-
function
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
}
|
|
4441
|
-
return null;
|
|
4515
|
+
function wordAttribute(element, localName) {
|
|
4516
|
+
const namespace = element.namespaceURI;
|
|
4517
|
+
if (!namespace) return null;
|
|
4518
|
+
const attributes = Array.from(element.attributes).filter((attribute)=>xmlAttributeLocalName(attribute) === localName && xmlAttributeNamespace(element, attribute) === namespace);
|
|
4519
|
+
return 1 === attributes.length ? attributes[0]?.value ?? null : null;
|
|
4442
4520
|
}
|
|
4443
|
-
function
|
|
4444
|
-
|
|
4521
|
+
function hasUnsupportedWordAttribute(element) {
|
|
4522
|
+
const namespace = element.namespaceURI;
|
|
4523
|
+
const supported = new Set([
|
|
4524
|
+
'id',
|
|
4525
|
+
'author',
|
|
4526
|
+
'date',
|
|
4527
|
+
'original'
|
|
4528
|
+
]);
|
|
4529
|
+
return Array.from(element.attributes).some((attribute)=>xmlAttributeNamespace(element, attribute) === namespace && !supported.has(xmlAttributeLocalName(attribute)));
|
|
4445
4530
|
}
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
'true'
|
|
4450
|
-
]);
|
|
4451
|
-
const OFF_VALUES = new Set([
|
|
4452
|
-
'0',
|
|
4453
|
-
'off',
|
|
4454
|
-
'false'
|
|
4455
|
-
]);
|
|
4456
|
-
function inspectDocxHiddenText(properties) {
|
|
4457
|
-
if (!properties) return {
|
|
4458
|
-
status: 'absent'
|
|
4459
|
-
};
|
|
4460
|
-
const localMatches = work_ooxml_package_directChildren(properties, 'vanish');
|
|
4461
|
-
if (!localMatches.length) return {
|
|
4462
|
-
status: 'absent'
|
|
4463
|
-
};
|
|
4464
|
-
const nativeMatches = localMatches.filter((element)=>DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? ''));
|
|
4465
|
-
if (1 !== localMatches.length || 1 !== nativeMatches.length) return {
|
|
4466
|
-
status: 'invalid'
|
|
4467
|
-
};
|
|
4468
|
-
const vanish = nativeMatches[0];
|
|
4469
|
-
if (work_ooxml_package_directChildren(vanish).length || Array.from(vanish.childNodes).some((node)=>(node.nodeType === Node.TEXT_NODE || node.nodeType === Node.CDATA_SECTION_NODE) && Boolean(node.textContent?.trim()))) return {
|
|
4470
|
-
status: 'invalid'
|
|
4471
|
-
};
|
|
4472
|
-
const attributes = Array.from(vanish.attributes).filter((attribute)=>xmlAttributeNamespace(vanish, attribute) !== work_docx_settings_xml_XMLNS_NAMESPACE && 'xmlns' !== attribute.name && !attribute.name.startsWith('xmlns:'));
|
|
4473
|
-
if (!attributes.length) return {
|
|
4474
|
-
status: 'valid',
|
|
4475
|
-
value: true
|
|
4476
|
-
};
|
|
4477
|
-
if (1 !== attributes.length || 'val' !== xmlAttributeLocalName(attributes[0]) || !DOCX_WORDPROCESSING_NAMESPACES.has(xmlAttributeNamespace(vanish, attributes[0]) ?? '')) return {
|
|
4478
|
-
status: 'invalid'
|
|
4479
|
-
};
|
|
4480
|
-
const value = attributes[0].value;
|
|
4481
|
-
if (ON_VALUES.has(value)) return {
|
|
4482
|
-
status: 'valid',
|
|
4483
|
-
value: true
|
|
4484
|
-
};
|
|
4485
|
-
if (OFF_VALUES.has(value)) return {
|
|
4486
|
-
status: 'valid',
|
|
4487
|
-
value: false
|
|
4488
|
-
};
|
|
4489
|
-
return {
|
|
4490
|
-
status: 'invalid'
|
|
4491
|
-
};
|
|
4531
|
+
function optionalDataset(element, key) {
|
|
4532
|
+
const value = element.dataset[key];
|
|
4533
|
+
return value ? value : null;
|
|
4492
4534
|
}
|
|
4493
|
-
function
|
|
4494
|
-
|
|
4495
|
-
|
|
4535
|
+
function numberingFormatName(format) {
|
|
4536
|
+
if (1 === format) return 'upperRoman';
|
|
4537
|
+
if (2 === format) return 'lowerRoman';
|
|
4538
|
+
if (3 === format) return 'upperLetter';
|
|
4539
|
+
if (4 === format) return 'lowerLetter';
|
|
4540
|
+
return 'decimal';
|
|
4496
4541
|
}
|
|
4497
|
-
function
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
if (void 0 !== candidate) hiddenText = candidate;
|
|
4502
|
-
}
|
|
4503
|
-
return hiddenText;
|
|
4542
|
+
function normalizeRevisionDate(value) {
|
|
4543
|
+
if (!value) return '';
|
|
4544
|
+
const time = Date.parse(value);
|
|
4545
|
+
return Number.isFinite(time) ? new Date(time).toISOString() : '';
|
|
4504
4546
|
}
|
|
4505
|
-
|
|
4506
|
-
'
|
|
4507
|
-
'on',
|
|
4508
|
-
'true'
|
|
4509
|
-
]);
|
|
4510
|
-
const work_docx_legacy_text_effects_OFF_VALUES = new Set([
|
|
4511
|
-
'0',
|
|
4512
|
-
'off',
|
|
4513
|
-
'false'
|
|
4514
|
-
]);
|
|
4515
|
-
function inspectDocxLegacyTextEffects(properties) {
|
|
4516
|
-
if (!properties) return {
|
|
4517
|
-
status: 'absent'
|
|
4518
|
-
};
|
|
4519
|
-
const effects = {};
|
|
4520
|
-
let present = false;
|
|
4521
|
-
for (const name of DOCUMENT_LEGACY_TEXT_EFFECT_NAMES){
|
|
4522
|
-
const localMatches = work_ooxml_package_directChildren(properties, name);
|
|
4523
|
-
if (!localMatches.length) continue;
|
|
4524
|
-
present = true;
|
|
4525
|
-
const nativeMatches = localMatches.filter((element)=>DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? ''));
|
|
4526
|
-
if (1 !== localMatches.length || 1 !== nativeMatches.length) return {
|
|
4527
|
-
status: 'invalid'
|
|
4528
|
-
};
|
|
4529
|
-
const value = inspectOnOffLeaf(nativeMatches[0]);
|
|
4530
|
-
if (null === value) return {
|
|
4531
|
-
status: 'invalid'
|
|
4532
|
-
};
|
|
4533
|
-
effects[name] = value;
|
|
4534
|
-
}
|
|
4535
|
-
if (!present) return {
|
|
4536
|
-
status: 'absent'
|
|
4537
|
-
};
|
|
4538
|
-
return documentLegacyTextEffectsConflict(effects) ? {
|
|
4539
|
-
status: 'invalid'
|
|
4540
|
-
} : {
|
|
4541
|
-
status: 'valid',
|
|
4542
|
-
value: effects
|
|
4543
|
-
};
|
|
4547
|
+
function isWordElement(element) {
|
|
4548
|
+
return DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? '');
|
|
4544
4549
|
}
|
|
4545
|
-
function
|
|
4546
|
-
|
|
4547
|
-
let present = false;
|
|
4548
|
-
for (const properties of propertySources){
|
|
4549
|
-
const inspection = inspectDocxLegacyTextEffects(properties);
|
|
4550
|
-
if ('invalid' === inspection.status) return;
|
|
4551
|
-
if ('valid' === inspection.status) {
|
|
4552
|
-
Object.assign(effects, inspection.value);
|
|
4553
|
-
present = true;
|
|
4554
|
-
if (documentLegacyTextEffectsConflict(effects)) return;
|
|
4555
|
-
}
|
|
4556
|
-
}
|
|
4557
|
-
return present ? effects : void 0;
|
|
4550
|
+
function isTextNode(value) {
|
|
4551
|
+
return value instanceof Text;
|
|
4558
4552
|
}
|
|
4559
|
-
function
|
|
4560
|
-
|
|
4561
|
-
const
|
|
4562
|
-
|
|
4563
|
-
if (
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
if (work_docx_legacy_text_effects_OFF_VALUES.has(value)) return false;
|
|
4567
|
-
return null;
|
|
4553
|
+
function work_docx_numbering_change_import_textNodes(root) {
|
|
4554
|
+
const document = root.ownerDocument;
|
|
4555
|
+
const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
4556
|
+
const nodes = [];
|
|
4557
|
+
if (!walker) return nodes;
|
|
4558
|
+
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
4559
|
+
return nodes;
|
|
4568
4560
|
}
|
|
4569
4561
|
const MAX_STYLE_INHERITANCE_DEPTH = 64;
|
|
4570
4562
|
function createDocxParagraphStyleResolver(stylesDocument) {
|
|
@@ -4576,13 +4568,13 @@ function createDocxParagraphStyleResolver(stylesDocument) {
|
|
|
4576
4568
|
const characterStyles = new Map();
|
|
4577
4569
|
let defaultStyleId;
|
|
4578
4570
|
for (const style of descendants(stylesDocument, 'style')){
|
|
4579
|
-
const type =
|
|
4571
|
+
const type = work_docx_paragraph_styles_wordAttribute(style, 'type');
|
|
4580
4572
|
if ('paragraph' !== type && 'character' !== type) continue;
|
|
4581
|
-
const styleId =
|
|
4573
|
+
const styleId = work_docx_paragraph_styles_wordAttribute(style, 'styleId')?.trim();
|
|
4582
4574
|
if (!styleId) continue;
|
|
4583
4575
|
const basedOn = directChild(style, 'basedOn');
|
|
4584
4576
|
const value = {
|
|
4585
|
-
basedOn: basedOn ?
|
|
4577
|
+
basedOn: basedOn ? work_docx_paragraph_styles_wordAttribute(basedOn, 'val')?.trim() || void 0 : void 0,
|
|
4586
4578
|
paragraphProperties: directChild(style, 'pPr'),
|
|
4587
4579
|
runProperties: directChild(style, 'rPr')
|
|
4588
4580
|
};
|
|
@@ -4605,7 +4597,7 @@ function docxParagraphPropertySources(directProperties, resolver, contextualProp
|
|
|
4605
4597
|
const sources = [];
|
|
4606
4598
|
if (resolver.defaultProperties) sources.push(resolver.defaultProperties);
|
|
4607
4599
|
const styleReference = directProperties ? directChild(directProperties, 'pStyle') : void 0;
|
|
4608
|
-
const styleId = (styleReference ?
|
|
4600
|
+
const styleId = (styleReference ? work_docx_paragraph_styles_wordAttribute(styleReference, 'val')?.trim() : void 0) || resolver.defaultStyleId;
|
|
4609
4601
|
if (styleId) sources.push(...stylePropertySources(resolver.styles, styleId, 'paragraphProperties'));
|
|
4610
4602
|
sources.push(...contextualProperties);
|
|
4611
4603
|
if (directProperties) sources.push(directProperties);
|
|
@@ -4615,13 +4607,13 @@ function docxRunPropertySources(paragraphProperties, runProperties, resolver, co
|
|
|
4615
4607
|
const sources = [];
|
|
4616
4608
|
if (resolver.defaultRunProperties) sources.push(resolver.defaultRunProperties);
|
|
4617
4609
|
const paragraphStyleReference = paragraphProperties ? directChild(paragraphProperties, 'pStyle') : void 0;
|
|
4618
|
-
const paragraphStyleId = (paragraphStyleReference ?
|
|
4610
|
+
const paragraphStyleId = (paragraphStyleReference ? work_docx_paragraph_styles_wordAttribute(paragraphStyleReference, 'val')?.trim() : void 0) || resolver.defaultStyleId;
|
|
4619
4611
|
if (paragraphStyleId) sources.push(...stylePropertySources(resolver.styles, paragraphStyleId, 'runProperties'));
|
|
4620
4612
|
sources.push(...contextualProperties);
|
|
4621
4613
|
const paragraphRunProperties = paragraphProperties ? directChild(paragraphProperties, 'rPr') : void 0;
|
|
4622
4614
|
if (paragraphRunProperties) sources.push(paragraphRunProperties);
|
|
4623
4615
|
const characterStyleReference = runProperties ? directChild(runProperties, 'rStyle') : void 0;
|
|
4624
|
-
const characterStyleId = characterStyleReference ?
|
|
4616
|
+
const characterStyleId = characterStyleReference ? work_docx_paragraph_styles_wordAttribute(characterStyleReference, 'val')?.trim() : void 0;
|
|
4625
4617
|
if (characterStyleId) sources.push(...stylePropertySources(resolver.characterStyles, characterStyleId, 'runProperties'));
|
|
4626
4618
|
if (runProperties) sources.push(runProperties);
|
|
4627
4619
|
return sources;
|
|
@@ -4643,11 +4635,11 @@ function stylePropertySources(styles, styleId, property) {
|
|
|
4643
4635
|
return inherited.reverse();
|
|
4644
4636
|
}
|
|
4645
4637
|
function onOffAttribute(element, name) {
|
|
4646
|
-
const value =
|
|
4638
|
+
const value = work_docx_paragraph_styles_wordAttribute(element, name)?.trim().toLowerCase();
|
|
4647
4639
|
if (null == value) return false;
|
|
4648
4640
|
return '0' !== value && 'false' !== value && 'off' !== value;
|
|
4649
4641
|
}
|
|
4650
|
-
function
|
|
4642
|
+
function work_docx_paragraph_styles_wordAttribute(element, name) {
|
|
4651
4643
|
return work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `w:${name}`);
|
|
4652
4644
|
}
|
|
4653
4645
|
const work_docx_table_styles_MAX_STYLE_INHERITANCE_DEPTH = 64;
|
|
@@ -4944,7 +4936,7 @@ function markDocxParagraphBorders(document, styleSource, themeSource, tableStyle
|
|
|
4944
4936
|
let invalidCount = 0;
|
|
4945
4937
|
let spoofedCount = 0;
|
|
4946
4938
|
for (const paragraph of descendants(document, 'p')){
|
|
4947
|
-
if (!
|
|
4939
|
+
if (!work_docx_paragraph_borders_import_isWordElement(paragraph)) continue;
|
|
4948
4940
|
const properties = wordDirectChildren(paragraph, 'pPr')[0];
|
|
4949
4941
|
const resolved = resolveDocxParagraphBordersForParagraph(paragraph, styles, theme, tableStyles);
|
|
4950
4942
|
invalidCount += resolved.invalidCount;
|
|
@@ -4953,7 +4945,7 @@ function markDocxParagraphBorders(document, styleSource, themeSource, tableStyle
|
|
|
4953
4945
|
if (!borders) continue;
|
|
4954
4946
|
const marker = `__A3S_WORK_PARAGRAPH_BORDER_${paragraphs.length + 1}__`;
|
|
4955
4947
|
const writableProperties = properties ?? insertParagraphProperties(document, paragraph);
|
|
4956
|
-
|
|
4948
|
+
work_docx_paragraph_borders_import_insertParagraphMarker(document, paragraph, writableProperties, marker);
|
|
4957
4949
|
paragraphs.push({
|
|
4958
4950
|
marker,
|
|
4959
4951
|
borders
|
|
@@ -4966,7 +4958,7 @@ function markDocxParagraphBorders(document, styleSource, themeSource, tableStyle
|
|
|
4966
4958
|
};
|
|
4967
4959
|
}
|
|
4968
4960
|
function resolveDocxParagraphBordersForParagraph(paragraph, styleSource, themeSource, tableStyleSource) {
|
|
4969
|
-
if (!
|
|
4961
|
+
if (!work_docx_paragraph_borders_import_isWordElement(paragraph) || 'p' !== paragraph.localName) return {
|
|
4970
4962
|
borders: null,
|
|
4971
4963
|
invalidCount: 0,
|
|
4972
4964
|
spoofedCount: 0
|
|
@@ -5037,7 +5029,7 @@ function parseBorderContainer(container, theme) {
|
|
|
5037
5029
|
const borders = {};
|
|
5038
5030
|
let invalidCount = 0;
|
|
5039
5031
|
let spoofedCount = 0;
|
|
5040
|
-
if (!
|
|
5032
|
+
if (!work_docx_paragraph_borders_import_isWordElement(container) || hasSemanticAttributes(container) || Array.from(container.childNodes).some((node)=>node.nodeType === Node.TEXT_NODE && node.textContent?.trim())) return {
|
|
5041
5033
|
borders,
|
|
5042
5034
|
invalidCount,
|
|
5043
5035
|
spoofedCount,
|
|
@@ -5095,187 +5087,457 @@ function parseDocxBorderElement(element, theme) {
|
|
|
5095
5087
|
...void 0 !== size ? {
|
|
5096
5088
|
size
|
|
5097
5089
|
} : {},
|
|
5098
|
-
...void 0 !== space ? {
|
|
5099
|
-
space
|
|
5090
|
+
...void 0 !== space ? {
|
|
5091
|
+
space
|
|
5092
|
+
} : {},
|
|
5093
|
+
...void 0 !== shadow ? {
|
|
5094
|
+
shadow
|
|
5095
|
+
} : {},
|
|
5096
|
+
...void 0 !== frame ? {
|
|
5097
|
+
frame
|
|
5098
|
+
} : {}
|
|
5099
|
+
});
|
|
5100
|
+
}
|
|
5101
|
+
function parseBorderColor(attributes, theme) {
|
|
5102
|
+
const rawColor = attributes.get('color')?.trim();
|
|
5103
|
+
const rawTheme = attributes.get('themeColor')?.trim();
|
|
5104
|
+
const rawTint = attributes.get('themeTint')?.trim();
|
|
5105
|
+
const rawShade = attributes.get('themeShade')?.trim();
|
|
5106
|
+
if (void 0 === rawColor && void 0 === rawTheme && void 0 === rawTint && void 0 === rawShade) return;
|
|
5107
|
+
const color = 'auto' === rawColor ? 'auto' : rawColor && /^[0-9a-f]{6}$/i.test(rawColor) ? `#${rawColor.toLowerCase()}` : null;
|
|
5108
|
+
const themeName = rawTheme && work_docx_paragraph_borders_import_WORD_THEME_COLORS.has(rawTheme) ? rawTheme : null;
|
|
5109
|
+
const tint = byteHex(rawTint);
|
|
5110
|
+
const shade = byteHex(rawShade);
|
|
5111
|
+
if (void 0 !== rawColor && !color || void 0 !== rawTheme && !themeName || void 0 !== rawTint && !tint || void 0 !== rawShade && !shade || (!themeName || 'none' === themeName) && (tint || shade)) return null;
|
|
5112
|
+
if (themeName && 'none' !== themeName) {
|
|
5113
|
+
const resolved = docxThemeColor(theme, themeName, tint, tint ? void 0 : shade);
|
|
5114
|
+
const fallback = color && 'auto' !== color ? color : null;
|
|
5115
|
+
const semanticValue = resolved ? `#${resolved}` : fallback;
|
|
5116
|
+
if (!semanticValue) return null;
|
|
5117
|
+
return {
|
|
5118
|
+
value: semanticValue,
|
|
5119
|
+
theme: work_docx_paragraph_borders_import_themeReference(themeName, semanticValue, tint, shade)
|
|
5120
|
+
};
|
|
5121
|
+
}
|
|
5122
|
+
if ('none' === themeName) {
|
|
5123
|
+
const value = color ?? 'auto';
|
|
5124
|
+
return {
|
|
5125
|
+
value,
|
|
5126
|
+
theme: work_docx_paragraph_borders_import_themeReference(themeName, 'auto' === value ? '#000000' : value, tint, shade)
|
|
5127
|
+
};
|
|
5128
|
+
}
|
|
5129
|
+
if (!color) return null;
|
|
5130
|
+
return {
|
|
5131
|
+
value: color
|
|
5132
|
+
};
|
|
5133
|
+
}
|
|
5134
|
+
function work_docx_paragraph_borders_import_themeReference(theme, resolved, tint, shade) {
|
|
5135
|
+
return {
|
|
5136
|
+
theme,
|
|
5137
|
+
resolved,
|
|
5138
|
+
...tint ? {
|
|
5139
|
+
tint
|
|
5140
|
+
} : {},
|
|
5141
|
+
...shade ? {
|
|
5142
|
+
shade
|
|
5143
|
+
} : {}
|
|
5144
|
+
};
|
|
5145
|
+
}
|
|
5146
|
+
function work_docx_paragraph_borders_import_wordLeafAttributes(element, allowed) {
|
|
5147
|
+
if (!work_docx_paragraph_borders_import_isWordElement(element) || work_ooxml_package_directChildren(element).length || Array.from(element.childNodes).some((node)=>node.nodeType === Node.TEXT_NODE && node.textContent?.trim())) return null;
|
|
5148
|
+
const result = new Map();
|
|
5149
|
+
for (const attribute of Array.from(element.attributes)){
|
|
5150
|
+
if (isNamespaceDeclaration(attribute)) continue;
|
|
5151
|
+
const name = xmlAttributeLocalName(attribute);
|
|
5152
|
+
if (xmlAttributeNamespace(element, attribute) !== element.namespaceURI || !allowed.has(name) || result.has(name)) return null;
|
|
5153
|
+
result.set(name, attribute.value);
|
|
5154
|
+
}
|
|
5155
|
+
return result;
|
|
5156
|
+
}
|
|
5157
|
+
function hasSemanticAttributes(element) {
|
|
5158
|
+
return Array.from(element.attributes).some((attribute)=>!isNamespaceDeclaration(attribute));
|
|
5159
|
+
}
|
|
5160
|
+
function isNamespaceDeclaration(attribute) {
|
|
5161
|
+
return attribute.namespaceURI === XMLNS_NAMESPACE || 'xmlns' === attribute.name || attribute.name.startsWith('xmlns:');
|
|
5162
|
+
}
|
|
5163
|
+
function unsignedInteger(value) {
|
|
5164
|
+
if (void 0 === value) return;
|
|
5165
|
+
const normalized = value.trim();
|
|
5166
|
+
if (!/^\+?\d+$/.test(normalized)) return null;
|
|
5167
|
+
const parsed = Number(normalized);
|
|
5168
|
+
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
5169
|
+
}
|
|
5170
|
+
function work_docx_paragraph_borders_import_onOffAttribute(value) {
|
|
5171
|
+
if (void 0 === value) return;
|
|
5172
|
+
const normalized = value.trim().toLowerCase();
|
|
5173
|
+
if ('1' === normalized || 'true' === normalized || 'on' === normalized) return true;
|
|
5174
|
+
if ('0' === normalized || 'false' === normalized || 'off' === normalized) return false;
|
|
5175
|
+
return null;
|
|
5176
|
+
}
|
|
5177
|
+
function byteHex(value) {
|
|
5178
|
+
if (void 0 === value) return;
|
|
5179
|
+
return /^[0-9a-f]{2}$/i.test(value) ? value.toUpperCase() : void 0;
|
|
5180
|
+
}
|
|
5181
|
+
function resetParagraphBorders() {
|
|
5182
|
+
return Object.fromEntries(DOCUMENT_PARAGRAPH_BORDER_EDGES.map((edge)=>[
|
|
5183
|
+
edge,
|
|
5184
|
+
{
|
|
5185
|
+
style: 'nil'
|
|
5186
|
+
}
|
|
5187
|
+
]));
|
|
5188
|
+
}
|
|
5189
|
+
function applyParagraphBorders(element, borders) {
|
|
5190
|
+
for (const [name, value] of Object.entries(documentParagraphBordersDomAttributes(borders))){
|
|
5191
|
+
if ('style' !== name) {
|
|
5192
|
+
element.setAttribute(name, value);
|
|
5193
|
+
continue;
|
|
5194
|
+
}
|
|
5195
|
+
for (const declaration of value.split(';')){
|
|
5196
|
+
const separator = declaration.indexOf(':');
|
|
5197
|
+
if (!(separator < 0)) element.style.setProperty(declaration.slice(0, separator).trim(), declaration.slice(separator + 1).trim());
|
|
5198
|
+
}
|
|
5199
|
+
}
|
|
5200
|
+
}
|
|
5201
|
+
function work_docx_paragraph_borders_import_insertParagraphMarker(document, paragraph, properties, marker) {
|
|
5202
|
+
const namespace = paragraph.namespaceURI ?? work_docx_paragraph_borders_import_WORD_NAMESPACE;
|
|
5203
|
+
const prefix = paragraph.prefix ?? 'w';
|
|
5204
|
+
const run = document.createElementNS(namespace, `${prefix}:r`);
|
|
5205
|
+
const text = document.createElementNS(namespace, `${prefix}:t`);
|
|
5206
|
+
text.setAttributeNS(work_docx_paragraph_borders_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
5207
|
+
text.textContent = marker;
|
|
5208
|
+
run.append(text);
|
|
5209
|
+
paragraph.insertBefore(run, properties.nextSibling);
|
|
5210
|
+
}
|
|
5211
|
+
function insertParagraphProperties(document, paragraph) {
|
|
5212
|
+
const namespace = paragraph.namespaceURI ?? work_docx_paragraph_borders_import_WORD_NAMESPACE;
|
|
5213
|
+
const prefix = paragraph.prefix ?? 'w';
|
|
5214
|
+
const properties = document.createElementNS(namespace, `${prefix}:pPr`);
|
|
5215
|
+
paragraph.insertBefore(properties, paragraph.firstChild);
|
|
5216
|
+
return properties;
|
|
5217
|
+
}
|
|
5218
|
+
function wordDirectChildren(parent, name) {
|
|
5219
|
+
return work_ooxml_package_directChildren(parent, name).filter(work_docx_paragraph_borders_import_isWordElement);
|
|
5220
|
+
}
|
|
5221
|
+
function work_docx_paragraph_borders_import_isWordElement(element) {
|
|
5222
|
+
return DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? '');
|
|
5223
|
+
}
|
|
5224
|
+
function closestParagraphBlock(element, markerNode) {
|
|
5225
|
+
const block = element?.closest('p, h1, h2, h3, h4, h5, h6, blockquote, li');
|
|
5226
|
+
if (!(block instanceof HTMLElement)) return null;
|
|
5227
|
+
return 'li' === block.tagName.toLowerCase() ? wrapListItemParagraph(block, markerNode) : block;
|
|
5228
|
+
}
|
|
5229
|
+
function wrapListItemParagraph(item, markerNode) {
|
|
5230
|
+
let anchor = markerNode;
|
|
5231
|
+
while(anchor.parentNode && anchor.parentNode !== item)anchor = anchor.parentNode;
|
|
5232
|
+
const children = Array.from(item.childNodes);
|
|
5233
|
+
const anchorIndex = children.indexOf(anchor);
|
|
5234
|
+
if (anchorIndex < 0) return item;
|
|
5235
|
+
let start = anchorIndex;
|
|
5236
|
+
let end = anchorIndex;
|
|
5237
|
+
while(start > 0 && !isListItemBlock(children[start - 1]))start -= 1;
|
|
5238
|
+
while(end + 1 < children.length && !isListItemBlock(children[end + 1]))end += 1;
|
|
5239
|
+
const paragraph = item.ownerDocument.createElement('p');
|
|
5240
|
+
const grouped = children.slice(start, end + 1);
|
|
5241
|
+
item.insertBefore(paragraph, grouped[0] ?? null);
|
|
5242
|
+
paragraph.append(...grouped);
|
|
5243
|
+
return paragraph;
|
|
5244
|
+
}
|
|
5245
|
+
function isListItemBlock(node) {
|
|
5246
|
+
if (!(node instanceof HTMLElement)) return false;
|
|
5247
|
+
return [
|
|
5248
|
+
'blockquote',
|
|
5249
|
+
'div',
|
|
5250
|
+
'h1',
|
|
5251
|
+
'h2',
|
|
5252
|
+
'h3',
|
|
5253
|
+
'h4',
|
|
5254
|
+
'h5',
|
|
5255
|
+
'h6',
|
|
5256
|
+
'hr',
|
|
5257
|
+
'ol',
|
|
5258
|
+
'p',
|
|
5259
|
+
'pre',
|
|
5260
|
+
'table',
|
|
5261
|
+
'ul'
|
|
5262
|
+
].includes(node.tagName.toLowerCase());
|
|
5263
|
+
}
|
|
5264
|
+
function work_docx_paragraph_borders_import_textNodes(root) {
|
|
5265
|
+
const document = root.ownerDocument;
|
|
5266
|
+
const walker = document?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
5267
|
+
const nodes = [];
|
|
5268
|
+
if (!walker) return nodes;
|
|
5269
|
+
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
5270
|
+
return nodes;
|
|
5271
|
+
}
|
|
5272
|
+
const PAGE_BORDER_EDGE_SET = new Set(DOCUMENT_PAGE_BORDER_EDGES);
|
|
5273
|
+
const PAGE_BORDER_ATTRIBUTES = new Set([
|
|
5274
|
+
'zOrder',
|
|
5275
|
+
'display',
|
|
5276
|
+
'offsetFrom'
|
|
5277
|
+
]);
|
|
5278
|
+
const PAGE_BORDER_DISPLAYS = new Set([
|
|
5279
|
+
'allPages',
|
|
5280
|
+
'firstPage',
|
|
5281
|
+
'notFirstPage'
|
|
5282
|
+
]);
|
|
5283
|
+
const PAGE_BORDER_OFFSETS = new Set([
|
|
5284
|
+
'page',
|
|
5285
|
+
'text'
|
|
5286
|
+
]);
|
|
5287
|
+
const PAGE_BORDER_Z_ORDERS = new Set([
|
|
5288
|
+
'front',
|
|
5289
|
+
'back'
|
|
5290
|
+
]);
|
|
5291
|
+
function inspectDocxPageBorders(sectionProperties, themeSource) {
|
|
5292
|
+
if ('sectPr' !== sectionProperties.localName || !DOCX_WORDPROCESSING_NAMESPACES.has(sectionProperties.namespaceURI ?? '')) return {
|
|
5293
|
+
status: 'absent',
|
|
5294
|
+
invalidCount: 0,
|
|
5295
|
+
spoofedCount: 0
|
|
5296
|
+
};
|
|
5297
|
+
const named = work_ooxml_package_directChildren(sectionProperties, 'pgBorders');
|
|
5298
|
+
const candidates = named.filter((element)=>element.namespaceURI === sectionProperties.namespaceURI);
|
|
5299
|
+
const spoofedContainers = named.length - candidates.length;
|
|
5300
|
+
if (!candidates.length) return {
|
|
5301
|
+
status: 'absent',
|
|
5302
|
+
invalidCount: 0,
|
|
5303
|
+
spoofedCount: spoofedContainers
|
|
5304
|
+
};
|
|
5305
|
+
if (1 !== candidates.length) return {
|
|
5306
|
+
status: 'invalid',
|
|
5307
|
+
invalidCount: candidates.length,
|
|
5308
|
+
spoofedCount: spoofedContainers
|
|
5309
|
+
};
|
|
5310
|
+
const container = candidates[0];
|
|
5311
|
+
if (!container) return {
|
|
5312
|
+
status: 'invalid',
|
|
5313
|
+
invalidCount: 1,
|
|
5314
|
+
spoofedCount: spoofedContainers
|
|
5315
|
+
};
|
|
5316
|
+
const attributes = wordContainerAttributes(container);
|
|
5317
|
+
if (!attributes || hasNonWhitespaceText(container)) return {
|
|
5318
|
+
status: 'invalid',
|
|
5319
|
+
invalidCount: 1,
|
|
5320
|
+
spoofedCount: spoofedContainers
|
|
5321
|
+
};
|
|
5322
|
+
const display = pageBorderDisplay(attributes.get('display'));
|
|
5323
|
+
const offsetFrom = pageBorderOffset(attributes.get('offsetFrom'));
|
|
5324
|
+
const zOrder = pageBorderZOrder(attributes.get('zOrder'));
|
|
5325
|
+
if (null === display || null === offsetFrom || null === zOrder) return {
|
|
5326
|
+
status: 'invalid',
|
|
5327
|
+
invalidCount: 1,
|
|
5328
|
+
spoofedCount: spoofedContainers
|
|
5329
|
+
};
|
|
5330
|
+
const theme = work_docx_theme_resolveDocxThemeResolver(themeSource);
|
|
5331
|
+
const edges = {};
|
|
5332
|
+
let invalidCount = 0;
|
|
5333
|
+
let spoofedCount = spoofedContainers;
|
|
5334
|
+
let previousIndex = -1;
|
|
5335
|
+
const seen = new Set();
|
|
5336
|
+
for (const child of work_ooxml_package_directChildren(container)){
|
|
5337
|
+
if (child.namespaceURI !== container.namespaceURI) {
|
|
5338
|
+
spoofedCount += 1;
|
|
5339
|
+
continue;
|
|
5340
|
+
}
|
|
5341
|
+
const edge = child.localName;
|
|
5342
|
+
const index = DOCUMENT_PAGE_BORDER_EDGES.indexOf(edge);
|
|
5343
|
+
if (!PAGE_BORDER_EDGE_SET.has(edge) || index < previousIndex || seen.has(edge)) return {
|
|
5344
|
+
status: 'invalid',
|
|
5345
|
+
invalidCount: invalidCount + 1,
|
|
5346
|
+
spoofedCount
|
|
5347
|
+
};
|
|
5348
|
+
previousIndex = index;
|
|
5349
|
+
seen.add(edge);
|
|
5350
|
+
const border = parseDocxBorderElement(child, theme);
|
|
5351
|
+
if (border) edges[edge] = border;
|
|
5352
|
+
else {
|
|
5353
|
+
invalidCount += 1;
|
|
5354
|
+
edges[edge] = {
|
|
5355
|
+
style: 'nil'
|
|
5356
|
+
};
|
|
5357
|
+
}
|
|
5358
|
+
}
|
|
5359
|
+
const pageBorders = normalizeDocumentPageBorders({
|
|
5360
|
+
...display ? {
|
|
5361
|
+
display
|
|
5362
|
+
} : {},
|
|
5363
|
+
...offsetFrom ? {
|
|
5364
|
+
offsetFrom
|
|
5100
5365
|
} : {},
|
|
5101
|
-
...
|
|
5102
|
-
|
|
5366
|
+
...zOrder ? {
|
|
5367
|
+
zOrder
|
|
5103
5368
|
} : {},
|
|
5104
|
-
|
|
5105
|
-
frame
|
|
5106
|
-
} : {}
|
|
5369
|
+
edges
|
|
5107
5370
|
});
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
const rawTint = attributes.get('themeTint')?.trim();
|
|
5113
|
-
const rawShade = attributes.get('themeShade')?.trim();
|
|
5114
|
-
if (void 0 === rawColor && void 0 === rawTheme && void 0 === rawTint && void 0 === rawShade) return;
|
|
5115
|
-
const color = 'auto' === rawColor ? 'auto' : rawColor && /^[0-9a-f]{6}$/i.test(rawColor) ? `#${rawColor.toLowerCase()}` : null;
|
|
5116
|
-
const themeName = rawTheme && work_docx_paragraph_borders_import_WORD_THEME_COLORS.has(rawTheme) ? rawTheme : null;
|
|
5117
|
-
const tint = byteHex(rawTint);
|
|
5118
|
-
const shade = byteHex(rawShade);
|
|
5119
|
-
if (void 0 !== rawColor && !color || void 0 !== rawTheme && !themeName || void 0 !== rawTint && !tint || void 0 !== rawShade && !shade || (!themeName || 'none' === themeName) && (tint || shade)) return null;
|
|
5120
|
-
if (themeName && 'none' !== themeName) {
|
|
5121
|
-
const resolved = docxThemeColor(theme, themeName, tint, tint ? void 0 : shade);
|
|
5122
|
-
const fallback = color && 'auto' !== color ? color : null;
|
|
5123
|
-
const semanticValue = resolved ? `#${resolved}` : fallback;
|
|
5124
|
-
if (!semanticValue) return null;
|
|
5125
|
-
return {
|
|
5126
|
-
value: semanticValue,
|
|
5127
|
-
theme: work_docx_paragraph_borders_import_themeReference(themeName, semanticValue, tint, shade)
|
|
5128
|
-
};
|
|
5129
|
-
}
|
|
5130
|
-
if ('none' === themeName) {
|
|
5131
|
-
const value = color ?? 'auto';
|
|
5132
|
-
return {
|
|
5133
|
-
value,
|
|
5134
|
-
theme: work_docx_paragraph_borders_import_themeReference(themeName, 'auto' === value ? '#000000' : value, tint, shade)
|
|
5135
|
-
};
|
|
5136
|
-
}
|
|
5137
|
-
if (!color) return null;
|
|
5138
|
-
return {
|
|
5139
|
-
value: color
|
|
5371
|
+
if (!pageBorders) return {
|
|
5372
|
+
status: 'invalid',
|
|
5373
|
+
invalidCount: invalidCount + 1,
|
|
5374
|
+
spoofedCount
|
|
5140
5375
|
};
|
|
5141
|
-
}
|
|
5142
|
-
function work_docx_paragraph_borders_import_themeReference(theme, resolved, tint, shade) {
|
|
5143
5376
|
return {
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
} : {},
|
|
5149
|
-
...shade ? {
|
|
5150
|
-
shade
|
|
5151
|
-
} : {}
|
|
5377
|
+
status: 'valid',
|
|
5378
|
+
pageBorders,
|
|
5379
|
+
invalidCount,
|
|
5380
|
+
spoofedCount
|
|
5152
5381
|
};
|
|
5153
5382
|
}
|
|
5154
|
-
function
|
|
5155
|
-
|
|
5383
|
+
function parseDocxPageBorders(sectionProperties, themeSource) {
|
|
5384
|
+
const inspected = inspectDocxPageBorders(sectionProperties, themeSource);
|
|
5385
|
+
if ('absent' === inspected.status) return;
|
|
5386
|
+
return 'valid' === inspected.status ? inspected.pageBorders : null;
|
|
5387
|
+
}
|
|
5388
|
+
function wordContainerAttributes(element) {
|
|
5156
5389
|
const result = new Map();
|
|
5157
5390
|
for (const attribute of Array.from(element.attributes)){
|
|
5158
|
-
if (
|
|
5391
|
+
if (work_docx_page_borders_import_isNamespaceDeclaration(attribute)) continue;
|
|
5159
5392
|
const name = xmlAttributeLocalName(attribute);
|
|
5160
|
-
if (xmlAttributeNamespace(element, attribute) !== element.namespaceURI || !
|
|
5393
|
+
if (xmlAttributeNamespace(element, attribute) !== element.namespaceURI || !PAGE_BORDER_ATTRIBUTES.has(name) || result.has(name)) return null;
|
|
5161
5394
|
result.set(name, attribute.value);
|
|
5162
5395
|
}
|
|
5163
5396
|
return result;
|
|
5164
5397
|
}
|
|
5165
|
-
function
|
|
5166
|
-
return Array.from(element.attributes).some((attribute)=>!isNamespaceDeclaration(attribute));
|
|
5167
|
-
}
|
|
5168
|
-
function isNamespaceDeclaration(attribute) {
|
|
5169
|
-
return attribute.namespaceURI === XMLNS_NAMESPACE || 'xmlns' === attribute.name || attribute.name.startsWith('xmlns:');
|
|
5170
|
-
}
|
|
5171
|
-
function unsignedInteger(value) {
|
|
5398
|
+
function pageBorderDisplay(value) {
|
|
5172
5399
|
if (void 0 === value) return;
|
|
5173
5400
|
const normalized = value.trim();
|
|
5174
|
-
|
|
5175
|
-
const parsed = Number(normalized);
|
|
5176
|
-
return Number.isSafeInteger(parsed) ? parsed : null;
|
|
5401
|
+
return PAGE_BORDER_DISPLAYS.has(normalized) ? normalized : null;
|
|
5177
5402
|
}
|
|
5178
|
-
function
|
|
5403
|
+
function pageBorderOffset(value) {
|
|
5179
5404
|
if (void 0 === value) return;
|
|
5180
|
-
const normalized = value.trim()
|
|
5181
|
-
|
|
5182
|
-
if ('0' === normalized || 'false' === normalized || 'off' === normalized) return false;
|
|
5183
|
-
return null;
|
|
5405
|
+
const normalized = value.trim();
|
|
5406
|
+
return PAGE_BORDER_OFFSETS.has(normalized) ? normalized : null;
|
|
5184
5407
|
}
|
|
5185
|
-
function
|
|
5408
|
+
function pageBorderZOrder(value) {
|
|
5186
5409
|
if (void 0 === value) return;
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
function resetParagraphBorders() {
|
|
5190
|
-
return Object.fromEntries(DOCUMENT_PARAGRAPH_BORDER_EDGES.map((edge)=>[
|
|
5191
|
-
edge,
|
|
5192
|
-
{
|
|
5193
|
-
style: 'nil'
|
|
5194
|
-
}
|
|
5195
|
-
]));
|
|
5196
|
-
}
|
|
5197
|
-
function applyParagraphBorders(element, borders) {
|
|
5198
|
-
for (const [name, value] of Object.entries(documentParagraphBordersDomAttributes(borders))){
|
|
5199
|
-
if ('style' !== name) {
|
|
5200
|
-
element.setAttribute(name, value);
|
|
5201
|
-
continue;
|
|
5202
|
-
}
|
|
5203
|
-
for (const declaration of value.split(';')){
|
|
5204
|
-
const separator = declaration.indexOf(':');
|
|
5205
|
-
if (!(separator < 0)) element.style.setProperty(declaration.slice(0, separator).trim(), declaration.slice(separator + 1).trim());
|
|
5206
|
-
}
|
|
5207
|
-
}
|
|
5410
|
+
const normalized = value.trim();
|
|
5411
|
+
return PAGE_BORDER_Z_ORDERS.has(normalized) ? normalized : null;
|
|
5208
5412
|
}
|
|
5209
|
-
function
|
|
5210
|
-
|
|
5211
|
-
const prefix = paragraph.prefix ?? 'w';
|
|
5212
|
-
const run = document.createElementNS(namespace, `${prefix}:r`);
|
|
5213
|
-
const text = document.createElementNS(namespace, `${prefix}:t`);
|
|
5214
|
-
text.setAttributeNS(work_docx_paragraph_borders_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
5215
|
-
text.textContent = marker;
|
|
5216
|
-
run.append(text);
|
|
5217
|
-
paragraph.insertBefore(run, properties.nextSibling);
|
|
5413
|
+
function hasNonWhitespaceText(element) {
|
|
5414
|
+
return Array.from(element.childNodes).some((node)=>node.nodeType === Node.TEXT_NODE && node.textContent?.trim());
|
|
5218
5415
|
}
|
|
5219
|
-
function
|
|
5220
|
-
|
|
5221
|
-
const prefix = paragraph.prefix ?? 'w';
|
|
5222
|
-
const properties = document.createElementNS(namespace, `${prefix}:pPr`);
|
|
5223
|
-
paragraph.insertBefore(properties, paragraph.firstChild);
|
|
5224
|
-
return properties;
|
|
5416
|
+
function work_docx_page_borders_import_isNamespaceDeclaration(attribute) {
|
|
5417
|
+
return attribute.namespaceURI === work_docx_settings_xml_XMLNS_NAMESPACE || 'xmlns' === attribute.name || attribute.name.startsWith('xmlns:');
|
|
5225
5418
|
}
|
|
5226
|
-
|
|
5227
|
-
|
|
5419
|
+
const ON_VALUES = new Set([
|
|
5420
|
+
'1',
|
|
5421
|
+
'on',
|
|
5422
|
+
'true'
|
|
5423
|
+
]);
|
|
5424
|
+
const OFF_VALUES = new Set([
|
|
5425
|
+
'0',
|
|
5426
|
+
'off',
|
|
5427
|
+
'false'
|
|
5428
|
+
]);
|
|
5429
|
+
function inspectDocxHiddenText(properties) {
|
|
5430
|
+
if (!properties) return {
|
|
5431
|
+
status: 'absent'
|
|
5432
|
+
};
|
|
5433
|
+
const localMatches = work_ooxml_package_directChildren(properties, 'vanish');
|
|
5434
|
+
if (!localMatches.length) return {
|
|
5435
|
+
status: 'absent'
|
|
5436
|
+
};
|
|
5437
|
+
const nativeMatches = localMatches.filter((element)=>DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? ''));
|
|
5438
|
+
if (1 !== localMatches.length || 1 !== nativeMatches.length) return {
|
|
5439
|
+
status: 'invalid'
|
|
5440
|
+
};
|
|
5441
|
+
const vanish = nativeMatches[0];
|
|
5442
|
+
if (work_ooxml_package_directChildren(vanish).length || Array.from(vanish.childNodes).some((node)=>(node.nodeType === Node.TEXT_NODE || node.nodeType === Node.CDATA_SECTION_NODE) && Boolean(node.textContent?.trim()))) return {
|
|
5443
|
+
status: 'invalid'
|
|
5444
|
+
};
|
|
5445
|
+
const attributes = Array.from(vanish.attributes).filter((attribute)=>xmlAttributeNamespace(vanish, attribute) !== work_docx_settings_xml_XMLNS_NAMESPACE && 'xmlns' !== attribute.name && !attribute.name.startsWith('xmlns:'));
|
|
5446
|
+
if (!attributes.length) return {
|
|
5447
|
+
status: 'valid',
|
|
5448
|
+
value: true
|
|
5449
|
+
};
|
|
5450
|
+
if (1 !== attributes.length || 'val' !== xmlAttributeLocalName(attributes[0]) || !DOCX_WORDPROCESSING_NAMESPACES.has(xmlAttributeNamespace(vanish, attributes[0]) ?? '')) return {
|
|
5451
|
+
status: 'invalid'
|
|
5452
|
+
};
|
|
5453
|
+
const value = attributes[0].value;
|
|
5454
|
+
if (ON_VALUES.has(value)) return {
|
|
5455
|
+
status: 'valid',
|
|
5456
|
+
value: true
|
|
5457
|
+
};
|
|
5458
|
+
if (OFF_VALUES.has(value)) return {
|
|
5459
|
+
status: 'valid',
|
|
5460
|
+
value: false
|
|
5461
|
+
};
|
|
5462
|
+
return {
|
|
5463
|
+
status: 'invalid'
|
|
5464
|
+
};
|
|
5228
5465
|
}
|
|
5229
|
-
function
|
|
5230
|
-
|
|
5466
|
+
function docxHiddenTextFromProperties(properties) {
|
|
5467
|
+
const inspection = inspectDocxHiddenText(properties);
|
|
5468
|
+
return 'valid' === inspection.status ? inspection.value : void 0;
|
|
5231
5469
|
}
|
|
5232
|
-
function
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5470
|
+
function resolveDocxHiddenText(propertySources) {
|
|
5471
|
+
let hiddenText;
|
|
5472
|
+
for (const properties of propertySources){
|
|
5473
|
+
const candidate = docxHiddenTextFromProperties(properties);
|
|
5474
|
+
if (void 0 !== candidate) hiddenText = candidate;
|
|
5475
|
+
}
|
|
5476
|
+
return hiddenText;
|
|
5236
5477
|
}
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5478
|
+
const work_docx_legacy_text_effects_ON_VALUES = new Set([
|
|
5479
|
+
'1',
|
|
5480
|
+
'on',
|
|
5481
|
+
'true'
|
|
5482
|
+
]);
|
|
5483
|
+
const work_docx_legacy_text_effects_OFF_VALUES = new Set([
|
|
5484
|
+
'0',
|
|
5485
|
+
'off',
|
|
5486
|
+
'false'
|
|
5487
|
+
]);
|
|
5488
|
+
function inspectDocxLegacyTextEffects(properties) {
|
|
5489
|
+
if (!properties) return {
|
|
5490
|
+
status: 'absent'
|
|
5491
|
+
};
|
|
5492
|
+
const effects = {};
|
|
5493
|
+
let present = false;
|
|
5494
|
+
for (const name of DOCUMENT_LEGACY_TEXT_EFFECT_NAMES){
|
|
5495
|
+
const localMatches = work_ooxml_package_directChildren(properties, name);
|
|
5496
|
+
if (!localMatches.length) continue;
|
|
5497
|
+
present = true;
|
|
5498
|
+
const nativeMatches = localMatches.filter((element)=>DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? ''));
|
|
5499
|
+
if (1 !== localMatches.length || 1 !== nativeMatches.length) return {
|
|
5500
|
+
status: 'invalid'
|
|
5501
|
+
};
|
|
5502
|
+
const value = inspectOnOffLeaf(nativeMatches[0]);
|
|
5503
|
+
if (null === value) return {
|
|
5504
|
+
status: 'invalid'
|
|
5505
|
+
};
|
|
5506
|
+
effects[name] = value;
|
|
5507
|
+
}
|
|
5508
|
+
if (!present) return {
|
|
5509
|
+
status: 'absent'
|
|
5510
|
+
};
|
|
5511
|
+
return documentLegacyTextEffectsConflict(effects) ? {
|
|
5512
|
+
status: 'invalid'
|
|
5513
|
+
} : {
|
|
5514
|
+
status: 'valid',
|
|
5515
|
+
value: effects
|
|
5516
|
+
};
|
|
5252
5517
|
}
|
|
5253
|
-
function
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
'
|
|
5259
|
-
'
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
5265
|
-
|
|
5266
|
-
'p',
|
|
5267
|
-
'pre',
|
|
5268
|
-
'table',
|
|
5269
|
-
'ul'
|
|
5270
|
-
].includes(node.tagName.toLowerCase());
|
|
5518
|
+
function resolveDocxLegacyTextEffects(propertySources) {
|
|
5519
|
+
const effects = {};
|
|
5520
|
+
let present = false;
|
|
5521
|
+
for (const properties of propertySources){
|
|
5522
|
+
const inspection = inspectDocxLegacyTextEffects(properties);
|
|
5523
|
+
if ('invalid' === inspection.status) return;
|
|
5524
|
+
if ('valid' === inspection.status) {
|
|
5525
|
+
Object.assign(effects, inspection.value);
|
|
5526
|
+
present = true;
|
|
5527
|
+
if (documentLegacyTextEffectsConflict(effects)) return;
|
|
5528
|
+
}
|
|
5529
|
+
}
|
|
5530
|
+
return present ? effects : void 0;
|
|
5271
5531
|
}
|
|
5272
|
-
function
|
|
5273
|
-
|
|
5274
|
-
const
|
|
5275
|
-
|
|
5276
|
-
if (!
|
|
5277
|
-
|
|
5278
|
-
return
|
|
5532
|
+
function inspectOnOffLeaf(element) {
|
|
5533
|
+
if (work_ooxml_package_directChildren(element).length || Array.from(element.childNodes).some((node)=>(node.nodeType === Node.TEXT_NODE || node.nodeType === Node.CDATA_SECTION_NODE) && Boolean(node.textContent?.trim()))) return null;
|
|
5534
|
+
const attributes = Array.from(element.attributes).filter((attribute)=>xmlAttributeNamespace(element, attribute) !== work_docx_settings_xml_XMLNS_NAMESPACE && 'xmlns' !== attribute.name && !attribute.name.startsWith('xmlns:'));
|
|
5535
|
+
if (!attributes.length) return true;
|
|
5536
|
+
if (1 !== attributes.length || 'val' !== xmlAttributeLocalName(attributes[0]) || !DOCX_WORDPROCESSING_NAMESPACES.has(xmlAttributeNamespace(element, attributes[0]) ?? '')) return null;
|
|
5537
|
+
const value = attributes[0].value;
|
|
5538
|
+
if (work_docx_legacy_text_effects_ON_VALUES.has(value)) return true;
|
|
5539
|
+
if (work_docx_legacy_text_effects_OFF_VALUES.has(value)) return false;
|
|
5540
|
+
return null;
|
|
5279
5541
|
}
|
|
5280
5542
|
function inspectDocxRunBorder(properties, themeSource) {
|
|
5281
5543
|
return inspectDocxRunBorderWithTheme(properties, work_docx_theme_resolveDocxThemeResolver(themeSource));
|
|
@@ -5635,247 +5897,100 @@ function resolveDocxRunShading(propertySources, themeSource) {
|
|
|
5635
5897
|
invalidCount += 1;
|
|
5636
5898
|
shading = {
|
|
5637
5899
|
pattern: 'nil'
|
|
5638
|
-
};
|
|
5639
|
-
}
|
|
5640
|
-
}
|
|
5641
|
-
return {
|
|
5642
|
-
shading,
|
|
5643
|
-
invalidCount,
|
|
5644
|
-
spoofedCount
|
|
5645
|
-
};
|
|
5646
|
-
}
|
|
5647
|
-
function inspectDocxRunShadingWithTheme(properties, theme) {
|
|
5648
|
-
if (!properties) return {
|
|
5649
|
-
status: 'absent',
|
|
5650
|
-
spoofedCount: 0
|
|
5651
|
-
};
|
|
5652
|
-
const matches = work_ooxml_package_directChildren(properties, 'shd');
|
|
5653
|
-
if (!matches.length) return {
|
|
5654
|
-
status: 'absent',
|
|
5655
|
-
spoofedCount: 0
|
|
5656
|
-
};
|
|
5657
|
-
const native = matches.filter((element)=>element.namespaceURI === properties.namespaceURI && DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? ''));
|
|
5658
|
-
const spoofedCount = matches.length - native.length;
|
|
5659
|
-
if (1 !== matches.length || 1 !== native.length) return {
|
|
5660
|
-
status: 'invalid',
|
|
5661
|
-
spoofedCount
|
|
5662
|
-
};
|
|
5663
|
-
const parsed = parseDocxParagraphShadingElement(native[0], theme);
|
|
5664
|
-
return parsed ? {
|
|
5665
|
-
status: 'valid',
|
|
5666
|
-
value: parsed,
|
|
5667
|
-
spoofedCount
|
|
5668
|
-
} : {
|
|
5669
|
-
status: 'invalid',
|
|
5670
|
-
spoofedCount
|
|
5671
|
-
};
|
|
5672
|
-
}
|
|
5673
|
-
function importedDocxUnderline(element, theme) {
|
|
5674
|
-
const rawStyle = work_ooxml_package_attribute(element, 'val');
|
|
5675
|
-
const style = null === rawStyle ? 'single' : normalizeDocumentUnderlineStyle(rawStyle) ?? 'single';
|
|
5676
|
-
const themeName = work_ooxml_package_attribute(element, 'themeColor')?.trim();
|
|
5677
|
-
const tint = normalizedByteHex(work_ooxml_package_attribute(element, 'themeTint'));
|
|
5678
|
-
const shade = normalizedByteHex(work_ooxml_package_attribute(element, 'themeShade'));
|
|
5679
|
-
const themed = theme && themeName ? docxThemeColor(theme, themeName, tint, shade) : void 0;
|
|
5680
|
-
const direct = normalizeDocumentUnderlineColor(work_ooxml_package_attribute(element, 'color'));
|
|
5681
|
-
const color = themed ? `#${themed}` : direct;
|
|
5682
|
-
const themeColor = themeName && color ? underlineThemeReference(themeName, color, tint, shade) : void 0;
|
|
5683
|
-
return {
|
|
5684
|
-
style,
|
|
5685
|
-
...color ? {
|
|
5686
|
-
color
|
|
5687
|
-
} : {},
|
|
5688
|
-
...themeColor ? {
|
|
5689
|
-
themeColor
|
|
5690
|
-
} : {}
|
|
5691
|
-
};
|
|
5692
|
-
}
|
|
5693
|
-
function underlineThemeReference(theme, resolved, tint, shade) {
|
|
5694
|
-
return {
|
|
5695
|
-
theme,
|
|
5696
|
-
resolved,
|
|
5697
|
-
...tint ? {
|
|
5698
|
-
tint
|
|
5699
|
-
} : {},
|
|
5700
|
-
...shade ? {
|
|
5701
|
-
shade
|
|
5702
|
-
} : {}
|
|
5703
|
-
};
|
|
5704
|
-
}
|
|
5705
|
-
function normalizedByteHex(value) {
|
|
5706
|
-
const normalized = value?.trim().toUpperCase();
|
|
5707
|
-
return normalized && /^[0-9A-F]{2}$/.test(normalized) ? normalized : void 0;
|
|
5708
|
-
}
|
|
5709
|
-
function importedDocxStrikeFlags(properties) {
|
|
5710
|
-
return {
|
|
5711
|
-
...importedFlag(directChild(properties, 'strike'), 'single'),
|
|
5712
|
-
...importedFlag(directChild(properties, 'dstrike'), 'double')
|
|
5713
|
-
};
|
|
5714
|
-
}
|
|
5715
|
-
function importedDocxStrike(properties) {
|
|
5716
|
-
const flags = importedDocxStrikeFlags(properties);
|
|
5717
|
-
return resolvedDocxStrikeFormatting(flags.single, flags.double);
|
|
5718
|
-
}
|
|
5719
|
-
function resolvedDocxStrikeFormatting(single, double, materializeNone = false) {
|
|
5720
|
-
if (void 0 === single && void 0 === double && !materializeNone) return;
|
|
5721
|
-
const style = double ? 'double' : single ? 'single' : 'none';
|
|
5722
|
-
return {
|
|
5723
|
-
style
|
|
5724
|
-
};
|
|
5725
|
-
}
|
|
5726
|
-
function importedFlag(element, name) {
|
|
5727
|
-
if (!element) return {};
|
|
5728
|
-
const value = work_ooxml_package_attribute(element, 'val')?.trim().toLowerCase();
|
|
5729
|
-
return {
|
|
5730
|
-
[name]: '0' !== value && 'false' !== value && 'off' !== value
|
|
5731
|
-
};
|
|
5732
|
-
}
|
|
5733
|
-
const PAGE_BORDER_EDGE_SET = new Set(DOCUMENT_PAGE_BORDER_EDGES);
|
|
5734
|
-
const PAGE_BORDER_ATTRIBUTES = new Set([
|
|
5735
|
-
'zOrder',
|
|
5736
|
-
'display',
|
|
5737
|
-
'offsetFrom'
|
|
5738
|
-
]);
|
|
5739
|
-
const PAGE_BORDER_DISPLAYS = new Set([
|
|
5740
|
-
'allPages',
|
|
5741
|
-
'firstPage',
|
|
5742
|
-
'notFirstPage'
|
|
5743
|
-
]);
|
|
5744
|
-
const PAGE_BORDER_OFFSETS = new Set([
|
|
5745
|
-
'page',
|
|
5746
|
-
'text'
|
|
5747
|
-
]);
|
|
5748
|
-
const PAGE_BORDER_Z_ORDERS = new Set([
|
|
5749
|
-
'front',
|
|
5750
|
-
'back'
|
|
5751
|
-
]);
|
|
5752
|
-
function inspectDocxPageBorders(sectionProperties, themeSource) {
|
|
5753
|
-
if ('sectPr' !== sectionProperties.localName || !DOCX_WORDPROCESSING_NAMESPACES.has(sectionProperties.namespaceURI ?? '')) return {
|
|
5754
|
-
status: 'absent',
|
|
5755
|
-
invalidCount: 0,
|
|
5756
|
-
spoofedCount: 0
|
|
5757
|
-
};
|
|
5758
|
-
const named = work_ooxml_package_directChildren(sectionProperties, 'pgBorders');
|
|
5759
|
-
const candidates = named.filter((element)=>element.namespaceURI === sectionProperties.namespaceURI);
|
|
5760
|
-
const spoofedContainers = named.length - candidates.length;
|
|
5761
|
-
if (!candidates.length) return {
|
|
5762
|
-
status: 'absent',
|
|
5763
|
-
invalidCount: 0,
|
|
5764
|
-
spoofedCount: spoofedContainers
|
|
5765
|
-
};
|
|
5766
|
-
if (1 !== candidates.length) return {
|
|
5767
|
-
status: 'invalid',
|
|
5768
|
-
invalidCount: candidates.length,
|
|
5769
|
-
spoofedCount: spoofedContainers
|
|
5770
|
-
};
|
|
5771
|
-
const container = candidates[0];
|
|
5772
|
-
if (!container) return {
|
|
5773
|
-
status: 'invalid',
|
|
5774
|
-
invalidCount: 1,
|
|
5775
|
-
spoofedCount: spoofedContainers
|
|
5776
|
-
};
|
|
5777
|
-
const attributes = wordContainerAttributes(container);
|
|
5778
|
-
if (!attributes || hasNonWhitespaceText(container)) return {
|
|
5779
|
-
status: 'invalid',
|
|
5780
|
-
invalidCount: 1,
|
|
5781
|
-
spoofedCount: spoofedContainers
|
|
5782
|
-
};
|
|
5783
|
-
const display = pageBorderDisplay(attributes.get('display'));
|
|
5784
|
-
const offsetFrom = pageBorderOffset(attributes.get('offsetFrom'));
|
|
5785
|
-
const zOrder = pageBorderZOrder(attributes.get('zOrder'));
|
|
5786
|
-
if (null === display || null === offsetFrom || null === zOrder) return {
|
|
5787
|
-
status: 'invalid',
|
|
5788
|
-
invalidCount: 1,
|
|
5789
|
-
spoofedCount: spoofedContainers
|
|
5790
|
-
};
|
|
5791
|
-
const theme = work_docx_theme_resolveDocxThemeResolver(themeSource);
|
|
5792
|
-
const edges = {};
|
|
5793
|
-
let invalidCount = 0;
|
|
5794
|
-
let spoofedCount = spoofedContainers;
|
|
5795
|
-
let previousIndex = -1;
|
|
5796
|
-
const seen = new Set();
|
|
5797
|
-
for (const child of work_ooxml_package_directChildren(container)){
|
|
5798
|
-
if (child.namespaceURI !== container.namespaceURI) {
|
|
5799
|
-
spoofedCount += 1;
|
|
5800
|
-
continue;
|
|
5801
|
-
}
|
|
5802
|
-
const edge = child.localName;
|
|
5803
|
-
const index = DOCUMENT_PAGE_BORDER_EDGES.indexOf(edge);
|
|
5804
|
-
if (!PAGE_BORDER_EDGE_SET.has(edge) || index < previousIndex || seen.has(edge)) return {
|
|
5805
|
-
status: 'invalid',
|
|
5806
|
-
invalidCount: invalidCount + 1,
|
|
5807
|
-
spoofedCount
|
|
5808
|
-
};
|
|
5809
|
-
previousIndex = index;
|
|
5810
|
-
seen.add(edge);
|
|
5811
|
-
const border = parseDocxBorderElement(child, theme);
|
|
5812
|
-
if (border) edges[edge] = border;
|
|
5813
|
-
else {
|
|
5814
|
-
invalidCount += 1;
|
|
5815
|
-
edges[edge] = {
|
|
5816
|
-
style: 'nil'
|
|
5817
|
-
};
|
|
5818
|
-
}
|
|
5819
|
-
}
|
|
5820
|
-
const pageBorders = normalizeDocumentPageBorders({
|
|
5821
|
-
...display ? {
|
|
5822
|
-
display
|
|
5823
|
-
} : {},
|
|
5824
|
-
...offsetFrom ? {
|
|
5825
|
-
offsetFrom
|
|
5826
|
-
} : {},
|
|
5827
|
-
...zOrder ? {
|
|
5828
|
-
zOrder
|
|
5829
|
-
} : {},
|
|
5830
|
-
edges
|
|
5831
|
-
});
|
|
5832
|
-
if (!pageBorders) return {
|
|
5900
|
+
};
|
|
5901
|
+
}
|
|
5902
|
+
}
|
|
5903
|
+
return {
|
|
5904
|
+
shading,
|
|
5905
|
+
invalidCount,
|
|
5906
|
+
spoofedCount
|
|
5907
|
+
};
|
|
5908
|
+
}
|
|
5909
|
+
function inspectDocxRunShadingWithTheme(properties, theme) {
|
|
5910
|
+
if (!properties) return {
|
|
5911
|
+
status: 'absent',
|
|
5912
|
+
spoofedCount: 0
|
|
5913
|
+
};
|
|
5914
|
+
const matches = work_ooxml_package_directChildren(properties, 'shd');
|
|
5915
|
+
if (!matches.length) return {
|
|
5916
|
+
status: 'absent',
|
|
5917
|
+
spoofedCount: 0
|
|
5918
|
+
};
|
|
5919
|
+
const native = matches.filter((element)=>element.namespaceURI === properties.namespaceURI && DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? ''));
|
|
5920
|
+
const spoofedCount = matches.length - native.length;
|
|
5921
|
+
if (1 !== matches.length || 1 !== native.length) return {
|
|
5833
5922
|
status: 'invalid',
|
|
5834
|
-
invalidCount: invalidCount + 1,
|
|
5835
5923
|
spoofedCount
|
|
5836
5924
|
};
|
|
5837
|
-
|
|
5925
|
+
const parsed = parseDocxParagraphShadingElement(native[0], theme);
|
|
5926
|
+
return parsed ? {
|
|
5838
5927
|
status: 'valid',
|
|
5839
|
-
|
|
5840
|
-
|
|
5928
|
+
value: parsed,
|
|
5929
|
+
spoofedCount
|
|
5930
|
+
} : {
|
|
5931
|
+
status: 'invalid',
|
|
5841
5932
|
spoofedCount
|
|
5842
5933
|
};
|
|
5843
5934
|
}
|
|
5844
|
-
function
|
|
5845
|
-
const
|
|
5846
|
-
|
|
5847
|
-
|
|
5935
|
+
function importedDocxUnderline(element, theme) {
|
|
5936
|
+
const rawStyle = work_ooxml_package_attribute(element, 'val');
|
|
5937
|
+
const style = null === rawStyle ? 'single' : normalizeDocumentUnderlineStyle(rawStyle) ?? 'single';
|
|
5938
|
+
const themeName = work_ooxml_package_attribute(element, 'themeColor')?.trim();
|
|
5939
|
+
const tint = normalizedByteHex(work_ooxml_package_attribute(element, 'themeTint'));
|
|
5940
|
+
const shade = normalizedByteHex(work_ooxml_package_attribute(element, 'themeShade'));
|
|
5941
|
+
const themed = theme && themeName ? docxThemeColor(theme, themeName, tint, shade) : void 0;
|
|
5942
|
+
const direct = normalizeDocumentUnderlineColor(work_ooxml_package_attribute(element, 'color'));
|
|
5943
|
+
const color = themed ? `#${themed}` : direct;
|
|
5944
|
+
const themeColor = themeName && color ? underlineThemeReference(themeName, color, tint, shade) : void 0;
|
|
5945
|
+
return {
|
|
5946
|
+
style,
|
|
5947
|
+
...color ? {
|
|
5948
|
+
color
|
|
5949
|
+
} : {},
|
|
5950
|
+
...themeColor ? {
|
|
5951
|
+
themeColor
|
|
5952
|
+
} : {}
|
|
5953
|
+
};
|
|
5848
5954
|
}
|
|
5849
|
-
function
|
|
5850
|
-
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
|
|
5855
|
-
|
|
5856
|
-
|
|
5857
|
-
|
|
5955
|
+
function underlineThemeReference(theme, resolved, tint, shade) {
|
|
5956
|
+
return {
|
|
5957
|
+
theme,
|
|
5958
|
+
resolved,
|
|
5959
|
+
...tint ? {
|
|
5960
|
+
tint
|
|
5961
|
+
} : {},
|
|
5962
|
+
...shade ? {
|
|
5963
|
+
shade
|
|
5964
|
+
} : {}
|
|
5965
|
+
};
|
|
5858
5966
|
}
|
|
5859
|
-
function
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
return PAGE_BORDER_DISPLAYS.has(normalized) ? normalized : null;
|
|
5967
|
+
function normalizedByteHex(value) {
|
|
5968
|
+
const normalized = value?.trim().toUpperCase();
|
|
5969
|
+
return normalized && /^[0-9A-F]{2}$/.test(normalized) ? normalized : void 0;
|
|
5863
5970
|
}
|
|
5864
|
-
function
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5971
|
+
function importedDocxStrikeFlags(properties) {
|
|
5972
|
+
return {
|
|
5973
|
+
...importedFlag(directChild(properties, 'strike'), 'single'),
|
|
5974
|
+
...importedFlag(directChild(properties, 'dstrike'), 'double')
|
|
5975
|
+
};
|
|
5868
5976
|
}
|
|
5869
|
-
function
|
|
5870
|
-
|
|
5871
|
-
|
|
5872
|
-
return PAGE_BORDER_Z_ORDERS.has(normalized) ? normalized : null;
|
|
5977
|
+
function importedDocxStrike(properties) {
|
|
5978
|
+
const flags = importedDocxStrikeFlags(properties);
|
|
5979
|
+
return resolvedDocxStrikeFormatting(flags.single, flags.double);
|
|
5873
5980
|
}
|
|
5874
|
-
function
|
|
5875
|
-
|
|
5981
|
+
function resolvedDocxStrikeFormatting(single, double, materializeNone = false) {
|
|
5982
|
+
if (void 0 === single && void 0 === double && !materializeNone) return;
|
|
5983
|
+
const style = double ? 'double' : single ? 'single' : 'none';
|
|
5984
|
+
return {
|
|
5985
|
+
style
|
|
5986
|
+
};
|
|
5876
5987
|
}
|
|
5877
|
-
function
|
|
5878
|
-
|
|
5988
|
+
function importedFlag(element, name) {
|
|
5989
|
+
if (!element) return {};
|
|
5990
|
+
const value = work_ooxml_package_attribute(element, 'val')?.trim().toLowerCase();
|
|
5991
|
+
return {
|
|
5992
|
+
[name]: '0' !== value && 'false' !== value && 'off' !== value
|
|
5993
|
+
};
|
|
5879
5994
|
}
|
|
5880
5995
|
const PAGE_MARGIN_ATTRIBUTE_SET = new Set([
|
|
5881
5996
|
'top',
|
|
@@ -7056,7 +7171,7 @@ function markDocxParagraphFormattingChanges(document, styleSource, themeSource,
|
|
|
7056
7171
|
marker,
|
|
7057
7172
|
id: `docx-paragraph-format-change-${change.id}`,
|
|
7058
7173
|
author: change.author,
|
|
7059
|
-
date:
|
|
7174
|
+
date: work_docx_paragraph_format_change_import_normalizeRevisionDate(change.date),
|
|
7060
7175
|
before
|
|
7061
7176
|
});
|
|
7062
7177
|
}
|
|
@@ -7171,7 +7286,7 @@ function work_docx_paragraph_format_change_import_isListItemBlock(node) {
|
|
|
7171
7286
|
'ul'
|
|
7172
7287
|
].includes(node.tagName.toLowerCase());
|
|
7173
7288
|
}
|
|
7174
|
-
function
|
|
7289
|
+
function work_docx_paragraph_format_change_import_normalizeRevisionDate(value) {
|
|
7175
7290
|
if (!value) return '';
|
|
7176
7291
|
const time = Date.parse(value);
|
|
7177
7292
|
return Number.isFinite(time) ? new Date(time).toISOString() : '';
|
|
@@ -7949,4 +8064,145 @@ function work_docx_run_formatting_import_formatNumber(value) {
|
|
|
7949
8064
|
function formatLineHeightFactor(value) {
|
|
7950
8065
|
return Number(value.toFixed(4)).toString();
|
|
7951
8066
|
}
|
|
7952
|
-
|
|
8067
|
+
const work_docx_table_of_contents_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
8068
|
+
const work_docx_table_of_contents_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
8069
|
+
function markDocxTablesOfContents(document) {
|
|
8070
|
+
const tables = [];
|
|
8071
|
+
for (const element of descendants(document, 'sdt')){
|
|
8072
|
+
if (!document.documentElement.contains(element)) continue;
|
|
8073
|
+
const field = docxFieldOccurrences(element).find(supportedDocxTableOfContentsField);
|
|
8074
|
+
if (!field) continue;
|
|
8075
|
+
const parsed = parseDocumentTableOfContentsInstruction(field.instruction);
|
|
8076
|
+
if (!parsed.supported) continue;
|
|
8077
|
+
const tableIndex = tables.length + 1;
|
|
8078
|
+
const marker = {
|
|
8079
|
+
marker: `__A3S_WORK_TABLE_OF_CONTENTS_${tableIndex}__`,
|
|
8080
|
+
id: `docx-table-of-contents-${tableIndex}`,
|
|
8081
|
+
options: {
|
|
8082
|
+
...parsed.options,
|
|
8083
|
+
leader: importedTableOfContentsLeader(element, parsed.options)
|
|
8084
|
+
},
|
|
8085
|
+
entries: importedTableOfContentsEntries(element, tableIndex)
|
|
8086
|
+
};
|
|
8087
|
+
element.replaceWith(work_docx_table_of_contents_import_markerParagraph(document, marker.marker));
|
|
8088
|
+
tables.push(marker);
|
|
8089
|
+
}
|
|
8090
|
+
return {
|
|
8091
|
+
tables
|
|
8092
|
+
};
|
|
8093
|
+
}
|
|
8094
|
+
function applyImportedDocxTableOfContentsMarkers(document, markers) {
|
|
8095
|
+
const headings = importedHtmlHeadings(document);
|
|
8096
|
+
for (const table of markers.tables){
|
|
8097
|
+
const usedHeadingIndexes = new Set();
|
|
8098
|
+
const text = work_docx_table_of_contents_import_textNodes(document.body).find((node)=>node.data.includes(table.marker));
|
|
8099
|
+
if (!text) continue;
|
|
8100
|
+
const entries = table.entries.map((entry)=>{
|
|
8101
|
+
const headingIndex = headings.findIndex((heading, index)=>!usedHeadingIndexes.has(index) && heading.level === entry.level && normalizedTitle(heading.title) === normalizedTitle(entry.title));
|
|
8102
|
+
if (headingIndex < 0) return entry;
|
|
8103
|
+
usedHeadingIndexes.add(headingIndex);
|
|
8104
|
+
const heading = headings[headingIndex];
|
|
8105
|
+
return heading ? {
|
|
8106
|
+
...entry,
|
|
8107
|
+
targetId: heading.targetId
|
|
8108
|
+
} : entry;
|
|
8109
|
+
});
|
|
8110
|
+
const fragment = document.createRange().createContextualFragment(documentTableOfContentsHtml({
|
|
8111
|
+
id: table.id,
|
|
8112
|
+
options: table.options,
|
|
8113
|
+
entries
|
|
8114
|
+
}));
|
|
8115
|
+
const block = work_docx_table_of_contents_import_closestHtmlBlock(text.parentElement);
|
|
8116
|
+
if (block) block.replaceWith(fragment);
|
|
8117
|
+
}
|
|
8118
|
+
}
|
|
8119
|
+
function hasImportedDocxTableOfContentsMarkers(markers) {
|
|
8120
|
+
return markers.tables.length > 0;
|
|
8121
|
+
}
|
|
8122
|
+
function supportedDocxTableOfContentsField(field) {
|
|
8123
|
+
const parsed = parseDocumentTableOfContentsInstruction(field.instruction);
|
|
8124
|
+
return parsed.supported && field.complete && !field.nested && !field.inDeletion && Boolean(work_docx_table_of_contents_import_closestAncestor(field.start, 'sdt'));
|
|
8125
|
+
}
|
|
8126
|
+
function importedTableOfContentsEntries(element, tableIndex) {
|
|
8127
|
+
const paragraphs = descendants(element, 'p');
|
|
8128
|
+
return paragraphs.flatMap((paragraph, index)=>{
|
|
8129
|
+
const style = directChild(directChild(paragraph, 'pPr') ?? paragraph, 'pStyle');
|
|
8130
|
+
const level = Number(/^TOC([1-9])$/i.exec(work_ooxml_package_attribute(style ?? paragraph, 'val') ?? '')?.[1]);
|
|
8131
|
+
if (!level) return [];
|
|
8132
|
+
const values = descendants(paragraph, 't').map((text)=>text.textContent ?? '').filter(Boolean);
|
|
8133
|
+
const last = values.at(-1)?.trim() ?? '';
|
|
8134
|
+
const hasPageNumber = /^\d{1,6}$/.test(last);
|
|
8135
|
+
const title = (hasPageNumber ? values.slice(0, -1) : values).join('').replace(/\s+/g, ' ').trim();
|
|
8136
|
+
if (!title) return [];
|
|
8137
|
+
const hyperlink = descendants(paragraph, 'hyperlink').find((candidate)=>Boolean(work_ooxml_package_attribute(candidate, 'anchor')));
|
|
8138
|
+
const anchor = work_ooxml_package_attribute(hyperlink ?? paragraph, 'anchor')?.trim();
|
|
8139
|
+
const targetId = /^heading-[a-z0-9._:-]{1,128}$/i.test(anchor ?? '') ? anchor : `heading-import-${tableIndex}-${index + 1}`;
|
|
8140
|
+
return [
|
|
8141
|
+
{
|
|
8142
|
+
targetId,
|
|
8143
|
+
title,
|
|
8144
|
+
level,
|
|
8145
|
+
pageNumber: hasPageNumber ? Number(last) : 1
|
|
8146
|
+
}
|
|
8147
|
+
];
|
|
8148
|
+
});
|
|
8149
|
+
}
|
|
8150
|
+
function importedTableOfContentsLeader(element, options) {
|
|
8151
|
+
if (!options.showPageNumbers || !options.rightAlignPageNumbers) return 'none';
|
|
8152
|
+
const tab = descendants(element, 'tab').find((candidate)=>candidate.parentElement?.localName === 'tabs' && 'right' === work_ooxml_package_attribute(candidate, 'val'));
|
|
8153
|
+
const leader = work_ooxml_package_attribute(tab ?? element, 'leader');
|
|
8154
|
+
if ('hyphen' === leader) return 'dash';
|
|
8155
|
+
if ('underscore' === leader) return 'underline';
|
|
8156
|
+
if (!leader || 'none' === leader) return 'none';
|
|
8157
|
+
return 'dot';
|
|
8158
|
+
}
|
|
8159
|
+
function work_docx_table_of_contents_import_markerParagraph(document, marker) {
|
|
8160
|
+
const paragraph = document.createElementNS(work_docx_table_of_contents_import_WORD_NAMESPACE, 'w:p');
|
|
8161
|
+
const run = document.createElementNS(work_docx_table_of_contents_import_WORD_NAMESPACE, 'w:r');
|
|
8162
|
+
const text = document.createElementNS(work_docx_table_of_contents_import_WORD_NAMESPACE, 'w:t');
|
|
8163
|
+
text.setAttributeNS(work_docx_table_of_contents_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
8164
|
+
text.textContent = marker;
|
|
8165
|
+
run.append(text);
|
|
8166
|
+
paragraph.append(run);
|
|
8167
|
+
return paragraph;
|
|
8168
|
+
}
|
|
8169
|
+
function importedHtmlHeadings(document) {
|
|
8170
|
+
return Array.from(document.body.querySelectorAll('h1,h2,h3,h4,h5,h6,p[data-office-outline-level]')).flatMap((heading, index)=>{
|
|
8171
|
+
const headingLevel = /^H([1-6])$/.exec(heading.tagName)?.[1];
|
|
8172
|
+
const outlineLevel = Number(heading.dataset.officeOutlineLevel);
|
|
8173
|
+
const level = headingLevel ? Number(headingLevel) : Number.isInteger(outlineLevel) && outlineLevel >= 0 && outlineLevel <= 8 ? outlineLevel + 1 : null;
|
|
8174
|
+
if (null === level) return [];
|
|
8175
|
+
const identity = normalizeDocumentParagraphId(heading.dataset.officeParagraphId);
|
|
8176
|
+
return [
|
|
8177
|
+
{
|
|
8178
|
+
title: heading.textContent ?? '',
|
|
8179
|
+
level,
|
|
8180
|
+
targetId: identity ? `heading-${identity.toLowerCase()}` : `heading-imported-${index + 1}`
|
|
8181
|
+
}
|
|
8182
|
+
];
|
|
8183
|
+
});
|
|
8184
|
+
}
|
|
8185
|
+
function work_docx_table_of_contents_import_textNodes(root) {
|
|
8186
|
+
const walker = root.ownerDocument?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
8187
|
+
const nodes = [];
|
|
8188
|
+
if (!walker) return nodes;
|
|
8189
|
+
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
8190
|
+
return nodes;
|
|
8191
|
+
}
|
|
8192
|
+
function work_docx_table_of_contents_import_closestHtmlBlock(element) {
|
|
8193
|
+
let current = element;
|
|
8194
|
+
while(current && current.parentElement?.tagName.toLowerCase() !== 'body')current = current.parentElement;
|
|
8195
|
+
return current;
|
|
8196
|
+
}
|
|
8197
|
+
function work_docx_table_of_contents_import_closestAncestor(element, localName) {
|
|
8198
|
+
let current = element;
|
|
8199
|
+
while(current){
|
|
8200
|
+
if (current.localName === localName) return current;
|
|
8201
|
+
current = current.parentElement;
|
|
8202
|
+
}
|
|
8203
|
+
return null;
|
|
8204
|
+
}
|
|
8205
|
+
function normalizedTitle(value) {
|
|
8206
|
+
return value.normalize('NFKC').replace(/\s+/g, ' ').trim().toLocaleLowerCase();
|
|
8207
|
+
}
|
|
8208
|
+
export { applyImportedDocxEquationMarkers, applyImportedDocxIndexMarkers, applyImportedDocxNumberingChangeMarkers, applyImportedDocxParagraphAlignmentMarkers, applyImportedDocxParagraphBorderMarkers, applyImportedDocxParagraphDirectionMarkers, applyImportedDocxParagraphFormattingChangeMarkers, applyImportedDocxParagraphIndentMarkers, applyImportedDocxParagraphPaginationMarkers, applyImportedDocxParagraphShadingMarkers, applyImportedDocxParagraphSpacingMarkers, applyImportedDocxParagraphTabStopMarkers, applyImportedDocxRunFormattingMarkers, applyImportedDocxTableOfContentsMarkers, createDocxParagraphStyleResolver, createDocxTableStyleResolver, createImportedDocxRunFormattingMarkerState, docxCaptionBookmark, docxCaptionReferenceTarget, docxCaptionSequenceKind, docxEquationHtml, docxFieldInstructions, docxFieldOccurrenceIsInlineEditable, docxFieldOccurrences, docxFieldResultText, docxRunPropertySources, docxTableCellStyleLayers, docxTablePropertySources, docxTableRunPropertySources, hasImportedDocxIndexMarkers, hasImportedDocxNumberingChangeMarkers, hasImportedDocxParagraphAlignmentMarkers, hasImportedDocxParagraphBorderMarkers, hasImportedDocxParagraphDirectionMarkers, hasImportedDocxParagraphFormattingChangeMarkers, hasImportedDocxParagraphIndentMarkers, hasImportedDocxParagraphPaginationMarkers, hasImportedDocxParagraphShadingMarkers, hasImportedDocxParagraphSpacingMarkers, hasImportedDocxParagraphTabStopMarkers, hasImportedDocxRunFormattingMarkers, hasImportedDocxTableOfContentsMarkers, hasInvalidDocxFieldStructure, importedDocxStrike, importedDocxUnderline, inspectDocxEquation, inspectDocxHiddenText, inspectDocxLegacyTextEffects, inspectDocxPageBorders, inspectDocxPageMarginSettings, inspectDocxPageMargins, inspectDocxPageSize, inspectDocxPaperSource, inspectDocxRunBorder, inspectDocxRunFonts, inspectDocxRunShading, isDocxEquationLikeRoot, isSupportedDocxEquationPlacement, isSupportedDocxNumberingChange, isSupportedDocxParagraphFormattingChange, isSupportedDocxRunFormattingChange, markDocxIndexes, markDocxNumberingChanges, markDocxPackageEquations, markDocxParagraphAlignments, markDocxParagraphBorders, markDocxParagraphDirections, markDocxParagraphFormattingChanges, markDocxParagraphIndents, markDocxParagraphPagination, markDocxParagraphShading, markDocxParagraphSpacing, markDocxParagraphTabStops, markDocxRunFormattingIntoState, markDocxTablesOfContents, parseDirectDocxParagraphShading, parseDocxPageBorders, parseDocxPageGeometry, parseDocxPageMargins, parseDocxPaperSource, resolveDocxHiddenText, resolveDocxLegacyTextEffects, resolveDocxParagraphBordersForParagraph, resolveDocxRunBorder, resolveDocxRunShading, resolveDocxTableStyleResolver, supportedDocxIndexEntryField, supportedDocxIndexField, supportedDocxTableOfContentsField };
|