hwpx2f 0.0.0-stage → 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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -2
  3. package/THIRD_PARTY_NOTICES.md +75 -0
  4. package/dist/cli.js +76 -0
  5. package/dist/index.d.ts +11 -0
  6. package/dist/index.js +32 -0
  7. package/dist/lib/chunk-36PRCVPO.js +131 -0
  8. package/dist/lib/chunk-45BAITEX.js +9749 -0
  9. package/dist/lib/chunk-4NRZ6MWV.js +133 -0
  10. package/dist/lib/chunk-6CFXTS7A.js +11971 -0
  11. package/dist/lib/chunk-6CPCDYOD.js +104 -0
  12. package/dist/lib/chunk-B6MTS4XP.js +313 -0
  13. package/dist/lib/chunk-BX24E7EG.js +1427 -0
  14. package/dist/lib/chunk-C64I2SU4.js +82 -0
  15. package/dist/lib/chunk-CEKQASS3.js +258 -0
  16. package/dist/lib/chunk-CMWTKXM2.js +204 -0
  17. package/dist/lib/chunk-E6KSYRHG.js +2189 -0
  18. package/dist/lib/chunk-IZDWVMTV.js +28786 -0
  19. package/dist/lib/chunk-JK6YR5NT.js +4276 -0
  20. package/dist/lib/chunk-O6FSHPNE.js +111 -0
  21. package/dist/lib/chunk-OYXOOP2U.js +199 -0
  22. package/dist/lib/chunk-PM4KBWF4.js +49 -0
  23. package/dist/lib/chunk-R5F3GHLO.js +290 -0
  24. package/dist/lib/chunk-R76DWHJR.js +1596 -0
  25. package/dist/lib/chunk-RFS3RTSR.js +6876 -0
  26. package/dist/lib/chunk-RYJRNK5Z.js +47 -0
  27. package/dist/lib/chunk-UOXPGSFH.js +43 -0
  28. package/dist/lib/chunk-UZH4UBMX.js +44 -0
  29. package/dist/lib/chunk-VZTE4GKI.js +52 -0
  30. package/dist/lib/chunk-WEOKEO6L.js +35291 -0
  31. package/dist/lib/detect-4XZNNYZA-O7IPA4XQ.js +32 -0
  32. package/dist/lib/dist-HVSOXNCJ.js +263 -0
  33. package/dist/lib/formula-LC62GV4D-K3VFC5GV.js +1173 -0
  34. package/dist/lib/generator-KYTTL4OS-TRAQ66QE.js +14 -0
  35. package/dist/lib/hancom-EM62ZVDM-WZKVI7XB.js +91 -0
  36. package/dist/lib/image-ocr-ZUZQXLYS-U66LBMRA.js +293 -0
  37. package/dist/lib/page-images-VCIFZAXK-KJLWQDRH.js +95 -0
  38. package/dist/lib/page-range-7R3JU6SQ-MDDQRZVK.js +10 -0
  39. package/dist/lib/parser-JQNH5QMM-HFFI4HYK.js +4310 -0
  40. package/dist/lib/pdf-ocr-C3MBR6J2-J3UGJKWT.js +46 -0
  41. package/dist/lib/to-hwpx-JUT2SOTT-MOPPK6OW.js +17 -0
  42. package/dist/notices/core-util-is/LICENSE +19 -0
  43. package/dist/notices/entities/LICENSE +11 -0
  44. package/dist/notices/immediate/LICENSE.txt +20 -0
  45. package/dist/notices/inherits/LICENSE +16 -0
  46. package/dist/notices/jszip/LICENSE.markdown +651 -0
  47. package/dist/notices/kordoc/LICENSE +21 -0
  48. package/dist/notices/kordoc/NOTICE +376 -0
  49. package/dist/notices/kordoc/THIRD_PARTY/apache-2.0.LICENSE +201 -0
  50. package/dist/notices/kordoc/THIRD_PARTY/claw-hwp.LICENSE +21 -0
  51. package/dist/notices/kordoc/THIRD_PARTY/hayro-pdf.txt +361 -0
  52. package/dist/notices/kordoc/THIRD_PARTY/hml-equation-parser.LICENSE +201 -0
  53. package/dist/notices/kordoc/THIRD_PARTY/hml-equation-parser.txt +35 -0
  54. package/dist/notices/kordoc/THIRD_PARTY/korean-report-hwpx.LICENSE +21 -0
  55. package/dist/notices/kordoc/THIRD_PARTY/memchr.LICENSE +21 -0
  56. package/dist/notices/kordoc/THIRD_PARTY/opendataloader-pdf.txt +32 -0
  57. package/dist/notices/kordoc/THIRD_PARTY/pix2text.txt +17 -0
  58. package/dist/notices/kordoc/THIRD_PARTY/quick-xml.LICENSE +23 -0
  59. package/dist/notices/kordoc/THIRD_PARTY/rhwp-forms.txt +35 -0
  60. package/dist/notices/lie/license.md +7 -0
  61. package/dist/notices/linkify-it/LICENSE +22 -0
  62. package/dist/notices/markdown-it/LICENSE +22 -0
  63. package/dist/notices/mdurl/LICENSE +45 -0
  64. package/dist/notices/pako/LICENSE +21 -0
  65. package/dist/notices/process-nextick-args/license.md +19 -0
  66. package/dist/notices/punycode.js/LICENSE-MIT.txt +20 -0
  67. package/dist/notices/readable-stream/LICENSE +47 -0
  68. package/dist/notices/safe-buffer/LICENSE +21 -0
  69. package/dist/notices/setimmediate/LICENSE.txt +20 -0
  70. package/dist/notices/string_decoder/LICENSE +48 -0
  71. package/dist/notices/uc.micro/LICENSE.txt +20 -0
  72. package/dist/notices/util-deprecate/LICENSE +24 -0
  73. package/package.json +66 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 seongWan03
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.
package/README.md CHANGED
@@ -1,3 +1,125 @@
1
- # Temporary Holding Version
1
+ # hwpx2f
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Convert Korean Hangul word processor documents (`.hwp`, `.hwpx`) to hwp, hwpx, Markdown, PDF or
4
+ Word (`.docx`) from the command line. Runs on Node.js, no Hancom Office needed.
5
+
6
+ ## Install
7
+
8
+ ```
9
+ npx hwpx2f <file> <format> # run without installing
10
+ npm i -g hwpx2f # or install the `hwpx2f` command globally
11
+ ```
12
+
13
+ Requires Node.js 20 or newer.
14
+
15
+ ## Usage
16
+
17
+ ```
18
+ hwpx2f <file> <hwp|hwpx|md|pdf|word> [-o <path>] [-f]
19
+ ```
20
+
21
+ - `<file>` is an HWP 5.x (`.hwp`) or HWPX (`.hwpx`) document. The type is detected from the file
22
+ content, not the extension.
23
+ - `<format>` is the target: `hwp`, `hwpx`, `md`, `pdf` or `word` (writes `.docx`).
24
+ - On success the output path is printed. On failure a one-line error is printed and the exit code is 1
25
+ (set `HWPX2F_DEBUG=1` to also see the underlying error).
26
+
27
+ Where the output goes:
28
+
29
+ | `-o` | Output |
30
+ |---|---|
31
+ | (none) | next to the input: `<input name>.<ext>` |
32
+ | an existing directory, or a path ending in `/` | `<dir>/<input name>.<ext>` (the directory is created if needed) |
33
+ | a path with a file extension | exactly that path (the format argument still decides the content) |
34
+ | a path without an extension that does not exist | treated as a directory |
35
+
36
+ `<ext>` is `hwp`, `hwpx`, `md`, `pdf` or `docx`. Converting to the input's own format is an error,
37
+ and the input file is never overwritten. An existing file at the output path is left alone unless
38
+ `-f` / `--force` is given, and hwpx2f never writes through a symbolic link.
39
+
40
+ ```
41
+ hwpx2f report.hwp md # -> report.md
42
+ hwpx2f report.hwpx pdf -o out/ # -> out/report.pdf
43
+ hwpx2f report.hwp word -o ~/final.docx # -> ~/final.docx
44
+ ```
45
+
46
+ Programmatic use:
47
+
48
+ ```js
49
+ import { convert } from 'hwpx2f';
50
+ const outPath = await convert('report.hwp', 'md'); // same -o rules as the CLI
51
+ await convert('report.hwp', 'pdf', 'out/');
52
+ ```
53
+
54
+ ## Conversions and fidelity
55
+
56
+ | From \ To | hwp | hwpx | md | pdf | word |
57
+ |---|---|---|---|---|---|
58
+ | hwp | - | yes | yes | yes | yes |
59
+ | hwpx | yes | - | yes | yes | yes |
60
+
61
+ - **hwp <-> hwpx**: done by [rhwp](https://github.com/edwardkim/rhwp) (`exportHwp` / `exportHwpx`).
62
+ The document model is re-serialized, so text, tables and formatting are kept for documents rhwp
63
+ understands; unusual content may be lost or changed. Check important documents in Hancom Office.
64
+ - **md**: done by [kordoc](https://github.com/chrisryugj/kordoc). Headings, paragraphs, lists and
65
+ tables (GFM pipe tables, or HTML tables for merged cells). Images are not extracted: the Markdown
66
+ keeps only a placeholder reference. Page layout, fonts and colors are dropped.
67
+ - **word** (`.docx`): built with [docx](https://github.com/dolanmiu/docx) from the same structure
68
+ kordoc reads: headings, paragraphs (bold/italic/underline/strike where known), lists and tables
69
+ (including merged cells and nested tables). Images, page setup, headers/footers and exact layout
70
+ are not carried over.
71
+ - **pdf**: each page is laid out by rhwp, rendered to SVG and drawn into the PDF with
72
+ [PDFKit](https://pdfkit.org) and [SVG-to-PDFKit](https://github.com/alafr/SVG-to-PDFKit). Page
73
+ count and page size follow the document, and text is real, selectable text. All text is drawn
74
+ with one Korean font (see below), so it will not look identical to Hancom Office; bold and
75
+ italic are synthesized. Only embedded PNG/JPEG images are drawn.
76
+
77
+ ### Fonts for PDF
78
+
79
+ PDF output needs a font with Hangul glyphs. hwpx2f does not bundle one; it looks in the usual
80
+ system font folders (Linux, macOS, Windows) for, in order: Nanum Gothic, Nanum Barun Gothic,
81
+ Malgun Gothic, Apple SD Gothic Neo, Noto Sans KR / Noto Sans CJK, Source Han Sans KR, Un Dotum,
82
+ AppleGothic, Gulim. To choose a font yourself, set `HWPX2F_FONT=/path/to/font.ttf` (`.ttf`,
83
+ `.otf` or `.ttc`). If no usable font is found, hwpx2f stops with an error instead of writing a PDF
84
+ with missing text. On Debian/Ubuntu: `sudo apt install fonts-nanum`.
85
+
86
+ ## Limits and safety
87
+
88
+ Input files are treated as untrusted: files over 200 MB (or HWPX files declaring more than 32 MB of
89
+ XML) are rejected, control characters and remote-image syntax are neutralised in Markdown output,
90
+ nothing is executed or
91
+ shelled out, external files or URLs referenced by a document are not loaded (only images embedded in
92
+ the document are used), and library errors are reported as one line without stack traces.
93
+
94
+ Conversion time and memory are not bounded: a small hostile document can keep the converter busy
95
+ for minutes. When converting documents in bulk from unknown sources, run hwpx2f under a timeout.
96
+ Converted text is still document content — if you feed it to an AI agent, treat it as data, not
97
+ instructions.
98
+
99
+ ## Use from AI agents
100
+
101
+ - **Claude Code**: this repo is a plugin with the skill `skills/hwpx2f/SKILL.md`
102
+ (`/plugin install` from a marketplace that lists it, or copy the skill folder into
103
+ `~/.claude/skills/`).
104
+ - **Codex and other agents** read `AGENTS.md`.
105
+ - **Gemini CLI**: `gemini-extension.json` loads `AGENTS.md` as context.
106
+
107
+ All of them just run `npx -y hwpx2f <file> <format> [-o <path>]`.
108
+
109
+ ## Development
110
+
111
+ ```
112
+ npm install
113
+ npm test # builds dist/ and runs the tests with node --test
114
+ ```
115
+
116
+ `test/make-fixtures.mjs` regenerates the test documents.
117
+
118
+ ## License
119
+
120
+ [MIT](LICENSE). Third-party licenses are listed in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
121
+
122
+ Built on [rhwp](https://github.com/edwardkim/rhwp) (HWP/HWPX parsing, conversion and layout),
123
+ [kordoc](https://github.com/chrisryugj/kordoc) (HWP/HWPX to Markdown),
124
+ [docx](https://github.com/dolanmiu/docx), [PDFKit](https://pdfkit.org),
125
+ [SVG-to-PDFKit](https://github.com/alafr/SVG-to-PDFKit) and [fontkit](https://github.com/foliojs/fontkit).
@@ -0,0 +1,75 @@
1
+ # Third-party notices
2
+
3
+ hwpx2f is MIT licensed (see `LICENSE`). It uses the packages below. Versions are the ones this
4
+ release was built and tested with.
5
+
6
+ ## Runtime dependencies (installed from npm with hwpx2f)
7
+
8
+ Each keeps its own license file in its `node_modules` folder. `@rhwp/core` also ships a `notices/`
9
+ directory (`THIRD_PARTY_LICENSES.md`, font and codec licenses) that covers the Rust crates and data
10
+ compiled into its WebAssembly module; it is installed unchanged as a normal dependency.
11
+
12
+ | Package | Version | License | URL |
13
+ |---|---|---|---|
14
+ | @rhwp/core | 0.9.1 | MIT | https://github.com/edwardkim/rhwp |
15
+ | docx | 9.16.2 | MIT | https://github.com/dolanmiu/docx |
16
+ | pdfkit | 0.21.0 | MIT | https://github.com/foliojs/pdfkit |
17
+ | svg-to-pdfkit | 0.1.8 | MIT | https://github.com/alafr/SVG-to-PDFKit |
18
+ | fontkit | 3.0.0 | MIT | https://github.com/foliojs/fontkit |
19
+ | cfb (required at runtime by the bundled kordoc) | 1.2.2 | Apache-2.0 | https://github.com/SheetJS/js-cfb |
20
+ | adler-32 | 1.3.1 | Apache-2.0 | https://github.com/SheetJS/js-adler32 |
21
+ | crc-32 | 1.2.2 | Apache-2.0 | https://github.com/SheetJS/js-crc32 |
22
+ | brotli | 2.2.0 | MIT | https://github.com/devongovett/brotli.js |
23
+ | dfa | 2.0.0 | MIT | https://github.com/devongovett/dfa |
24
+ | fflate | 0.8.3 | MIT | https://github.com/101arrowz/fflate |
25
+ | linebreak | 2.1.0 | MIT | https://github.com/devongovett/linebreaker |
26
+ | nanoid | 6.0.2 | MIT | https://github.com/ai/nanoid |
27
+ | @noble/ciphers | 2.4.0 | MIT | https://github.com/paulmillr/noble-ciphers |
28
+ | @noble/hashes | 2.4.0 | MIT | https://github.com/paulmillr/noble-hashes |
29
+ | png-js | 3.0.0 | MIT | https://github.com/devongovett/png.js |
30
+ | restructure | 3.0.2 | MIT | https://github.com/devongovett/restructure |
31
+ | unicode-properties | 2.0.2 | MIT | https://github.com/devongovett/unicode-properties |
32
+ | unicode-trie | 3.0.0 | MIT | https://github.com/devongovett/unicode-trie |
33
+ | @types/node (declared as a dependency by docx) | 26.6.11 | MIT | https://github.com/DefinitelyTyped/DefinitelyTyped |
34
+ | undici-types | 8.9.0 | MIT | https://github.com/nodejs/undici |
35
+
36
+ ## Bundled into `dist/` (not installed separately)
37
+
38
+ `kordoc` is bundled at build time so that installing hwpx2f does not also install kordoc's optional
39
+ OCR and image packages (`onnxruntime-node`, `sharp` with LGPL-3.0 `libvips`, `@hyzyla/pdfium`, ...),
40
+ which hwpx2f never uses. The license and notice files of every bundled package are copied to
41
+ `dist/notices/<package>/`, including kordoc's `NOTICE` and `THIRD_PARTY` files.
42
+
43
+ | Package | Version | License | URL |
44
+ |---|---|---|---|
45
+ | kordoc | 4.25.40 | MIT | https://github.com/chrisryugj/kordoc |
46
+ | jszip | 3.10.2 | MIT OR GPL-3.0-or-later (used under MIT) | https://github.com/Stuk/jszip |
47
+ | pako | 1.0.11 | MIT AND Zlib | https://github.com/nodeca/pako |
48
+ | lie | 3.3.0 | MIT | https://github.com/calvinmetcalf/lie |
49
+ | immediate | 3.0.6 | MIT | https://github.com/calvinmetcalf/immediate |
50
+ | setimmediate | 1.0.5 | MIT | https://github.com/YuzuJS/setImmediate |
51
+ | readable-stream | 2.3.8 | MIT | https://github.com/nodejs/readable-stream |
52
+ | string_decoder | 1.1.1 | MIT | https://github.com/nodejs/string_decoder |
53
+ | safe-buffer | 5.1.2 | MIT | https://github.com/feross/safe-buffer |
54
+ | core-util-is | 1.0.3 | MIT | https://github.com/isaacs/core-util-is |
55
+ | inherits | 2.0.4 | ISC | https://github.com/isaacs/inherits |
56
+ | isarray | 1.0.0 | MIT (Copyright (c) 2013 Julian Gruber; the package has no license file) | https://github.com/juliangruber/isarray |
57
+ | process-nextick-args | 2.0.1 | MIT | https://github.com/calvinmetcalf/process-nextick-args |
58
+ | util-deprecate | 1.0.2 | MIT | https://github.com/TooTallNate/util-deprecate |
59
+ | markdown-it | 14.3.3 | MIT | https://github.com/markdown-it/markdown-it |
60
+ | linkify-it | 5.0.2 | MIT | https://github.com/markdown-it/linkify-it |
61
+ | mdurl | 2.1.0 | MIT | https://github.com/markdown-it/mdurl |
62
+ | uc.micro | 2.1.0 | MIT | https://github.com/markdown-it/uc.micro |
63
+ | punycode.js | 2.3.1 | MIT | https://github.com/mathiasbynens/punycode.js |
64
+ | entities | 4.5.0 | BSD-2-Clause | https://github.com/fb55/entities |
65
+
66
+ ## Fonts
67
+
68
+ No font is bundled. PDF output uses a Korean font already installed on the system (or the file in
69
+ `HWPX2F_FONT`); the used glyphs are embedded in the PDF as a subset under that font's own license.
70
+
71
+ ## Test fixtures
72
+
73
+ `test/fixtures/sample.hwpx` and `sample.hwp` were generated for this project by
74
+ `test/make-fixtures.mjs` (kordoc `markdownToHwpx`, then `@rhwp/core` `exportHwp`). They contain only
75
+ text written for the tests.
package/dist/cli.js ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __hwpx2fRequire } from 'node:module'; const require = __hwpx2fRequire(import.meta.url);
3
+ import {
4
+ FORMATS,
5
+ Hwpx2fError,
6
+ convert
7
+ } from "./lib/chunk-R5F3GHLO.js";
8
+ import "./lib/chunk-WEOKEO6L.js";
9
+ import "./lib/chunk-IZDWVMTV.js";
10
+ import "./lib/chunk-36PRCVPO.js";
11
+ import "./lib/chunk-RFS3RTSR.js";
12
+ import "./lib/chunk-BX24E7EG.js";
13
+ import "./lib/chunk-6CPCDYOD.js";
14
+ import "./lib/chunk-4NRZ6MWV.js";
15
+ import "./lib/chunk-CMWTKXM2.js";
16
+ import "./lib/chunk-45BAITEX.js";
17
+ import "./lib/chunk-C64I2SU4.js";
18
+ import "./lib/chunk-UOXPGSFH.js";
19
+ import "./lib/chunk-E6KSYRHG.js";
20
+ import "./lib/chunk-VZTE4GKI.js";
21
+ import "./lib/chunk-UZH4UBMX.js";
22
+ import "./lib/chunk-CEKQASS3.js";
23
+ import "./lib/chunk-O6FSHPNE.js";
24
+ import "./lib/chunk-R76DWHJR.js";
25
+ import "./lib/chunk-B6MTS4XP.js";
26
+ import "./lib/chunk-PM4KBWF4.js";
27
+ import "./lib/chunk-OYXOOP2U.js";
28
+ import "./lib/chunk-RYJRNK5Z.js";
29
+
30
+ // src/cli.ts
31
+ import { readFileSync } from "node:fs";
32
+ import { parseArgs } from "node:util";
33
+ var USAGE = `Usage: hwpx2f <file> <hwp|hwpx|md|pdf|word> [-o <path>] [-f]
34
+
35
+ Convert a Korean Hangul document (.hwp or .hwpx) to another format.
36
+
37
+ Arguments:
38
+ <file> input .hwp or .hwpx file (detected by content)
39
+ <format> hwp, hwpx, md, pdf, or word (.docx)
40
+
41
+ Options:
42
+ -o <path> output file, or a directory (existing, or ending in "/")
43
+ default: next to the input, as <name>.<ext>
44
+ -f, --force replace an existing output file
45
+ -h, --help show this help
46
+ -v, --version show the version`;
47
+ function fail(message, err) {
48
+ console.error(`hwpx2f: ${message}`);
49
+ if (process.env.HWPX2F_DEBUG && err) console.error(err);
50
+ process.exit(1);
51
+ }
52
+ var args;
53
+ try {
54
+ args = parseArgs({
55
+ allowPositionals: true,
56
+ options: { output: { type: "string", short: "o" }, force: { type: "boolean", short: "f" }, help: { type: "boolean", short: "h" }, version: { type: "boolean", short: "v" } }
57
+ });
58
+ } catch (e) {
59
+ fail(`${e.message.split("\n")[0]} (see --help)`);
60
+ }
61
+ var { values, positionals } = args;
62
+ if (values.help) {
63
+ console.log(USAGE);
64
+ } else if (values.version) {
65
+ console.log(JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version);
66
+ } else {
67
+ if (positionals.length !== 2) fail("expected <file> and <format> (see --help)");
68
+ const [file, format] = positionals;
69
+ if (!FORMATS.includes(format)) fail(`unknown format "${format}" (expected one of: ${FORMATS.join(", ")})`);
70
+ try {
71
+ console.log(await convert(file, format, values.output, values.force));
72
+ } catch (e) {
73
+ if (e instanceof Hwpx2fError) fail(e.message + (e.cause && !process.env.HWPX2F_DEBUG ? " (set HWPX2F_DEBUG=1 for details)" : ""), e.cause ?? e);
74
+ fail(String(e?.message ?? e).split("\n")[0], e);
75
+ }
76
+ }
@@ -0,0 +1,11 @@
1
+ export type Format = 'hwp' | 'hwpx' | 'md' | 'pdf' | 'word';
2
+ export declare const FORMATS: readonly Format[];
3
+ /** Error with a message that is safe to show to the user as-is. */
4
+ export declare class Hwpx2fError extends Error {
5
+ }
6
+ /**
7
+ * Convert an .hwp/.hwpx file to `format` and write the result.
8
+ * `outPath` follows the CLI `-o` rules. An existing output file is only replaced when `force` is set.
9
+ * Returns the absolute output path.
10
+ */
11
+ export declare function convert(inputPath: string, format: Format, outPath?: string, force?: boolean): Promise<string>;
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ import { createRequire as __hwpx2fRequire } from 'node:module'; const require = __hwpx2fRequire(import.meta.url);
2
+ import {
3
+ FORMATS,
4
+ Hwpx2fError,
5
+ convert
6
+ } from "./lib/chunk-R5F3GHLO.js";
7
+ import "./lib/chunk-WEOKEO6L.js";
8
+ import "./lib/chunk-IZDWVMTV.js";
9
+ import "./lib/chunk-36PRCVPO.js";
10
+ import "./lib/chunk-RFS3RTSR.js";
11
+ import "./lib/chunk-BX24E7EG.js";
12
+ import "./lib/chunk-6CPCDYOD.js";
13
+ import "./lib/chunk-4NRZ6MWV.js";
14
+ import "./lib/chunk-CMWTKXM2.js";
15
+ import "./lib/chunk-45BAITEX.js";
16
+ import "./lib/chunk-C64I2SU4.js";
17
+ import "./lib/chunk-UOXPGSFH.js";
18
+ import "./lib/chunk-E6KSYRHG.js";
19
+ import "./lib/chunk-VZTE4GKI.js";
20
+ import "./lib/chunk-UZH4UBMX.js";
21
+ import "./lib/chunk-CEKQASS3.js";
22
+ import "./lib/chunk-O6FSHPNE.js";
23
+ import "./lib/chunk-R76DWHJR.js";
24
+ import "./lib/chunk-B6MTS4XP.js";
25
+ import "./lib/chunk-PM4KBWF4.js";
26
+ import "./lib/chunk-OYXOOP2U.js";
27
+ import "./lib/chunk-RYJRNK5Z.js";
28
+ export {
29
+ FORMATS,
30
+ Hwpx2fError,
31
+ convert
32
+ };
@@ -0,0 +1,131 @@
1
+ import { createRequire as __hwpx2fRequire } from 'node:module'; const require = __hwpx2fRequire(import.meta.url);
2
+
3
+ // node_modules/kordoc/dist/chunk-IXQ45P43.js
4
+ import { execFile } from "child_process";
5
+ import { platform } from "os";
6
+ import { win32 } from "path";
7
+ import { promisify } from "util";
8
+ var execFileAsync = promisify(execFile);
9
+ function powershellPath() {
10
+ return win32.join(process.env.SystemRoot || process.env.windir || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
11
+ }
12
+ var NO_HANCOM_ENV = "KORDOC_NO_HANCOM";
13
+ function hancomAllowed(options) {
14
+ return platform() === "win32" && options?.hancomFallback !== false && process.env[NO_HANCOM_ENV] !== "1";
15
+ }
16
+ function isComFallbackAvailable(options) {
17
+ return hancomAllowed(options);
18
+ }
19
+ function isEncryptedHwpx(manifestXml) {
20
+ return manifestXml.includes("encryption-data");
21
+ }
22
+ async function extractTextViaCom(filePath) {
23
+ if (platform() !== "win32") {
24
+ throw new Error("COM fallback\uC740 Windows\uC5D0\uC11C\uB9CC \uC0AC\uC6A9 \uAC00\uB2A5\uD569\uB2C8\uB2E4");
25
+ }
26
+ const { args, env } = comPowerShellInvocation(filePath);
27
+ const { stdout } = await execFileAsync(powershellPath(), args, {
28
+ encoding: "utf-8",
29
+ env,
30
+ timeout: 12e4,
31
+ // 2분 타임아웃
32
+ windowsHide: true,
33
+ maxBuffer: 50 * 1024 * 1024
34
+ // 50MB
35
+ });
36
+ const trimmed = stdout.trim();
37
+ const jsonStart = trimmed.indexOf("{");
38
+ if (jsonStart < 0) throw new Error(`COM \uCD9C\uB825\uC5D0 JSON\uC774 \uC5C6\uC2B5\uB2C8\uB2E4: ${trimmed.slice(0, 200)}`);
39
+ const json = JSON.parse(trimmed.slice(jsonStart));
40
+ if (json.error) {
41
+ throw new Error(`COM \uD14D\uC2A4\uD2B8 \uCD94\uCD9C \uC2E4\uD328: ${json.error}`);
42
+ }
43
+ const warnings = [];
44
+ const pages = Array.isArray(json.pages) ? json.pages : [];
45
+ const pageCount = json.pageCount ?? pages.length;
46
+ if (pages.length === 0) {
47
+ warnings.push({ message: "COM\uC73C\uB85C \uD14D\uC2A4\uD2B8\uB97C \uCD94\uCD9C\uD558\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4", code: "COM_EMPTY" });
48
+ }
49
+ return { pages, pageCount, warnings };
50
+ }
51
+ function comPowerShellInvocation(filePath) {
52
+ const ps1 = `
53
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
54
+ $ErrorActionPreference = 'Stop'
55
+
56
+ $src = $env:KORDOC_COM_SRC
57
+ $tmpDir = Join-Path $env:TEMP ('hwp-com-' + [guid]::NewGuid().ToString('N'))
58
+
59
+ try {
60
+ # \uD3F4\uB354 \uB9CC\uB4E4\uAE30\xB7\uBCF5\uC0AC\uB3C4 try \uC548 \u2014 \uBCF5\uC0AC\uAC00 \uC2E4\uD328\uD574\uB3C4 finally \uAC00 \uC784\uC2DC \uD3F4\uB354\uB97C \uC9C0\uC6B4\uB2E4 (#177)
61
+ [void](New-Item -ItemType Directory -Path $tmpDir -Force)
62
+ $tmpFile = Join-Path $tmpDir (Split-Path $src -Leaf)
63
+ Copy-Item -LiteralPath $src -Destination $tmpFile -Force
64
+ $hwp = New-Object -ComObject HWPFrame.HwpObject
65
+ $hwp.RegisterModule('FilePathCheckDLL', 'FilePathCheckerModuleExample') | Out-Null
66
+ # suspendpassword: \uC5F4\uAE30 \uC554\uD638\uAC00 \uAC78\uB9B0 \uBB38\uC11C\uB294 \uC554\uD638 \uC785\uB825 \uCC3D\uC744 \uB744\uC6B0\uC9C0 \uC54A\uACE0 \uBC14\uB85C \uC2E4\uD328 \u2014 \uC228\uC740 \uCC3D\uC774 \uC785\uB825\uC744 \uAE30\uB2E4\uB9AC\uBA70 \uBA48\uCD94\uB358 \uAC83 (#93)
67
+ $opened = $hwp.Open($tmpFile, '', 'suspendpassword:TRUE;forceopen:TRUE;versionwarning:FALSE')
68
+ if (-not $opened) { throw 'Open \uC2E4\uD328 (\uC5F4\uAE30 \uC554\uD638\uAC00 \uAC78\uB9B0 \uBB38\uC11C\uC77C \uC218 \uC788\uC74C)' }
69
+ $pc = $hwp.PageCount
70
+ $result = @{ pageCount = $pc; pages = @() }
71
+ for ($p = 1; $p -le $pc; $p++) {
72
+ $t = $hwp.GetPageText($p, 0)
73
+ $result.pages += @($t)
74
+ }
75
+ $hwp.Clear(1) | Out-Null
76
+ try { $hwp.Quit() | Out-Null } catch { }
77
+ [System.Runtime.InteropServices.Marshal]::ReleaseComObject($hwp) | Out-Null
78
+ [GC]::Collect()
79
+ [GC]::WaitForPendingFinalizers()
80
+ $result | ConvertTo-Json -Depth 3 -Compress
81
+ } catch {
82
+ @{ error = $_.Exception.Message } | ConvertTo-Json -Compress
83
+ } finally {
84
+ # \uC784\uC2DC \uD30C\uC77C \uC815\uB9AC + \uC880\uBE44 Hwp.exe \uBC29\uC9C0\uC6A9 garbage collect
85
+ try { Remove-Item -LiteralPath $tmpDir -Recurse -Force -ErrorAction SilentlyContinue } catch { }
86
+ [GC]::Collect()
87
+ [GC]::WaitForPendingFinalizers()
88
+ }
89
+ `;
90
+ return {
91
+ args: ["-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-Command", ps1],
92
+ env: { ...process.env, KORDOC_COM_SRC: filePath }
93
+ };
94
+ }
95
+ function comResultToParseResult(pages, pageCount, warnings) {
96
+ const blocks = [];
97
+ const lines = [];
98
+ for (let i = 0; i < pages.length; i++) {
99
+ const text = (pages[i] ?? "").trim();
100
+ if (!text) continue;
101
+ const paragraphs = text.split(/\n/);
102
+ for (const para of paragraphs) {
103
+ const trimmed = para.trim();
104
+ if (!trimmed) continue;
105
+ blocks.push({ type: "paragraph", text: trimmed, pageNumber: i + 1 });
106
+ lines.push(trimmed);
107
+ }
108
+ }
109
+ const markdown = lines.join("\n\n");
110
+ const metadata = { pageCount, pageMode: "layout" };
111
+ warnings.push({
112
+ message: "DRM \uBB38\uC11C: \uD55C\uCEF4 COM API\uB85C \uD14D\uC2A4\uD2B8 \uCD94\uCD9C (\uC11C\uC2DD/\uD45C \uC815\uBCF4 \uC81C\uD55C\uC801)",
113
+ code: "DRM_COM_FALLBACK"
114
+ });
115
+ return {
116
+ markdown,
117
+ blocks,
118
+ metadata,
119
+ warnings: warnings.length > 0 ? warnings : void 0
120
+ };
121
+ }
122
+
123
+ export {
124
+ powershellPath,
125
+ NO_HANCOM_ENV,
126
+ hancomAllowed,
127
+ isComFallbackAvailable,
128
+ isEncryptedHwpx,
129
+ extractTextViaCom,
130
+ comResultToParseResult
131
+ };