- `paths` draws a custom shape from several paths, each filled with the
shape's fill, not at all, or lighter or darker, and with or without its line
- A closed part of a path inside another is a hole, whichever way round it
is drawn: parts are turned round so both fill rules cut the same holes
- `textArea` sets where a custom shape's text goes, and "fitText" fits it
- `connectionPoints` gives a custom shape its own connection points
- Connection sites and text areas are guides that keep their share of the
shape when it is resized, as PowerPoint writes freeforms
- Demo 120, with a reference render, and docs in shapes.md
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(patcher): patch repeated document placeholders in reverse order
A PatchType.DOCUMENT patch splices each matching paragraph out of its
parent, which shifts the indices of later siblings. The replacer applied
the splices in traversal order using paths collected before the first
splice, so every later occurrence was patched at a stale index: an
unrelated element was deleted, the inserted content was duplicated, and
the real placeholder was left for the recursive pass.
Apply document patches in reverse document order, innermost first, so
each splice only moves elements that have already been patched.
Fixes#3504
* fix(patcher): patch nested paragraphs, multi-text runs and repeated placeholders correctly
- Patch paragraphs in reverse traversal order for paragraph patches too. A
paragraph patch moves the runs after the placeholder, so a placeholder in a
text box inside a matched paragraph was patched at a stale path and threw.
- Reverse the breadth-first traversal instead of sorting, and skip document
patch matches inside another match, which were formatted and thrown away.
- Give each w:t in a run the right start and end, and replace the start of a
placeholder by its position in that w:t. A placeholder in a run's second
w:t threw TokenNotFoundError, and a start that also came earlier in the
same w:t replaced the wrong text.
- Mark the split with U+FFFF, which cannot be in XML, instead of a ɵ, which
can be in the document's own text.
- With keepOriginalStyles, only give the placeholder's w:rPr to inserted runs,
and merge it into a run's own w:rPr instead of adding a second one. Keep the
formatting of the text after the placeholder when keepOriginalStyles is
false.
- Patch every occurrence in one pass without searching the inserted content,
so a patch that contains its own placeholder no longer loops forever.
recursive now picks between every occurrence in a paragraph and only the
first.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- Document's background.color takes a ThemeColor, written with w:themeColor,
w:themeTint or w:themeShade and the hex colour it comes to. The released
themeColor, themeTint and themeShade strings still work, and are deprecated.
- patchDocument reads the template's theme colours (a:srgbClr, a:sysClr), so
theme colours in patches get the template's hex value rather than Office's.
- Demo 119 has a page background in a theme colour. Docs updated.
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Shapes in a ShapeGroupRun or the new ShapeCanvasRun can have an `id`, and a
child with `type: "connector"` joins two of them:
{ type: "connector", from: "start", to: { id: "step", side: "top" }, route: "elbow" }
The connector is drawn from one shape to the other, so it needs no size or
position. It attaches at the shapes' connection sites (a:stCxn/a:endCxn),
choosing the facing sides unless a side is given, and routes as Word does:
a straight line, or elbow and curved connectors that leave and arrive at right
angles and loop around shapes when they have to.
Word only keeps connectors attached when shapes move on a drawing canvas, so
ShapeCanvasRun writes a wpc:wpc canvas with an optional background and outline.
Connection sites come from the preset shape definitions of ECMA-376:
scripts/generate-preset-shape-geometry.ts extracts each shape's sites and the
guides they depend on, and a small evaluator calculates them for a shape's size
and adjustments. A test also checks the adjustments table against the
definitions.
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
OOXML abbreviates or numbers many names (roundRect, snip2DiagRect, ribbon2,
bentConnector3, sysDot, lgDash, sm/med/lg). The public API now uses names
that say what each value is, and maps them to OOXML names when writing XML:
- 49 of the 187 preset shape types, e.g. rectangle, roundedRectangle,
diagonalSnippedCornersRectangle, ribbonUp, elbowConnector, lineCallout
- Line dashes: longDash, shortDot, shortDashDot, ...
- Arrowhead sizes: small, medium, large
- Gradient path: rectangle
Passing an OOXML shape name throws an error that suggests the new name.
A new Shape Types docs page lists every shape with its OOXML name.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* watermark added
* fix: resolve final eslint identifier denylist error for string key
* fix: resolve verbatimModuleSyntax errors by using type-only imports
* style: format watermark files with prettier
* style: format watermark files with prettier
* fix: bypass prettier and eslint conflict using computed property for string key
* fix: replace explicit any with unknown array in mock context
* fix: replace explicit any with unknown array in mock context
* fix: replace explicit any with unknown array in mock context
* feat: add text and image watermarks on a generic VML drawing layer
Adds TextWatermark and ImageWatermark, inline elements that go inside a
header paragraph and emit the same markup Word writes for its own
watermarks (WordArt shape type 136 for text, picture frame type 75 for
images, PowerPlusWaterMarkObject / WordPictureWatermark ids), so Word
recognizes them and can remove or replace them from Design > Watermark.
The watermarks are built on a new src/file/vml module: typed builders for
w:pict, v:shape, v:shapetype, v:fill, v:stroke, v:textpath, v:imagedata,
v:path, v:formulas, v:handles and o:lock, plus the Word preset shape types.
The existing Textbox now uses the same builders, and future VML drawing
features can compose them too.
Compared with the original draft, rotation is written in degrees in the
shape style as Word does (not 65536-based fixed point), the shape type
definition is included, colours are normalized for VML, the default height
keeps letters in proportion for the text length, and image watermarks
register their media and header relationship like ImageRun.
Also adds docs/usage/watermarks.md, a sidebar entry, a cross-link from the
headers and footers page, and two demos.
Resolves#3017
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: unknown <yusuf.unal@nordisglobal.com>
Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
* test: paragraphStyles should not set `w:pStyle` as it is already a style
* fix(styles): stop emitting an implicit ListParagraph pStyle inside style definitions
`ParagraphProperties` adds `<w:pStyle w:val="ListParagraph"/>` whenever a paragraph has
`numbering` (or `bullet`) and names no style of its own. That is right for document
paragraphs, but the same class also builds the `w:pPr` of paragraph styles, numbering
levels and document defaults, so a custom paragraph style with `numbering` ended up
declaring `ListParagraph` as its own paragraph style. A definition inherits through
`basedOn`, not `pStyle`, and Word was reported to fall back to `ListParagraph` when
applying such a style.
Add an `implicitListParagraphStyle` config flag to `ParagraphProperties` (default `true`)
and pass `false` from `StyleForParagraph`, `LevelBase` and `ParagraphPropertiesDefaults`.
Document paragraphs, textboxes and revision tracking keep the existing behaviour.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Alexander Nortung <alexander.nortung@oakdigital.dk>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
The cover page linked to "#Welcome", but the README heading was renamed to
"Welcome to docx", so docsify resolved it to "#/?id=welcome" which matches
nothing. Point it at the current heading id instead.
Also lift the GitHub corner above the cover page. The theme gives both
".cover-main" and ".github-corner" z-index 1 and the cover is rendered later
in the DOM, so once scrolled the cover overlapped the corner and made the
link unclickable.
Fixes#3477
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
* fix(table): emit numeric pct widths in fiftieths of a percent
createTableWidthElement wrote a numeric PERCENTAGE size as a "50%" string.
Both that string and the fiftieths-of-a-percent integer (50% = 2500) are
valid under ST_MeasurementOrPercent, but Word writes the integer, and
stricter consumers — Google Docs and Apple Pages/QuickLook/Mail — misread
the string form and collapse table columns to one character.
Emit the integer (Math.round(size * 50)) for numeric pct sizes to match
Word's output. Callers who want the literal percent string can still pass a
Percentage (e.g. "50%"), which is left untouched. Adds table-width.spec.ts
and updates the two specs that asserted the old string output.
* fix(table): derive tblGrid from table and cell widths so tables render in Google Docs and Pages
Writing pct widths as fiftieths of a percent (previous commit) is correct but
does not fix#1457 on its own. Google Docs, Apple Pages, QuickLook and other
consumers lay a table out from w:tblGrid alone and ignore w:tblW / w:tcW
percentages, while docx wrote a placeholder grid of 100 twips per column
whenever columnWidths was omitted. Every percentage-width table therefore
collapsed to one character per column in those readers (#1457, #349, #216,
#3015). Word recomputes the layout from the preferred widths, which is why it
was never affected.
When columnWidths is omitted the grid is now derived, in twips, the way Word
writes it after laying the table out:
- percentages resolve against the text width of the section the table is in
(page width minus margins and gutter, per column in multi-column sections),
or against the parent cell for nested tables, at serialization time
- dxa and universal-measure widths are used as they are
- columns without a width share what is left of the table width equally
- column spans and the continuation cells inserted for rowSpan are honoured
Explicit columnWidths are written unchanged. Tables formatted without a
document (bare Formatter, patcher) resolve against the default A4 page, and
formatting a table more than once is idempotent.
New: SectionProperties.AvailableTextWidth, Body.getSectionPropertiesFor,
universalMeasureToTwips, Table.ColumnWidths and Table.getCellWidth. Adds a
demo, documents columnWidths, and applies the review nits on table-width.spec.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* test: use a cspell-friendly malformed measure in the universalMeasureToTwips spec
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
* fix: allocate bookmark numeric ids per document
* test: cover the bookmark id getter and explicit end id
* fix: reserve explicitly supplied bookmark ids
* fix: draw bookmark ids from one shared counter at construction
Resolving ids lazily from `context.file.BookmarkIds` in `prepForXml` broke
three things that worked before:
- `prepForXml` pushed a new attributes object each time it ran. Headers and
footers are formatted twice per compile, so any bookmark in one was written
with duplicate `w:id`/`w:name` attributes and Word could not open the file.
Packing the same Document twice corrupted document.xml the same way.
- `patchDocument` and `Formatter` with the default context have no
`BookmarkIds`, so formatting a Bookmark there threw.
- An explicit `BookmarkStart(name, id)` was never linked to its name, so
`BookmarkEnd(name)` allocated a different id and the pair did not match.
Give each Bookmark its id once, when it is constructed, from a single
process-wide counter (`bookmarkUniqueNumericId`). The root cause of #3478
was only that every Bookmark held its own generator, so they all wrote
`w:id="1"`; sharing one generator fixes that while keeping serialization
free of side effects and independent of the document context.
`BookmarkStart` and `BookmarkEnd` go back to their released signatures,
and the `BookmarkIds` registry and `File.BookmarkIds` getter are removed.
A compiler test now checks ids across the body, header and footer over
two compiles.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* test: cover patching in a bookmark with patchDocument
The patcher formats with a stand-in file, which is where the earlier
context-based bookmark ids threw. Check that a patched-in bookmark is
written with a start and end that share one id.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* build(deps-dev): bump eslint from 9.39.2 to 10.11.0
Bumps [eslint](https://github.com/eslint/eslint) from 9.39.2 to 10.11.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Commits](https://github.com/eslint/eslint/compare/v9.39.2...v10.11.0)
---
updated-dependencies:
- dependency-name: eslint
dependency-version: 10.11.0
dependency-type: direct:development
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore: Fix lint for ESLint 10
ESLint 10 no longer pulls in @eslint/js or globals transitively, so the
config failed to load. Add both as explicit devDependencies.
eslint-plugin-import 2.x crashes on ESLint 10 (it reads the removed
context.parserOptions) and has no release supporting it. Replace it with
eslint-plugin-import-x, the maintained fork, using the resolver-next API
with the TypeScript and Node resolvers. Rule configuration is unchanged
apart from the import/ -> import-x/ prefix.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Dolan Miu <dolan_miu@hotmail.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>