Compare commits
23 Commits
v0.0.2
...
refactor/r
| Author | SHA1 | Date | |
|---|---|---|---|
|
26d11301a2
|
|||
|
aeb413abb4
|
|||
|
6095b5784e
|
|||
|
6f13df815f
|
|||
| 1dd66fd587 | |||
| c7c777f5fa | |||
| 7ef7f653b7 | |||
|
dd6d38a282
|
|||
|
6140cff3c5
|
|||
|
1be1dccb6b
|
|||
| 422681ba6e | |||
|
23af042a36
|
|||
|
c7d12bf6c6
|
|||
|
6394c8e5c5
|
|||
|
65d11fc920
|
|||
|
a935484665
|
|||
|
c0a42aa8a6
|
|||
|
37dce1f7c9
|
|||
|
a9633f25a3
|
|||
|
a929f506ac
|
|||
|
aa9a082ba5
|
|||
|
6f502f2e18
|
|||
|
03e9904d43
|
17
CHANGELOG.md
17
CHANGELOG.md
@@ -1,5 +1,22 @@
|
||||
# Changelog
|
||||
|
||||
## [v0.3.0] - 2025-05-03
|
||||
- updated CeTZ to 0.3.4
|
||||
- updated to Typst 0.13.1
|
||||
- updated Tidy to 0.4.2
|
||||
- updated Codly to 1.3.0 and codly-languages to 0.1.8
|
||||
- added `ltr-bits` config option
|
||||
- added a "Loading" section to the manual
|
||||
|
||||
## [v0.2.0] - 2025-02-23
|
||||
- updated CeTZ to 0.3.2
|
||||
- updated to Typst 0.13.0
|
||||
- fixed missing bit index on dependencies
|
||||
- updated docs (Tidy, codelst -> codly)
|
||||
|
||||
## [v0.1.0] - 2024-10-02
|
||||
- prepared for publication in Typst Universe
|
||||
|
||||
## [v0.0.2] - 2024-06-15
|
||||
### Added
|
||||
- `width` parameter to `schema.render` for easier integration
|
||||
|
||||
13
README.md
13
README.md
@@ -31,14 +31,11 @@ It is based on the [homonymous Python script](https://git.kb28.ch/HEL/rivet/)
|
||||
*Click on the example image to jump to the code.*
|
||||
|
||||
## Usage
|
||||
For information, see the [manual](manual.pdf)
|
||||
For more information, see the [manual](manual.pdf)
|
||||
|
||||
To use this package, simply import `schema` [src/lib.typ](src/lib.typ) and call `schema.load` to parse a schema description. Then use `schema.render` to render it, et voilà !
|
||||
To use this package, simply import `schema` from [rivet](https://typst.app/universe/package/rivet) and call `schema.load` to parse a schema description. Then use `schema.render` to render it, et voilà !
|
||||
```typ
|
||||
#import "src/lib.typ": schema
|
||||
#let doc = schema.load("path/to/schema.yaml")
|
||||
#import "@preview/rivet:0.3.0": schema
|
||||
#let doc = schema.load(yaml("path/to/schema.yaml"))
|
||||
#schema.render(doc)
|
||||
```
|
||||
|
||||
## Installing
|
||||
> TODO
|
||||
```
|
||||
@@ -1,7 +1,7 @@
|
||||
/// Creates a dictionary of all configuration parameters
|
||||
///
|
||||
/// - default-font-family (str): The default font family
|
||||
/// - default font-size (length): The absolute default font size
|
||||
/// - default-font-size (length): The absolute default font size
|
||||
/// - italic-font-family (str): The italic font family (for value descriptions)
|
||||
/// - italic-font-size (length): The absolute italic font size
|
||||
/// - background (color): The diagram background color
|
||||
@@ -15,7 +15,7 @@
|
||||
/// - dash-length (float): The length of individual dashes (for dashed lines)
|
||||
/// - dash-space (float): The space between two dashes (for dashed lines)
|
||||
/// - arrow-size (float): The size of arrow heads
|
||||
/// - margins (tuple[float]): TODO -> remove
|
||||
/// - margins (tuple): TODO -> remove
|
||||
/// - arrow-margin (float): The margin between arrows and the structures they link
|
||||
/// - values-gap (float): The gap between individual values
|
||||
/// - arrow-label-distance (float): The distance between arrows and their labels
|
||||
@@ -25,6 +25,7 @@
|
||||
/// - height (float): TODO -> remove
|
||||
/// - full-page (bool): If true, the page will be resized to fit the diagram and take the background color
|
||||
/// - all-bit-i (bool): If true, all bit indices will be rendered, otherwise, only the ends of each range will be displayed
|
||||
/// - ltr-bits (bool): If true, bits are placed with the LSB on the left instead of the right
|
||||
/// -> dictionary
|
||||
#let config(
|
||||
default-font-family: "Ubuntu Mono",
|
||||
@@ -51,13 +52,14 @@
|
||||
width: 1200,
|
||||
height: 800,
|
||||
full-page: false,
|
||||
all-bit-i: true
|
||||
all-bit-i: true,
|
||||
ltr-bits: false
|
||||
) = {}
|
||||
|
||||
/// Dark theme config
|
||||
/// - ..args (any): see #doc-ref("config.config")
|
||||
/// - ..args (any): see @@config()
|
||||
#let dark(..args) = {}
|
||||
|
||||
/// Blueprint theme config
|
||||
/// - ..args (any): see #doc-ref("config.config")
|
||||
/// - ..args (any): see @@config()
|
||||
#let blueprint(..args) = {}
|
||||
@@ -1,4 +1,3 @@
|
||||
#import "@preview/cetz:0.2.2": draw
|
||||
#import "../src/lib.typ": schema
|
||||
#import "../src/util.typ"
|
||||
|
||||
@@ -14,7 +13,7 @@
|
||||
box(
|
||||
stroke: black + 1pt,
|
||||
radius: .5em,
|
||||
fill: if fill {yellow.lighten(80%)} else {none},
|
||||
fill: if fill {orange.lighten(95%)} else {none},
|
||||
if show-src {
|
||||
let src-block = align(left, raw(src, lang: "typc"))
|
||||
table(
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
/// Loads a schema from a file or a raw block.
|
||||
/// This function returns a dictionary of structures
|
||||
/// This function returns a dictionary of structures\
|
||||
/// See the #link(<loading>)[Loading] chapter for examples of schema loading for each supported format
|
||||
///
|
||||
/// Supported formats: #schema.valid-extensions.map(e => raw("." + e)).join(", ")
|
||||
/// - path-or-schema (str, raw, dictionary): If it is a string, defines the path to load. \
|
||||
/// If it is a raw block, its content is directly parsed (the block's language will define the format to use) \
|
||||
/// If it is a dictionary, it directly defines the schema structure
|
||||
/// - path-or-schema (str, raw, dictionary):
|
||||
/// #list(
|
||||
/// [If it is a string, defines the path to load.\ #emoji.warning Warning: this will only work if this package is part of your project, as packages installed in the `@local` or `@preview` namespace cannot access project files],
|
||||
/// [If it is a raw block, its content is directly parsed (the block's language will define the format to use)],
|
||||
/// [If it is a dictionary, it directly defines the schema structure]
|
||||
/// )
|
||||
/// -> dictionary
|
||||
#let load(path-or-schema) = {}
|
||||
|
||||
/// Renders the given schema
|
||||
/// This functions
|
||||
/// - schema (dictionary): A schema dictionary, as returned by #doc-ref("schema.load")
|
||||
/// - schema (dictionary): A schema dictionary, as returned by @@load()
|
||||
/// - config (auto, dictionary): The configuration parameters, as returned by #doc-ref("config.config")
|
||||
/// - width (ratio, length): The width of the generated figure
|
||||
#let render(schema, config: auto, width: 100%) = {}
|
||||
40
gallery.bash
40
gallery.bash
@@ -1,40 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
PDFS=false
|
||||
|
||||
while getopts "p" flag
|
||||
do
|
||||
case "${flag}" in
|
||||
p) PDFS=true;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "Generating gallery images"
|
||||
|
||||
set -- ./gallery/example*.typ
|
||||
cnt="$#"
|
||||
i=1
|
||||
for f
|
||||
do
|
||||
f2="${f/typ/png}"
|
||||
echo "($i/$cnt) $f -> $f2"
|
||||
typst c --root ./ "$f" "$f2"
|
||||
i=$((i+1))
|
||||
done
|
||||
|
||||
if [ "$PDFS" = true ]
|
||||
then
|
||||
echo
|
||||
echo "Generating gallery PDFs"
|
||||
|
||||
set -- ./gallery/*.typ
|
||||
cnt="$#"
|
||||
i=1
|
||||
for f
|
||||
do
|
||||
f2="${f/typ/pdf}"
|
||||
echo "($i/$cnt) $f -> $f2"
|
||||
typst c --root ./ "$f" "$f2"
|
||||
i=$((i+1))
|
||||
done
|
||||
fi
|
||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 376 KiB After Width: | Height: | Size: 378 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 302 KiB After Width: | Height: | Size: 303 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 487 KiB After Width: | Height: | Size: 485 KiB |
Binary file not shown.
BIN
gallery/test.pdf
BIN
gallery/test.pdf
Binary file not shown.
12
justfile
Normal file
12
justfile
Normal file
@@ -0,0 +1,12 @@
|
||||
# Local Variables:
|
||||
# mode: makefile
|
||||
# End:
|
||||
gallery_dir := "./gallery"
|
||||
set shell := ["bash", "-uc"]
|
||||
|
||||
manual:
|
||||
typst c manual.typ manual.pdf
|
||||
|
||||
gallery:
|
||||
for f in "{{gallery_dir}}"/*.typ; do typst c --root . "$f" "${f/typ/pdf}"; done
|
||||
for f in "{{gallery_dir}}"/example*.typ; do typst c --root . "$f" "${f/typ/png}"; done
|
||||
BIN
manual.pdf
BIN
manual.pdf
Binary file not shown.
208
manual.typ
208
manual.typ
@@ -1,22 +1,24 @@
|
||||
#import "@preview/tidy:0.3.0"
|
||||
#import "@preview/codelst:2.0.1": sourcecode
|
||||
#import "@preview/showybox:2.0.1": showybox
|
||||
#import "@preview/tidy:0.4.2"
|
||||
#import "@preview/codly:1.3.0": codly-init, codly
|
||||
#import "@preview/codly-languages:0.1.8": codly-languages
|
||||
#import "@preview/showybox:2.0.4": showybox
|
||||
#import "src/lib.typ"
|
||||
#import "src/schema.typ"
|
||||
#import "docs/examples.typ"
|
||||
|
||||
#show: codly-init
|
||||
|
||||
#codly(languages: codly-languages)
|
||||
|
||||
#set heading(numbering: (..num) => if num.pos().len() < 4 {
|
||||
numbering("1.1", ..num)
|
||||
})
|
||||
#{
|
||||
outline(indent: true, depth: 3)
|
||||
}
|
||||
|
||||
#set page(numbering: "1/1", header: align(right)[rivet #sym.dash.em v#lib.version])
|
||||
|
||||
#let doc-ref(target, full: false, var: false) = {
|
||||
let (module, func) = target.split(".")
|
||||
let label-name = module + func
|
||||
let label-name = module + "-" + func
|
||||
let display-name = func
|
||||
if full {
|
||||
display-name = target
|
||||
@@ -25,7 +27,7 @@
|
||||
label-name += "()"
|
||||
display-name += "()"
|
||||
}
|
||||
link(label(label-name))[#display-name]
|
||||
link(label(label-name), raw(display-name))
|
||||
}
|
||||
|
||||
#let note(it) = showybox(
|
||||
@@ -43,6 +45,37 @@
|
||||
|
||||
#show link: set text(blue)
|
||||
|
||||
#let sch = schema.load(```yaml
|
||||
structures:
|
||||
main:
|
||||
bits: 5
|
||||
ranges:
|
||||
4:
|
||||
name: R
|
||||
description: Register
|
||||
3:
|
||||
name: I
|
||||
description: Instruction
|
||||
2:
|
||||
name: V
|
||||
description: Visualizer
|
||||
1:
|
||||
name: E
|
||||
description: Explainer
|
||||
0:
|
||||
name: T
|
||||
description: Tool
|
||||
```)
|
||||
#align(center, schema.render(sch, width: 50%, config: lib.config.config(left-labels: true)))
|
||||
#v(1fr)
|
||||
#box(
|
||||
width: 100%,
|
||||
stroke: black,
|
||||
inset: 1em,
|
||||
outline(indent: auto, depth: 3)
|
||||
)
|
||||
#pagebreak(weak: true)
|
||||
|
||||
= Introduction
|
||||
|
||||
This package provides a way to make beautiful register diagrams using the CeTZ package. It can be used to document Assembly instructions or binary registers
|
||||
@@ -51,26 +84,30 @@ This is a port of the #link("https://git.kb28.ch/HEL/rivet")[homonymous Python s
|
||||
|
||||
= Usage
|
||||
|
||||
Simply import `schema` from #link("src/lib.typ") and call `schema.load` to parse a schema description. Then use `schema.render` to render it, et voilà !
|
||||
#pad(left: 1em)[```typ
|
||||
#import "src/lib.typ": schema
|
||||
#let doc = schema.load("path/to/schema.yaml")
|
||||
#let import-stmt = "#import \"@preview/rivet:" + str(lib.version) + "\""
|
||||
|
||||
Simply import the `schema` module and call `schema.load` to parse a schema description. Then use `schema.render` to render it, et voilà !
|
||||
#raw(block: true, lang: "typ", ```typ
|
||||
$import: schema
|
||||
#let doc = schema.load(yaml("path/to/schema.yaml"))
|
||||
#schema.render(doc)
|
||||
```]
|
||||
```.text.replace("$import", import-stmt))
|
||||
|
||||
Please read the #link(<loading>)[Loading] chapter for more detailed explanations on how to load schema descriptions.
|
||||
|
||||
= Format
|
||||
|
||||
This section describes the structure of a schema definition. The examples given use the JSON syntax. For examples in different formats, see #link("https://git.kb28.ch/HEL/rivet-typst/src/branch/main/gallery/test.yaml")[test.yaml], #link("https://git.kb28.ch/HEL/rivet-typst/src/branch/main/gallery/test.json")[test.json] and #link("https://git.kb28.ch/HEL/rivet-typst/src/branch/main/gallery/test.xml")[test.xml]. You can also directly define a schema using Typst dictionaries and arrays.
|
||||
|
||||
Since the XML format is quite different from the other, you might find it helpful to look at the examples on GitHub to get familiar with it.
|
||||
Since the XML format is quite different from the other, you might find it helpful to look at the examples in the #link("https://git.kb28.ch/HEL/rivet-typst/src/branch/main/gallery/")[Gitea repo] to get familiar with it.
|
||||
|
||||
== Main layout
|
||||
|
||||
A schema contains a dictionary of structures. The must be at least one defined structure named "main".
|
||||
A schema contains a dictionary of structures. There must be at least one defined structure named "main".
|
||||
|
||||
It can also optionnaly contain a "colors" dictionary. More details about this in #link(<format-colors>)[Colors]
|
||||
|
||||
#sourcecode[```json
|
||||
```json
|
||||
{
|
||||
"structures": {
|
||||
"main": {
|
||||
@@ -85,7 +122,7 @@ It can also optionnaly contain a "colors" dictionary. More details about this in
|
||||
...
|
||||
}
|
||||
}
|
||||
```]
|
||||
```
|
||||
|
||||
#pagebreak(weak: true)
|
||||
|
||||
@@ -93,9 +130,9 @@ It can also optionnaly contain a "colors" dictionary. More details about this in
|
||||
|
||||
A structure has a given number of bits and one or multiple ranges. Each range of bits can have a name, a description and / or values with special meaning (see #link(<format-range>)[Range]). A range's structure can also depend on another range's value (see #link(<format-dependencies>)[Dependencies]).
|
||||
|
||||
The range name (or key) defines the left- and rightmost bits (e.g. `7-4` goes from bit 7 down to bit 4). Bits are displayed in big-endian, i.e. the leftmost bit has the highest value.
|
||||
The range name (or key) defines the left- and rightmost bits (e.g. `7-4` goes from bit 7 down to bit 4). The order in which you write the range is not important, meaning `7-4` is equivalent to `4-7`. Bits are displayed in big-endian, i.e. the leftmost bit has the highest value, except if you enable the `ltr-bits` #doc-ref("config.config") option.
|
||||
|
||||
#sourcecode[```json
|
||||
```json
|
||||
"main": {
|
||||
"bits": 8,
|
||||
"ranges": {
|
||||
@@ -113,7 +150,35 @@ The range name (or key) defines the left- and rightmost bits (e.g. `7-4` goes fr
|
||||
}
|
||||
}
|
||||
}
|
||||
```]
|
||||
```
|
||||
|
||||
=== Start <format-start>
|
||||
|
||||
By default, structures start at bit 0, but you may want to number bits from 1, or another arbitrary value. To do this, you can set the `start` property of a structure to the desired start value. For example,
|
||||
|
||||
```json
|
||||
"main": {
|
||||
"bits": 8,
|
||||
"start": 4,
|
||||
"ranges": {
|
||||
"11-7": { ... },
|
||||
"6-4": { ... }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#let start-schema = (structures: (main: (bits: 8, start: 4, ranges: ("11-7": (name: ""), "6-4": (name: "")))))
|
||||
|
||||
would render as
|
||||
|
||||
#align(
|
||||
center,
|
||||
schema.render(
|
||||
schema.load(start-schema),
|
||||
width: 50%
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
== Range <format-range>
|
||||
|
||||
@@ -125,7 +190,7 @@ For values depending on other ranges, see #link(<format-dependencies>)[Dependenc
|
||||
In YAML, make sure to wrap values in quotes because some values can be interpreted as octal notation (e.g. 010 #sym.arrow.r 8)
|
||||
]
|
||||
|
||||
#sourcecode[```json
|
||||
```json
|
||||
"3-2": {
|
||||
"name": "op",
|
||||
"description": "Logical operation",
|
||||
@@ -136,7 +201,7 @@ For values depending on other ranges, see #link(<format-dependencies>)[Dependenc
|
||||
"11": "NAND"
|
||||
}
|
||||
}
|
||||
```]
|
||||
```
|
||||
|
||||
#pagebreak(weak: true)
|
||||
|
||||
@@ -144,9 +209,9 @@ For values depending on other ranges, see #link(<format-dependencies>)[Dependenc
|
||||
|
||||
The structure of one range may depend on the value of another. To represent this situation, first indicate on the child range the range on which it depends.
|
||||
|
||||
Then, in its values, indicate which structure to use. A description can also be added (displayed above the horizontal dependency arrow)
|
||||
Then, in its values, indicate which structure to use. A description can also be added (displayed below the horizontal dependency arrow)
|
||||
|
||||
#sourcecode[```json
|
||||
```json
|
||||
"7-4": {
|
||||
...
|
||||
"depends-on": "0",
|
||||
@@ -161,11 +226,11 @@ Then, in its values, indicate which structure to use. A description can also be
|
||||
}
|
||||
}
|
||||
}
|
||||
```]
|
||||
```
|
||||
|
||||
Finally, add the sub-structures to the structure dictionary:
|
||||
|
||||
#sourcecode[```json
|
||||
```json
|
||||
{
|
||||
"structures": {
|
||||
"main": {
|
||||
@@ -182,7 +247,7 @@ Finally, add the sub-structures to the structure dictionary:
|
||||
...
|
||||
}
|
||||
}
|
||||
```]
|
||||
```
|
||||
|
||||
#pagebreak(weak: true)
|
||||
|
||||
@@ -190,7 +255,7 @@ Finally, add the sub-structures to the structure dictionary:
|
||||
|
||||
You may want to highlight some ranges to make your diagram more readable. For this, you can use colors. Colors may be defined in a separate dictionary, at the same level as the "structures" dictionary:
|
||||
|
||||
#sourcecode[```json
|
||||
```json
|
||||
{
|
||||
"structures": {
|
||||
...
|
||||
@@ -199,11 +264,11 @@ You may want to highlight some ranges to make your diagram more readable. For th
|
||||
...
|
||||
}
|
||||
}
|
||||
```]
|
||||
```
|
||||
|
||||
It can contain color definitions for any number of ranges. For each range, you may then define a dictionary mapping bit ranges to a particular color:
|
||||
|
||||
#sourcecode[```json
|
||||
```json
|
||||
"colors": {
|
||||
"main": {
|
||||
"31-28": "#ABCDEF",
|
||||
@@ -213,7 +278,7 @@ It can contain color definitions for any number of ranges. For each range, you m
|
||||
"19-10": [12, 34, 56]
|
||||
}
|
||||
}
|
||||
```]
|
||||
```
|
||||
|
||||
Valid color formats are:
|
||||
- hex string starting with `#`, e.g. `"#23fa78"`
|
||||
@@ -223,7 +288,7 @@ Valid color formats are:
|
||||
|
||||
#note[
|
||||
The XML format implements colors a bit differently. Instead of having a "colors" dictionary, color definitions are directly put on the same level as structure definitions. For this, you can use a `color` node with the attributes "structure", "color", "start" and "end", like so:
|
||||
#sourcecode[```xml
|
||||
```xml
|
||||
<schema>
|
||||
<structure id="main" bits="8">
|
||||
...
|
||||
@@ -232,11 +297,86 @@ Valid color formats are:
|
||||
<color structure="main" color="#FF0000" start="4" end="7" />
|
||||
<color structure="main" color="255,0,0" start="0" end="3" />
|
||||
</schema>
|
||||
```]
|
||||
```
|
||||
]
|
||||
|
||||
#pagebreak(weak: true)
|
||||
|
||||
= Loading <loading>
|
||||
|
||||
Due to current limitations of the Typst compiler, the package can only access its own files, unless directly included in your project. For this reason, rivet cannot load a schema from a path, and you will need to read the files yourself to pass their contents to the package.
|
||||
|
||||
Here are a number of ways you can load your schemas:
|
||||
|
||||
== JSON Format
|
||||
|
||||
````typ
|
||||
// From file (ONLY IF PACKAGE INSTALLED IN PROJECT)
|
||||
#let s = schema.load("schema.json")
|
||||
// From file
|
||||
#let s = schema.load(json("schema.json"))
|
||||
// Raw block
|
||||
#let s = schema.load(```json
|
||||
{
|
||||
"structures": {
|
||||
"main": {
|
||||
...
|
||||
}
|
||||
}
|
||||
}
|
||||
```)
|
||||
````
|
||||
|
||||
== YAML Format
|
||||
|
||||
````typ
|
||||
// From file (ONLY IF PACKAGE INSTALLED IN PROJECT)
|
||||
#let s = schema.load("schema.yaml")
|
||||
// From file
|
||||
#let s = schema.load(yaml("schema.yaml"))
|
||||
// Raw block
|
||||
#let s = schema.load(```yaml
|
||||
structures:
|
||||
main:
|
||||
...
|
||||
```)
|
||||
````
|
||||
|
||||
== Typst Format
|
||||
|
||||
```typ
|
||||
#let s = schema.load((
|
||||
structures: (
|
||||
main: (
|
||||
...
|
||||
)
|
||||
)
|
||||
))
|
||||
```
|
||||
|
||||
#pagebreak(weak: true)
|
||||
|
||||
== XML Format
|
||||
|
||||
````typ
|
||||
// From file (ONLY IF PACKAGE INSTALLED IN PROJECT)
|
||||
#let x = schema.xml-loader.load("schema.xml")
|
||||
#let s = schema.load(x)
|
||||
// From file
|
||||
#let x = schema.xml-loader.parse(yaml("schema.yaml").first())
|
||||
#let s = schema.load(x)
|
||||
// Raw block
|
||||
#let s = schema.load(```xml
|
||||
<schema>
|
||||
<structure id="main" bits="32">
|
||||
...
|
||||
</structure>
|
||||
</schema>
|
||||
```)
|
||||
````
|
||||
|
||||
#pagebreak(weak: true)
|
||||
|
||||
= Config presets
|
||||
|
||||
Aside from the default config, some example presets are also provided:
|
||||
@@ -254,6 +394,7 @@ Aside from the default config, some example presets are also provided:
|
||||
#let doc-config = tidy.parse-module(
|
||||
read("docs/config.typ"),
|
||||
name: "config",
|
||||
old-syntax: true,
|
||||
scope: (
|
||||
doc-ref: doc-ref
|
||||
)
|
||||
@@ -265,6 +406,7 @@ Aside from the default config, some example presets are also provided:
|
||||
#let doc-schema = tidy.parse-module(
|
||||
read("docs/schema.typ"),
|
||||
name: "schema",
|
||||
old-syntax: true,
|
||||
scope: (
|
||||
schema: schema,
|
||||
doc-ref: doc-ref
|
||||
|
||||
1
src/cetz.typ
Normal file
1
src/cetz.typ
Normal file
@@ -0,0 +1 @@
|
||||
#import "@preview/cetz:0.3.4": *
|
||||
@@ -23,7 +23,8 @@
|
||||
width: 1200,
|
||||
height: 800,
|
||||
full-page: false,
|
||||
all-bit-i: true
|
||||
all-bit-i: true,
|
||||
ltr-bits: false,
|
||||
) = {
|
||||
return (
|
||||
default-font-family: default-font-family,
|
||||
@@ -50,7 +51,8 @@
|
||||
width: width,
|
||||
height: height,
|
||||
full-page: full-page,
|
||||
all-bit-i: all-bit-i
|
||||
all-bit-i: all-bit-i,
|
||||
ltr-bits: ltr-bits,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#let version = version((0,0,2))
|
||||
#let version = version(0,3,0)
|
||||
|
||||
#import "config.typ"
|
||||
#import "schema.typ"
|
||||
@@ -15,6 +15,9 @@
|
||||
}
|
||||
let start = int(start-end.last())
|
||||
let end = int(start-end.first())
|
||||
if end < start {
|
||||
(start, end) = (end, start)
|
||||
}
|
||||
return (start, end)
|
||||
}
|
||||
|
||||
|
||||
116
src/render/structure.typ
Normal file
116
src/render/structure.typ
Normal file
@@ -0,0 +1,116 @@
|
||||
#import "../cetz.typ": draw
|
||||
|
||||
#let BACKGROUND-LAYER = -1
|
||||
|
||||
#let draw-track(config, schema, struct, pos) = draw.group(name: "track", {
|
||||
let colors = schema.at("colors", default: (:))
|
||||
let total-width = struct.bits * config.bit-width
|
||||
|
||||
let bit-colors = (:)
|
||||
|
||||
if struct.name in colors {
|
||||
for (s, col) in colors.at(struct.name) {
|
||||
let (start, end) = rng.parse-span(s)
|
||||
for i in range(start, end + 1) {
|
||||
bit-colors.insert(str(i), col)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let boundaries = ()
|
||||
for r in struct.ranges.values() {
|
||||
boundaries.push(if config.ltr-bits {r.end} else {r.start})
|
||||
boundaries.push(if config.ltr-bits {r.start - 1} else {r.end + 1})
|
||||
}
|
||||
|
||||
draw.group(name: "bits", {
|
||||
for i in range(struct.bits) {
|
||||
let rank = struct.start + i
|
||||
let j = if config.ltr-bits {i} else {struct.bits - i - 1}
|
||||
let col = bit-colors.at(str(rank), default: config.background)
|
||||
|
||||
// Background color
|
||||
draw.on-layer(BACKGROUND-LAYER, {
|
||||
draw.rect(
|
||||
(rel: (j * config.bit-width, 0), to: pos),
|
||||
(rel: (config.bit-width, config.bit-height)),
|
||||
fill: col,
|
||||
stroke: none,
|
||||
name: str(rank)
|
||||
)
|
||||
})
|
||||
|
||||
if j != struct.bits - 1 {
|
||||
let top = str(rank) + ".north-east"
|
||||
let bottom = str(rank) + ".south-east"
|
||||
|
||||
// Group boundary
|
||||
if rank in boundaries {
|
||||
draw.line(
|
||||
top,
|
||||
bottom,
|
||||
stroke: config.border-color
|
||||
)
|
||||
|
||||
// Bit separator
|
||||
} else {
|
||||
draw.line(
|
||||
top,
|
||||
((), 20%, bottom),
|
||||
stroke: config.border-color
|
||||
)
|
||||
draw.line(
|
||||
bottom,
|
||||
((), 20%, top),
|
||||
stroke: config.border-color
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Frame
|
||||
draw.rect(
|
||||
"bits.north-west", "bits.south-east",
|
||||
name: "frame",
|
||||
stroke: config.border-color + 2pt
|
||||
)
|
||||
|
||||
// Names
|
||||
for r in struct.ranges.values() {
|
||||
let i0 = r.start
|
||||
let i1 = r.end
|
||||
if not config.ltr-bits {
|
||||
(i0, i1) = (i1, i0)
|
||||
}
|
||||
let start = "bits." + str(i0) + ".north-west"
|
||||
let end = "bits." + str(i1) + ".south-east"
|
||||
draw.content(
|
||||
(start, 50%, end),
|
||||
r.name
|
||||
)
|
||||
}
|
||||
|
||||
let indices = if config.all-bit-i {
|
||||
range(struct.start, struct.start + struct.bits)
|
||||
} else {
|
||||
struct.ranges.values().map(r => (r.start, r.end)).flatten().dedup()
|
||||
}
|
||||
for i in indices {
|
||||
draw.content(
|
||||
"bits." + str(i) + ".north",
|
||||
anchor: "south",
|
||||
str(i),
|
||||
padding: 4pt // TODO: Maybe configurable
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
#let render(
|
||||
config,
|
||||
schema,
|
||||
struct,
|
||||
pos: (0, 0),
|
||||
) = draw.group(name: struct.name, {
|
||||
draw-track(config, schema, struct, pos)
|
||||
})
|
||||
535
src/renderer.typ
535
src/renderer.typ
@@ -1,535 +1,10 @@
|
||||
#import "@preview/cetz:0.2.2": canvas, draw
|
||||
|
||||
#import "range.typ" as rng
|
||||
#import "structure.typ"
|
||||
#import "vec.typ"
|
||||
|
||||
#let draw-rect(color, x, y, width, height, thickness: 0) = {
|
||||
let fill = none
|
||||
let stroke = color + thickness * 1pt
|
||||
if thickness == 0 {
|
||||
fill = color
|
||||
stroke = none
|
||||
}
|
||||
draw.rect((x, -y), (x + width, -y - height), fill: fill, stroke: stroke)
|
||||
}
|
||||
|
||||
#let draw-text(
|
||||
txt,
|
||||
color,
|
||||
x,
|
||||
y,
|
||||
anchor: "center",
|
||||
font: none,
|
||||
italic: false,
|
||||
size: 1em,
|
||||
fill: none
|
||||
) = {
|
||||
let text-params = (:)
|
||||
if font != none {
|
||||
text-params.insert("font", font)
|
||||
}
|
||||
if italic {
|
||||
text-params.insert("style", "italic")
|
||||
}
|
||||
|
||||
draw.content(
|
||||
(x, -y),
|
||||
text(txt, fill: color, size: size, ..text-params),
|
||||
anchor: anchor,
|
||||
stroke: none
|
||||
)
|
||||
}
|
||||
|
||||
#let draw-line(color, a, b) = {
|
||||
let (x0, y0) = a
|
||||
let (x1, y1) = b
|
||||
draw.line((x0, -y0), (x1, -y1), stroke: color)
|
||||
}
|
||||
|
||||
#let draw-lines(color, ..pts) = {
|
||||
let pts = pts.pos().map(pt => (pt.at(0), -pt.at(1)))
|
||||
draw.line(..pts, stroke: color)
|
||||
}
|
||||
|
||||
#let draw-poly(color, ..pts, thickness: 0) = {
|
||||
let pts = pts.pos().map(pt => (pt.at(0), -pt.at(1)))
|
||||
let params = (
|
||||
stroke: (paint: color, thickness: thickness),
|
||||
fill: none
|
||||
)
|
||||
if thickness == 0 {
|
||||
params = (
|
||||
stroke: none,
|
||||
fill: color
|
||||
)
|
||||
}
|
||||
draw.line(..pts, ..params)
|
||||
}
|
||||
|
||||
#let draw-underbracket(config, start, end, bits-y) = {
|
||||
let bit-w = config.bit-width
|
||||
let bit-h = config.bit-height
|
||||
|
||||
let x0 = start + bit-w / 2
|
||||
let x1 = end - bit-w / 2
|
||||
let y0 = bits-y + bit-h * 1.25
|
||||
let y1 = bits-y + bit-h * 1.5
|
||||
|
||||
let col = config.link-color
|
||||
draw-lines(col, (x0, y0), (x0, y1), (x1, y1), (x1, y0))
|
||||
}
|
||||
|
||||
#let draw-link(
|
||||
config,
|
||||
start-x,
|
||||
start-y,
|
||||
end-x,
|
||||
end-y
|
||||
) = {
|
||||
let bit-h = config.bit-height
|
||||
let arrow-margin = config.arrow-margin
|
||||
|
||||
if end-x > start-x {
|
||||
end-x -= arrow-margin
|
||||
} else {
|
||||
end-x += arrow-margin
|
||||
}
|
||||
|
||||
draw-lines(
|
||||
config.link-color,
|
||||
(start-x, start-y + bit-h * 1.5),
|
||||
(start-x, end-y + bit-h / 2),
|
||||
(end-x, end-y + bit-h / 2),
|
||||
)
|
||||
}
|
||||
|
||||
#let draw-values(config, values, desc-x, desc-y) = {
|
||||
let shapes = ()
|
||||
let txt-col = config.text-color
|
||||
let bit-w = config.bit-height // Why ? I don't remember
|
||||
let gap = config.values-gap
|
||||
|
||||
for (val, desc) in values.pairs().sorted(key: p => p.first()) {
|
||||
desc-y += gap
|
||||
let txt = val + " = " + desc
|
||||
shapes += draw-text(
|
||||
txt, txt-col, desc-x + bit-w / 2, desc-y,
|
||||
anchor: "north-west",
|
||||
font: config.italic-font-family,
|
||||
italic: true,
|
||||
size: config.italic-font-size
|
||||
)
|
||||
|
||||
desc-y += config.italic-font-size / 1.2pt
|
||||
}
|
||||
|
||||
return (shapes, desc-x, desc-y)
|
||||
}
|
||||
|
||||
#let draw-description(
|
||||
config,
|
||||
range_,
|
||||
start-x,
|
||||
start-y,
|
||||
width,
|
||||
desc-x,
|
||||
desc-y
|
||||
) = {
|
||||
let shapes = ()
|
||||
let bit-w = config.bit-width
|
||||
let bit-h = config.bit-height
|
||||
|
||||
if config.left-labels {
|
||||
desc-x = calc.min(desc-x, start-x + width / 2 - bit-w)
|
||||
} else {
|
||||
desc-x = calc.max(desc-x, start-x + width / 2 + bit-w)
|
||||
}
|
||||
|
||||
shapes += draw-underbracket(config, start-x, start-x + width, start-y)
|
||||
|
||||
let mid-x = start-x + width / 2
|
||||
shapes += draw-link(config, mid-x, start-y, desc-x, desc-y)
|
||||
|
||||
let txt-x = desc-x
|
||||
|
||||
if config.left-labels {
|
||||
txt-x -= range_.description.len() * config.default-font-size / 2pt
|
||||
}
|
||||
|
||||
shapes += draw-text(
|
||||
range_.description,
|
||||
config.text-color,
|
||||
txt-x, desc-y + bit-h / 2,
|
||||
anchor: "west"
|
||||
)
|
||||
|
||||
desc-y += config.default-font-size / 0.75pt
|
||||
|
||||
if range_.values != none and range_.depends-on == none {
|
||||
let shapes_
|
||||
(shapes_, _, desc-y) = draw-values(config, range_.values, txt-x, desc-y)
|
||||
shapes += shapes_
|
||||
}
|
||||
|
||||
desc-y += config.description-margin
|
||||
|
||||
return (shapes, desc-x, desc-y)
|
||||
}
|
||||
|
||||
#let draw-arrow(config, start-x, start-y, end-x, end-y, label: "") = {
|
||||
let shapes = ()
|
||||
let dash-len = config.dash-length
|
||||
let dash-space = config.dash-space
|
||||
let arrow-size = config.arrow-size
|
||||
let link-col = config.link-color
|
||||
let txt-col = config.text-color
|
||||
let arrow-label-dist = config.arrow-label-distance
|
||||
|
||||
let start = vec.vec(start-x, start-y)
|
||||
let end = vec.vec(end-x, end-y)
|
||||
let start-end = vec.sub(end, start)
|
||||
let d = vec.normalize(start-end)
|
||||
|
||||
let dashes = int(vec.mag(start-end) / (dash-len + dash-space))
|
||||
|
||||
for i in range(dashes) {
|
||||
let a = vec.add(
|
||||
start,
|
||||
vec.mul(d, i * (dash-len + dash-space))
|
||||
)
|
||||
let b = vec.add(
|
||||
a,
|
||||
vec.mul(d, dash-len)
|
||||
)
|
||||
|
||||
shapes += draw-line(link-col, (a.x, a.y), (b.x, b.y))
|
||||
}
|
||||
|
||||
let n = vec.vec(d.y, -d.x)
|
||||
let width = arrow-size / 1.5
|
||||
let p1 = vec.sub(
|
||||
end,
|
||||
vec.sub(
|
||||
vec.mul(d, arrow-size),
|
||||
vec.mul(n, width)
|
||||
)
|
||||
)
|
||||
let p2 = vec.sub(
|
||||
end,
|
||||
vec.add(
|
||||
vec.mul(d, arrow-size),
|
||||
vec.mul(n, width)
|
||||
)
|
||||
)
|
||||
|
||||
shapes += draw-poly(
|
||||
link-col,
|
||||
(end.x, end.y),
|
||||
(p1.x, p1.y),
|
||||
(p2.x, p2.y)
|
||||
)
|
||||
|
||||
if label != "" {
|
||||
shapes += draw-text(
|
||||
label,
|
||||
txt-col,
|
||||
(start.x + end.x) / 2,
|
||||
(start.y + end.y) / 2 + arrow-label-dist,
|
||||
anchor: "north"
|
||||
)
|
||||
}
|
||||
|
||||
return shapes
|
||||
}
|
||||
|
||||
#let draw-dependency(
|
||||
draw-struct, config,
|
||||
struct, schema, bits-x, bits-y, range_, desc-x, desc-y
|
||||
) = {
|
||||
let shapes = ()
|
||||
|
||||
let bit-w = config.bit-width
|
||||
let bit-h = config.bit-height
|
||||
let arrow-margin = config.arrow-margin
|
||||
|
||||
let start-i = struct.bits - range_.end - 1
|
||||
let start-x = bits-x + start-i * bit-w
|
||||
let width = rng.bits(range_) * bit-w
|
||||
|
||||
shapes += draw-underbracket(config, start-x, start-x + width, bits-y)
|
||||
let depend-key = rng.key(..range_.depends-on)
|
||||
let depend-range = struct.ranges.at(depend-key)
|
||||
let prev-range-y = bits-y + bit-h * 1.5
|
||||
|
||||
let prev-depend-y = if depend-range.last-value-y == -1 {
|
||||
bits-y + bit-h * 1.5
|
||||
} else {
|
||||
depend-range.last-value-y
|
||||
}
|
||||
|
||||
let depend-start-i = struct.bits - depend-range.end - 1
|
||||
let depend-start-x = bits-x + depend-start-i * bit-w
|
||||
let depend-width = rng.bits(depend-range) * bit-w
|
||||
let depend-mid = depend-start-x + depend-width / 2
|
||||
shapes += draw-underbracket(config, depend-start-x, depend-start-x + depend-width, bits-y)
|
||||
|
||||
for (val, data) in range_.values.pairs().sorted(key: p => p.first()) {
|
||||
shapes += draw-arrow(config, depend-mid, prev-depend-y, depend-mid, desc-y - arrow-margin)
|
||||
|
||||
let val-ranges = (:)
|
||||
for i in range(rng.bits(depend-range)) {
|
||||
val-ranges.insert(
|
||||
str(depend-range.end - i),
|
||||
(name: val.at(i))
|
||||
)
|
||||
}
|
||||
|
||||
let val-struct = (
|
||||
bits: rng.bits(depend-range),
|
||||
start: depend-range.start,
|
||||
ranges: val-ranges
|
||||
)
|
||||
val-struct = structure.load("", val-struct)
|
||||
|
||||
let shapes_
|
||||
(shapes_, ..) = draw-struct(config, val-struct, schema, ox: depend-start-x, oy: desc-y)
|
||||
shapes += shapes_
|
||||
|
||||
let y = desc-y + bit-h * 1.5
|
||||
|
||||
let x1
|
||||
let x2
|
||||
|
||||
// Arrow from left to right
|
||||
if depend-range.end > range_.start {
|
||||
x1 = depend-start-x + depend-width + arrow-margin
|
||||
x2 = start-x - arrow-margin
|
||||
|
||||
// Arrow from right to left
|
||||
} else {
|
||||
x1 = depend-start-x - arrow-margin
|
||||
x2 = start-x + width + arrow-margin
|
||||
}
|
||||
|
||||
shapes += draw-arrow(config, x1, y, x2, y, label: data.description)
|
||||
shapes += draw-arrow(config,
|
||||
start-x + width - bit-w,
|
||||
prev-range-y,
|
||||
start-x + width - bit-w,
|
||||
desc-y + bit-h - arrow-margin
|
||||
)
|
||||
|
||||
prev-depend-y = desc-y + bit-h * 2 + arrow-margin
|
||||
prev-range-y = prev-depend-y
|
||||
depend-range.last-value-y = prev-depend-y
|
||||
|
||||
(shapes_, desc-y) = draw-struct(config, schema.structures.at(data.structure), schema, ox: start-x, oy: desc-y)
|
||||
shapes += shapes_
|
||||
}
|
||||
|
||||
struct.ranges.at(depend-key) = depend-range
|
||||
|
||||
return (shapes, desc-x, desc-y, struct)
|
||||
}
|
||||
|
||||
#let draw-structure(config, struct, schema, ox: 0, oy: 0) = {
|
||||
let shapes
|
||||
let colors = schema.at("colors", default: (:))
|
||||
let bg-col = config.background
|
||||
let txt-col = config.text-color
|
||||
let border-col = config.border-color
|
||||
let bit-w = config.bit-width
|
||||
let bit-h = config.bit-height
|
||||
|
||||
let (bits-x, bits-y) = (ox, oy + bit-h)
|
||||
let bits-width = struct.bits * bit-w
|
||||
let start-bit = struct.start
|
||||
let bit-colors = (:)
|
||||
for i in range(struct.bits) {
|
||||
bit-colors.insert(str(i), bg-col)
|
||||
}
|
||||
if struct.name in colors {
|
||||
for (s, col) in colors.at(struct.name) {
|
||||
let (start, end) = rng.parse-span(s)
|
||||
for i in range(start, end + 1) {
|
||||
let real-i = struct.bits - i - 1 + start-bit
|
||||
bit-colors.insert(str(real-i), col)
|
||||
}
|
||||
}
|
||||
}
|
||||
let range-boundaries = ()
|
||||
for r in struct.ranges.values() {
|
||||
let i = struct.bits - r.end - 1 + start-bit
|
||||
range-boundaries.push(i)
|
||||
}
|
||||
|
||||
// Draw colors
|
||||
for i in range(struct.bits) {
|
||||
let bit-x = ox + i * bit-w
|
||||
shapes += draw-rect(bit-colors.at(str(i)), bit-x, bits-y, bit-w+1, bit-h)
|
||||
}
|
||||
|
||||
// Draw rectangle around structure
|
||||
shapes += draw-rect(border-col, bits-x, bits-y, bits-width, bit-h, thickness: 2)
|
||||
|
||||
let indices = range(struct.bits)
|
||||
if not config.all-bit-i {
|
||||
indices = ()
|
||||
for r in struct.ranges.values() {
|
||||
indices.push(r.start)
|
||||
indices.push(r.end)
|
||||
}
|
||||
}
|
||||
|
||||
for i in range(struct.bits) {
|
||||
let bit-x = ox + i * bit-w
|
||||
let real-i = struct.bits - i - 1 + start-bit
|
||||
|
||||
if real-i in indices {
|
||||
shapes += draw-text(
|
||||
str(real-i),
|
||||
txt-col,
|
||||
bit-x + bit-w / 2,
|
||||
oy + bit-h / 2
|
||||
)
|
||||
}
|
||||
|
||||
// Draw separator
|
||||
if i != 0 and not i in range-boundaries {
|
||||
shapes += draw-line(border-col, (bit-x, bits-y), (bit-x, bits-y + bit-h * 0.2))
|
||||
shapes += draw-line(border-col, (bit-x, bits-y + bit-h * 0.8), (bit-x, bits-y + bit-h))
|
||||
}
|
||||
}
|
||||
|
||||
let ranges = structure.get-sorted-ranges(struct)
|
||||
if config.left-labels {
|
||||
ranges = ranges.rev()
|
||||
}
|
||||
|
||||
let desc-x
|
||||
if config.force-descs-on-side {
|
||||
desc-x = config.margins.at(3) + structures.main.bits * bit-w
|
||||
if config.left-labels {
|
||||
desc-x = config.width - desc-x
|
||||
}
|
||||
} else {
|
||||
desc-x = ox
|
||||
if config.left-labels {
|
||||
desc-x += struct.bits * bit-w
|
||||
}
|
||||
}
|
||||
|
||||
let desc-y = bits-y + bit-h * 2
|
||||
|
||||
// Names + simple descriptions
|
||||
for range_ in ranges {
|
||||
let start-i = struct.bits - range_.end + start-bit - 1
|
||||
let start-x = bits-x + start-i * bit-w
|
||||
let width = rng.bits(range_) * bit-w
|
||||
|
||||
let name-x = start-x + width / 2
|
||||
let name-y = bits-y + bit-h / 2
|
||||
|
||||
shapes += draw-line(border-col, (start-x, bits-y), (start-x, bits-y + bit-h))
|
||||
shapes += draw-text(range_.name, txt-col, name-x, name-y, fill: bg-col)
|
||||
|
||||
if range_.description != "" {
|
||||
let shapes_
|
||||
(shapes_, desc-x, desc-y) = draw-description(
|
||||
config, range_, start-x, bits-y, width, desc-x, desc-y
|
||||
)
|
||||
shapes += shapes_
|
||||
}
|
||||
}
|
||||
|
||||
// Dependencies
|
||||
for range_ in ranges {
|
||||
if range_.values() != none and range_.depends-on != none {
|
||||
let shapes_
|
||||
(shapes_, desc-x, desc-y, struct) = draw-dependency(
|
||||
draw-structure, config,
|
||||
struct, schema, bits-x, bits-y, range_, desc-x, desc-y,
|
||||
)
|
||||
shapes += shapes_
|
||||
}
|
||||
}
|
||||
|
||||
return (shapes, desc-y)
|
||||
}
|
||||
#import "cetz.typ": canvas
|
||||
#import "render/structure.typ" as struct
|
||||
|
||||
#let render(config, schema, width: 100%) = {
|
||||
set text(
|
||||
font: config.default-font-family,
|
||||
size: config.default-font-size
|
||||
)
|
||||
|
||||
let main = schema.structures.main
|
||||
let ox = config.margins.at(3)
|
||||
if config.left-labels {
|
||||
ox = config.width - ox - main.bits * config.bit-width
|
||||
}
|
||||
|
||||
let params = if config.full-page {
|
||||
(
|
||||
width: auto,
|
||||
height: auto,
|
||||
fill: config.background,
|
||||
margin: 0cm
|
||||
)
|
||||
} else {
|
||||
(:)
|
||||
}
|
||||
|
||||
set page(..params)
|
||||
|
||||
let cnvs = canvas(length: 1pt, background: config.background, {
|
||||
let (shapes, _) = draw-structure(
|
||||
config, main, schema,
|
||||
ox: ox,
|
||||
oy: config.margins.at(0)
|
||||
)
|
||||
// Workaround for margins
|
||||
draw.group(name: "g", padding: config.margins, shapes)
|
||||
draw.line(
|
||||
"g.north-west",
|
||||
"g.north-east",
|
||||
"g.south-east",
|
||||
"g.south-west",
|
||||
stroke: none,
|
||||
fill: none
|
||||
)
|
||||
canvas(length: 1pt, {
|
||||
struct.render(config, schema, schema.structures.main)
|
||||
})
|
||||
|
||||
if config.full-page {
|
||||
cnvs
|
||||
} else {
|
||||
layout(size => {
|
||||
let m = measure(cnvs)
|
||||
let w = m.width
|
||||
let h = m.height
|
||||
let base-w = if type(width) == ratio {
|
||||
size.width * width
|
||||
} else {
|
||||
width
|
||||
}
|
||||
let r = if w == 0 {
|
||||
0
|
||||
} else {
|
||||
base-w / w
|
||||
}
|
||||
|
||||
let new-w = w * r
|
||||
let new-h = h * r
|
||||
r *= 100%
|
||||
|
||||
box(
|
||||
width: new-w,
|
||||
height: new-h,
|
||||
scale(x: r, y: r, cnvs, reflow: true)
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#let make(config) = {
|
||||
@@ -537,4 +12,4 @@
|
||||
config: config,
|
||||
render: render.with(config)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#let parse-raw(schema) = {
|
||||
let lang = schema.lang
|
||||
let content = schema.text
|
||||
let content = bytes(schema.text)
|
||||
if not lang in valid-extensions {
|
||||
let fmts = valid-extensions.join(", ")
|
||||
fmts = "(" + fmts + ")"
|
||||
@@ -33,11 +33,11 @@
|
||||
}
|
||||
|
||||
if lang == "yaml" {
|
||||
return yaml.decode(content)
|
||||
return yaml(content)
|
||||
} else if lang == "json" {
|
||||
return json.decode(content)
|
||||
return json(content)
|
||||
} else if lang == "xml" {
|
||||
return xml-loader.parse(xml.decode(content).first())
|
||||
return xml-loader.parse(xml(content).first())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
name = "rivet"
|
||||
version = "0.0.2"
|
||||
compiler = "0.11.0"
|
||||
version = "0.3.0"
|
||||
compiler = "0.13.1"
|
||||
repository = "https://git.kb28.ch/HEL/rivet-typst"
|
||||
entrypoint = "src/lib.typ"
|
||||
authors = [
|
||||
@@ -11,4 +11,4 @@ categories = [ "visualization" ]
|
||||
license = "Apache-2.0"
|
||||
description = "Register / Instruction Visualizer & Explainer Tool with Typst, using CeTZ"
|
||||
keywords = [ "assembly", "instruction", "binary" ]
|
||||
exclude = [ "/gallery/*" ]
|
||||
exclude = [ "gallery", "justfile", "docs" ]
|
||||
Reference in New Issue
Block a user