diff --git a/packages/preview/colorful-boxes/1.1.0/LICENSE b/packages/preview/colorful-boxes/1.1.0/LICENSE new file mode 100644 index 000000000..bdb7064c3 --- /dev/null +++ b/packages/preview/colorful-boxes/1.1.0/LICENSE @@ -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. diff --git a/packages/preview/colorful-boxes/1.1.0/README.md b/packages/preview/colorful-boxes/1.1.0/README.md new file mode 100644 index 000000000..e348f6298 --- /dev/null +++ b/packages/preview/colorful-boxes/1.1.0/README.md @@ -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) +] +``` diff --git a/packages/preview/colorful-boxes/1.1.0/background.svg b/packages/preview/colorful-boxes/1.1.0/background.svg new file mode 100644 index 000000000..d8b3af2d2 --- /dev/null +++ b/packages/preview/colorful-boxes/1.1.0/background.svg @@ -0,0 +1,18 @@ + + +background + + + + + + + + + + + + + + + diff --git a/packages/preview/colorful-boxes/1.1.0/examples/colorbox.png b/packages/preview/colorful-boxes/1.1.0/examples/colorbox.png new file mode 100644 index 000000000..2d3447291 Binary files /dev/null and b/packages/preview/colorful-boxes/1.1.0/examples/colorbox.png differ diff --git a/packages/preview/colorful-boxes/1.1.0/examples/outlinebox.png b/packages/preview/colorful-boxes/1.1.0/examples/outlinebox.png new file mode 100644 index 000000000..98e5b70c0 Binary files /dev/null and b/packages/preview/colorful-boxes/1.1.0/examples/outlinebox.png differ diff --git a/packages/preview/colorful-boxes/1.1.0/examples/slantedColorbox.png b/packages/preview/colorful-boxes/1.1.0/examples/slantedColorbox.png new file mode 100644 index 000000000..3c546f198 Binary files /dev/null and b/packages/preview/colorful-boxes/1.1.0/examples/slantedColorbox.png differ diff --git a/packages/preview/colorful-boxes/1.1.0/examples/stickybox.png b/packages/preview/colorful-boxes/1.1.0/examples/stickybox.png new file mode 100644 index 000000000..6a01c880a Binary files /dev/null and b/packages/preview/colorful-boxes/1.1.0/examples/stickybox.png differ diff --git a/packages/preview/colorful-boxes/1.1.0/lib.typ b/packages/preview/colorful-boxes/1.1.0/lib.typ new file mode 100644 index 000000000..b1139decb --- /dev/null +++ b/packages/preview/colorful-boxes/1.1.0/lib.typ @@ -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 + ] + ] + ] +} \ No newline at end of file diff --git a/packages/preview/colorful-boxes/1.1.0/tape.svg b/packages/preview/colorful-boxes/1.1.0/tape.svg new file mode 100644 index 000000000..fb7d57a54 --- /dev/null +++ b/packages/preview/colorful-boxes/1.1.0/tape.svg @@ -0,0 +1,7 @@ + + +sticky + + + + \ No newline at end of file diff --git a/packages/preview/colorful-boxes/1.1.0/typst.toml b/packages/preview/colorful-boxes/1.1.0/typst.toml new file mode 100644 index 000000000..f1b0e034d --- /dev/null +++ b/packages/preview/colorful-boxes/1.1.0/typst.toml @@ -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 "] +license = "MIT" +description = "Predefined colorful boxes" +exclude = [ "/examples/*"] \ No newline at end of file