Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples #61

Merged
merged 3 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/01-basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<!-- Require cheerpj dependency -->
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
<!-- Require PlantUML.js -->
<script src="node_modules/@plantuml/plantuml.js/plantuml.js"></script>
<script src="node_modules/@sakirtemel/plantuml.js/plantuml.js"></script>
</head>
<body>
<img src="loading.png" id="plantuml-diagram" />
<script type="text/javascript">
plantuml.initialize('/app/node_modules/@plantuml/plantuml.js').then(() => {
plantuml.initialize('/app/node_modules/@sakirtemel/plantuml.js').then(() => {
const element = document.getElementById('plantuml-diagram')
const pumlContent = `
@startuml
Expand Down
8 changes: 4 additions & 4 deletions examples/01-basic/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/01-basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"author": "",
"license": "MIT",
"dependencies": {
"@plantuml/plantuml.js": "file:../../plantuml-wasm"
"@sakirtemel/plantuml.js": "^1.0.0"
}
}
4 changes: 2 additions & 2 deletions examples/02-asciidoctor.js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!-- Require cheerpj dependency -->
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
<!-- Require PlantUML.js -->
<script src="node_modules/@plantuml/plantuml.js/plantuml.js"></script>
<script src="node_modules/@sakirtemel/plantuml.js/plantuml.js"></script>
</head>
<body>
<div id="content"></div>
Expand Down Expand Up @@ -60,7 +60,7 @@
})

// render marked plantuml diagrams
plantuml.initialize('/app/node_modules/@plantuml/plantuml.js').then(() => {
plantuml.initialize('/app/node_modules/@sakirtemel/plantuml.js').then(() => {
for(const element of document.querySelectorAll('.plantuml-diagram')){
const code = element.querySelector('*:is(code, pre)').innerText
const url = plantuml.renderPng(code).then((blob) => {
Expand Down
8 changes: 4 additions & 4 deletions examples/02-asciidoctor.js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/02-asciidoctor.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"license": "MIT",
"dependencies": {
"asciidoctor": "^2.2.6",
"@plantuml/plantuml.js": "file:../../plantuml-wasm"
"@sakirtemel/plantuml.js": "^1.0.0"
}
}
7 changes: 7 additions & 0 deletions examples/02-asciidoctor.js/sequence-diagram.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ Alice <-- Bob: Another authentication Response
@enduml
----

[source,plantuml]
----
@startuml
Bob -> Alice: Hello!
@enduml
----

=== Without rendering

[source,plantuml,render=false]
Expand Down
4 changes: 2 additions & 2 deletions plantuml-wasm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plantuml-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sakirtemel/plantuml.js",
"version": "1.0.0",
"version": "1.0.1",
"description": "PlantUML that runs completely on javascript without needing java/servers",
"main": "plantuml.js",
"scripts": {
Expand Down
17 changes: 11 additions & 6 deletions plantuml-wasm/plantuml.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ const plantuml = (() => {

const renderPng = (pumlContent) => {
return new Promise((resolve, reject) => {
const renderingStartedAt = new Date()
cjCall("com.plantuml.wasm.v1.Png", "convert", "light", "/files/result.png", pumlContent).then((result) => {
console.log(result);
const renderingStartedAt = new Date()
const resultFileSuffix = renderingStartedAt.getTime().toString()
cjCall("com.plantuml.wasm.v1.Png", "convert", "light", `/files/result-${resultFileSuffix}.png`, pumlContent).then((result) => {
const obj = JSON.parse(result);
if (obj.status=='ok') {
cjFileBlob("result.png").then((blob) => {
console.log('Rendering finished in', (new Date()).getTime() - renderingStartedAt.getTime(), 'ms');
resolve(blob)
cjFileBlob(`result-${resultFileSuffix}.png`).then((blob) => {
const transaction = cheerpjGetFSMountForPath('/files/').dbConnection.transaction('files', 'readwrite')
transaction.objectStore('files').delete(`/result-${resultFileSuffix}.png`)

transaction.oncomplete = () => {
console.log('Rendering finished in', (new Date()).getTime() - renderingStartedAt.getTime(), 'ms');
resolve(blob)
}
})
}
})
Expand Down