Skip to content
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
16 changes: 16 additions & 0 deletions packages/preview/dashy-todo/0.1.3/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
MIT No Attribution

Copyright 2024-2025 Otto-AA

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.

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.
50 changes: 50 additions & 0 deletions packages/preview/dashy-todo/0.1.3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Dashy TODO

Create simple TODO comments, which are displayed at the sides of the page.

I suggest to also take a look at the [drafting package](https://typst.app/universe/package/drafting), which is a more feature-complete annotation library, but also suitable for simple TODO comments.

![Screenshot](example.svg)

## Usage

The package provides a `todo(message, position: auto | left | right)` method. Call it anywhere you need a todo message.

```typst
#import "@preview/dashy-todo:0.1.3": todo

// It automatically goes to the closer side (left or right)
A todo on the left #todo[On the left].

// You can specify a position if you want to (auto, left, right or "inline")
#todo(position: right)[Also right]

// You can add arbitrary content
#todo[We need to fix the $lim_(x -> oo)$ equation. See #link("https://example.com")[example.com]]

// And you can create an outline for the TODOs
#outline(title: "TODOs", target: figure.where(kind: "todo"))
```

## Styling

You can change the border color with any [stroke](https://typst.app/docs/reference/visualize/stroke/) type:

```
#todo(stroke: blue)[This is in blue!]

#let blue-todo = todo.with(stroke: blue)
#blue-todo[This is also in blue!]
```

You can modify the text by wrapping it, e.g.:

```
#let small-todo = (..args) => text(size: 0.6em)[#todo(..args)]

#small-todo[This will be in fine print]
```

## Contributing

See https://github.com/Otto-AA/dashy-todo/blob/main/CONTRIBUTING.md.
1,738 changes: 1,738 additions & 0 deletions packages/preview/dashy-todo/0.1.3/example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions packages/preview/dashy-todo/0.1.3/example.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#import "/lib/todo.typ": todo

#set page(width: 16cm, height: 12cm, margin: (left: 20%, right: 20%), fill: white)
#show link: underline

= Dashy TODOs

#let blue-todo = todo.with(stroke: blue)

TODOs are automatically positioned on the closer#todo[On the right] side to the method call.#blue-todo[On the left] If it doesn't fit, you can manually override it. #todo(position: "inline")[You can also place them in an inline box.]

You can add custom content.#todo(position: right, stroke: (paint: green, thickness: 1pt, dash: "densely-dashed"))[We need to fix the $lim_(x -> oo)$ equation. See #link("https://example.com")[example.com]]

#let small-todo = (..args) => text(size: 0.6em)[#todo(..args)]

We can also control the text #small-todo[This will be in fine print]size if we wrap it in a `text` call.

And finally, you can create a table of all your TODOs:

#outline(title: "TODOs", target: figure.where(kind: "todo"))
47 changes: 47 additions & 0 deletions packages/preview/dashy-todo/0.1.3/lib/box-placement.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Given a set of box heights and the preferred positions for the boxes this function calculates the position for each box
#let calculate-box-positions(boxes) = {
let total-height = boxes.map(box => box.height).sum()

let positions = ()
// If the total height of the boxes is bigger than the page height, we don't have room to re-arrange the boxes based on their preferred position. Just start at the top and place them underneath each other
if total-height >= page.height {
let accumulated-height = 0mm
for box in boxes {
let top = accumulated-height
let bottom = top + box.height
positions.push((top: top, bottom: bottom))
accumulated-height = bottom
}
}
// If there is still room available, try to move as many boxes to their preferred position as possible
else {
// `slack` is the amount of free space we still have available to move around the boxes
let slack = page.height - total-height
// Start filling the page at the bottom with the last box and work upwards
let last-box-pos = page.height
for box in boxes.rev() {
let preferred-pos = box.preferred-pos.to-absolute() // We cannot compare pt to em, so we need to make the position absolute first
// `lowest-possible-pos` is the lowest position we can give the box to make it barely fit the available space
let lowest-possible-pos = last-box-pos - box.height
// `highest-possible-pos` is the highest possible postion we can give the box so the remaining boxes still barely fit on the remaining page (all slack would be used up in this case)
let highest-possible-pos = lowest-possible-pos - slack
let box-pos
// If the preferred position can be achieved, just give it to the box
if preferred-pos >= highest-possible-pos and preferred-pos <= lowest-possible-pos {
box-pos = preferred-pos
}
// If putting the box at its preferred position is impossible, move it down as much as possible to give the other boxes as much space as possible to move to their preferred positions
else {
box-pos = lowest-possible-pos
}
let top = box-pos
let bottom = top + box.height
positions.push((top: top, bottom: bottom))
last-box-pos = box-pos
// Track how much of the slack we've used up
slack -= lowest-possible-pos - box-pos
}
positions = positions.rev()
}
positions
}
101 changes: 101 additions & 0 deletions packages/preview/dashy-todo/0.1.3/lib/side-margin.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#let rel-to-abs = (rel, size) => rel.length + rel.ratio * size

// must run within a context
#let resolve-page-binding() = {
assert(
not (page.binding == auto and text.dir == auto),
message: "Could not infer page margins. Please use `#set page(binding: left)` or `#set page(binding: right)` or `#set text(dir: left)` or `#set text(dir: right)`.",
)

if page.binding == left or (page.binding == auto and text.dir == ltr) {
left
} else {
right
}
}

// must run within a context
#let get-right-page-margin() = {
if "inside" in page.margin.keys() or "outside" in page.margin.keys() {
if calc.even(here().page()) {
if resolve-page-binding() == left {
page.margin.inside
} else {
page.margin.outside
}
} else {
if resolve-page-binding() == left {
page.margin.outside
} else {
page.margin.inside
}
}
} else {
page.margin.right
}
}

// must run within a context
#let get-left-page-margin() = {
if "inside" in page.margin.keys() or "outside" in page.margin.keys() {
if calc.even(here().page()) {
if resolve-page-binding() == left {
page.margin.outside
} else {
page.margin.inside
}
} else {
if resolve-page-binding() == left {
page.margin.inside
} else {
page.margin.outside
}
}
} else {
page.margin.left
}
}

#let calc-side-margin(side) = {
// https://typst.app/docs/reference/layout/page/#parameters-margin
let auto-margin = calc.min(page.width, page.height) * 2.5 / 21

if page.margin == auto {
auto-margin
} else if type(page.margin) == relative {
rel-to-abs(page.margin, page.width)
} else {
if side == left and get-left-page-margin() == auto or side == right and get-right-page-margin() == auto {
auto-margin
} else {
if side == left {
rel-to-abs(get-left-page-margin(), page.width)
} else {
rel-to-abs(get-right-page-margin(), page.width)
}
}
}
}

// must run within a context
#let calculate-page-margin-box(side) = {
assert(side in (left, right))

let margin = calc-side-margin(side)

if side == left {
(
"x": 0pt,
"y": 0pt,
"width": margin,
"height": page.height,
)
} else {
(
"x": page.width - margin,
"y": 0pt,
"width": margin,
"height": page.height,
)
}
}
Loading