From 80f31d37b656e1c59afffae2d2b1c5fe7f2fcc45 Mon Sep 17 00:00:00 2001 From: A_A <21040751+Otto-AA@users.noreply.github.com> Date: Tue, 14 Jan 2025 09:47:41 +0100 Subject: [PATCH] dashy-todo:0.0.2 (#1561) Co-authored-by: Ana Gelez --- packages/preview/dashy-todo/0.0.2/LICENSE | 16 + packages/preview/dashy-todo/0.0.2/README.md | 41 + packages/preview/dashy-todo/0.0.2/example.svg | 2053 +++++++++++++++++ packages/preview/dashy-todo/0.0.2/example.typ | 18 + .../0.0.2/lib/place-in-page-margin.typ | 24 + .../dashy-todo/0.0.2/lib/side-margin.typ | 46 + .../preview/dashy-todo/0.0.2/lib/todo.typ | 76 + packages/preview/dashy-todo/0.0.2/typst.toml | 11 + 8 files changed, 2285 insertions(+) create mode 100644 packages/preview/dashy-todo/0.0.2/LICENSE create mode 100644 packages/preview/dashy-todo/0.0.2/README.md create mode 100644 packages/preview/dashy-todo/0.0.2/example.svg create mode 100644 packages/preview/dashy-todo/0.0.2/example.typ create mode 100644 packages/preview/dashy-todo/0.0.2/lib/place-in-page-margin.typ create mode 100644 packages/preview/dashy-todo/0.0.2/lib/side-margin.typ create mode 100644 packages/preview/dashy-todo/0.0.2/lib/todo.typ create mode 100644 packages/preview/dashy-todo/0.0.2/typst.toml diff --git a/packages/preview/dashy-todo/0.0.2/LICENSE b/packages/preview/dashy-todo/0.0.2/LICENSE new file mode 100644 index 000000000..5b7f6866d --- /dev/null +++ b/packages/preview/dashy-todo/0.0.2/LICENSE @@ -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. \ No newline at end of file diff --git a/packages/preview/dashy-todo/0.0.2/README.md b/packages/preview/dashy-todo/0.0.2/README.md new file mode 100644 index 000000000..f63f3eaab --- /dev/null +++ b/packages/preview/dashy-todo/0.0.2/README.md @@ -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] +``` diff --git a/packages/preview/dashy-todo/0.0.2/example.svg b/packages/preview/dashy-todo/0.0.2/example.svg new file mode 100644 index 000000000..e7f8e220e --- /dev/null +++ b/packages/preview/dashy-todo/0.0.2/example.svg @@ -0,0 +1,2053 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/preview/dashy-todo/0.0.2/example.typ b/packages/preview/dashy-todo/0.0.2/example.typ new file mode 100644 index 000000000..cf4efaeb1 --- /dev/null +++ b/packages/preview/dashy-todo/0.0.2/example.typ @@ -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")) diff --git a/packages/preview/dashy-todo/0.0.2/lib/place-in-page-margin.typ b/packages/preview/dashy-todo/0.0.2/lib/place-in-page-margin.typ new file mode 100644 index 000000000..56b54a33e --- /dev/null +++ b/packages/preview/dashy-todo/0.0.2/lib/place-in-page-margin.typ @@ -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) + ] + }) +) \ No newline at end of file diff --git a/packages/preview/dashy-todo/0.0.2/lib/side-margin.typ b/packages/preview/dashy-todo/0.0.2/lib/side-margin.typ new file mode 100644 index 000000000..dff4ebb48 --- /dev/null +++ b/packages/preview/dashy-todo/0.0.2/lib/side-margin.typ @@ -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, + ) + } +} \ No newline at end of file diff --git a/packages/preview/dashy-todo/0.0.2/lib/todo.typ b/packages/preview/dashy-todo/0.0.2/lib/todo.typ new file mode 100644 index 000000000..9bc33bd0b --- /dev/null +++ b/packages/preview/dashy-todo/0.0.2/lib/todo.typ @@ -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, + ), + ), + ) + ] + ] + }) +) \ No newline at end of file diff --git a/packages/preview/dashy-todo/0.0.2/typst.toml b/packages/preview/dashy-todo/0.0.2/typst.toml new file mode 100644 index 000000000..26cf64b4a --- /dev/null +++ b/packages/preview/dashy-todo/0.0.2/typst.toml @@ -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*"]