<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: jiang jinfeng</title>
    <description>The latest articles on DEV Community by jiang jinfeng (@jiang_jinfeng_205d3a3d590).</description>
    <link>https://dev.to/jiang_jinfeng_205d3a3d590</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4285584%2F22068abb-0dec-4b73-95d0-10b679f103cb.png</url>
      <title>DEV Community: jiang jinfeng</title>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jiang_jinfeng_205d3a3d590"/>
    <language>en</language>
    <item>
      <title>One Codebase, Five Targets: Inside go-pptx's Architecture</title>
      <dc:creator>jiang jinfeng</dc:creator>
      <pubDate>Sun, 06 Dec 2026 02:14:21 +0000</pubDate>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590/one-codebase-five-targets-inside-go-pptxs-architecture-1al6</link>
      <guid>https://dev.to/jiang_jinfeng_205d3a3d590/one-codebase-five-targets-inside-go-pptxs-architecture-1al6</guid>
      <description>&lt;h1&gt;
  
  
  One Codebase, Five Targets: Inside go-pptx's Architecture
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;go-pptx Tech Blog · Part 10: Architecture Evolution and Cross-Platform Delivery — v2 Layering, engine, CLI, and WASM&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Series: go-pptx Tech Blog (10 parts)&lt;br&gt;
Baseline: v2.4.4&lt;br&gt;
Keywords: ADR-030, facade convergence, engine, archlint, ECMA-376 generation pipeline, API tiers, CLI, WASM, cross-build&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. v1's architectural problem: facade and implementation entangled
&lt;/h2&gt;

&lt;p&gt;v1's module root was both the "public facade" and the "implementation itself":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;63 non-test files, over 20,000 lines;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Presentation&lt;/code&gt; + &lt;code&gt;Slide&lt;/code&gt; had more than 100 methods;&lt;/li&gt;
&lt;li&gt;Public types and business implementation were 100% in the same package;&lt;/li&gt;
&lt;li&gt;CLI, WASM, and IR each attached to the facade, prone to implementation drift;&lt;/li&gt;
&lt;li&gt;Refactoring the implementation inevitably touched public signatures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This was fine early in the project, but by v2 the bottleneck was obvious: &lt;strong&gt;the public API is frozen, yet the implementation needs to evolve freely.&lt;/strong&gt; So ADR-030 came about.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. ADR-030: A layered meta-repository
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Target layout
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;go-pptx/
├── go.mod / LICENSE / README.md     # meta-repo root (no .go files)
├── pptx/                            # public facade (the only package imported externally)
├── internal/
│   ├── document/                    # domain logic
│   │   ├── model/ style/ geometry/ text/ media/ table/
│   ├── opc/ xmlstore/               # transport/storage layer
│   ├── ooxml/ + ooxml/schema/       # format layer (read-only projection)
│   ├── engine/                      # orchestration layer
│   ├── ir/                          # read-only IR + semantic diff
│   ├── chart/ bind/ editplan/ ...   # feature subsystems
│   └── archlint/                    # dependency-direction validation
├── cmd/pptx  cmd/pptx_check         # thin entry points
├── wasm/check  wasm/site            # browser side
├── render/                          # public rendering contract (no implementation)
├── testdata/corpus/                 # corpus index and public golden samples
└── docs/                            # ADRs, design, release notes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key changes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The module root no longer has &lt;code&gt;package pptx&lt;/code&gt; files;&lt;/li&gt;
&lt;li&gt;The only official import path becomes &lt;code&gt;github.com/F31/go-pptx/v2/pptx&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;All implementation moves down into &lt;code&gt;internal/&lt;/code&gt;, protected by Go language-level privacy;&lt;/li&gt;
&lt;li&gt;The public facade holds only stable types and thin delegation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a &lt;strong&gt;one-time breaking change&lt;/strong&gt; (import path migration), in exchange for long-term implementation freedom.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.2 Six key mechanisms
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Thin facade, thick domain&lt;/strong&gt;: &lt;code&gt;pptx/&lt;/code&gt; holds only stable types and thin delegation; business logic lives in &lt;code&gt;internal/document&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OOXML type generation (read-only only)&lt;/strong&gt;: generate typed structures from the ECMA-376 XSD, replacing hand-written parsing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tests travel with packages&lt;/strong&gt;: code and tests migrate together, so coverage is naturally correct by package ownership.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unidirectional dependencies, enforced by CI&lt;/strong&gt;: build a dependency-rule check with the std-lib, without introducing external arch-lint tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;cmd/wasm share the engine&lt;/strong&gt;: CLI and WASM no longer each write their own set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Module root becomes a meta-repository&lt;/strong&gt;: structural pressure drops to zero, and future file growth is distributed across subdomain packages.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  3. engine: the shared core of CLI and WASM
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;internal/engine&lt;/code&gt; carries read-only orchestration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Inspect&lt;/code&gt;: full IR projection;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Validate&lt;/code&gt;: structural validation + diagnostic grading;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Capability&lt;/code&gt;: six-dimensional capability manifest;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ProjectIR&lt;/code&gt;: facade → IR adapter.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Its constraints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Depends only on the facade and the read-only IR;&lt;/li&gt;
&lt;li&gt;Performs no I/O;&lt;/li&gt;
&lt;li&gt;Is unaware of flag / exit code / stdout;&lt;/li&gt;
&lt;li&gt;The caller is responsible for opening input and the output form.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This way CLI and WASM get the &lt;strong&gt;same source of truth&lt;/strong&gt;, and there is no drift where "the CLI says supported, WASM says something else."&lt;/p&gt;

