@office-open/docx 0.9.2 → 0.9.3

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.
@@ -1,6 +1,6 @@
1
- import { A as stringifyParagraphProperties, D as stringifyChildDispatch, E as tableDesc, F as parseDrawingRun, M as parseMathChildren, O as stringifyParagraphInline, Y as BorderStyle, at as Media, j as stringifyRunProperties, n as sectionPropertiesDesc, ot as createTransformation } from "./document-CeM-U6J3.mjs";
1
+ import { A as stringifyParagraphProperties, D as stringifyChildDispatch, E as tableDesc, F as parseDrawingRun, M as parseMathChildren, O as stringifyParagraphInline, Y as BorderStyle, ct as Media, et as parseFormFieldData, j as stringifyRunProperties, lt as createTransformation, n as sectionPropertiesDesc } from "./document-D8HDkCHs.mjs";
2
2
  import { Relationships, convertInchesToTwip, decimalNumber, derivePasswordHash, hexColorValue, toUint8Array, uCharHexNumber, uniqueId, uniqueNumericIdCreator, uniqueUuid } from "@office-open/core";
3
- import { attr, attrBool, attrNum, children, colorAttr, element, escapeXml, findChild, js2xml, textOf, xml2js } from "@office-open/xml";
3
+ import { attr, attrBool, attrNum, children, colorAttr, escapeXml, findChild, js2xml, textOf, xml2js } from "@office-open/xml";
4
4
  import { ChartCollection } from "@office-open/core/chart";
5
5
  import { SmartArtCollection } from "@office-open/core/smartart";
6
6
  //#region src/parts/paragraph/formatting/alignment.ts
@@ -440,154 +440,6 @@ const RubyAlign = {
440
440
  RIGHT_VERTICAL: "rightVertical"
441
441
  };
442
442
  //#endregion
