auto-hwpx 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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,137 @@
1
+ # auto-hwpx
2
+
3
+ TypeScript utility to replace placeholders in `.hwpx` files and emit a new `.hwpx`.
4
+
5
+ > Note: 100% Codex-generated.
6
+
7
+ ## Placeholder syntax
8
+
9
+ - Text placeholder: `<@key@>`
10
+ - Text placeholder with default: `<@key=default text@>`
11
+ - Image placeholder: `<@imgKey@>`
12
+
13
+ The renderer supports both raw token form and XML-escaped form (`&lt;@...@&gt;`) inside HWPX XML entries.
14
+
15
+ ## Behavior
16
+
17
+ - Scans `.xml`, `.txt`, and `.hpf` entries in the HWPX zip.
18
+ - For missing text keys:
19
+ - If default exists, default is used.
20
+ - If default does not exist, placeholder is left unchanged.
21
+ - Image placeholders are replaced with a donor `hp:pic` structure loaded from a template HWPX (default: `hwpx-examples/with-img.hwpx`).
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ npm install
27
+ ```
28
+
29
+ ## Demo script
30
+
31
+ Run a one-command demo that:
32
+ - finds `hwpx-examples/*.example.hwpx`
33
+ - creates a tiny demo image
34
+ - fills text + image placeholders
35
+ - writes `demo-output/demo-result.hwpx`
36
+
37
+ ```bash
38
+ npm run demo
39
+ ```
40
+
41
+ ## Publish to npm
42
+
43
+ This package is configured as a global CLI with command name:
44
+
45
+ ```bash
46
+ auto-hwpx
47
+ ```
48
+
49
+ ### 1) Build and verify locally
50
+
51
+ ```bash
52
+ npm install
53
+ npm run test
54
+ npm run build
55
+ npm pack --dry-run
56
+ ```
57
+
58
+ ### 2) Publish
59
+
60
+ ```bash
61
+ npm login
62
+ npm publish
63
+ ```
64
+
65
+ If you later move to a scoped package (for example `@your-scope/auto-hwpx`), publish with:
66
+
67
+ ```bash
68
+ npm publish --access public
69
+ ```
70
+
71
+ ### 3) Global install (for users)
72
+
73
+ ```bash
74
+ npm install -g auto-hwpx
75
+ auto-hwpx --help
76
+ ```
77
+
78
+ ## CLI usage
79
+
80
+ ```bash
81
+ npm run start -- \
82
+ --input hwpx-examples/초과근무내역서.example.hwpx \
83
+ --output /tmp/output.hwpx \
84
+ --text-json '{"name":"홍길동","content":"작업 내용"}' \
85
+ --images-json '{"img":"/absolute/path/to/image.png"}'
86
+ ```
87
+
88
+ Optional donor template path:
89
+
90
+ ```bash
91
+ npm run start -- \
92
+ --input hwpx-examples/초과근무내역서.example.hwpx \
93
+ --output /tmp/output.hwpx \
94
+ --text-json '{}' \
95
+ --images-json '{"img":"/absolute/path/to/image.png"}' \
96
+ --image-template hwpx-examples/with-img.hwpx
97
+ ```
98
+
99
+ Both `--text-json` and `--images-json` accept either inline JSON text or a path to a JSON file.
100
+
101
+ ## Programmatic API
102
+
103
+ ```ts
104
+ import { replaceHwpxPlaceholders } from "./src/render-hwpx.js";
105
+
106
+ const result = await replaceHwpxPlaceholders({
107
+ inputPath: "hwpx-examples/초과근무내역서.example.hwpx",
108
+ outputPath: "/tmp/output.hwpx",
109
+ replacements: {
110
+ text: {
111
+ name: "홍길동",
112
+ content: "작업 내용",
113
+ },
114
+ images: {
115
+ img: "/absolute/path/to/image.png",
116
+ },
117
+ },
118
+ });
119
+
120
+ console.log(result);
121
+ ```
122
+
123
+ Return shape:
124
+
125
+ ```ts
126
+ interface ReplaceHwpxResult {
127
+ textReplacements: number;
128
+ imageReplacements: number;
129
+ unresolvedPlaceholders: string[];
130
+ }
131
+ ```
132
+
133
+ ## Test
134
+
135
+ ```bash
136
+ npm test
137
+ ```
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ import { promises as fs } from "node:fs";
3
+ import { Command } from "commander";
4
+ import { replaceHwpxPlaceholders } from "./render-hwpx.js";
5
+ function isPlainObject(value) {
6
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
7
+ return false;
8
+ }
9
+ return Object.values(value).every((item) => typeof item === "string");
10
+ }
11
+ async function parseJsonMapInput(raw, label) {
12
+ let source = raw;
13
+ try {
14
+ await fs.access(raw);
15
+ source = await fs.readFile(raw, "utf8");
16
+ }
17
+ catch {
18
+ // Not a file path. Treat as inline JSON text.
19
+ }
20
+ let parsed;
21
+ try {
22
+ parsed = JSON.parse(source);
23
+ }
24
+ catch (error) {
25
+ throw new Error(`Invalid ${label} JSON: ${String(error)}`);
26
+ }
27
+ if (!isPlainObject(parsed)) {
28
+ throw new Error(`${label} must be a JSON object of string values.`);
29
+ }
30
+ return parsed;
31
+ }
32
+ async function main() {
33
+ const program = new Command();
34
+ program
35
+ .name("auto-hwpx")
36
+ .description("Replace text and image placeholders in a .hwpx file.")
37
+ .requiredOption("--input <path>", "Input .hwpx file path")
38
+ .requiredOption("--output <path>", "Output .hwpx file path")
39
+ .option("--text-json <jsonOrPath>", "Text replacement JSON object or path", "{}")
40
+ .option("--images-json <jsonOrPath>", "Image replacement JSON object or path", "{}")
41
+ .option("--image-template <path>", "Template .hwpx containing a donor hp:pic run");
42
+ program.parse(process.argv);
43
+ const options = program.opts();
44
+ const [textReplacements, imageReplacements] = await Promise.all([
45
+ parseJsonMapInput(options.textJson, "--text-json"),
46
+ parseJsonMapInput(options.imagesJson, "--images-json"),
47
+ ]);
48
+ const result = await replaceHwpxPlaceholders({
49
+ inputPath: options.input,
50
+ outputPath: options.output,
51
+ replacements: {
52
+ text: textReplacements,
53
+ images: imageReplacements,
54
+ },
55
+ imageTemplatePath: options.imageTemplate,
56
+ });
57
+ process.stdout.write(`${JSON.stringify({
58
+ outputPath: options.output,
59
+ textReplacements: result.textReplacements,
60
+ imageReplacements: result.imageReplacements,
61
+ unresolvedPlaceholders: result.unresolvedPlaceholders,
62
+ }, null, 2)}\n`);
63
+ }
64
+ main().catch((error) => {
65
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
66
+ process.exitCode = 1;
67
+ });
68
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CA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,CAAC,CAAC;AACvB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { replaceHwpxPlaceholders, type ReplaceHwpxInput, type ReplaceHwpxResult, } from "./render-hwpx.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,EACvB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { replaceHwpxPlaceholders, } from "./render-hwpx.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uBAAuB,GAGxB,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,16 @@
1
+ export interface ReplaceHwpxInput {
2
+ inputPath: string;
3
+ outputPath: string;
4
+ replacements: {
5
+ text: Record<string, string>;
6
+ images: Record<string, string>;
7
+ };
8
+ imageTemplatePath?: string;
9
+ }
10
+ export interface ReplaceHwpxResult {
11
+ textReplacements: number;
12
+ imageReplacements: number;
13
+ unresolvedPlaceholders: string[];
14
+ }
15
+ export declare function replaceHwpxPlaceholders(input: ReplaceHwpxInput): Promise<ReplaceHwpxResult>;
16
+ //# sourceMappingURL=render-hwpx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-hwpx.d.ts","sourceRoot":"","sources":["../src/render-hwpx.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE;QACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;IACF,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sBAAsB,EAAE,MAAM,EAAE,CAAC;CAClC;AAmgBD,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,gBAAgB,GACtB,OAAO,CAAC,iBAAiB,CAAC,CA0J5B"}
@@ -0,0 +1,518 @@
1
+ import { promises as fs } from "node:fs";
2
+ import path from "node:path";
3
+ import JSZip from "jszip";
4
+ import { DOMParser, XMLSerializer } from "@xmldom/xmldom";
5
+ import { imageSize } from "image-size";
6
+ import xpath from "xpath";
7
+ const DEFAULT_TEMPLATE_PATH = path.resolve(process.cwd(), "hwpx-examples/with-img.hwpx");
8
+ const XML_NS = {
9
+ hp: "http://www.hancom.co.kr/hwpml/2011/paragraph",
10
+ hc: "http://www.hancom.co.kr/hwpml/2011/core",
11
+ opf: "http://www.idpf.org/2007/opf/",
12
+ };
13
+ const select = xpath.useNamespaces(XML_NS);
14
+ const XML_DECLARATION_RE = /^<\?xml[^>]+?>/;
15
+ const PLACEHOLDER_RE = /(?:&lt;|<)@([^=@>\s]+)(?:=([^@]*?))?@(?:&gt;|>)/g;
16
+ const IMAGE_PLACEHOLDER_RE = /^<@([^=@>\s]+)(?:=([^@]*?))?@>$/;
17
+ function parseXml(xmlText) {
18
+ return new DOMParser({
19
+ errorHandler: {
20
+ warning: () => undefined,
21
+ error: (message) => {
22
+ throw new Error(`XML parse error: ${message}`);
23
+ },
24
+ fatalError: (message) => {
25
+ throw new Error(`XML fatal parse error: ${message}`);
26
+ },
27
+ },
28
+ }).parseFromString(xmlText, "application/xml");
29
+ }
30
+ function serializeXml(doc, originalText) {
31
+ const serialized = new XMLSerializer().serializeToString(doc);
32
+ if (XML_DECLARATION_RE.test(serialized)) {
33
+ return serialized;
34
+ }
35
+ const originalDecl = originalText.match(XML_DECLARATION_RE)?.[0];
36
+ if (originalDecl) {
37
+ return `${originalDecl}${serialized}`;
38
+ }
39
+ return serialized;
40
+ }
41
+ function escapeXmlText(text) {
42
+ return text
43
+ .replaceAll("&", "&amp;")
44
+ .replaceAll("<", "&lt;")
45
+ .replaceAll(">", "&gt;")
46
+ .replaceAll('"', "&quot;")
47
+ .replaceAll("'", "&apos;");
48
+ }
49
+ function isTextEntry(fileName) {
50
+ return (fileName.endsWith(".xml") ||
51
+ fileName.endsWith(".txt") ||
52
+ fileName.endsWith(".hpf"));
53
+ }
54
+ function isSectionEntry(fileName) {
55
+ return /^Contents\/section\d+\.xml$/.test(fileName);
56
+ }
57
+ function decodePlaceholderToken(text) {
58
+ return text.replaceAll("&lt;", "<").replaceAll("&gt;", ">");
59
+ }
60
+ function replaceTextPlaceholders(params) {
61
+ const { input, textValues, imageKeys, escapeOutput, unresolved } = params;
62
+ let replaced = 0;
63
+ const output = input.replaceAll(PLACEHOLDER_RE, (fullMatch, key, defaultValue) => {
64
+ if (imageKeys.has(key)) {
65
+ return fullMatch;
66
+ }
67
+ const explicitValue = textValues[key];
68
+ if (explicitValue !== undefined) {
69
+ replaced += 1;
70
+ return escapeOutput ? escapeXmlText(explicitValue) : explicitValue;
71
+ }
72
+ if (defaultValue !== undefined) {
73
+ replaced += 1;
74
+ return escapeOutput ? escapeXmlText(defaultValue) : defaultValue;
75
+ }
76
+ unresolved.add(key);
77
+ return fullMatch;
78
+ });
79
+ return { output, replaced };
80
+ }
81
+ function firstElementByXPath(expr, contextNode) {
82
+ const found = select(expr, contextNode);
83
+ if (found.length === 0) {
84
+ return null;
85
+ }
86
+ return found[0];
87
+ }
88
+ function listElementsByXPath(expr, contextNode) {
89
+ return select(expr, contextNode).map((node) => node);
90
+ }
91
+ function parseIntAttr(element, attrName) {
92
+ if (!element) {
93
+ return null;
94
+ }
95
+ const raw = element.getAttribute(attrName);
96
+ if (!raw) {
97
+ return null;
98
+ }
99
+ const parsed = Number.parseInt(raw, 10);
100
+ return Number.isFinite(parsed) ? parsed : null;
101
+ }
102
+ function setIntAttr(element, attrName, value) {
103
+ if (!element) {
104
+ return;
105
+ }
106
+ element.setAttribute(attrName, String(Math.max(1, Math.round(value))));
107
+ }
108
+ function detectImageTypeAndSize(buffer) {
109
+ const details = imageSize(buffer);
110
+ if (!details.width || !details.height || !details.type) {
111
+ throw new Error("Unable to detect image dimensions and format.");
112
+ }
113
+ const normalizedType = details.type.toLowerCase();
114
+ const extensionMap = {
115
+ jpg: "jpg",
116
+ jpeg: "jpeg",
117
+ png: "png",
118
+ gif: "gif",
119
+ bmp: "bmp",
120
+ tiff: "tiff",
121
+ tif: "tif",
122
+ svg: "svg",
123
+ };
124
+ const mediaTypeMap = {
125
+ jpg: "image/jpeg",
126
+ jpeg: "image/jpeg",
127
+ png: "image/png",
128
+ gif: "image/gif",
129
+ bmp: "image/bmp",
130
+ tiff: "image/tiff",
131
+ tif: "image/tiff",
132
+ svg: "image/svg+xml",
133
+ };
134
+ const extension = extensionMap[normalizedType];
135
+ const mediaType = mediaTypeMap[normalizedType];
136
+ if (!extension || !mediaType) {
137
+ throw new Error(`Unsupported image type: ${details.type}`);
138
+ }
139
+ return {
140
+ extension,
141
+ mediaType,
142
+ width: details.width,
143
+ height: details.height,
144
+ };
145
+ }
146
+ function calculateDisplaySize(params) {
147
+ // HWPX image dimensions in the sample map closely to 75 HWP units per pixel.
148
+ const unitPerPixel = 75;
149
+ const originalWidth = Math.max(1, Math.round(params.pixelWidth * unitPerPixel));
150
+ const originalHeight = Math.max(1, Math.round(params.pixelHeight * unitPerPixel));
151
+ const maxWidth = Math.max(1, Math.round(params.maxWidth));
152
+ const maxHeight = Math.max(1, Math.round(params.maxHeight));
153
+ const scale = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
154
+ const clampedScale = Number.isFinite(scale) && scale > 0 ? scale : 1;
155
+ return {
156
+ width: Math.max(1, Math.round(originalWidth * clampedScale)),
157
+ height: Math.max(1, Math.round(originalHeight * clampedScale)),
158
+ };
159
+ }
160
+ function getRunParagraph(runElement) {
161
+ let current = runElement.parentNode;
162
+ while (current) {
163
+ if (current.nodeType === current.ELEMENT_NODE) {
164
+ const element = current;
165
+ if (element.localName === "p" && element.prefix === "hp") {
166
+ return element;
167
+ }
168
+ }
169
+ current = current.parentNode;
170
+ }
171
+ return null;
172
+ }
173
+ function getParentTableCell(runElement) {
174
+ let current = runElement.parentNode;
175
+ while (current) {
176
+ if (current.nodeType === current.ELEMENT_NODE) {
177
+ const element = current;
178
+ if (element.localName === "tc" && element.prefix === "hp") {
179
+ return element;
180
+ }
181
+ }
182
+ current = current.parentNode;
183
+ }
184
+ return null;
185
+ }
186
+ function resolvePlaceholderBox(runElement) {
187
+ const cell = getParentTableCell(runElement);
188
+ if (cell) {
189
+ const cellSize = firstElementByXPath("./hp:cellSz", cell);
190
+ const cellMargin = firstElementByXPath("./hp:cellMargin", cell);
191
+ const width = parseIntAttr(cellSize, "width");
192
+ const height = parseIntAttr(cellSize, "height");
193
+ if (width && height) {
194
+ const marginLeft = parseIntAttr(cellMargin, "left") ?? 0;
195
+ const marginRight = parseIntAttr(cellMargin, "right") ?? 0;
196
+ const marginTop = parseIntAttr(cellMargin, "top") ?? 0;
197
+ const marginBottom = parseIntAttr(cellMargin, "bottom") ?? 0;
198
+ return {
199
+ width: Math.max(1, width - marginLeft - marginRight),
200
+ height: Math.max(1, height - marginTop - marginBottom),
201
+ };
202
+ }
203
+ }
204
+ const paragraph = getRunParagraph(runElement);
205
+ if (paragraph) {
206
+ const lineSeg = firstElementByXPath("./hp:linesegarray/hp:lineseg", paragraph);
207
+ const width = parseIntAttr(lineSeg, "horzsize");
208
+ const height = parseIntAttr(lineSeg, "textheight");
209
+ if (width && height) {
210
+ return { width, height };
211
+ }
212
+ }
213
+ return { width: 26280, height: 40980 };
214
+ }
215
+ function setPictureGeometry(picElement, imageResource, displaySize) {
216
+ const originalWidth = imageResource.originalWidth;
217
+ const originalHeight = imageResource.originalHeight;
218
+ const width = displaySize.width;
219
+ const height = displaySize.height;
220
+ const orgSz = firstElementByXPath("./hp:orgSz", picElement);
221
+ setIntAttr(orgSz, "width", width);
222
+ setIntAttr(orgSz, "height", height);
223
+ const sz = firstElementByXPath("./hp:sz", picElement);
224
+ setIntAttr(sz, "width", width);
225
+ setIntAttr(sz, "height", height);
226
+ const rotationInfo = firstElementByXPath("./hp:rotationInfo", picElement);
227
+ setIntAttr(rotationInfo, "centerX", Math.round(width / 2));
228
+ setIntAttr(rotationInfo, "centerY", Math.round(height / 2));
229
+ const imgRef = firstElementByXPath("./hc:img", picElement);
230
+ if (!imgRef) {
231
+ throw new Error("Template picture is missing hc:img node.");
232
+ }
233
+ imgRef.setAttribute("binaryItemIDRef", imageResource.itemId);
234
+ const point0 = firstElementByXPath("./hp:imgRect/hc:pt0", picElement);
235
+ const point1 = firstElementByXPath("./hp:imgRect/hc:pt1", picElement);
236
+ const point2 = firstElementByXPath("./hp:imgRect/hc:pt2", picElement);
237
+ const point3 = firstElementByXPath("./hp:imgRect/hc:pt3", picElement);
238
+ if (!point0 || !point1 || !point2 || !point3) {
239
+ throw new Error("Template picture is missing imgRect points.");
240
+ }
241
+ point0.setAttribute("x", "0");
242
+ point0.setAttribute("y", "0");
243
+ point1.setAttribute("x", String(width));
244
+ point1.setAttribute("y", "0");
245
+ point2.setAttribute("x", String(width));
246
+ point2.setAttribute("y", String(height));
247
+ point3.setAttribute("x", "0");
248
+ point3.setAttribute("y", String(height));
249
+ const clip = firstElementByXPath("./hp:imgClip", picElement);
250
+ if (clip) {
251
+ clip.setAttribute("left", "0");
252
+ clip.setAttribute("top", "0");
253
+ clip.setAttribute("right", String(originalWidth));
254
+ clip.setAttribute("bottom", String(originalHeight));
255
+ }
256
+ const dimension = firstElementByXPath("./hp:imgDim", picElement);
257
+ if (dimension) {
258
+ dimension.setAttribute("dimwidth", String(originalWidth));
259
+ dimension.setAttribute("dimheight", String(originalHeight));
260
+ }
261
+ }
262
+ function buildRunFromTemplate(params) {
263
+ const doc = parseXml(`<root xmlns:hp="${XML_NS.hp}" xmlns:hc="${XML_NS.hc}">${params.templateRunXml}</root>`);
264
+ const runElement = firstElementByXPath("/root/hp:run", doc);
265
+ if (!runElement) {
266
+ throw new Error("Unable to parse template run XML.");
267
+ }
268
+ if (params.charPrIDRef) {
269
+ runElement.setAttribute("charPrIDRef", params.charPrIDRef);
270
+ }
271
+ const pic = firstElementByXPath("./hp:pic", runElement);
272
+ if (!pic) {
273
+ throw new Error("Template run does not contain hp:pic.");
274
+ }
275
+ pic.setAttribute("id", String(params.picId));
276
+ pic.setAttribute("instid", String(params.instId));
277
+ setPictureGeometry(pic, params.imageResource, params.displaySize);
278
+ if (!firstElementByXPath("./hp:t", runElement)) {
279
+ const emptyText = doc.createElementNS(XML_NS.hp, "hp:t");
280
+ runElement.appendChild(emptyText);
281
+ }
282
+ return runElement;
283
+ }
284
+ function findNextImageIndex(contentDoc) {
285
+ const itemNodes = listElementsByXPath("/opf:package/opf:manifest/opf:item", contentDoc);
286
+ let max = 0;
287
+ for (const item of itemNodes) {
288
+ const id = item.getAttribute("id");
289
+ if (!id) {
290
+ continue;
291
+ }
292
+ const match = /^image(\d+)$/.exec(id);
293
+ if (!match) {
294
+ continue;
295
+ }
296
+ max = Math.max(max, Number.parseInt(match[1], 10));
297
+ }
298
+ return max + 1;
299
+ }
300
+ function ensureManifestItem(contentDoc, itemId, href, mediaType) {
301
+ const manifest = firstElementByXPath("/opf:package/opf:manifest", contentDoc);
302
+ if (!manifest) {
303
+ throw new Error("Contents/content.hpf is missing opf:manifest.");
304
+ }
305
+ const existing = listElementsByXPath("./opf:item", manifest).find((item) => item.getAttribute("id") === itemId);
306
+ if (existing) {
307
+ existing.setAttribute("href", href);
308
+ existing.setAttribute("media-type", mediaType);
309
+ existing.setAttribute("isEmbeded", "1");
310
+ return;
311
+ }
312
+ const item = contentDoc.createElementNS(XML_NS.opf, "opf:item");
313
+ item.setAttribute("id", itemId);
314
+ item.setAttribute("href", href);
315
+ item.setAttribute("media-type", mediaType);
316
+ item.setAttribute("isEmbeded", "1");
317
+ manifest.appendChild(item);
318
+ }
319
+ function collectMaxNumericAttributes(sectionDocs) {
320
+ let maxId = 1;
321
+ let maxInstId = 1;
322
+ for (const doc of sectionDocs) {
323
+ const allElements = listElementsByXPath("//*", doc);
324
+ for (const element of allElements) {
325
+ const idAttr = element.getAttribute("id");
326
+ if (idAttr && /^\d+$/.test(idAttr)) {
327
+ maxId = Math.max(maxId, Number.parseInt(idAttr, 10));
328
+ }
329
+ const instAttr = element.getAttribute("instid");
330
+ if (instAttr && /^\d+$/.test(instAttr)) {
331
+ maxInstId = Math.max(maxInstId, Number.parseInt(instAttr, 10));
332
+ }
333
+ }
334
+ }
335
+ return { maxId, maxInstId };
336
+ }
337
+ async function loadTemplateRunXml(imageTemplatePath) {
338
+ const templateBytes = await fs.readFile(imageTemplatePath);
339
+ const templateZip = await JSZip.loadAsync(templateBytes);
340
+ const sectionNames = Object.keys(templateZip.files).filter(isSectionEntry).sort();
341
+ for (const sectionName of sectionNames) {
342
+ const sectionFile = templateZip.file(sectionName);
343
+ if (!sectionFile) {
344
+ continue;
345
+ }
346
+ const xml = await sectionFile.async("string");
347
+ const doc = parseXml(xml);
348
+ const run = firstElementByXPath("//hp:run[hp:pic]", doc);
349
+ if (run) {
350
+ return new XMLSerializer().serializeToString(run);
351
+ }
352
+ }
353
+ throw new Error(`No template hp:run with hp:pic was found in image template: ${imageTemplatePath}`);
354
+ }
355
+ function parsePlaceholderInTextNode(text) {
356
+ const decoded = decodePlaceholderToken(text.trim());
357
+ const matched = IMAGE_PLACEHOLDER_RE.exec(decoded);
358
+ if (!matched) {
359
+ return null;
360
+ }
361
+ return { key: matched[1] };
362
+ }
363
+ async function ensureImageResource(params) {
364
+ const cached = params.cache.get(params.imageKey);
365
+ if (cached) {
366
+ return cached;
367
+ }
368
+ let fileBuffer;
369
+ try {
370
+ fileBuffer = await fs.readFile(params.imagePath);
371
+ }
372
+ catch (error) {
373
+ throw new Error(`Image file not found for key "${params.imageKey}": ${params.imagePath}`, { cause: error });
374
+ }
375
+ const details = detectImageTypeAndSize(fileBuffer);
376
+ const itemId = `image${params.nextImageIndexRef.value++}`;
377
+ const fileName = `${itemId}.${details.extension}`;
378
+ const zipEntryPath = `BinData/${fileName}`;
379
+ params.zip.file(zipEntryPath, fileBuffer);
380
+ ensureManifestItem(params.contentDoc, itemId, zipEntryPath, details.mediaType);
381
+ const resource = {
382
+ itemId,
383
+ fileName,
384
+ mediaType: details.mediaType,
385
+ originalWidth: Math.max(1, Math.round(details.width * 75)),
386
+ originalHeight: Math.max(1, Math.round(details.height * 75)),
387
+ };
388
+ params.cache.set(params.imageKey, resource);
389
+ return resource;
390
+ }
391
+ export async function replaceHwpxPlaceholders(input) {
392
+ const imageTemplatePath = input.imageTemplatePath ?? DEFAULT_TEMPLATE_PATH;
393
+ const [inputBytes] = await Promise.all([
394
+ fs.readFile(input.inputPath),
395
+ fs.access(imageTemplatePath),
396
+ ]);
397
+ const zip = await JSZip.loadAsync(inputBytes);
398
+ const unresolved = new Set();
399
+ const imageKeys = new Set(Object.keys(input.replacements.images));
400
+ let textReplacements = 0;
401
+ const allEntries = Object.keys(zip.files);
402
+ for (const entryName of allEntries) {
403
+ const entry = zip.file(entryName);
404
+ if (!entry || !isTextEntry(entryName)) {
405
+ continue;
406
+ }
407
+ const sourceText = await entry.async("string");
408
+ const replaced = replaceTextPlaceholders({
409
+ input: sourceText,
410
+ textValues: input.replacements.text,
411
+ imageKeys,
412
+ escapeOutput: entryName.endsWith(".xml") || entryName.endsWith(".hpf"),
413
+ unresolved,
414
+ });
415
+ textReplacements += replaced.replaced;
416
+ if (replaced.output !== sourceText) {
417
+ zip.file(entryName, replaced.output);
418
+ }
419
+ }
420
+ const templateRunXml = await loadTemplateRunXml(imageTemplatePath);
421
+ const contentEntry = zip.file("Contents/content.hpf");
422
+ if (!contentEntry) {
423
+ throw new Error("Input HWPX is missing Contents/content.hpf.");
424
+ }
425
+ const contentText = await contentEntry.async("string");
426
+ const contentDoc = parseXml(contentText);
427
+ const nextImageIndexRef = { value: findNextImageIndex(contentDoc) };
428
+ const imageResourceCache = new Map();
429
+ const sectionNames = allEntries.filter(isSectionEntry).sort();
430
+ const sectionDocs = new Map();
431
+ for (const sectionName of sectionNames) {
432
+ const sectionText = await zip.file(sectionName).async("string");
433
+ sectionDocs.set(sectionName, { original: sectionText, doc: parseXml(sectionText) });
434
+ }
435
+ const initialMax = collectMaxNumericAttributes(Array.from(sectionDocs.values(), (item) => item.doc));
436
+ let nextPicId = initialMax.maxId + 1;
437
+ let nextInstId = initialMax.maxInstId + 1;
438
+ let imageReplacements = 0;
439
+ for (const [sectionName, section] of sectionDocs) {
440
+ const runNodes = listElementsByXPath("//hp:run[hp:t]", section.doc);
441
+ let changed = false;
442
+ for (const runNode of runNodes) {
443
+ const textNode = firstElementByXPath("./hp:t", runNode);
444
+ if (!textNode || textNode.textContent === null) {
445
+ continue;
446
+ }
447
+ const placeholder = parsePlaceholderInTextNode(textNode.textContent);
448
+ if (!placeholder) {
449
+ continue;
450
+ }
451
+ const imagePath = input.replacements.images[placeholder.key];
452
+ if (!imagePath) {
453
+ continue;
454
+ }
455
+ const imageResource = await ensureImageResource({
456
+ zip,
457
+ contentDoc,
458
+ cache: imageResourceCache,
459
+ imageKey: placeholder.key,
460
+ imagePath,
461
+ nextImageIndexRef,
462
+ });
463
+ const box = resolvePlaceholderBox(runNode);
464
+ const displaySize = calculateDisplaySize({
465
+ pixelWidth: Math.max(1, Math.round(imageResource.originalWidth / 75)),
466
+ pixelHeight: Math.max(1, Math.round(imageResource.originalHeight / 75)),
467
+ maxWidth: box.width,
468
+ maxHeight: box.height,
469
+ });
470
+ const newRun = buildRunFromTemplate({
471
+ templateRunXml,
472
+ charPrIDRef: runNode.getAttribute("charPrIDRef"),
473
+ imageResource,
474
+ displaySize,
475
+ picId: nextPicId++,
476
+ instId: nextInstId++,
477
+ });
478
+ const parent = runNode.parentNode;
479
+ if (!parent) {
480
+ continue;
481
+ }
482
+ const importedNode = section.doc.importNode
483
+ ? section.doc.importNode(newRun, true)
484
+ : newRun.cloneNode(true);
485
+ parent.replaceChild(importedNode, runNode);
486
+ const paragraph = importedNode.nodeType === importedNode.ELEMENT_NODE
487
+ ? getRunParagraph(importedNode)
488
+ : null;
489
+ const lineSeg = paragraph
490
+ ? firstElementByXPath("./hp:linesegarray/hp:lineseg", paragraph)
491
+ : null;
492
+ if (lineSeg) {
493
+ lineSeg.setAttribute("horzsize", "0");
494
+ }
495
+ imageReplacements += 1;
496
+ changed = true;
497
+ }
498
+ if (changed) {
499
+ const serialized = serializeXml(section.doc, section.original);
500
+ zip.file(sectionName, serialized);
501
+ }
502
+ }
503
+ const updatedContent = serializeXml(contentDoc, contentText);
504
+ zip.file("Contents/content.hpf", updatedContent);
505
+ const outputBytes = await zip.generateAsync({
506
+ type: "nodebuffer",
507
+ compression: "DEFLATE",
508
+ compressionOptions: { level: 9 },
509
+ });
510
+ await fs.mkdir(path.dirname(input.outputPath), { recursive: true });
511
+ await fs.writeFile(input.outputPath, outputBytes);
512
+ return {
513
+ textReplacements,
514
+ imageReplacements,
515
+ unresolvedPlaceholders: [...unresolved].sort(),
516
+ };
517
+ }
518
+ //# sourceMappingURL=render-hwpx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-hwpx.js","sourceRoot":"","sources":["../src/render-hwpx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,MAAM,OAAO,CAAC;AA+B1B,MAAM,qBAAqB,GAAG,IAAI,CAAC,OAAO,CACxC,OAAO,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E,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;IAElD,OAAO;QACL,gBAAgB;QAChB,iBAAiB;QACjB,sBAAsB,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,EAAE;KAC/C,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "auto-hwpx",
3
+ "version": "0.1.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "description": "TypeScript utility for replacing text and image placeholders in HWPX files.",
8
+ "bin": {
9
+ "auto-hwpx": "./dist/cli.js"
10
+ },
11
+ "main": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "engines": {
25
+ "node": ">=18"
26
+ },
27
+ "keywords": [
28
+ "hwpx",
29
+ "hwp",
30
+ "cli",
31
+ "template",
32
+ "document"
33
+ ],
34
+ "scripts": {
35
+ "build": "tsc -p tsconfig.build.json",
36
+ "typecheck": "tsc -p tsconfig.json",
37
+ "test": "vitest run",
38
+ "test:watch": "vitest",
39
+ "start": "node --import tsx src/cli.ts",
40
+ "demo": "node --import tsx scripts/demo.ts",
41
+ "prepublishOnly": "npm run test && npm run build"
42
+ },
43
+ "dependencies": {
44
+ "@xmldom/xmldom": "^0.8.10",
45
+ "commander": "^13.1.0",
46
+ "image-size": "^2.0.2",
47
+ "jszip": "^3.10.1",
48
+ "xpath": "^0.0.34"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^22.15.18",
52
+ "tsx": "^4.20.3",
53
+ "typescript": "^5.8.3",
54
+ "vitest": "^3.1.2"
55
+ }
56
+ }