&lt;p&gt;&lt;code&gt;internal/engine&lt;/code&gt; is the only explicit exception to &lt;code&gt;internal/* → pptx&lt;/code&gt;, because it needs the facade's public handles. This exception is registered in &lt;code&gt;internal/archlint&lt;/code&gt;, not "let through casually."&lt;/p&gt;




&lt;h2&gt;
  
  
  4. archlint: turning dependency direction into a test
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;internal/archlint&lt;/code&gt; uses the standard library (&lt;code&gt;go/parser&lt;/code&gt; / &lt;code&gt;go list&lt;/code&gt;) to check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;internal/*&lt;/code&gt; must not import &lt;code&gt;pptx&lt;/code&gt; in reverse (&lt;code&gt;engine&lt;/code&gt; is the exception);&lt;/li&gt;
&lt;li&gt;Except for &lt;code&gt;engine&lt;/code&gt;, &lt;code&gt;internal/*&lt;/code&gt; must not import &lt;code&gt;internal/engine&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;New packages must be registered;&lt;/li&gt;
&lt;li&gt;Cross-layer imports must conform to the rules.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It runs via &lt;code&gt;go test&lt;/code&gt;, so &lt;strong&gt;no extra CI tool is needed&lt;/strong&gt;. This fits the project's "zero extra CI dependencies" policy.&lt;/p&gt;

&lt;p&gt;The value is that the architecture diagram is not a drawing in documentation, but a constraint that makes CI fail. New packages silently going unchecked, or internal packages depending on the facade in reverse, both turn red immediately.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. ECMA-376 generation pipeline: read-only projection, never touching the write path
&lt;/h2&gt;

&lt;h3&gt;
  
  
  5.1 What is generated
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;scripts/gen/schema&lt;/code&gt; generates Go types from the &lt;strong&gt;ECMA-376 Part 4 Transitional&lt;/strong&gt; XSD:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;26 XSDs;&lt;/li&gt;
&lt;li&gt;8 namespaces, 7,300+ lines;&lt;/li&gt;
&lt;li&gt;Generates read-only projection types in &lt;code&gt;internal/ooxml/schema&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5.2 Why read-only
&lt;/h3&gt;

&lt;p&gt;This is a hard constraint of ADR-030:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Generated types may only be used for read-only projection and must not enter the write path.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The reason is straightforward: &lt;code&gt;encoding/xml&lt;/code&gt; round-tripping does &lt;strong&gt;not guarantee&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Attribute order;&lt;/li&gt;
&lt;li&gt;Namespace prefix selection;&lt;/li&gt;
&lt;li&gt;Self-closing form;&lt;/li&gt;
&lt;li&gt;Whitespace.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once generated types participate in writing, the three byte-level fidelity pieces of evidence immediately become invalid:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Empty change set → byte-identical;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TestSavePlanUnchangedIsB1&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ext-0024&lt;/code&gt; single-Run replacement with a 1-byte difference.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the write path is always:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;xmlstore span patch + byte copy of unmodified Parts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generated types are used only for the read-side projection of &lt;code&gt;internal/ooxml&lt;/code&gt; (slides / notes / timing / chart), for the engine to build the IR and auditing.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.3 Pitfalls of the input source
&lt;/h3&gt;

&lt;p&gt;ECMA-376 has two schema sets, Strict and Transitional. What the project needs is &lt;strong&gt;Part 4 Transitional&lt;/strong&gt; (&lt;code&gt;schemas.openxmlformats.org&lt;/code&gt;), not Part 1 Strict (&lt;code&gt;purl.oclc.org&lt;/code&gt;). If this detail is gotten wrong, the generated types will not match real PPTX files.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. API stability tiers: making upgrades predictable
&lt;/h2&gt;

&lt;h3&gt;
  
  
  6.1 Three-tier labels
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Label&lt;/th&gt;
&lt;th&gt;Commitment&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;// Stable:&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Backward compatible, additive only, no breaks; behavior may be tightened but not loosened&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;API (default)&lt;/td&gt;
&lt;td&gt;Fields may be adjusted before v2.x is locked&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;// Deprecated:&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Retained for at least two minor versions, with a replacement entry point&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Error codes / error types are Stable by default — error codes are a hard constraint of the compatibility contract.&lt;/p&gt;

&lt;h3&gt;
  
  
  6.2 Golden-sample gate
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;pptx/api_surface_test.go&lt;/code&gt; freezes the public surface into assertions. Counts for v2.4.4:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Item&lt;/th&gt;
&lt;th&gt;Count&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Public API types&lt;/td&gt;
&lt;td&gt;221&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;// Stable:&lt;/code&gt; paragraphs&lt;/td&gt;
&lt;td&gt;73&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stable symbols&lt;/td&gt;
&lt;td&gt;96&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stable methods&lt;/td&gt;
&lt;td&gt;183&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exported methods&lt;/td&gt;
&lt;td&gt;207&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Top-level functions&lt;/td&gt;
&lt;td&gt;44&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Error sentinels&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Constants&lt;/td&gt;
&lt;td&gt;164&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These numbers are not "marketing language," but a contract that test failures will block.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. CLI: 9 subcommands, unified exit codes
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pptx inspect deck.pptx
pptx validate deck.pptx
pptx replace --old Q3 --new Q4 --output out.pptx deck.pptx
pptx &lt;span class="nb"&gt;bind&lt;/span&gt; --data data.json --output out.pptx template.pptx
pptx narrate --manifest tracks.json --output narrated.pptx deck.pptx
pptx timing-plan deck.pptx
pptx export-ir --output deck.ir.json deck.pptx
pptx capability
pptx diff old.pptx new.pptx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exit codes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Code&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;success&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;runtime / I/O error&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;usage error&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;capability / validation error&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;resource limit&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;CLI design principles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JSON is written to stdout; progress/error summaries are written to stderr;&lt;/li&gt;
&lt;li&gt;Read-only commands reject &lt;code&gt;--output&lt;/code&gt; by default;&lt;/li&gt;
&lt;li&gt;Write commands require &lt;code&gt;--output&lt;/code&gt;, and overwriting requires &lt;code&gt;--overwrite&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--help&lt;/code&gt; goes to stdout + exit 0; argument errors go to stderr + exit 2.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  8. WASM: files never leave the device
&lt;/h2&gt;

&lt;h3&gt;
  
  
  8.1 Capabilities
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;wasm/check&lt;/code&gt; exposes three pure functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;wasm&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Inspect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pptxBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;// IR projection JSON&lt;/span&gt;
&lt;span class="n"&gt;wasm&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pptxBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// validation diagnostics JSON&lt;/span&gt;
&lt;span class="n"&gt;wasm&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Capability&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fileName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;               &lt;span class="c1"&gt;// capability manifest JSON&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Input exists only in wasm linear memory;&lt;/li&gt;
&lt;li&gt;No filesystem writes;&lt;/li&gt;
&lt;li&gt;No network access;&lt;/li&gt;
&lt;li&gt;Returns JSON strings, convenient for consumption at the JS boundary.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8.2 Offline static page
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;wasm/site/&lt;/code&gt; contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;check.html&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;check.js&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pptx_check.wasm&lt;/code&gt; generated by the build script&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;wasm_exec.js&lt;/code&gt; copied from &lt;code&gt;GOROOT&lt;/code&gt; by the build script&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Opening &lt;code&gt;check.html&lt;/code&gt; directly in a modern browser is enough to use it; no server, no CDN, no backend needed.&lt;/p&gt;

&lt;p&gt;Use cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Audits where client files cannot be uploaded, such as in law firms/healthcare/finance;&lt;/li&gt;
&lt;li&gt;Client-side pre-checks before upload;&lt;/li&gt;
&lt;li&gt;Capability confirmation in offline environments.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  8.3 Build
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;GOOS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;js &lt;span class="nv"&gt;GOARCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;wasm go build -o wasm/site/pptx_check.wasm ./cmd/pptx_check
&lt;span class="c"&gt;# or (also copies wasm_exec.js)&lt;/span&gt;
bash scripts/check_wasm.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  9. Cross-build: five target classes
&lt;/h2&gt;

&lt;p&gt;CI validates on every push/PR:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Target&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;js/wasm&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;browser-side read-only check&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;wasip1/wasm&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;WASI sandbox container&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;darwin/arm64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Apple Silicon&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;linux/arm64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;ARM servers&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;windows/amd64&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Windows server/desktop&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All with &lt;code&gt;CGO_ENABLED=0&lt;/code&gt;, no C toolchain dependency, and statically linkable into containers.&lt;/p&gt;

&lt;p&gt;macOS/Windows also run the native test matrix (Go 1.24 / 1.27), avoiding "only Linux can pass."&lt;/p&gt;




&lt;h2&gt;
  
  
  10. Rendering contract: define the interface, don't pretend to implement
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;render&lt;/code&gt; subpackage defines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Renderer&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RenderOptions&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RenderCapabilities&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RenderedSlide&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RenderAll&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But has &lt;strong&gt;no implementation&lt;/strong&gt;. In Capability, the &lt;code&gt;rendering.native&lt;/code&gt; status is &lt;code&gt;Untested&lt;/code&gt;, and the documentation explicitly states "the interface has landed, but the implementation has not been scoped."&lt;/p&gt;

&lt;p&gt;This is a deliberate boundary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Native rendering would introduce heavy dependencies such as fonts, shaping, and layout;&lt;/li&gt;
&lt;li&gt;It is not suitable to cram into the core SDK;&lt;/li&gt;
&lt;li&gt;Third-party adapters can implement the interface, but must declare the capability scope;&lt;/li&gt;
&lt;li&gt;Any preview capability must be labeled "limited preview" and must not be used to prove visual consistency with PowerPoint.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  11. Roadmap and known limitations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  11.1 Explicitly not done for now
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Native rendering;&lt;/li&gt;
&lt;li&gt;Writing of encryption/signature/OLE;&lt;/li&gt;
&lt;li&gt;Full animation editing/playback evaluation;&lt;/li&gt;
&lt;li&gt;In-place saving of source files;&lt;/li&gt;
&lt;li&gt;Covering all OOXML features.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  11.2 Evolution direction
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;2.x patch line: coverage converging toward 90%, bug fixes, golden-sample guard reinforcement;&lt;/li&gt;
&lt;li&gt;2.1.x: the &lt;code&gt;Open&lt;/code&gt; series adds &lt;code&gt;ctx&lt;/code&gt; (a signature-level change, requiring an ADR + transition period);&lt;/li&gt;
&lt;li&gt;2.2.x: experimental capabilities are promoted or deprecated based on usage; deeper extraction within &lt;code&gt;internal&lt;/code&gt; proceeds as triggered;&lt;/li&gt;
&lt;li&gt;3.0 (if started): native rendering scoped as an independent project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  11.3 Evolution principles
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Do not break Stable;&lt;/li&gt;
&lt;li&gt;API additions are the default;&lt;/li&gt;
&lt;li&gt;Architectural pressure is split according to trigger conditions (merge-conflict hotspots / third-party extension needs / compile-time bottlenecks).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  12. Ten-part retrospective
&lt;/h2&gt;

&lt;p&gt;This series moves from "why do it" to "how to evolve":&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Overview&lt;/strong&gt;: purpose, goals, architecture, competitors, capabilities;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Byte-level fidelity&lt;/strong&gt;: xmlstore + SpanPatch + B1;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OPC and transactions&lt;/strong&gt;: lazy indexing, budgets, SavePlan, atomic save;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Object model and handles&lt;/strong&gt;: cross-Run text, STALE-GUARD, monotonic IDs;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chart subsystem&lt;/strong&gt;: 9 chart types, combination charts, workbooks, canonical;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Media and auto-narration&lt;/strong&gt;: pure Go probing, playback tree, timing plan;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Template binding&lt;/strong&gt;: plan/apply, zero residue;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read-only audit&lt;/strong&gt;: IR, semantic diff, Capability;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quality engineering&lt;/strong&gt;: corpus, golden samples, coverage, fuzz, L3;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Architecture evolution and cross-platform&lt;/strong&gt;: layering, engine, archlint, CLI, WASM.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you had to summarize go-pptx's design philosophy in one sentence:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Treat "modifying a document" as a verifiable transaction: touch only the bytes you should, leave no half-finished product on failure, and state the capability boundaries clearly.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  13. References and further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Repository: &lt;code&gt;github.com/F31/go-pptx&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Module: &lt;code&gt;github.com/F31/go-pptx/v2&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Facade: &lt;code&gt;github.com/F31/go-pptx/v2/pptx&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Documentation:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;README.zh.md&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;docs/architecture-current.md&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;docs/go-pptx-技术白皮书-v2.0.md&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;docs/adr/&lt;/code&gt; (ADR-014 to ADR-096)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;docs/api-reference.md&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;CHANGELOG.md&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Series navigation&lt;/strong&gt;: &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/09-quality-engineering.md" rel="noopener noreferrer"&gt;← Part 9: Quality Engineering&lt;/a&gt; · &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/01-overview.md" rel="noopener noreferrer"&gt;Back to Part 1: Overview&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>webassembly</category>
      <category>architecture</category>
      <category>cli</category>
    </item>
    <item>
      <title>How We Prove a PPTX Library Actually Works</title>
      <dc:creator>jiang jinfeng</dc:creator>
      <pubDate>Sun, 06 Dec 2026 02:14:19 +0000</pubDate>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590/how-we-prove-a-pptx-library-actually-works-48nb</link>
      <guid>https://dev.to/jiang_jinfeng_205d3a3d590/how-we-prove-a-pptx-library-actually-works-48nb</guid>
      <description>&lt;h1&gt;
  
  
  How We Prove a PPTX Library Actually Works
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;go-pptx Tech Blog · Part 9: Quality Engineering — Corpus, Golden Samples, Coverage, Fuzz, and the Real-Device Matrix&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Series: go-pptx Tech Blog (10 parts)&lt;br&gt;
Baseline: v2.4.4&lt;br&gt;
Keywords: corpus regression, B1 assertions, coverage gate, native fuzz, L3 client matrix, performance guardrails, CI&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Why "unit tests pass" is not enough
&lt;/h2&gt;

&lt;p&gt;Quality problems in a file-format library are usually not "the function is written wrong," but rather:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real documents contain extensions you have never seen;&lt;/li&gt;
&lt;li&gt;Clients differ in their tolerance and interpretation of element order and namespaces;&lt;/li&gt;
&lt;li&gt;A single "optimization" quietly changes the output bytes;&lt;/li&gt;
&lt;li&gt;Newly added security branches have no tests, and coverage silently declines;&lt;/li&gt;
&lt;li&gt;You only tested on Linux, and the Windows/WASM build fails.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;go-pptx's quality engineering revolves around one principle: &lt;strong&gt;turn "claimed capabilities" into reproducible evidence.&lt;/strong&gt; This part breaks down its layers of defense.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Corpus: 30+ real samples + public golden samples
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Corpus structure
&lt;/h3&gt;

&lt;p&gt;The project maintains a corpus index (&lt;code&gt;testdata/corpus&lt;/code&gt;):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;th&gt;Content&lt;/th&gt;
&lt;th&gt;Distributed&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Public golden samples&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;s001-text&lt;/code&gt; / &lt;code&gt;s002-table&lt;/code&gt; / &lt;code&gt;s003-image&lt;/code&gt; / &lt;code&gt;s004-audio&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Yes (license permits)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Private index&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;ext-0001&lt;/code&gt; … &lt;code&gt;ext-0033&lt;/code&gt; (sources such as PowerPoint / WPS / Google Slides / Keynote)&lt;/td&gt;
&lt;td&gt;No, manifest only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Documentation count&lt;/td&gt;
&lt;td&gt;36 samples (public golden samples + private index); &lt;code&gt;testdata/corpus&lt;/code&gt; currently has 37 manifests&lt;/td&gt;
&lt;td&gt;—&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each sample records at least:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sample ID, source license, whether it may be redistributed;&lt;/li&gt;
&lt;li&gt;Generator and version, platform;&lt;/li&gt;
&lt;li&gt;Creation steps, font environment;&lt;/li&gt;
&lt;li&gt;OOXML type (Transitional / Strict);&lt;/li&gt;
&lt;li&gt;Feature tags (which capabilities are exercised);&lt;/li&gt;
&lt;li&gt;Expected assertions;&lt;/li&gt;
&lt;li&gt;Known issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Private samples are not distributed with the open source, but their &lt;strong&gt;index&lt;/strong&gt; is kept, to prove that "we tested real sources," not just files we generated ourselves.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.2 The closed loop of public golden samples
&lt;/h3&gt;

&lt;p&gt;Each public golden sample contains:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;s001-text/
├── s001-text.pptx           # before modification
├── s001-text.edited.pptx    # after modification
├── s001-text.actions.json   # modification actions
└── s001-text.compat-smoke.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CI will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Validate the manifest / actions conventions;&lt;/li&gt;
&lt;li&gt;Replay the actions with &lt;code&gt;-tags=corpus&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Compare the post-modification bytes / structure;&lt;/li&gt;
&lt;li&gt;Archive logs on failure.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is far more meaningful than "sample files sit in the repository and nobody runs them."&lt;/p&gt;

&lt;h3&gt;
  
  
  2.3 B1 byte assertions
&lt;/h3&gt;

&lt;p&gt;The three pieces of evidence for B1:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Empty change set save: unmodified Part decompressed content is byte-identical;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ext-0024&lt;/code&gt; (WPS, containing animation + unknown extensions) single-Run replacement: the difference span converges to &lt;strong&gt;1 byte&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;Public golden sample pre/post-modification replay: byte-level comparison.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The significance of B1 is: &lt;strong&gt;differences appear only where you declared a modification.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Coverage gate: from "silent decline" to "immediately red"
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 A real lesson
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;internal/opc&lt;/code&gt; once &lt;strong&gt;silently fell from 90.4% to 89.5%&lt;/strong&gt;, dropping below the 90% threshold, and &lt;strong&gt;no one noticed for three days&lt;/strong&gt;. The reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ADR-018&lt;/code&gt; Tier 2 raw pass-through added 4 new security-limit rejection branches;&lt;/li&gt;
&lt;li&gt;These branches had no tests;&lt;/li&gt;
&lt;li&gt;At the time CI only ran build/test/vet, not coverage.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.2 Gate mechanism
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;scripts/coverage/gate.sh&lt;/code&gt; turns each package's threshold into an assertion:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;FLOORS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
  &lt;span class="s2"&gt;"github.com/F31/go-pptx/v2/pptx=82"&lt;/span&gt;
  &lt;span class="s2"&gt;"github.com/F31/go-pptx/v2/internal/opc=90"&lt;/span&gt;
  &lt;span class="s2"&gt;"github.com/F31/go-pptx/v2/internal/xmlstore=90"&lt;/span&gt;
  &lt;span class="s2"&gt;"github.com/F31/go-pptx/v2/internal/chart=90"&lt;/span&gt;
  &lt;span class="c"&gt;# ...&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It also performs a &lt;strong&gt;completeness check&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every package in &lt;code&gt;go list ./...&lt;/code&gt; must appear in &lt;code&gt;FLOORS&lt;/code&gt; or &lt;code&gt;SKIP&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Otherwise FAIL — closing off "new packages silently going unchecked."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This rule comes from three lessons of "forgot to add a threshold after adding a package."&lt;/p&gt;

&lt;h3&gt;
  
  
  3.3 Current coverage (v2.4.4)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Package&lt;/th&gt;
&lt;th&gt;Coverage&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;pptx&lt;/code&gt; (public facade)&lt;/td&gt;
&lt;td&gt;82.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;internal/opc&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;90.6%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;internal/chart&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;90.8%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;internal/ooxml&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;92.7%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;internal/document/geometry&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;90.7%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;internal/document/style&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;90.9%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Whole-repo weighted&lt;/td&gt;
&lt;td&gt;about 84%+&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The threshold is not "the higher the better," but "a regression-prevention lower bound + behavior first." For example, &lt;code&gt;ir&lt;/code&gt; / &lt;code&gt;render&lt;/code&gt; / &lt;code&gt;chart&lt;/code&gt; value the behavioral contract more, so their thresholds are taken as regression-prevention lower bounds.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Fuzz: untrusted input does not panic
&lt;/h2&gt;

&lt;p&gt;Native fuzz targets cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open paths: &lt;code&gt;opc.Load&lt;/code&gt; / &lt;code&gt;opc.Scan&lt;/code&gt; / &lt;code&gt;xmlstore.Scanner&lt;/code&gt; / &lt;code&gt;xmlstore.Index&lt;/code&gt; / &lt;code&gt;OpenReader&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Text editing: &lt;code&gt;ReplaceText&lt;/code&gt; / &lt;code&gt;SetPlainText&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Template binding: &lt;code&gt;FuzzBind&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Edit paths: &lt;code&gt;fuzz_edit&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The value of fuzz is not only "finding panics," but also:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whether resource budgets take effect (oversized Parts, overly deep XML);&lt;/li&gt;
&lt;li&gt;Whether errors are classifiable (&lt;code&gt;ErrMalformedPackage&lt;/code&gt; / &lt;code&gt;ErrLimitExceeded&lt;/code&gt; / &lt;code&gt;ErrEncoding&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;Whether zero residue is preserved on failure (revision unchanged).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Known fixes driven by fuzz include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Chart &lt;code&gt;c:pt/@idx&lt;/code&gt; upper bound (preventing the &lt;code&gt;makeslice&lt;/code&gt; panic / ~16GB allocation from &lt;code&gt;make([]string, max+1)&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;MP4 &lt;code&gt;ftyp&lt;/code&gt; compatible brand collection capped at 64 (preventing 21× amplification);&lt;/li&gt;
&lt;li&gt;Shape ID duplicate diagnostics (&lt;code&gt;DRAWING_ID_DUPLICATE&lt;/code&gt;).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. L3 client matrix: open, edit, and re-save on real devices
&lt;/h2&gt;

&lt;p&gt;Unit tests cannot prove "PowerPoint can open it." The project fills this layer with a real-device matrix:&lt;/p&gt;

&lt;h3&gt;
  
  
  5.1 First-round matrix (2026-09-11)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Microsoft PowerPoint 16.0.20326 (Microsoft 365, Windows 11);&lt;/li&gt;
&lt;li&gt;WPS Presentation 12.1.0.28599 (Windows 11);&lt;/li&gt;
&lt;li&gt;4 files × 2 clients = &lt;strong&gt;8/8 passed&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;Verified: opens with no repair prompt, re-saves, and go-pptx re-verification yields 0 errors.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sample coverage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real private samples &lt;code&gt;ext-0001&lt;/code&gt; / &lt;code&gt;ext-0008&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ext-0024&lt;/code&gt; (WPS animation + unknown extensions);&lt;/li&gt;
&lt;li&gt;Public golden sample &lt;code&gt;s001-text&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5.2 v2.4.x extended matrix
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;PowerPoint 16 / WPS 12: a &lt;strong&gt;13-page comprehensive sample&lt;/strong&gt; opens and re-saves successfully;&lt;/li&gt;
&lt;li&gt;LibreOffice 24.2: PDF conversion passes;&lt;/li&gt;
&lt;li&gt;Combination charts, series labels/styles/markers, gridlines, number formats, table styleId/diagonal lines, connector sites, and seven categories of effects are all verified to be preserved;&lt;/li&gt;
&lt;li&gt;WPS may downgrade 3D columns to 2D — recorded as known behavior, without pretending "fully identical."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reproduction script: &lt;code&gt;scripts/l3/run_client.sh&lt;/code&gt; (Windows host COM automation).&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Performance guardrails: three corpus tiers × six benchmark types
&lt;/h2&gt;

&lt;h3&gt;
  
  
  6.1 Benchmark design
&lt;/h3&gt;

&lt;p&gt;Three corpus tiers:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Corpus&lt;/th&gt;
&lt;th&gt;Scale&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;10p-text&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;10 pages of plain text&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;50p-image&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;50 pages of text and images, each page with a text box + one small image&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;100p-media&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;100 pages, with the first 20 pages overlaid with noisy large images&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Six benchmark types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Open&lt;/code&gt;: open + close;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Traverse&lt;/code&gt;: Slides → Shapes → TextFrame → Paragraph.Text;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Replace&lt;/code&gt;: single replacement;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SaveMem&lt;/code&gt;: &lt;code&gt;Write&lt;/code&gt; to &lt;code&gt;io.Discard&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SaveDisk&lt;/code&gt;: &lt;code&gt;Save&lt;/code&gt; to disk (including atomic replacement);&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PeakHeap&lt;/code&gt;: full-process heap peak.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  6.2 A real performance fix
&lt;/h3&gt;

&lt;p&gt;The V2.0.1 review found that &lt;code&gt;Presentation.Slides()&lt;/code&gt; repeatedly parsed relationships inside a loop, and that &lt;code&gt;AddPicture&lt;/code&gt; deduplication read the full bytes + SHA-256 of every stored media, forming O(N²).&lt;/p&gt;

&lt;p&gt;Measured (&lt;code&gt;BenchmarkPerfTraverse/100p-media&lt;/code&gt;, &lt;code&gt;-benchtime=6x&lt;/code&gt;):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Before fix&lt;/th&gt;
&lt;th&gt;After fix&lt;/th&gt;
&lt;th&gt;Reduction&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Time&lt;/td&gt;
&lt;td&gt;16.40 ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;3.96 ms&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;−75.8%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory&lt;/td&gt;
&lt;td&gt;26.77 MB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.17 MB&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;−95.6%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;allocs&lt;/td&gt;
&lt;td&gt;223,284&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;10,713&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;−95.2%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Such data is "platform-dependent"; the project explicitly does not write "how many times faster than Python," nor does it assert ns/op thresholds on shared CI runners (which would be flaky). CI only does a smoke guard:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The benchmark suite compiles;&lt;/li&gt;
&lt;li&gt;All three corpus tiers execute;&lt;/li&gt;
&lt;li&gt;The report generator can parse;&lt;/li&gt;
&lt;li&gt;The corpus size lower bound is guarded.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A full baseline runs separately at night.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. CI: one matrix
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Job&lt;/th&gt;
&lt;th&gt;Content&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;lint&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;gofmt -l .&lt;/code&gt; + &lt;code&gt;go vet&lt;/code&gt; (default + corpus tag)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;test&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Ubuntu / Windows / macOS × Go 1.24 / 1.27, &lt;code&gt;CGO_ENABLED=0&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;race&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;go test -race ./...&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;corpus-replay&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;-tags=corpus&lt;/code&gt; replay of public golden samples + &lt;code&gt;ext-0024&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;cross-build&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;js/wasm&lt;/code&gt;, &lt;code&gt;darwin/arm64&lt;/code&gt;, &lt;code&gt;wasip1/wasm&lt;/code&gt;, &lt;code&gt;linux/arm64&lt;/code&gt; (Windows covered by the test matrix)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;coverage-gate&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Per-package thresholds + completeness check&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;perf-smoke&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Benchmarks run, report parses, size lower bound&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Dependency direction is enforced by &lt;code&gt;internal/archlint&lt;/code&gt; within &lt;code&gt;go test&lt;/code&gt;, with no external lint tools introduced, keeping CI with zero extra dependencies.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Principles of quality engineering
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Evidence is reproducible&lt;/strong&gt;: golden samples come with actions, manifests, and logs; not "I ran it locally."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Differences are explainable&lt;/strong&gt;: B1 assertions constrain differences to the declared scope; opaque diffs are not guessed at.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thresholds are executable&lt;/strong&gt;: coverage, cross-build, and corpus replay are all CI assertions, not slogans in documentation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Failures are classifiable&lt;/strong&gt;: error codes, diagnostics, and capability states are all stable strings, convenient for downstream handling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Boundaries are disclosed&lt;/strong&gt;: no rendering, no encrypted writing, no in-place save — state it clearly rather than pretending to support it.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  9. Known limitations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Private &lt;code&gt;ext-*&lt;/code&gt; samples are not distributed with the open source, so they cannot be fully reproduced externally; public golden samples can only serve as a fallback.&lt;/li&gt;
&lt;li&gt;L3 relies on real Windows machines/COM and cannot be fully automated in CI; it relies on scripts + a manual matrix.&lt;/li&gt;
&lt;li&gt;Performance numbers are strongly correlated with hardware and Go version; cross-machine comparison requires fixing the environment first.&lt;/li&gt;
&lt;li&gt;Coverage is not a sufficient condition for quality; the behavioral contract (especially byte fidelity) takes priority.&lt;/li&gt;
&lt;li&gt;What fuzz covers is "no panic / classifiable errors," not "all semantics are correct."&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  10. Summary
&lt;/h2&gt;

&lt;p&gt;The core of quality engineering is not "more tests," but &lt;strong&gt;what the tests can prove&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The corpus proves "real files can be handled";&lt;/li&gt;
&lt;li&gt;Golden samples + B1 prove "the scope of change is controllable";&lt;/li&gt;
&lt;li&gt;The coverage gate proves "new code does not silently regress";&lt;/li&gt;
&lt;li&gt;Fuzz proves "malicious input does not bring down the service";&lt;/li&gt;
&lt;li&gt;L3 proves "clients can open it";&lt;/li&gt;
&lt;li&gt;Performance guardrails prove "optimizations introduce no regressions."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next post is the final one: Architecture Evolution and Cross-Platform Delivery — v2 facade convergence, engine, archlint, the ECMA-376 generation pipeline, the CLI, and WASM.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series navigation&lt;/strong&gt;: &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/08-audit-ir-diff.md" rel="noopener noreferrer"&gt;← Part 8: Read-Only Audit and Semantic Diff&lt;/a&gt; · &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/10-architecture-wasm.md" rel="noopener noreferrer"&gt;Part 10: Architecture Evolution and Cross-Platform Delivery →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>testing</category>
      <category>fuzzing</category>
      <category>cicd</category>
    </item>
    <item>
      <title>Auditing PPTX: Structure, Semantics, and Zero Guesswork</title>
      <dc:creator>jiang jinfeng</dc:creator>
      <pubDate>Sun, 06 Dec 2026 02:04:40 +0000</pubDate>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590/auditing-pptx-structure-semantics-and-zero-guesswork-fp8</link>
      <guid>https://dev.to/jiang_jinfeng_205d3a3d590/auditing-pptx-structure-semantics-and-zero-guesswork-fp8</guid>
      <description>&lt;h1&gt;
  
  
  Auditing PPTX: Structure, Semantics, and Zero Guesswork
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;go-pptx Tech Blog · Part 8: Read-Only Auditing — IR, Semantic Diff, and the Six-Dimensional Capability Manifest&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Series: go-pptx Tech Blog (10 parts)&lt;br&gt;
Baseline: v2.4.4&lt;br&gt;
Keywords: read-only IR, timing IR, weighted LCS, Jaccard, opaque diff, Capability, Validate&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Why "Read-Only" Capabilities Are Needed
&lt;/h2&gt;

&lt;p&gt;Editing is not the only need. In real engineering, people often need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Content extraction&lt;/strong&gt;: extract PPT text/notes/tables and feed them to search, RAG, or review;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Version comparison&lt;/strong&gt;: legal contracts, before/after translation, editing workflows—want to know "what exactly changed";&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pre-deployment capability confirmation&lt;/strong&gt;: can this library handle my file? Which capabilities are limited?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Structural validation&lt;/strong&gt;: check for duplicate shape IDs, dangling relationships, and over-limit resources before release.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These operations should not modify the document, nor should they require callers to parse OOXML themselves. go-pptx's answer is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Read-only IR&lt;/strong&gt; (&lt;code&gt;go-pptx.ir/1.0&lt;/code&gt;): a structured JSON view;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Semantic Diff&lt;/strong&gt; (&lt;code&gt;go-pptx.diff/1.0&lt;/code&gt;): page alignment + shape-level comparison;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Validate&lt;/code&gt;&lt;/strong&gt;: structural diagnostics;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Capability&lt;/code&gt;&lt;/strong&gt;: the six-dimensional capability manifest.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;They share the same core through &lt;code&gt;internal/engine&lt;/code&gt;; the CLI and WASM do not each write their own.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Read-Only IR: Giving a Document a Stable JSON View
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Top-level structure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"schemaVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"go-pptx.ir/1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"sdkVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"v2.4.4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"documentID"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"core"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"creator"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"pages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"index"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"slideID"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;256&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"part"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/ppt/slides/slide1.xml"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Cover"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"shapes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Title 1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"kind"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"autoShape"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"bounds"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"x"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;914400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"y"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;914400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"w"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6096000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"h"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;914400&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="nl"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Q4 Business Analysis"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"notesText"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Hello everyone..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"hasTiming"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"hidden"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"diagnostics"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2.2 Projected content
&lt;/h3&gt;

&lt;p&gt;The current IR covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Document metadata summary (&lt;code&gt;core.xml&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;Page order, &lt;code&gt;SlideID&lt;/code&gt;, name, notes text, hidden state;&lt;/li&gt;
&lt;li&gt;Top-level shapes: ID / Name / Kind / AltText / Decorative / Bounds / WorldBox;&lt;/li&gt;
&lt;li&gt;Charts: type and first Categories group;&lt;/li&gt;
&lt;li&gt;Tables: rows/columns and plain-text concatenation;&lt;/li&gt;
&lt;li&gt;Text boxes/auto shapes: paragraph text;&lt;/li&gt;
&lt;li&gt;Media Part name + ContentType (&lt;strong&gt;binary not embedded&lt;/strong&gt;);&lt;/li&gt;
&lt;li&gt;timing IR (optional).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.3 schemaVersion is independent of the SDK version
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;go-pptx.ir/1.0&lt;/code&gt; has its own version cadence:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding optional fields stays backward compatible;&lt;/li&gt;
&lt;li&gt;Deleting/renaming/changing types must bump &lt;code&gt;schemaVersion&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Callers judge compatibility by schemaVersion, not by library version number.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.4 Read-only constraints
&lt;/h3&gt;

&lt;p&gt;IR cannot be used as input for "PPTX → PPTX default overwrite save". It is used only for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Content extraction;&lt;/li&gt;
&lt;li&gt;Debugging/preview;&lt;/li&gt;
&lt;li&gt;Cross-format adaptation;&lt;/li&gt;
&lt;li&gt;The input view for semantic diff.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the future, if "importing from IR" is needed, it must go through an explicit lossy new-creation interface, rather than "read it out and overwrite everything".&lt;/p&gt;

&lt;h3&gt;
  
  
  2.5 timing IR
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;p:timing&lt;/code&gt; subtree is the core of animation/playback, with complex structure and many vendor extensions. IR projects it as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;PageTiming&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;TimingNode&lt;/code&gt;: Kind (parallel/sequence/cTn/audio/video/cmd/anim/set/opaque);&lt;/li&gt;
&lt;li&gt;Trigger conditions (Begin/End);&lt;/li&gt;
&lt;li&gt;Animation target (Target);&lt;/li&gt;
&lt;li&gt;Unrecognized child elements are output as &lt;code&gt;OpaqueNode&lt;/code&gt; and counted in diagnostics.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The principle is "do not guess, do not omit": recognized structures are structured, unrecognized ones are marked opaque.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Semantic Diff: Why Not Compare by Line/Byte
&lt;/h2&gt;

&lt;p&gt;The differences between two PPTX files may come from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Text changed;&lt;/li&gt;
&lt;li&gt;Shape moved/scaled;&lt;/li&gt;
&lt;li&gt;Page order changed;&lt;/li&gt;
&lt;li&gt;A page deleted, a page added;&lt;/li&gt;
&lt;li&gt;Notes changed;&lt;/li&gt;
&lt;li&gt;Animation timing changed;&lt;/li&gt;
&lt;li&gt;Unknown extensions changed internally.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you diff XML text directly, you get a lot of "tag order/whitespace/namespace" noise; if you crudely compare by position under "page correspondence", you will misjudge "inserting one page" as "every page after it changed".&lt;/p&gt;

&lt;p&gt;go-pptx's approach is &lt;strong&gt;two-level alignment&lt;/strong&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  3.1 Page level: weighted LCS + Jaccard
&lt;/h3&gt;

&lt;p&gt;The rules of &lt;code&gt;pageScore(a, b)&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Both sides have non-zero and equal &lt;code&gt;SlideID&lt;/code&gt; → 1.0 (strong match);&lt;/li&gt;
&lt;li&gt;Both sides have non-zero but unequal &lt;code&gt;SlideID&lt;/code&gt; → 0 (definitely different pages);&lt;/li&gt;
&lt;li&gt;Otherwise, use the Jaccard similarity of the set of shape IDs within the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thresholds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;matchThreshold = 0.5&lt;/code&gt;: treated as "two revisions of the same page" in the ordered LCS;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;orphanThreshold = 0.8&lt;/code&gt;: secondary pairing of leftover pages after ordered alignment (to identify moves/reorders); a higher threshold avoids mismatching "added pages" with "removed pages".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alignment flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use weighted LCS for order-sensitive alignment;&lt;/li&gt;
&lt;li&gt;Do secondary matching for unpaired pages (allowing out-of-order), marking them as moved;&lt;/li&gt;
&lt;li&gt;Still unpaired → page added/page removed;&lt;/li&gt;
&lt;li&gt;Compare aligned pages one by one.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Very large documents (page count product &amp;gt; 1,000,000) degrade to linear alignment of "same SlideID first, the rest by position" to avoid runaway memory/time.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2 Within a page: pair by ShapeID
&lt;/h3&gt;

&lt;p&gt;Within aligned pages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pair by &lt;code&gt;ShapeID&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Compare text, geometry, type, name, alt text, table size, and chart type;&lt;/li&gt;
&lt;li&gt;Recursively handle child shapes within groups;&lt;/li&gt;
&lt;li&gt;Unrecognized/unprojected regions are marked as &lt;strong&gt;opaque diff&lt;/strong&gt;, with &lt;code&gt;Part&lt;/code&gt; + &lt;code&gt;NodePath&lt;/code&gt; given, but internal changes are &lt;strong&gt;not guessed&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.3 Change types
&lt;/h3&gt;

&lt;p&gt;Stable string enums, callers can branch directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.core_changed
page.added / page.removed / page.moved
page.notes_changed / page.timing_changed
shape.added / shape.removed
shape.text_changed / shape.bounds_changed / shape.kind_changed
shape.name_changed / shape.alttext_changed
shape.table_size_changed / shape.chart_type_changed
opaque.diff
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3.4 Report structure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"schemaVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"go-pptx.diff/1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"changed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"stats"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"pagesAdded"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"pagesRemoved"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"pagesMoved"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"pagesChanged"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"textChanges"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"opaqueRegions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"entries"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"kind"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"shape.text_changed"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"pageIndexA"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"pageIndexB"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"shapeID"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"part"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/ppt/slides/slide1.xml"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"nodePath"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"p:sld/p:cSld/p:spTree/p:sp[1]"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"from"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Q3 Revenue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"to"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Q4 Revenue"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"opaque"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"part"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/ppt/slides/slide1.xml"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"nodePath"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"reason"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Chart cache values are not in the IR (only the chart type is projected)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"changed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3.5 Options
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;ir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Diff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithIgnoreGeometry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithIgnoreWhitespace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithIgnoreNotes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ir&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithMaxEntries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;IgnoreGeometry&lt;/code&gt;: compare content only;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;IgnoreWhitespace&lt;/code&gt;: text normalization;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;IgnoreNotes&lt;/code&gt;: ignore notes;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;MaxEntries&lt;/code&gt;: limit the number of report entries; overflow is marked &lt;code&gt;Truncated&lt;/code&gt;, but statistics continue.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Validate: Structural Diagnostics, Not "It Opens So It Passes"
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Validate&lt;/code&gt; performs L0 structural validation and outputs a list of &lt;code&gt;Diagnostic&lt;/code&gt;. Typical diagnostics:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Diagnostic code&lt;/th&gt;
&lt;th&gt;Severity&lt;/th&gt;
&lt;th&gt;Trigger condition&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DRAWING_ID_DUPLICATE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Warning&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;cNvPr@id&lt;/code&gt; duplicated within the same slide spTree&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;OPC_DANGLING_REL&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Depends on context&lt;/td&gt;
&lt;td&gt;Relationship points to a non-existent Part&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Other structural/resource diagnostics&lt;/td&gt;
&lt;td&gt;Info/Warning/Error&lt;/td&gt;
&lt;td&gt;Determined by the specific check&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Design principles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Diagnose by default, do not refuse to open&lt;/strong&gt;: malformed but readable files can still be inspected;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Strict mode is up to the caller&lt;/strong&gt;: refuse after reading &lt;code&gt;ValidationReport&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do not silently discard&lt;/strong&gt;: unknown content is preserved, and problems are presented as diagnostics.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pptx validate deck.pptx
&lt;span class="c"&gt;# Exit code 3 when the error count &amp;gt; 0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  5. Capability: The Six-Dimensional Capability Manifest
&lt;/h2&gt;

&lt;h3&gt;
  
  
  5.1 The six dimensions
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;Current status&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Inspect&lt;/td&gt;
&lt;td&gt;Supported&lt;/td&gt;
&lt;td&gt;Full read-only inspection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Create&lt;/td&gt;
&lt;td&gt;Partial&lt;/td&gt;
&lt;td&gt;Supported features can be created&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Edit&lt;/td&gt;
&lt;td&gt;Partial&lt;/td&gt;
&lt;td&gt;Cross-Run text, tables, media, clone, bind&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Preserve&lt;/td&gt;
&lt;td&gt;Supported&lt;/td&gt;
&lt;td&gt;Byte-level fidelity (B1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Render&lt;/td&gt;
&lt;td&gt;Untested&lt;/td&gt;
&lt;td&gt;Interface landed, implementation not yet planned&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Play&lt;/td&gt;
&lt;td&gt;Partial&lt;/td&gt;
&lt;td&gt;timing read-only + audio narration attachment&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  5.2 Four status levels
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Supported   Core scenarios have been verified in golden samples and tests
Partial     A limited subset has been verified; uncovered paths explicitly error
Unsupported Declared unsupported; callers should degrade/work around it
Untested    Not yet verified on real corpora (default, transparent to callers)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5.3 manifest structure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"schemaVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"go-pptx.capability/1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"sdkVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"v2.4.4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"dimensions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"inspect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Supported"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"limits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"create"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Partial"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="nl"&gt;"notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"limits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"edit"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Partial"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="nl"&gt;"notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"limits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"preserve"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Supported"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"limits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"render"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Untested"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="nl"&gt;"notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"limits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"play"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Partial"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="nl"&gt;"notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"limits"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"features"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"TEXT-02"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"dimension"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"edit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Supported"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"notes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Cross-Run faithful replacement"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5.4 Why this matters
&lt;/h3&gt;

&lt;p&gt;Most libraries only say "supports PPTX". But real projects need to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can it read? Can it write?&lt;/li&gt;
&lt;li&gt;Can it write? Can it preserve fidelity?&lt;/li&gt;
&lt;li&gt;Can it preserve fidelity? Can it play?&lt;/li&gt;
&lt;li&gt;For capabilities it cannot do, does it return an error or silently degrade?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Capability turns the answers to these questions into machine-readable JSON. Running &lt;code&gt;pptx capability&lt;/code&gt; once before deployment is much better than discovering "this chart cannot be modified" only after going live.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. CLI: inspect / diff / export-ir / capability / validate
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Structured inspection&lt;/span&gt;
pptx inspect deck.pptx &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; report.json

&lt;span class="c"&gt;# Semantic diff&lt;/span&gt;
pptx diff --ignore-whitespace old.pptx new.pptx &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; diff.json

&lt;span class="c"&gt;# Export IR&lt;/span&gt;
pptx export-ir --output deck.ir.json deck.pptx

&lt;span class="c"&gt;# Capability manifest&lt;/span&gt;
pptx capability &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; capability.json

&lt;span class="c"&gt;# Structural validation&lt;/span&gt;
pptx validate deck.pptx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exit codes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;0&lt;/code&gt; success;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;1&lt;/code&gt; runtime error;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;2&lt;/code&gt; usage error;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;3&lt;/code&gt; capability/validation error;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;4&lt;/code&gt; resource limit.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  7. Design Trade-offs
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Choice&lt;/th&gt;
&lt;th&gt;Reason&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Does IR embed media&lt;/td&gt;
&lt;td&gt;No, only Part name + type&lt;/td&gt;
&lt;td&gt;IR is a structured view, not a package copy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Can IR be saved back&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Avoids "read it out and overwrite everything" breaking fidelity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Page alignment&lt;/td&gt;
&lt;td&gt;SlideID strong match + Jaccard + LCS&lt;/td&gt;
&lt;td&gt;Distinguishes "same-page revision" from "page deleted + page added"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Out-of-order pages&lt;/td&gt;
&lt;td&gt;High-threshold secondary pairing&lt;/td&gt;
&lt;td&gt;Identifies moves, avoids mismatching additions/deletions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unprojected regions&lt;/td&gt;
&lt;td&gt;opaque diff + Part/NodePath&lt;/td&gt;
&lt;td&gt;Traceable, but does not guess&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Very large documents&lt;/td&gt;
&lt;td&gt;Linear degradation alignment&lt;/td&gt;
&lt;td&gt;Prevents runaway memory/time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Diagnostic strategy&lt;/td&gt;
&lt;td&gt;Record by default, do not refuse to open&lt;/td&gt;
&lt;td&gt;Auditing scenarios need to "read malformed files"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Capability status&lt;/td&gt;
&lt;td&gt;Four levels + six dimensions&lt;/td&gt;
&lt;td&gt;Avoids the binary "supported/unsupported" hiding limitations&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  8. Summary
&lt;/h2&gt;

&lt;p&gt;The core of the read-only auditing chain is "&lt;strong&gt;structured + traceable + no guessing&lt;/strong&gt;":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IR provides a stable JSON view, with the schema versioned independently;&lt;/li&gt;
&lt;li&gt;timing IR structures what it recognizes and marks the rest opaque;&lt;/li&gt;
&lt;li&gt;Diff uses page alignment + shape pairing to distinguish revision/move/add/remove;&lt;/li&gt;
&lt;li&gt;opaque diff gives Part/NodePath but does not fabricate internal changes;&lt;/li&gt;
&lt;li&gt;Capability uses six dimensions and four levels to make "what it can and cannot do" machine-readable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next part moves into quality engineering: how these capabilities are constrained by corpora, golden samples, coverage, fuzz, and a real-device matrix.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series navigation&lt;/strong&gt;: &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/07-template-binding.md" rel="noopener noreferrer"&gt;← Part 7: Template Data Binding&lt;/a&gt; · &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/09-quality-engineering.md" rel="noopener noreferrer"&gt;Part 9: Quality Engineering →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>auditing</category>
      <category>diff</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Template Binding That Never Leaves a Half-Written Deck</title>
      <dc:creator>jiang jinfeng</dc:creator>
      <pubDate>Sun, 06 Dec 2026 02:04:32 +0000</pubDate>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590/template-binding-that-never-leaves-a-half-written-deck-199c</link>
      <guid>https://dev.to/jiang_jinfeng_205d3a3d590/template-binding-that-never-leaves-a-half-written-deck-199c</guid>
      <description>&lt;h1&gt;
  
  
  Template Binding That Never Leaves a Half-Written Deck
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;go-pptx Tech Blog · Part 7: Template Data Binding — Two-Phase plan/apply and "Zero Residue on Failure"&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Series: go-pptx Tech Blog (10 parts)&lt;br&gt;
Baseline: v2.4.4&lt;br&gt;
Keywords: &lt;code&gt;{{path}}&lt;/code&gt;, &lt;code&gt;#if&lt;/code&gt;, &lt;code&gt;#each&lt;/code&gt;, table row looping, chart binding, plan/apply, strict mode&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Scenario: Why Template Binding Is Needed
&lt;/h2&gt;

&lt;p&gt;Batch report generation usually looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Quarterly Report Template.pptx
  ├── Title: {{title}}
  ├── Subtitle: "{{period}} · {{owner}}"
  ├── Conditional paragraph: {{#if netPositive}}Net profit is positive{{/if}}
  ├── Table: {{#each regions}} … {{/each}}
  └── Chart: Revenue trend
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Data comes from a database/JSON, and the goal is to generate hundreds of personalized PPTs. The requirement here is not "being able to replace strings", but:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Placeholders may be split across multiple Runs (template editors often do this);&lt;/li&gt;
&lt;li&gt;Conditional paragraphs must be removable as a whole;&lt;/li&gt;
&lt;li&gt;Table rows must be duplicated according to the number of data entries;&lt;/li&gt;
&lt;li&gt;Charts must be able to bind data;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;If anything fails, no half-corrupted document may be left behind.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;go-pptx's template binding (TPL-01) is designed for this. It builds on two existing capabilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cross-Run faithful replacement (TEXT-02);&lt;/li&gt;
&lt;li&gt;SpanPatch and multi-Part transactions (Parts 2 and 3).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;No second editing path is introduced.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Template Syntax
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Inline placeholder &lt;code&gt;{{path}}&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Dot-separated paths: &lt;code&gt;title&lt;/code&gt;, &lt;code&gt;user.name&lt;/code&gt;, &lt;code&gt;items.0.name&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;May appear in shape body text and in any paragraph of table cells;&lt;/li&gt;
&lt;li&gt;Cross-Run matching is guaranteed by &lt;code&gt;replacePatches&lt;/code&gt;—a placeholder split across multiple Runs can still be matched;&lt;/li&gt;
&lt;li&gt;Strict mode by default: a missing key or a value type that cannot be rendered → &lt;code&gt;ErrInvalidArgument&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.2 Conditional paragraphs &lt;code&gt;{{#if path}} … {{/if}}&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Markers must &lt;strong&gt;occupy a paragraph on their own&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;When the condition is false, delete the markers and all paragraphs within the block;&lt;/li&gt;
&lt;li&gt;Nesting is supported (stack-based evaluation);&lt;/li&gt;
&lt;li&gt;Truthiness rules: &lt;code&gt;nil&lt;/code&gt; / &lt;code&gt;false&lt;/code&gt; / empty string / zero numeric value / empty slice → false; everything else is true.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.3 Table row looping &lt;code&gt;{{#each path}} … {{/each}}&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Markers must be inside cells of the &lt;strong&gt;same table row&lt;/strong&gt; and occupy a paragraph on their own;&lt;/li&gt;
&lt;li&gt;That row serves as the template row and is duplicated according to the number of data entries;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{{field}}&lt;/code&gt; within the block is resolved with the entry as its scope;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;{{.}}&lt;/code&gt; refers to the scalar entry itself;&lt;/li&gt;
&lt;li&gt;When the data is an empty slice, the template row is deleted;&lt;/li&gt;
&lt;li&gt;If the table has only this row, deletion would result in an empty table → rejected (&lt;code&gt;ErrUnsupportedEdit&lt;/code&gt;) to avoid producing an empty table.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.4 Chart data binding
&lt;/h3&gt;

&lt;p&gt;When a value in the data source is &lt;code&gt;pptx.ChartData&lt;/code&gt; and its key equals the chart shape name (&lt;code&gt;p:cNvPr@name&lt;/code&gt;), it is bound:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;any&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Q4 Business Analysis"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"regions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;any&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;any&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"East China"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"revenue"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;120.0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;any&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"South China"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"revenue"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;98.0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"Revenue trend"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartData&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;       &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartBar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Categories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Q1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Q2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Q3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Q4"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Series&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartSeries&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Revenue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;float64&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;135&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;168&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Chart binding goes through &lt;code&gt;ChartShape.SetData&lt;/code&gt; and requires the chart to have a canonical structure (Part 5). The plan phase pre-checks "whether this chart can be written"; if not, it fails before changing any byte.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Two-Phase plan/apply
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 Phase 1: plan (read-only)
&lt;/h3&gt;

&lt;p&gt;The first step of &lt;code&gt;Bind&lt;/code&gt; is to scan the entire document:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scan all pages, shapes, paragraphs, and tables;&lt;/li&gt;
&lt;li&gt;Identify inline placeholders, conditional blocks, and row loops;&lt;/li&gt;
&lt;li&gt;Parse the data source and validate types;&lt;/li&gt;
&lt;li&gt;Pre-check chart writability;&lt;/li&gt;
&lt;li&gt;Build the patch plan.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This phase &lt;strong&gt;does not modify any byte&lt;/strong&gt;. Any semantic error is returned here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Missing key;&lt;/li&gt;
&lt;li&gt;Type mismatch;&lt;/li&gt;
&lt;li&gt;Unpaired conditional/loop markers;&lt;/li&gt;
&lt;li&gt;Row loop nested inside a condition (not supported);&lt;/li&gt;
&lt;li&gt;Chart not canonical;&lt;/li&gt;
&lt;li&gt;Empty table risk.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.2 Phase 2: apply (single transaction)
&lt;/h3&gt;

&lt;p&gt;Once plan passes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Patches are aggregated by Part;&lt;/li&gt;
&lt;li&gt;One &lt;code&gt;ApplyPatches&lt;/code&gt; per Part;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A single commit&lt;/strong&gt; via &lt;code&gt;MultiPartPlan&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;revision is incremented only once;&lt;/li&gt;
&lt;li&gt;Chart binding was pre-checked in the plan phase and is then committed chart by chart.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result is: &lt;strong&gt;either the entire document is rendered according to the data, or it is left completely unchanged.&lt;/strong&gt; There is no intermediate state such as "the title changed, the table did not change, and the chart was half-changed".&lt;/p&gt;

&lt;h3&gt;
  
  
  3.3 Return report
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;BindReport&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Slides&lt;/span&gt;            &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;Placeholders&lt;/span&gt;      &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;Substituted&lt;/span&gt;       &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;RowsGenerated&lt;/span&gt;     &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;RowsRemoved&lt;/span&gt;       &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;ParagraphsRemoved&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;ChartsBound&lt;/span&gt;       &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;Parts&lt;/span&gt;             &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="nc"&gt;Revision&lt;/span&gt;          &lt;span class="kt"&gt;uint64&lt;/span&gt;
    &lt;span class="nc"&gt;Diagnostics&lt;/span&gt;       &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nc"&gt;Diagnostic&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This lets you audit "what this binding actually did", rather than just looking at an &lt;code&gt;error&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Strict Mode and Loose Mode
&lt;/h2&gt;

&lt;p&gt;Default &lt;code&gt;WithBindStrict(true)&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Missing key → &lt;code&gt;ErrInvalidArgument&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Value type cannot be rendered → &lt;code&gt;ErrInvalidArgument&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Unsupported construct → &lt;code&gt;ErrUnsupportedEdit&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Loose mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBindStrict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Unresolved placeholders keep their original text;&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;Warning&lt;/code&gt; diagnostic is recorded;&lt;/li&gt;
&lt;li&gt;Suitable for incremental scenarios where "the template works first and data is filled in later".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But note: loose mode is not "swallow everything". Structural errors (unpaired markers, row loop nested inside a condition, empty table) still fail.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Relationship with Faithful Editing
&lt;/h2&gt;

&lt;p&gt;Template binding does not start a separate "string replacement" path:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inline placeholders reuse &lt;code&gt;replacePatches&lt;/code&gt; (the same path as TEXT-02);&lt;/li&gt;
&lt;li&gt;Paragraph deletion and row duplication reuse &lt;code&gt;xmlstore.SpanPatch&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Multi-Part commits reuse &lt;code&gt;editplan.MultiPartPlan&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;revision semantics are consistent with &lt;code&gt;Save&lt;/code&gt; / &lt;code&gt;Validate&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Placeholders can be matched across Runs;&lt;/li&gt;
&lt;li&gt;Text and formatting that are not matched are preserved;&lt;/li&gt;
&lt;li&gt;Deleting paragraphs/rows deletes only the target bytes;&lt;/li&gt;
&lt;li&gt;There is no partial write on failure;&lt;/li&gt;
&lt;li&gt;Saving still follows the B1 copy + patch path.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  6. CLI Usage
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pptx &lt;span class="nb"&gt;bind&lt;/span&gt; --data data.json --output out.pptx template.pptx
pptx &lt;span class="nb"&gt;bind&lt;/span&gt; --loose --data data.json --output out.pptx template.pptx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;--loose&lt;/code&gt; corresponds to loose mode;&lt;/li&gt;
&lt;li&gt;The output file refuses to overwrite by default (consistent with the library's save semantics);&lt;/li&gt;
&lt;li&gt;Exit codes: &lt;code&gt;0&lt;/code&gt; success, &lt;code&gt;1&lt;/code&gt; runtime error, &lt;code&gt;2&lt;/code&gt; usage error, &lt;code&gt;3&lt;/code&gt; capability/validation error, &lt;code&gt;4&lt;/code&gt; resource limit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A &lt;code&gt;data.json&lt;/code&gt; example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Q4 Business Analysis"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"period"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026 Q4"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"owner"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Strategy Department"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"netPositive"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"regions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"East China"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"revenue"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"South China"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"revenue"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;98&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  7. Design Trade-offs
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Choice&lt;/th&gt;
&lt;th&gt;Reason&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Template syntax&lt;/td&gt;
&lt;td&gt;A Mustache-style subset&lt;/td&gt;
&lt;td&gt;Simple, readable, easy to debug; does not introduce a scripting engine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Condition/loop&lt;/td&gt;
&lt;td&gt;Paragraphs only on their own&lt;/td&gt;
&lt;td&gt;Avoids XML structural ambiguity caused by "half-paragraph conditions"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Row loop markers&lt;/td&gt;
&lt;td&gt;Same table row&lt;/td&gt;
&lt;td&gt;Clear duplication unit; avoids cross-row ambiguity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Empty table&lt;/td&gt;
&lt;td&gt;Reject&lt;/td&gt;
&lt;td&gt;Does not produce "looks successful but unusable" results like an empty table&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Condition nested in a row loop&lt;/td&gt;
&lt;td&gt;Not supported&lt;/td&gt;
&lt;td&gt;High combination complexity; explicitly rejected in the first version&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Missing key&lt;/td&gt;
&lt;td&gt;Strict failure by default&lt;/td&gt;
&lt;td&gt;Silent blanks are more dangerous in batch generation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chart binding&lt;/td&gt;
&lt;td&gt;Canonical charts only&lt;/td&gt;
&lt;td&gt;Non-canonical charts do not support incremental data changes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Atomicity&lt;/td&gt;
&lt;td&gt;plan/apply&lt;/td&gt;
&lt;td&gt;Zero residue on failure is a hard requirement for batch scenarios&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  8. Testing and Fuzz Verification
&lt;/h2&gt;

&lt;p&gt;Template binding is one of the fuzz targets (&lt;code&gt;FuzzBind&lt;/code&gt;). It randomly generates data and template structures and verifies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No panic;&lt;/li&gt;
&lt;li&gt;revision is unchanged on failure;&lt;/li&gt;
&lt;li&gt;The report counts are consistent with the document on success;&lt;/li&gt;
&lt;li&gt;Edge behaviors such as cross-Run placeholders, nested conditions, and empty slices are stable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition, unit tests cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cross-Run placeholders;&lt;/li&gt;
&lt;li&gt;Nested conditions;&lt;/li&gt;
&lt;li&gt;Table row duplication/removal;&lt;/li&gt;
&lt;li&gt;Empty table rejection;&lt;/li&gt;
&lt;li&gt;Chart binding pre-check;&lt;/li&gt;
&lt;li&gt;Loose mode diagnostics.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  9. Summary
&lt;/h2&gt;

&lt;p&gt;The core of template binding is not "being able to replace strings", but:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Declarative&lt;/strong&gt;: write placeholders in the template and provide values in the data;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Faithful&lt;/strong&gt;: reuse cross-Run replacement and SpanPatch without rewriting the entire document;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Atomic&lt;/strong&gt;: plan is pure-read validation, apply is a single transaction, zero residue on failure;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Auditable&lt;/strong&gt;: the report tells you what was changed and what was skipped.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The next part moves into read-only auditing: IR projection, semantic diff, and the six-dimensional capability manifest—that is, "how to let a machine understand a PPT and explain clearly where two PPTs differ".&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series navigation&lt;/strong&gt;: &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/06-media-narration.md" rel="noopener noreferrer"&gt;← Part 6: Media and Auto-Narration&lt;/a&gt; · &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/08-audit-ir-diff.md" rel="noopener noreferrer"&gt;Part 8: Read-Only Auditing and Semantic Diff →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>templates</category>
      <category>json</category>
      <category>automation</category>
    </item>
    <item>
      <title>Auto-Narration Without FFmpeg</title>
      <dc:creator>jiang jinfeng</dc:creator>
      <pubDate>Sun, 06 Dec 2026 01:59:30 +0000</pubDate>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590/auto-narration-without-ffmpeg-2lid</link>
      <guid>https://dev.to/jiang_jinfeng_205d3a3d590/auto-narration-without-ffmpeg-2lid</guid>
      <description>&lt;h1&gt;
  
  
  Auto-Narration Without FFmpeg
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;go-pptx Tech Blog · Part 6: Media, Playback Timing, and Auto-Narration — A Pure Go Approach Without FFmpeg&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Series: go-pptx Tech Blog (10 parts)&lt;br&gt;
Baseline: v2.4.4&lt;br&gt;
Keywords: WAV/MP3/MP4/WebM probing, duration state, media deduplication, playback tree, PlanTimingSync, narrate&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Why "auto-narrating a PPT" needs media probing
&lt;/h2&gt;

&lt;p&gt;The typical pipeline for "auto-narration" products is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Notes/script → TTS generates audio → embed in PPT → set per-page playback/advance duration → present
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key question is: &lt;strong&gt;how long should this page stay?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if the audio duration is unknown, the advance time can't be computed;&lt;/li&gt;
&lt;li&gt;if you call FFmpeg/ffprobe directly, you introduce an external binary dependency;&lt;/li&gt;
&lt;li&gt;if the duration declared by the client can't be trusted, you may produce a presentation that "advances before the audio finishes".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;go-pptx's choice is: &lt;strong&gt;parse common container headers in pure Go to obtain a trustworthy duration or an explicit "unknown" state&lt;/strong&gt;, without calling FFmpeg.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Audio probing: WAV and MP3
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;internal/audioprobe&lt;/code&gt; supports:&lt;/p&gt;

&lt;h3&gt;
  
  
  2.1 RIFF/WAVE (PCM)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;walks the top-level chunk linked list, handling padding bytes;&lt;/li&gt;
&lt;li&gt;reads sample rate, channels, bit depth, and byte rate from the &lt;code&gt;fmt&lt;/code&gt; block;&lt;/li&gt;
&lt;li&gt;when a &lt;code&gt;data&lt;/code&gt; chunk is present, computes duration as &lt;code&gt;ceil(data_bytes / byteRate)&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;when &lt;code&gt;data&lt;/code&gt; is missing, falls back to &lt;code&gt;DurationUnknown&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.2 MPEG 1 Layer III (MP3)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;handles the ID3v2 header (including unsynchronisation + extended header) and the ID3v1 trailer;&lt;/li&gt;
&lt;li&gt;parses the MPEG frame header;&lt;/li&gt;
&lt;li&gt;supports CBR (constant bitrate);&lt;/li&gt;
&lt;li&gt;supports Xing/Info VBR headers;&lt;/li&gt;
&lt;li&gt;supports LAME/VBRI VBR headers;&lt;/li&gt;
&lt;li&gt;the duration source falls back in order: &lt;code&gt;FrameScanned&lt;/code&gt; → &lt;code&gt;HeaderDerived&lt;/code&gt; → &lt;code&gt;DurationUnknown&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.3 Duration state semantics
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;MediaInfo&lt;/code&gt; doesn't simply stuff "duration" into a &lt;code&gt;time.Duration&lt;/code&gt;; it carries a state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;DurationState&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="c1"&gt;// Known / Unknown&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;MediaInfo&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Container&lt;/span&gt;     &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="nc"&gt;Encoding&lt;/span&gt;      &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="nc"&gt;SampleRate&lt;/span&gt;    &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;Channels&lt;/span&gt;      &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;BitsPerSample&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;BitrateKbps&lt;/span&gt;   &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;ByteSize&lt;/span&gt;      &lt;span class="kt"&gt;int64&lt;/span&gt;
    &lt;span class="nc"&gt;Duration&lt;/span&gt;      &lt;span class="nc"&gt;Duration&lt;/span&gt;
    &lt;span class="nc"&gt;State&lt;/span&gt;         &lt;span class="nc"&gt;DurationState&lt;/span&gt;
    &lt;span class="nc"&gt;Origin&lt;/span&gt;        &lt;span class="nc"&gt;Origin&lt;/span&gt; &lt;span class="c1"&gt;// ByteSignature / CallerDeclared / Unknown&lt;/span&gt;
    &lt;span class="nc"&gt;Warnings&lt;/span&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Callers can decide based on this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;State == Known&lt;/code&gt;: use it directly for timing;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;State == Unknown&lt;/code&gt;: either the caller supplies a duration, or return &lt;code&gt;ErrDurationUnknown&lt;/code&gt; — don't guess.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Video probing: MP4 and WebM
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;internal/videoprobe&lt;/code&gt; supports:&lt;/p&gt;

&lt;h3&gt;
  
  
  3.1 ISO BMFF (MP4/MOV)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;identifies &lt;code&gt;ftyp&lt;/code&gt; via the leading &lt;code&gt;box size + type&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;parses &lt;code&gt;major_brand&lt;/code&gt; and &lt;code&gt;compatible_brands&lt;/code&gt; (allowlist, collection cap of 64 to prevent amplification attacks);&lt;/li&gt;
&lt;li&gt;does not parse the full box tree to derive duration (that would introduce FFmpeg/MediaInfo-level complexity);&lt;/li&gt;
&lt;li&gt;duration uniformly returns &lt;code&gt;DurationUnknown&lt;/code&gt;, to be supplied or rejected by the caller as needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.2 WebM/Matroska
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;identifies via the EBML header signature &lt;code&gt;0x1A45DFA3&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;the version segment and &lt;code&gt;Duration&lt;/code&gt; element involve VINT parsing; currently simplified to "signature present + container known + duration unknown".&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.3 Why video duration isn't derived
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;MP4 duration requires parsing &lt;code&gt;moov&lt;/code&gt; / &lt;code&gt;mvex&lt;/code&gt; / track headers, with many edge cases;&lt;/li&gt;
&lt;li&gt;WebM's Duration is VINT-encoded and may be missing;&lt;/li&gt;
&lt;li&gt;for presentations, "container identification + byte deduplication + relationship allocation + &lt;code&gt;p:videoFile&lt;/code&gt; fragment generation" is already the core value;&lt;/li&gt;
&lt;li&gt;the duration can be supplied by the caller, or accepted as "unknown".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is an explicit trade-off: &lt;strong&gt;don't introduce an external media toolchain for a single field.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Media embedding: deduplication, relationships, and content types
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.1 Content-hash deduplication
&lt;/h3&gt;

&lt;p&gt;Images/audio/video are deduplicated by content SHA-256:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the same content creates only one media Part;&lt;/li&gt;
&lt;li&gt;different shapes reuse the same Part;&lt;/li&gt;
&lt;li&gt;hash results are cached per revision, avoiding recomputation across all media on every traversal (V2.0.1 fixed the O(N²)).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4.2 Done in a single transaction
&lt;/h3&gt;

&lt;p&gt;Embedding media isn't just writing a file; it also needs to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;add a media Part;&lt;/li&gt;
&lt;li&gt;add/modify the slide relationship (&lt;code&gt;r:embed&lt;/code&gt; / &lt;code&gt;r:link&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;add/modify the content type;&lt;/li&gt;
&lt;li&gt;write the shape fragment (&lt;code&gt;p:pic&lt;/code&gt; / &lt;code&gt;p:audio&lt;/code&gt; / &lt;code&gt;p:videoFile&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;possibly write &lt;code&gt;docProps/audio.xml&lt;/code&gt; / &lt;code&gt;video.xml&lt;/code&gt; metadata.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of these are committed in a single &lt;code&gt;MultiPartPlan&lt;/code&gt;, with zero residue on failure.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.3 Default position of audio shapes
&lt;/h3&gt;

&lt;p&gt;When &lt;code&gt;AudioSpec&lt;/code&gt;'s position is all zeros:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;default size 1in × 1in;&lt;/li&gt;
&lt;li&gt;positioned at the bottom-right corner of the page (0.25in from the right/bottom edges).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This matches PowerPoint's habit when inserting audio, avoiding "invisible 0×0 shapes" or covering the body text.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Playback tree and timing plan
&lt;/h2&gt;

&lt;h3&gt;
  
  
  5.1 Audio roles
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;AudioRole&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;AudioRoleNarration&lt;/span&gt;  &lt;span class="nc"&gt;AudioRole&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;iota&lt;/span&gt; &lt;span class="c1"&gt;// narration track, participates in advance-time computation&lt;/span&gt;
    &lt;span class="nc"&gt;AudioRoleBackground&lt;/span&gt;                   &lt;span class="c1"&gt;// background audio, does not participate&lt;/span&gt;
    &lt;span class="nc"&gt;AudioRoleEffect&lt;/span&gt;                       &lt;span class="c1"&gt;// sound effect, does not participate&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only finite tracks that are &lt;code&gt;Narration&lt;/code&gt; with &lt;code&gt;Trigger = OnSlideEnter&lt;/code&gt; participate in advance-time computation; background audio, loops, and click-triggered audio do not participate.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.2 Advance formula
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AdvanceAfter = max(end time of all participating tracks) + TailPadding
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;PlanTimingSync&lt;/code&gt; outputs a &lt;code&gt;TimingPlan&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;BaseRevision&lt;/code&gt;: the revision the plan is based on;&lt;/li&gt;
&lt;li&gt;each page's &lt;code&gt;AdvanceAfter&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;the participating tracks and their computation basis;&lt;/li&gt;
&lt;li&gt;unknown durations fail the entire batch by default (&lt;code&gt;ErrDurationUnknown&lt;/code&gt;), unless skipping is explicitly chosen.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5.3 ApplyTimingPlan: atomic commit
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PlanTimingSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TimingSyncOptions&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;TailPadding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Millisecond&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ApplyTimingPlan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ErrConcurrentModification&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// the document was modified after the plan was generated; re-plan&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ApplyTimingPlan&lt;/code&gt; will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;verify &lt;code&gt;plan.BaseRevision == p.Revision()&lt;/code&gt;, returning &lt;code&gt;ErrConcurrentModification&lt;/code&gt; on mismatch;&lt;/li&gt;
&lt;li&gt;write &lt;code&gt;p:transition@advTm&lt;/code&gt; per page;&lt;/li&gt;
&lt;li&gt;if any page fails, the entire batch is not committed.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5.4 SetPlayback: restricted rebuild
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;AudioShape.SetPlayback&lt;/code&gt; supports:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Trigger&lt;/code&gt;: auto-play on slide entry / play on click;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;StartDelay&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;IconMode&lt;/code&gt;: icon visible / hidden during presentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the page has an existing timing subtree that can't be safely merged (non-pure-audio structures such as animations/video), it returns &lt;code&gt;ErrTimingConflict&lt;/code&gt; and modifies no original node. This is the "reject rather than break animations" choice.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. CLI: narrate and timing-plan
&lt;/h2&gt;

&lt;h3&gt;
  
  
  6.1 &lt;code&gt;pptx narrate&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Embeds audio from a &lt;code&gt;tracks.json&lt;/code&gt; manifest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pptx narrate --manifest tracks.json --output narrated.pptx deck.pptx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The manifest roughly describes each page's audio file, role, track key, etc. The CLI calls the library's embedding path and writes the result to the output file.&lt;/p&gt;

&lt;h3&gt;
  
  
  6.2 &lt;code&gt;pptx timing-plan&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Read-only preview of the timing plan:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pptx timing-plan --tail-padding 500ms deck.pptx
pptx timing-plan --strict deck.pptx   &lt;span class="c"&gt;# fail directly on unknown durations&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output includes each page's advance time, participating tracks, and computation basis. It is read-only, convenient for checking before the real write.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Resource limits and failure model
&lt;/h2&gt;

&lt;p&gt;Media is the part of a PPTX that most easily "grows large", so budget constraints matter:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Limit&lt;/th&gt;
&lt;th&gt;Default&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MaxMediaBytes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;512 MiB&lt;/td&gt;
&lt;td&gt;decompressed limit for a single media Part&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MaxXMLBytes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;32 MiB&lt;/td&gt;
&lt;td&gt;limit for a single XML Part&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MaxTotalBytes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1 GiB&lt;/td&gt;
&lt;td&gt;declared size + actual cumulative bytes read&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MaxEntries&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;10,000&lt;/td&gt;
&lt;td&gt;total number of ZIP entries&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Failure model:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;unknown duration: &lt;code&gt;ErrDurationUnknown&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;unable to safely merge timing: &lt;code&gt;ErrTimingConflict&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;media over budget: &lt;code&gt;ErrLimitExceeded&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;unsupported container: the prober returns &lt;code&gt;MediaInfo{}&lt;/code&gt;, and the upper layer decides to reject;&lt;/li&gt;
&lt;li&gt;unsupported edit: &lt;code&gt;ErrUnsupportedEdit&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These errors are all classifiable, not "a single generic failure".&lt;/p&gt;




&lt;h2&gt;
  
  
  8. A complete auto-narration example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"deck.pptx"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;slides&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Slides&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;slides&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;audio&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddAudio&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FileMedia&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"voice/%02d.mp3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AudioSpec&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;TrackKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"page-%02d"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AudioRoleNarration&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="c1"&gt;// omit Duration: derived by probe; returns ErrDurationUnknown when it can't be derived&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="c1"&gt;// ErrDurationUnknown / ErrUnsupportedEdit&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;audio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetPlayback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PlaybackSpec&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Trigger&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PlaybackOnSlideEnter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PlanTimingSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TimingSyncOptions&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;TailPadding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Millisecond&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ApplyTimingPlan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"narrated.pptx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaveOverwrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  9. Boundaries and trade-offs
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Item&lt;/th&gt;
&lt;th&gt;Current choice&lt;/th&gt;
&lt;th&gt;Reason&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Audio duration&lt;/td&gt;
&lt;td&gt;pure Go parsing for WAV/MP3&lt;/td&gt;
&lt;td&gt;common formats, parsing is controllable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Video duration&lt;/td&gt;
&lt;td&gt;usually unknown&lt;/td&gt;
&lt;td&gt;full parsing is costly; the caller can supply it&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;FFmpeg&lt;/td&gt;
&lt;td&gt;no dependency&lt;/td&gt;
&lt;td&gt;keeps a single binary, zero external runtime&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Extended containers&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;MediaProbe&lt;/code&gt; interface reserved&lt;/td&gt;
&lt;td&gt;users can inject FLAC/AAC/OGG/MKV, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Playback controls&lt;/td&gt;
&lt;td&gt;restricted fields only&lt;/td&gt;
&lt;td&gt;complex animation/control writing is left for later&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Timing merge&lt;/td&gt;
&lt;td&gt;reject when unsafe&lt;/td&gt;
&lt;td&gt;don't break the existing animation tree&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Icon/poster frame&lt;/td&gt;
&lt;td&gt;restricted expression&lt;/td&gt;
&lt;td&gt;implemented in a form PowerPoint accepts&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  10. Summary
&lt;/h2&gt;

&lt;p&gt;The key to media and auto-narration is not "being able to embed a file", but &lt;strong&gt;the consistency of duration, playback, and advance&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;pure Go probing gives "a trustworthy duration or an explicit unknown";&lt;/li&gt;
&lt;li&gt;content-hash deduplication avoids duplicate media;&lt;/li&gt;
&lt;li&gt;multi-Part transactions guarantee complete relationships/content types;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PlanTimingSync&lt;/code&gt; computes the plan first, &lt;code&gt;ApplyTimingPlan&lt;/code&gt; commits atomically;&lt;/li&gt;
&lt;li&gt;unsafe structures are explicitly rejected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next part moves on to template data binding: how to map JSON data to text, conditional paragraphs, table rows, and charts, while guaranteeing zero residue on failure.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series navigation&lt;/strong&gt;: &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/05-charts.md" rel="noopener noreferrer"&gt;← Part 5: The Chart Subsystem&lt;/a&gt; · &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/07-template-binding.md" rel="noopener noreferrer"&gt;Part 7: Template Data Binding →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>audio</category>
      <category>media</category>
      <category>opensource</category>
    </item>
    <item>
      <title>A Chart Is Four Systems in a Trench Coat</title>
      <dc:creator>jiang jinfeng</dc:creator>
      <pubDate>Sun, 06 Dec 2026 01:59:19 +0000</pubDate>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590/a-chart-is-four-systems-in-a-trench-coat-50ab</link>
      <guid>https://dev.to/jiang_jinfeng_205d3a3d590/a-chart-is-four-systems-in-a-trench-coat-50ab</guid>
      <description>&lt;h1&gt;
  
  
  A Chart Is Four Systems in a Trench Coat
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;go-pptx Tech Blog · Part 5: The Chart Subsystem — From Restricted Types to Combo Charts and Embedded Workbooks&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Series: go-pptx Tech Blog (10 parts)&lt;br&gt;
Baseline: v2.4.4&lt;br&gt;
Keywords: ChartML, embedded workbook, combo charts, secondary axis, series labels, canonical validation, client compatibility&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Why charts are much harder than "drawing a bar"
&lt;/h2&gt;

&lt;p&gt;A PPT chart involves at least four layers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Chart XML&lt;/strong&gt; (&lt;code&gt;c:chartSpace&lt;/code&gt;): chart type, series, axes, legend, labels, styles;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Embedded workbook&lt;/strong&gt; (xlsx Part): the chart's "data source", which PowerPoint reads when you open "Edit Data";&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cached data&lt;/strong&gt; (&lt;code&gt;c:strCache&lt;/code&gt; / &lt;code&gt;c:numCache&lt;/code&gt;): lets the chart display without opening the workbook;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Relationships and content types&lt;/strong&gt;: the slide → chart → workbook rels chain and &lt;code&gt;[Content_Types].xml&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These four layers must stay consistent. Change only the chart XML and not the workbook, and "Edit Data" in PowerPoint will show stale values; change only the cache and not the formula references, and clients may display inconsistently; if the workbook's sheet name, column order, or series order don't match, the chart will be misaligned.&lt;/p&gt;

&lt;p&gt;So go-pptx's chart implementation is not "stitching together a chunk of XML"; it treats a chart as a &lt;strong&gt;restricted subsystem with an explicit contract&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;ChartSpec&lt;/code&gt; (type, categories, series, position, axis options, labels, styles);&lt;/li&gt;
&lt;li&gt;Output: chart Part + embedded xlsx + slide relationships + content types;&lt;/li&gt;
&lt;li&gt;Validation: run canonical validation after building; reject non-canonical structures in &lt;code&gt;SetData&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Compatibility: tighten the allowlist according to what PowerPoint / WPS / LibreOffice actually accept.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Supported chart types
&lt;/h2&gt;

&lt;p&gt;There are currently 9 supported types:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;&lt;code&gt;ChartType&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;Main elements&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Bar chart&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ChartBar&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;barChart&lt;/code&gt; + catAx/valAx&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Line chart&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ChartLine&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;lineChart&lt;/code&gt; + catAx/valAx&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pie chart&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ChartPie&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;pieChart&lt;/code&gt;, no axes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Doughnut chart&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ChartDoughnut&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;doughnutChart&lt;/code&gt;, &lt;code&gt;holeSize=50&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Area chart&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ChartArea&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;areaChart&lt;/code&gt; + catAx/valAx&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Radar chart&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ChartRadar&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;radarChart&lt;/code&gt; (marker)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3D bar chart&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ChartBar3D&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;bar3DChart&lt;/code&gt; + &lt;code&gt;view3D&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scatter chart&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ChartScatter&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;scatterChart&lt;/code&gt; + xVal/yVal + two valAx&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bubble chart&lt;/td&gt;
&lt;td&gt;&lt;code&gt;ChartBubble&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;bubbleChart&lt;/code&gt; + xVal/yVal/bubbleSize&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;All these types go through the same &lt;code&gt;internal/chart&lt;/code&gt; build/parse/validate/workbook-sync path. Adding a type is not "copy-pasting a builder"; it means updating in sync:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;types.go&lt;/code&gt;: the type enum and &lt;code&gt;PlotElement()&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;build.go&lt;/code&gt;: chart groups, axes, series references;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;parse.go&lt;/code&gt;: read-back;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;canonical.go&lt;/code&gt;: allowlist validation;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;workbook.go&lt;/code&gt;: column layout (categories/X values, series values, bubble sizes);&lt;/li&gt;
&lt;li&gt;tests and client re-save verification.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Build flow: from &lt;code&gt;ChartSpec&lt;/code&gt; to chart Part + xlsx
&lt;/h2&gt;

&lt;p&gt;A typical bar + line combo chart:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartSpec&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;       &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartBar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="s2"&gt;"Quarterly Revenue and Growth Rate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Categories&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Q1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Q2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Q3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Q4"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Series&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartSeries&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Revenue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;float64&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;135&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;168&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;LineSeries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartSeries&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Growth Rate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;float64&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;12.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;11.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;SecondaryAxis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// the line uses the secondary axis&lt;/span&gt;
    &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;914400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;914400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6096000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3429000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;slide&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddChart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;spec&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Internally, it roughly does the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Allocate chart Part names&lt;/strong&gt; (e.g. &lt;code&gt;/ppt/charts/chart1.xml&lt;/code&gt;) and workbook Part names;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build the chartSpace XML&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;c:chart&lt;/code&gt; → &lt;code&gt;c:plotArea&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;primary &lt;code&gt;barChart&lt;/code&gt; + overlay &lt;code&gt;lineChart&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;shared axis or secondary axis (&lt;code&gt;SecondaryAxis&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;c:ser&lt;/code&gt;'s &lt;code&gt;c:tx&lt;/code&gt; / &lt;code&gt;c:cat&lt;/code&gt; / &lt;code&gt;c:val&lt;/code&gt; references;&lt;/li&gt;
&lt;li&gt;title, legend, labels, styles, axis options;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build the embedded xlsx&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;[Content_Types].xml&lt;/code&gt;, &lt;code&gt;_rels/.rels&lt;/code&gt;, &lt;code&gt;xl/workbook.xml&lt;/code&gt;, &lt;code&gt;xl/worksheets/sheet1.xml&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;row 1 for series names, rows 2..n+1 for categories + values;&lt;/li&gt;
&lt;li&gt;for scatter/bubble charts, column A holds X values; bubble charts additionally write a size column;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Establish relationships&lt;/strong&gt;: slide → chart, chart → workbook, chart → embedded object;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Commit as a single multi-Part transaction.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The workbook's column layout must strictly match the formula references in the chart XML. For example, the primary series starts at column B, and overlay series follow right after; if the series order changes, the column references must change too. &lt;code&gt;BuildChartSpaceXML&lt;/code&gt; writes column references using a &lt;code&gt;series offset&lt;/code&gt; to avoid misalignment.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Combo charts and secondary axes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.1 Bar + line
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nc"&gt;ChartSpec&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;       &lt;span class="nc"&gt;ChartBar&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Series&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nc"&gt;ChartSeries&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Revenue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;LineSeries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nc"&gt;ChartSeries&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Growth Rate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;plotArea&lt;/code&gt; writes &lt;code&gt;barChart&lt;/code&gt; + &lt;code&gt;lineChart&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;shares two &lt;code&gt;axId&lt;/code&gt;s;&lt;/li&gt;
&lt;li&gt;axes are written only once;&lt;/li&gt;
&lt;li&gt;workbook columns: categories in A, primary series in B.., overlay series right after.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4.2 Bar + line + secondary axis
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nc"&gt;SecondaryAxis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;the secondary axis IDs are fixed to &lt;code&gt;catAxID+2&lt;/code&gt; / &lt;code&gt;valAxID+2&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;lineChart&lt;/code&gt; uses the secondary &lt;code&gt;axId&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;plotArea&lt;/code&gt; adds a hidden secondary category axis (&lt;code&gt;delete=1&lt;/code&gt;) and a right-side secondary value axis (&lt;code&gt;axPos="r"&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;on read-back, &lt;code&gt;SecondaryAxis&lt;/code&gt; is inferred from the number of &lt;code&gt;valAx&lt;/code&gt; elements.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4.3 Bar + area, area + line
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ChartSpec/ChartData.AreaSeries&lt;/code&gt;: bar primary + area overlay (can coexist with line);&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ChartArea&lt;/code&gt; supports a &lt;code&gt;LineSeries&lt;/code&gt; overlay;&lt;/li&gt;
&lt;li&gt;canonical allows up to 3 plots (bar + line/area);&lt;/li&gt;
&lt;li&gt;the secondary axis flag also applies to area overlays.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4.4 Secondary-axis series
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;SecondaryLineSeries&lt;/code&gt;: a secondary-axis line layer on a line chart;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SecondaryBarSeries&lt;/code&gt;: a secondary-axis bar layer on a bar chart.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These capabilities were added batch by batch, and each batch updated build / parse / canonical / workbook in sync and performed client re-save verification.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Expressiveness of series and axes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  5.1 Series-level data labels
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nc"&gt;ChartSeries&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="s2"&gt;"Revenue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;float64&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;135&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;168&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;DataLabel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartDataLabel&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Show&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;     &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ctr"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// tightened per chart type&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The position allowlist is not "write whatever you like":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;bar / line / line overlay / secondary bar overlay: empty or &lt;code&gt;ctr&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;area / pie / doughnut / radar / bar3D / area overlay: empty only.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The reason is that PowerPoint will &lt;strong&gt;reject the entire package&lt;/strong&gt; for inapplicable positions. For example, using &lt;code&gt;outB&lt;/code&gt; for bar, &lt;code&gt;ctr&lt;/code&gt; for area, or &lt;code&gt;ctr&lt;/code&gt; for pie/radar/bar3D can all make the file fail to open. go-pptx chooses to "tighten according to client acceptance" rather than "accept every parameter and leave it to luck whether it breaks".&lt;/p&gt;

&lt;h3&gt;
  
  
  5.2 Series styles
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nc"&gt;ChartSeries&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Revenue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Style&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartSeriesStyle&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Fill&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartColor&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;RGB&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2E75B6"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Line&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartColor&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;RGB&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"1F4E79"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;LineWidth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;12700&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Writes &lt;code&gt;c:ser/c:spPr&lt;/code&gt;, supporting solid fills and lines; colors can be sRGB or theme colors.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.3 Series markers
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nc"&gt;ChartSeries&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Growth Rate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Marker&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartMarker&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"circle"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Fill&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartColor&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;RGB&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2E75B6"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only effective for line / scatter / bubble series; symbol supports circle/square/diamond/triangle/x/star/dot/plus/dash/none/auto.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.4 Axis gridlines and number formats
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="nc"&gt;Axes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartAxisOptions&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;ValueNumberFormat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="s2"&gt;"0.0%"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;CategoryNumberFormat&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"General"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;ValueMajorGridlines&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartGridlines&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Line&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ChartColor&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="no"&gt;RGB&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"D9D9D9"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;6350&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Writes &lt;code&gt;c:valAx/c:majorGridlines&lt;/code&gt;, the &lt;code&gt;numFmt&lt;/code&gt; of &lt;code&gt;c:categoryAx&lt;/code&gt;, and so on. Number formats matter especially for financial reports: formats like &lt;code&gt;0.0%&lt;/code&gt;, &lt;code&gt;#,##0&lt;/code&gt;, &lt;code&gt;¥#,##0&lt;/code&gt; directly determine the reading experience.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Canonical validation: why only "canonical layouts" are accepted
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;internal/chart/canonical.go&lt;/code&gt; defines a strict allowlist. &lt;code&gt;SetData&lt;/code&gt; rejects non-canonical chart Parts because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;charts rewritten by external tools/clients may contain many extensions this library doesn't understand (&lt;code&gt;spPr&lt;/code&gt;, &lt;code&gt;dLbls&lt;/code&gt;, &lt;code&gt;trendline&lt;/code&gt;, complex layouts);&lt;/li&gt;
&lt;li&gt;"partial merging" easily produces semantic inconsistency (data changed, styles not changed, cache not changed);&lt;/li&gt;
&lt;li&gt;rather than guess, it rejects, and lets the caller take the "rebuild the chart" or "keep it as-is" path.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The canonical check covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;c:chartSpace&lt;/code&gt; may only contain &lt;code&gt;c:chart&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;the allowlist and counts of &lt;code&gt;c:chart&lt;/code&gt;'s child elements;&lt;/li&gt;
&lt;li&gt;the chart groups, axis counts, and combination legality of &lt;code&gt;plotArea&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;the child element order and allowed items of &lt;code&gt;c:ser&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;the subtrees of legend, title, and view3D;&lt;/li&gt;
&lt;li&gt;the allowlists for extensions such as axes, labels, and styles.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The cost is: &lt;strong&gt;non-canonical charts can only be read, not incrementally updated&lt;/strong&gt;. This is an intentional boundary — the precondition for faithful editing is "I know what I'm changing".&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Read-back and two-model conversion
&lt;/h2&gt;

&lt;p&gt;v2.4.4 adds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nc"&gt;ChartDataFromSpec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="nc"&gt;ChartSpec&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;ChartData&lt;/span&gt;
&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="nc"&gt;ChartSpecFromData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="nc"&gt;ChartData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="kt"&gt;int64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;ChartSpec&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Uses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;read &lt;code&gt;ChartData&lt;/code&gt; back from an existing chart, then convert it to &lt;code&gt;ChartSpec&lt;/code&gt; for "copy/reconfigure";&lt;/li&gt;
&lt;li&gt;slices are copied, nested pointers are shared (avoiding deep-copy cost).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The read-back path handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;primary chart type and overlays;&lt;/li&gt;
&lt;li&gt;categories, series values, X values, bubble sizes;&lt;/li&gt;
&lt;li&gt;title/rich-text Runs;&lt;/li&gt;
&lt;li&gt;legend, labels, styles, markers, gridlines, number formats;&lt;/li&gt;
&lt;li&gt;the secondary axis flag;&lt;/li&gt;
&lt;li&gt;the embedded workbook's sheet name and column references.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  8. Performance: single traversal and combo paths
&lt;/h2&gt;

&lt;p&gt;Chart parsing once had an obvious performance problem: multiple repeated scans of &lt;code&gt;plotArea&lt;/code&gt;. v2.4.4 changes it to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;first collect the chart groups of &lt;code&gt;plotArea&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;then dispatch overlays by primary chart type;&lt;/li&gt;
&lt;li&gt;complete in a single traversal.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Combo-shape path generation also changed from "repeated concatenation at each layer" to a &lt;code&gt;[]string&lt;/code&gt; segment stack that concatenates only once when generating the &lt;code&gt;NodePath&lt;/code&gt;, eliminating the O(depth²) allocations of deep combinations.&lt;/p&gt;

&lt;p&gt;These optimizations don't change semantics, but make large-document / deep-combination / many-chart scenarios more stable.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. Compatibility and verification
&lt;/h2&gt;

&lt;p&gt;Chart client compatibility is more sensitive than ordinary text because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PowerPoint is very strict about element order, required child elements, and enum values;&lt;/li&gt;
&lt;li&gt;WPS has its own tolerance;&lt;/li&gt;
&lt;li&gt;LibreOffice's rendering/re-save behavior is different again.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The project's verification approach is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;unit tests: build → parse → rebuild round-trips;&lt;/li&gt;
&lt;li&gt;canonical tests: illegal combinations must be rejected;&lt;/li&gt;
&lt;li&gt;workbook tests: column layout and references stay consistent;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;client re-save&lt;/strong&gt;: open in PowerPoint 16 / WPS 12 / LibreOffice 24.2, re-save, then re-verify;&lt;/li&gt;
&lt;li&gt;a 13-page comprehensive sample covering combo charts, labels, styles, markers, gridlines, and number formats.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Known limitations are written into the docs rather than hidden. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;series label positions are more fully verified only for bar/line; other types support only the default position;&lt;/li&gt;
&lt;li&gt;the secondary axis is fixed on the right and the category axis is hidden; clients may rearrange axes;&lt;/li&gt;
&lt;li&gt;legend order may be adjusted by the client;&lt;/li&gt;
&lt;li&gt;non-canonical charts don't support incremental &lt;code&gt;SetData&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  10. Summary
&lt;/h2&gt;

&lt;p&gt;The core of the chart subsystem is not "how many chart types it supports", but &lt;strong&gt;four-layer consistency&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;the chart XML structure is correct;&lt;/li&gt;
&lt;li&gt;the embedded workbook's column layout matches the formula references;&lt;/li&gt;
&lt;li&gt;the cached data matches the workbook;&lt;/li&gt;
&lt;li&gt;relationships/content types are complete, and clients can open and re-save.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;go-pptx uses "restricted types + canonical allowlist + client re-save verification" to guarantee these four layers. It doesn't aim for "any chart can be edited", but for "charts we support, clients accept them after editing".&lt;/p&gt;

&lt;p&gt;The next part moves on to media and auto-narration: without installing FFmpeg, how to probe audio/video in pure Go and wire them into playback timing.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series navigation&lt;/strong&gt;: &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/04-object-model-handles-text.md" rel="noopener noreferrer"&gt;← Part 4: Object Model and Handles&lt;/a&gt; · &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/06-media-narration.md" rel="noopener noreferrer"&gt;Part 6: Media and Auto-Narration →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>charts</category>
      <category>ooxml</category>
      <category>data</category>
    </item>
    <item>
      <title>Text Edits That Survive Real PowerPoint Files</title>
      <dc:creator>jiang jinfeng</dc:creator>
      <pubDate>Sun, 06 Dec 2026 01:52:40 +0000</pubDate>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590/text-edits-that-survive-real-powerpoint-files-48jb</link>
      <guid>https://dev.to/jiang_jinfeng_205d3a3d590/text-edits-that-survive-real-powerpoint-files-48jb</guid>
      <description>&lt;h1&gt;
  
  
  Text Edits That Survive Real PowerPoint Files
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;go-pptx Tech Blog · Part 4: Object Model, Cross-Run Text Replacement, and Handle Lifecycle&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Series: go-pptx Tech Blog (10 parts)&lt;br&gt;
Baseline: v2.4.4&lt;br&gt;
Keywords: TextFrame / Paragraph / Run, cross-Run replacement, grapheme cluster, &lt;code&gt;cNvPr@id&lt;/code&gt;, STALE-GUARD, monotonic ID allocation&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Object Model: Strictly Aligned with the DrawingML Hierarchy
&lt;/h2&gt;

&lt;p&gt;go-pptx's public object model is not "designed off the top of one's head"; it aligns with the OOXML PresentationML / DrawingML hierarchy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Presentation (Root)
└── Slide 1..N
    └── Shape
        ├── GroupShape / AutoShape (including the TextShape alias) / OpaqueShape
        ├── PictureShape / TableShape / ChartShape
        ├── AudioShape / VideoShape
        └── TextFrame
            └── Paragraph 1..N
                └── TextRun 1..N
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The benefit of this hierarchy is that the object relationships callers see correspond almost one-to-one with the structure in the XML. You do not need to first learn a "library-specific document model" and then guess how it maps to OOXML.&lt;/p&gt;

&lt;p&gt;But once an object model introduces "handles", it must answer a question that every long-running editor faces: &lt;strong&gt;when do handles become stale?&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Handle Identity: Reusing Stable IDs That Already Exist in OOXML
&lt;/h2&gt;

&lt;p&gt;go-pptx does not maintain a separate "object ID table". It reuses the stable identities that already exist in OOXML:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Handle layer&lt;/th&gt;
&lt;th&gt;Stable identity&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Shape&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;cNvPr@id&lt;/code&gt; (DrawingML requires it to be globally unique within an spTree)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;TextFrame&lt;/code&gt; / &lt;code&gt;Paragraph&lt;/code&gt; / &lt;code&gt;TextRun&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;shapeHint = the &lt;code&gt;cNvPr@id&lt;/code&gt; of the owning shape&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;Cell&lt;/code&gt; (table)&lt;/td&gt;
&lt;td&gt;shapeHint = the &lt;code&gt;cNvPr@id&lt;/code&gt; of the &lt;code&gt;graphicFrame&lt;/code&gt; of the owning table&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;NodePath&lt;/code&gt; serves only as a parent-container hint for "which spTree / grpSp to search under", not as identity. The resolution flow is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;resolve the parent container by path;&lt;/li&gt;
&lt;li&gt;search among child elements by &lt;code&gt;cNvPr@id&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;compare the &lt;code&gt;cNvPr@id&lt;/code&gt; of the nearest ancestor with the hint recorded in the handle;&lt;/li&gt;
&lt;li&gt;not found or mismatched → &lt;code&gt;ErrStaleHandle&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This has one fewer source of truth than "building your own ID table", and it avoids the classic bug of "the XML changed but the ID table was not synced".&lt;/p&gt;

&lt;h3&gt;
  
  
  2.1 Which Operations Invalidate a Handle?
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th&gt;Handle state&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MoveShape&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Still valid (&lt;code&gt;cNvPr@id&lt;/code&gt; unchanged)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Adding a shape at a sibling position&lt;/td&gt;
&lt;td&gt;Still valid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Text editing&lt;/td&gt;
&lt;td&gt;Still valid&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;RemoveShape&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The target &lt;code&gt;cNvPr@id&lt;/code&gt; disappears → &lt;code&gt;ErrStaleHandle&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Child shapes after grouping&lt;/td&gt;
&lt;td&gt;Old handle is invalidated (grouping changes the hierarchy path; re-fetch required)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Close&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Business methods return &lt;code&gt;ErrClosed&lt;/code&gt;; handle reads may return &lt;code&gt;ErrStaleHandle&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  2.2 Monotonic ID Allocator: Avoiding the ABA Trap
&lt;/h3&gt;

&lt;p&gt;Here is an easily overlooked bug:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If the allocator takes "the current &lt;code&gt;max(id)+1&lt;/code&gt; within the spTree", then after deleting the shape with the largest id, a newly added shape will &lt;strong&gt;reuse the same id&lt;/strong&gt;. When an old handle locates by id lazily, it will "resurrect" from the first matching element and return the geometry/text of the wrong shape instead of &lt;code&gt;ErrStaleHandle&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since v2.0.2, the allocator has been changed to be &lt;strong&gt;monotonically increasing and never reusing&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;maxShapeIDValue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4294967295&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nc"&gt;Presentation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;allocShapeID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maxShapeID&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;maxShapeIDValue&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ErrOutOfRange&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maxShapeID&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maxShapeID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In addition, after &lt;code&gt;New&lt;/code&gt; / &lt;code&gt;Open&lt;/code&gt; / &lt;code&gt;OpenReader&lt;/code&gt;, it scans the spTree of every slide in the whole document and takes the global maximum of the existing &lt;code&gt;cNvPr@id&lt;/code&gt; as the initial upper bound (&lt;code&gt;seedShapeIDAlloc&lt;/code&gt;). This way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;appending across sessions does not fall back;&lt;/li&gt;
&lt;li&gt;deleting a shape does not make the allocator regress;&lt;/li&gt;
&lt;li&gt;locating an old handle fails with &lt;code&gt;ErrStaleHandle&lt;/code&gt;, and &lt;strong&gt;does not silently point to a new shape because the id was reused&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;OOXML allows &lt;code&gt;cNvPr@id&lt;/code&gt; to skip within its range; monotonic allocation does not violate the spec.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Cross-Run Text Replacement: Why Not Just &lt;code&gt;strings.Replace&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;PPT text is not one big string; it is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;TextFrame
└── Paragraph
    ├── Run 1: "Q3 revenue"
    ├── Run 2: "year-over-year"
    └── Run 3: "12%"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each Run can have its own font, color, size, and hyperlink. What the user sees as "Q3 revenue year-over-year 12%" is the logical concatenation of these Runs.&lt;/p&gt;

&lt;p&gt;If you apply &lt;code&gt;strings.Replace&lt;/code&gt; directly to the &lt;code&gt;&amp;lt;a:t&amp;gt;&lt;/code&gt; of some Run, you will run into:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the target string crossing Runs: it cannot be found within a single Run;&lt;/li&gt;
&lt;li&gt;formatting lost after replacement: the new text inherits the wrong Run's formatting;&lt;/li&gt;
&lt;li&gt;splitting grapheme clusters: cutting an emoji or combining character in half;&lt;/li&gt;
&lt;li&gt;breaking field/line-break/hyperlink boundaries: a match crossing &lt;code&gt;a:br&lt;/code&gt;, &lt;code&gt;a:fld&lt;/code&gt;, or Runs with different links.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rules of &lt;code&gt;pptx.TextFrame.ReplaceText&lt;/code&gt; / &lt;code&gt;Paragraph.ReplaceText&lt;/code&gt; are explicit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;case-sensitive, literal matching, left to right, non-overlapping, based on an initial text snapshot, replacement results not processed recursively&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;an empty old returns &lt;code&gt;ErrInvalidArgument&lt;/code&gt;&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;matches do not cross &lt;code&gt;a:br&lt;/code&gt; / &lt;code&gt;a:fld&lt;/code&gt;&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;matches do not cross adjacent Runs with "different hyperlinks/actions"&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;match boundaries must not split combining characters or ZWJ sequences&lt;/strong&gt;; violating hits are skipped and recorded as diagnostics;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;replacement containing a line break (U+000A) is rejected in the first version&lt;/strong&gt; (express it with the paragraph API).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.1 Three Formatting Strategies
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;ReplaceMode&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c1"&gt;// default: replacement inherits the explicit formatting of the Run containing the first matched character&lt;/span&gt;
    &lt;span class="nc"&gt;ReplaceFirstCharacter&lt;/span&gt; &lt;span class="nc"&gt;ReplaceMode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;iota&lt;/span&gt;
    &lt;span class="c1"&gt;// old and replacement must have the same number of runes; each Run keeps its own formatting&lt;/span&gt;
    &lt;span class="nc"&gt;ReplaceEqualLengthPerRune&lt;/span&gt;
    &lt;span class="c1"&gt;// the caller provides formatting via WithReplacementStyle&lt;/span&gt;
    &lt;span class="nc"&gt;ReplaceExplicitStyle&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TextFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReplaceText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Q3"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Q4"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"matches=%d replaced=%d skipped=%d\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Matches&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Replaced&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Skipped&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ReplaceResult&lt;/code&gt; does not just tell you "success/failure"; it also gives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Matches&lt;/code&gt;: the total number of matches on the initial snapshot;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Replaced&lt;/code&gt;: the number actually completed;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Skipped&lt;/code&gt;: the number skipped due to boundary/safety rules;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Hits&lt;/code&gt;: the range of each hit, whether it was replaced, and the skip reason.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Skip reasons are stable strings, for example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;grapheme-cluster-boundary&lt;/code&gt;: the match splits a combining character/ZWJ;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;unsafe-link-or-extension-run&lt;/code&gt;: a Run within the covered range contains semantic child elements such as hyperlinks/extensions;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;adjacent-match-run-conflict&lt;/code&gt;: adjacent hits share a Run and cannot be expressed independently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is more honest than "all replacements succeeded": some positions simply cannot be replaced safely, and the library tells you why.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2 Minimal Patch Planning Across Runs
&lt;/h3&gt;

&lt;p&gt;The internal implementation (&lt;code&gt;internal/textmap&lt;/code&gt;) does three things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;rune mapping&lt;/strong&gt;: index Run text by rune rather than by byte;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;span location&lt;/strong&gt;: map &lt;code&gt;[start,end)&lt;/code&gt; of the logical text to the first/last Run and its internal offset;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;grapheme safety&lt;/strong&gt;: check whether a match boundary falls inside a combining character or ZWJ sequence.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Then the replacement plan is greedily scheduled by "occupied Run interval":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multiple in-place text changes in the same Run are merged into a single &lt;code&gt;&amp;lt;a:t&amp;gt;&lt;/code&gt; content replacement;&lt;/li&gt;
&lt;li&gt;for hits that need Run splitting, the formatting strategy decides the &lt;code&gt;rPr&lt;/code&gt; of the new Run;&lt;/li&gt;
&lt;li&gt;all patches are validated as a whole first, then applied in one pass via &lt;code&gt;ApplyPatches&lt;/code&gt; + &lt;code&gt;SinglePartPatch&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result: &lt;strong&gt;the preceding and following content and formatting of non-hits are fully preserved; a hit's replacement changes only the necessary interval.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3.3 Paragraphs/Fields/Plain Text
&lt;/h3&gt;

&lt;p&gt;Besides &lt;code&gt;ReplaceText&lt;/code&gt;, there are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;SetPlainText&lt;/code&gt;: for template batch-replacement scenarios, bypassing the rich-text structure;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Paragraph.AppendField&lt;/code&gt; / &lt;code&gt;InsertField&lt;/code&gt; / &lt;code&gt;Fields&lt;/code&gt; / &lt;code&gt;Remove&lt;/code&gt; / &lt;code&gt;SetText&lt;/code&gt;: support the &lt;code&gt;slidenum&lt;/code&gt; / &lt;code&gt;datetime&lt;/code&gt; whitelisted fields;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Paragraph.Text()&lt;/code&gt;: concatenates ordinary Run text with field cached text, as a logical text view.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Fields and line breaks are hard boundaries, and this must be consistent in match planning; otherwise "the text you see" and "the range you can replace" will not line up.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. A Complete Text Editing Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"template.pptx"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;slides&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Slides&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;shapes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;slides&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Shapes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;shapes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TextFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReplaceText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{{customer}}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"East China Region Customer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithReplaceMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReplaceFirstCharacter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Skipped&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="k"&gt;range&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Hits&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Replaced&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"skip [%d,%d): %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StartRune&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EndRune&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Reason&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// field: page number&lt;/span&gt;
&lt;span class="n"&gt;para&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddParagraph&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ParagraphSpec&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;para&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AppendField&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FieldSpec&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FieldSlideNumber&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"out.pptx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaveOverwrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  5. Observability of Handle Invalidation
&lt;/h2&gt;

&lt;p&gt;go-pptx's error model is "explicit failure", not "return a zero value and let you guess":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;after a shape is deleted, the old &lt;code&gt;Shape.Bounds()&lt;/code&gt; returns &lt;code&gt;ErrStaleHandle&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;after a slide is deleted, &lt;code&gt;SpeakerNotesText()&lt;/code&gt; on the old &lt;code&gt;Slide&lt;/code&gt; handle returns &lt;code&gt;ErrStaleHandle&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;after &lt;code&gt;Close&lt;/code&gt;, business methods return &lt;code&gt;ErrClosed&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Close()&lt;/code&gt; itself is idempotent: repeated calls return &lt;code&gt;nil&lt;/code&gt;, compatible with &lt;code&gt;defer p.Close()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This looks "verbose", but it is very important for long-running services: you can see in the logs that "a handle that has already been deleted is used here", rather than getting a coordinate that looks normal but actually belongs to another shape.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Design Trade-offs
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Choice&lt;/th&gt;
&lt;th&gt;Cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Handle identity&lt;/td&gt;
&lt;td&gt;Reuse &lt;code&gt;cNvPr@id&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Depends on OOXML's "unique within spTree" premise; malformed files may have duplicate IDs, and &lt;code&gt;Validate&lt;/code&gt; reports &lt;code&gt;DRAWING_ID_DUPLICATE&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ID after deletion&lt;/td&gt;
&lt;td&gt;Monotonically increasing, no reuse&lt;/td&gt;
&lt;td&gt;IDs grow larger, but ABA is avoided; nearing the uint32 limit returns &lt;code&gt;ErrOutOfRange&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Replacement range&lt;/td&gt;
&lt;td&gt;Does not cross br/fld/links&lt;/td&gt;
&lt;td&gt;Some text that "looks continuous" cannot be replaced at once and needs segmented handling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Grapheme safety&lt;/td&gt;
&lt;td&gt;Skip anything that splits&lt;/td&gt;
&lt;td&gt;A few boundary scenarios require the caller to express it differently&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Line breaks&lt;/td&gt;
&lt;td&gt;First version rejects a replacement containing &lt;code&gt;\n&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;Express it explicitly with the paragraph API, avoiding implicit structural changes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Formatting strategy&lt;/td&gt;
&lt;td&gt;Three fixed modes&lt;/td&gt;
&lt;td&gt;No arbitrary "map formatting by character" scripting capability&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  7. Summary
&lt;/h2&gt;

&lt;p&gt;The core of the object model layer is two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Text editing must be faithful&lt;/strong&gt;: cross-Run matching, minimal patching, grapheme safety, explicable boundaries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Handles must fail safely&lt;/strong&gt;: reuse OOXML identity, monotonic IDs, explicit &lt;code&gt;ErrStaleHandle&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The next part moves into the chart subsystem: a chart is not just drawing a bar; it simultaneously involves chart XML, embedded workbooks, cached data, and client compatibility.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series navigation&lt;/strong&gt;: &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/03-opc-transaction-atomic-save.md" rel="noopener noreferrer"&gt;← Part 3: OPC and Transactions&lt;/a&gt; · &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/05-charts.md" rel="noopener noreferrer"&gt;Part 5: Chart Subsystem →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>ooxml</category>
      <category>textprocessing</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Saving a PPTX Should Feel Like a Database Transaction</title>
      <dc:creator>jiang jinfeng</dc:creator>
      <pubDate>Sun, 06 Dec 2026 01:47:48 +0000</pubDate>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590/saving-a-pptx-should-feel-like-a-database-transaction-5cj4</link>
      <guid>https://dev.to/jiang_jinfeng_205d3a3d590/saving-a-pptx-should-feel-like-a-database-transaction-5cj4</guid>
      <description>&lt;h1&gt;
  
  
  Saving a PPTX Should Feel Like a Database Transaction
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;go-pptx Tech Blog · Part 3: OPC Container, Transactional Editing, and Atomic Save&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Series: go-pptx Tech Blog (10 parts)&lt;br&gt;
Baseline: v2.4.4&lt;br&gt;
Keywords: OPC, ZIP lazy indexing, resource budget, ChangeSet, SavePlan, revision, atomic flush to disk&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. A PPTX is Essentially an OPC Package
&lt;/h2&gt;

&lt;p&gt;A PPTX file is not "an XML file" but a collection of Parts inside a ZIP container (OPC, Open Packaging Conventions):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;presentation.pptx
├── [Content_Types].xml        # content type for each extension/Part
├── _rels/.rels                # package-level relationships: officeDocument → ppt/presentation.xml
├── ppt/
│   ├── presentation.xml       # slide list
│   ├── _rels/presentation.xml.rels
│   ├── slides/slide1.xml      # spTree for each slide
│   ├── slideLayouts/...
│   ├── slideMasters/...
│   ├── theme/theme1.xml
│   ├── media/image1.png
│   ├── charts/chart1.xml
│   └── embeddings/...
└── docProps/
    ├── core.xml
    ├── app.xml
    └── custom.xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A single "change a word" operation actually has to handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;byte patches to the target XML Part;&lt;/li&gt;
&lt;li&gt;possibly newly added media Parts (images/audio/video);&lt;/li&gt;
&lt;li&gt;content types for new Parts (&lt;code&gt;[Content_Types].xml&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;newly added/modified relationships (&lt;code&gt;_rels/*.rels&lt;/code&gt;);&lt;/li&gt;
&lt;li&gt;deleting relationships when a Part is removed;&lt;/li&gt;
&lt;li&gt;finally producing a new ZIP.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If these steps are not atomic, you end up with broken packages such as "a relationship points to a nonexistent Part", "a content type is missing", or "duplicate ZIP entries". go-pptx solves this with a three-layer mechanism: &lt;strong&gt;lazy indexing + resource budget&lt;/strong&gt;, &lt;strong&gt;ChangeSet/SavePlan&lt;/strong&gt;, and &lt;strong&gt;transactions + atomic flush to disk&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Open: Lazy Indexing and a Budget for Untrusted Input
&lt;/h2&gt;

&lt;h3&gt;
  
  
  2.1 Only the Central Directory and a Lightweight Index
&lt;/h3&gt;

&lt;p&gt;When &lt;code&gt;internal/opc&lt;/code&gt; opens a file, it does not immediately decompress every Part:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it parses the ZIP central directory and builds an entry index;&lt;/li&gt;
&lt;li&gt;it parses &lt;code&gt;[Content_Types].xml&lt;/code&gt; and the relationship streams;&lt;/li&gt;
&lt;li&gt;media bytes are read lazily on demand;&lt;/li&gt;
&lt;li&gt;an XML Part is parsed into &lt;code&gt;xmlstore.XMLDocument&lt;/code&gt; only when accessed, and cached by revision.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This matters for large files: a 100-slide presentation with 20 large images should not load every image into memory on open.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.2 Budget: Setting Limits on Untrusted Input
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;Budget&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;MaxEntries&lt;/span&gt;    &lt;span class="kt"&gt;int&lt;/span&gt;   &lt;span class="c1"&gt;// total number of ZIP entries&lt;/span&gt;
    &lt;span class="nc"&gt;MaxXMLBytes&lt;/span&gt;   &lt;span class="kt"&gt;int64&lt;/span&gt; &lt;span class="c1"&gt;// decompressed limit for a single XML Part (default 32 MiB)&lt;/span&gt;
    &lt;span class="nc"&gt;MaxMediaBytes&lt;/span&gt; &lt;span class="kt"&gt;int64&lt;/span&gt; &lt;span class="c1"&gt;// limit for a single media Part (default 512 MiB)&lt;/span&gt;
    &lt;span class="nc"&gt;MaxTotalBytes&lt;/span&gt; &lt;span class="kt"&gt;int64&lt;/span&gt; &lt;span class="c1"&gt;// limit on declared size and actual cumulative bytes read (default 1 GiB)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Default values (&lt;code&gt;DefaultBudget()&lt;/code&gt;):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Default&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MaxEntries&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;10,000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MaxXMLBytes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;32 MiB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MaxMediaBytes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;512 MiB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;MaxTotalBytes&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1 GiB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A few design details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;0 does not mean unlimited&lt;/strong&gt;: unconfigured fields fall back to defaults; to tighten, explicitly give a positive value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Actual bytes read are also constrained&lt;/strong&gt;: since v2.4.4, &lt;code&gt;MaxTotalBytes&lt;/code&gt; constrains both the ZIP declared size and the actual cumulative decompressed bytes read; exceeding it returns &lt;code&gt;ErrLimitExceeded&lt;/code&gt; rather than waiting for an OOM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Depth limits are not in Budget&lt;/strong&gt;: XML nesting depth is handled by the parsing side (xmlstore defaults to 256 levels), avoiding a fake knob that "is set but has no effect".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Malicious packages do not panic&lt;/strong&gt;: the three entry points &lt;code&gt;Open&lt;/code&gt; / &lt;code&gt;OpenReader&lt;/code&gt; / &lt;code&gt;New&lt;/code&gt; all return explicit errors.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Editing: ChangeSet and SavePlan
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 ChangeSet: The Set of Changes for One Save
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;ChangeSet&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Patched&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;PartName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;
    &lt;span class="nc"&gt;Added&lt;/span&gt;   &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;PartName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nc"&gt;AddedPart&lt;/span&gt;
    &lt;span class="nc"&gt;Deleted&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;PartName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It only describes "what the output should become relative to the current package"; it does not care how the ZIP is written. Key rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a Part in &lt;code&gt;Patched&lt;/code&gt; must already exist;&lt;/li&gt;
&lt;li&gt;a Part in &lt;code&gt;Added&lt;/code&gt; must not exist, and must have a determinable content type;&lt;/li&gt;
&lt;li&gt;a Part in &lt;code&gt;Deleted&lt;/code&gt; must already exist;&lt;/li&gt;
&lt;li&gt;the same Part cannot appear in mutually exclusive sets at the same time;&lt;/li&gt;
&lt;li&gt;deleting a Part automatically removes its relationship stream as well (relationships are meaningless once detached from their source Part).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.2 SavePlan: A Determined List of Output Entries
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;BuildSavePlan&lt;/code&gt; turns a ChangeSet into &lt;code&gt;[]PlannedEntry&lt;/code&gt;, where each entry has one of four actions:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Action&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Byte source&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CopyOriginal&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Unmodified&lt;/td&gt;
&lt;td&gt;Decompressed content of the original ZIP entry, copied as-is (B1)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;EmitPatched&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Modified&lt;/td&gt;
&lt;td&gt;New bytes provided by the change set&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;EmitNew&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Newly created&lt;/td&gt;
&lt;td&gt;New bytes provided by the change set&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Omit&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Deleted&lt;/td&gt;
&lt;td&gt;Does not appear in the output&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Output entries are sorted by Part name, guaranteeing &lt;strong&gt;determinism&lt;/strong&gt;. The package structure generated from the same change set is stable, which helps comparison and reproduction.&lt;/p&gt;

&lt;p&gt;A SavePlan also carries two kinds of diagnostics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Blocking errors&lt;/strong&gt;: invalid Part names, patching/deleting a nonexistent Part, creating an already-existing Part, undeterminable content type;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-blocking diagnostics&lt;/strong&gt;: for example, dangling relationships, recorded in &lt;code&gt;Diagnostics&lt;/code&gt;, with the caller deciding whether to accept them.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.3 Content Types and Relationships Generated from a Single Source
&lt;/h3&gt;

&lt;p&gt;A common source of broken packages is "a Part was added but its content type was forgotten". SavePlan's strategy is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a newly added Part must provide a &lt;code&gt;ContentType&lt;/code&gt;, or its extension must already be covered by a &lt;code&gt;Default&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;otherwise the plan fails outright (&lt;code&gt;ErrPlanInvalid&lt;/code&gt;); producing an untyped Part is not allowed;&lt;/li&gt;
&lt;li&gt;relationship streams are generated from the same source as the change set, and relationships are handled together when a Part is deleted.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is not "one extra step" but rather blocking "broken packages" before the save happens.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Transactions: SinglePartPatch and MultiPartPlan
&lt;/h2&gt;

&lt;h3&gt;
  
  
  4.1 Single-Part Editing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;plan&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;editplan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NewSinglePartPatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;partName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;store&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// StagePatch + Commit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suitable for operations that change only one XML Part, such as text replacement or shape property modification.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.2 Multi-Part Editing
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;plan&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;editplan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NewMultiPartPlan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;editplan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;slidePart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newSlideXML&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;editplan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mediaPart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;imageBytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"image/png"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;editplan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;contentTypesPart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newCT&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;editplan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;relsPart&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newRels&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nf"&gt;applyMultiPartPlan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pres&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;plan&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A multi-Part operation must be a single transaction:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if any &lt;code&gt;Stage*&lt;/code&gt; fails, the whole plan fails;&lt;/li&gt;
&lt;li&gt;on failure, &lt;code&gt;pending&lt;/code&gt; is restored, leaving no half-committed state;&lt;/li&gt;
&lt;li&gt;on success, a single &lt;code&gt;Commit&lt;/code&gt; happens, and revision is incremented only once.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This solves the intermediate-state problem of "the image was added halfway, the relationship was added, but the content type was not".&lt;/p&gt;

&lt;h3&gt;
  
  
  4.3 revision: Detecting Concurrent Modification
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Presentation&lt;/code&gt; maintains a monotonically increasing revision:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;+1 on every successful commit;&lt;/li&gt;
&lt;li&gt;parse caches and media hash caches are invalidated wholesale with the revision;&lt;/li&gt;
&lt;li&gt;the save plan is based on a snapshot of a certain revision;&lt;/li&gt;
&lt;li&gt;if the document is modified again after the plan is generated, &lt;code&gt;p.rev != rev&lt;/code&gt; and the save returns &lt;code&gt;ErrConcurrentModification&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This makes a race between "read snapshot → build plan → save" detectable, instead of silently saving a mixed state.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Saving: Atomic Flush to Disk, Not "Delete Old and Write New"
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Save&lt;/code&gt; flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;target check
  → temporary file in the same directory
  → write ZIP
  → (optional) fsync the file
  → Close
  → output validation (ZIP opens, entry set matches the plan)
  → atomic replace of the target
  → (optional) fsync the directory
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5.1 Overwrite Denied by Default
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;target exists and overwrite is not explicitly allowed → &lt;code&gt;ErrOutputExists&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;overwriting must be explicitly enabled with &lt;code&gt;WithSaveOverwrite(true)&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;overwriting still uses atomic replace and does not degrade into "delete the old file first, then write the new file".&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  5.2 Saving In Place Over the Source File Is Rejected
&lt;/h3&gt;

&lt;p&gt;The current version &lt;strong&gt;does not support in-place saving&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sameSourceEntity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ErrInvalidArgument&lt;/span&gt; &lt;span class="c1"&gt;// please choose a new output path&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reason is that the source file is still being read lazily; safe in-place replacement would require handling source handle lifetimes, temporary packages, and rollback semantics. This limitation is an explicit rejection, not "silently writing something broken".&lt;/p&gt;

&lt;h3&gt;
  
  
  5.3 Durability: Durability Levels
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Level&lt;/th&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DurabilityDefault&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Guarantees error handling and atomic visibility, but does not promise power-loss durability&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;DurabilityFull&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Additionally performs file fsync and (on supported platforms) directory fsync&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  5.4 Failure Recovery
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;any failure before commit: the temporary file is deleted, and the old target remains unchanged;&lt;/li&gt;
&lt;li&gt;cleanup failure: the error is attached with &lt;code&gt;errors.Join&lt;/code&gt; so the primary error is not masked;&lt;/li&gt;
&lt;li&gt;atomic replace unavailable: returns &lt;code&gt;ErrAtomicReplaceUnavailable&lt;/code&gt;, and the old target is preserved;&lt;/li&gt;
&lt;li&gt;output validation failure: the target is not replaced, avoiding a broken package.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This set of semantics is much like a database transaction: &lt;strong&gt;you either see the old version or the complete new version, never half a package.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Deterministic Saving and raw Pass-Through
&lt;/h2&gt;

&lt;h3&gt;
  
  
  6.1 Deterministic Output
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;SaveOptions.Deterministic&lt;/code&gt; can pin metadata such as timestamps, so that the same input produces the same output. This is useful for CI golden files, content addressing, and caching.&lt;/p&gt;

&lt;h3&gt;
  
  
  6.2 raw Pass-Through
&lt;/h3&gt;

&lt;p&gt;Unmodified media Parts can use raw pass-through: copy the compressed bytes directly from the original ZIP instead of decompressing and recompressing. Since v2.4.4, entries with a data descriptor (Flags bit3) are supported: CRC/size is taken from the central directory, and the actual compressed byte count is re-checked after copying.&lt;/p&gt;

&lt;p&gt;Exclusions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;encrypted frames;&lt;/li&gt;
&lt;li&gt;exotic compression methods;&lt;/li&gt;
&lt;li&gt;XML / rels (these need to be readable and modifiable).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the actual compressed byte count does not match after copying, the entire save fails rather than silently producing a broken package.&lt;/p&gt;

&lt;h3&gt;
  
  
  6.3 Save Statistics
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;SaveReport&lt;/code&gt; provides the write distribution:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;SaveReport&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;RawParts&lt;/span&gt;      &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="c1"&gt;// raw pass-through&lt;/span&gt;
    &lt;span class="nc"&gt;StreamedParts&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="c1"&gt;// streamed copy&lt;/span&gt;
    &lt;span class="nc"&gt;PatchedParts&lt;/span&gt;  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="c1"&gt;// patch write&lt;/span&gt;
    &lt;span class="nc"&gt;NewParts&lt;/span&gt;      &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="c1"&gt;// newly added&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This lets callers observe "how much this save actually changed", and also helps with performance tuning.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. A Complete Edit-Save Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"template.pptx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBudget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Budget&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;MaxEntries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;    &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;MaxTotalBytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;256&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;defer&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;slides&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Slides&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;shapes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;slides&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Shapes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;shapes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TextFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ReplaceText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"{{title}}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Q4 Business Review"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"out.pptx"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaveOverwrite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaveDurability&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pptx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DurabilityFull&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ErrOutputExists / ErrConcurrentModification / ErrLimitExceeded ...&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"revision=%d patched=%d new=%d raw=%d\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Revision&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PatchedParts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NewParts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;RawParts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What actually happens behind this code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;on open, only the index is built; not all media is read;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ReplaceText&lt;/code&gt; generates a minimal SpanPatch via xmlstore;&lt;/li&gt;
&lt;li&gt;one transaction is committed, revision +1;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Save&lt;/code&gt; builds a SavePlan based on the current revision;&lt;/li&gt;
&lt;li&gt;unmodified Parts go through &lt;code&gt;CopyOriginal&lt;/code&gt;, modified Parts go through &lt;code&gt;EmitPatched&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;the temporary file is written, validated, and atomically replaced.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  8. Boundaries and Trade-offs
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Item&lt;/th&gt;
&lt;th&gt;Current choice&lt;/th&gt;
&lt;th&gt;Reason&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;In-place save&lt;/td&gt;
&lt;td&gt;Rejected&lt;/td&gt;
&lt;td&gt;Source file is read lazily; safe replacement and rollback are not yet fully closed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Overwrite by default&lt;/td&gt;
&lt;td&gt;Rejected&lt;/td&gt;
&lt;td&gt;Prevents accidental overwrite; explicit &lt;code&gt;WithSaveOverwrite&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Large media&lt;/td&gt;
&lt;td&gt;Lazy read + raw pass-through&lt;/td&gt;
&lt;td&gt;Avoids full decompression; unmodified media is not decompressed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Resource limits&lt;/td&gt;
&lt;td&gt;Configurable via Budget&lt;/td&gt;
&lt;td&gt;Server-side processing of untrusted files must be controllable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Save failure&lt;/td&gt;
&lt;td&gt;Old target preserved&lt;/td&gt;
&lt;td&gt;No half-finished product&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Missing content type&lt;/td&gt;
&lt;td&gt;Fails at plan time&lt;/td&gt;
&lt;td&gt;Producing an untyped Part is not allowed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dangling relationships&lt;/td&gt;
&lt;td&gt;Diagnostic (non-blocking)&lt;/td&gt;
&lt;td&gt;Some real samples have historical leftovers; report first, then decide&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  9. Summary
&lt;/h2&gt;

&lt;p&gt;The core of the OPC layer is not "being able to read and write ZIP" but turning &lt;strong&gt;package-level consistency&lt;/strong&gt; into verifiable constraints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;open: lazy indexing + budget, so malicious input cannot bring down the service;&lt;/li&gt;
&lt;li&gt;edit: ChangeSet describes intent, SavePlan generates deterministic output;&lt;/li&gt;
&lt;li&gt;transaction: single/multi-Part plans, zero residue on failure;&lt;/li&gt;
&lt;li&gt;concurrency: revision snapshots, detecting modifications during planning;&lt;/li&gt;
&lt;li&gt;save: temporary file + validation + atomic replace, so the old target is never harmed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next part moves into the object model layer: how handles become stale, how cross-Run text is replaced faithfully, and why shape IDs must be monotonically increasing.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series navigation&lt;/strong&gt;: &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/02-byte-fidelity-xmlstore.md" rel="noopener noreferrer"&gt;← Part 2: Byte-Level Fidelity&lt;/a&gt; · &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/04-object-model-handles-text.md" rel="noopener noreferrer"&gt;Part 4: Object Model, Cross-Run Text, and Handle Lifecycle →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>zip</category>
      <category>opc</category>
      <category>transactions</category>
    </item>
    <item>
      <title>Edit One Run, Leave the Other 99% Untouched</title>
      <dc:creator>jiang jinfeng</dc:creator>
      <pubDate>Sun, 06 Dec 2026 01:42:55 +0000</pubDate>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590/edit-one-run-leave-the-other-99-untouched-1fal</link>
      <guid>https://dev.to/jiang_jinfeng_205d3a3d590/edit-one-run-leave-the-other-99-untouched-1fal</guid>
      <description>&lt;h1&gt;
  
  
  Edit One Run, Leave the Other 99% Untouched
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;go-pptx Tech Blog · Part 2: Byte-level Fidelity — xmlstore and the SpanPatch Engine&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Series: go-pptx Tech Blog (10 parts)&lt;br&gt;
Baseline: v2.4.4&lt;br&gt;
Keywords: XML scanner, namespace scope, node index, SpanPatch, B1 invariant&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. The Problem: Why "Read Out and Write Back" Damages Documents
&lt;/h2&gt;

&lt;p&gt;The edit path of most PPTX libraries is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Parse XML → modify the object tree → re-serialize the entire Part → write back to ZIP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This path is fine for "generating from scratch," but dangerous for "processing existing documents":&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Unknown extensions are dropped&lt;/strong&gt;: OOXML allows vendor extensions (&lt;code&gt;p14:&lt;/code&gt;, &lt;code&gt;p15:&lt;/code&gt;, &lt;code&gt;mc:AlternateContent&lt;/code&gt;, WPS private nodes). The object tree doesn't recognize them, and they easily vanish on re-serialization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lexical details are rewritten&lt;/strong&gt;: attribute order, namespace prefixes, self-closing form, whitespace, and entity spelling may all change. Semantically the same, but byte-wise different, affecting downstream signatures, comparisons, and audits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unrelated regions are dragged in&lt;/strong&gt;: changing only one Run re-lays-out the entire page's XML, expanding the difference from a few bytes to the whole page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Concurrent modifications are hard to detect&lt;/strong&gt;: you read first, then construct a new document, then write everything back; you don't know if the source document was modified in between.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;go-pptx's choice is: &lt;strong&gt;treat raw bytes as the invariant and patch only the target region.&lt;/strong&gt; The foundation of this mechanism is &lt;code&gt;internal/xmlstore&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The Four Components of xmlstore
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;internal/xmlstore&lt;/code&gt; is not a general-purpose XML editor, but "a minimal XML storage layer serving fidelity editing." It does four things:&lt;/p&gt;

&lt;h3&gt;
  
  
  2.1 Namespace-aware Lexical Scanner
&lt;/h3&gt;

&lt;p&gt;The scanner outputs tokens with &lt;strong&gt;raw byte spans&lt;/strong&gt;, covering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start tags / end tags / text / comments / CDATA / PI / DOCTYPE;&lt;/li&gt;
&lt;li&gt;Attribute names, attribute values, in-quote ranges;&lt;/li&gt;
&lt;li&gt;Namespace declarations &lt;code&gt;xmlns&lt;/code&gt; / &lt;code&gt;xmlns:p&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;Close validation, mismatch detection;&lt;/li&gt;
&lt;li&gt;Direct refusal of non-UTF-8 (&lt;code&gt;ErrEncoding&lt;/code&gt;), because a reliable byte mapping cannot be established.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Key point: &lt;strong&gt;do not use regex to locate XML, and do not &lt;code&gt;Unmarshal&lt;/code&gt; the entire Part into a struct then &lt;code&gt;Marshal&lt;/code&gt; it.&lt;/strong&gt; For unknown elements, build nodes as usual and preserve the raw bytes.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.2 Namespace Scope
&lt;/h3&gt;

&lt;p&gt;Each element node holds an immutable &lt;code&gt;NamespaceScope&lt;/code&gt;, which stores the &lt;code&gt;xmlns&lt;/code&gt; bindings it declares and chains to the parent scope:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;NamespaceScope&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;parent&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nc"&gt;NamespaceScope&lt;/span&gt;
    &lt;span class="n"&gt;decls&lt;/span&gt;  &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="c1"&gt;// "" means the default namespace&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When identifying elements, use &lt;strong&gt;URI + local name&lt;/strong&gt;, never guess semantics from the prefix. Because prefixes can be bound arbitrarily, only the URI is a stable identity. Upper layers can ask:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What URI does this prefix resolve to in the current scope?&lt;/li&gt;
&lt;li&gt;Does the target URI already have a usable prefix at the insertion point?&lt;/li&gt;
&lt;li&gt;What is the context of &lt;code&gt;mc:Ignorable&lt;/code&gt; / &lt;code&gt;mc:AlternateContent&lt;/code&gt;?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2.3 Node Index Tree
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;XMLDocument&lt;/code&gt; builds every element into a &lt;code&gt;NodeRecord&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;NodeRecord&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="no"&gt;ID&lt;/span&gt;     &lt;span class="nc"&gt;NodeID&lt;/span&gt;
    &lt;span class="nc"&gt;Parent&lt;/span&gt; &lt;span class="nc"&gt;NodeID&lt;/span&gt;
    &lt;span class="nc"&gt;QName&lt;/span&gt;  &lt;span class="nc"&gt;QName&lt;/span&gt;
    &lt;span class="nc"&gt;Namespace&lt;/span&gt;  &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="nc"&gt;Source&lt;/span&gt;     &lt;span class="nc"&gt;ByteRange&lt;/span&gt; &lt;span class="c1"&gt;// the whole element [Start, End)&lt;/span&gt;
    &lt;span class="nc"&gt;OpenEnd&lt;/span&gt;    &lt;span class="kt"&gt;int&lt;/span&gt;       &lt;span class="c1"&gt;// end of the open tag, start of content&lt;/span&gt;
    &lt;span class="nc"&gt;CloseStart&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;       &lt;span class="c1"&gt;// offset of the closing tag '&amp;lt;'; -1 for self-closing&lt;/span&gt;
    &lt;span class="nc"&gt;Attrs&lt;/span&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nc"&gt;AttributeRecord&lt;/span&gt;
    &lt;span class="nc"&gt;Children&lt;/span&gt;   &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="nc"&gt;NodeID&lt;/span&gt;
    &lt;span class="n"&gt;scope&lt;/span&gt;      &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nc"&gt;NamespaceScope&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These spans let upper layers answer precisely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In which interval of the raw bytes is the &lt;code&gt;&amp;lt;a:t&amp;gt;&lt;/code&gt; content of this Run?&lt;/li&gt;
&lt;li&gt;Where does the complete &lt;code&gt;&amp;lt;a:p&amp;gt;&lt;/code&gt; of this paragraph start and end?&lt;/li&gt;
&lt;li&gt;When deleting this shape, which byte segment should be deleted?&lt;/li&gt;
&lt;li&gt;During text replacement, which bytes must be preserved?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Non-element content (text, comments, CDATA, PI, DOCTYPE) does not get its own node, but the raw bytes are always fully preserved in &lt;code&gt;XMLDocument.original&lt;/code&gt;; layers needing text location (such as &lt;code&gt;textmap&lt;/code&gt;) work on spans.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.4 Controlled Structure Insertion
&lt;/h3&gt;

&lt;p&gt;Besides replacement, xmlstore also provides &lt;code&gt;InsertBefore&lt;/code&gt; / &lt;code&gt;InsertAfter&lt;/code&gt; / &lt;code&gt;AppendChild&lt;/code&gt;. The constraints are clear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The inserted fragment must be a &lt;strong&gt;well-formed single-root fragment&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;Prefixes explicitly used in the fragment must be self-contained, or resolvable in the scope at the insertion point;&lt;/li&gt;
&lt;li&gt;Otherwise return &lt;code&gt;ErrFragmentNamespace&lt;/code&gt; instead of producing a package that "might not open."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This constraint looks conservative, but it actually protects client compatibility: PowerPoint has very low tolerance for unbound prefixes, multiple root nodes, and incorrect nesting.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. SpanPatch: Atomic Application of One Change Set
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1 Data Structure
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;SpanPatch&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Start&lt;/span&gt;       &lt;span class="kt"&gt;int&lt;/span&gt;    &lt;span class="c1"&gt;// raw-byte half-open interval [Start, End)&lt;/span&gt;
    &lt;span class="nc"&gt;End&lt;/span&gt;         &lt;span class="kt"&gt;int&lt;/span&gt;
    &lt;span class="nc"&gt;Replacement&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;
    &lt;span class="nc"&gt;Expect&lt;/span&gt;      &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt; &lt;span class="c1"&gt;// optional anchor: require data[Start:End] == Expect before applying&lt;/span&gt;
    &lt;span class="nc"&gt;Desc&lt;/span&gt;        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="c1"&gt;// for diagnostics only&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Expect&lt;/code&gt; is "baseline drift protection": after a patch is constructed and before it is applied, if the target interval has already been changed by another path, the anchor check fails and returns &lt;code&gt;ErrPatchAnchor&lt;/code&gt;, rather than overwriting with wrong content.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2 Application Contract
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;ApplyPatches&lt;/code&gt; guarantees four things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;An empty set returns the original data&lt;/strong&gt; (no copy);&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Validate everything first, then apply all at once&lt;/strong&gt;: out-of-range, &lt;code&gt;Start &amp;gt; End&lt;/code&gt;, overlapping intervals, or anchor mismatch—any failure fails the whole thing, with no partial application;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rebuild into a new buffer in ascending Start order&lt;/strong&gt;: the new buffer is immune to offset drift, equivalent to "in-place replacement in descending order," but the caller does not need to handle offsets themselves;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replacement content must be explicitly escaped by the caller&lt;/strong&gt;: &lt;code&gt;EscapeText&lt;/code&gt; / &lt;code&gt;EscapeAttrValue&lt;/code&gt; do not happen implicitly inside &lt;code&gt;ApplyPatches&lt;/code&gt;, avoiding double-escaping semantic ambiguity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Illustration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;patches&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="n"&gt;xmlstore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SpanPatch&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;End&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;135&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Replacement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Q4"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Expect&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Q3 revenue"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Start&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;End&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;412&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Replacement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"new note"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;xmlstore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ApplyPatches&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;patches&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ErrPatchOverlap / ErrPatchRange / ErrPatchAnchor / ErrEscapeInvalidRune&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3.3 Escaping Is Explicit, Invalid Characters Are Refused
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;EscapeText&lt;/code&gt; handles &lt;code&gt;&amp;amp; &amp;lt; &amp;gt;&lt;/code&gt;; &lt;code&gt;EscapeAttrValue&lt;/code&gt; additionally handles quotes. Both check the character range allowed by XML 1.0:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allowed: &lt;code&gt;#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Refused: most C0 control characters, &lt;code&gt;U+FFFE&lt;/code&gt;, &lt;code&gt;U+FFFF&lt;/code&gt;, invalid UTF-8&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Invalid characters return &lt;code&gt;ErrEscapeInvalidRune&lt;/code&gt;, and the caller decides whether to sanitize or refuse. &lt;strong&gt;No silent replacement&lt;/strong&gt;—otherwise "lexical fidelity" would be empty talk.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Why "Change One Run, Leave the Rest of the Bytes Unchanged" Is Possible
&lt;/h2&gt;

&lt;p&gt;Take a simplified XML snippet as an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a:p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;a:r&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a:rPr&lt;/span&gt; &lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"zh-CN"&lt;/span&gt; &lt;span class="na"&gt;sz&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"1800"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a:t&amp;gt;&lt;/span&gt;Q3 revenue&lt;span class="nt"&gt;&amp;lt;/a:t&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/a:r&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;a:r&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a:rPr&lt;/span&gt; &lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"zh-CN"&lt;/span&gt; &lt;span class="na"&gt;sz&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"1800"&lt;/span&gt; &lt;span class="na"&gt;b&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a:t&amp;gt;&lt;/span&gt;up 12% year over year&lt;span class="nt"&gt;&amp;lt;/a:t&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/a:r&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a:p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To change "Q3" to "Q4":&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The scanner builds the node tree and locates the first &lt;code&gt;&amp;lt;a:t&amp;gt;&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;The text layer computes the rune interval and confirms the match does not cross a grapheme-cluster boundary;&lt;/li&gt;
&lt;li&gt;It constructs a &lt;code&gt;SpanPatch&lt;/code&gt; covering only the two bytes of &lt;code&gt;Q3&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ApplyPatches&lt;/code&gt; validates and rebuilds, and only these two bytes change;&lt;/li&gt;
&lt;li&gt;All remaining tags, attribute order, whitespace, and the second Run's bytes are preserved as-is.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the target string spans Runs—say "Q3 revenue" is split across two Runs—the text layer plans &lt;strong&gt;multiple patches&lt;/strong&gt;: delete/replace the target portion in the first Run, clear the target portion in the middle Run, and replace the target portion in the last Run. Each patch still covers only the necessary interval, and the formatting and bytes of other Runs are not rewritten.&lt;/p&gt;

&lt;p&gt;This is the underlying logic of "cross-Run fidelity replacement," which Part 4 expands on.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Unknown Extensions and Namespace Safety
&lt;/h2&gt;

&lt;p&gt;A common "pitfall" in OOXML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p:sp&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p:nvSpPr&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/p:nvSpPr&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p:spPr&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a:xfrm&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/a:xfrm&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;a:prstGeom&lt;/span&gt; &lt;span class="na"&gt;prst&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"rect"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/a:prstGeom&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p14:shadowObscured&lt;/span&gt; &lt;span class="na"&gt;xmlns:p14&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"..."&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/p:spPr&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p:txBody&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/p:txBody&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p:sp&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;p14:shadowObscured&lt;/code&gt; is an unknown extension. xmlstore handles it by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building a node as usual, recording the URI/local name and byte span;&lt;/li&gt;
&lt;li&gt;The upper layer does not interpret it, but does not delete it either;&lt;/li&gt;
&lt;li&gt;When editing other child elements of &lt;code&gt;p:spPr&lt;/code&gt;, the patch covers only the target child element, and the &lt;code&gt;p14:&lt;/code&gt; node's raw bytes are preserved;&lt;/li&gt;
&lt;li&gt;If a new element must be created, the insertion point checks whether the prefix is resolvable in the current scope, avoiding unbound prefixes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is safer than "dropping unknown nodes" or "forcing schema-ization." The cost: xmlstore does not provide "full schema validation"; it only guarantees &lt;strong&gt;structurally parseable + byte-locatable + namespace-resolvable&lt;/strong&gt;. Completeness validation is handled by &lt;code&gt;Validate&lt;/code&gt; and higher-layer business rules.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. The B1 Invariant: Verifiable, Not a Slogan
&lt;/h2&gt;

&lt;p&gt;In the project, "unmodified Part bytes are identical" is called &lt;strong&gt;B1&lt;/strong&gt;. It is constrained by at least three pieces of evidence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Saving an empty change set&lt;/strong&gt;: &lt;code&gt;BuildSavePlan&lt;/code&gt; produces a full &lt;code&gt;CopyOriginal&lt;/code&gt; for an empty &lt;code&gt;ChangeSet&lt;/code&gt;, and the decompressed content matches the input bytes (&lt;code&gt;TestSavePlanUnchangedIsB1&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Single-Run replacement&lt;/strong&gt;: on the real sample &lt;code&gt;ext-0024&lt;/code&gt; (WPS, with animations and unknown extensions), replacing only one Run converges the difference span to &lt;strong&gt;1 byte&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Public golden sample replay&lt;/strong&gt;: the "before-change/after-change" golden samples of &lt;code&gt;s001-text&lt;/code&gt; / &lt;code&gt;s002-table&lt;/code&gt; / &lt;code&gt;s003-image&lt;/code&gt; / &lt;code&gt;s004-audio&lt;/code&gt; are replayed in CI with byte-level comparison.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The meaning of B1 is not "pursuing zero difference," but &lt;strong&gt;limiting the difference to the declared scope&lt;/strong&gt;: wherever you changed something, the difference appears only there; wherever you did not change anything, the tool has no right to touch it.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Design Trade-offs and Boundaries
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Trade-off&lt;/th&gt;
&lt;th&gt;Choice&lt;/th&gt;
&lt;th&gt;Reason&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;XML parsing method&lt;/td&gt;
&lt;td&gt;Self-developed lexical scan + node index&lt;/td&gt;
&lt;td&gt;Preserve byte spans and namespaces; avoid &lt;code&gt;encoding/xml&lt;/code&gt; synchronization deviations on certain self-closing combinations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Write method&lt;/td&gt;
&lt;td&gt;SpanPatch interval replacement&lt;/td&gt;
&lt;td&gt;Untouched regions preserve bytes; difference scope is controllable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unknown nodes&lt;/td&gt;
&lt;td&gt;Build tree as-is, preserve as-is&lt;/td&gt;
&lt;td&gt;Do not drop vendor extensions; do not guess semantics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;schema usage&lt;/td&gt;
&lt;td&gt;Read-only projection (&lt;code&gt;internal/ooxml/schema&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;Generated types do not enter the write path, avoiding re-serialization damage to fidelity&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Invalid characters&lt;/td&gt;
&lt;td&gt;Explicit refusal&lt;/td&gt;
&lt;td&gt;No silent sanitization, avoiding "looks successful but semantics changed"&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nesting depth&lt;/td&gt;
&lt;td&gt;Default 256-level budget&lt;/td&gt;
&lt;td&gt;Prevent deep recursion from untrusted input&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Limitations to be clear about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;xmlstore is &lt;strong&gt;not&lt;/strong&gt; a general-purpose XML DOM and does not provide XPath, XSLT, or full schema validation.&lt;/li&gt;
&lt;li&gt;It assumes the input is UTF-8; non-UTF-8 is refused directly rather than transcoded and then claimed to be faithful.&lt;/li&gt;
&lt;li&gt;It guarantees "structure locatable + patch applicable," not "business semantics definitely correct"; business validation lives at a higher layer.&lt;/li&gt;
&lt;li&gt;The write path does not use generated schema types; generated types are only used for read-only projection (a hard constraint of ADR-030).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  8. Summary
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;xmlstore&lt;/code&gt; solves the lowest-level and most easily overlooked problem: &lt;strong&gt;how to precisely change a small piece of XML without damaging the document.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Its answer consists of four parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Namespace-aware scanning that preserves raw byte spans;&lt;/li&gt;
&lt;li&gt;A node index tree that supports locating by element;&lt;/li&gt;
&lt;li&gt;The SpanPatch engine that validates everything first, then applies all at once;&lt;/li&gt;
&lt;li&gt;Controlled insertion and explicit escaping that refuse to produce invalid XML.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The next post moves up a layer: how these patches enter the OPC package, how saving is planned together with relationships/content types, and how transactions and atomic persistence are guaranteed.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series navigation&lt;/strong&gt;: &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/01-overview.md" rel="noopener noreferrer"&gt;← Part 1: Overview&lt;/a&gt; · &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/03-opc-transaction-atomic-save.md" rel="noopener noreferrer"&gt;Part 3: OPC Container, Transactional Editing, and Atomic Save →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>xml</category>
      <category>ooxml</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Why Go Deserves Its Own PPTX Engine</title>
      <dc:creator>jiang jinfeng</dc:creator>
      <pubDate>Sun, 06 Dec 2026 01:42:38 +0000</pubDate>
      <link>https://dev.to/jiang_jinfeng_205d3a3d590/why-go-deserves-its-own-pptx-engine-383m</link>
      <guid>https://dev.to/jiang_jinfeng_205d3a3d590/why-go-deserves-its-own-pptx-engine-383m</guid>
      <description>&lt;h1&gt;
  
  
  Why Go Deserves Its Own PPTX Engine
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;go-pptx Tech Blog · Part 1: Overview — Why Rebuild PPTX Processing in Pure Go&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Series: go-pptx Tech Blog (10 parts)&lt;br&gt;
Baseline: v2.4.4 (2026-12)&lt;br&gt;
Repository: &lt;code&gt;github.com/F31/go-pptx&lt;/code&gt;; public import path: &lt;code&gt;github.com/F31/go-pptx/v2/pptx&lt;/code&gt;&lt;br&gt;
License: Apache-2.0&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Purpose: Filling the Gap for "Programmatic PPTX Processing" in the Go Ecosystem
&lt;/h2&gt;

&lt;p&gt;Presentations are one of the most common content carriers in enterprise and education settings, yet "modifying PPT programmatically" has long been the territory of Python, Java, and .NET:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;python-pptx&lt;/code&gt; depends on a Python interpreter;&lt;/li&gt;
&lt;li&gt;Apache POI depends on the JVM;&lt;/li&gt;
&lt;li&gt;LibreOffice UNO requires a full office suite installed on the target machine;&lt;/li&gt;
&lt;li&gt;Aspose.Slides is capable but requires a commercial license and runtime;&lt;/li&gt;
&lt;li&gt;Open XML SDK is bound to .NET.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The common needs of Go server-side deployments are the opposite: &lt;strong&gt;single-binary deployment, zero runtime, static linking, direct entry into containers and CI&lt;/strong&gt;. If a Go service only wants to replace a few pieces of text in a template, embed images and audio into a page, or batch-generate hundreds of client proposals, having to install Python or call an external process first is architecturally awkward.&lt;/p&gt;

&lt;p&gt;go-pptx targets exactly this class of "&lt;strong&gt;programmatic PPTX processing&lt;/strong&gt;" scenarios:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Batch generation of template reports&lt;/strong&gt;: open an existing template, replace text, table rows, and chart data by data, then save.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fine-grained editing of existing documents&lt;/strong&gt;: modify only the target region without "reading out and rewriting" the whole document, avoiding damage to unknown extensions and layout details.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated narration / voiceover PPT&lt;/strong&gt;: convert notes into scripts, embed audio, generate slide-advance timing, and finally deliver a presentable file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read-only audit and comparison&lt;/strong&gt;: structured inspection, capability disclosure, and semantic difference reports between two versions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Browser-side privacy audit&lt;/strong&gt;: use WASM to inspect files locally, with files never uploaded.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In one sentence: &lt;strong&gt;operate PPTX like a structured document, while depending on neither Office, LibreOffice, FFmpeg, nor any interpreter.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Design Goals: Six Capability Pillars
&lt;/h2&gt;

&lt;p&gt;go-pptx is not designed to "wrap every OOXML field in a layer"; it makes trade-offs around six capability pillars:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pillar&lt;/th&gt;
&lt;th&gt;Goal&lt;/th&gt;
&lt;th&gt;Key Constraint&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;General read/write&lt;/td&gt;
&lt;td&gt;Create, parse, save, pages, shapes, images, text, notes, tables, supported charts&lt;/td&gt;
&lt;td&gt;Public object model aligns with the DrawingML hierarchy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Controlled fidelity&lt;/td&gt;
&lt;td&gt;Unmodified Parts and unknown XML preserved as-is; explicit refusal when safe execution is impossible&lt;/td&gt;
&lt;td&gt;The write path only performs SpanPatch, never full re-serialization&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fine formatting&lt;/td&gt;
&lt;td&gt;Distinguish local formatting, inherited formatting, and layout results; cross-Run editing, group transforms, table styles&lt;/td&gt;
&lt;td&gt;Inheritance chains are explainable; failures yield diagnostics rather than silent guessing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Automated narration&lt;/td&gt;
&lt;td&gt;Rich-text notes, audio embedding, playback configuration, slide-advance timing&lt;/td&gt;
&lt;td&gt;Detect media in pure Go without invoking FFmpeg&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Engineering reliability&lt;/td&gt;
&lt;td&gt;Lazy parsing, resource budgets, transactional commit, validation reports, real-corpus regression, native fuzzing&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;CGO_ENABLED=0&lt;/code&gt;; errors are returned, never panics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Optional extensions&lt;/td&gt;
&lt;td&gt;Read-only IR, CLI, media probing, rendering adapter contract&lt;/td&gt;
&lt;td&gt;Core dependencies stay simple; extensions do not pollute the facade&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A few hard rules that run throughout:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Byte fidelity first&lt;/strong&gt;: unmodified Parts are copied as raw bytes; modified Parts receive only minimal patches. Saving an empty change set must be byte-identical (B1).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transactional editing&lt;/strong&gt;: first &lt;code&gt;plan&lt;/code&gt; as a pure read-only validation, then &lt;code&gt;apply&lt;/code&gt; in a single transactional commit; zero residue on failure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Diagnose, don't silently corrupt&lt;/strong&gt;: unsupported edits return stable error codes or a &lt;code&gt;Diagnostic&lt;/code&gt;, never "guess something that looks close enough."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Budgets for untrusted input&lt;/strong&gt;: Part count, XML size, media size, and cumulative decompressed read volume are all constrained by &lt;code&gt;Budget&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API grading&lt;/strong&gt;: &lt;code&gt;// Stable:&lt;/code&gt; sections promise backward compatibility; other symbols evolve under the management contract.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Technical Architecture: Facade + Domain Logic + Format Layer + Transport Layer
&lt;/h2&gt;

&lt;p&gt;Starting with v2.0, the module root is a "meta-repository" that no longer contains &lt;code&gt;package pptx&lt;/code&gt; files; the only official public import path is the &lt;code&gt;pptx/&lt;/code&gt; subpackage. Internal implementation is layered by responsibility:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─────────────────────────────────────────────────────────┐
│ Public facade  github.com/F31/go-pptx/v2/pptx            │
│ Presentation · Slide · Shape · TextFrame · TableShape   │
│ ChartShape · PictureShape · AudioShape · VideoShape     │
│ (currently 221 types · 44 top-level functions · 17 error sentinels) │
└────────────────────────┬────────────────────────────────┘
                         │
┌────────────────────────┴────────────────────────────────┐
│ Orchestration  internal/engine                           │
│ Inspect / Validate / Capability / IR shared by CLI and WASM │
└────────────────────────┬────────────────────────────────┘
                         │
┌────────────────────────┴────────────────────────────────┐
│ Domain logic  internal/document/{model,style,geometry,text, │
│         media,table} · chart · bind · ir · editplan      │
└────────────────────────┬────────────────────────────────┘
                         │
┌────────────────────────┴────────────────────────────────┐
│ Format layer  internal/ooxml (read-only projection)      │
│         internal/ooxml/schema (ECMA-376 generated types) │
└────────────────────────┬────────────────────────────────┘
                         │
┌────────────────────────┴────────────────────────────────┐
│ Transport layer  internal/opc (ZIP/relationships/content types/save plan/budget) │
│         internal/xmlstore (scan/index/SpanPatch)         │
└─────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dependency direction is enforced in CI by &lt;code&gt;internal/archlint&lt;/code&gt;: &lt;code&gt;pptx → internal/*&lt;/code&gt; is allowed; &lt;code&gt;internal/* → pptx&lt;/code&gt; is forbidden (&lt;code&gt;internal/engine&lt;/code&gt; is the only explicit exception, because it carries the adaptation from facade to IR); an unregistered new package or a cross-layer reverse reference makes &lt;code&gt;go test&lt;/code&gt; fail directly.&lt;/p&gt;

&lt;p&gt;A few key subsystems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;internal/xmlstore&lt;/code&gt;&lt;/strong&gt;: namespace-aware scanner + node index + SpanPatch engine. It preserves the original byte span of every element, so "change only one Run, leave the rest of the bytes unchanged" is verifiable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;internal/opc&lt;/code&gt;&lt;/strong&gt;: OPC package model, relationship graph, content types, &lt;code&gt;SavePlan&lt;/code&gt;, atomic persistence, resource budget.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;internal/editplan&lt;/code&gt;&lt;/strong&gt;: single-Part / multi-Part edit plans with unified transactional semantics.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;internal/chart&lt;/code&gt;&lt;/strong&gt;: chart XML building, parsing, canonical validation, workbook synchronization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;internal/ir&lt;/code&gt;&lt;/strong&gt;: read-only intermediate representation, timing IR, semantic diff.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;internal/ooxml&lt;/code&gt;&lt;/strong&gt;: read-only projection generated from the ECMA-376 Part 4 Transitional XSD, used by engine for auditing and IR projection.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Competitive Analysis: Not "Another python-pptx"
&lt;/h2&gt;

&lt;p&gt;The comparison below is compiled from public information and self-testing criteria, focusing on "deployment form, editing fidelity, unknown extensions, and audit capability" rather than simply counting feature items.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;&lt;strong&gt;go-pptx&lt;/strong&gt;&lt;/th&gt;
&lt;th&gt;python-pptx&lt;/th&gt;
&lt;th&gt;Apache POI (XSLF)&lt;/th&gt;
&lt;th&gt;LibreOffice UNO&lt;/th&gt;
&lt;th&gt;Aspose.Slides&lt;/th&gt;
&lt;th&gt;Open XML SDK&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Language / runtime&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Go, zero runtime dependencies&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Python interpreter&lt;/td&gt;
&lt;td&gt;JVM&lt;/td&gt;
&lt;td&gt;C++/multiple languages&lt;/td&gt;
&lt;td&gt;.NET/Java/cloud&lt;/td&gt;
&lt;td&gt;.NET&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deployment form&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Single binary / WASM&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Requires Python environment&lt;/td&gt;
&lt;td&gt;Requires JVM&lt;/td&gt;
&lt;td&gt;Requires LibreOffice installed&lt;/td&gt;
&lt;td&gt;Requires runtime + commercial license&lt;/td&gt;
&lt;td&gt;Requires .NET&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Editing fidelity&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Byte-level precise patching&lt;/strong&gt;, zero changes to untouched areas&lt;/td&gt;
&lt;td&gt;Reads out then rewrites the whole package&lt;/td&gt;
&lt;td&gt;Rebuilds the document&lt;/td&gt;
&lt;td&gt;Rebuilds the document&lt;/td&gt;
&lt;td&gt;Rebuilds the document (relatively good fidelity)&lt;/td&gt;
&lt;td&gt;Full rewrite&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unknown extension preservation&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Preserved as raw bytes&lt;/strong&gt; (Opaque strategy)&lt;/td&gt;
&lt;td&gt;Depends on rewrite path, easily lost&lt;/td&gt;
&lt;td&gt;Depends on parse coverage&lt;/td&gt;
&lt;td&gt;Depends on parse coverage&lt;/td&gt;
&lt;td&gt;Depends on version&lt;/td&gt;
&lt;td&gt;Preserved at structure level&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Browser-side offline read-only&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;WASM, files never leave the device&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Web API (requires upload)&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Capability self-description manifest&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Yes (six-dimensional Supported/Partial/…)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Semantic diff (page-aligned)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Built-in (weighted LCS + Jaccard)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Yes (difference comparison)&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Template data binding&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Built-in&lt;/strong&gt; (inline/conditional/row loop/chart)&lt;/td&gt;
&lt;td&gt;Requires jinja2 et al.&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Yes (macros/scripts)&lt;/td&gt;
&lt;td&gt;Yes (template API)&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Media duration/signature probing&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;Pure Go&lt;/strong&gt; (WAV/MP3/MP4/WebM)&lt;/td&gt;
&lt;td&gt;No built-in&lt;/td&gt;
&lt;td&gt;No built-in&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;License&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Apache-2.0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;MIT&lt;/td&gt;
&lt;td&gt;Apache-2.0&lt;/td&gt;
&lt;td&gt;MPL-2.0&lt;/td&gt;
&lt;td&gt;Commercial&lt;/td&gt;
&lt;td&gt;MIT&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Points to clarify:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Aspose.Slides remains stronger in feature coverage and rendering, and go-pptx does not claim to "fully replace" it; its advantages are &lt;strong&gt;open source, zero runtime, byte fidelity, and self-hostability&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;python-pptx has a great ecosystem and ease of use; go-pptx's differentiators are &lt;strong&gt;Go single-binary deployment&lt;/strong&gt; and &lt;strong&gt;low-side-effect editing of existing documents&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;"Fidelity" is not a slogan: the project constrains it with empty-change-set byte identity, convergence of single-Run replacement differences to 1 byte on real samples, and client re-save verification.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Key Differentiators
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The only "byte-level fidelity" pure Go implementation&lt;/strong&gt;: change only the target region, keep untouched regions as original bytes; suited to existing-document processing that is sensitive to "documents being damaged by tool rewrites."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Go ecosystem lacks a PPTX SDK of comparable scope&lt;/strong&gt;: single binary, directly usable in existing Go services/CI, WASM-capable in the browser.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Built-in audit and capability negotiation&lt;/strong&gt;: &lt;code&gt;Diff&lt;/code&gt;, &lt;code&gt;Validate&lt;/code&gt;, and &lt;code&gt;Capability&lt;/code&gt; let callers know which capabilities are available and which are limited before deployment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open source and self-hostable&lt;/strong&gt;: Apache-2.0, no runtime/license cost, controllable cost for batch processing and automation scenarios.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  5. Features: From "Can Edit Text" to "Can Deliver"
&lt;/h2&gt;

&lt;p&gt;Current public capabilities can be roughly grouped by work package:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;th&gt;Capability&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Creation&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;New()&lt;/code&gt; with 4 built-in standard layouts; &lt;code&gt;AddSlide&lt;/code&gt; / &lt;code&gt;AddSlideWithPlaceholders&lt;/code&gt; / &lt;code&gt;NewBatch&lt;/code&gt;; text boxes, auto shapes, images, charts, tables, audio, video; &lt;code&gt;WithSlideSize&lt;/code&gt;; move/delete pages and shapes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Text editing&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Paragraph / Run object model; cross-Run literal replacement (3 formatting strategies, grapheme-cluster protection, br/field/hyperlink boundary safety); font/color/size patch and Reset; text box properties and slidenum/datetime fields&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Visual writing&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;SetFill&lt;/code&gt; / &lt;code&gt;SetLine&lt;/code&gt; / &lt;code&gt;SetBackground&lt;/code&gt;; shadows, glow, soft edges, reflection, inner shadow, fill overlay, blur; image cropping, SVG + PNG fallback; theme fonts/colors; batch add images/charts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Images/media&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;PNG/JPEG et al. embedding with 4 Fit modes; media content hash deduplication; MP3/WAV/MP4/WebM pure Go probing; audio playback tree and timing plan&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Charts/tables&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Bar/line/pie/doughnut/area/radar/scatter/bubble/3D bar; combo charts, secondary axis, series labels/styles/markers, axis gridlines/number formats; rich-text tables, merges, diagonals, style IDs and batch style resolution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Template binding&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Inline &lt;code&gt;{{path}}&lt;/code&gt;, conditional paragraphs, table row loops, chart data binding; pure read-only validation in the plan stage + single-transaction atomic commit, zero residue on failure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Read-only audit&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Read-only IR (schemaVersion'd JSON), semantic &lt;code&gt;Diff&lt;/code&gt;, &lt;code&gt;Validate&lt;/code&gt;, six-dimensional &lt;code&gt;Capability&lt;/code&gt; manifest&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Fidelity mechanisms&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;SpanPatch precise byte patching, unknown subtrees/extensions preserved as-is, revision concurrency protection, atomic persistence and failure recovery&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Browser-side&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;WASM compile target + offline static inspection page (files never leave the device, no external network/no CDN)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A set of current baseline numbers (v2.4.4):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Public API types&lt;/td&gt;
&lt;td&gt;221&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stable sections / symbols / methods&lt;/td&gt;
&lt;td&gt;73 / 96 / 183&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exported methods / top-level functions&lt;/td&gt;
&lt;td&gt;207 / 44&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Error sentinels&lt;/td&gt;
&lt;td&gt;17&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Repo-wide coverage&lt;/td&gt;
&lt;td&gt;Weighted approx. 84%+&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Public corpus&lt;/td&gt;
&lt;td&gt;36+ sample index (public golden samples + 33 private ext-* indexes)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;L3 real devices&lt;/td&gt;
&lt;td&gt;PowerPoint 16 + WPS 12: 8/8 pass; v2.4.x additionally has a 13-page three-client composite sample&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  6. Quality and Validation: Turning "It Works" into "It Keeps Working"
&lt;/h2&gt;

&lt;p&gt;go-pptx does several things in engineering validation that are uncommon among similar projects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Corpus regression&lt;/strong&gt;: 30+ real sample indexes; public golden samples come with a "before-change / after-change / actions / smoke" closed loop, reproducible in CI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Byte-level assertions (B1)&lt;/strong&gt;: after saving an empty change set, the decompressed content of unmodified Parts is byte-identical; the difference span of a single-Run replacement converges to 1 byte.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client matrix (L3)&lt;/strong&gt;: real-device open, edit, re-save, and re-verify on PowerPoint 16 / WPS 12; v2.4.x extends to a 13-page composite sample and LibreOffice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coverage gate&lt;/strong&gt;: &lt;code&gt;scripts/coverage/gate.sh&lt;/code&gt; sets thresholds per package, and an unregistered new package fails directly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Native fuzzing&lt;/strong&gt;: open path, text replacement, and template binding all have fuzz targets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance baseline&lt;/strong&gt;: three corpus tiers × six benchmark categories (Open / Traverse / Replace / SaveMem / SaveDisk / PeakHeap).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross builds&lt;/strong&gt;: &lt;code&gt;js/wasm&lt;/code&gt;, &lt;code&gt;wasip1/wasm&lt;/code&gt;, &lt;code&gt;darwin/arm64&lt;/code&gt;, &lt;code&gt;linux/arm64&lt;/code&gt;, &lt;code&gt;windows/amd64&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These topics are expanded in Part 9.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Series Plan: What the Next 9 Parts Cover
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Part&lt;/th&gt;
&lt;th&gt;Topic&lt;/th&gt;
&lt;th&gt;Content Highlights&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Overview&lt;/td&gt;
&lt;td&gt;Purpose, design goals, technical architecture, competitive analysis, features, quality baseline (this post)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Byte-level fidelity&lt;/td&gt;
&lt;td&gt;xmlstore scanner, namespace environment, node index, SpanPatch contract, unknown subtree preservation, B1 evidence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;OPC and transactions&lt;/td&gt;
&lt;td&gt;ZIP lazy index, relationships/content types, ChangeSet and SavePlan, single/multi-Part edit plans, revision, atomic save, raw passthrough&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Object model and handles&lt;/td&gt;
&lt;td&gt;Cross-Run text replacement, rune/grapheme boundaries, three replacement strategies, &lt;code&gt;cNvPr@id&lt;/code&gt; identity, STALE-GUARD, monotonic ID allocator&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Chart subsystem&lt;/td&gt;
&lt;td&gt;Chart XML and embedded workbook, 9 chart types, combo charts/dual axes, series labels/styles/markers, canonical validation, client compatibility&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Media and automated narration&lt;/td&gt;
&lt;td&gt;WAV/MP3/MP4/WebM pure Go probing, duration state semantics, media deduplication, playback tree, narrate/timing-plan, resource budget&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;Template data binding&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;{{path}}&lt;/code&gt;/&lt;code&gt;#if&lt;/code&gt;/&lt;code&gt;#each&lt;/code&gt;/table row loops/chart binding, plan/apply two phases, zero residue, relationship with fidelity patches&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;Read-only audit and semantic diff&lt;/td&gt;
&lt;td&gt;IR projection, timing IR, weighted LCS + Jaccard page alignment, opaque diff, six-dimensional Capability, Validate diagnostics&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;Quality engineering&lt;/td&gt;
&lt;td&gt;30+ corpus, public golden samples, B1 assertions, coverage gate, fuzzing, three-client L3, performance guardrails, CI&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;Architecture evolution and cross-platform&lt;/td&gt;
&lt;td&gt;ADR-030 facade convergence, engine orchestration, archlint, ECMA-376 generation pipeline, CLI 9 subcommands, WASM offline, five-platform cross builds&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Reading suggestions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To quickly judge whether it fits your scenario: read Parts 1, 3, and 9.&lt;/li&gt;
&lt;li&gt;To understand "why it won't damage documents": read Parts 2, 3, and 4.&lt;/li&gt;
&lt;li&gt;To build reports/charts/voiceover: read Parts 5, 6, and 7.&lt;/li&gt;
&lt;li&gt;To build audit/comparison/browser pre-checks: read Parts 8 and 10.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  8. Boundaries and Trade-offs
&lt;/h2&gt;

&lt;p&gt;go-pptx is not a "universal PPTX engine" and currently explicitly does not promise:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No native rendering&lt;/strong&gt;: the &lt;code&gt;render&lt;/code&gt; subpackage only defines an adapter contract, and the &lt;code&gt;rendering.native&lt;/code&gt; capability status is &lt;code&gt;Untested&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No full animation editing&lt;/strong&gt;: the timing tree is primarily read-only IR; it can detect conflicts but does not promise full playback evaluation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No writing of encryption/signature/OLE&lt;/strong&gt;: it recognizes and explicitly refuses rather than silently converting.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No promise to cover all OOXML features&lt;/strong&gt;: chart types, styles, and effects all follow the "supported subset + capability disclosure + diagnostics" model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No in-place saving of the source file&lt;/strong&gt;: the source file is still read lazily, and safe replacement and rollback semantics are not yet closed, so it is currently explicitly refused.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This boundary of "knowing what it does not do," together with the error model of "clearly telling you why on failure," is the biggest difference between go-pptx and tools that "seem able to edit everything but actually silently drop content."&lt;/p&gt;




&lt;h2&gt;
  
  
  9. Summary
&lt;/h2&gt;

&lt;p&gt;The core of go-pptx is not "rewriting python-pptx in Go," but solving three engineering problems together:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Fidelity&lt;/strong&gt;: treat raw bytes as the invariant and patch only the target region.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transactions&lt;/strong&gt;: validate first, then commit; zero residue on failure; revision guard for concurrency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verifiability&lt;/strong&gt;: real corpus, byte assertions, client real devices, coverage, and fuzzing together constrain "the capabilities it claims."&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The next post starts from the lowest-level &lt;code&gt;xmlstore&lt;/code&gt; and explains "why changing only one Run leaves the rest of the bytes unchanged."&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Series navigation&lt;/strong&gt;: &lt;a href="https://github.com/F31/go-pptx/blob/main/docs/blog/02-byte-fidelity-xmlstore.md" rel="noopener noreferrer"&gt;Part 2: Byte-level Fidelity and the SpanPatch Engine →&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>pptx</category>
      <category>opensource</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
