-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
313 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 lkoehl | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# typst-boxes | ||
|
||
Colorful boxes in [Typst](https://github.com/typst/typst). | ||
|
||
Check out [the example project](https://typst.app/project/rp9q3upfc69bPUCbv0BjzX) to see all boxes in action | ||
|
||
Current features include: | ||
|
||
- a colorful box is in four different colors (black, red, blue, green) | ||
- a colorful box with a slanted headline | ||
- a box with a simple outline | ||
- a rotateable stickynote | ||
|
||
## Colorbox | ||
|
||
![colorbox_example](examples/colorbox.png) | ||
|
||
### Usage | ||
|
||
``` | ||
#colorbox( | ||
title: lorem(5), | ||
color: "blue", | ||
radius: 2pt, | ||
width: auto | ||
)[ | ||
#lorem(50) | ||
] | ||
``` | ||
|
||
## Slanted Colorbox | ||
|
||
![slantedColorbox_example](examples/slantedColorbox.png) | ||
|
||
### Usage | ||
|
||
``` | ||
#slanted-colorbox( | ||
title: lorem(5), | ||
color: "red", | ||
radius: 0pt, | ||
width: auto | ||
)[ | ||
#lorem(50) | ||
] | ||
``` | ||
|
||
## Outlinebox | ||
|
||
![outlinebox_example](examples/outlinebox.png) | ||
|
||
### Usage | ||
|
||
``` | ||
#outlinebox( | ||
title: lorem(5), | ||
color: none, | ||
width: auto, | ||
radius: 2pt, | ||
centering: false | ||
)[ | ||
#lorem(50) | ||
] | ||
#outlinebox( | ||
title: lorem(5), | ||
color: "green", | ||
width: auto, | ||
radius: 2pt, | ||
centering: true | ||
)[ | ||
#lorem(50) | ||
] | ||
``` | ||
|
||
## Stickybox | ||
|
||
![stickybox](examples/stickybox.png) | ||
|
||
### Usage | ||
|
||
``` | ||
#stickybox( | ||
rotation: 3deg, | ||
width: 7cm | ||
)[ | ||
#lorem(20) | ||
] | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
#let colorbox(title: "title", color: none, radius: 2pt, width: auto, body) = { | ||
|
||
let strokeColor = luma(70) | ||
let backgroundColor = white | ||
|
||
if color == "red" { | ||
strokeColor = rgb(237, 32, 84) | ||
backgroundColor = rgb(253, 228, 224) | ||
} else if color == "green" { | ||
strokeColor = rgb(102, 174, 62) | ||
backgroundColor = rgb(235, 244, 222) | ||
} else if color == "blue" { | ||
strokeColor = rgb(29, 144, 208) | ||
backgroundColor = rgb(232, 246, 253) | ||
} | ||
|
||
return box( | ||
fill: backgroundColor, | ||
stroke: 2pt + strokeColor, | ||
radius: radius, | ||
width: width | ||
)[ | ||
#block( | ||
fill: strokeColor, | ||
inset: 8pt, | ||
radius: (top-left: radius, bottom-right: radius), | ||
)[ | ||
#text(fill: white, weight: "bold")[#title] | ||
] | ||
#block( | ||
width: 100%, | ||
inset: (x: 8pt, bottom: 8pt) | ||
)[ | ||
#body | ||
] | ||
] | ||
} | ||
|
||
#let slantedBackground(color: black, body) = { | ||
set text(fill: white, weight: "bold") | ||
style(styles => { | ||
let size = measure(body, styles) | ||
let inset = 8pt | ||
[#block()[ | ||
#polygon( | ||
fill: color, | ||
(0pt, 0pt), | ||
(0pt, size.height + (2*inset)), | ||
(size.width + (2*inset), size.height + (2*inset)), | ||
(size.width + (2*inset) + 6pt, 0cm) | ||
) | ||
#place(center + top, dy: size.height, dx: -3pt)[#body] | ||
]] | ||
}) | ||
} | ||
|
||
#let slantedColorbox(title: "title", color: none, radius: 0pt, width: auto, body) = { | ||
|
||
let strokeColor = luma(70) | ||
let backgroundColor = white | ||
|
||
if color == "red" { | ||
strokeColor = rgb(237, 32, 84) | ||
backgroundColor = rgb(253, 228, 224) | ||
} else if color == "green" { | ||
strokeColor = rgb(102, 174, 62) | ||
backgroundColor = rgb(235, 244, 222) | ||
} else if color == "blue" { | ||
strokeColor = rgb(29, 144, 208) | ||
backgroundColor = rgb(232, 246, 253) | ||
} | ||
|
||
return box( | ||
fill: backgroundColor, | ||
stroke: 2pt + strokeColor, | ||
radius: radius, | ||
width: width | ||
)[ | ||
#slantedBackground(color: strokeColor)[#title] | ||
#block( | ||
width: 100%, | ||
inset: (top: -2pt, x: 10pt, bottom: 10pt) | ||
)[ | ||
#body | ||
] | ||
] | ||
} | ||
|
||
#let outlinebox(title: "title",color: none, width: 100%, radius: 2pt, centering: false, body) = { | ||
|
||
let strokeColor = luma(70) | ||
|
||
if color == "red" { | ||
strokeColor = rgb(237, 32, 84) | ||
} else if color == "green" { | ||
strokeColor = rgb(102, 174, 62) | ||
} else if color == "blue" { | ||
strokeColor = rgb(29, 144, 208) | ||
} | ||
|
||
return block( | ||
stroke: 2pt + strokeColor, | ||
radius: radius, | ||
width: width, | ||
above: 26pt, | ||
)[ | ||
#if centering [ | ||
#place(top + center, dy: -12pt)[ | ||
#block( | ||
fill: strokeColor, | ||
inset: 8pt, | ||
radius: radius, | ||
)[ | ||
#text(fill: white, weight: "bold")[#title] | ||
] | ||
] | ||
] else [ | ||
#place(top + start, dy: -12pt, dx:20pt)[ | ||
#block( | ||
fill: strokeColor, | ||
inset: 8pt, | ||
radius: radius, | ||
)[ | ||
#text(fill: white, weight: "bold")[#title] | ||
] | ||
] | ||
] | ||
|
||
#block( | ||
width: 100%, | ||
inset: (top:20pt, x: 10pt, bottom: 10pt) | ||
)[ | ||
#body | ||
] | ||
] | ||
} | ||
|
||
#let stickybox(rotation: 0deg, width: 100%, body) = { | ||
let stickyYellow = rgb(255, 240, 172) | ||
|
||
return rotate(rotation)[ | ||
#let shadow = 100% | ||
#if width != 100% { | ||
shadow = width | ||
} | ||
#place(bottom + center, dy: 0.04*shadow)[ | ||
#image("background.svg", | ||
width: shadow - 3mm, | ||
) | ||
] | ||
#block( | ||
fill: stickyYellow, | ||
width: width | ||
)[ | ||
#place(top + center, dy: -2mm)[ | ||
#image("tape.svg", | ||
width: calc.clamp(width * 0.35 / 1cm, 1, 4) * 1cm, | ||
height: 4mm, | ||
) | ||
] | ||
#block( | ||
width: 100%, | ||
inset: (top:12pt, x: 8pt, bottom: 8pt) | ||
)[ | ||
#body | ||
] | ||
] | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "colorful-boxes" | ||
version = "1.1.0" | ||
repository = "https://github.com/lkoehl/typst-boxes" | ||
entrypoint = "lib.typ" | ||
authors = ["Lukas Köhl <https://github.com/lkoehl>"] | ||
license = "MIT" | ||
description = "Predefined colorful boxes" | ||
exclude = [ "/examples/*"] |