443
- //#region src/parts/paragraph/run/form-field.ts
444
- /**
445
- * Form field module for WordprocessingML documents.
446
- *
447
- * Form fields allow creating interactive controls (checkboxes, dropdown lists,
448
- * text inputs) within a document. Each form field is wrapped in a field code
449
- * region delimited by fldChar elements (begin/separate/end), with ffData
450
- * attached to the begin fldChar.
451
- *
452
- * Reference: ISO/IEC 29500-4, wml.xsd, CT_FFData, CT_FFCheckBox, CT_FFDDList, CT_FFTextInput
453
- *
454
- * @module
455
- */
456
- /**
457
- * Text input field type (ST_FFTextType).
458
- *
459
- * ## XSD Schema
460
- * ```xml
461
- * <xsd:simpleType name="ST_FFTextType">
462
- * <xsd:restriction base="xsd:string">
463
- * <xsd:enumeration value="regular"/>
464
- * <xsd:enumeration value="number"/>
465
- * <xsd:enumeration value="date"/>
466
- * <xsd:enumeration value="currentTime"/>
467
- * <xsd:enumeration value="currentDate"/>
468
- * <xsd:enumeration value="calculated"/>
469
- * </xsd:restriction>
470
- * </xsd:simpleType>
471
- * ```
472
- */
473
- const FormFieldTextType = {
474
- /** Regular text input */
475
- REGULAR: "regular",
476
- /** Numeric input */
477
- NUMBER: "number",
478
- /** Date input */
479
- DATE: "date",
480
- /** Current time */
481
- CURRENT_TIME: "currentTime",
482
- /** Current date */
483
- CURRENT_DATE: "currentDate",
484
- /** Calculated value */
485
- CALCULATED: "calculated"
486
- };
487
- /** Build a w:val-style element with a single attribute. */
488
- const valElement = (name, val) => `<${name} w:val="${val}"/>`;
489
- /**
490
- * Creates a help or status text element.
491
- */
492
- const createFormFieldText = (name, options) => `<${name} w:type="${options.type}" w:val="${options.value}"/>`;
493
- /**
494
- * Creates a checkbox form field element (w:checkBox).
495
- */
496
- const createCheckBox = (options) => {
497
- const children = [];
498
- if (options.size !== void 0) children.push(valElement("w:size", options.size));
499
- else if (options.sizeAuto !== void 0) children.push(`<w:sizeAuto/>`);
500
- if (options.default !== void 0) children.push(`<w:default/>`);
501
- if (options.checked !== void 0) children.push(`<w:checked/>`);
502
- return element("w:checkBox", void 0, children);
503
- };
504
- /**
505
- * Creates a dropdown list form field element (w:ddList).
506
- */
507
- const createDropDownList = (options) => {
508
- const children = [];
509
- if (options.result !== void 0) children.push(valElement("w:result", options.result));
510
- if (options.default !== void 0) children.push(valElement("w:default", options.default));
511
- for (const entry of options.entries) children.push(valElement("w:listEntry", entry));
512
- return element("w:ddList", void 0, children);
513
- };
514
- /**
515
- * Creates a text input form field element (w:textInput).
516
- */
517
- const createTextInput = (options) => {
518
- const children = [];
519
- if (options.type !== void 0) children.push(valElement("w:type", options.type));
520
- if (options.default !== void 0) children.push(valElement("w:default", options.default));
521
- if (options.maxLength !== void 0) children.push(valElement("w:maxLength", options.maxLength));
522
- if (options.format !== void 0) children.push(valElement("w:format", options.format));
523
- return element("w:textInput", void 0, children);
524
- };
525
- /**
526
- * Creates a form field data element (w:ffData).
527
- *
528
- * This element contains the definition for an interactive form field
529
- * (checkbox, dropdown list, or text input) within a document.
530
- *
531
- * ## XSD Schema
532
- * ```xml
533
- * <xsd:complexType name="CT_FFData">
534
- * <xsd:choice maxOccurs="unbounded">
535
- * <xsd:element name="name" type="CT_FFName"/>
536
- * <xsd:element name="label" type="CT_DecimalNumber"/>
537
- * <xsd:element name="tabIndex" type="CT_UnsignedDecimalNumber"/>
538
- * <xsd:element name="enabled" type="CT_OnOff"/>
539
- * <xsd:element name="calcOnExit" type="CT_OnOff"/>
540
- * <xsd:element name="entryMacro" type="CT_MacroName"/>
541
- * <xsd:element name="exitMacro" type="CT_MacroName"/>
542
- * <xsd:element name="helpText" type="CT_FFHelpText"/>
543
- * <xsd:element name="statusText" type="CT_FFStatusText"/>
544
- * <xsd:choice>
545
- * <xsd:element name="checkBox" type="CT_FFCheckBox"/>
546
- * <xsd:element name="ddList" type="CT_FFDDList"/>
547
- * <xsd:element name="textInput" type="CT_FFTextInput"/>
548
- * </xsd:choice>
549
- * </xsd:choice>
550
- * </xsd:complexType>
551
- * ```
552
- *
553
- * @example
554
- * ```typescript
555
- * // Checkbox
556
- * createFormFieldData({
557
- * name: "Check1",
558
- * checkBox: { checked: true, sizeAuto: true },
559
- * });
560
- *
561
- * // Dropdown
562
- * createFormFieldData({
563
- * name: "DropDown1",
564
- * dropDownList: { entries: ["Option A", "Option B", "Option C"], result: 0 },
565
- * });
566
- *
567
- * // Text input
568
- * createFormFieldData({
569
- * name: "Text1",
570
- * textInput: { type: "regular", default: "Enter text here" },
571
- * });
572
- * ```
573
- */
574
- const createFormFieldData = (options) => {
575
- const children = [];
576
- if (options.name !== void 0) children.push(valElement("w:name", options.name));
577
- if (options.label !== void 0) children.push(valElement("w:label", options.label));
578
- if (options.tabIndex !== void 0) children.push(valElement("w:tabIndex", options.tabIndex));
579
- if (options.enabled !== void 0) children.push(`<w:enabled/>`);
580
- if (options.calcOnExit !== void 0) children.push(`<w:calcOnExit/>`);
581
- if (options.entryMacro !== void 0) children.push(valElement("w:entryMacro", options.entryMacro));
582
- if (options.exitMacro !== void 0) children.push(valElement("w:exitMacro", options.exitMacro));
583
- if (options.helpText) children.push(createFormFieldText("w:helpText", options.helpText));
584
- if (options.statusText) children.push(createFormFieldText("w:statusText", options.statusText));
585
- if (options.checkBox) children.push(createCheckBox(options.checkBox));
586
- else if (options.dropDownList) children.push(createDropDownList(options.dropDownList));
587
- else if (options.textInput) children.push(createTextInput(options.textInput));
588
- return element("w:ffData", void 0, children);
589
- };
590
- //#endregion
591
443
  //#region src/parts/paragraph/run/proof-error.ts
