-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add docs about using node.js api usage
- Loading branch information
Showing
6 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as fs from 'fs' | ||
import { render, PintoraConfig } from '..' | ||
|
||
const buildSVG = async (code: string, config?: Partial<PintoraConfig>) => { | ||
const str = await render({ | ||
code: code, | ||
pintoraConfig: config, | ||
mimeType: 'image/svg+xml', | ||
width: 1000, | ||
backgroundColor: '#fff', | ||
}) | ||
fs.writeFileSync('example.svg', str) | ||
} | ||
|
||
const buildPNG = async (code: string, config?: Partial<PintoraConfig>) => { | ||
const buf = await render({ | ||
code: code, | ||
pintoraConfig: config, | ||
mimeType: 'image/png', | ||
width: 800, | ||
backgroundColor: '#fdfdfd', // use some other background color | ||
}) | ||
fs.writeFileSync('example.png', buf) | ||
} | ||
|
||
const code = ` | ||
activityDiagram | ||
start | ||
:render functionl called; | ||
if (is mimeType image/svg+xml ?) then | ||
:renderer svg; | ||
:render with jsdom; | ||
:generate string; | ||
else (no) | ||
:renderer canvas; | ||
:render with node-canvas; | ||
:generate image buffer by mimeType; | ||
endif | ||
:return result; | ||
end | ||
` | ||
|
||
buildSVG(code) | ||
|
||
buildPNG(code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "lib", | ||
"module": "commonjs" | ||
}, | ||
"references": [ | ||
{ "path": ".." }, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters