@ohah/hwpjs 0.1.0-rc.1
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/Hwpjs.podspec +27 -0
- package/LICENSE +21 -0
- package/README.md +87 -0
- package/android/CMakeLists.txt +50 -0
- package/android/build.gradle +110 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/rs/craby/hwpjs/HwpjsPackage.kt +59 -0
- package/android/src/main/jni/OnLoad.cpp +22 -0
- package/android/src/main/jni/include/CrabySignals.h +53 -0
- package/android/src/main/jni/include/cxx.h +1150 -0
- package/android/src/main/jni/include/ffi.rs.h +1041 -0
- package/android/src/main/jni/libs/arm64-v8a/libhwpjs-prebuilt.a +0 -0
- package/android/src/main/jni/libs/arm64-v8a/libreactnative-prebuilt.a +0 -0
- package/android/src/main/jni/libs/armeabi-v7a/libhwpjs-prebuilt.a +0 -0
- package/android/src/main/jni/libs/armeabi-v7a/libreactnative-prebuilt.a +0 -0
- package/android/src/main/jni/libs/x86/libhwpjs-prebuilt.a +0 -0
- package/android/src/main/jni/libs/x86/libreactnative-prebuilt.a +0 -0
- package/android/src/main/jni/libs/x86_64/libhwpjs-prebuilt.a +0 -0
- package/android/src/main/jni/libs/x86_64/libreactnative-prebuilt.a +0 -0
- package/android/src/main/jni/src/ffi.rs.cc +1179 -0
- package/android/stubs/CMakeLists.txt +31 -0
- package/android/stubs/Hwpjs_stub.cpp +9 -0
- package/android/stubs/Hwpjs_stub.h +12 -0
- package/cpp/CrabyUtils.hpp +91 -0
- package/cpp/CxxHwpjsModule.cpp +125 -0
- package/cpp/CxxHwpjsModule.hpp +53 -0
- package/cpp/bridging-generated.hpp +158 -0
- package/dist/browser.js +1 -0
- package/dist/hwpjs-napi.wasi-browser.js +61 -0
- package/dist/hwpjs-napi.wasi.cjs +113 -0
- package/dist/hwpjs.wasi-browser.js +61 -0
- package/dist/hwpjs.wasi.cjs +113 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.js +577 -0
- package/dist/react-native/index.cjs +40 -0
- package/dist/react-native/index.cjs.map +1 -0
- package/dist/react-native/index.d.cts +22 -0
- package/dist/react-native/index.d.mts +22 -0
- package/dist/react-native/index.mjs +40 -0
- package/dist/react-native/index.mjs.map +1 -0
- package/dist/wasi-worker-browser.mjs +32 -0
- package/dist/wasi-worker.mjs +63 -0
- package/ios/HwpjsModuleProvider.mm +47 -0
- package/ios/framework/libhwpjs.xcframework/Info.plist +44 -0
- package/ios/framework/libhwpjs.xcframework/ios-arm64/libhwpjs-prebuilt.a +0 -0
- package/ios/framework/libhwpjs.xcframework/ios-arm64_x86_64-simulator/libhwpjs-prebuilt.a +0 -0
- package/ios/framework/libreactnative.xcframework/Info.plist +44 -0
- package/ios/framework/libreactnative.xcframework/ios-arm64/libreactnative-prebuilt.a +0 -0
- package/ios/framework/libreactnative.xcframework/ios-arm64_x86_64-simulator/libreactnative-prebuilt.a +0 -0
- package/ios/include/CrabySignals.h +53 -0
- package/ios/include/cxx.h +1150 -0
- package/ios/include/ffi.rs.h +1041 -0
- package/ios/src/ffi.rs.cc +1179 -0
- package/package.json +147 -0
- package/react-native.config.js +24 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createOnMessage as __wasmCreateOnMessageForFsProxy,
|
|
3
|
+
getDefaultContext as __emnapiGetDefaultContext,
|
|
4
|
+
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
|
|
5
|
+
WASI as __WASI,
|
|
6
|
+
} from '@napi-rs/wasm-runtime'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const __wasi = new __WASI({
|
|
11
|
+
version: 'preview1',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const __wasmUrl = new URL('./hwpjs.wasm32-wasi.wasm', import.meta.url).href
|
|
15
|
+
const __emnapiContext = __emnapiGetDefaultContext()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const __sharedMemory = new WebAssembly.Memory({
|
|
19
|
+
initial: 4000,
|
|
20
|
+
maximum: 65536,
|
|
21
|
+
shared: true,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
instance: __napiInstance,
|
|
28
|
+
module: __wasiModule,
|
|
29
|
+
napiModule: __napiModule,
|
|
30
|
+
} = __emnapiInstantiateNapiModuleSync(__wasmFile, {
|
|
31
|
+
context: __emnapiContext,
|
|
32
|
+
asyncWorkPoolSize: 4,
|
|
33
|
+
wasi: __wasi,
|
|
34
|
+
onCreateWorker() {
|
|
35
|
+
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
|
|
36
|
+
type: 'module',
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return worker
|
|
40
|
+
},
|
|
41
|
+
overwriteImports(importObject) {
|
|
42
|
+
importObject.env = {
|
|
43
|
+
...importObject.env,
|
|
44
|
+
...importObject.napi,
|
|
45
|
+
...importObject.emnapi,
|
|
46
|
+
memory: __sharedMemory,
|
|
47
|
+
}
|
|
48
|
+
return importObject
|
|
49
|
+
},
|
|
50
|
+
beforeInit({ instance }) {
|
|
51
|
+
for (const name of Object.keys(instance.exports)) {
|
|
52
|
+
if (name.startsWith('__napi_register__')) {
|
|
53
|
+
instance.exports[name]()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
export default __napiModule.exports
|
|
59
|
+
export const fileHeader = __napiModule.exports.fileHeader
|
|
60
|
+
export const toJson = __napiModule.exports.toJson
|
|
61
|
+
export const toMarkdown = __napiModule.exports.toMarkdown
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* prettier-ignore */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
const __nodeFs = require('node:fs')
|
|
7
|
+
const __nodePath = require('node:path')
|
|
8
|
+
const { WASI: __nodeWASI } = require('node:wasi')
|
|
9
|
+
const { Worker } = require('node:worker_threads')
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
createOnMessage: __wasmCreateOnMessageForFsProxy,
|
|
13
|
+
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
|
+
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
15
|
+
} = require('@napi-rs/wasm-runtime')
|
|
16
|
+
|
|
17
|
+
const __rootDir = __nodePath.parse(process.cwd()).root
|
|
18
|
+
|
|
19
|
+
const __wasi = new __nodeWASI({
|
|
20
|
+
version: 'preview1',
|
|
21
|
+
env: process.env,
|
|
22
|
+
preopens: {
|
|
23
|
+
[__rootDir]: __rootDir,
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const __emnapiContext = __emnapiGetDefaultContext()
|
|
28
|
+
|
|
29
|
+
const __sharedMemory = new WebAssembly.Memory({
|
|
30
|
+
initial: 4000,
|
|
31
|
+
maximum: 65536,
|
|
32
|
+
shared: true,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
let __wasmFilePath = __nodePath.join(__dirname, 'hwpjs.wasm32-wasi.wasm')
|
|
36
|
+
const __wasmDebugFilePath = __nodePath.join(__dirname, 'hwpjs.wasm32-wasi.debug.wasm')
|
|
37
|
+
|
|
38
|
+
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
|
|
39
|
+
__wasmFilePath = __wasmDebugFilePath
|
|
40
|
+
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
|
|
41
|
+
try {
|
|
42
|
+
__wasmFilePath = __nodePath.resolve('@ohah/hwpjs-wasm32-wasi')
|
|
43
|
+
} catch {
|
|
44
|
+
throw new Error('Cannot find hwpjs.wasm32-wasi.wasm file, and @ohah/hwpjs-wasm32-wasi package is not installed.')
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
|
|
49
|
+
context: __emnapiContext,
|
|
50
|
+
asyncWorkPoolSize: (function() {
|
|
51
|
+
const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
|
|
52
|
+
// NaN > 0 is false
|
|
53
|
+
if (threadsSizeFromEnv > 0) {
|
|
54
|
+
return threadsSizeFromEnv
|
|
55
|
+
} else {
|
|
56
|
+
return 4
|
|
57
|
+
}
|
|
58
|
+
})(),
|
|
59
|
+
reuseWorker: true,
|
|
60
|
+
wasi: __wasi,
|
|
61
|
+
onCreateWorker() {
|
|
62
|
+
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
63
|
+
env: process.env,
|
|
64
|
+
})
|
|
65
|
+
worker.onmessage = ({ data }) => {
|
|
66
|
+
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The main thread of Node.js waits for all the active handles before exiting.
|
|
70
|
+
// But Rust threads are never waited without `thread::join`.
|
|
71
|
+
// So here we hack the code of Node.js to prevent the workers from being referenced (active).
|
|
72
|
+
// According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
|
|
73
|
+
// a worker is consist of two handles: kPublicPort and kHandle.
|
|
74
|
+
{
|
|
75
|
+
const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
|
|
76
|
+
s.toString().includes("kPublicPort")
|
|
77
|
+
);
|
|
78
|
+
if (kPublicPort) {
|
|
79
|
+
worker[kPublicPort].ref = () => {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
|
|
83
|
+
s.toString().includes("kHandle")
|
|
84
|
+
);
|
|
85
|
+
if (kHandle) {
|
|
86
|
+
worker[kHandle].ref = () => {};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
worker.unref();
|
|
90
|
+
}
|
|
91
|
+
return worker
|
|
92
|
+
},
|
|
93
|
+
overwriteImports(importObject) {
|
|
94
|
+
importObject.env = {
|
|
95
|
+
...importObject.env,
|
|
96
|
+
...importObject.napi,
|
|
97
|
+
...importObject.emnapi,
|
|
98
|
+
memory: __sharedMemory,
|
|
99
|
+
}
|
|
100
|
+
return importObject
|
|
101
|
+
},
|
|
102
|
+
beforeInit({ instance }) {
|
|
103
|
+
for (const name of Object.keys(instance.exports)) {
|
|
104
|
+
if (name.startsWith('__napi_register__')) {
|
|
105
|
+
instance.exports[name]()
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
module.exports = __napiModule.exports
|
|
111
|
+
module.exports.fileHeader = __napiModule.exports.fileHeader
|
|
112
|
+
module.exports.toJson = __napiModule.exports.toJson
|
|
113
|
+
module.exports.toMarkdown = __napiModule.exports.toMarkdown
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Extract FileHeader from HWP file as JSON
|
|
5
|
+
*
|
|
6
|
+
* # Arguments
|
|
7
|
+
* * `data` - Byte array containing HWP file data (Buffer or Uint8Array)
|
|
8
|
+
*
|
|
9
|
+
* # Returns
|
|
10
|
+
* FileHeader as JSON string
|
|
11
|
+
*/
|
|
12
|
+
export declare function fileHeader(data: Buffer): string
|
|
13
|
+
|
|
14
|
+
/** Image data structure */
|
|
15
|
+
export interface ImageData {
|
|
16
|
+
/**
|
|
17
|
+
* Image ID (e.g., "image-0")
|
|
18
|
+
* 이미지 ID (예: "image-0")
|
|
19
|
+
*/
|
|
20
|
+
id: string
|
|
21
|
+
/**
|
|
22
|
+
* Image data as Uint8Array
|
|
23
|
+
* 이미지 데이터 (Uint8Array)
|
|
24
|
+
*/
|
|
25
|
+
data: Buffer
|
|
26
|
+
/**
|
|
27
|
+
* Image format (e.g., "jpg", "png", "bmp")
|
|
28
|
+
* 이미지 형식 (예: "jpg", "png", "bmp")
|
|
29
|
+
*/
|
|
30
|
+
format: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Convert HWP file to JSON
|
|
35
|
+
*
|
|
36
|
+
* # Arguments
|
|
37
|
+
* * `data` - Byte array containing HWP file data (Buffer or Uint8Array)
|
|
38
|
+
*
|
|
39
|
+
* # Returns
|
|
40
|
+
* Parsed HWP document as JSON string
|
|
41
|
+
*/
|
|
42
|
+
export declare function toJson(data: Buffer): string
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Convert HWP file to Markdown format
|
|
46
|
+
*
|
|
47
|
+
* # Arguments
|
|
48
|
+
* * `data` - Byte array containing HWP file data (Buffer or Uint8Array)
|
|
49
|
+
* * `options` - Optional markdown conversion options
|
|
50
|
+
*
|
|
51
|
+
* # Returns
|
|
52
|
+
* ToMarkdownResult containing markdown string and image data
|
|
53
|
+
*/
|
|
54
|
+
export declare function toMarkdown(data: Buffer, options?: ToMarkdownOptions | undefined | null): ToMarkdownResult
|
|
55
|
+
|
|
56
|
+
/** Markdown conversion options */
|
|
57
|
+
export interface ToMarkdownOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Optional directory path to save images as files. If None, images are embedded as base64 data URIs.
|
|
60
|
+
* 이미지를 파일로 저장할 디렉토리 경로 (선택). None이면 base64 데이터 URI로 임베드됩니다.
|
|
61
|
+
*/
|
|
62
|
+
imageOutputDir?: string
|
|
63
|
+
/**
|
|
64
|
+
* Image format: 'base64' to embed base64 data URI directly in markdown, 'blob' to return as separate ImageData array (default: 'blob')
|
|
65
|
+
* 이미지 형식: 'base64'는 마크다운에 base64 데이터 URI를 직접 포함, 'blob'은 별도 ImageData 배열로 반환 (기본값: 'blob')
|
|
66
|
+
*/
|
|
67
|
+
image?: string
|
|
68
|
+
/**
|
|
69
|
+
* Whether to use HTML tags (if Some(true), use <br> tags in areas where line breaks are not possible, such as tables)
|
|
70
|
+
* HTML 태그 사용 여부 (Some(true)인 경우 테이블 등 개행 불가 영역에 <br> 태그 사용)
|
|
71
|
+
*/
|
|
72
|
+
useHtml?: boolean
|
|
73
|
+
/**
|
|
74
|
+
* Whether to include version information
|
|
75
|
+
* 버전 정보 포함 여부
|
|
76
|
+
*/
|
|
77
|
+
includeVersion?: boolean
|
|
78
|
+
/**
|
|
79
|
+
* Whether to include page information
|
|
80
|
+
* 페이지 정보 포함 여부
|
|
81
|
+
*/
|
|
82
|
+
includePageInfo?: boolean
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Markdown conversion result */
|
|
86
|
+
export interface ToMarkdownResult {
|
|
87
|
+
/**
|
|
88
|
+
* Markdown string with image references (e.g., "")
|
|
89
|
+
* 이미지 참조가 포함된 마크다운 문자열 (예: "")
|
|
90
|
+
*/
|
|
91
|
+
markdown: string
|
|
92
|
+
/**
|
|
93
|
+
* Extracted image data
|
|
94
|
+
* 추출된 이미지 데이터
|
|
95
|
+
*/
|
|
96
|
+
images: Array<ImageData>
|
|
97
|
+
}
|