Skip to contents

Compare moods and sizes on a single offline page. Creating the page starts no Shiny app, opens no viewer and writes no files. Printing the returned page opens the available Viewer or browser. It can also be embedded in an R Markdown or Quarto document.

Usage

mascot_preview(
  character = "tessa",
  ...,
  mood = NULL,
  status = NULL,
  bubble = NULL,
  size = 160,
  theme = NULL,
  motion = FALSE
)

Arguments

character

A character id such as "tessa", or a mascot_character() helper (Knurl and Neer are experimental). Defaults to "tessa". NULL is not accepted.

...

Must be empty. Forces the arguments after it to be named.

mood

A mood name or mascot_mood() object, or NULL (the default) to show every mood from mascot_moods().

status

A non-empty string or mascot_status() object. NULL (the default) follows the mood. Text is always escaped, even inside htmltools::HTML().

bubble

A non-empty string, an htmltools tag or tag list, or a mascot_bubble() object. NULL (the default) shows no bubble. A plain string gets the defaults of mascot_bubble(): five seconds and a close button. Plain text is escaped; htmltools::HTML() or tags supply HTML. Tags with dependencies or head content are not supported.

size

A finite number of CSS pixels (at least 24), a positive percentage string such as "20%", or a mascot_size() object. Defaults to 160. Percentages follow the comparison cell width. NULL is not accepted.

theme

A palette id string from mascot_palettes(), a named list of colour roles, a bslib::bs_theme() or a mascot_theme() object. NULL (the default) keeps the character's own colours. A palette sets the base colours for light and dark mode; "original" selects the character's own colours. Roles you leave unset follow the character's rules.

motion

A logical flag or mascot_motion_settings() object. Defaults to FALSE for steady faces; TRUE allows movement unless the visitor prefers reduced motion. NULL is not accepted.

Value

A browsable htmltools tag list. Its contrast attribute is a data frame with role, colour, background, ratio and mode columns, one row per supplied colour below 3:1. With no findings it is a zero-row data frame with the same columns. Colours are not changed. R gives one combined warning unless mascot.contrast_warnings is FALSE.

Details

Comparison grid. Rows are moods; columns are the requested size, then 160, 96 and 24 CSS pixels. The first column keeps your percentage and small_screen settings; the fixed columns do not change on narrow screens. Every size draws the full character. Each cell keeps its status text, since small faces lose fine detail.

Theme and contrast. A palette id string works as in mascot(). Built-in palette colours do not add contrast warnings. When the theme gives both a light and a dark map, both are shown, even if it sets one mode. Backgrounds are white and #212529, or the bslib theme's bg and body-bg-dark; text uses fg and body-color-dark. Only supplied colour roles are checked, using the same contrast calculation as mascot(). The browser reads colours from experimental CSS variables and checks them. Any warnings appear in the browser's developer console, not in the R contrast attribute.

Bubbles. Cells without a bubble leave out its space; a supplied bubble keeps its normal space and timing. Each cell is wide enough to hold it, so bubbles never cover neighbouring cells.

Experimental

Experimental Its purpose, arguments and page layout may change in a later release.

Examples

page <- mascot_preview(mood = "happy", size = 96)
attr(page, "contrast")
#> [1] role       colour     background ratio      mode      
#> <0 rows> (or 0-length row.names)
if (FALSE) { # interactive()
mascot_preview()
}