Skip to content

Commit

Permalink
Updating Pintorita to 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorh140 committed Oct 4, 2024
1 parent 877217d commit f9d776c
Show file tree
Hide file tree
Showing 8 changed files with 1,670 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/preview/pintorita/0.1.2/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1,443 changes: 1,443 additions & 0 deletions packages/preview/pintorita/0.1.2/NOTICE

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions packages/preview/pintorita/0.1.2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# [Pintorita - Pintora plugin for typst ](https://github.com/taylorh140/typst-pintora)

[Pintora](https://pintorajs.vercel.app/)

Typst package for drawing the following from markup:
- Sequence Diagram
- Entity Relationship Diagram
- Component Diagram
- Activity Diagram
- Mind Map Experiment
- Gantt Diagram Experiment
- DOT Diagram Experiment

![](pintorita.svg)


````typ
#import "@preview/pintorita:0.1.2"
#set page(height: auto, width: auto, fill: black, margin: 2em)
#set text(fill: white)
#show raw.where(lang: "pintora"): it => pintorita.render(it.text)
= pintora
Typst just got a load of diagrams.
```pintora
mindmap
@param layoutDirection TB
+ UML Diagrams
++ Behavior Diagrams
+++ Sequence Diagram
+++ State Diagram
+++ Activity Diagram
++ Structural Diagrams
+++ Class Diagram
+++ Component Diagram
```
```
mindmap
@param layoutDirection TB
+ UML Diagrams
++ Behavior Diagrams
+++ Sequence Diagram
+++ State Diagram
+++ Activity Diagram
++ Structural Diagrams
+++ Class Diagram
+++ Component Diagram
```
````


## Documentation

### `render`

Render a pintora string to an image

#### Arguments

* `src`: `str` - pintora source string
* `factor`: scale output svg, "factor:0.5" will scale images down by half, so scale can be consistent across renders.
* `style`: `str` diagram style, `default` or `dark` or `larkLight` or `larkDark`
* `font`: `str` font family, default is `Source Code Pro, sans-serif`
* All other arguments are passed to `image.decode` so you can customize the image size

#### Returns

The image, of type `content`

### `render_svg`

Render a pintora string to an image

#### Arguments

* `src`: `str` - pintora source string
* `factor`: scale output svg, "factor:0.5" will scale images down by half, so scale can be consistent across renders.
* `style`: `str` diagram style, `default` or `dark` or `larkLight` or `larkDark`
* `font`: `str` font family, default is `Source Code Pro, sans-serif`
* All other arguments are passed to `image.decode` so you can customize the image size

#### Returns

The svg image

## History

* 0.1.0 - Inital Release
* 0.1.1 - Updated to Jogs 0.2.3 and pintora 0.7.3
* 0.1.2 - Fixed strange offset of text rows in class diagram, added `render_svg` function and more customization options
3 changes: 3 additions & 0 deletions packages/preview/pintorita/0.1.2/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#import "./pintorita.typ": render, render_svg


47 changes: 47 additions & 0 deletions packages/preview/pintorita/0.1.2/pintora.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/preview/pintorita/0.1.2/pintorita.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions packages/preview/pintorita/0.1.2/pintorita.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#import "@preview/jogs:0.2.3": compile-js, call-js-function

#let pintora-src = read("./pintora.js")
#let pintora-bytecode = compile-js(pintora-src)

#let render(src, ..args) = {
let named-args = args.named()
let factor = named-args.at("factor",default:none)
let style = named-args.at("style",default:"larkLight")
let font = named-args.at("font",default:"Arial")
let svg-output = call-js-function(pintora-bytecode, "PintoraRender", src, style, font)

if (factor != none){
let svg-width = svg-output.find(regex("width=\"(\d+)")).find(regex("\d+"))

let new-width = int(svg-width) * factor * 1pt
named-args.insert("width", new-width)
let junk = named-args.remove("factor")
}
image.decode(svg-output, ..args.pos(), ..named-args)
}

#let render_svg(src, ..args) = {

Check warning on line 23 in packages/preview/pintorita/0.1.2/pintorita.typ

View check run for this annotation

Typst package check / @preview/pintorita:0.1.2

packages/preview/pintorita/0.1.2/pintorita.typ#L23

This value seems to be public. It is recommended to use kebab-case names.
// style: ["default", "larkLight", "larkDark", "dark"]
let named-args = args.named()
let factor = named-args.at("factor",default:none)
let style = named-args.at("style",default:"larkLight")
let font = named-args.at("font",default:"Arial")
let svg-output = call-js-function(pintora-bytecode, "PintoraRender", src, style, font)

if (factor != none){
let svg-width = svg-output.find(regex("width=\"(\d+)")).find(regex("\d+"))

let new-width = int(svg-width) * factor * 1pt
named-args.insert("width", new-width)
let junk = named-args.remove("factor")
}
svg-output
}

21 changes: 21 additions & 0 deletions packages/preview/pintorita/0.1.2/typst.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "pintorita"
version = "0.1.2"
entrypoint = "lib.typ"
authors = ["Min Chen (hikerpig)","Taylorh140"]
license = "MIT"
description = "Package to draw Sequence Diagrams, Entity Relationship Diagrams, Component Diagrams, Activity Diagrams, Mind Maps, Gantt Diagrams, and DOT Diagrams based on Pintora which is heavily influenced by mermaid.js and plantuml."
categories = ["visualization"]

homepage = "https://github.com/taylorh140/typst-pintora"

Check failure on line 10 in packages/preview/pintorita/0.1.2/typst.toml

View check run for this annotation

Typst package check / @preview/pintorita:0.1.2

packages/preview/pintorita/0.1.2/typst.toml#L10

Use the homepage field only if there is a dedicated website. Otherwise, prefer the `repository` field.
repository = "https://github.com/taylorh140/typst-pintora"
keywords = [
"js",
"javascript",
"pintora",
"gantt",
"sequence",
]
exclude = [
"pintorita.svg",
]

0 comments on commit f9d776c

Please sign in to comment.