@takumi-rs/core 0.6.0 → 0.7.2

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 (3) hide show
  1. package/index.d.ts +10 -0
  2. package/index.js +379 -0
  3. package/package.json +6 -6
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+ export declare class Renderer {
4
+ constructor()
5
+ loadFontAsync(data: ArrayBuffer, signal?: AbortSignal | undefined | null): Promise<number>
6
+ loadFontsAsync(fonts: Array<ArrayBuffer>, signal?: AbortSignal | undefined | null): Promise<number>
7
+ clearImageStore(): void
8
+ preloadImageAsync(url: string, signal?: AbortSignal | undefined | null): Promise<void>
9
+ renderAsync(source: { type: string }, width: number, height: number, signal?: AbortSignal): Promise<Buffer>
10
+ }
package/index.js ADDED
@@ -0,0 +1,379 @@
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ const { createRequire } = require('node:module')
7
+ require = createRequire(__filename)
8
+
9
+ const { readFileSync } = require('node:fs')
10
+ let nativeBinding = null
11
+ const loadErrors = []
12
+
13
+ const isMusl = () => {
14
+ let musl = false
15
+ if (process.platform === 'linux') {
16
+ musl = isMuslFromFilesystem()
17
+ if (musl === null) {
18
+ musl = isMuslFromReport()
19
+ }
20
+ if (musl === null) {
21
+ musl = isMuslFromChildProcess()
22
+ }
23
+ }
24
+ return musl
25
+ }
26
+
27
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
28
+
29
+ const isMuslFromFilesystem = () => {
30
+ try {
31
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
32
+ } catch {
33
+ return null
34
+ }
35
+ }
36
+
37
+ const isMuslFromReport = () => {
38
+ let report = null
39
+ if (typeof process.report?.getReport === 'function') {
40
+ process.report.excludeNetwork = true
41
+ report = process.report.getReport()
42
+ }
43
+ if (!report) {
44
+ return null
45
+ }
46
+ if (report.header && report.header.glibcVersionRuntime) {
47
+ return false
48
+ }
49
+ if (Array.isArray(report.sharedObjects)) {
50
+ if (report.sharedObjects.some(isFileMusl)) {
51
+ return true
52
+ }
53
+ }
54
+ return false
55
+ }
56
+
57
+ const isMuslFromChildProcess = () => {
58
+ try {
59
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
60
+ } catch (e) {
61
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
62
+ return false
63
+ }
64
+ }
65
+
66
+ function requireNative() {
67
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
68
+ try {
69
+ nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
70
+ } catch (err) {
71
+ loadErrors.push(err)
72
+ }
73
+ } else if (process.platform === 'android') {
74
+ if (process.arch === 'arm64') {
75
+ try {
76
+ return require('./core.android-arm64.node')
77
+ } catch (e) {
78
+ loadErrors.push(e)
79
+ }
80
+ try {
81
+ return require('@takumi-rs/core-android-arm64')
82
+ } catch (e) {
83
+ loadErrors.push(e)
84
+ }
85
+
86
+ } else if (process.arch === 'arm') {
87
+ try {
88
+ return require('./core.android-arm-eabi.node')
89
+ } catch (e) {
90
+ loadErrors.push(e)
91
+ }
92
+ try {
93
+ return require('@takumi-rs/core-android-arm-eabi')
94
+ } catch (e) {
95
+ loadErrors.push(e)
96
+ }
97
+
98
+ } else {
99
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
100
+ }
101
+ } else if (process.platform === 'win32') {
102
+ if (process.arch === 'x64') {
103
+ try {
104
+ return require('./core.win32-x64-msvc.node')
105
+ } catch (e) {
106
+ loadErrors.push(e)
107
+ }
108
+ try {
109
+ return require('@takumi-rs/core-win32-x64-msvc')
110
+ } catch (e) {
111
+ loadErrors.push(e)
112
+ }
113
+
114
+ } else if (process.arch === 'ia32') {
115
+ try {
116
+ return require('./core.win32-ia32-msvc.node')
117
+ } catch (e) {
118
+ loadErrors.push(e)
119
+ }
120
+ try {
121
+ return require('@takumi-rs/core-win32-ia32-msvc')
122
+ } catch (e) {
123
+ loadErrors.push(e)
124
+ }
125
+
126
+ } else if (process.arch === 'arm64') {
127
+ try {
128
+ return require('./core.win32-arm64-msvc.node')
129
+ } catch (e) {
130
+ loadErrors.push(e)
131
+ }
132
+ try {
133
+ return require('@takumi-rs/core-win32-arm64-msvc')
134
+ } catch (e) {
135
+ loadErrors.push(e)
136
+ }
137
+
138
+ } else {
139
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
140
+ }
141
+ } else if (process.platform === 'darwin') {
142
+ try {
143
+ return require('./core.darwin-universal.node')
144
+ } catch (e) {
145
+ loadErrors.push(e)
146
+ }
147
+ try {
148
+ return require('@takumi-rs/core-darwin-universal')
149
+ } catch (e) {
150
+ loadErrors.push(e)
151
+ }
152
+
153
+ if (process.arch === 'x64') {
154
+ try {
155
+ return require('./core.darwin-x64.node')
156
+ } catch (e) {
157
+ loadErrors.push(e)
158
+ }
159
+ try {
160
+ return require('@takumi-rs/core-darwin-x64')
161
+ } catch (e) {
162
+ loadErrors.push(e)
163
+ }
164
+
165
+ } else if (process.arch === 'arm64') {
166
+ try {
167
+ return require('./core.darwin-arm64.node')
168
+ } catch (e) {
169
+ loadErrors.push(e)
170
+ }
171
+ try {
172
+ return require('@takumi-rs/core-darwin-arm64')
173
+ } catch (e) {
174
+ loadErrors.push(e)
175
+ }
176
+
177
+ } else {
178
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
179
+ }
180
+ } else if (process.platform === 'freebsd') {
181
+ if (process.arch === 'x64') {
182
+ try {
183
+ return require('./core.freebsd-x64.node')
184
+ } catch (e) {
185
+ loadErrors.push(e)
186
+ }
187
+ try {
188
+ return require('@takumi-rs/core-freebsd-x64')
189
+ } catch (e) {
190
+ loadErrors.push(e)
191
+ }
192
+
193
+ } else if (process.arch === 'arm64') {
194
+ try {
195
+ return require('./core.freebsd-arm64.node')
196
+ } catch (e) {
197
+ loadErrors.push(e)
198
+ }
199
+ try {
200
+ return require('@takumi-rs/core-freebsd-arm64')
201
+ } catch (e) {
202
+ loadErrors.push(e)
203
+ }
204
+
205
+ } else {
206
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
207
+ }
208
+ } else if (process.platform === 'linux') {
209
+ if (process.arch === 'x64') {
210
+ if (isMusl()) {
211
+ try {
212
+ return require('./core.linux-x64-musl.node')
213
+ } catch (e) {
214
+ loadErrors.push(e)
215
+ }
216
+ try {
217
+ return require('@takumi-rs/core-linux-x64-musl')
218
+ } catch (e) {
219
+ loadErrors.push(e)
220
+ }
221
+
222
+ } else {
223
+ try {
224
+ return require('./core.linux-x64-gnu.node')
225
+ } catch (e) {
226
+ loadErrors.push(e)
227
+ }
228
+ try {
229
+ return require('@takumi-rs/core-linux-x64-gnu')
230
+ } catch (e) {
231
+ loadErrors.push(e)
232
+ }
233
+
234
+ }
235
+ } else if (process.arch === 'arm64') {
236
+ if (isMusl()) {
237
+ try {
238
+ return require('./core.linux-arm64-musl.node')
239
+ } catch (e) {
240
+ loadErrors.push(e)
241
+ }
242
+ try {
243
+ return require('@takumi-rs/core-linux-arm64-musl')
244
+ } catch (e) {
245
+ loadErrors.push(e)
246
+ }
247
+
248
+ } else {
249
+ try {
250
+ return require('./core.linux-arm64-gnu.node')
251
+ } catch (e) {
252
+ loadErrors.push(e)
253
+ }
254
+ try {
255
+ return require('@takumi-rs/core-linux-arm64-gnu')
256
+ } catch (e) {
257
+ loadErrors.push(e)
258
+ }
259
+
260
+ }
261
+ } else if (process.arch === 'arm') {
262
+ if (isMusl()) {
263
+ try {
264
+ return require('./core.linux-arm-musleabihf.node')
265
+ } catch (e) {
266
+ loadErrors.push(e)
267
+ }
268
+ try {
269
+ return require('@takumi-rs/core-linux-arm-musleabihf')
270
+ } catch (e) {
271
+ loadErrors.push(e)
272
+ }
273
+
274
+ } else {
275
+ try {
276
+ return require('./core.linux-arm-gnueabihf.node')
277
+ } catch (e) {
278
+ loadErrors.push(e)
279
+ }
280
+ try {
281
+ return require('@takumi-rs/core-linux-arm-gnueabihf')
282
+ } catch (e) {
283
+ loadErrors.push(e)
284
+ }
285
+
286
+ }
287
+ } else if (process.arch === 'riscv64') {
288
+ if (isMusl()) {
289
+ try {
290
+ return require('./core.linux-riscv64-musl.node')
291
+ } catch (e) {
292
+ loadErrors.push(e)
293
+ }
294
+ try {
295
+ return require('@takumi-rs/core-linux-riscv64-musl')
296
+ } catch (e) {
297
+ loadErrors.push(e)
298
+ }
299
+
300
+ } else {
301
+ try {
302
+ return require('./core.linux-riscv64-gnu.node')
303
+ } catch (e) {
304
+ loadErrors.push(e)
305
+ }
306
+ try {
307
+ return require('@takumi-rs/core-linux-riscv64-gnu')
308
+ } catch (e) {
309
+ loadErrors.push(e)
310
+ }
311
+
312
+ }
313
+ } else if (process.arch === 'ppc64') {
314
+ try {
315
+ return require('./core.linux-ppc64-gnu.node')
316
+ } catch (e) {
317
+ loadErrors.push(e)
318
+ }
319
+ try {
320
+ return require('@takumi-rs/core-linux-ppc64-gnu')
321
+ } catch (e) {
322
+ loadErrors.push(e)
323
+ }
324
+
325
+ } else if (process.arch === 's390x') {
326
+ try {
327
+ return require('./core.linux-s390x-gnu.node')
328
+ } catch (e) {
329
+ loadErrors.push(e)
330
+ }
331
+ try {
332
+ return require('@takumi-rs/core-linux-s390x-gnu')
333
+ } catch (e) {
334
+ loadErrors.push(e)
335
+ }
336
+
337
+ } else {
338
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
339
+ }
340
+ } else {
341
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
342
+ }
343
+ }
344
+
345
+ nativeBinding = requireNative()
346
+
347
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
348
+ try {
349
+ nativeBinding = require('./core.wasi.cjs')
350
+ } catch (err) {
351
+ if (process.env.NAPI_RS_FORCE_WASI) {
352
+ loadErrors.push(err)
353
+ }
354
+ }
355
+ if (!nativeBinding) {
356
+ try {
357
+ nativeBinding = require('@takumi-rs/core-wasm32-wasi')
358
+ } catch (err) {
359
+ if (process.env.NAPI_RS_FORCE_WASI) {
360
+ loadErrors.push(err)
361
+ }
362
+ }
363
+ }
364
+ }
365
+
366
+ if (!nativeBinding) {
367
+ if (loadErrors.length > 0) {
368
+ throw new Error(
369
+ `Cannot find native binding. ` +
370
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
371
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
372
+ { cause: loadErrors }
373
+ )
374
+ }
375
+ throw new Error(`Failed to load native binding`)
376
+ }
377
+
378
+ module.exports = nativeBinding
379
+ module.exports.Renderer = nativeBinding.Renderer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takumi-rs/core",
3
- "version": "0.6.0",
3
+ "version": "0.7.2",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": ">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0"
@@ -41,10 +41,10 @@
41
41
  "typescript": "^5.8.3"
42
42
  },
43
43
  "optionalDependencies": {
44
- "@takumi-rs/core-darwin-arm64": "0.6.0",
45
- "@takumi-rs/core-linux-arm64-gnu": "0.6.0",
46
- "@takumi-rs/core-linux-arm64-musl": "0.6.0",
47
- "@takumi-rs/core-linux-x64-gnu": "0.6.0",
48
- "@takumi-rs/core-linux-x64-musl": "0.6.0"
44
+ "@takumi-rs/core-darwin-arm64": "0.7.2",
45
+ "@takumi-rs/core-linux-arm64-gnu": "0.7.2",
46
+ "@takumi-rs/core-linux-arm64-musl": "0.7.2",
47
+ "@takumi-rs/core-linux-x64-gnu": "0.7.2",
48
+ "@takumi-rs/core-linux-x64-musl": "0.7.2"
49
49
  }
50
50
  }