bare-x-to-pdf 0.2.0 → 0.3.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/CMakeLists.txt CHANGED
@@ -6,11 +6,10 @@ find_package(cmake-fetch REQUIRED PATHS node_modules/cmake-fetch)
6
6
  project(simple_converter C)
7
7
 
8
8
  include(cmake/rust.cmake)
9
- include(cmake/pdfium.cmake)
10
9
 
11
10
  bare_target(target)
12
11
 
13
- add_bare_module(simple_converter NAME bare-x-to-pdf-${target} INSTALL TARGET pdfium)
12
+ add_bare_module(simple_converter NAME bare-x-to-pdf-${target})
14
13
 
15
14
  target_sources(
16
15
  ${simple_converter}
@@ -29,3 +28,11 @@ target_link_libraries(
29
28
  PRIVATE
30
29
  simple_converter_core
31
30
  )
31
+
32
+ if(CMAKE_STRIP AND NOT WIN32)
33
+ add_custom_command(
34
+ TARGET ${simple_converter}_module
35
+ POST_BUILD
36
+ COMMAND ${CMAKE_STRIP} $<IF:$<PLATFORM_ID:Darwin,iOS>,-x,--strip-unneeded> $<TARGET_FILE:${simple_converter}_module>
37
+ )
38
+ endif()
package/LICENSE.md ADDED
@@ -0,0 +1,198 @@
1
+ # License
2
+
3
+ This project is licensed under the Apache License, Version 2.0.
4
+ See below for the full license text.
5
+
6
+ ## Apache License
7
+
8
+ _Version 2.0, January 2004_
9
+ _&lt;<http://www.apache.org/licenses/>&gt;_
10
+
11
+ ### Terms and Conditions for use, reproduction, and distribution
12
+
13
+ #### 1. Definitions
14
+
15
+ “License” shall mean the terms and conditions for use, reproduction, and
16
+ distribution as defined by Sections 1 through 9 of this document.
17
+
18
+ “Licensor” shall mean the copyright owner or entity authorized by the copyright
19
+ owner that is granting the License.
20
+
21
+ “Legal Entity” shall mean the union of the acting entity and all other entities
22
+ that control, are controlled by, or are under common control with that entity.
23
+ For the purposes of this definition, “control” means **(i)** the power, direct or
24
+ indirect, to cause the direction or management of such entity, whether by
25
+ contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
26
+ outstanding shares, or **(iii)** beneficial ownership of such entity.
27
+
28
+ “You” (or “Your”) shall mean an individual or Legal Entity exercising
29
+ permissions granted by this License.
30
+
31
+ “Source” form shall mean the preferred form for making modifications, including
32
+ but not limited to software source code, documentation source, and configuration
33
+ files.
34
+
35
+ “Object” form shall mean any form resulting from mechanical transformation or
36
+ translation of a Source form, including but not limited to compiled object code,
37
+ generated documentation, and conversions to other media types.
38
+
39
+ “Work” shall mean the work of authorship, whether in Source or Object form, made
40
+ available under the License, as indicated by a copyright notice that is included
41
+ in or attached to the work (an example is provided in the Appendix below).
42
+
43
+ “Derivative Works” shall mean any work, whether in Source or Object form, that
44
+ is based on (or derived from) the Work and for which the editorial revisions,
45
+ annotations, elaborations, or other modifications represent, as a whole, an
46
+ original work of authorship. For the purposes of this License, Derivative Works
47
+ shall not include works that remain separable from, or merely link (or bind by
48
+ name) to the interfaces of, the Work and Derivative Works thereof.
49
+
50
+ “Contribution” shall mean any work of authorship, including the original version
51
+ of the Work and any modifications or additions to that Work or Derivative Works
52
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
53
+ by the copyright owner or by an individual or Legal Entity authorized to submit
54
+ on behalf of the copyright owner. For the purposes of this definition,
55
+ “submitted” means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems, and
58
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
59
+ the purpose of discussing and improving the Work, but excluding communication
60
+ that is conspicuously marked or otherwise designated in writing by the copyright
61
+ owner as “Not a Contribution.”
62
+
63
+ “Contributor” shall mean Licensor and any individual or Legal Entity on behalf
64
+ of whom a Contribution has been received by Licensor and subsequently
65
+ incorporated within the Work.
66
+
67
+ #### 2. Grant of Copyright License
68
+
69
+ Subject to the terms and conditions of this License, each Contributor hereby
70
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
71
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the Work and such
73
+ Derivative Works in Source or Object form.
74
+
75
+ #### 3. Grant of Patent License
76
+
77
+ Subject to the terms and conditions of this License, each Contributor hereby
78
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
79
+ irrevocable (except as stated in this section) patent license to make, have
80
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
81
+ such license applies only to those patent claims licensable by such Contributor
82
+ that are necessarily infringed by their Contribution(s) alone or by combination
83
+ of their Contribution(s) with the Work to which such Contribution(s) was
84
+ submitted. If You institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
86
+ Contribution incorporated within the Work constitutes direct or contributory
87
+ patent infringement, then any patent licenses granted to You under this License
88
+ for that Work shall terminate as of the date such litigation is filed.
89
+
90
+ #### 4. Redistribution
91
+
92
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
93
+ in any medium, with or without modifications, and in Source or Object form,
94
+ provided that You meet the following conditions:
95
+
96
+ - **(a)** You must give any other recipients of the Work or Derivative Works a copy of
97
+ this License; and
98
+ - **(b)** You must cause any modified files to carry prominent notices stating that You
99
+ changed the files; and
100
+ - **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
101
+ all copyright, patent, trademark, and attribution notices from the Source form
102
+ of the Work, excluding those notices that do not pertain to any part of the
103
+ Derivative Works; and
104
+ - **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
105
+ Derivative Works that You distribute must include a readable copy of the
106
+ attribution notices contained within such NOTICE file, excluding those notices
107
+ that do not pertain to any part of the Derivative Works, in at least one of the
108
+ following places: within a NOTICE text file distributed as part of the
109
+ Derivative Works; within the Source form or documentation, if provided along
110
+ with the Derivative Works; or, within a display generated by the Derivative
111
+ Works, if and wherever such third-party notices normally appear. The contents of
112
+ the NOTICE file are for informational purposes only and do not modify the
113
+ License. You may add Your own attribution notices within Derivative Works that
114
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
115
+ provided that such additional attribution notices cannot be construed as
116
+ modifying the License.
117
+
118
+ You may add Your own copyright statement to Your modifications and may provide
119
+ additional or different license terms and conditions for use, reproduction, or
120
+ distribution of Your modifications, or for any such Derivative Works as a whole,
121
+ provided Your use, reproduction, and distribution of the Work otherwise complies
122
+ with the conditions stated in this License.
123
+
124
+ #### 5. Submission of Contributions
125
+
126
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
127
+ for inclusion in the Work by You to the Licensor shall be under the terms and
128
+ conditions of this License, without any additional terms or conditions.
129
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of
130
+ any separate license agreement you may have executed with Licensor regarding
131
+ such Contributions.
132
+
133
+ #### 6. Trademarks
134
+
135
+ This License does not grant permission to use the trade names, trademarks,
136
+ service marks, or product names of the Licensor, except as required for
137
+ reasonable and customary use in describing the origin of the Work and
138
+ reproducing the content of the NOTICE file.
139
+
140
+ #### 7. Disclaimer of Warranty
141
+
142
+ Unless required by applicable law or agreed to in writing, Licensor provides the
143
+ Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
144
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
145
+ including, without limitation, any warranties or conditions of TITLE,
146
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
147
+ solely responsible for determining the appropriateness of using or
148
+ redistributing the Work and assume any risks associated with Your exercise of
149
+ permissions under this License.
150
+
151
+ #### 8. Limitation of Liability
152
+
153
+ In no event and under no legal theory, whether in tort (including negligence),
154
+ contract, or otherwise, unless required by applicable law (such as deliberate
155
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
156
+ liable to You for damages, including any direct, indirect, special, incidental,
157
+ or consequential damages of any character arising as a result of this License or
158
+ out of the use or inability to use the Work (including but not limited to
159
+ damages for loss of goodwill, work stoppage, computer failure or malfunction, or
160
+ any and all other commercial damages or losses), even if such Contributor has
161
+ been advised of the possibility of such damages.
162
+
163
+ #### 9. Accepting Warranty or Additional Liability
164
+
165
+ While redistributing the Work or Derivative Works thereof, You may choose to
166
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
167
+ other liability obligations and/or rights consistent with this License. However,
168
+ in accepting such obligations, You may act only on Your own behalf and on Your
169
+ sole responsibility, not on behalf of any other Contributor, and only if You
170
+ agree to indemnify, defend, and hold each Contributor harmless for any liability
171
+ incurred by, or claims asserted against, such Contributor by reason of your
172
+ accepting any such warranty or additional liability.
173
+
174
+ _END OF TERMS AND CONDITIONS_
175
+
176
+ ### APPENDIX: How to apply the Apache License to your work
177
+
178
+ To apply the Apache License to your work, attach the following boilerplate
179
+ notice, with the fields enclosed by brackets `[]` replaced with your own
180
+ identifying information. (Don't include the brackets!) The text should be
181
+ enclosed in the appropriate comment syntax for the file format. We also
182
+ recommend that a file or class name and description of purpose be included on
183
+ the same “printed page” as the copyright notice for easier identification within
184
+ third-party archives.
185
+
186
+ Copyright [yyyy] [name of copyright owner]
187
+
188
+ Licensed under the Apache License, Version 2.0 (the "License");
189
+ you may not use this file except in compliance with the License.
190
+ You may obtain a copy of the License at
191
+
192
+ http://www.apache.org/licenses/LICENSE-2.0
193
+
194
+ Unless required by applicable law or agreed to in writing, software
195
+ distributed under the License is distributed on an "AS IS" BASIS,
196
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
197
+ See the License for the specific language governing permissions and
198
+ limitations under the License.
package/NOTICE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2026 Tether Inc
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md CHANGED
@@ -2,31 +2,38 @@
2
2
 
3
3
  Convert office documents to PDF for [Bare](https://github.com/holepunchto/bare).
4
4
  A native addon with a Rust engine that lays pages out with
5
- [Typst](https://typst.app) and reads PDFs with
6
- [PDFium](https://pdfium.googlesource.com/pdfium/).
5
+ [Typst](https://typst.app).
7
6
 
8
7
  `x` is every format it reads into a PDF today:
9
8
 
10
- | Family | Extensions |
11
- | ----------------- | ---------------------------------- |
12
- | Word (OOXML) | `.docx`, `.docm`, `.dotx`, `.dotm` |
13
- | Word 97–2003 | `.doc`, `.dot` |
14
- | OpenDocument Text | `.odt`, `.ott`, `.fodt` |
15
- | PowerPoint | `.pptx` |
16
- | Excel | `.xlsx`, `.xlsm`, `.xltx`, `.xltm` |
17
-
18
- PDF to `.docx` (fixed-layout) also exists, in the other direction.
9
+ | Family | Extensions |
10
+ | ------------------------- | ---------------------------------- |
11
+ | Word | `.docx`, `.docm`, `.dotx`, `.dotm` |
12
+ | Word 97–2003 | `.doc`, `.dot` |
13
+ | Excel | `.xlsx`, `.xlsm`, `.xltx`, `.xltm` |
14
+ | Excel 97–2003 | `.xls`, `.xlt` |
15
+ | PowerPoint | `.pptx` |
16
+ | OpenDocument Text | `.odt`, `.ott`, `.fodt` |
17
+ | OpenDocument Spreadsheet | `.ods`, `.ots`, `.fods` |
18
+ | OpenDocument Presentation | `.odp`, `.otp`, `.fodp` |
19
+ | Markdown | `.md`, `.markdown` |
20
+
21
+ The `from` name for each is the extension without its dot, and PDF is the only output.
22
+ Markdown is CommonMark plus GitHub tables, task lists and strikethrough. Legacy
23
+ PowerPoint (`.ppt`), `.pptm`, `.potx`, `.ppsx`, Rich Text and HTML are not read.
19
24
 
20
25
  ## Install
21
26
 
22
27
  ```sh
23
- npm install bare-x-to-pdf@beta
28
+ npm install bare-x-to-pdf
24
29
  ```
25
30
 
26
31
  The native prebuild is an optional dependency per platform (`bare-x-to-pdf-<platform>-<arch>`),
27
- so an install downloads only the package for its own platform, about 20 MB, plus the
28
- fonts and sources in the main package. darwin, linux, win32, android and ios are covered;
29
- other hosts build from source with the Bare toolchain, CMake 4 and Rust.
32
+ so an install downloads only the package for its own platform, about 17 MB packed and
33
+ 42 MB unpacked, plus the main package with the fonts and sources, about 4 MB packed.
34
+ Prebuilds exist for android (arm, arm64, x64), darwin (arm64, x64), ios (arm64 and the
35
+ arm64 and x64 simulators), linux (arm64, x64) and win32 (x64); other hosts build from a
36
+ checkout with the Bare toolchain, CMake 4 and Rust.
30
37
 
31
38
  To bundle for a different platform, ask npm for that prebuild as well:
32
39
 
@@ -41,7 +48,6 @@ npm install --os=ios --cpu=arm64
41
48
  const converter = require('bare-x-to-pdf')
42
49
 
43
50
  const pdf = converter.convert(docxBytes, { to: 'pdf' })
44
- const docx = converter.convert(pdfBytes, { to: 'docx' })
45
51
  ```
46
52
 
47
53
  Input is a `Uint8Array` or `ArrayBuffer` and the result is a `Buffer`. Calls are
@@ -53,14 +59,18 @@ synchronous and CPU bound; run them in a `Bare.Thread` when latency matters.
53
59
 
54
60
  Convert `input` and return a `Buffer`.
55
61
 
56
- - `options.to` — target format, e.g. `'pdf'` or `'docx'`. Required.
57
- - `options.from` — source format; sniffed from the bytes when omitted.
62
+ - `options.to` — target format, `'pdf'`. Required.
63
+ - `options.from` — source format; sniffed from the bytes when omitted. Markdown has no
64
+ signature to sniff, so pass `from: 'md'` for it. Markdown images load only from `data:`
65
+ URIs, since the input is bytes with no directory to resolve relative paths against.
58
66
  - `options.fontsDir` — a directory of fonts to use instead of the bundled set.
59
- - `options.pdfiumPath` — path to the PDFium shared library.
60
67
 
61
68
  ### `detect(input)`
62
69
 
63
- Return the detected format (`'docx'`, `'pdf'`, `'doc'`, …) or `null`.
70
+ Sniff the format from the bytes and return `'docx'`, `'pptx'`, `'xlsx'`, `'doc'`, `'xls'`,
71
+ `'odt'`, `'ods'`, `'odp'`, `'fodt'`, `'fods'`, `'fodp'` or `null`. Templates and
72
+ macro-enabled files report their base format (a `.dotx` is `'docx'`, an `.ots` is
73
+ `'ods'`), which converts the same way. Markdown is plain text and always returns `null`.
64
74
 
65
75
  ### `supports(from, to)`
66
76
 
@@ -74,11 +84,23 @@ Return every supported pair as `{ from, to }`.
74
84
 
75
85
  Path to the bundled fonts directory.
76
86
 
77
- ### `defaultPdfiumPath()`
87
+ ## Development
88
+
89
+ The platform packages in `npm/` are npm workspaces, and each declares its own `os` and `cpu`
90
+ so that installs download only one. In a checkout, install with `npm install --force` so npm
91
+ links all of them, then build the host prebuild with `npm run prebuild` and run `npm test`.
92
+ The fidelity benchmark in `bench/` has its own dependencies: `cd bench && npm install`.
93
+
94
+ ## Releases
78
95
 
79
- Path to the PDFium library shipped in the platform package beside the addon.
96
+ `.github/workflows/publish.yml` runs when a `v*` tag is pushed. Tag the commit whose
97
+ `package.json` has that version, after running `npm run packages` to bring the platform
98
+ packages to it. The workflow builds every platform, publishes the platform packages and then
99
+ the main package through npm trusted publishing, and creates a GitHub release. A tag newer
100
+ than npm's current `latest` publishes as `latest`; an older one as `release-<major>.<minor>`.
80
101
 
81
102
  ## License
82
103
 
83
- Apache-2.0. PDFium is BSD; Typst and its dependencies are Apache-2.0 or MIT; the
84
- bundled fonts are under the SIL Open Font License (see `fonts/`).
104
+ Apache-2.0. Typst, pulldown-cmark and the other Rust dependencies are Apache-2.0 or MIT.
105
+ Liberation, Carlito and Caladea are under the SIL Open Font License (see `fonts/`);
106
+ OpenSymbol comes from LibreOffice.
package/binding.c CHANGED
@@ -35,14 +35,14 @@ static js_value_t *
35
35
  simple_converter_convert(js_env_t *env, js_callback_info_t *info) {
36
36
  int err;
37
37
 
38
- size_t argc = 5;
39
- js_value_t *argv[5];
38
+ size_t argc = 4;
39
+ js_value_t *argv[4];
40
40
 
41
41
  err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
42
42
  assert(err == 0);
43
43
 
44
- if (argc < 5) {
45
- err = js_throw_error(env, NULL, "convert expects (bytes, from, to, fontsDir, pdfiumPath)");
44
+ if (argc < 4) {
45
+ err = js_throw_error(env, NULL, "convert expects (bytes, from, to, fontsDir)");
46
46
  assert(err == 0);
47
47
  return NULL;
48
48
  }
@@ -59,19 +59,16 @@ simple_converter_convert(js_env_t *env, js_callback_info_t *info) {
59
59
  char *from = NULL;
60
60
  char *to = NULL;
61
61
  char *fonts_dir = NULL;
62
- char *pdfium_path = NULL;
63
62
 
64
63
  bool ok = simple_converter__string(env, argv[1], &from) &&
65
64
  simple_converter__string(env, argv[2], &to) &&
66
- simple_converter__string(env, argv[3], &fonts_dir) &&
67
- simple_converter__string(env, argv[4], &pdfium_path);
65
+ simple_converter__string(env, argv[3], &fonts_dir);
68
66
 
69
67
  if (!ok) {
70
68
  free(from);
71
69
  free(to);
72
70
  free(fonts_dir);
73
- free(pdfium_path);
74
- err = js_throw_error(env, NULL, "from, to, fontsDir and pdfiumPath must be strings");
71
+ err = js_throw_error(env, NULL, "from, to and fontsDir must be strings");
75
72
  assert(err == 0);
76
73
  return NULL;
77
74
  }
@@ -79,12 +76,11 @@ simple_converter_convert(js_env_t *env, js_callback_info_t *info) {
79
76
  sc_buffer_t out = {NULL, 0};
80
77
  sc_buffer_t error = {NULL, 0};
81
78
 
82
- int status = sc_convert(input, input_len, from, to, fonts_dir, pdfium_path, &out, &error);
79
+ int status = sc_convert(input, input_len, from, to, fonts_dir, &out, &error);
83
80
 
84
81
  free(from);
85
82
  free(to);
86
83
  free(fonts_dir);
87
- free(pdfium_path);
88
84
 
89
85
  if (status != 0) {
90
86
  char *message = malloc(error.len + 1);