@a3s-lab/office 0.45.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 CHANGED
@@ -309,6 +309,29 @@ and [CLI reference](./docs/latest/en/cli-reference.md).
309
309
 
310
310
  ## Current release
311
311
 
312
+ Version `0.47.0` adds a bounded common-field workflow for Writer without
313
+ introducing a second document model or a remote service:
314
+
315
+ - The Insert ribbon exposes live word and character counts. PAGE, NUMPAGES,
316
+ SECTION, SECTIONPAGES, DATE, and TIME continue to refresh from the measured
317
+ page model, while generated field results stay out of document statistics.
318
+ - The Cross-reference dialog can insert a bookmark-backed `PAGEREF` with a
319
+ stable target identity. Supported native DOCX switches round-trip as fields;
320
+ unsupported, malformed, nested, or missing-target instructions remain cached
321
+ text with explicit compatibility diagnostics.
322
+
323
+ Version `0.46.0` adds native, bounded Writer text boxes without introducing a
324
+ second document model or a remote service:
325
+
326
+ - The Insert ribbon adds an editable **Text Box** block. Its contextual ribbon
327
+ controls inline/floating placement, millimeter geometry, relative offsets,
328
+ fill, outline, padding, and vertical alignment with one controlled update and
329
+ one Undo record per intent.
330
+ - Isolated WordprocessingML text boxes round-trip through native DOCX geometry,
331
+ body properties, and fill/outline state and share the same live, preview, and
332
+ PDF projection. Mixed or malformed drawings remain an explicit diagnostic
333
+ boundary instead of being silently flattened.
334
+
312
335
  Version `0.45.0` adds bounded Writer picture transforms without introducing a
313
336
  second document model or a remote service:
314
337
 
@@ -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, 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";
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;
@@ -4246,15 +4246,15 @@ function insertFieldBoundaryMarkers(document, field, start, end) {
4246
4246
  field.end.parentNode?.insertBefore(markerText(document, end), field.end.nextSibling);
4247
4247
  return;
4248
4248
  }
4249
- field.start.parentNode?.insertBefore(markerRun(document, start), field.start);
4250
- field.end.parentNode?.insertBefore(markerRun(document, end), field.end.nextSibling);
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);
4251
4251
  }
4252
4252
  function markerParagraph(document, marker) {
4253
4253
  const paragraph = document.createElementNS(WORD_NAMESPACE, 'w:p');
4254
- paragraph.append(markerRun(document, marker));
4254
+ paragraph.append(work_docx_index_import_markerRun(document, marker));
4255
4255
  return paragraph;
4256
4256
  }
4257
- function markerRun(document, value) {
4257
+ function work_docx_index_import_markerRun(document, value) {
4258
4258
  const run = document.createElementNS(WORD_NAMESPACE, 'w:r');
4259
4259
  run.append(markerText(document, value));
4260
4260
  return run;
@@ -8205,4 +8205,310 @@ function work_docx_table_of_contents_import_closestAncestor(element, localName)
8205
8205
  function normalizedTitle(value) {
8206
8206
  return value.normalize('NFKC').replace(/\s+/g, ' ').trim().toLocaleLowerCase();
8207
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 };
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
+ });
8254
+ }
8255
+ return {
8256
+ textBoxes
8257
+ };
8258
+ }
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
+ }
8274
+ return {
8275
+ supported,
8276
+ unsupported
8277
+ };
8278
+ }
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();
8306
+ }
8307
+ function hasImportedDocxTextBoxMarkers(markers) {
8308
+ return markers.textBoxes.length > 0;
8309
+ }
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;
8321
+ }
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;
8332
+ }
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
+ }
8344
+ }
8345
+ return true;
8346
+ }
8347
+ function work_docx_text_box_import_isWordElement(element, localName) {
8348
+ return element.localName === localName && isWordNamespace(element);
8349
+ }
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;
8352
+ }
8353
+ function docxDrawings(document) {
8354
+ return [
8355
+ ...descendants(document, 'anchor'),
8356
+ ...descendants(document, 'inline')
8357
+ ].filter((element)=>WORDPROCESSING_DRAWING_NAMESPACES.has(element.namespaceURI ?? ''));
8358
+ }
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';
8364
+ }
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);
8380
+ }
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;
8388
+ }
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;
8393
+ }
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
+ });
8427
+ }
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';
8434
+ }
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();
8444
+ return {
8445
+ color: value && /^[0-9a-f]{6}$/i.test(value) ? `#${value}` : '#4472c4',
8446
+ width: emuMillimeters(work_ooxml_package_attribute(line, 'w'), 0.35)
8447
+ };
8448
+ }
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);
8458
+ }
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';
8464
+ }
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;
8470
+ }
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;
8476
+ }
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;
8480
+ }
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;
8485
+ }
8486
+ function attributeOptional(element, name) {
8487
+ return element ? work_ooxml_package_attribute(element, name) : null;
8488
+ }
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}__`;
8493
+ }
8494
+ function work_docx_text_box_import_closestAncestor(element, localName) {
8495
+ let current = element;
8496
+ while(current){
8497
+ if (current.localName === localName) return current;
8498
+ current = current.parentElement;
8499
+ }
8500
+ return null;
8501
+ }
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
+ }
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 };