@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,31 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
|
2
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
3
|
+
|
|
4
|
+
file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp)
|
|
5
|
+
|
|
6
|
+
add_library(
|
|
7
|
+
react_codegen_Hwpjs_stub
|
|
8
|
+
OBJECT
|
|
9
|
+
${react_codegen_SRCS}
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
target_include_directories(react_codegen_Hwpjs_stub PUBLIC .)
|
|
13
|
+
|
|
14
|
+
target_link_libraries(
|
|
15
|
+
react_codegen_Hwpjs_stub
|
|
16
|
+
fbjni
|
|
17
|
+
jsi
|
|
18
|
+
# We need to link different libraries based on whether we are building rncore or not, that's necessary
|
|
19
|
+
# because we want to break a circular dependency between react_codegen_rncore and reactnative
|
|
20
|
+
reactnative
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
target_compile_options(
|
|
24
|
+
react_codegen_Hwpjs_stub
|
|
25
|
+
PRIVATE
|
|
26
|
+
-DLOG_TAG=\"Hwpjs\"
|
|
27
|
+
-fexceptions
|
|
28
|
+
-frtti
|
|
29
|
+
-std=c++20
|
|
30
|
+
-Wall
|
|
31
|
+
)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <ReactCommon/JavaTurboModule.h>
|
|
4
|
+
#include <ReactCommon/TurboModule.h>
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
|
|
7
|
+
namespace facebook::react {
|
|
8
|
+
|
|
9
|
+
JSI_EXPORT
|
|
10
|
+
std::shared_ptr<TurboModule> Hwpjs_stub_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms);
|
|
11
|
+
|
|
12
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Auto generated by Craby. DO NOT EDIT.
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "cxx.h"
|
|
5
|
+
#include "ffi.rs.h"
|
|
6
|
+
#include <condition_variable>
|
|
7
|
+
#include <functional>
|
|
8
|
+
#include <mutex>
|
|
9
|
+
#include <queue>
|
|
10
|
+
#include <thread>
|
|
11
|
+
#include <vector>
|
|
12
|
+
|
|
13
|
+
namespace craby {
|
|
14
|
+
namespace hwpjs {
|
|
15
|
+
namespace utils {
|
|
16
|
+
|
|
17
|
+
class ThreadPool {
|
|
18
|
+
private:
|
|
19
|
+
bool stop;
|
|
20
|
+
std::mutex mutex;
|
|
21
|
+
std::condition_variable condition;
|
|
22
|
+
std::queue<std::function<void()>> tasks;
|
|
23
|
+
std::vector<std::thread> workers;
|
|
24
|
+
|
|
25
|
+
public:
|
|
26
|
+
ThreadPool(size_t num_threads = 10) : stop(false) {
|
|
27
|
+
for (size_t i = 0; i < num_threads; ++i) {
|
|
28
|
+
workers.emplace_back([this] {
|
|
29
|
+
while (true) {
|
|
30
|
+
std::function<void()> task;
|
|
31
|
+
|
|
32
|
+
{
|
|
33
|
+
std::unique_lock<std::mutex> lock(this->mutex);
|
|
34
|
+
this->condition.wait(
|
|
35
|
+
lock, [this] { return this->stop || !this->tasks.empty(); });
|
|
36
|
+
|
|
37
|
+
if (this->stop && this->tasks.empty()) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
task = std::move(this->tasks.front());
|
|
42
|
+
this->tasks.pop();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
task();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
template <class F> void enqueue(F &&f) {
|
|
52
|
+
{
|
|
53
|
+
std::unique_lock<std::mutex> lock(mutex);
|
|
54
|
+
if (stop) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
tasks.emplace(std::forward<F>(f));
|
|
58
|
+
}
|
|
59
|
+
condition.notify_one();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
void shutdown() {
|
|
63
|
+
{
|
|
64
|
+
std::unique_lock<std::mutex> lock(mutex);
|
|
65
|
+
stop = true;
|
|
66
|
+
std::queue<std::function<void()>> empty;
|
|
67
|
+
std::swap(tasks, empty);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
condition.notify_all();
|
|
71
|
+
|
|
72
|
+
for (std::thread &worker : workers) {
|
|
73
|
+
if (worker.joinable()) {
|
|
74
|
+
worker.join();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
~ThreadPool() {
|
|
80
|
+
shutdown();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
inline std::string errorMessage(const std::exception &err) {
|
|
85
|
+
const auto* rs_err = dynamic_cast<const rust::Error*>(&err);
|
|
86
|
+
return std::string(rs_err ? rs_err->what() : err.what());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
} // namespace utils
|
|
90
|
+
} // namespace hwpjs
|
|
91
|
+
} // namespace craby
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// Auto generated by Craby. DO NOT EDIT.
|
|
2
|
+
#include "CxxHwpjsModule.hpp"
|
|
3
|
+
#include "cxx.h"
|
|
4
|
+
#include "bridging-generated.hpp"
|
|
5
|
+
#include <react/bridging/Bridging.h>
|
|
6
|
+
|
|
7
|
+
using namespace facebook;
|
|
8
|
+
|
|
9
|
+
namespace craby {
|
|
10
|
+
namespace hwpjs {
|
|
11
|
+
namespace modules {
|
|
12
|
+
|
|
13
|
+
std::string CxxHwpjsModule::dataPath = std::string();
|
|
14
|
+
|
|
15
|
+
CxxHwpjsModule::CxxHwpjsModule(
|
|
16
|
+
std::shared_ptr<react::CallInvoker> jsInvoker)
|
|
17
|
+
: TurboModule(CxxHwpjsModule::kModuleName, jsInvoker) {
|
|
18
|
+
// No signals
|
|
19
|
+
callInvoker_ = std::move(jsInvoker);
|
|
20
|
+
module_ = std::shared_ptr<craby::hwpjs::bridging::Hwpjs>(
|
|
21
|
+
craby::hwpjs::bridging::createHwpjs(
|
|
22
|
+
reinterpret_cast<uintptr_t>(this),
|
|
23
|
+
rust::Str(dataPath.data(), dataPath.size())).into_raw(),
|
|
24
|
+
[](craby::hwpjs::bridging::Hwpjs *ptr) { rust::Box<craby::hwpjs::bridging::Hwpjs>::from_raw(ptr); }
|
|
25
|
+
);
|
|
26
|
+
threadPool_ = std::make_shared<craby::hwpjs::utils::ThreadPool>(10);
|
|
27
|
+
methodMap_["fileHeader"] = MethodMetadata{1, &CxxHwpjsModule::fileHeader};
|
|
28
|
+
methodMap_["toJson"] = MethodMetadata{1, &CxxHwpjsModule::toJson};
|
|
29
|
+
methodMap_["toMarkdown"] = MethodMetadata{2, &CxxHwpjsModule::toMarkdown};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
CxxHwpjsModule::~CxxHwpjsModule() {
|
|
33
|
+
invalidate();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void CxxHwpjsModule::invalidate() {
|
|
37
|
+
if (invalidated_.exchange(true)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
invalidated_.store(true);
|
|
42
|
+
listenersMap_.clear();
|
|
43
|
+
|
|
44
|
+
// No signals
|
|
45
|
+
|
|
46
|
+
// Shutdown thread pool
|
|
47
|
+
threadPool_->shutdown();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
jsi::Value CxxHwpjsModule::fileHeader(jsi::Runtime &rt,
|
|
51
|
+
react::TurboModule &turboModule,
|
|
52
|
+
const jsi::Value args[],
|
|
53
|
+
size_t count) {
|
|
54
|
+
auto &thisModule = static_cast<CxxHwpjsModule &>(turboModule);
|
|
55
|
+
auto callInvoker = thisModule.callInvoker_;
|
|
56
|
+
auto it_ = thisModule.module_;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
if (1 != count) {
|
|
60
|
+
throw jsi::JSError(rt, "Expected 1 argument");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
auto arg0 = react::bridging::fromJs<rust::Vec<double>>(rt, args[0], callInvoker);
|
|
64
|
+
auto ret = craby::hwpjs::bridging::fileHeader(*it_, arg0);
|
|
65
|
+
|
|
66
|
+
return react::bridging::toJs(rt, ret);
|
|
67
|
+
} catch (const jsi::JSError &err) {
|
|
68
|
+
throw err;
|
|
69
|
+
} catch (const std::exception &err) {
|
|
70
|
+
throw jsi::JSError(rt, craby::hwpjs::utils::errorMessage(err));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
jsi::Value CxxHwpjsModule::toJson(jsi::Runtime &rt,
|
|
75
|
+
react::TurboModule &turboModule,
|
|
76
|
+
const jsi::Value args[],
|
|
77
|
+
size_t count) {
|
|
78
|
+
auto &thisModule = static_cast<CxxHwpjsModule &>(turboModule);
|
|
79
|
+
auto callInvoker = thisModule.callInvoker_;
|
|
80
|
+
auto it_ = thisModule.module_;
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
if (1 != count) {
|
|
84
|
+
throw jsi::JSError(rt, "Expected 1 argument");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
auto arg0 = react::bridging::fromJs<rust::Vec<double>>(rt, args[0], callInvoker);
|
|
88
|
+
auto ret = craby::hwpjs::bridging::toJson(*it_, arg0);
|
|
89
|
+
|
|
90
|
+
return react::bridging::toJs(rt, ret);
|
|
91
|
+
} catch (const jsi::JSError &err) {
|
|
92
|
+
throw err;
|
|
93
|
+
} catch (const std::exception &err) {
|
|
94
|
+
throw jsi::JSError(rt, craby::hwpjs::utils::errorMessage(err));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
jsi::Value CxxHwpjsModule::toMarkdown(jsi::Runtime &rt,
|
|
99
|
+
react::TurboModule &turboModule,
|
|
100
|
+
const jsi::Value args[],
|
|
101
|
+
size_t count) {
|
|
102
|
+
auto &thisModule = static_cast<CxxHwpjsModule &>(turboModule);
|
|
103
|
+
auto callInvoker = thisModule.callInvoker_;
|
|
104
|
+
auto it_ = thisModule.module_;
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
if (2 != count) {
|
|
108
|
+
throw jsi::JSError(rt, "Expected 2 arguments");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
auto arg0 = react::bridging::fromJs<rust::Vec<double>>(rt, args[0], callInvoker);
|
|
112
|
+
auto arg1 = react::bridging::fromJs<craby::hwpjs::bridging::ToMarkdownOptions>(rt, args[1], callInvoker);
|
|
113
|
+
auto ret = craby::hwpjs::bridging::toMarkdown(*it_, arg0, arg1);
|
|
114
|
+
|
|
115
|
+
return react::bridging::toJs(rt, ret);
|
|
116
|
+
} catch (const jsi::JSError &err) {
|
|
117
|
+
throw err;
|
|
118
|
+
} catch (const std::exception &err) {
|
|
119
|
+
throw jsi::JSError(rt, craby::hwpjs::utils::errorMessage(err));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
} // namespace modules
|
|
124
|
+
} // namespace hwpjs
|
|
125
|
+
} // namespace craby
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Auto generated by Craby. DO NOT EDIT.
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "CrabyUtils.hpp"
|
|
5
|
+
#include "ffi.rs.h"
|
|
6
|
+
#include <ReactCommon/TurboModule.h>
|
|
7
|
+
#include <jsi/jsi.h>
|
|
8
|
+
#include <memory>
|
|
9
|
+
|
|
10
|
+
namespace craby {
|
|
11
|
+
namespace hwpjs {
|
|
12
|
+
namespace modules {
|
|
13
|
+
|
|
14
|
+
class JSI_EXPORT CxxHwpjsModule : public facebook::react::TurboModule {
|
|
15
|
+
public:
|
|
16
|
+
static constexpr const char *kModuleName = "Hwpjs";
|
|
17
|
+
static std::string dataPath;
|
|
18
|
+
|
|
19
|
+
CxxHwpjsModule(std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
|
|
20
|
+
~CxxHwpjsModule();
|
|
21
|
+
|
|
22
|
+
void invalidate();
|
|
23
|
+
static facebook::jsi::Value
|
|
24
|
+
fileHeader(facebook::jsi::Runtime &rt,
|
|
25
|
+
facebook::react::TurboModule &turboModule,
|
|
26
|
+
const facebook::jsi::Value args[], size_t count);
|
|
27
|
+
|
|
28
|
+
static facebook::jsi::Value
|
|
29
|
+
toJson(facebook::jsi::Runtime &rt,
|
|
30
|
+
facebook::react::TurboModule &turboModule,
|
|
31
|
+
const facebook::jsi::Value args[], size_t count);
|
|
32
|
+
|
|
33
|
+
static facebook::jsi::Value
|
|
34
|
+
toMarkdown(facebook::jsi::Runtime &rt,
|
|
35
|
+
facebook::react::TurboModule &turboModule,
|
|
36
|
+
const facebook::jsi::Value args[], size_t count);
|
|
37
|
+
|
|
38
|
+
protected:
|
|
39
|
+
std::shared_ptr<facebook::react::CallInvoker> callInvoker_;
|
|
40
|
+
std::shared_ptr<craby::hwpjs::bridging::Hwpjs> module_;
|
|
41
|
+
std::atomic<bool> invalidated_{false};
|
|
42
|
+
std::atomic<size_t> nextListenerId_{0};
|
|
43
|
+
std::mutex listenersMutex_;
|
|
44
|
+
std::unordered_map<
|
|
45
|
+
std::string,
|
|
46
|
+
std::unordered_map<size_t, std::shared_ptr<facebook::jsi::Function>>>
|
|
47
|
+
listenersMap_;
|
|
48
|
+
std::shared_ptr<craby::hwpjs::utils::ThreadPool> threadPool_;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
} // namespace modules
|
|
52
|
+
} // namespace hwpjs
|
|
53
|
+
} // namespace craby
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Auto generated by Craby. DO NOT EDIT.
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "cxx.h"
|
|
5
|
+
#include "ffi.rs.h"
|
|
6
|
+
#include <react/bridging/Bridging.h>
|
|
7
|
+
|
|
8
|
+
using namespace facebook;
|
|
9
|
+
|
|
10
|
+
namespace facebook {
|
|
11
|
+
namespace react {
|
|
12
|
+
|
|
13
|
+
template <>
|
|
14
|
+
struct Bridging<rust::Str> {
|
|
15
|
+
static rust::Str fromJs(jsi::Runtime& rt, const jsi::Value &value, std::shared_ptr<CallInvoker> callInvoker) {
|
|
16
|
+
auto str = value.asString(rt).utf8(rt);
|
|
17
|
+
return rust::Str(str.data(), str.size());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static jsi::Value toJs(jsi::Runtime& rt, const rust::Str& value) {
|
|
21
|
+
return react::bridging::toJs(rt, std::string(value.data(), value.size()));
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
template <>
|
|
26
|
+
struct Bridging<rust::String> {
|
|
27
|
+
static rust::String fromJs(jsi::Runtime& rt, const jsi::Value &value, std::shared_ptr<CallInvoker> callInvoker) {
|
|
28
|
+
auto str = value.asString(rt).utf8(rt);
|
|
29
|
+
return rust::String(str.data(), str.size());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static jsi::Value toJs(jsi::Runtime& rt, const rust::String& value) {
|
|
33
|
+
return react::bridging::toJs(rt, std::string(value.data(), value.size()));
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
template <typename T>
|
|
38
|
+
struct Bridging<rust::Vec<T>> {
|
|
39
|
+
static rust::Vec<T> fromJs(jsi::Runtime& rt, const jsi::Value &value, std::shared_ptr<CallInvoker> callInvoker) {
|
|
40
|
+
auto arr = value.asObject(rt).asArray(rt);
|
|
41
|
+
size_t len = arr.length(rt);
|
|
42
|
+
rust::Vec<T> vec;
|
|
43
|
+
vec.reserve(len);
|
|
44
|
+
|
|
45
|
+
for (size_t i = 0; i < len; i++) {
|
|
46
|
+
auto element = arr.getValueAtIndex(rt, i);
|
|
47
|
+
vec.push_back(react::bridging::fromJs<T>(rt, element, callInvoker));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return vec;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static jsi::Array toJs(jsi::Runtime& rt, const rust::Vec<T>& vec) {
|
|
54
|
+
auto arr = jsi::Array(rt, vec.size());
|
|
55
|
+
|
|
56
|
+
for (size_t i = 0; i < vec.size(); i++) {
|
|
57
|
+
auto jsElement = react::bridging::toJs(rt, vec[i]);
|
|
58
|
+
arr.setValueAtIndex(rt, i, jsElement);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return arr;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
template <>
|
|
66
|
+
struct Bridging<craby::hwpjs::bridging::NullableString> {
|
|
67
|
+
static craby::hwpjs::bridging::NullableString fromJs(jsi::Runtime &rt, const jsi::Value& value, std::shared_ptr<CallInvoker> callInvoker) {
|
|
68
|
+
if (value.isNull()) {
|
|
69
|
+
return craby::hwpjs::bridging::NullableString{true, rust::String()};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
auto val = react::bridging::fromJs<rust::String>(rt, value, callInvoker);
|
|
73
|
+
auto ret = craby::hwpjs::bridging::NullableString{false, val};
|
|
74
|
+
|
|
75
|
+
return ret;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static jsi::Value toJs(jsi::Runtime &rt, craby::hwpjs::bridging::NullableString value) {
|
|
79
|
+
if (value.null) {
|
|
80
|
+
return jsi::Value::null();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return react::bridging::toJs(rt, value.val);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
template <>
|
|
88
|
+
struct Bridging<craby::hwpjs::bridging::ToMarkdownOptions> {
|
|
89
|
+
static craby::hwpjs::bridging::ToMarkdownOptions fromJs(jsi::Runtime &rt, const jsi::Value& value, std::shared_ptr<CallInvoker> callInvoker) {
|
|
90
|
+
auto obj = value.asObject(rt);
|
|
91
|
+
auto obj$imageOutputDir = obj.getProperty(rt, "imageOutputDir");
|
|
92
|
+
auto obj$image = obj.getProperty(rt, "image");
|
|
93
|
+
auto obj$useHtml = obj.getProperty(rt, "useHtml");
|
|
94
|
+
auto obj$includeVersion = obj.getProperty(rt, "includeVersion");
|
|
95
|
+
auto obj$includePageInfo = obj.getProperty(rt, "includePageInfo");
|
|
96
|
+
|
|
97
|
+
auto _obj$imageOutputDir = react::bridging::fromJs<craby::hwpjs::bridging::NullableString>(rt, obj$imageOutputDir, callInvoker);
|
|
98
|
+
auto _obj$image = react::bridging::fromJs<craby::hwpjs::bridging::NullableString>(rt, obj$image, callInvoker);
|
|
99
|
+
auto _obj$useHtml = react::bridging::fromJs<bool>(rt, obj$useHtml, callInvoker);
|
|
100
|
+
auto _obj$includeVersion = react::bridging::fromJs<bool>(rt, obj$includeVersion, callInvoker);
|
|
101
|
+
auto _obj$includePageInfo = react::bridging::fromJs<bool>(rt, obj$includePageInfo, callInvoker);
|
|
102
|
+
|
|
103
|
+
craby::hwpjs::bridging::ToMarkdownOptions ret = {
|
|
104
|
+
_obj$imageOutputDir,
|
|
105
|
+
_obj$image,
|
|
106
|
+
_obj$useHtml,
|
|
107
|
+
_obj$includeVersion,
|
|
108
|
+
_obj$includePageInfo
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
return ret;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static jsi::Value toJs(jsi::Runtime &rt, craby::hwpjs::bridging::ToMarkdownOptions value) {
|
|
115
|
+
jsi::Object obj = jsi::Object(rt);
|
|
116
|
+
auto _obj$imageOutputDir = react::bridging::toJs(rt, value.image_output_dir);
|
|
117
|
+
auto _obj$image = react::bridging::toJs(rt, value.image);
|
|
118
|
+
auto _obj$useHtml = react::bridging::toJs(rt, value.use_html);
|
|
119
|
+
auto _obj$includeVersion = react::bridging::toJs(rt, value.include_version);
|
|
120
|
+
auto _obj$includePageInfo = react::bridging::toJs(rt, value.include_page_info);
|
|
121
|
+
|
|
122
|
+
obj.setProperty(rt, "imageOutputDir", _obj$imageOutputDir);
|
|
123
|
+
obj.setProperty(rt, "image", _obj$image);
|
|
124
|
+
obj.setProperty(rt, "useHtml", _obj$useHtml);
|
|
125
|
+
obj.setProperty(rt, "includeVersion", _obj$includeVersion);
|
|
126
|
+
obj.setProperty(rt, "includePageInfo", _obj$includePageInfo);
|
|
127
|
+
|
|
128
|
+
return jsi::Value(rt, obj);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
template <>
|
|
133
|
+
struct Bridging<craby::hwpjs::bridging::ToMarkdownResult> {
|
|
134
|
+
static craby::hwpjs::bridging::ToMarkdownResult fromJs(jsi::Runtime &rt, const jsi::Value& value, std::shared_ptr<CallInvoker> callInvoker) {
|
|
135
|
+
auto obj = value.asObject(rt);
|
|
136
|
+
auto obj$markdown = obj.getProperty(rt, "markdown");
|
|
137
|
+
|
|
138
|
+
auto _obj$markdown = react::bridging::fromJs<rust::String>(rt, obj$markdown, callInvoker);
|
|
139
|
+
|
|
140
|
+
craby::hwpjs::bridging::ToMarkdownResult ret = {
|
|
141
|
+
_obj$markdown
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return ret;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static jsi::Value toJs(jsi::Runtime &rt, craby::hwpjs::bridging::ToMarkdownResult value) {
|
|
148
|
+
jsi::Object obj = jsi::Object(rt);
|
|
149
|
+
auto _obj$markdown = react::bridging::toJs(rt, value.markdown);
|
|
150
|
+
|
|
151
|
+
obj.setProperty(rt, "markdown", _obj$markdown);
|
|
152
|
+
|
|
153
|
+
return jsi::Value(rt, obj);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
} // namespace react
|
|
158
|
+
} // namespace facebook
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@ohah/hwpjs-wasm32-wasi'
|
|
@@ -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-napi.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-napi.wasm32-wasi.wasm')
|
|
36
|
+
const __wasmDebugFilePath = __nodePath.join(__dirname, 'hwpjs-napi.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-napi.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
|