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

dashy-todo:0.0.2 #1561

Merged
merged 2 commits into from
Jan 14, 2025
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.0.2/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.
41 changes: 41 additions & 0 deletions packages/preview/dashy-todo/0.0.2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Dashy TODO

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

I suggest to 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)

## Limitations

Currently, there is no prevention of TODOs being rendered on top of each other. See [here](https://github.com/Otto-AA/dashy-todo/issues/1) for more information.

## 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.0.2": todo

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

// You can specify a side if you want to
#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 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]
```
2,053 changes: 2,053 additions & 0 deletions packages/preview/dashy-todo/0.0.2/example.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions packages/preview/dashy-todo/0.0.2/example.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#import "lib/todo.typ": todo

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

= Dashy TODOs

TODOs are automatically positioned on the closer#todo[On the right] side to the method call.#todo[On the left] If it doesn't fit, you can manually override it.

You can add custom content.#todo(position: right)[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"))
24 changes: 24 additions & 0 deletions packages/preview/dashy-todo/0.0.2/lib/place-in-page-margin.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#import "side-margin.typ": calc-side-margin

#let place-in-page-margin(body, cur-pos: none, position: auto) = (
box({
let side = position
if position == auto {
if cur-pos.x > page.width / 2 {
side = right
} else {
side = left
}
}

// caclulation based on https://typst.app/docs/reference/layout/page/#parameters-margin
let page-side-margin = calc-side-margin(side)

let target-x = if side == left { 0pt } else { page.width - page-side-margin }
let delta-x = target-x - cur-pos.x

place(dx: delta-x)[
#box(body, width: page-side-margin)
]
})
)
46 changes: 46 additions & 0 deletions packages/preview/dashy-todo/0.0.2/lib/side-margin.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#let rel-to-abs = (rel, size) => rel.length + rel.ratio * size

// must run within a context
#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 page.margin.left == auto or side == right and page.margin.right == auto {
auto-margin
} else {
if side == left {
rel-to-abs(page.margin.left, page.width)
} else {
rel-to-abs(page.margin.right, 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,
)
}
}
76 changes: 76 additions & 0 deletions packages/preview/dashy-todo/0.0.2/lib/todo.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#import "side-margin.typ": calculate-page-margin-box

#let to-string(content) = {
if type(content) == str {
content
} else if content.has("text") {
content.text
} else if content.has("children") {
content.children.map(to-string).join("")
} else if content.has("body") {
to-string(content.body)
} else if content == [ ] {
" "
}
}

#let todo(body, position: auto) = (
context box({
assert(position in (auto, left, right), message: "Can only position todo on the left or right side currently")

let text-position = here().position()

let side = position
if position == auto {
if text-position.x > page.width / 2 {
side = right
} else {
side = left
}
}

let page-margin-box = calculate-page-margin-box(side)
let shift-y = .5em
let outer-box-inset = 4pt
let dx = page-margin-box.x - text-position.x

place(dx: dx, dy: -shift-y)[
#box(inset: outer-box-inset, width: page-margin-box.width)[
#box(stroke: orange, width: 100%)[
#place({
// defaults for right side
let line-size = dx
let line-x = -line-size
let tick-x = -line-size
// overwrites for left side
if side == left {
line-size = calc.abs(dx) - page-margin-box.width + outer-box-inset
line-x = page-margin-box.width - outer-box-inset * 2
tick-x = calc.abs(dx) - outer-box-inset
}

place(line(length: line-size, start: (line-x, shift-y), stroke: orange))
place(line(length: 4pt, start: (tick-x, shift-y), angle: -90deg, stroke: orange))
})
// the todo message
#box(body, inset: 0.2em)
]
// invisible figure, s.t. we can reference it in the outline
// probably depends on https://github.com/typst/typst/issues/147 for a cleaner solution
#hide(
box(
height: 0pt,
width: 0pt,
figure(
none,
kind: "todo",
supplement: [TODO],
caption: to-string(body),
outlined: true,
),
),
)
]
]
})
)
11 changes: 11 additions & 0 deletions packages/preview/dashy-todo/0.0.2/typst.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "dashy-todo"
version = "0.0.2"
entrypoint = "lib/todo.typ"
authors = ["Otto-AA"]
license = "MIT-0"
description = "A method to display TODOs at the side of the page."
repository = "https://github.com/Otto-AA/dashy-todo"
keywords = ["todo"]
categories = ["utility"]
exclude = ["*.svg*"]
Loading