@a3s-lab/office 0.46.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/dist/0~2133.js +748 -748
- package/dist/0~document-editor.js +3877 -3847
- package/dist/0~work-docx-export.js +2 -2
- package/dist/0~work-docx-import.js +41 -5
- package/dist/0~work-office-diagnostics.js +21 -6
- package/dist/4174.js +1817 -1565
- package/dist/internal/features/work/work-document-field-node.d.ts +2 -2
- package/dist/internal/features/work/work-document-fields.d.ts +36 -2
- package/dist/internal/features/work/work-docx-bookmark-import.d.ts +1 -1
- package/dist/internal/features/work/work-docx-field-import.d.ts +5 -1
- package/dist/internal/features/work/work-docx-import.d.ts +1 -1
- package/package.json +1 -1
package/dist/0~2133.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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 "./6968.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~4042.js";
|
|
3
|
-
import { normalizeDocumentEmphasisMark, normalizeDocumentPageBorders, textBoxCss, documentCharacterPositionDomAttributes, DOCUMENT_PAGE_BORDER_EDGES, normalizeDocumentTabStops, documentTextCaseFromWordFlags, documentStrikeDomAttributes, serializeDocumentNumberingChange, numberingTypeFromFormat, normalizeDocumentUnderlineColor, documentAutoLineHeight,
|
|
3
|
+
import { normalizeDocumentEmphasisMark, normalizeDocumentPageBorders, textBoxCss, documentCharacterPositionDomAttributes, DOCUMENT_PAGE_BORDER_EDGES, normalizeDocumentTabStops, documentTextCaseFromWordFlags, documentStrikeDomAttributes, serializeDocumentNumberingChange, numberingTypeFromFormat, normalizeDocumentUnderlineColor, documentAutoLineHeight, documentKerningDomAttributes, documentCharacterScaleDomAttributes, textBoxDomAttributes, serializeDocumentParagraphFormatting, normalizeDocumentPaperSource, documentEquationText, documentLegacyTextEffectsDomAttributes, documentLegacyTextEffectsConflict, documentCharacterSpacingDomAttributes, normalizeDocumentParagraphIndent, normalizeDocumentEquation, documentOpenTypeDomAttributes, normalizeDocumentTextBoxProperties, 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;
|
|
@@ -4074,292 +4074,221 @@ function nextEquationMarker(state) {
|
|
|
4074
4074
|
return marker;
|
|
4075
4075
|
}
|
|
4076
4076
|
const WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
4077
|
-
const
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
const
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
if (textBoxes.length >= MAX_IMPORTED_TEXT_BOXES) throw new Error('Imported DOCX exceeds the text-box limit.');
|
|
4114
|
-
const marker = nextTextBoxMarker(document, nextMarker);
|
|
4115
|
-
nextMarker += 1;
|
|
4116
|
-
const properties = textBoxProperties(drawing, shape, textBoxes.length + 1);
|
|
4117
|
-
replaceParagraphWithTextBoxRuns(document, paragraph, shape.content, marker);
|
|
4118
|
-
textBoxes.push({
|
|
4119
|
-
marker,
|
|
4120
|
-
properties
|
|
4121
|
-
});
|
|
4077
|
+
const work_docx_index_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
4078
|
+
function markDocxIndexes(document) {
|
|
4079
|
+
const fields = docxFieldOccurrences(document);
|
|
4080
|
+
const entries = fields.flatMap((field, index)=>{
|
|
4081
|
+
const parsed = parseDocumentIndexEntryInstruction(field.instruction);
|
|
4082
|
+
if (!parsed.supported || !docxFieldOccurrenceIsInlineEditable(field)) return [];
|
|
4083
|
+
const marker = {
|
|
4084
|
+
start: `__A3S_WORK_INDEX_ENTRY_START_${index + 1}__`,
|
|
4085
|
+
end: `__A3S_WORK_INDEX_ENTRY_END_${index + 1}__`,
|
|
4086
|
+
id: `index-entry-import-${index + 1}`,
|
|
4087
|
+
value: parsed.value
|
|
4088
|
+
};
|
|
4089
|
+
insertFieldBoundaryMarkers(document, field, marker.start, marker.end);
|
|
4090
|
+
return [
|
|
4091
|
+
marker
|
|
4092
|
+
];
|
|
4093
|
+
});
|
|
4094
|
+
const indexes = [];
|
|
4095
|
+
for (const field of fields){
|
|
4096
|
+
if (!supportedDocxIndexField(field)) continue;
|
|
4097
|
+
const parsed = parseDocumentIndexInstruction(field.instruction);
|
|
4098
|
+
if (!parsed.supported) continue;
|
|
4099
|
+
const control = work_docx_index_import_closestAncestor(field.start, 'sdt');
|
|
4100
|
+
if (!control || !document.documentElement.contains(control)) continue;
|
|
4101
|
+
const index = indexes.length + 1;
|
|
4102
|
+
const marker = {
|
|
4103
|
+
marker: `__A3S_WORK_DOCUMENT_INDEX_${index}__`,
|
|
4104
|
+
id: `document-index-import-${index}`,
|
|
4105
|
+
options: {
|
|
4106
|
+
...parsed.options,
|
|
4107
|
+
leader: importedIndexLeader(control, parsed.options)
|
|
4108
|
+
},
|
|
4109
|
+
entries: importedIndexEntries(control, index)
|
|
4110
|
+
};
|
|
4111
|
+
control.replaceWith(markerParagraph(document, marker.marker));
|
|
4112
|
+
indexes.push(marker);
|
|
4122
4113
|
}
|
|
4123
4114
|
return {
|
|
4124
|
-
|
|
4115
|
+
entries,
|
|
4116
|
+
indexes
|
|
4125
4117
|
};
|
|
4126
4118
|
}
|
|
4127
|
-
function
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
}
|
|
4137
|
-
const paragraph = work_docx_text_box_import_closestAncestor(drawing, 'p');
|
|
4138
|
-
const run = work_docx_text_box_import_closestAncestor(drawing, 'r');
|
|
4139
|
-
if (paragraph && run && isSoleDrawingParagraph(paragraph, run)) supported += 1;
|
|
4140
|
-
else unsupported += 1;
|
|
4119
|
+
function applyImportedDocxIndexMarkers(document, markers) {
|
|
4120
|
+
for (const entry of markers.entries){
|
|
4121
|
+
const html = documentIndexEntryHtml({
|
|
4122
|
+
id: entry.id,
|
|
4123
|
+
...entry.value
|
|
4124
|
+
});
|
|
4125
|
+
const parsed = document.createRange().createContextualFragment(html);
|
|
4126
|
+
const replacement = parsed.firstElementChild;
|
|
4127
|
+
if (replacement instanceof HTMLElement) replaceMarkerRange(document.body, entry.start, entry.end, replacement);
|
|
4141
4128
|
}
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
while(block.firstChild)wrapper.append(block.firstChild);
|
|
4171
|
-
block.replaceWith(wrapper);
|
|
4129
|
+
const importedEntries = Array.from(document.body.querySelectorAll('[data-document-index-entry]'));
|
|
4130
|
+
for (const index of markers.indexes){
|
|
4131
|
+
const text = textNodes(document.body).find((node)=>node.data.includes(index.marker));
|
|
4132
|
+
if (!text) continue;
|
|
4133
|
+
const entries = index.entries.map((entry, entryIndex)=>{
|
|
4134
|
+
const targets = importedEntries.filter((candidate)=>normalizedTerm(candidate.dataset.indexMainEntry) === normalizedTerm(entry.mainEntry) && normalizedTerm(candidate.dataset.indexSubEntry) === normalizedTerm(entry.subEntry));
|
|
4135
|
+
const targetIds = targets.flatMap((candidate)=>{
|
|
4136
|
+
const id = candidate.dataset.indexEntryId?.trim();
|
|
4137
|
+
return id ? [
|
|
4138
|
+
id
|
|
4139
|
+
] : [];
|
|
4140
|
+
});
|
|
4141
|
+
return {
|
|
4142
|
+
...entry,
|
|
4143
|
+
pages: entry.pages.map((page)=>({
|
|
4144
|
+
...page,
|
|
4145
|
+
targetIds: targetIds.length ? targetIds : [
|
|
4146
|
+
`index-entry-import-${index.id}-${entryIndex + 1}`
|
|
4147
|
+
]
|
|
4148
|
+
}))
|
|
4149
|
+
};
|
|
4150
|
+
});
|
|
4151
|
+
const fragment = document.createRange().createContextualFragment(documentIndexHtml({
|
|
4152
|
+
id: index.id,
|
|
4153
|
+
options: index.options,
|
|
4154
|
+
entries
|
|
4155
|
+
}));
|
|
4156
|
+
closestHtmlBlock(text.parentElement)?.replaceWith(fragment);
|
|
4172
4157
|
}
|
|
4173
|
-
document.body.normalize();
|
|
4174
4158
|
}
|
|
4175
|
-
function
|
|
4176
|
-
return markers.
|
|
4159
|
+
function hasImportedDocxIndexMarkers(markers) {
|
|
4160
|
+
return markers.entries.length > 0 || markers.indexes.length > 0;
|
|
4177
4161
|
}
|
|
4178
|
-
function
|
|
4179
|
-
|
|
4180
|
-
const graphicData = descendants(drawing, 'graphicData').find((element)=>DRAWING_NAMESPACES.has(element.namespaceURI ?? '') && work_ooxml_package_attribute(element, 'uri') === WORDPROCESSING_SHAPE_URI);
|
|
4181
|
-
if (!graphicData) return null;
|
|
4182
|
-
const shape = directChild(graphicData, 'wsp');
|
|
4183
|
-
if (!shape || !WORDPROCESSING_SHAPE_NAMESPACES.has(shape.namespaceURI ?? '')) return null;
|
|
4184
|
-
const nonVisual = directChild(shape, 'cNvSpPr');
|
|
4185
|
-
if (nonVisual && !WORDPROCESSING_SHAPE_NAMESPACES.has(nonVisual.namespaceURI ?? '')) return null;
|
|
4186
|
-
const txBox = work_ooxml_package_attribute(nonVisual ?? shape, 'txBox')?.trim().toLowerCase();
|
|
4187
|
-
if ('1' !== txBox && 'true' !== txBox) return null;
|
|
4188
|
-
return shape;
|
|
4162
|
+
function supportedDocxIndexEntryField(field) {
|
|
4163
|
+
return parseDocumentIndexEntryInstruction(field.instruction).supported && docxFieldOccurrenceIsInlineEditable(field);
|
|
4189
4164
|
}
|
|
4190
|
-
function
|
|
4191
|
-
|
|
4192
|
-
if (!shape) return null;
|
|
4193
|
-
const txbx = directChild(shape, 'txbx');
|
|
4194
|
-
if (txbx && !WORDPROCESSING_SHAPE_NAMESPACES.has(txbx.namespaceURI ?? '')) return null;
|
|
4195
|
-
const content = txbx ? directChild(txbx, 'txbxContent') : void 0;
|
|
4196
|
-
return content && isWordElement(content, 'txbxContent') && isSupportedTextBoxContent(content) ? {
|
|
4197
|
-
shape,
|
|
4198
|
-
content
|
|
4199
|
-
} : null;
|
|
4165
|
+
function supportedDocxIndexField(field) {
|
|
4166
|
+
return parseDocumentIndexInstruction(field.instruction).supported && field.complete && !field.nested && !field.inDeletion && Boolean(work_docx_index_import_closestAncestor(field.start, 'sdt'));
|
|
4200
4167
|
}
|
|
4201
|
-
function
|
|
4202
|
-
const
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
const
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4168
|
+
function importedIndexEntries(control, indexNumber) {
|
|
4169
|
+
const entries = [];
|
|
4170
|
+
let currentMain = '';
|
|
4171
|
+
let row = 0;
|
|
4172
|
+
for (const paragraph of descendants(control, 'p')){
|
|
4173
|
+
const style = directChild(directChild(paragraph, 'pPr') ?? paragraph, 'pStyle');
|
|
4174
|
+
const styleName = work_ooxml_package_attribute(style ?? paragraph, 'val') ?? '';
|
|
4175
|
+
const level = /^Index([12])$/i.exec(styleName)?.[1];
|
|
4176
|
+
if (!level) continue;
|
|
4177
|
+
row += 1;
|
|
4178
|
+
const parsed = importedIndexParagraph(paragraph, indexNumber, row);
|
|
4179
|
+
if (parsed) {
|
|
4180
|
+
if ('1' === level) {
|
|
4181
|
+
currentMain = parsed.term;
|
|
4182
|
+
if (!parsed.pages.length && !parsed.crossReference) continue;
|
|
4183
|
+
entries.push({
|
|
4184
|
+
mainEntry: parsed.term,
|
|
4185
|
+
subEntry: '',
|
|
4186
|
+
crossReference: parsed.crossReference,
|
|
4187
|
+
pages: parsed.pages
|
|
4188
|
+
});
|
|
4189
|
+
continue;
|
|
4190
|
+
}
|
|
4191
|
+
if (currentMain) entries.push({
|
|
4192
|
+
mainEntry: currentMain,
|
|
4193
|
+
subEntry: parsed.term,
|
|
4194
|
+
crossReference: parsed.crossReference,
|
|
4195
|
+
pages: parsed.pages
|
|
4196
|
+
});
|
|
4211
4197
|
}
|
|
4212
4198
|
}
|
|
4213
|
-
return
|
|
4214
|
-
}
|
|
4215
|
-
function isWordElement(element, localName) {
|
|
4216
|
-
return element.localName === localName && isWordNamespace(element);
|
|
4217
|
-
}
|
|
4218
|
-
function isWordNamespace(element) {
|
|
4219
|
-
return element.namespaceURI === WORD_NAMESPACE || element.namespaceURI === work_docx_text_box_import_STRICT_WORD_NAMESPACE;
|
|
4220
|
-
}
|
|
4221
|
-
function docxDrawings(document) {
|
|
4222
|
-
return [
|
|
4223
|
-
...descendants(document, 'anchor'),
|
|
4224
|
-
...descendants(document, 'inline')
|
|
4225
|
-
].filter((element)=>WORDPROCESSING_DRAWING_NAMESPACES.has(element.namespaceURI ?? ''));
|
|
4226
|
-
}
|
|
4227
|
-
function isSoleDrawingParagraph(paragraph, run) {
|
|
4228
|
-
const meaningful = work_ooxml_package_directChildren(paragraph).filter((element)=>'pPr' !== element.localName);
|
|
4229
|
-
if (1 !== meaningful.length || meaningful[0] !== run) return false;
|
|
4230
|
-
const runContent = work_ooxml_package_directChildren(run).filter((element)=>'rPr' !== element.localName);
|
|
4231
|
-
return 1 === runContent.length && runContent[0]?.localName === 'drawing';
|
|
4199
|
+
return entries;
|
|
4232
4200
|
}
|
|
4233
|
-
function
|
|
4234
|
-
const
|
|
4235
|
-
const
|
|
4236
|
-
const
|
|
4237
|
-
|
|
4238
|
-
const
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
}
|
|
4244
|
-
const markerRun = createTextRun(document, namespace, prefix, marker);
|
|
4245
|
-
paragraph.replaceChildren(...paragraphProperties ? [
|
|
4246
|
-
paragraphProperties
|
|
4247
|
-
] : [], markerRun, ...runs);
|
|
4248
|
-
}
|
|
4249
|
-
function createTextRun(document, namespace, prefix, textValue) {
|
|
4250
|
-
const run = document.createElementNS(namespace, `${prefix}r`);
|
|
4251
|
-
const text = document.createElementNS(namespace, `${prefix}t`);
|
|
4252
|
-
text.setAttributeNS(work_docx_text_box_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
4253
|
-
text.textContent = textValue;
|
|
4254
|
-
run.append(text);
|
|
4255
|
-
return run;
|
|
4256
|
-
}
|
|
4257
|
-
function createBreakRun(document, namespace, prefix) {
|
|
4258
|
-
const run = document.createElementNS(namespace, `${prefix}r`);
|
|
4259
|
-
run.append(document.createElementNS(namespace, `${prefix}br`));
|
|
4260
|
-
return run;
|
|
4261
|
-
}
|
|
4262
|
-
function textBoxProperties(drawing, shape, index) {
|
|
4263
|
-
const extent = directChild(drawing, 'extent');
|
|
4264
|
-
const shapeProperties = directChild(shape.shape, 'spPr');
|
|
4265
|
-
const transform = shapeProperties ? directChild(shapeProperties, 'xfrm') : void 0;
|
|
4266
|
-
const extension = directChild(transform ?? shapeProperties ?? shape.shape, 'ext');
|
|
4267
|
-
const width = emuMillimeters(work_ooxml_package_attribute(extent ?? extension ?? shape.shape, 'cx') ?? work_ooxml_package_attribute(extent ?? extension ?? shape.shape, 'x'), 120);
|
|
4268
|
-
const height = emuMillimeters(work_ooxml_package_attribute(extent ?? extension ?? shape.shape, 'cy') ?? work_ooxml_package_attribute(extent ?? extension ?? shape.shape, 'y'), 45);
|
|
4269
|
-
const docProperties = directChild(drawing, 'docPr');
|
|
4270
|
-
const docPropertiesId = integerAttribute(docProperties, 'id');
|
|
4271
|
-
const sourceName = attributeOptional(docProperties, 'name')?.trim() ?? '';
|
|
4272
|
-
const id = sourceName.startsWith('A3S Text Box ') ? sourceName.slice(13).trim() : null === docPropertiesId ? `docx-text-box-${index}` : `docx-text-box-${docPropertiesId}`;
|
|
4273
|
-
const bodyProperties = directChild(shape.shape, 'bodyPr');
|
|
4274
|
-
const horizontal = directChild(drawing, 'positionH');
|
|
4275
|
-
const vertical = directChild(drawing, 'positionV');
|
|
4276
|
-
const layout = 'anchor' === drawing.localName ? 'floating' : 'inline';
|
|
4277
|
-
const fill = shapeFill(shapeProperties);
|
|
4278
|
-
const border = shapeBorder(shapeProperties);
|
|
4279
|
-
return normalizeDocumentTextBoxProperties({
|
|
4280
|
-
id,
|
|
4281
|
-
width,
|
|
4282
|
-
height,
|
|
4283
|
-
layout,
|
|
4284
|
-
horizontalOffset: positionOffset(horizontal),
|
|
4285
|
-
verticalOffset: positionOffset(vertical),
|
|
4286
|
-
horizontalReference: positionReference(horizontal, 'column'),
|
|
4287
|
-
verticalReference: positionReference(vertical, 'paragraph'),
|
|
4288
|
-
fill,
|
|
4289
|
-
borderColor: border.color,
|
|
4290
|
-
borderWidth: border.width,
|
|
4291
|
-
padding: bodyPadding(bodyProperties),
|
|
4292
|
-
verticalAlign: bodyVerticalAlign(bodyProperties),
|
|
4293
|
-
docPropertiesId
|
|
4294
|
-
});
|
|
4295
|
-
}
|
|
4296
|
-
function shapeFill(shapeProperties) {
|
|
4297
|
-
if (!shapeProperties || directChild(shapeProperties, 'noFill')) return 'transparent';
|
|
4298
|
-
const fill = directChild(shapeProperties, 'solidFill');
|
|
4299
|
-
const rgb = fill ? directChild(fill, 'srgbClr') : void 0;
|
|
4300
|
-
const value = attributeOptional(rgb, 'val')?.trim();
|
|
4301
|
-
return value && /^[0-9a-f]{6}$/i.test(value) ? `#${value}` : 'transparent';
|
|
4302
|
-
}
|
|
4303
|
-
function shapeBorder(shapeProperties) {
|
|
4304
|
-
const line = shapeProperties ? directChild(shapeProperties, 'ln') : void 0;
|
|
4305
|
-
if (!line || directChild(line, 'noFill')) return {
|
|
4306
|
-
color: 'none',
|
|
4307
|
-
width: 0
|
|
4308
|
-
};
|
|
4309
|
-
const fill = directChild(line, 'solidFill');
|
|
4310
|
-
const rgb = fill ? directChild(fill, 'srgbClr') : void 0;
|
|
4311
|
-
const value = attributeOptional(rgb, 'val')?.trim();
|
|
4312
|
-
return {
|
|
4313
|
-
color: value && /^[0-9a-f]{6}$/i.test(value) ? `#${value}` : '#4472c4',
|
|
4314
|
-
width: emuMillimeters(work_ooxml_package_attribute(line, 'w'), 0.35)
|
|
4201
|
+
function importedIndexParagraph(paragraph, indexNumber, row) {
|
|
4202
|
+
const textElements = descendants(paragraph, 't');
|
|
4203
|
+
const values = textElements.map((element)=>element.textContent ?? '');
|
|
4204
|
+
const combined = values.join('').replace(/\s+/g, ' ').trim();
|
|
4205
|
+
if (!combined) return null;
|
|
4206
|
+
const crossReference = /^(.+?),\s*(?:see|参见)\s+(.+)$/i.exec(combined);
|
|
4207
|
+
if (crossReference?.[1] && crossReference[2]) return {
|
|
4208
|
+
term: crossReference[1].trim(),
|
|
4209
|
+
crossReference: crossReference[2].trim(),
|
|
4210
|
+
pages: []
|
|
4315
4211
|
};
|
|
4212
|
+
const pageElements = textElements.filter((element)=>/^\d{1,6}$/.test((element.textContent ?? '').trim()));
|
|
4213
|
+
const pages = pageElements.map((element, pageIndex)=>{
|
|
4214
|
+
const properties = directChild(work_docx_index_import_closestAncestor(element, 'r') ?? element, 'rPr');
|
|
4215
|
+
return {
|
|
4216
|
+
pageNumber: Number((element.textContent ?? '').trim()),
|
|
4217
|
+
pageBold: Boolean(properties && directChild(properties, 'b')),
|
|
4218
|
+
pageItalic: Boolean(properties && directChild(properties, 'i')),
|
|
4219
|
+
targetIds: [
|
|
4220
|
+
`index-entry-import-${indexNumber}-${row}-${pageIndex + 1}`
|
|
4221
|
+
]
|
|
4222
|
+
};
|
|
4223
|
+
});
|
|
4224
|
+
const pageText = pageElements.map((element)=>element.textContent ?? '');
|
|
4225
|
+
let term = combined;
|
|
4226
|
+
for (const value of pageText)term = term.replace(new RegExp(`(?:,\\s*)?${escapeRegExp(value)}\\s*$`), '');
|
|
4227
|
+
term = term.replace(/[,\s]+$/, '').trim();
|
|
4228
|
+
return term ? {
|
|
4229
|
+
term,
|
|
4230
|
+
crossReference: '',
|
|
4231
|
+
pages
|
|
4232
|
+
} : null;
|
|
4316
4233
|
}
|
|
4317
|
-
function
|
|
4318
|
-
if (!
|
|
4319
|
-
const
|
|
4320
|
-
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
return Math.min(...values);
|
|
4234
|
+
function importedIndexLeader(control, options) {
|
|
4235
|
+
if (!options.rightAlignPageNumbers) return 'none';
|
|
4236
|
+
const tab = descendants(control, 'tab').find((candidate)=>candidate.parentElement?.localName === 'tabs' && 'right' === work_ooxml_package_attribute(candidate, 'val'));
|
|
4237
|
+
const leader = work_ooxml_package_attribute(tab ?? control, 'leader');
|
|
4238
|
+
if ('hyphen' === leader) return 'dash';
|
|
4239
|
+
if ('underscore' === leader) return 'underline';
|
|
4240
|
+
if (!leader || 'none' === leader) return 'none';
|
|
4241
|
+
return 'dot';
|
|
4326
4242
|
}
|
|
4327
|
-
function
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4243
|
+
function insertFieldBoundaryMarkers(document, field, start, end) {
|
|
4244
|
+
if ('fldChar' === field.start.localName && 'fldChar' === field.end.localName) {
|
|
4245
|
+
field.start.parentNode?.insertBefore(markerText(document, start), field.start);
|
|
4246
|
+
field.end.parentNode?.insertBefore(markerText(document, end), field.end.nextSibling);
|
|
4247
|
+
return;
|
|
4248
|
+
}
|
|
4249
|
+
field.start.parentNode?.insertBefore(work_docx_index_import_markerRun(document, start), field.start);
|
|
4250
|
+
field.end.parentNode?.insertBefore(work_docx_index_import_markerRun(document, end), field.end.nextSibling);
|
|
4332
4251
|
}
|
|
4333
|
-
function
|
|
4334
|
-
const
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
return Number.isFinite(value) ? value / EMUS_PER_MILLIMETER : null;
|
|
4252
|
+
function markerParagraph(document, marker) {
|
|
4253
|
+
const paragraph = document.createElementNS(WORD_NAMESPACE, 'w:p');
|
|
4254
|
+
paragraph.append(work_docx_index_import_markerRun(document, marker));
|
|
4255
|
+
return paragraph;
|
|
4338
4256
|
}
|
|
4339
|
-
function
|
|
4340
|
-
const
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
return fallback;
|
|
4257
|
+
function work_docx_index_import_markerRun(document, value) {
|
|
4258
|
+
const run = document.createElementNS(WORD_NAMESPACE, 'w:r');
|
|
4259
|
+
run.append(markerText(document, value));
|
|
4260
|
+
return run;
|
|
4344
4261
|
}
|
|
4345
|
-
function
|
|
4346
|
-
const
|
|
4347
|
-
|
|
4262
|
+
function markerText(document, value) {
|
|
4263
|
+
const text = document.createElementNS(WORD_NAMESPACE, 'w:t');
|
|
4264
|
+
text.setAttributeNS(work_docx_index_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
4265
|
+
text.textContent = value;
|
|
4266
|
+
return text;
|
|
4348
4267
|
}
|
|
4349
|
-
function
|
|
4350
|
-
|
|
4351
|
-
const
|
|
4352
|
-
|
|
4268
|
+
function replaceMarkerRange(root, start, end, replacement) {
|
|
4269
|
+
const nodes = textNodes(root);
|
|
4270
|
+
const startNode = nodes.find((node)=>node.data.includes(start));
|
|
4271
|
+
const endNode = nodes.find((node)=>node.data.includes(end));
|
|
4272
|
+
if (!startNode || !endNode) return;
|
|
4273
|
+
const range = root.ownerDocument.createRange();
|
|
4274
|
+
range.setStart(startNode, startNode.data.indexOf(start));
|
|
4275
|
+
range.setEnd(endNode, endNode.data.indexOf(end) + end.length);
|
|
4276
|
+
range.deleteContents();
|
|
4277
|
+
range.insertNode(replacement);
|
|
4353
4278
|
}
|
|
4354
|
-
function
|
|
4355
|
-
|
|
4279
|
+
function textNodes(root) {
|
|
4280
|
+
const walker = root.ownerDocument?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
4281
|
+
const nodes = [];
|
|
4282
|
+
if (!walker) return nodes;
|
|
4283
|
+
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
4284
|
+
return nodes;
|
|
4356
4285
|
}
|
|
4357
|
-
function
|
|
4358
|
-
let
|
|
4359
|
-
while(
|
|
4360
|
-
return
|
|
4286
|
+
function closestHtmlBlock(element) {
|
|
4287
|
+
let current = element;
|
|
4288
|
+
while(current && current.parentElement?.tagName.toLowerCase() !== 'body')current = current.parentElement;
|
|
4289
|
+
return current;
|
|
4361
4290
|
}
|
|
4362
|
-
function
|
|
4291
|
+
function work_docx_index_import_closestAncestor(element, localName) {
|
|
4363
4292
|
let current = element;
|
|
4364
4293
|
while(current){
|
|
4365
4294
|
if (current.localName === localName) return current;
|
|
@@ -4367,246 +4296,11 @@ function work_docx_text_box_import_closestAncestor(element, localName) {
|
|
|
4367
4296
|
}
|
|
4368
4297
|
return null;
|
|
4369
4298
|
}
|
|
4370
|
-
function
|
|
4371
|
-
|
|
4372
|
-
const block = element.closest('p, h1, h2, h3, h4, h5, h6, li, blockquote, td, th');
|
|
4373
|
-
return block instanceof HTMLElement ? block : null;
|
|
4374
|
-
}
|
|
4375
|
-
function textNodes(root) {
|
|
4376
|
-
const walker = root.ownerDocument?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
4377
|
-
const nodes = [];
|
|
4378
|
-
if (!walker) return nodes;
|
|
4379
|
-
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
4380
|
-
return nodes;
|
|
4299
|
+
function normalizedTerm(value) {
|
|
4300
|
+
return (value ?? '').normalize('NFKC').replace(/\s+/g, ' ').trim().toLowerCase();
|
|
4381
4301
|
}
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
function markDocxIndexes(document) {
|
|
4385
|
-
const fields = docxFieldOccurrences(document);
|
|
4386
|
-
const entries = fields.flatMap((field, index)=>{
|
|
4387
|
-
const parsed = parseDocumentIndexEntryInstruction(field.instruction);
|
|
4388
|
-
if (!parsed.supported || !docxFieldOccurrenceIsInlineEditable(field)) return [];
|
|
4389
|
-
const marker = {
|
|
4390
|
-
start: `__A3S_WORK_INDEX_ENTRY_START_${index + 1}__`,
|
|
4391
|
-
end: `__A3S_WORK_INDEX_ENTRY_END_${index + 1}__`,
|
|
4392
|
-
id: `index-entry-import-${index + 1}`,
|
|
4393
|
-
value: parsed.value
|
|
4394
|
-
};
|
|
4395
|
-
insertFieldBoundaryMarkers(document, field, marker.start, marker.end);
|
|
4396
|
-
return [
|
|
4397
|
-
marker
|
|
4398
|
-
];
|
|
4399
|
-
});
|
|
4400
|
-
const indexes = [];
|
|
4401
|
-
for (const field of fields){
|
|
4402
|
-
if (!supportedDocxIndexField(field)) continue;
|
|
4403
|
-
const parsed = parseDocumentIndexInstruction(field.instruction);
|
|
4404
|
-
if (!parsed.supported) continue;
|
|
4405
|
-
const control = work_docx_index_import_closestAncestor(field.start, 'sdt');
|
|
4406
|
-
if (!control || !document.documentElement.contains(control)) continue;
|
|
4407
|
-
const index = indexes.length + 1;
|
|
4408
|
-
const marker = {
|
|
4409
|
-
marker: `__A3S_WORK_DOCUMENT_INDEX_${index}__`,
|
|
4410
|
-
id: `document-index-import-${index}`,
|
|
4411
|
-
options: {
|
|
4412
|
-
...parsed.options,
|
|
4413
|
-
leader: importedIndexLeader(control, parsed.options)
|
|
4414
|
-
},
|
|
4415
|
-
entries: importedIndexEntries(control, index)
|
|
4416
|
-
};
|
|
4417
|
-
control.replaceWith(markerParagraph(document, marker.marker));
|
|
4418
|
-
indexes.push(marker);
|
|
4419
|
-
}
|
|
4420
|
-
return {
|
|
4421
|
-
entries,
|
|
4422
|
-
indexes
|
|
4423
|
-
};
|
|
4424
|
-
}
|
|
4425
|
-
function applyImportedDocxIndexMarkers(document, markers) {
|
|
4426
|
-
for (const entry of markers.entries){
|
|
4427
|
-
const html = documentIndexEntryHtml({
|
|
4428
|
-
id: entry.id,
|
|
4429
|
-
...entry.value
|
|
4430
|
-
});
|
|
4431
|
-
const parsed = document.createRange().createContextualFragment(html);
|
|
4432
|
-
const replacement = parsed.firstElementChild;
|
|
4433
|
-
if (replacement instanceof HTMLElement) replaceMarkerRange(document.body, entry.start, entry.end, replacement);
|
|
4434
|
-
}
|
|
4435
|
-
const importedEntries = Array.from(document.body.querySelectorAll('[data-document-index-entry]'));
|
|
4436
|
-
for (const index of markers.indexes){
|
|
4437
|
-
const text = work_docx_index_import_textNodes(document.body).find((node)=>node.data.includes(index.marker));
|
|
4438
|
-
if (!text) continue;
|
|
4439
|
-
const entries = index.entries.map((entry, entryIndex)=>{
|
|
4440
|
-
const targets = importedEntries.filter((candidate)=>normalizedTerm(candidate.dataset.indexMainEntry) === normalizedTerm(entry.mainEntry) && normalizedTerm(candidate.dataset.indexSubEntry) === normalizedTerm(entry.subEntry));
|
|
4441
|
-
const targetIds = targets.flatMap((candidate)=>{
|
|
4442
|
-
const id = candidate.dataset.indexEntryId?.trim();
|
|
4443
|
-
return id ? [
|
|
4444
|
-
id
|
|
4445
|
-
] : [];
|
|
4446
|
-
});
|
|
4447
|
-
return {
|
|
4448
|
-
...entry,
|
|
4449
|
-
pages: entry.pages.map((page)=>({
|
|
4450
|
-
...page,
|
|
4451
|
-
targetIds: targetIds.length ? targetIds : [
|
|
4452
|
-
`index-entry-import-${index.id}-${entryIndex + 1}`
|
|
4453
|
-
]
|
|
4454
|
-
}))
|
|
4455
|
-
};
|
|
4456
|
-
});
|
|
4457
|
-
const fragment = document.createRange().createContextualFragment(documentIndexHtml({
|
|
4458
|
-
id: index.id,
|
|
4459
|
-
options: index.options,
|
|
4460
|
-
entries
|
|
4461
|
-
}));
|
|
4462
|
-
work_docx_index_import_closestHtmlBlock(text.parentElement)?.replaceWith(fragment);
|
|
4463
|
-
}
|
|
4464
|
-
}
|
|
4465
|
-
function hasImportedDocxIndexMarkers(markers) {
|
|
4466
|
-
return markers.entries.length > 0 || markers.indexes.length > 0;
|
|
4467
|
-
}
|
|
4468
|
-
function supportedDocxIndexEntryField(field) {
|
|
4469
|
-
return parseDocumentIndexEntryInstruction(field.instruction).supported && docxFieldOccurrenceIsInlineEditable(field);
|
|
4470
|
-
}
|
|
4471
|
-
function supportedDocxIndexField(field) {
|
|
4472
|
-
return parseDocumentIndexInstruction(field.instruction).supported && field.complete && !field.nested && !field.inDeletion && Boolean(work_docx_index_import_closestAncestor(field.start, 'sdt'));
|
|
4473
|
-
}
|
|
4474
|
-
function importedIndexEntries(control, indexNumber) {
|
|
4475
|
-
const entries = [];
|
|
4476
|
-
let currentMain = '';
|
|
4477
|
-
let row = 0;
|
|
4478
|
-
for (const paragraph of descendants(control, 'p')){
|
|
4479
|
-
const style = directChild(directChild(paragraph, 'pPr') ?? paragraph, 'pStyle');
|
|
4480
|
-
const styleName = work_ooxml_package_attribute(style ?? paragraph, 'val') ?? '';
|
|
4481
|
-
const level = /^Index([12])$/i.exec(styleName)?.[1];
|
|
4482
|
-
if (!level) continue;
|
|
4483
|
-
row += 1;
|
|
4484
|
-
const parsed = importedIndexParagraph(paragraph, indexNumber, row);
|
|
4485
|
-
if (parsed) {
|
|
4486
|
-
if ('1' === level) {
|
|
4487
|
-
currentMain = parsed.term;
|
|
4488
|
-
if (!parsed.pages.length && !parsed.crossReference) continue;
|
|
4489
|
-
entries.push({
|
|
4490
|
-
mainEntry: parsed.term,
|
|
4491
|
-
subEntry: '',
|
|
4492
|
-
crossReference: parsed.crossReference,
|
|
4493
|
-
pages: parsed.pages
|
|
4494
|
-
});
|
|
4495
|
-
continue;
|
|
4496
|
-
}
|
|
4497
|
-
if (currentMain) entries.push({
|
|
4498
|
-
mainEntry: currentMain,
|
|
4499
|
-
subEntry: parsed.term,
|
|
4500
|
-
crossReference: parsed.crossReference,
|
|
4501
|
-
pages: parsed.pages
|
|
4502
|
-
});
|
|
4503
|
-
}
|
|
4504
|
-
}
|
|
4505
|
-
return entries;
|
|
4506
|
-
}
|
|
4507
|
-
function importedIndexParagraph(paragraph, indexNumber, row) {
|
|
4508
|
-
const textElements = descendants(paragraph, 't');
|
|
4509
|
-
const values = textElements.map((element)=>element.textContent ?? '');
|
|
4510
|
-
const combined = values.join('').replace(/\s+/g, ' ').trim();
|
|
4511
|
-
if (!combined) return null;
|
|
4512
|
-
const crossReference = /^(.+?),\s*(?:see|参见)\s+(.+)$/i.exec(combined);
|
|
4513
|
-
if (crossReference?.[1] && crossReference[2]) return {
|
|
4514
|
-
term: crossReference[1].trim(),
|
|
4515
|
-
crossReference: crossReference[2].trim(),
|
|
4516
|
-
pages: []
|
|
4517
|
-
};
|
|
4518
|
-
const pageElements = textElements.filter((element)=>/^\d{1,6}$/.test((element.textContent ?? '').trim()));
|
|
4519
|
-
const pages = pageElements.map((element, pageIndex)=>{
|
|
4520
|
-
const properties = directChild(work_docx_index_import_closestAncestor(element, 'r') ?? element, 'rPr');
|
|
4521
|
-
return {
|
|
4522
|
-
pageNumber: Number((element.textContent ?? '').trim()),
|
|
4523
|
-
pageBold: Boolean(properties && directChild(properties, 'b')),
|
|
4524
|
-
pageItalic: Boolean(properties && directChild(properties, 'i')),
|
|
4525
|
-
targetIds: [
|
|
4526
|
-
`index-entry-import-${indexNumber}-${row}-${pageIndex + 1}`
|
|
4527
|
-
]
|
|
4528
|
-
};
|
|
4529
|
-
});
|
|
4530
|
-
const pageText = pageElements.map((element)=>element.textContent ?? '');
|
|
4531
|
-
let term = combined;
|
|
4532
|
-
for (const value of pageText)term = term.replace(new RegExp(`(?:,\\s*)?${escapeRegExp(value)}\\s*$`), '');
|
|
4533
|
-
term = term.replace(/[,\s]+$/, '').trim();
|
|
4534
|
-
return term ? {
|
|
4535
|
-
term,
|
|
4536
|
-
crossReference: '',
|
|
4537
|
-
pages
|
|
4538
|
-
} : null;
|
|
4539
|
-
}
|
|
4540
|
-
function importedIndexLeader(control, options) {
|
|
4541
|
-
if (!options.rightAlignPageNumbers) return 'none';
|
|
4542
|
-
const tab = descendants(control, 'tab').find((candidate)=>candidate.parentElement?.localName === 'tabs' && 'right' === work_ooxml_package_attribute(candidate, 'val'));
|
|
4543
|
-
const leader = work_ooxml_package_attribute(tab ?? control, 'leader');
|
|
4544
|
-
if ('hyphen' === leader) return 'dash';
|
|
4545
|
-
if ('underscore' === leader) return 'underline';
|
|
4546
|
-
if (!leader || 'none' === leader) return 'none';
|
|
4547
|
-
return 'dot';
|
|
4548
|
-
}
|
|
4549
|
-
function insertFieldBoundaryMarkers(document, field, start, end) {
|
|
4550
|
-
if ('fldChar' === field.start.localName && 'fldChar' === field.end.localName) {
|
|
4551
|
-
field.start.parentNode?.insertBefore(markerText(document, start), field.start);
|
|
4552
|
-
field.end.parentNode?.insertBefore(markerText(document, end), field.end.nextSibling);
|
|
4553
|
-
return;
|
|
4554
|
-
}
|
|
4555
|
-
field.start.parentNode?.insertBefore(work_docx_index_import_markerRun(document, start), field.start);
|
|
4556
|
-
field.end.parentNode?.insertBefore(work_docx_index_import_markerRun(document, end), field.end.nextSibling);
|
|
4557
|
-
}
|
|
4558
|
-
function markerParagraph(document, marker) {
|
|
4559
|
-
const paragraph = document.createElementNS(work_docx_index_import_WORD_NAMESPACE, 'w:p');
|
|
4560
|
-
paragraph.append(work_docx_index_import_markerRun(document, marker));
|
|
4561
|
-
return paragraph;
|
|
4562
|
-
}
|
|
4563
|
-
function work_docx_index_import_markerRun(document, value) {
|
|
4564
|
-
const run = document.createElementNS(work_docx_index_import_WORD_NAMESPACE, 'w:r');
|
|
4565
|
-
run.append(markerText(document, value));
|
|
4566
|
-
return run;
|
|
4567
|
-
}
|
|
4568
|
-
function markerText(document, value) {
|
|
4569
|
-
const text = document.createElementNS(work_docx_index_import_WORD_NAMESPACE, 'w:t');
|
|
4570
|
-
text.setAttributeNS(work_docx_index_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
4571
|
-
text.textContent = value;
|
|
4572
|
-
return text;
|
|
4573
|
-
}
|
|
4574
|
-
function replaceMarkerRange(root, start, end, replacement) {
|
|
4575
|
-
const nodes = work_docx_index_import_textNodes(root);
|
|
4576
|
-
const startNode = nodes.find((node)=>node.data.includes(start));
|
|
4577
|
-
const endNode = nodes.find((node)=>node.data.includes(end));
|
|
4578
|
-
if (!startNode || !endNode) return;
|
|
4579
|
-
const range = root.ownerDocument.createRange();
|
|
4580
|
-
range.setStart(startNode, startNode.data.indexOf(start));
|
|
4581
|
-
range.setEnd(endNode, endNode.data.indexOf(end) + end.length);
|
|
4582
|
-
range.deleteContents();
|
|
4583
|
-
range.insertNode(replacement);
|
|
4584
|
-
}
|
|
4585
|
-
function work_docx_index_import_textNodes(root) {
|
|
4586
|
-
const walker = root.ownerDocument?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
4587
|
-
const nodes = [];
|
|
4588
|
-
if (!walker) return nodes;
|
|
4589
|
-
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
4590
|
-
return nodes;
|
|
4591
|
-
}
|
|
4592
|
-
function work_docx_index_import_closestHtmlBlock(element) {
|
|
4593
|
-
let current = element;
|
|
4594
|
-
while(current && current.parentElement?.tagName.toLowerCase() !== 'body')current = current.parentElement;
|
|
4595
|
-
return current;
|
|
4596
|
-
}
|
|
4597
|
-
function work_docx_index_import_closestAncestor(element, localName) {
|
|
4598
|
-
let current = element;
|
|
4599
|
-
while(current){
|
|
4600
|
-
if (current.localName === localName) return current;
|
|
4601
|
-
current = current.parentElement;
|
|
4602
|
-
}
|
|
4603
|
-
return null;
|
|
4604
|
-
}
|
|
4605
|
-
function normalizedTerm(value) {
|
|
4606
|
-
return (value ?? '').normalize('NFKC').replace(/\s+/g, ' ').trim().toLowerCase();
|
|
4607
|
-
}
|
|
4608
|
-
function escapeRegExp(value) {
|
|
4609
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
4302
|
+
function escapeRegExp(value) {
|
|
4303
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
4610
4304
|
}
|
|
4611
4305
|
const work_docx_numbering_change_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
4612
4306
|
const work_docx_numbering_change_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
@@ -4618,7 +4312,7 @@ function markDocxNumberingChanges(document) {
|
|
|
4618
4312
|
let active;
|
|
4619
4313
|
let markerIndex = 0;
|
|
4620
4314
|
for (const paragraph of descendants(document, 'p')){
|
|
4621
|
-
if (!
|
|
4315
|
+
if (!isWordElement(paragraph)) {
|
|
4622
4316
|
active = void 0;
|
|
4623
4317
|
continue;
|
|
4624
4318
|
}
|
|
@@ -4687,7 +4381,7 @@ function supportedNumberingChangeInParagraph(paragraph) {
|
|
|
4687
4381
|
return supportedNumberingChange(changes[0]);
|
|
4688
4382
|
}
|
|
4689
4383
|
function supportedNumberingChange(change) {
|
|
4690
|
-
if (!change || 'numberingChange' !== change.localName || !
|
|
4384
|
+
if (!change || 'numberingChange' !== change.localName || !isWordElement(change)) return null;
|
|
4691
4385
|
const namespace = change.namespaceURI ?? '';
|
|
4692
4386
|
const numbering = change.parentElement;
|
|
4693
4387
|
const properties = numbering?.parentElement;
|
|
@@ -4809,7 +4503,7 @@ function insertParagraphMarker(document, paragraph, properties, marker) {
|
|
|
4809
4503
|
}
|
|
4810
4504
|
function directWordChildren(parent, localName) {
|
|
4811
4505
|
const namespace = parent.namespaceURI;
|
|
4812
|
-
return work_ooxml_package_directChildren(parent, localName).filter((element)=>element.namespaceURI === namespace &&
|
|
4506
|
+
return work_ooxml_package_directChildren(parent, localName).filter((element)=>element.namespaceURI === namespace && isWordElement(element));
|
|
4813
4507
|
}
|
|
4814
4508
|
function boundedWordInteger(element, name, minimum, maximum) {
|
|
4815
4509
|
if (!element) return null;
|
|
@@ -4850,7 +4544,7 @@ function normalizeRevisionDate(value) {
|
|
|
4850
4544
|
const time = Date.parse(value);
|
|
4851
4545
|
return Number.isFinite(time) ? new Date(time).toISOString() : '';
|
|
4852
4546
|
}
|
|
4853
|
-
function
|
|
4547
|
+
function isWordElement(element) {
|
|
4854
4548
|
return DOCX_WORDPROCESSING_NAMESPACES.has(element.namespaceURI ?? '');
|
|
4855
4549
|
}
|
|
4856
4550
|
function isTextNode(value) {
|
|
@@ -8227,280 +7921,577 @@ function importedRunFormattingChange(runProperties, paragraphProperties, styles,
|
|
|
8227
7921
|
function isSupportedDocxRunFormattingChange(change) {
|
|
8228
7922
|
return Boolean(supportedRunFormattingChangeElement(change));
|
|
8229
7923
|
}
|
|
8230
|
-
function supportedRunFormattingChange(runProperties) {
|
|
8231
|
-
if (!runProperties) return null;
|
|
8232
|
-
const changes = Array.from(runProperties.children).filter((child)=>'rPrChange' === child.localName);
|
|
8233
|
-
return 1 === changes.length ? supportedRunFormattingChangeElement(changes[0]) : null;
|
|
7924
|
+
function supportedRunFormattingChange(runProperties) {
|
|
7925
|
+
if (!runProperties) return null;
|
|
7926
|
+
const changes = Array.from(runProperties.children).filter((child)=>'rPrChange' === child.localName);
|
|
7927
|
+
return 1 === changes.length ? supportedRunFormattingChangeElement(changes[0]) : null;
|
|
7928
|
+
}
|
|
7929
|
+
function supportedRunFormattingChangeElement(change) {
|
|
7930
|
+
if ('rPrChange' !== change.localName || !DOCX_WORDPROCESSING_NAMESPACES.has(change.namespaceURI ?? '')) return null;
|
|
7931
|
+
const properties = Array.from(change.children).filter((child)=>'rPr' === child.localName && DOCX_WORDPROCESSING_NAMESPACES.has(child.namespaceURI ?? ''));
|
|
7932
|
+
if (1 !== properties.length || 1 !== change.children.length) return null;
|
|
7933
|
+
const source = properties[0];
|
|
7934
|
+
const names = new Set();
|
|
7935
|
+
for (const child of Array.from(source.children)){
|
|
7936
|
+
const supportedWordProperty = DOCX_WORDPROCESSING_NAMESPACES.has(child.namespaceURI ?? '') && SUPPORTED_RUN_PROPERTY_CHANGE_CHILDREN.has(child.localName);
|
|
7937
|
+
const supportedOpenTypeProperty = child.namespaceURI === DOCX_WORD_2010_NAMESPACE && SUPPORTED_OPEN_TYPE_PROPERTY_CHANGE_CHILDREN.has(child.localName);
|
|
7938
|
+
const key = `${child.namespaceURI ?? ''}|${child.localName}`;
|
|
7939
|
+
if (!supportedWordProperty && !supportedOpenTypeProperty || names.has(key)) return null;
|
|
7940
|
+
names.add(key);
|
|
7941
|
+
}
|
|
7942
|
+
if (Array.from(source.children).some((child)=>child.namespaceURI === DOCX_WORD_2010_NAMESPACE)) {
|
|
7943
|
+
const openType = resolveDocxOpenTypeFeatures([
|
|
7944
|
+
source
|
|
7945
|
+
]);
|
|
7946
|
+
if (!openType.features || openType.invalidCount || openType.spoofedCount) return null;
|
|
7947
|
+
}
|
|
7948
|
+
const id = work_ooxml_package_attribute(change, 'id')?.trim() ?? '';
|
|
7949
|
+
const author = work_ooxml_package_attribute(change, 'author')?.trim() ?? '';
|
|
7950
|
+
const date = work_ooxml_package_attribute(change, 'date');
|
|
7951
|
+
if (!/^\+?\d{1,10}$/.test(id) || !author || author.length > 255) return null;
|
|
7952
|
+
if (date && !Number.isFinite(Date.parse(date))) return null;
|
|
7953
|
+
return {
|
|
7954
|
+
id,
|
|
7955
|
+
author,
|
|
7956
|
+
date,
|
|
7957
|
+
properties: source
|
|
7958
|
+
};
|
|
7959
|
+
}
|
|
7960
|
+
function formattingChangeMarkup(document, change) {
|
|
7961
|
+
const span = document.createElement('span');
|
|
7962
|
+
span.dataset.documentChange = 'true';
|
|
7963
|
+
span.dataset.changeKind = 'formatting';
|
|
7964
|
+
span.dataset.changeId = change.id;
|
|
7965
|
+
span.dataset.changeAuthor = change.author;
|
|
7966
|
+
span.dataset.changeDate = change.date;
|
|
7967
|
+
span.dataset.changeBefore = change.before;
|
|
7968
|
+
const html = span.outerHTML;
|
|
7969
|
+
return {
|
|
7970
|
+
start: html.slice(0, html.indexOf('>') + 1),
|
|
7971
|
+
end: '</span>'
|
|
7972
|
+
};
|
|
7973
|
+
}
|
|
7974
|
+
function work_docx_run_formatting_import_normalizeRevisionDate(value) {
|
|
7975
|
+
if (!value) return '';
|
|
7976
|
+
const time = Date.parse(value);
|
|
7977
|
+
return Number.isFinite(time) ? new Date(time).toISOString() : '';
|
|
7978
|
+
}
|
|
7979
|
+
function work_docx_run_formatting_import_themeReference(element, themeName, tintName, shadeName, resolved) {
|
|
7980
|
+
const theme = work_docx_run_formatting_import_wordAttribute(element, themeName)?.trim();
|
|
7981
|
+
if (!theme) return;
|
|
7982
|
+
const tint = work_docx_run_formatting_import_normalizedByteHex(work_docx_run_formatting_import_wordAttribute(element, tintName));
|
|
7983
|
+
const shade = work_docx_run_formatting_import_normalizedByteHex(work_docx_run_formatting_import_wordAttribute(element, shadeName));
|
|
7984
|
+
return {
|
|
7985
|
+
theme,
|
|
7986
|
+
resolved,
|
|
7987
|
+
...tint ? {
|
|
7988
|
+
tint
|
|
7989
|
+
} : {},
|
|
7990
|
+
...shade ? {
|
|
7991
|
+
shade
|
|
7992
|
+
} : {}
|
|
7993
|
+
};
|
|
7994
|
+
}
|
|
7995
|
+
function work_docx_run_formatting_import_normalizedByteHex(value) {
|
|
7996
|
+
const normalized = value?.trim().toUpperCase();
|
|
7997
|
+
return normalized && /^[0-9A-F]{2}$/.test(normalized) ? normalized : void 0;
|
|
7998
|
+
}
|
|
7999
|
+
function overriddenBoolean(current, next) {
|
|
8000
|
+
return void 0 === next ? current : next;
|
|
8001
|
+
}
|
|
8002
|
+
function overriddenValue(current, next) {
|
|
8003
|
+
return void 0 === next ? current : next;
|
|
8004
|
+
}
|
|
8005
|
+
function propertySourcesUseComplexScript(propertySources) {
|
|
8006
|
+
let complexScript;
|
|
8007
|
+
let rightToLeft;
|
|
8008
|
+
for (const properties of propertySources){
|
|
8009
|
+
complexScript = overriddenBoolean(complexScript, onOffProperty(properties, 'cs'));
|
|
8010
|
+
rightToLeft = overriddenBoolean(rightToLeft, onOffProperty(properties, 'rtl'));
|
|
8011
|
+
}
|
|
8012
|
+
return true === complexScript || true === rightToLeft;
|
|
8013
|
+
}
|
|
8014
|
+
function onOffProperty(properties, propertyName) {
|
|
8015
|
+
const element = directChild(properties, propertyName);
|
|
8016
|
+
if (!element) return;
|
|
8017
|
+
const value = work_docx_run_formatting_import_wordAttribute(element, 'val')?.trim().toLowerCase();
|
|
8018
|
+
return '0' !== value && 'false' !== value && 'off' !== value;
|
|
8019
|
+
}
|
|
8020
|
+
function underlineProperty(properties, theme) {
|
|
8021
|
+
const element = directChild(properties, 'u');
|
|
8022
|
+
if (!element) return;
|
|
8023
|
+
return importedDocxUnderline(element, theme);
|
|
8024
|
+
}
|
|
8025
|
+
function work_docx_run_formatting_import_closestAncestor(element, localName) {
|
|
8026
|
+
let current = element.parentElement;
|
|
8027
|
+
while(current){
|
|
8028
|
+
if (current.localName === localName) return current;
|
|
8029
|
+
current = current.parentElement;
|
|
8030
|
+
}
|
|
8031
|
+
return null;
|
|
8032
|
+
}
|
|
8033
|
+
function defaultThemeFontFamily(theme, preferred) {
|
|
8034
|
+
const fonts = {
|
|
8035
|
+
ascii: docxThemeFont(theme, 'minorAscii'),
|
|
8036
|
+
highAnsi: docxThemeFont(theme, 'minorHAnsi'),
|
|
8037
|
+
eastAsia: docxThemeFont(theme, 'minorEastAsia'),
|
|
8038
|
+
complexScript: docxThemeFont(theme, 'minorBidi')
|
|
8039
|
+
};
|
|
8040
|
+
return uniqueFonts(documentScriptFontFallbackSlots(preferred).map((slot)=>fonts[slot]));
|
|
8041
|
+
}
|
|
8042
|
+
function uniqueFonts(values) {
|
|
8043
|
+
const fonts = [
|
|
8044
|
+
...new Set(values.filter((value)=>!!value))
|
|
8045
|
+
];
|
|
8046
|
+
return fonts.length ? fonts.map(cssFontFamily).join(', ') : void 0;
|
|
8047
|
+
}
|
|
8048
|
+
function cssFontFamily(value) {
|
|
8049
|
+
return /[\s"',]/.test(value) ? `"${value.replaceAll('\\', '\\\\').replaceAll('"', '\\"')}"` : value;
|
|
8050
|
+
}
|
|
8051
|
+
function work_docx_run_formatting_import_numericAttribute(element, name) {
|
|
8052
|
+
if (!element) return;
|
|
8053
|
+
const raw = work_docx_run_formatting_import_wordAttribute(element, name);
|
|
8054
|
+
if (null === raw || !raw.trim()) return;
|
|
8055
|
+
const value = Number(raw);
|
|
8056
|
+
return Number.isFinite(value) ? value : void 0;
|
|
8057
|
+
}
|
|
8058
|
+
function work_docx_run_formatting_import_wordAttribute(element, name) {
|
|
8059
|
+
return work_ooxml_package_attribute(element, name) ?? work_ooxml_package_attribute(element, `w:${name}`);
|
|
8060
|
+
}
|
|
8061
|
+
function work_docx_run_formatting_import_formatNumber(value) {
|
|
8062
|
+
return Number(value.toFixed(2)).toString();
|
|
8063
|
+
}
|
|
8064
|
+
function formatLineHeightFactor(value) {
|
|
8065
|
+
return Number(value.toFixed(4)).toString();
|
|
8066
|
+
}
|
|
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;
|
|
8234
8196
|
}
|
|
8235
|
-
function
|
|
8236
|
-
|
|
8237
|
-
|
|
8238
|
-
|
|
8239
|
-
|
|
8240
|
-
const names = new Set();
|
|
8241
|
-
for (const child of Array.from(source.children)){
|
|
8242
|
-
const supportedWordProperty = DOCX_WORDPROCESSING_NAMESPACES.has(child.namespaceURI ?? '') && SUPPORTED_RUN_PROPERTY_CHANGE_CHILDREN.has(child.localName);
|
|
8243
|
-
const supportedOpenTypeProperty = child.namespaceURI === DOCX_WORD_2010_NAMESPACE && SUPPORTED_OPEN_TYPE_PROPERTY_CHANGE_CHILDREN.has(child.localName);
|
|
8244
|
-
const key = `${child.namespaceURI ?? ''}|${child.localName}`;
|
|
8245
|
-
if (!supportedWordProperty && !supportedOpenTypeProperty || names.has(key)) return null;
|
|
8246
|
-
names.add(key);
|
|
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;
|
|
8247
8202
|
}
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8203
|
+
return null;
|
|
8204
|
+
}
|
|
8205
|
+
function normalizedTitle(value) {
|
|
8206
|
+
return value.normalize('NFKC').replace(/\s+/g, ' ').trim().toLocaleLowerCase();
|
|
8207
|
+
}
|
|
8208
|
+
const work_docx_text_box_import_WORD_NAMESPACE = 'http://schemas.openxmlformats.org/wordprocessingml/2006/main';
|
|
8209
|
+
const work_docx_text_box_import_STRICT_WORD_NAMESPACE = 'http://purl.oclc.org/ooxml/wordprocessingml/main';
|
|
8210
|
+
const WORDPROCESSING_DRAWING_NAMESPACES = new Set([
|
|
8211
|
+
'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing',
|
|
8212
|
+
'http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing'
|
|
8213
|
+
]);
|
|
8214
|
+
const DRAWING_NAMESPACES = new Set([
|
|
8215
|
+
'http://schemas.openxmlformats.org/drawingml/2006/main',
|
|
8216
|
+
'http://purl.oclc.org/ooxml/drawingml/main'
|
|
8217
|
+
]);
|
|
8218
|
+
const WORDPROCESSING_SHAPE_NAMESPACES = new Set([
|
|
8219
|
+
'http://schemas.microsoft.com/office/word/2010/wordprocessingShape'
|
|
8220
|
+
]);
|
|
8221
|
+
const work_docx_text_box_import_XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace';
|
|
8222
|
+
const WORDPROCESSING_SHAPE_URI = 'http://schemas.microsoft.com/office/word/2010/wordprocessingShape';
|
|
8223
|
+
const EMUS_PER_MILLIMETER = 36000;
|
|
8224
|
+
const MAX_IMPORTED_TEXT_BOXES = 1024;
|
|
8225
|
+
const TEXT_BOX_MARKER_PATTERN = /__A3S_WORK_TEXT_BOX_\d+__/g;
|
|
8226
|
+
const TEXT_BOX_RUN_CONTENT_NAMES = new Set([
|
|
8227
|
+
'br',
|
|
8228
|
+
'cr',
|
|
8229
|
+
'noBreakHyphen',
|
|
8230
|
+
'softHyphen',
|
|
8231
|
+
'sym',
|
|
8232
|
+
'tab',
|
|
8233
|
+
't'
|
|
8234
|
+
]);
|
|
8235
|
+
function markDocxTextBoxes(document) {
|
|
8236
|
+
const textBoxes = [];
|
|
8237
|
+
const drawings = docxDrawings(document);
|
|
8238
|
+
let nextMarker = 1;
|
|
8239
|
+
for (const drawing of drawings){
|
|
8240
|
+
const shape = supportedTextBoxShape(drawing);
|
|
8241
|
+
if (!shape) continue;
|
|
8242
|
+
const paragraph = work_docx_text_box_import_closestAncestor(drawing, 'p');
|
|
8243
|
+
const run = work_docx_text_box_import_closestAncestor(drawing, 'r');
|
|
8244
|
+
if (!paragraph || !run || !isSoleDrawingParagraph(paragraph, run)) continue;
|
|
8245
|
+
if (textBoxes.length >= MAX_IMPORTED_TEXT_BOXES) throw new Error('Imported DOCX exceeds the text-box limit.');
|
|
8246
|
+
const marker = nextTextBoxMarker(document, nextMarker);
|
|
8247
|
+
nextMarker += 1;
|
|
8248
|
+
const properties = textBoxProperties(drawing, shape, textBoxes.length + 1);
|
|
8249
|
+
replaceParagraphWithTextBoxRuns(document, paragraph, shape.content, marker);
|
|
8250
|
+
textBoxes.push({
|
|
8251
|
+
marker,
|
|
8252
|
+
properties
|
|
8253
|
+
});
|
|
8253
8254
|
}
|
|
8254
|
-
const id = work_ooxml_package_attribute(change, 'id')?.trim() ?? '';
|
|
8255
|
-
const author = work_ooxml_package_attribute(change, 'author')?.trim() ?? '';
|
|
8256
|
-
const date = work_ooxml_package_attribute(change, 'date');
|
|
8257
|
-
if (!/^\+?\d{1,10}$/.test(id) || !author || author.length > 255) return null;
|
|
8258
|
-
if (date && !Number.isFinite(Date.parse(date))) return null;
|
|
8259
8255
|
return {
|
|
8260
|
-
|
|
8261
|
-
author,
|
|
8262
|
-
date,
|
|
8263
|
-
properties: source
|
|
8256
|
+
textBoxes
|
|
8264
8257
|
};
|
|
8265
8258
|
}
|
|
8266
|
-
function
|
|
8267
|
-
|
|
8268
|
-
|
|
8269
|
-
|
|
8270
|
-
|
|
8271
|
-
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
|
|
8259
|
+
function inspectDocxTextBoxes(document) {
|
|
8260
|
+
let supported = 0;
|
|
8261
|
+
let unsupported = 0;
|
|
8262
|
+
for (const drawing of docxDrawings(document)){
|
|
8263
|
+
if (!textBoxShapeCandidate(drawing)) continue;
|
|
8264
|
+
const shape = supportedTextBoxShape(drawing);
|
|
8265
|
+
if (!shape) {
|
|
8266
|
+
unsupported += 1;
|
|
8267
|
+
continue;
|
|
8268
|
+
}
|
|
8269
|
+
const paragraph = work_docx_text_box_import_closestAncestor(drawing, 'p');
|
|
8270
|
+
const run = work_docx_text_box_import_closestAncestor(drawing, 'r');
|
|
8271
|
+
if (paragraph && run && isSoleDrawingParagraph(paragraph, run)) supported += 1;
|
|
8272
|
+
else unsupported += 1;
|
|
8273
|
+
}
|
|
8275
8274
|
return {
|
|
8276
|
-
|
|
8277
|
-
|
|
8275
|
+
supported,
|
|
8276
|
+
unsupported
|
|
8278
8277
|
};
|
|
8279
8278
|
}
|
|
8280
|
-
function
|
|
8281
|
-
if (!
|
|
8282
|
-
const
|
|
8283
|
-
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
const
|
|
8287
|
-
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8279
|
+
function applyImportedDocxTextBoxMarkers(document, markers) {
|
|
8280
|
+
if (!markers.textBoxes.length) return;
|
|
8281
|
+
const byMarker = new Map(markers.textBoxes.map((textBox)=>[
|
|
8282
|
+
textBox.marker,
|
|
8283
|
+
textBox
|
|
8284
|
+
]));
|
|
8285
|
+
const nodes = work_docx_text_box_import_textNodes(document.body);
|
|
8286
|
+
for (const node of nodes){
|
|
8287
|
+
if (!node.data.includes('__A3S_WORK_TEXT_BOX_')) continue;
|
|
8288
|
+
const match = node.data.match(TEXT_BOX_MARKER_PATTERN)?.find((value)=>byMarker.has(value));
|
|
8289
|
+
if (!match) continue;
|
|
8290
|
+
const textBox = byMarker.get(match);
|
|
8291
|
+
if (!textBox) continue;
|
|
8292
|
+
node.data = node.data.replace(match, '');
|
|
8293
|
+
const block = work_docx_text_box_import_closestHtmlBlock(node.parentElement);
|
|
8294
|
+
if (!block) continue;
|
|
8295
|
+
const wrapper = document.createElement('div');
|
|
8296
|
+
for (const attribute of Array.from(block.attributes))if (attribute.name.startsWith('data-office-') || attribute.name.startsWith('data-document-')) wrapper.setAttribute(attribute.name, attribute.value);
|
|
8297
|
+
for (const [name, value] of Object.entries(textBoxDomAttributes(textBox.properties)))if (void 0 !== value) wrapper.setAttribute(name, value);
|
|
8298
|
+
wrapper.className = 'work-document-text-box';
|
|
8299
|
+
wrapper.setAttribute('role', 'textbox');
|
|
8300
|
+
wrapper.setAttribute('aria-label', '文本框');
|
|
8301
|
+
wrapper.setAttribute('style', textBoxCss(textBox.properties));
|
|
8302
|
+
while(block.firstChild)wrapper.append(block.firstChild);
|
|
8303
|
+
block.replaceWith(wrapper);
|
|
8304
|
+
}
|
|
8305
|
+
document.body.normalize();
|
|
8300
8306
|
}
|
|
8301
|
-
function
|
|
8302
|
-
|
|
8303
|
-
return normalized && /^[0-9A-F]{2}$/.test(normalized) ? normalized : void 0;
|
|
8307
|
+
function hasImportedDocxTextBoxMarkers(markers) {
|
|
8308
|
+
return markers.textBoxes.length > 0;
|
|
8304
8309
|
}
|
|
8305
|
-
function
|
|
8306
|
-
|
|
8310
|
+
function textBoxShapeCandidate(drawing) {
|
|
8311
|
+
if (!WORDPROCESSING_DRAWING_NAMESPACES.has(drawing.namespaceURI ?? '')) return null;
|
|
8312
|
+
const graphicData = descendants(drawing, 'graphicData').find((element)=>DRAWING_NAMESPACES.has(element.namespaceURI ?? '') && work_ooxml_package_attribute(element, 'uri') === WORDPROCESSING_SHAPE_URI);
|
|
8313
|
+
if (!graphicData) return null;
|
|
8314
|
+
const shape = directChild(graphicData, 'wsp');
|
|
8315
|
+
if (!shape || !WORDPROCESSING_SHAPE_NAMESPACES.has(shape.namespaceURI ?? '')) return null;
|
|
8316
|
+
const nonVisual = directChild(shape, 'cNvSpPr');
|
|
8317
|
+
if (nonVisual && !WORDPROCESSING_SHAPE_NAMESPACES.has(nonVisual.namespaceURI ?? '')) return null;
|
|
8318
|
+
const txBox = work_ooxml_package_attribute(nonVisual ?? shape, 'txBox')?.trim().toLowerCase();
|
|
8319
|
+
if ('1' !== txBox && 'true' !== txBox) return null;
|
|
8320
|
+
return shape;
|
|
8307
8321
|
}
|
|
8308
|
-
function
|
|
8309
|
-
|
|
8322
|
+
function supportedTextBoxShape(drawing) {
|
|
8323
|
+
const shape = textBoxShapeCandidate(drawing);
|
|
8324
|
+
if (!shape) return null;
|
|
8325
|
+
const txbx = directChild(shape, 'txbx');
|
|
8326
|
+
if (txbx && !WORDPROCESSING_SHAPE_NAMESPACES.has(txbx.namespaceURI ?? '')) return null;
|
|
8327
|
+
const content = txbx ? directChild(txbx, 'txbxContent') : void 0;
|
|
8328
|
+
return content && work_docx_text_box_import_isWordElement(content, 'txbxContent') && isSupportedTextBoxContent(content) ? {
|
|
8329
|
+
shape,
|
|
8330
|
+
content
|
|
8331
|
+
} : null;
|
|
8310
8332
|
}
|
|
8311
|
-
function
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
for (const
|
|
8315
|
-
|
|
8316
|
-
|
|
8333
|
+
function isSupportedTextBoxContent(content) {
|
|
8334
|
+
const paragraphs = work_ooxml_package_directChildren(content);
|
|
8335
|
+
if (!paragraphs.length) return false;
|
|
8336
|
+
for (const paragraph of paragraphs){
|
|
8337
|
+
if (!work_docx_text_box_import_isWordElement(paragraph, 'p')) return false;
|
|
8338
|
+
const children = work_ooxml_package_directChildren(paragraph).filter((element)=>'pPr' !== element.localName);
|
|
8339
|
+
for (const child of children){
|
|
8340
|
+
if (!work_docx_text_box_import_isWordElement(child, 'r')) return false;
|
|
8341
|
+
const runChildren = work_ooxml_package_directChildren(child).filter((element)=>'rPr' !== element.localName);
|
|
8342
|
+
if (runChildren.some((element)=>!isWordNamespace(element) || !TEXT_BOX_RUN_CONTENT_NAMES.has(element.localName))) return false;
|
|
8343
|
+
}
|
|
8317
8344
|
}
|
|
8318
|
-
return true
|
|
8319
|
-
}
|
|
8320
|
-
function onOffProperty(properties, propertyName) {
|
|
8321
|
-
const element = directChild(properties, propertyName);
|
|
8322
|
-
if (!element) return;
|
|
8323
|
-
const value = work_docx_run_formatting_import_wordAttribute(element, 'val')?.trim().toLowerCase();
|
|
8324
|
-
return '0' !== value && 'false' !== value && 'off' !== value;
|
|
8345
|
+
return true;
|
|
8325
8346
|
}
|
|
8326
|
-
function
|
|
8327
|
-
|
|
8328
|
-
if (!element) return;
|
|
8329
|
-
return importedDocxUnderline(element, theme);
|
|
8347
|
+
function work_docx_text_box_import_isWordElement(element, localName) {
|
|
8348
|
+
return element.localName === localName && isWordNamespace(element);
|
|
8330
8349
|
}
|
|
8331
|
-
function
|
|
8332
|
-
|
|
8333
|
-
while(current){
|
|
8334
|
-
if (current.localName === localName) return current;
|
|
8335
|
-
current = current.parentElement;
|
|
8336
|
-
}
|
|
8337
|
-
return null;
|
|
8350
|
+
function isWordNamespace(element) {
|
|
8351
|
+
return element.namespaceURI === work_docx_text_box_import_WORD_NAMESPACE || element.namespaceURI === work_docx_text_box_import_STRICT_WORD_NAMESPACE;
|
|
8338
8352
|
}
|
|
8339
|
-
function
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
|
|
8343
|
-
|
|
8344
|
-
complexScript: docxThemeFont(theme, 'minorBidi')
|
|
8345
|
-
};
|
|
8346
|
-
return uniqueFonts(documentScriptFontFallbackSlots(preferred).map((slot)=>fonts[slot]));
|
|
8353
|
+
function docxDrawings(document) {
|
|
8354
|
+
return [
|
|
8355
|
+
...descendants(document, 'anchor'),
|
|
8356
|
+
...descendants(document, 'inline')
|
|
8357
|
+
].filter((element)=>WORDPROCESSING_DRAWING_NAMESPACES.has(element.namespaceURI ?? ''));
|
|
8347
8358
|
}
|
|
8348
|
-
function
|
|
8349
|
-
const
|
|
8350
|
-
|
|
8351
|
-
|
|
8352
|
-
return
|
|
8359
|
+
function isSoleDrawingParagraph(paragraph, run) {
|
|
8360
|
+
const meaningful = work_ooxml_package_directChildren(paragraph).filter((element)=>'pPr' !== element.localName);
|
|
8361
|
+
if (1 !== meaningful.length || meaningful[0] !== run) return false;
|
|
8362
|
+
const runContent = work_ooxml_package_directChildren(run).filter((element)=>'rPr' !== element.localName);
|
|
8363
|
+
return 1 === runContent.length && runContent[0]?.localName === 'drawing';
|
|
8353
8364
|
}
|
|
8354
|
-
function
|
|
8355
|
-
|
|
8365
|
+
function replaceParagraphWithTextBoxRuns(document, paragraph, content, marker) {
|
|
8366
|
+
const namespace = paragraph.namespaceURI || work_docx_text_box_import_WORD_NAMESPACE;
|
|
8367
|
+
const prefix = paragraph.prefix ? `${paragraph.prefix}:` : 'w:';
|
|
8368
|
+
const paragraphProperties = directChild(paragraph, 'pPr');
|
|
8369
|
+
const runs = [];
|
|
8370
|
+
const sourceParagraphs = work_ooxml_package_directChildren(content, 'p');
|
|
8371
|
+
for (const [paragraphIndex, sourceParagraph] of sourceParagraphs.entries()){
|
|
8372
|
+
if (paragraphIndex > 0) runs.push(createBreakRun(document, namespace, prefix));
|
|
8373
|
+
const sourceRuns = work_ooxml_package_directChildren(sourceParagraph, 'r');
|
|
8374
|
+
for (const sourceRun of sourceRuns)runs.push(document.importNode(sourceRun, true));
|
|
8375
|
+
}
|
|
8376
|
+
const markerRun = createTextRun(document, namespace, prefix, marker);
|
|
8377
|
+
paragraph.replaceChildren(...paragraphProperties ? [
|
|
8378
|
+
paragraphProperties
|
|
8379
|
+
] : [], markerRun, ...runs);
|
|
8356
8380
|
}
|
|
8357
|
-
function
|
|
8358
|
-
|
|
8359
|
-
const
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8381
|
+
function createTextRun(document, namespace, prefix, textValue) {
|
|
8382
|
+
const run = document.createElementNS(namespace, `${prefix}r`);
|
|
8383
|
+
const text = document.createElementNS(namespace, `${prefix}t`);
|
|
8384
|
+
text.setAttributeNS(work_docx_text_box_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
8385
|
+
text.textContent = textValue;
|
|
8386
|
+
run.append(text);
|
|
8387
|
+
return run;
|
|
8363
8388
|
}
|
|
8364
|
-
function
|
|
8365
|
-
|
|
8389
|
+
function createBreakRun(document, namespace, prefix) {
|
|
8390
|
+
const run = document.createElementNS(namespace, `${prefix}r`);
|
|
8391
|
+
run.append(document.createElementNS(namespace, `${prefix}br`));
|
|
8392
|
+
return run;
|
|
8366
8393
|
}
|
|
8367
|
-
function
|
|
8368
|
-
|
|
8394
|
+
function textBoxProperties(drawing, shape, index) {
|
|
8395
|
+
const extent = directChild(drawing, 'extent');
|
|
8396
|
+
const shapeProperties = directChild(shape.shape, 'spPr');
|
|
8397
|
+
const transform = shapeProperties ? directChild(shapeProperties, 'xfrm') : void 0;
|
|
8398
|
+
const extension = directChild(transform ?? shapeProperties ?? shape.shape, 'ext');
|
|
8399
|
+
const width = emuMillimeters(work_ooxml_package_attribute(extent ?? extension ?? shape.shape, 'cx') ?? work_ooxml_package_attribute(extent ?? extension ?? shape.shape, 'x'), 120);
|
|
8400
|
+
const height = emuMillimeters(work_ooxml_package_attribute(extent ?? extension ?? shape.shape, 'cy') ?? work_ooxml_package_attribute(extent ?? extension ?? shape.shape, 'y'), 45);
|
|
8401
|
+
const docProperties = directChild(drawing, 'docPr');
|
|
8402
|
+
const docPropertiesId = integerAttribute(docProperties, 'id');
|
|
8403
|
+
const sourceName = attributeOptional(docProperties, 'name')?.trim() ?? '';
|
|
8404
|
+
const id = sourceName.startsWith('A3S Text Box ') ? sourceName.slice(13).trim() : null === docPropertiesId ? `docx-text-box-${index}` : `docx-text-box-${docPropertiesId}`;
|
|
8405
|
+
const bodyProperties = directChild(shape.shape, 'bodyPr');
|
|
8406
|
+
const horizontal = directChild(drawing, 'positionH');
|
|
8407
|
+
const vertical = directChild(drawing, 'positionV');
|
|
8408
|
+
const layout = 'anchor' === drawing.localName ? 'floating' : 'inline';
|
|
8409
|
+
const fill = shapeFill(shapeProperties);
|
|
8410
|
+
const border = shapeBorder(shapeProperties);
|
|
8411
|
+
return normalizeDocumentTextBoxProperties({
|
|
8412
|
+
id,
|
|
8413
|
+
width,
|
|
8414
|
+
height,
|
|
8415
|
+
layout,
|
|
8416
|
+
horizontalOffset: positionOffset(horizontal),
|
|
8417
|
+
verticalOffset: positionOffset(vertical),
|
|
8418
|
+
horizontalReference: positionReference(horizontal, 'column'),
|
|
8419
|
+
verticalReference: positionReference(vertical, 'paragraph'),
|
|
8420
|
+
fill,
|
|
8421
|
+
borderColor: border.color,
|
|
8422
|
+
borderWidth: border.width,
|
|
8423
|
+
padding: bodyPadding(bodyProperties),
|
|
8424
|
+
verticalAlign: bodyVerticalAlign(bodyProperties),
|
|
8425
|
+
docPropertiesId
|
|
8426
|
+
});
|
|
8369
8427
|
}
|
|
8370
|
-
function
|
|
8371
|
-
|
|
8428
|
+
function shapeFill(shapeProperties) {
|
|
8429
|
+
if (!shapeProperties || directChild(shapeProperties, 'noFill')) return 'transparent';
|
|
8430
|
+
const fill = directChild(shapeProperties, 'solidFill');
|
|
8431
|
+
const rgb = fill ? directChild(fill, 'srgbClr') : void 0;
|
|
8432
|
+
const value = attributeOptional(rgb, 'val')?.trim();
|
|
8433
|
+
return value && /^[0-9a-f]{6}$/i.test(value) ? `#${value}` : 'transparent';
|
|
8372
8434
|
}
|
|
8373
|
-
|
|
8374
|
-
const
|
|
8375
|
-
|
|
8376
|
-
|
|
8377
|
-
|
|
8378
|
-
|
|
8379
|
-
|
|
8380
|
-
|
|
8381
|
-
|
|
8382
|
-
if (!parsed.supported) continue;
|
|
8383
|
-
const tableIndex = tables.length + 1;
|
|
8384
|
-
const marker = {
|
|
8385
|
-
marker: `__A3S_WORK_TABLE_OF_CONTENTS_${tableIndex}__`,
|
|
8386
|
-
id: `docx-table-of-contents-${tableIndex}`,
|
|
8387
|
-
options: {
|
|
8388
|
-
...parsed.options,
|
|
8389
|
-
leader: importedTableOfContentsLeader(element, parsed.options)
|
|
8390
|
-
},
|
|
8391
|
-
entries: importedTableOfContentsEntries(element, tableIndex)
|
|
8392
|
-
};
|
|
8393
|
-
element.replaceWith(work_docx_table_of_contents_import_markerParagraph(document, marker.marker));
|
|
8394
|
-
tables.push(marker);
|
|
8395
|
-
}
|
|
8435
|
+
function shapeBorder(shapeProperties) {
|
|
8436
|
+
const line = shapeProperties ? directChild(shapeProperties, 'ln') : void 0;
|
|
8437
|
+
if (!line || directChild(line, 'noFill')) return {
|
|
8438
|
+
color: 'none',
|
|
8439
|
+
width: 0
|
|
8440
|
+
};
|
|
8441
|
+
const fill = directChild(line, 'solidFill');
|
|
8442
|
+
const rgb = fill ? directChild(fill, 'srgbClr') : void 0;
|
|
8443
|
+
const value = attributeOptional(rgb, 'val')?.trim();
|
|
8396
8444
|
return {
|
|
8397
|
-
|
|
8445
|
+
color: value && /^[0-9a-f]{6}$/i.test(value) ? `#${value}` : '#4472c4',
|
|
8446
|
+
width: emuMillimeters(work_ooxml_package_attribute(line, 'w'), 0.35)
|
|
8398
8447
|
};
|
|
8399
8448
|
}
|
|
8400
|
-
function
|
|
8401
|
-
|
|
8402
|
-
|
|
8403
|
-
|
|
8404
|
-
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
|
|
8408
|
-
|
|
8409
|
-
usedHeadingIndexes.add(headingIndex);
|
|
8410
|
-
const heading = headings[headingIndex];
|
|
8411
|
-
return heading ? {
|
|
8412
|
-
...entry,
|
|
8413
|
-
targetId: heading.targetId
|
|
8414
|
-
} : entry;
|
|
8415
|
-
});
|
|
8416
|
-
const fragment = document.createRange().createContextualFragment(documentTableOfContentsHtml({
|
|
8417
|
-
id: table.id,
|
|
8418
|
-
options: table.options,
|
|
8419
|
-
entries
|
|
8420
|
-
}));
|
|
8421
|
-
const block = work_docx_table_of_contents_import_closestHtmlBlock(text.parentElement);
|
|
8422
|
-
if (block) block.replaceWith(fragment);
|
|
8423
|
-
}
|
|
8424
|
-
}
|
|
8425
|
-
function hasImportedDocxTableOfContentsMarkers(markers) {
|
|
8426
|
-
return markers.tables.length > 0;
|
|
8449
|
+
function bodyPadding(bodyProperties) {
|
|
8450
|
+
if (!bodyProperties) return 3;
|
|
8451
|
+
const values = [
|
|
8452
|
+
'lIns',
|
|
8453
|
+
'rIns',
|
|
8454
|
+
'tIns',
|
|
8455
|
+
'bIns'
|
|
8456
|
+
].map((name)=>emuMillimeters(attributeOptional(bodyProperties, name), 3));
|
|
8457
|
+
return Math.min(...values);
|
|
8427
8458
|
}
|
|
8428
|
-
function
|
|
8429
|
-
const
|
|
8430
|
-
|
|
8459
|
+
function bodyVerticalAlign(bodyProperties) {
|
|
8460
|
+
const value = attributeOptional(bodyProperties, 'anchor');
|
|
8461
|
+
if ('ctr' === value) return 'center';
|
|
8462
|
+
if ('b' === value) return 'bottom';
|
|
8463
|
+
return 'top';
|
|
8431
8464
|
}
|
|
8432
|
-
function
|
|
8433
|
-
const
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
if (!level) return [];
|
|
8438
|
-
const values = descendants(paragraph, 't').map((text)=>text.textContent ?? '').filter(Boolean);
|
|
8439
|
-
const last = values.at(-1)?.trim() ?? '';
|
|
8440
|
-
const hasPageNumber = /^\d{1,6}$/.test(last);
|
|
8441
|
-
const title = (hasPageNumber ? values.slice(0, -1) : values).join('').replace(/\s+/g, ' ').trim();
|
|
8442
|
-
if (!title) return [];
|
|
8443
|
-
const hyperlink = descendants(paragraph, 'hyperlink').find((candidate)=>Boolean(work_ooxml_package_attribute(candidate, 'anchor')));
|
|
8444
|
-
const anchor = work_ooxml_package_attribute(hyperlink ?? paragraph, 'anchor')?.trim();
|
|
8445
|
-
const targetId = /^heading-[a-z0-9._:-]{1,128}$/i.test(anchor ?? '') ? anchor : `heading-import-${tableIndex}-${index + 1}`;
|
|
8446
|
-
return [
|
|
8447
|
-
{
|
|
8448
|
-
targetId,
|
|
8449
|
-
title,
|
|
8450
|
-
level,
|
|
8451
|
-
pageNumber: hasPageNumber ? Number(last) : 1
|
|
8452
|
-
}
|
|
8453
|
-
];
|
|
8454
|
-
});
|
|
8465
|
+
function positionOffset(element) {
|
|
8466
|
+
const offset = element ? directChild(element, 'posOffset') : void 0;
|
|
8467
|
+
if (!offset?.textContent?.trim()) return null;
|
|
8468
|
+
const value = Number(offset.textContent);
|
|
8469
|
+
return Number.isFinite(value) ? value / EMUS_PER_MILLIMETER : null;
|
|
8455
8470
|
}
|
|
8456
|
-
function
|
|
8457
|
-
|
|
8458
|
-
|
|
8459
|
-
|
|
8460
|
-
|
|
8461
|
-
if ('underscore' === leader) return 'underline';
|
|
8462
|
-
if (!leader || 'none' === leader) return 'none';
|
|
8463
|
-
return 'dot';
|
|
8471
|
+
function positionReference(element, fallback) {
|
|
8472
|
+
const value = attributeOptional(element, 'relativeFrom');
|
|
8473
|
+
if ('margin' === value || 'page' === value || 'column' === value) return value;
|
|
8474
|
+
if ('paragraph' === value) return value;
|
|
8475
|
+
return fallback;
|
|
8464
8476
|
}
|
|
8465
|
-
function
|
|
8466
|
-
const
|
|
8467
|
-
|
|
8468
|
-
const text = document.createElementNS(work_docx_table_of_contents_import_WORD_NAMESPACE, 'w:t');
|
|
8469
|
-
text.setAttributeNS(work_docx_table_of_contents_import_XML_NAMESPACE, 'xml:space', 'preserve');
|
|
8470
|
-
text.textContent = marker;
|
|
8471
|
-
run.append(text);
|
|
8472
|
-
paragraph.append(run);
|
|
8473
|
-
return paragraph;
|
|
8477
|
+
function emuMillimeters(value, fallback) {
|
|
8478
|
+
const number = null === value ? NaN : Number(value);
|
|
8479
|
+
return Number.isFinite(number) && number >= 0 ? number / EMUS_PER_MILLIMETER : fallback;
|
|
8474
8480
|
}
|
|
8475
|
-
function
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
const level = headingLevel ? Number(headingLevel) : Number.isInteger(outlineLevel) && outlineLevel >= 0 && outlineLevel <= 8 ? outlineLevel + 1 : null;
|
|
8480
|
-
if (null === level) return [];
|
|
8481
|
-
const identity = normalizeDocumentParagraphId(heading.dataset.officeParagraphId);
|
|
8482
|
-
return [
|
|
8483
|
-
{
|
|
8484
|
-
title: heading.textContent ?? '',
|
|
8485
|
-
level,
|
|
8486
|
-
targetId: identity ? `heading-${identity.toLowerCase()}` : `heading-imported-${index + 1}`
|
|
8487
|
-
}
|
|
8488
|
-
];
|
|
8489
|
-
});
|
|
8481
|
+
function integerAttribute(element, name) {
|
|
8482
|
+
if (!element) return null;
|
|
8483
|
+
const value = Number(attributeOptional(element, name));
|
|
8484
|
+
return Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
8490
8485
|
}
|
|
8491
|
-
function
|
|
8492
|
-
|
|
8493
|
-
const nodes = [];
|
|
8494
|
-
if (!walker) return nodes;
|
|
8495
|
-
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
8496
|
-
return nodes;
|
|
8486
|
+
function attributeOptional(element, name) {
|
|
8487
|
+
return element ? work_ooxml_package_attribute(element, name) : null;
|
|
8497
8488
|
}
|
|
8498
|
-
function
|
|
8499
|
-
let
|
|
8500
|
-
while(
|
|
8501
|
-
return
|
|
8489
|
+
function nextTextBoxMarker(document, start) {
|
|
8490
|
+
let index = start;
|
|
8491
|
+
while(document.documentElement.textContent?.includes(`__A3S_WORK_TEXT_BOX_${index}__`))index += 1;
|
|
8492
|
+
return `__A3S_WORK_TEXT_BOX_${index}__`;
|
|
8502
8493
|
}
|
|
8503
|
-
function
|
|
8494
|
+
function work_docx_text_box_import_closestAncestor(element, localName) {
|
|
8504
8495
|
let current = element;
|
|
8505
8496
|
while(current){
|
|
8506
8497
|
if (current.localName === localName) return current;
|
|
@@ -8508,7 +8499,16 @@ function work_docx_table_of_contents_import_closestAncestor(element, localName)
|
|
|
8508
8499
|
}
|
|
8509
8500
|
return null;
|
|
8510
8501
|
}
|
|
8511
|
-
function
|
|
8512
|
-
|
|
8502
|
+
function work_docx_text_box_import_closestHtmlBlock(element) {
|
|
8503
|
+
if (!element) return null;
|
|
8504
|
+
const block = element.closest('p, h1, h2, h3, h4, h5, h6, li, blockquote, td, th');
|
|
8505
|
+
return block instanceof HTMLElement ? block : null;
|
|
8506
|
+
}
|
|
8507
|
+
function work_docx_text_box_import_textNodes(root) {
|
|
8508
|
+
const walker = root.ownerDocument?.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
8509
|
+
const nodes = [];
|
|
8510
|
+
if (!walker) return nodes;
|
|
8511
|
+
while(walker.nextNode())nodes.push(walker.currentNode);
|
|
8512
|
+
return nodes;
|
|
8513
8513
|
}
|
|
8514
8514
|
export { applyImportedDocxEquationMarkers, applyImportedDocxIndexMarkers, applyImportedDocxNumberingChangeMarkers, applyImportedDocxParagraphAlignmentMarkers, applyImportedDocxParagraphBorderMarkers, applyImportedDocxParagraphDirectionMarkers, applyImportedDocxParagraphFormattingChangeMarkers, applyImportedDocxParagraphIndentMarkers, applyImportedDocxParagraphPaginationMarkers, applyImportedDocxParagraphShadingMarkers, applyImportedDocxParagraphSpacingMarkers, applyImportedDocxParagraphTabStopMarkers, applyImportedDocxRunFormattingMarkers, applyImportedDocxTableOfContentsMarkers, applyImportedDocxTextBoxMarkers, 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, hasImportedDocxTextBoxMarkers, hasInvalidDocxFieldStructure, importedDocxStrike, importedDocxUnderline, inspectDocxEquation, inspectDocxHiddenText, inspectDocxLegacyTextEffects, inspectDocxPageBorders, inspectDocxPageMarginSettings, inspectDocxPageMargins, inspectDocxPageSize, inspectDocxPaperSource, inspectDocxRunBorder, inspectDocxRunFonts, inspectDocxRunShading, inspectDocxTextBoxes, isDocxEquationLikeRoot, isSupportedDocxEquationPlacement, isSupportedDocxNumberingChange, isSupportedDocxParagraphFormattingChange, isSupportedDocxRunFormattingChange, markDocxIndexes, markDocxNumberingChanges, markDocxPackageEquations, markDocxParagraphAlignments, markDocxParagraphBorders, markDocxParagraphDirections, markDocxParagraphFormattingChanges, markDocxParagraphIndents, markDocxParagraphPagination, markDocxParagraphShading, markDocxParagraphSpacing, markDocxParagraphTabStops, markDocxRunFormattingIntoState, markDocxTablesOfContents, markDocxTextBoxes, parseDirectDocxParagraphShading, parseDocxPageBorders, parseDocxPageGeometry, parseDocxPageMargins, parseDocxPaperSource, resolveDocxHiddenText, resolveDocxLegacyTextEffects, resolveDocxParagraphBordersForParagraph, resolveDocxRunBorder, resolveDocxRunShading, resolveDocxTableStyleResolver, supportedDocxIndexEntryField, supportedDocxIndexField, supportedDocxTableOfContentsField };
|