592
444
  /**
593
445
  * Proof error types for WordprocessingML documents.
@@ -3554,6 +3406,18 @@ function parseParagraphProperties(el, ctx) {
3554
3406
  return opts;
3555
3407
  }
3556
3408
  /**
3409
+ * Concatenate `<w:t>` text in a run element.
3410
+ *
3411
+ * Used to capture a textInput form field's current value from the result run
3412
+ * (the runs between the `separate` and `end` fldChars). Only `<w:t>` is read —
3413
+ * `<w:tab>`/`<w:br>` in results are ignored as rare for user-entered text.
3414
+ */
3415
+ function collectRunText(el) {
3416
+ let text = "";
3417
+ for (const c of el.elements ?? []) if (c.name === "w:t") text += textOf(c);
3418
+ return text;
3419
+ }
3420
+ /**
3557
3421
  * Parse a w:p element into ParagraphOptions.
3558
3422
  */
3559
3423
  function parseParagraph(el, ctx) {
@@ -3561,9 +3425,35 @@ function parseParagraph(el, ctx) {
3561
3425
  const pPr = findChild(el, "w:pPr");
3562
3426
  if (pPr) Object.assign(opts, parseParagraphProperties(pPr, ctx));
3563
3427
  const childList = [];
3428
+ let pendingFormField = null;
3429
+ let collectingResult = false;
3564
3430
  for (const child of el.elements ?? []) switch (child.name) {
3565
3431
  case "w:pPr": break;
3566
3432
  case "w:r": {
3433
+ const fldCharEl = findChild(child, "w:fldChar");
3434
+ if (fldCharEl) {
3435
+ const fctype = attr(fldCharEl, "w:fldCharType");
3436
+ if (fctype === "begin") {
3437
+ const ffDataEl = findChild(fldCharEl, "w:ffData");
3438
+ if (ffDataEl) pendingFormField = parseFormFieldData(ffDataEl);
3439
+ } else if (fctype === "separate") collectingResult = true;
3440
+ else if (fctype === "end" && pendingFormField) {
3441
+ childList.push({ formField: pendingFormField });
3442
+ pendingFormField = null;
3443
+ collectingResult = false;
3444
+ }
3445
+ break;
3446
+ }
3447
+ if (pendingFormField) {
3448
+ if (collectingResult && pendingFormField.textInput) {
3449
+ const text = collectRunText(child);
3450
+ if (text) {
3451
+ const ti = pendingFormField.textInput;
3452
+ ti.value = (ti.value ?? "") + text;
3453
+ }
3454
+ }
3455
+ break;
3456
+ }
3567
3457
  const drawingEl = findChild(child, "w:drawing");
3568
3458
  if (drawingEl) {
3569
3459
  const drawingChild = parseDrawingRun(drawingEl, ctx);
@@ -3873,6 +3763,22 @@ function parseSdtProperties(el) {
3873
3763
  if (gallery) opts.docPartList.gallery = attr(gallery, "w:val");
3874
3764
  const category = findChild(dp, "w:docPartCategory");
3875
3765
  if (category) opts.docPartList.category = attr(category, "w:val");
3766
+ } else if (findChild(el, "w14:checkbox")) {
3767
+ const cb = findChild(el, "w14:checkbox");
3768
+ const cbObj = {};
3769
+ const checked = findChild(cb, "w14:checked");
3770
+ if (checked) cbObj.checked = attrBool(checked, "w14:val") ?? true;
3771
+ const checkedState = findChild(cb, "w14:checkedState");
3772
+ if (checkedState) cbObj.checkedState = {
3773
+ val: attr(checkedState, "w14:val") ?? "",
3774
+ font: attr(checkedState, "w14:font")
3775
+ };
3776
+ const uncheckedState = findChild(cb, "w14:uncheckedState");
3777
+ if (uncheckedState) cbObj.uncheckedState = {
3778
+ val: attr(uncheckedState, "w14:val") ?? "",
3779
+ font: attr(uncheckedState, "w14:font")
3780
+ };
3781
+ opts.checkbox = cbObj;
3876
3782
  }
3877
3783
  return opts;
3878
3784
  }
@@ -4714,6 +4620,28 @@ function sdtDocPartXml(name, options) {
4714
4620
  function onOffAttr(name, val) {
4715
4621
  return val ? `<${name}/>` : `<${name} w:val="0"/>`;
4716
4622
  }
4623
+ const W14_NS = "xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\"";
4624
+ /** Default symbol font for checkbox content controls (CT_SdtCheckboxSymbol). */
4625
+ const CHECKBOX_FONT = "MS Gothic";
4626
+ const DEFAULT_CHECKED = {
4627
+ val: "2612",
4628
+ font: CHECKBOX_FONT
4629
+ };
4630
+ const DEFAULT_UNCHECKED = {
4631
+ val: "2610",
4632
+ font: CHECKBOX_FONT
4633
+ };
4634
+ /**
4635
+ * Build a w14:checkbox element (Word 2010+ content control checkbox).
4636
+ *
4637
+ * Lives in the w14 extension namespace; emitted with an inline xmlns:w14 so it
4638
+ * is valid wherever w:sdtPr appears. validate.ts tolerates the w14 namespace.
4639
+ */
4640
+ function sdtCheckboxXml(opts) {
4641
+ const checked = opts.checkedState ?? DEFAULT_CHECKED;
4642
+ const unchecked = opts.uncheckedState ?? DEFAULT_UNCHECKED;
4643
+ return `<w14:checkbox ${W14_NS}>${(opts.checked ? "<w14:checked/>" : "<w14:checked w14:val=\"0\"/>") + `<w14:checkedState w14:val="${escapeXml$1(checked.val)}" w14:font="${escapeXml$1(checked.font ?? CHECKBOX_FONT)}"/><w14:uncheckedState w14:val="${escapeXml$1(unchecked.val)}" w14:font="${escapeXml$1(unchecked.font ?? CHECKBOX_FONT)}"/>`}</w14:checkbox>`;
4644
+ }
4717
4645
  function stringifySdtPr(opts) {
4718
4646
  const parts = [];
4719
4647
  if (opts.alias !== void 0) parts.push(`<w:alias w:val="${escapeXml$1(opts.alias)}"/>`);
@@ -4740,6 +4668,7 @@ function stringifySdtPr(opts) {
4740
4668
  } else if (opts.citation) parts.push("<w:citation/>");
4741
4669
  else if (opts.group) parts.push("<w:group/>");
4742
4670
  else if (opts.bibliography) parts.push("<w:bibliography/>");
4671
+ else if (opts.checkbox) parts.push(sdtCheckboxXml(opts.checkbox));
4743
4672
  return parts.length ? `<w:sdtPr>${parts.join("")}</w:sdtPr>` : "<w:sdtPr/>";
4744
4673
  }
4745
4674
  /** Parse w:sdtPr element into SdtPropertiesOptions. */
@@ -4843,6 +4772,23 @@ function parseSdtPr(el) {
4843
4772
  else if (findChild(el, "w:citation")) opts.citation = true;
4844
4773
  else if (findChild(el, "w:group")) opts.group = true;
4845
4774
  else if (findChild(el, "w:bibliography")) opts.bibliography = true;
4775
+ else if (findChild(el, "w14:checkbox")) {
4776
+ const cb = findChild(el, "w14:checkbox");
4777
+ const cbObj = {};
4778
+ const checked = findChild(cb, "w14:checked");
4779
+ if (checked) cbObj.checked = attrBool(checked, "w14:val") ?? true;
4780
+ const checkedState = findChild(cb, "w14:checkedState");
4781
+ if (checkedState) cbObj.checkedState = {
4782
+ val: attr(checkedState, "w14:val") ?? "",
4783
+ font: attr(checkedState, "w14:font")
4784
+ };
4785
+ const uncheckedState = findChild(cb, "w14:uncheckedState");
4786
+ if (uncheckedState) cbObj.uncheckedState = {
4787
+ val: attr(uncheckedState, "w14:val") ?? "",
4788
+ font: attr(uncheckedState, "w14:font")
4789
+ };
4790
+ opts.checkbox = cbObj;
4791
+ }
4846
4792
  return opts;
4847
4793
  }
4848
4794
  /** Parse w:customXmlPr element into CustomXmlPrOptions. */
@@ -4889,7 +4835,13 @@ const sdtBlockDesc = {
4889
4835
  const parts = ["<w:sdt>"];
4890
4836
  parts.push(stringifySdtPr(opts.properties));
4891
4837
  parts.push("<w:sdtEndPr/>");
4892
- if (opts.children && opts.children.length > 0) {
4838
+ if (opts.properties.checkbox) {
4839
+ const cb = opts.properties.checkbox;
4840
+ const symbol = cb.checked ?? false ? cb.checkedState ?? DEFAULT_CHECKED : cb.uncheckedState ?? DEFAULT_UNCHECKED;
4841
+ const font = escapeXml$1(symbol.font ?? CHECKBOX_FONT);
4842
+ const char = escapeXml$1(String.fromCodePoint(parseInt(symbol.val, 16)));
4843
+ parts.push(`<w:sdtContent><w:p><w:r><w:rPr><w:rFonts w:ascii="${font}" w:hAnsi="${font}"/></w:rPr><w:t>${char}</w:t></w:r></w:p></w:sdtContent>`);
4844
+ } else if (opts.children && opts.children.length > 0) {
4893
4845
  const contentParts = [];
4894
4846
  for (const child of opts.children) contentParts.push(ctx.stringifyChild(child, ctx));
4895
4847
  const contentBody = contentParts.join("");
@@ -5579,6 +5531,6 @@ var DocxReadContext = class {
5579
5531
  }
5580
5532
  };
5581
5533
  //#endregion
5582
- export { RelativeVerticalPosition as $, footnotesDesc as A, settingsDesc as B, fontTableDesc as C, EditGroupType as D, AltChunkCollection as E, stringifyTableOfContents as F, Numbering as G, buildNumberingCache as H, parseToc as I, LevelSuffix as J, parseNumberingDefinitions as K, SdtDateMappingType as L, parseParagraphProperties as M, stringifyBodyChild as N, parseSdtBlock as O, stringifyDocumentXml as P, RelativeHorizontalPosition as Q, SdtLock as R, bibliographyDesc as S, SubDocCollection as T, buildStyleCache as U, Styles as V, parseStyleDefinitions as W, TableLayoutType as X, TABLE_BORDERS_NONE as Y, OverlapType as Z, commentsDesc as _, AlignmentType as _t, framesetXml as a, PositionalTabAlignment as at, DocPartType as b, corePropertiesDesc as c, EmphasisMarkType as ct, sdtBlockDesc as d, HighlightColor as dt, TableAnchorType as et, setBodyParseChild as f, TextEffect as ft, contentTypesDesc as g, HeadingLevel as gt, buildContentTypes as h, TextboxTightWrapType as ht, frameXml as i, RubyAlign as it, parseParagraph as j, endnotesDesc as k, altChunkDesc as l, UnderlineType as lt, relationshipsDesc as m, TextAlignmentType as mt, DocxWriteContext as n, FormFieldTextType as nt, webSettingsDesc as o, PositionalTabLeader as ot, subDocDesc as p, PageNumber as pt, LevelFormat as q, TargetScreenSize as r, createFormFieldData as rt, customPropertiesDesc as s, PositionalTabRelativeTo as st, DocxReadContext as t, ProofErrorType as tt, customXmlBlockDesc as u, createImageData as ut, DocPartBehavior as v, CharacterSet as w, glossaryDesc as x, DocPartGallery as y, StyleLevel as z };
5534
+ export { RelativeVerticalPosition as $, footnotesDesc as A, settingsDesc as B, fontTableDesc as C, EditGroupType as D, AltChunkCollection as E, stringifyTableOfContents as F, Numbering as G, buildNumberingCache as H, parseToc as I, LevelSuffix as J, parseNumberingDefinitions as K, SdtDateMappingType as L, parseParagraphProperties as M, stringifyBodyChild as N, parseSdtBlock as O, stringifyDocumentXml as P, RelativeHorizontalPosition as Q, SdtLock as R, bibliographyDesc as S, SubDocCollection as T, buildStyleCache as U, Styles as V, parseStyleDefinitions as W, TableLayoutType as X, TABLE_BORDERS_NONE as Y, OverlapType as Z, commentsDesc as _, framesetXml as a, PositionalTabRelativeTo as at, DocPartType as b, corePropertiesDesc as c, createImageData as ct, sdtBlockDesc as d, PageNumber as dt, TableAnchorType as et, setBodyParseChild as f, TextAlignmentType as ft, contentTypesDesc as g, buildContentTypes as h, AlignmentType as ht, frameXml as i, PositionalTabLeader as it, parseParagraph as j, endnotesDesc as k, altChunkDesc as l, HighlightColor as lt, relationshipsDesc as m, HeadingLevel as mt, DocxWriteContext as n, RubyAlign as nt, webSettingsDesc as o, EmphasisMarkType as ot, subDocDesc as p, TextboxTightWrapType as pt, LevelFormat as q, TargetScreenSize as r, PositionalTabAlignment as rt, customPropertiesDesc as s, UnderlineType as st, DocxReadContext as t, ProofErrorType as tt, customXmlBlockDesc as u, TextEffect as ut, DocPartBehavior as v, CharacterSet as w, glossaryDesc as x, DocPartGallery as y, StyleLevel as z };
5583
5535
 
5584
- //# sourceMappingURL=context-CERMOUn0.mjs.map
5536
+ //# sourceMappingURL=context-DeKZoZem.mjs.map