otomate 0.0.10 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -55,6 +55,7 @@ Output: serializable `DiffResult` with typed operations — `insert`, `delete`,
55
55
  | `@otomate/diff` | Tree diff engine + Myers string-level diffing |
56
56
  | `@otomate/html` | HTML ↔ UDM adapter (via hast) |
57
57
  | `@otomate/docx` | docx ↔ UDM adapter (via jszip + fast-xml-parser) |
58
+ | `@otomate/inject` | Template injection — fill `{{placeholders}}` with data |
58
59
  | `@otomate/css-docx` | CSS properties → OOXML style mapping |
59
60
  | `@otomate/ui` | Web UI for testing conversions and diffs |
60
61
 
@@ -184,6 +185,49 @@ const result = diff(htmlTree, docxTree);
184
185
  // Structural comparison regardless of source format
185
186
  ```
186
187
 
188
+ ### Template injection
189
+
190
+ Fill `{{placeholders}}` in a document template with data from any source.
191
+
192
+ ```typescript
193
+ import { readDocx, writeDocx, inject } from "otomate";
194
+
195
+ // 1. Read template (HTML or docx with content controls)
196
+ const tree = await readDocx(templateBuffer);
197
+
198
+ // 2. Inject data — any JSON object, keys match {{placeholders}}
199
+ const filled = inject(tree, {
200
+ name: "John Doe",
201
+ position: "Senior Engineer",
202
+ benefits: [
203
+ { name: "Health", description: "Full medical coverage" },
204
+ { name: "401k", description: "6% company match" },
205
+ ],
206
+ showRelocation: true,
207
+ relocationAmount: "$15,000",
208
+ });
209
+
210
+ // 3. Export filled document
211
+ const output = await writeDocx(filled);
212
+ ```
213
+
214
+ **Placeholder syntax:**
215
+
216
+ | Syntax | Description |
217
+ |--------|-------------|
218
+ | `{{fieldName}}` | Replace with value (inherits formatting) |
219
+ | `{{obj.nested}}` | Dot-path into nested objects |
220
+ | `{{#each items}}...{{/each}}` | Repeat block for each array item |
221
+ | `{{#if condition}}...{{/if}}` | Conditional block |
222
+ | `{{#if x}}...{{else}}...{{/if}}` | Conditional with else |
223
+ | `{{@richField}}` | Replace paragraph with block-level content |
224
+
225
+ **Word content controls:** When reading a `.docx` created with Word's Developer tab content controls, otomate automatically detects them and converts each control's tag name into a `{{placeholder}}`. No manual placeholder typing needed.
226
+
227
+ **Data format:** Free-form JSON — no fixed schema. The keys in your data object map directly to the placeholder names in your template.
228
+
229
+ **Interactive demo:** Open `examples/inject-demo.html` to try it live with editable JSON and instant preview.
230
+
187
231
  ## Web UI
188
232
 
189
233
  A built-in test interface for interactive conversion and diffing:
package/dist/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export { type UdmNode, type UdmParent, type UdmLiteral, type Root, type Paragrap
2
2
  export { diff, diffText, type DiffResult, type DiffOptions, type EditOperation, type TextChange, type NodeMapping, } from "@otomate/diff";
3
3
  export { readHtml, writeHtml, renderDiffHtml, parseCssClasses, parseCssRules, type HtmlReadOptions, type HtmlWriteOptions, type DiffHtmlOptions, type CssClassRules, type CssParsedRules, } from "@otomate/html";
4
4
  export { readDocx, writeDocx, type DocxReadOptions, type DocxWriteOptions, } from "@otomate/docx";
5
+ export { inject, normalizeTextRuns, parseTokens, splitByPlaceholders, hasPlaceholders, resolveValue, valueToString, isTruthy, type InjectData, type InjectOptions, type PlaceholderToken, type PlaceholderHit, type RichContent, } from "@otomate/inject";
5
6
  export { cssToRunProps, cssToParaProps, parseColor, parseLengthTwips, parseLengthHalfPts, runPropsToXml, paraPropsToXml, buildStyleElement, type OoxmlRunProps, type OoxmlParaProps, } from "@otomate/css-docx";
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAC7C,KAAK,IAAI,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EACxD,KAAK,IAAI,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EACxC,KAAK,KAAK,EAAE,KAAK,QAAQ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