@kookyleo/graphviz-anywhere-rn 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.
- package/android/build.gradle +72 -0
- package/android/src/main/CMakeLists.txt +25 -0
- package/android/src/main/java/com/graphviznative/GraphvizModule.java +149 -0
- package/android/src/main/java/com/graphviznative/GraphvizPackage.java +37 -0
- package/android/src/main/jni/graphviz_jni.c +151 -0
- package/ios/GraphvizModule.h +23 -0
- package/ios/GraphvizModule.m +160 -0
- package/ios/GraphvizNative.podspec +33 -0
- package/lib/commonjs/NativeGraphviz.js +15 -0
- package/lib/commonjs/NativeGraphviz.js.map +1 -0
- package/lib/commonjs/index.js +95 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/NativeGraphviz.js +13 -0
- package/lib/module/NativeGraphviz.js.map +1 -0
- package/lib/module/index.js +89 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/NativeGraphviz.d.ts +25 -0
- package/lib/typescript/NativeGraphviz.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +60 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/macos/GraphvizModule.h +23 -0
- package/macos/GraphvizModule.m +163 -0
- package/package.json +95 -0
- package/scripts/download-native.js +98 -0
- package/src/NativeGraphviz.ts +27 -0
- package/src/index.ts +123 -0
- package/windows/GraphvizNative/GraphvizModule.cpp +159 -0
- package/windows/GraphvizNative/GraphvizModule.h +51 -0
- package/windows/GraphvizNative/ReactPackageProvider.cpp +20 -0
- package/windows/GraphvizNative/ReactPackageProvider.h +21 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Download prebuilt native libraries for React Native from GitHub Releases.
|
|
5
|
+
* Runs automatically on `npm install` via postinstall hook.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const https = require('https');
|
|
11
|
+
const { execSync } = require('child_process');
|
|
12
|
+
|
|
13
|
+
// Read version from package.json
|
|
14
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8'));
|
|
15
|
+
const version = pkg.version;
|
|
16
|
+
const tag = `v${version}`;
|
|
17
|
+
|
|
18
|
+
const GITHUB_REPO = 'nicekook/graphviz-anywhere';
|
|
19
|
+
const RELEASE_URL = `https://github.com/${GITHUB_REPO}/releases/download/${tag}`;
|
|
20
|
+
|
|
21
|
+
const downloads = [
|
|
22
|
+
{
|
|
23
|
+
name: 'graphviz-native-ios.tar.gz',
|
|
24
|
+
dest: path.join(__dirname, '../ios/Frameworks'),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'graphviz-native-macos-universal.tar.gz',
|
|
28
|
+
dest: path.join(__dirname, '../macos/Frameworks'),
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'graphviz-native-windows-x86_64.zip',
|
|
32
|
+
dest: path.join(__dirname, '../windows/Frameworks'),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'graphviz-native-android-arm64-v8a.tar.gz',
|
|
36
|
+
dest: path.join(__dirname, '../android/libs/arm64-v8a'),
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'graphviz-native-android-armeabi-v7a.tar.gz',
|
|
40
|
+
dest: path.join(__dirname, '../android/libs/armeabi-v7a'),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'graphviz-native-android-x86_64.tar.gz',
|
|
44
|
+
dest: path.join(__dirname, '../android/libs/x86_64'),
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
async function downloadFile(url, dest) {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
const file = fs.createWriteStream(dest);
|
|
51
|
+
https.get(url, (response) => {
|
|
52
|
+
response.pipe(file);
|
|
53
|
+
file.on('finish', () => {
|
|
54
|
+
file.close(resolve);
|
|
55
|
+
});
|
|
56
|
+
}).on('error', reject);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function main() {
|
|
61
|
+
console.log(`📦 Downloading prebuilt libraries for v${version}...`);
|
|
62
|
+
|
|
63
|
+
for (const { name, dest } of downloads) {
|
|
64
|
+
const url = `${RELEASE_URL}/${name}`;
|
|
65
|
+
const tempFile = path.join(__dirname, '../../', name);
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
// Create destination directory
|
|
69
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
70
|
+
|
|
71
|
+
console.log(` ⬇️ ${name}`);
|
|
72
|
+
|
|
73
|
+
// Download
|
|
74
|
+
await downloadFile(url, tempFile);
|
|
75
|
+
|
|
76
|
+
// Extract
|
|
77
|
+
if (name.endsWith('.tar.gz')) {
|
|
78
|
+
execSync(`tar -xzf "${tempFile}" -C "${dest}"`, { stdio: 'inherit' });
|
|
79
|
+
} else if (name.endsWith('.zip')) {
|
|
80
|
+
execSync(`unzip -o "${tempFile}" -d "${dest}"`, { stdio: 'inherit' });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Cleanup
|
|
84
|
+
fs.unlinkSync(tempFile);
|
|
85
|
+
console.log(` ✓ ${name}`);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.warn(` ⚠️ Failed to download ${name}: ${error.message}`);
|
|
88
|
+
// Continue with other downloads on error
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
console.log('✨ Done!');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
main().catch((error) => {
|
|
96
|
+
console.error('❌ Error:', error);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* TurboModule spec for the Graphviz native module (New Architecture).
|
|
6
|
+
*
|
|
7
|
+
* This interface defines the contract between JS and native code.
|
|
8
|
+
* For the old architecture, we fall back to NativeModules.
|
|
9
|
+
*/
|
|
10
|
+
export interface Spec extends TurboModule {
|
|
11
|
+
/**
|
|
12
|
+
* Render a DOT string to the specified format.
|
|
13
|
+
*
|
|
14
|
+
* @param dot - DOT language string
|
|
15
|
+
* @param engine - Layout engine (dot, neato, fdp, sfdp, circo, twopi, osage, patchwork)
|
|
16
|
+
* @param format - Output format (svg, png, pdf, ps, json, dot, xdot, plain)
|
|
17
|
+
* @returns Rendered output as a string (base64 for binary formats)
|
|
18
|
+
*/
|
|
19
|
+
renderDot(dot: string, engine: string, format: string): Promise<string>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get the Graphviz library version string.
|
|
23
|
+
*/
|
|
24
|
+
getVersion(): Promise<string>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('GraphvizNative');
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
const LINKING_ERROR =
|
|
4
|
+
`The package 'graphviz-anywhere-react-native' doesn't seem to be linked. Make sure:\n\n` +
|
|
5
|
+
Platform.select({
|
|
6
|
+
ios: '- You have run `pod install`\n',
|
|
7
|
+
macos: '- You have run `pod install`\n',
|
|
8
|
+
android: '',
|
|
9
|
+
windows: '',
|
|
10
|
+
default: '',
|
|
11
|
+
}) +
|
|
12
|
+
'- You rebuilt the app after installing the package\n' +
|
|
13
|
+
'- You are not using Expo Go\n';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Error codes returned by the native Graphviz module.
|
|
17
|
+
*/
|
|
18
|
+
export const GraphvizErrorCode = {
|
|
19
|
+
NULL_INPUT: 'NULL_INPUT',
|
|
20
|
+
INVALID_DOT: 'INVALID_DOT',
|
|
21
|
+
LAYOUT_FAILED: 'LAYOUT_FAILED',
|
|
22
|
+
RENDER_FAILED: 'RENDER_FAILED',
|
|
23
|
+
INVALID_ENGINE: 'INVALID_ENGINE',
|
|
24
|
+
INVALID_FORMAT: 'INVALID_FORMAT',
|
|
25
|
+
OUT_OF_MEMORY: 'OUT_OF_MEMORY',
|
|
26
|
+
NOT_INITIALIZED: 'NOT_INITIALIZED',
|
|
27
|
+
UNKNOWN: 'UNKNOWN',
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
export type GraphvizErrorCodeType =
|
|
31
|
+
(typeof GraphvizErrorCode)[keyof typeof GraphvizErrorCode];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Layout engines supported by Graphviz.
|
|
35
|
+
*/
|
|
36
|
+
export type GraphvizEngine =
|
|
37
|
+
| 'dot'
|
|
38
|
+
| 'neato'
|
|
39
|
+
| 'fdp'
|
|
40
|
+
| 'sfdp'
|
|
41
|
+
| 'circo'
|
|
42
|
+
| 'twopi'
|
|
43
|
+
| 'osage'
|
|
44
|
+
| 'patchwork';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Output formats supported by Graphviz.
|
|
48
|
+
*/
|
|
49
|
+
export type GraphvizFormat =
|
|
50
|
+
| 'svg'
|
|
51
|
+
| 'png'
|
|
52
|
+
| 'pdf'
|
|
53
|
+
| 'ps'
|
|
54
|
+
| 'json'
|
|
55
|
+
| 'dot'
|
|
56
|
+
| 'xdot'
|
|
57
|
+
| 'plain';
|
|
58
|
+
|
|
59
|
+
interface NativeGraphvizModule {
|
|
60
|
+
renderDot(dot: string, engine: string, format: string): Promise<string>;
|
|
61
|
+
getVersion(): Promise<string>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Resolve the native module, preferring TurboModules (new arch) with
|
|
66
|
+
* fallback to the bridge-based NativeModules (old arch).
|
|
67
|
+
*/
|
|
68
|
+
function getNativeModule(): NativeGraphvizModule {
|
|
69
|
+
// Try TurboModule first (new architecture)
|
|
70
|
+
try {
|
|
71
|
+
const turbo = require('./NativeGraphviz').default;
|
|
72
|
+
if (turbo) {
|
|
73
|
+
return turbo as NativeGraphvizModule;
|
|
74
|
+
}
|
|
75
|
+
} catch {
|
|
76
|
+
// TurboModules not available, fall through
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Fallback to old architecture NativeModules
|
|
80
|
+
const nativeModule = NativeModules.GraphvizNative;
|
|
81
|
+
if (!nativeModule) {
|
|
82
|
+
throw new Error(LINKING_ERROR);
|
|
83
|
+
}
|
|
84
|
+
return nativeModule as NativeGraphvizModule;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const GraphvizNative: NativeGraphvizModule = getNativeModule();
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Render a DOT language string into the specified output format.
|
|
91
|
+
*
|
|
92
|
+
* All rendering is performed on a background thread and the result
|
|
93
|
+
* is delivered asynchronously via a Promise.
|
|
94
|
+
*
|
|
95
|
+
* @param dot - DOT language string describing the graph
|
|
96
|
+
* @param engine - Layout engine to use (default: "dot")
|
|
97
|
+
* @param format - Output format (default: "svg")
|
|
98
|
+
* @returns Promise resolving to the rendered output string.
|
|
99
|
+
* For text formats (svg, json, dot, xdot, plain) the raw text is returned.
|
|
100
|
+
* For binary formats (png, pdf, ps) the output is base64-encoded.
|
|
101
|
+
*/
|
|
102
|
+
export async function renderDot(
|
|
103
|
+
dot: string,
|
|
104
|
+
engine: GraphvizEngine = 'dot',
|
|
105
|
+
format: GraphvizFormat = 'svg'
|
|
106
|
+
): Promise<string> {
|
|
107
|
+
return GraphvizNative.renderDot(dot, engine, format);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get the Graphviz library version string.
|
|
112
|
+
*
|
|
113
|
+
* @returns Promise resolving to the version string (e.g. "12.2.1")
|
|
114
|
+
*/
|
|
115
|
+
export async function getVersion(): Promise<string> {
|
|
116
|
+
return GraphvizNative.getVersion();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default {
|
|
120
|
+
renderDot,
|
|
121
|
+
getVersion,
|
|
122
|
+
GraphvizErrorCode,
|
|
123
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* GraphvizModule.cpp (Windows)
|
|
3
|
+
*
|
|
4
|
+
* C++/WinRT React Native module implementation for Windows.
|
|
5
|
+
* Manages a singleton Graphviz context with mutex-protected access.
|
|
6
|
+
* Promise resolution dispatches work via the thread pool.
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "GraphvizModule.h"
|
|
12
|
+
|
|
13
|
+
#include <thread>
|
|
14
|
+
#include <cstring>
|
|
15
|
+
|
|
16
|
+
namespace GraphvizNative {
|
|
17
|
+
|
|
18
|
+
static const char kBase64Table[] =
|
|
19
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
20
|
+
|
|
21
|
+
GraphvizModule::GraphvizModule() : m_context(nullptr) {}
|
|
22
|
+
|
|
23
|
+
GraphvizModule::~GraphvizModule() {
|
|
24
|
+
std::lock_guard<std::mutex> lock(m_mutex);
|
|
25
|
+
if (m_context) {
|
|
26
|
+
gv_context_free(m_context);
|
|
27
|
+
m_context = nullptr;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
gv_context_t* GraphvizModule::ensureContext() {
|
|
32
|
+
// Caller must hold m_mutex
|
|
33
|
+
if (!m_context) {
|
|
34
|
+
m_context = gv_context_new();
|
|
35
|
+
}
|
|
36
|
+
return m_context;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
std::string GraphvizModule::errorCodeToString(gv_error_t err) {
|
|
40
|
+
switch (err) {
|
|
41
|
+
case GV_ERR_NULL_INPUT: return "NULL_INPUT";
|
|
42
|
+
case GV_ERR_INVALID_DOT: return "INVALID_DOT";
|
|
43
|
+
case GV_ERR_LAYOUT_FAILED: return "LAYOUT_FAILED";
|
|
44
|
+
case GV_ERR_RENDER_FAILED: return "RENDER_FAILED";
|
|
45
|
+
case GV_ERR_INVALID_ENGINE: return "INVALID_ENGINE";
|
|
46
|
+
case GV_ERR_INVALID_FORMAT: return "INVALID_FORMAT";
|
|
47
|
+
case GV_ERR_OUT_OF_MEMORY: return "OUT_OF_MEMORY";
|
|
48
|
+
case GV_ERR_NOT_INITIALIZED: return "NOT_INITIALIZED";
|
|
49
|
+
default: return "UNKNOWN";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
bool GraphvizModule::isTextFormat(const std::string& format) {
|
|
54
|
+
return format == "svg" ||
|
|
55
|
+
format == "json" ||
|
|
56
|
+
format == "dot" ||
|
|
57
|
+
format == "xdot" ||
|
|
58
|
+
format == "plain";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
std::string GraphvizModule::base64Encode(const char* data, size_t length) {
|
|
62
|
+
std::string output;
|
|
63
|
+
size_t olen = 4 * ((length + 2) / 3);
|
|
64
|
+
output.resize(olen);
|
|
65
|
+
|
|
66
|
+
size_t i = 0, j = 0;
|
|
67
|
+
while (i < length) {
|
|
68
|
+
uint32_t a = i < length ? static_cast<uint8_t>(data[i++]) : 0;
|
|
69
|
+
uint32_t b = i < length ? static_cast<uint8_t>(data[i++]) : 0;
|
|
70
|
+
uint32_t c = i < length ? static_cast<uint8_t>(data[i++]) : 0;
|
|
71
|
+
uint32_t triple = (a << 16) | (b << 8) | c;
|
|
72
|
+
|
|
73
|
+
output[j++] = kBase64Table[(triple >> 18) & 0x3F];
|
|
74
|
+
output[j++] = kBase64Table[(triple >> 12) & 0x3F];
|
|
75
|
+
output[j++] = kBase64Table[(triple >> 6) & 0x3F];
|
|
76
|
+
output[j++] = kBase64Table[triple & 0x3F];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
size_t mod = length % 3;
|
|
80
|
+
if (mod == 1) {
|
|
81
|
+
output[olen - 1] = '=';
|
|
82
|
+
output[olen - 2] = '=';
|
|
83
|
+
} else if (mod == 2) {
|
|
84
|
+
output[olen - 1] = '=';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return output;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void GraphvizModule::renderDot(
|
|
91
|
+
std::string dot,
|
|
92
|
+
std::string engine,
|
|
93
|
+
std::string format,
|
|
94
|
+
React::ReactPromise<std::string> promise) noexcept {
|
|
95
|
+
|
|
96
|
+
// Dispatch to a worker thread to avoid blocking the JS thread
|
|
97
|
+
std::thread([this, dot = std::move(dot), engine = std::move(engine),
|
|
98
|
+
format = std::move(format), promise = std::move(promise)]() mutable {
|
|
99
|
+
std::lock_guard<std::mutex> lock(m_mutex);
|
|
100
|
+
|
|
101
|
+
gv_context_t* ctx = ensureContext();
|
|
102
|
+
if (!ctx) {
|
|
103
|
+
promise.Reject(React::ReactError{
|
|
104
|
+
"NOT_INITIALIZED",
|
|
105
|
+
"Failed to initialize Graphviz context"
|
|
106
|
+
});
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
char* outData = nullptr;
|
|
111
|
+
size_t outLength = 0;
|
|
112
|
+
|
|
113
|
+
gv_error_t err = gv_render(
|
|
114
|
+
ctx,
|
|
115
|
+
dot.c_str(),
|
|
116
|
+
engine.c_str(),
|
|
117
|
+
format.c_str(),
|
|
118
|
+
&outData,
|
|
119
|
+
&outLength
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
if (err != GV_OK) {
|
|
123
|
+
std::string code = errorCodeToString(err);
|
|
124
|
+
const char* msg = gv_strerror(err);
|
|
125
|
+
promise.Reject(React::ReactError{
|
|
126
|
+
code,
|
|
127
|
+
msg ? std::string(msg) : "Unknown error"
|
|
128
|
+
});
|
|
129
|
+
if (outData) {
|
|
130
|
+
gv_free_render_data(outData);
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
std::string result;
|
|
136
|
+
if (isTextFormat(format)) {
|
|
137
|
+
result = std::string(outData, outLength);
|
|
138
|
+
} else {
|
|
139
|
+
result = base64Encode(outData, outLength);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
gv_free_render_data(outData);
|
|
143
|
+
promise.Resolve(result);
|
|
144
|
+
}).detach();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
void GraphvizModule::getVersion(React::ReactPromise<std::string> promise) noexcept {
|
|
148
|
+
const char* version = gv_version();
|
|
149
|
+
if (version) {
|
|
150
|
+
promise.Resolve(std::string(version));
|
|
151
|
+
} else {
|
|
152
|
+
promise.Reject(React::ReactError{
|
|
153
|
+
"UNKNOWN",
|
|
154
|
+
"Failed to get Graphviz version"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
} // namespace GraphvizNative
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* GraphvizModule.h (Windows)
|
|
3
|
+
*
|
|
4
|
+
* C++/WinRT React Native module for Graphviz rendering on Windows.
|
|
5
|
+
* Uses the react-native-windows native module API.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <functional>
|
|
13
|
+
#include <string>
|
|
14
|
+
#include <mutex>
|
|
15
|
+
|
|
16
|
+
#include <NativeModules.h>
|
|
17
|
+
|
|
18
|
+
extern "C" {
|
|
19
|
+
#include "graphviz_api.h"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
namespace GraphvizNative {
|
|
23
|
+
|
|
24
|
+
REACT_MODULE(GraphvizModule, L"GraphvizNative")
|
|
25
|
+
struct GraphvizModule {
|
|
26
|
+
|
|
27
|
+
GraphvizModule();
|
|
28
|
+
~GraphvizModule();
|
|
29
|
+
|
|
30
|
+
REACT_METHOD(renderDot, L"renderDot")
|
|
31
|
+
void renderDot(
|
|
32
|
+
std::string dot,
|
|
33
|
+
std::string engine,
|
|
34
|
+
std::string format,
|
|
35
|
+
React::ReactPromise<std::string> promise) noexcept;
|
|
36
|
+
|
|
37
|
+
REACT_METHOD(getVersion, L"getVersion")
|
|
38
|
+
void getVersion(React::ReactPromise<std::string> promise) noexcept;
|
|
39
|
+
|
|
40
|
+
private:
|
|
41
|
+
gv_context_t* ensureContext();
|
|
42
|
+
|
|
43
|
+
gv_context_t* m_context;
|
|
44
|
+
std::mutex m_mutex;
|
|
45
|
+
|
|
46
|
+
static std::string errorCodeToString(gv_error_t err);
|
|
47
|
+
static bool isTextFormat(const std::string& format);
|
|
48
|
+
static std::string base64Encode(const char* data, size_t length);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
} // namespace GraphvizNative
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ReactPackageProvider.cpp (Windows)
|
|
3
|
+
*
|
|
4
|
+
* Registers the GraphvizModule with the React Native Windows runtime.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include "ReactPackageProvider.h"
|
|
10
|
+
|
|
11
|
+
#include <NativeModules.h>
|
|
12
|
+
|
|
13
|
+
namespace winrt::GraphvizNative::implementation {
|
|
14
|
+
|
|
15
|
+
void ReactPackageProvider::CreatePackage(
|
|
16
|
+
winrt::Microsoft::ReactNative::IReactPackageBuilder const& packageBuilder) noexcept {
|
|
17
|
+
AddAttributedModules(packageBuilder, true);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
} // namespace winrt::GraphvizNative::implementation
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ReactPackageProvider.h (Windows)
|
|
3
|
+
*
|
|
4
|
+
* Registers the GraphvizModule with the React Native Windows runtime.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include <winrt/Microsoft.ReactNative.h>
|
|
12
|
+
|
|
13
|
+
namespace winrt::GraphvizNative::implementation {
|
|
14
|
+
|
|
15
|
+
struct ReactPackageProvider
|
|
16
|
+
: winrt::implements<ReactPackageProvider, winrt::Microsoft::ReactNative::IReactPackageProvider> {
|
|
17
|
+
|
|
18
|
+
void CreatePackage(winrt::Microsoft::ReactNative::IReactPackageBuilder const& packageBuilder) noexcept;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
} // namespace winrt::GraphvizNative::implementation
|