@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.
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.GraphvizErrorCode = void 0;
7
+ exports.getVersion = getVersion;
8
+ exports.renderDot = renderDot;
9
+ var _reactNative = require("react-native");
10
+ const LINKING_ERROR = `The package 'graphviz-anywhere-react-native' doesn't seem to be linked. Make sure:\n\n` + _reactNative.Platform.select({
11
+ ios: '- You have run `pod install`\n',
12
+ macos: '- You have run `pod install`\n',
13
+ android: '',
14
+ windows: '',
15
+ default: ''
16
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
17
+
18
+ /**
19
+ * Error codes returned by the native Graphviz module.
20
+ */
21
+ const GraphvizErrorCode = exports.GraphvizErrorCode = {
22
+ NULL_INPUT: 'NULL_INPUT',
23
+ INVALID_DOT: 'INVALID_DOT',
24
+ LAYOUT_FAILED: 'LAYOUT_FAILED',
25
+ RENDER_FAILED: 'RENDER_FAILED',
26
+ INVALID_ENGINE: 'INVALID_ENGINE',
27
+ INVALID_FORMAT: 'INVALID_FORMAT',
28
+ OUT_OF_MEMORY: 'OUT_OF_MEMORY',
29
+ NOT_INITIALIZED: 'NOT_INITIALIZED',
30
+ UNKNOWN: 'UNKNOWN'
31
+ };
32
+
33
+ /**
34
+ * Layout engines supported by Graphviz.
35
+ */
36
+
37
+ /**
38
+ * Output formats supported by Graphviz.
39
+ */
40
+
41
+ /**
42
+ * Resolve the native module, preferring TurboModules (new arch) with
43
+ * fallback to the bridge-based NativeModules (old arch).
44
+ */
45
+ function getNativeModule() {
46
+ // Try TurboModule first (new architecture)
47
+ try {
48
+ const turbo = require('./NativeGraphviz').default;
49
+ if (turbo) {
50
+ return turbo;
51
+ }
52
+ } catch {
53
+ // TurboModules not available, fall through
54
+ }
55
+
56
+ // Fallback to old architecture NativeModules
57
+ const nativeModule = _reactNative.NativeModules.GraphvizNative;
58
+ if (!nativeModule) {
59
+ throw new Error(LINKING_ERROR);
60
+ }
61
+ return nativeModule;
62
+ }
63
+ const GraphvizNative = getNativeModule();
64
+
65
+ /**
66
+ * Render a DOT language string into the specified output format.
67
+ *
68
+ * All rendering is performed on a background thread and the result
69
+ * is delivered asynchronously via a Promise.
70
+ *
71
+ * @param dot - DOT language string describing the graph
72
+ * @param engine - Layout engine to use (default: "dot")
73
+ * @param format - Output format (default: "svg")
74
+ * @returns Promise resolving to the rendered output string.
75
+ * For text formats (svg, json, dot, xdot, plain) the raw text is returned.
76
+ * For binary formats (png, pdf, ps) the output is base64-encoded.
77
+ */
78
+ async function renderDot(dot, engine = 'dot', format = 'svg') {
79
+ return GraphvizNative.renderDot(dot, engine, format);
80
+ }
81
+
82
+ /**
83
+ * Get the Graphviz library version string.
84
+ *
85
+ * @returns Promise resolving to the version string (e.g. "12.2.1")
86
+ */
87
+ async function getVersion() {
88
+ return GraphvizNative.getVersion();
89
+ }
90
+ var _default = exports.default = {
91
+ renderDot,
92
+ getVersion,
93
+ GraphvizErrorCode
94
+ };
95
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","macos","android","windows","default","GraphvizErrorCode","exports","NULL_INPUT","INVALID_DOT","LAYOUT_FAILED","RENDER_FAILED","INVALID_ENGINE","INVALID_FORMAT","OUT_OF_MEMORY","NOT_INITIALIZED","UNKNOWN","getNativeModule","turbo","nativeModule","NativeModules","GraphvizNative","Error","renderDot","dot","engine","format","getVersion","_default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,wFAAwF,GACxFC,qBAAQ,CAACC,MAAM,CAAC;EACdC,GAAG,EAAE,gCAAgC;EACrCC,KAAK,EAAE,gCAAgC;EACvCC,OAAO,EAAE,EAAE;EACXC,OAAO,EAAE,EAAE;EACXC,OAAO,EAAE;AACX,CAAC,CAAC,GACF,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA;AACA;AACO,MAAMC,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG;EAC/BE,UAAU,EAAE,YAAY;EACxBC,WAAW,EAAE,aAAa;EAC1BC,aAAa,EAAE,eAAe;EAC9BC,aAAa,EAAE,eAAe;EAC9BC,cAAc,EAAE,gBAAgB;EAChCC,cAAc,EAAE,gBAAgB;EAChCC,aAAa,EAAE,eAAe;EAC9BC,eAAe,EAAE,iBAAiB;EAClCC,OAAO,EAAE;AACX,CAAU;;AAKV;AACA;AACA;;AAWA;AACA;AACA;;AAgBA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAAA,EAAyB;EAC/C;EACA,IAAI;IACF,MAAMC,KAAK,GAAGrB,OAAO,CAAC,kBAAkB,CAAC,CAACQ,OAAO;IACjD,IAAIa,KAAK,EAAE;MACT,OAAOA,KAAK;IACd;EACF,CAAC,CAAC,MAAM;IACN;EAAA;;EAGF;EACA,MAAMC,YAAY,GAAGC,0BAAa,CAACC,cAAc;EACjD,IAAI,CAACF,YAAY,EAAE;IACjB,MAAM,IAAIG,KAAK,CAACxB,aAAa,CAAC;EAChC;EACA,OAAOqB,YAAY;AACrB;AAEA,MAAME,cAAoC,GAAGJ,eAAe,CAAC,CAAC;;AAE9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeM,SAASA,CAC7BC,GAAW,EACXC,MAAsB,GAAG,KAAK,EAC9BC,MAAsB,GAAG,KAAK,EACb;EACjB,OAAOL,cAAc,CAACE,SAAS,CAACC,GAAG,EAAEC,MAAM,EAAEC,MAAM,CAAC;AACtD;;AAEA;AACA;AACA;AACA;AACA;AACO,eAAeC,UAAUA,CAAA,EAAoB;EAClD,OAAON,cAAc,CAACM,UAAU,CAAC,CAAC;AACpC;AAAC,IAAAC,QAAA,GAAArB,OAAA,CAAAF,OAAA,GAEc;EACbkB,SAAS;EACTI,UAAU;EACVrB;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+
5
+ /**
6
+ * TurboModule spec for the Graphviz native module (New Architecture).
7
+ *
8
+ * This interface defines the contract between JS and native code.
9
+ * For the old architecture, we fall back to NativeModules.
10
+ */
11
+
12
+ export default TurboModuleRegistry.getEnforcing('GraphvizNative');
13
+ //# sourceMappingURL=NativeGraphviz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeGraphviz.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;;AAElD;AACA;AACA;AACA;AACA;AACA;;AAkBA,eAAeA,mBAAmB,CAACC,YAAY,CAAO,gBAAgB,CAAC","ignoreList":[]}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ import { NativeModules, Platform } from 'react-native';
4
+ const LINKING_ERROR = `The package 'graphviz-anywhere-react-native' doesn't seem to be linked. Make sure:\n\n` + Platform.select({
5
+ ios: '- You have run `pod install`\n',
6
+ macos: '- You have run `pod install`\n',
7
+ android: '',
8
+ windows: '',
9
+ default: ''
10
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
11
+
12
+ /**
13
+ * Error codes returned by the native Graphviz module.
14
+ */
15
+ export const GraphvizErrorCode = {
16
+ NULL_INPUT: 'NULL_INPUT',
17
+ INVALID_DOT: 'INVALID_DOT',
18
+ LAYOUT_FAILED: 'LAYOUT_FAILED',
19
+ RENDER_FAILED: 'RENDER_FAILED',
20
+ INVALID_ENGINE: 'INVALID_ENGINE',
21
+ INVALID_FORMAT: 'INVALID_FORMAT',
22
+ OUT_OF_MEMORY: 'OUT_OF_MEMORY',
23
+ NOT_INITIALIZED: 'NOT_INITIALIZED',
24
+ UNKNOWN: 'UNKNOWN'
25
+ };
26
+
27
+ /**
28
+ * Layout engines supported by Graphviz.
29
+ */
30
+
31
+ /**
32
+ * Output formats supported by Graphviz.
33
+ */
34
+
35
+ /**
36
+ * Resolve the native module, preferring TurboModules (new arch) with
37
+ * fallback to the bridge-based NativeModules (old arch).
38
+ */
39
+ function getNativeModule() {
40
+ // Try TurboModule first (new architecture)
41
+ try {
42
+ const turbo = require('./NativeGraphviz').default;
43
+ if (turbo) {
44
+ return turbo;
45
+ }
46
+ } catch {
47
+ // TurboModules not available, fall through
48
+ }
49
+
50
+ // Fallback to old architecture NativeModules
51
+ const nativeModule = NativeModules.GraphvizNative;
52
+ if (!nativeModule) {
53
+ throw new Error(LINKING_ERROR);
54
+ }
55
+ return nativeModule;
56
+ }
57
+ const GraphvizNative = getNativeModule();
58
+
59
+ /**
60
+ * Render a DOT language string into the specified output format.
61
+ *
62
+ * All rendering is performed on a background thread and the result
63
+ * is delivered asynchronously via a Promise.
64
+ *
65
+ * @param dot - DOT language string describing the graph
66
+ * @param engine - Layout engine to use (default: "dot")
67
+ * @param format - Output format (default: "svg")
68
+ * @returns Promise resolving to the rendered output string.
69
+ * For text formats (svg, json, dot, xdot, plain) the raw text is returned.
70
+ * For binary formats (png, pdf, ps) the output is base64-encoded.
71
+ */
72
+ export async function renderDot(dot, engine = 'dot', format = 'svg') {
73
+ return GraphvizNative.renderDot(dot, engine, format);
74
+ }
75
+
76
+ /**
77
+ * Get the Graphviz library version string.
78
+ *
79
+ * @returns Promise resolving to the version string (e.g. "12.2.1")
80
+ */
81
+ export async function getVersion() {
82
+ return GraphvizNative.getVersion();
83
+ }
84
+ export default {
85
+ renderDot,
86
+ getVersion,
87
+ GraphvizErrorCode
88
+ };
89
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","macos","android","windows","default","GraphvizErrorCode","NULL_INPUT","INVALID_DOT","LAYOUT_FAILED","RENDER_FAILED","INVALID_ENGINE","INVALID_FORMAT","OUT_OF_MEMORY","NOT_INITIALIZED","UNKNOWN","getNativeModule","turbo","require","nativeModule","GraphvizNative","Error","renderDot","dot","engine","format","getVersion"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,wFAAwF,GACxFD,QAAQ,CAACE,MAAM,CAAC;EACdC,GAAG,EAAE,gCAAgC;EACrCC,KAAK,EAAE,gCAAgC;EACvCC,OAAO,EAAE,EAAE;EACXC,OAAO,EAAE,EAAE;EACXC,OAAO,EAAE;AACX,CAAC,CAAC,GACF,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA;AACA;AACA,OAAO,MAAMC,iBAAiB,GAAG;EAC/BC,UAAU,EAAE,YAAY;EACxBC,WAAW,EAAE,aAAa;EAC1BC,aAAa,EAAE,eAAe;EAC9BC,aAAa,EAAE,eAAe;EAC9BC,cAAc,EAAE,gBAAgB;EAChCC,cAAc,EAAE,gBAAgB;EAChCC,aAAa,EAAE,eAAe;EAC9BC,eAAe,EAAE,iBAAiB;EAClCC,OAAO,EAAE;AACX,CAAU;;AAKV;AACA;AACA;;AAWA;AACA;AACA;;AAgBA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAAA,EAAyB;EAC/C;EACA,IAAI;IACF,MAAMC,KAAK,GAAGC,OAAO,CAAC,kBAAkB,CAAC,CAACb,OAAO;IACjD,IAAIY,KAAK,EAAE;MACT,OAAOA,KAAK;IACd;EACF,CAAC,CAAC,MAAM;IACN;EAAA;;EAGF;EACA,MAAME,YAAY,GAAGtB,aAAa,CAACuB,cAAc;EACjD,IAAI,CAACD,YAAY,EAAE;IACjB,MAAM,IAAIE,KAAK,CAACtB,aAAa,CAAC;EAChC;EACA,OAAOoB,YAAY;AACrB;AAEA,MAAMC,cAAoC,GAAGJ,eAAe,CAAC,CAAC;;AAE9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeM,SAASA,CAC7BC,GAAW,EACXC,MAAsB,GAAG,KAAK,EAC9BC,MAAsB,GAAG,KAAK,EACb;EACjB,OAAOL,cAAc,CAACE,SAAS,CAACC,GAAG,EAAEC,MAAM,EAAEC,MAAM,CAAC;AACtD;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,UAAUA,CAAA,EAAoB;EAClD,OAAON,cAAc,CAACM,UAAU,CAAC,CAAC;AACpC;AAEA,eAAe;EACbJ,SAAS;EACTI,UAAU;EACVpB;AACF,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,25 @@
1
+ import type { TurboModule } from 'react-native';
2
+ /**
3
+ * TurboModule spec for the Graphviz native module (New Architecture).
4
+ *
5
+ * This interface defines the contract between JS and native code.
6
+ * For the old architecture, we fall back to NativeModules.
7
+ */
8
+ export interface Spec extends TurboModule {
9
+ /**
10
+ * Render a DOT string to the specified format.
11
+ *
12
+ * @param dot - DOT language string
13
+ * @param engine - Layout engine (dot, neato, fdp, sfdp, circo, twopi, osage, patchwork)
14
+ * @param format - Output format (svg, png, pdf, ps, json, dot, xdot, plain)
15
+ * @returns Rendered output as a string (base64 for binary formats)
16
+ */
17
+ renderDot(dot: string, engine: string, format: string): Promise<string>;
18
+ /**
19
+ * Get the Graphviz library version string.
20
+ */
21
+ getVersion(): Promise<string>;
22
+ }
23
+ declare const _default: Spec;
24
+ export default _default;
25
+ //# sourceMappingURL=NativeGraphviz.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeGraphviz.d.ts","sourceRoot":"","sources":["../../src/NativeGraphviz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD;;;;;GAKG;AACH,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC;;;;;;;OAOG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAExE;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/B;;AAED,wBAAwE"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Error codes returned by the native Graphviz module.
3
+ */
4
+ export declare const GraphvizErrorCode: {
5
+ readonly NULL_INPUT: "NULL_INPUT";
6
+ readonly INVALID_DOT: "INVALID_DOT";
7
+ readonly LAYOUT_FAILED: "LAYOUT_FAILED";
8
+ readonly RENDER_FAILED: "RENDER_FAILED";
9
+ readonly INVALID_ENGINE: "INVALID_ENGINE";
10
+ readonly INVALID_FORMAT: "INVALID_FORMAT";
11
+ readonly OUT_OF_MEMORY: "OUT_OF_MEMORY";
12
+ readonly NOT_INITIALIZED: "NOT_INITIALIZED";
13
+ readonly UNKNOWN: "UNKNOWN";
14
+ };
15
+ export type GraphvizErrorCodeType = (typeof GraphvizErrorCode)[keyof typeof GraphvizErrorCode];
16
+ /**
17
+ * Layout engines supported by Graphviz.
18
+ */
19
+ export type GraphvizEngine = 'dot' | 'neato' | 'fdp' | 'sfdp' | 'circo' | 'twopi' | 'osage' | 'patchwork';
20
+ /**
21
+ * Output formats supported by Graphviz.
22
+ */
23
+ export type GraphvizFormat = 'svg' | 'png' | 'pdf' | 'ps' | 'json' | 'dot' | 'xdot' | 'plain';
24
+ /**
25
+ * Render a DOT language string into the specified output format.
26
+ *
27
+ * All rendering is performed on a background thread and the result
28
+ * is delivered asynchronously via a Promise.
29
+ *
30
+ * @param dot - DOT language string describing the graph
31
+ * @param engine - Layout engine to use (default: "dot")
32
+ * @param format - Output format (default: "svg")
33
+ * @returns Promise resolving to the rendered output string.
34
+ * For text formats (svg, json, dot, xdot, plain) the raw text is returned.
35
+ * For binary formats (png, pdf, ps) the output is base64-encoded.
36
+ */
37
+ export declare function renderDot(dot: string, engine?: GraphvizEngine, format?: GraphvizFormat): Promise<string>;
38
+ /**
39
+ * Get the Graphviz library version string.
40
+ *
41
+ * @returns Promise resolving to the version string (e.g. "12.2.1")
42
+ */
43
+ export declare function getVersion(): Promise<string>;
44
+ declare const _default: {
45
+ renderDot: typeof renderDot;
46
+ getVersion: typeof getVersion;
47
+ GraphvizErrorCode: {
48
+ readonly NULL_INPUT: "NULL_INPUT";
49
+ readonly INVALID_DOT: "INVALID_DOT";
50
+ readonly LAYOUT_FAILED: "LAYOUT_FAILED";
51
+ readonly RENDER_FAILED: "RENDER_FAILED";
52
+ readonly INVALID_ENGINE: "INVALID_ENGINE";
53
+ readonly INVALID_FORMAT: "INVALID_FORMAT";
54
+ readonly OUT_OF_MEMORY: "OUT_OF_MEMORY";
55
+ readonly NOT_INITIALIZED: "NOT_INITIALIZED";
56
+ readonly UNKNOWN: "UNKNOWN";
57
+ };
58
+ };
59
+ export default _default;
60
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;CAUpB,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAC/B,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,KAAK,GACL,OAAO,GACP,KAAK,GACL,MAAM,GACN,OAAO,GACP,OAAO,GACP,OAAO,GACP,WAAW,CAAC;AAEhB;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,KAAK,GACL,KAAK,GACL,KAAK,GACL,IAAI,GACJ,MAAM,GACN,KAAK,GACL,MAAM,GACN,OAAO,CAAC;AAgCZ;;;;;;;;;;;;GAYG;AACH,wBAAsB,SAAS,CAC7B,GAAG,EAAE,MAAM,EACX,MAAM,GAAE,cAAsB,EAC9B,MAAM,GAAE,cAAsB,GAC7B,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED;;;;GAIG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAElD;;;;;;;;;;;;;;;;AAED,wBAIE"}
@@ -0,0 +1,23 @@
1
+ /*
2
+ * GraphvizModule.h (macOS)
3
+ *
4
+ * React Native native module for Graphviz rendering on macOS.
5
+ * Supports both old architecture (RCTBridgeModule) and
6
+ * new architecture (TurboModules) via RCT_NEW_ARCH_ENABLED.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0
9
+ */
10
+
11
+ #import <React/RCTBridgeModule.h>
12
+
13
+ #ifdef RCT_NEW_ARCH_ENABLED
14
+ #import <GraphvizNativeSpec/GraphvizNativeSpec.h>
15
+ #endif
16
+
17
+ @interface GraphvizModule : NSObject <RCTBridgeModule
18
+ #ifdef RCT_NEW_ARCH_ENABLED
19
+ , NativeGraphvizNativeSpec
20
+ #endif
21
+ >
22
+
23
+ @end
@@ -0,0 +1,163 @@
1
+ /*
2
+ * GraphvizModule.m (macOS)
3
+ *
4
+ * React Native native module implementation for macOS.
5
+ * Manages a singleton Graphviz context and dispatches rendering
6
+ * to a background queue to keep the JS thread responsive.
7
+ *
8
+ * This is functionally identical to the iOS implementation, built
9
+ * separately to allow platform-specific podspec configuration.
10
+ *
11
+ * Licensed under the Apache License, Version 2.0
12
+ */
13
+
14
+ #import "GraphvizModule.h"
15
+ #import "graphviz_api.h"
16
+
17
+ #import <React/RCTLog.h>
18
+
19
+ @implementation GraphvizModule {
20
+ gv_context_t *_context;
21
+ dispatch_queue_t _renderQueue;
22
+ }
23
+
24
+ RCT_EXPORT_MODULE(GraphvizNative)
25
+
26
+ - (instancetype)init {
27
+ self = [super init];
28
+ if (self) {
29
+ _renderQueue = dispatch_queue_create("com.graphviznative.render", DISPATCH_QUEUE_SERIAL);
30
+ _context = NULL;
31
+ }
32
+ return self;
33
+ }
34
+
35
+ - (void)dealloc {
36
+ if (_context) {
37
+ gv_context_free(_context);
38
+ _context = NULL;
39
+ }
40
+ }
41
+
42
+ + (BOOL)requiresMainQueueSetup {
43
+ return NO;
44
+ }
45
+
46
+ /**
47
+ * Lazily initializes the Graphviz context on the render queue.
48
+ * Must be called from within a dispatch to _renderQueue.
49
+ */
50
+ - (gv_context_t *)ensureContext {
51
+ if (!_context) {
52
+ _context = gv_context_new();
53
+ if (!_context) {
54
+ RCTLogError(@"GraphvizNative: failed to create Graphviz context");
55
+ }
56
+ }
57
+ return _context;
58
+ }
59
+
60
+ /**
61
+ * Map native error codes to JS-friendly error code strings.
62
+ */
63
+ static NSString *errorCodeToString(gv_error_t err) {
64
+ switch (err) {
65
+ case GV_ERR_NULL_INPUT: return @"NULL_INPUT";
66
+ case GV_ERR_INVALID_DOT: return @"INVALID_DOT";
67
+ case GV_ERR_LAYOUT_FAILED: return @"LAYOUT_FAILED";
68
+ case GV_ERR_RENDER_FAILED: return @"RENDER_FAILED";
69
+ case GV_ERR_INVALID_ENGINE: return @"INVALID_ENGINE";
70
+ case GV_ERR_INVALID_FORMAT: return @"INVALID_FORMAT";
71
+ case GV_ERR_OUT_OF_MEMORY: return @"OUT_OF_MEMORY";
72
+ case GV_ERR_NOT_INITIALIZED: return @"NOT_INITIALIZED";
73
+ default: return @"UNKNOWN";
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Returns YES for text-based output formats that do not need base64 encoding.
79
+ */
80
+ static BOOL isTextFormat(NSString *format) {
81
+ static NSSet *textFormats;
82
+ static dispatch_once_t onceToken;
83
+ dispatch_once(&onceToken, ^{
84
+ textFormats = [NSSet setWithArray:@[@"svg", @"json", @"dot", @"xdot", @"plain"]];
85
+ });
86
+ return [textFormats containsObject:format];
87
+ }
88
+
89
+ RCT_EXPORT_METHOD(renderDot:(NSString *)dot
90
+ engine:(NSString *)engine
91
+ format:(NSString *)format
92
+ resolve:(RCTPromiseResolveBlock)resolve
93
+ reject:(RCTPromiseRejectBlock)reject) {
94
+ dispatch_async(_renderQueue, ^{
95
+ gv_context_t *ctx = [self ensureContext];
96
+ if (!ctx) {
97
+ reject(@"NOT_INITIALIZED", @"Failed to initialize Graphviz context", nil);
98
+ return;
99
+ }
100
+
101
+ char *outData = NULL;
102
+ size_t outLength = 0;
103
+
104
+ gv_error_t err = gv_render(
105
+ ctx,
106
+ [dot UTF8String],
107
+ [engine UTF8String],
108
+ [format UTF8String],
109
+ &outData,
110
+ &outLength
111
+ );
112
+
113
+ if (err != GV_OK) {
114
+ NSString *code = errorCodeToString(err);
115
+ NSString *message = [NSString stringWithUTF8String:gv_strerror(err)];
116
+ reject(code, message, nil);
117
+ if (outData) {
118
+ gv_free_render_data(outData);
119
+ }
120
+ return;
121
+ }
122
+
123
+ NSString *result;
124
+ if (isTextFormat(format)) {
125
+ result = [[NSString alloc] initWithBytes:outData
126
+ length:outLength
127
+ encoding:NSUTF8StringEncoding];
128
+ } else {
129
+ NSData *data = [NSData dataWithBytesNoCopy:outData
130
+ length:outLength
131
+ freeWhenDone:NO];
132
+ result = [data base64EncodedStringWithOptions:0];
133
+ }
134
+
135
+ gv_free_render_data(outData);
136
+
137
+ if (!result) {
138
+ reject(@"RENDER_FAILED", @"Failed to convert render output to string", nil);
139
+ return;
140
+ }
141
+
142
+ resolve(result);
143
+ });
144
+ }
145
+
146
+ RCT_EXPORT_METHOD(getVersion:(RCTPromiseResolveBlock)resolve
147
+ reject:(RCTPromiseRejectBlock)reject) {
148
+ const char *version = gv_version();
149
+ if (version) {
150
+ resolve([NSString stringWithUTF8String:version]);
151
+ } else {
152
+ reject(@"UNKNOWN", @"Failed to get Graphviz version", nil);
153
+ }
154
+ }
155
+
156
+ #ifdef RCT_NEW_ARCH_ENABLED
157
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
158
+ (const facebook::react::ObjCTurboModule::InitParams &)params {
159
+ return std::make_shared<facebook::react::NativeGraphvizNativeSpecJSI>(params);
160
+ }
161
+ #endif
162
+
163
+ @end
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "@kookyleo/graphviz-anywhere-rn",
3
+ "version": "0.1.0",
4
+ "description": "React Native package for graphviz-anywhere with native binary support",
5
+ "main": "lib/commonjs/index.js",
6
+ "module": "lib/module/index.js",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "source": "src/index.ts",
9
+ "license": "Apache-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/nicekook/graphviz-anywhere.git",
13
+ "directory": "packages/react-native"
14
+ },
15
+ "author": "kookyleo <kookyleo@gmail.com>",
16
+ "files": [
17
+ "src",
18
+ "lib",
19
+ "ios",
20
+ "android",
21
+ "macos",
22
+ "windows",
23
+ "scripts",
24
+ "graphviz-anywhere-react-native.podspec",
25
+ "!**/__tests__"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "typescript": "tsc --noEmit",
32
+ "build": "bob build",
33
+ "prepare": "bob build",
34
+ "postinstall": "node scripts/download-native.js",
35
+ "lint": "eslint \"src/**/*.{ts,tsx}\"",
36
+ "fmt": "prettier --write src",
37
+ "test": "jest"
38
+ },
39
+ "keywords": [
40
+ "react-native",
41
+ "graphviz",
42
+ "dot",
43
+ "graph",
44
+ "visualization",
45
+ "svg",
46
+ "ios",
47
+ "android",
48
+ "macos",
49
+ "windows"
50
+ ],
51
+ "peerDependencies": {
52
+ "react": ">=18.0.0",
53
+ "react-native": ">=0.71.0",
54
+ "react-native-macos": ">=0.71.0",
55
+ "react-native-windows": ">=0.71.0"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "react-native-macos": {
59
+ "optional": true
60
+ },
61
+ "react-native-windows": {
62
+ "optional": true
63
+ }
64
+ },
65
+ "devDependencies": {
66
+ "@types/react": "^19.0.0",
67
+ "@types/react-native": "^0.73.0",
68
+ "react": "19.2.3",
69
+ "react-native": "0.84.1",
70
+ "react-native-builder-bob": "^0.35.0",
71
+ "typescript": "^5.7.0"
72
+ },
73
+ "react-native-builder-bob": {
74
+ "source": "src",
75
+ "output": "lib",
76
+ "targets": [
77
+ "commonjs",
78
+ "module",
79
+ [
80
+ "typescript",
81
+ {
82
+ "project": "tsconfig.json"
83
+ }
84
+ ]
85
+ ]
86
+ },
87
+ "codegenConfig": {
88
+ "name": "GraphvizAnywhereNativeSpec",
89
+ "type": "modules",
90
+ "jsSrcsDir": "src",
91
+ "android": {
92
+ "javaPackageName": "com.graphviznative"
93
+ }
94
+ }
95
+ }