😎 Give your xaringan slides some style
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
16KB

  1. # Generated by inst/scripts/generate_theme_functions.R: do not edit by hand
  2. #' @param text_color Text Color. Defaults to #000. Modifies the `body` element.
  3. #' @param header_color Header Color. Defaults to #000. Modifies the
  4. #' `h1, h2, h3` elements.
  5. #' @param background_color Slide Background Color. Defaults to #FFF. Modifies
  6. #' the `.remark-slide-content` class.
  7. #' @param link_color Link Color. Defaults to rgb(249, 38, 114). Modifies the
  8. #' `a, a > code` elements.
  9. #' @param text_bold_color Bold Text Color. Defaults to `NULL`. Modifies the
  10. #' `strong` element.
  11. #' @param text_slide_number_color Slide Number Color. Defaults to
  12. #' `inverse_background_color`. Modifies the `.remark-slide-number` class.
  13. #' @param padding Slide Padding in `top right [bottom left]` format. Defaults
  14. #' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
  15. #' @param background_image Background image applied to each *and every* slide.
  16. #' Set `title_slide_background_image = "none"` to remove the background image
  17. #' from the title slide. Defaults to `NULL`. Modifies the
  18. #' `.remark-slide-content` class.
  19. #' @param background_size Background image size, requires `background_image` to
  20. #' be set. If `background_image` is set, `background_size` will default to
  21. #' `cover` so the backround fills the screen. If both `background_image` and
  22. #' `background_position` are set, will default to 100 percent. Defaults to
  23. #' `NULL`. Modifies the `.remark-slide-content` class.
  24. #' @param background_position Background image position, requires
  25. #' `background_image` to be set, and it is recommended to adjust
  26. #' `background_size`. Defaults to `NULL`. Modifies the
  27. #' `.remark-slide-content` class.
  28. #' @param code_highlight_color Code Line Highlight. Defaults to
  29. #' rgba(255,255,0,0.5). Modifies the `.remark-code-line-highlighted` class.
  30. #' @param code_inline_color Inline Code Color. Defaults to #000. Modifies the
  31. #' `.remark-inline-code` class.
  32. #' @param code_inline_background_color Inline Code Background Color. Defaults
  33. #' to `NULL`. Modifies the `.remark-inline-code` class.
  34. #' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
  35. #' Modifies the `.remark-inline-code` class.
  36. #' @param inverse_background_color Inverse Background Color. Defaults to
  37. #' #272822. Modifies the `.inverse` class.
  38. #' @param inverse_text_color Inverse Text Color. Defaults to #d6d6d6. Modifies
  39. #' the `.inverse` class.
  40. #' @param inverse_text_shadow Enables Shadow on text of inverse slides.
  41. #' Defaults to `FALSE`. Modifies the `.inverse` class.
  42. #' @param inverse_header_color Inverse Header Color. Defaults to #f3f3f3.
  43. #' Modifies the `.inverse h1, .inverse h2, .inverse h3` classes.
  44. #' @param title_slide_text_color Title Slide Text Color. Defaults to
  45. #' `inverse_text_color`. Modifies the `.title-slide` class.
  46. #' @param title_slide_background_color Title Slide Background Color. Defaults
  47. #' to `inverse_background_color`. Modifies the `.title-slide` class.
  48. #' @param title_slide_background_image Title Slide Background Image URL.
  49. #' Defaults to `NULL`. Modifies the `.title-slide` class.
  50. #' @param title_slide_background_size Title Slide Background Image Size,
  51. #' defaults to "cover" if background image is set. Defaults to `NULL`.
  52. #' Modifies the `.title-slide` class.
  53. #' @param title_slide_background_position Title Slide Background Image
  54. #' Position. Defaults to `NULL`. Modifies the `.title-slide` class.
  55. #' @param footnote_color Footnote text color (if `NA`, then it will be the same
  56. #' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
  57. #' class.
  58. #' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
  59. #' the `.footnote` class.
  60. #' @param footnote_position_bottom Footnote location from bottom of screen.
  61. #' Defaults to 60px. Modifies the `.footnote` class.
  62. #' @param left_column_subtle_color Left Column Text (not last). Defaults to
  63. #' #777. Modifies the `.left-column h2, .left-column h3` classes.
  64. #' @param left_column_selected_color Left Column Current Selection. Defaults to
  65. #' #000. Modifies the
  66. #' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
  67. #' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
  68. #' to lightgray. Modifies the `blockquote` element.
  69. #' @param table_border_color Table top/bottom border. Defaults to #666.
  70. #' Modifies the `table: border-top, border-bottom` elements.
  71. #' @param table_row_border_color Table row inner bottom border. Defaults to
  72. #' #ddd. Modifies the `table thead th: border-bottom` elements.
  73. #' @param table_row_even_background_color Table Even Row Background Color.
  74. #' Defaults to #eee. Modifies the `thead, tfoot, tr:nth-child(even)`
  75. #' elements.
  76. #' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
  77. #' Defaults to 20px. Modifies the `html` element.
  78. #' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
  79. #' the `.remark-slide-content` class.
  80. #' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
  81. #' Modifies the `.remark-slide-content h1` class.
  82. #' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
  83. #' Modifies the `.remark-slide-content h2` class.
  84. #' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
  85. #' Modifies the `.remark-slide-content h3` class.
  86. #' @param header_background_auto Add background under slide title automatically
  87. #' for h1 header elements. If not enabled, use `class: header_background` to
  88. #' enable. Defaults to `FALSE`.
  89. #' @param header_background_color Background Color for h1 Header with
  90. #' Background. Defaults to `header_color`. Modifies the
  91. #' `.remark-slide-content h1` class.
  92. #' @param header_background_text_color Text Color for h1 Header with
  93. #' Background. Defaults to `background_color`. Modifies the
  94. #' `.remark-slide-content h1` class.
  95. #' @param header_background_padding Padding for h1 Header with Background.
  96. #' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class.
  97. #' @param header_background_content_padding_top Top Padding for Content in
  98. #' Slide with Header with Background. Defaults to 7rem. Modifies the
  99. #' `.remark-slide-content` class.
  100. #' @param header_background_ignore_classes Slide Classes Where Header with
  101. #' Background will not be Applied. Defaults to
  102. #' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
  103. #' `.remark-slide-content` class.
  104. #' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
  105. #' 0.9em. Modifies the `.remark-slide-number` class.
  106. #' @param text_font_google Use `google_font()` to specify body font. Defaults
  107. #' to `NULL`. Modifies the `body` element.
  108. #' @param text_font_family Body Text Font Family (xaringan default is
  109. #' `'Droid Serif'`). Defaults to Noto Sans. Modifies the `body` element.
  110. #' @param text_font_weight Body Text Font Weight. Defaults to normal. Modifies
  111. #' the `body` element.
  112. #' @param text_font_url Body Text Font URL(s). Defaults to
  113. #' https://fonts.googleapis.com/css?family=Noto+Sans:400,400i,700,700i&display=swap.
  114. #' Modifies the `@import url()` elements.
  115. #' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
  116. #' -apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue,
  117. #' helvetica, Ubuntu, roboto, noto, segoe ui, arial. Modifies the `body`
  118. #' element.
  119. #' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
  120. #' to sans-serif. Modifies the `body` element.
  121. #' @param header_font_google Use `google_font()` to specify header font.
  122. #' Defaults to `NULL`. Modifies the `body` element.
  123. #' @param header_font_family Header Font Family (xaringan default is
  124. #' `'Yanone Kaffeesatz'`). Defaults to Cabin. Modifies the `h1, h2, h3`
  125. #' elements.
  126. #' @param header_font_weight Header Font Weight. Defaults to 600. Modifies the
  127. #' `h1, h2, h3` elements.
  128. #' @param header_font_url Header Font URL. Defaults to
  129. #' https://fonts.googleapis.com/css?family=Cabin:600,600i&display=swap.
  130. #' Modifies the `@import url` elements.
  131. #' @param code_font_google Use `google_font()` to specify code font. Defaults
  132. #' to `NULL`. Modifies the `body` element.
  133. #' @param code_font_family Code Font Family. Defaults to Source Code Pro.
  134. #' Modifies the `.remark-code, .remark-inline-code` classes.
  135. #' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
  136. #' `.remark-inline` class.
  137. #' @param code_font_url Code Font URL. Defaults to
  138. #' https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700&display=swap.
  139. #' Modifies the `@import url` elements.
  140. #' @param code_font_family_fallback Code Font Fallback. Defaults to Menlo,
  141. #' Consolas, Monaco, Liberation Mono, Lucida Console. Modifies the
  142. #' `.remark-code, .remark-inline-code` classes.
  143. #' @template theme_params
  144. #' @template style_xaringan
  145. #' @export
  146. style_xaringan <- function(
  147. text_color = "#000",
  148. header_color = "#000",
  149. background_color = "#FFF",
  150. link_color = "rgb(249, 38, 114)",
  151. text_bold_color = NULL,
  152. text_slide_number_color = inverse_background_color,
  153. padding = "16px 64px 16px 64px",
  154. background_image = NULL,
  155. background_size = NULL,
  156. background_position = NULL,
  157. code_highlight_color = "rgba(255,255,0,0.5)",
  158. code_inline_color = "#000",
  159. code_inline_background_color = NULL,
  160. code_inline_font_size = "1em",
  161. inverse_background_color = "#272822",
  162. inverse_text_color = "#d6d6d6",
  163. inverse_text_shadow = FALSE,
  164. inverse_header_color = "#f3f3f3",
  165. title_slide_text_color = inverse_text_color,
  166. title_slide_background_color = inverse_background_color,
  167. title_slide_background_image = NULL,
  168. title_slide_background_size = NULL,
  169. title_slide_background_position = NULL,
  170. footnote_color = NULL,
  171. footnote_font_size = "0.9em",
  172. footnote_position_bottom = "60px",
  173. left_column_subtle_color = "#777",
  174. left_column_selected_color = "#000",
  175. blockquote_left_border_color = "lightgray",
  176. table_border_color = "#666",
  177. table_row_border_color = "#ddd",
  178. table_row_even_background_color = "#eee",
  179. base_font_size = "20px",
  180. text_font_size = "1rem",
  181. header_h1_font_size = "2.75rem",
  182. header_h2_font_size = "2.25rem",
  183. header_h3_font_size = "1.75rem",
  184. header_background_auto = FALSE,
  185. header_background_color = header_color,
  186. header_background_text_color = background_color,
  187. header_background_padding = NULL,
  188. header_background_content_padding_top = "7rem",
  189. header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
  190. text_slide_number_font_size = "0.9em",
  191. text_font_google = NULL,
  192. text_font_family = "Noto Sans",
  193. text_font_weight = "normal",
  194. text_font_url = "https://fonts.googleapis.com/css?family=Noto+Sans:400,400i,700,700i&display=swap",
  195. text_font_family_fallback = "-apple-system, BlinkMacSystemFont, avenir next, avenir, helvetica neue, helvetica, Ubuntu, roboto, noto, segoe ui, arial",
  196. text_font_base = "sans-serif",
  197. header_font_google = NULL,
  198. header_font_family = "Cabin",
  199. header_font_weight = "600",
  200. header_font_url = "https://fonts.googleapis.com/css?family=Cabin:600,600i&display=swap",
  201. code_font_google = NULL,
  202. code_font_family = "Source Code Pro",
  203. code_font_size = "0.9rem",
  204. code_font_url = "https://fonts.googleapis.com/css?family=Source+Code+Pro:400,700&display=swap",
  205. code_font_family_fallback = "Menlo, Consolas, Monaco, Liberation Mono, Lucida Console",
  206. colors = NULL,
  207. extra_css = NULL,
  208. extra_fonts = NULL,
  209. outfile = "xaringan-themer.css"
  210. ) {
  211. # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
  212. # Make sure font names are wrapped in quotes if they have spaces
  213. f_args <- names(formals(sys.function()))
  214. for (var in f_args[grepl("font_family$", f_args)]) {
  215. var_value <- get(var, inherits = FALSE)
  216. if (!is.null(var_value)) {
  217. eval(parse(text = paste0(var, "<-quote_elements_w_spaces(", var, ")")))
  218. }
  219. # set an is_google flag default of FALSE that is possibly overwritten later
  220. eval(parse(text = paste0(sub("font_family$", "font_is_google", var), "<-0")))
  221. }
  222. # Warn if base_font_size isn't absolute
  223. css_abs_units <- c("cm", "mm", "Q", "in", "pc", "pt", "px")
  224. if (!grepl(paste(tolower(css_abs_units), collapse = "|"), tolower(base_font_size))) {
  225. warning(
  226. glue::glue(
  227. "Base font size '{base_font_size}' is not in absolute units. ",
  228. "For best results, specify the `base_font_size` using absolute CSS units: ",
  229. "{paste(css_abs_units, collapse = ', ')}"
  230. ),
  231. call. = FALSE,
  232. immediate. = TRUE
  233. )
  234. }
  235. # Use font_..._google args to overwrite font args
  236. for (var in f_args[grepl("font_google$", f_args)]) {
  237. gf <- eval(parse(text = var))
  238. if (is.null(gf)) next
  239. if (!inherits(gf, "google_font")) {
  240. stop("`", var, "` must be set using `google_font()`.")
  241. }
  242. group <- strsplit(var, "_")[[1]][1]
  243. if (group == "text") {
  244. text_font_family <- quote_elements_w_spaces(gf$family)
  245. text_font_weight <- gf$weights %||% "normal"
  246. text_font_weight <- substr(text_font_weight, 1, regexpr(",", text_font_weight)[1] - 1)
  247. text_font_url <- gf$url
  248. } else {
  249. eval(parse(text = paste0(group, "_font_family <- quote_elements_w_spaces(gf$family)")))
  250. eval(parse(text = paste0(group, "_font_url <- gf$url")))
  251. }
  252. eval(parse(text = paste0(group, "_font_is_google <- 1")))
  253. }
  254. is_default <- function(type, suffix, reference = style_xaringan) {
  255. var <- paste0(type, "_", suffix)
  256. default_value <- formals(reference)[[var]]
  257. if (suffix == "font_family") {
  258. default_value <- quote_elements_w_spaces(default_value)
  259. }
  260. get(var, envir = parent.frame(2), inherits = FALSE) == default_value
  261. }
  262. # the defaults are google fonts
  263. for (var in c("text", "header", "code")) {
  264. suffixes <- c("font_family", "font_weight", "font_url")
  265. if (var == "code") suffixes <- setdiff(suffixes, "font_weight")
  266. var_is_google <- all(vapply(suffixes, is_default, logical(1), type = var))
  267. if (var_is_google) {
  268. eval(parse(text = paste0(var, "_font_is_google <- 1")))
  269. }
  270. }
  271. extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts)
  272. extra_font_imports <- paste(extra_font_imports, collapse = "\n")
  273. # convert NA arguments to NULL
  274. for (var in f_args) {
  275. val <- eval(parse(text = var))
  276. if (is.null(val)) next
  277. val <- val[!is.na(val)]
  278. is_na <- length(val) == 0
  279. if (is_na) assign(var, NULL)
  280. }
  281. # prepare variables for template
  282. body_font_family <- paste(c(text_font_family, text_font_family_fallback, text_font_base), collapse = ", ")
  283. background_size_fallback <- if (is.null(background_position)) "cover" else "100%"
  284. background_size <- background_image %??% (background_size %||% background_size_fallback)
  285. title_slide_background_size <- title_slide_background_size %||% (
  286. title_slide_background_image %??% "cover"
  287. )
  288. table_row_even_background_color <- table_row_even_background_color %||% background_color
  289. # stash theme settings in package env
  290. lapply(f_args, function(n) assign(n, get(n), envir = xaringanthemer_env))
  291. for (font_is_google in paste0(c("text", "code", "header"), "_font_is_google")) {
  292. assign(
  293. font_is_google,
  294. get(font_is_google, inherits = FALSE) == 1,
  295. envir = xaringanthemer_env
  296. )
  297. }
  298. xaringanthemer_version <- utils::packageVersion("xaringanthemer")
  299. # prepare header background object
  300. needs_leading_dot <- !grepl("^\\.", header_background_ignore_classes)
  301. header_background_ignore_classes[needs_leading_dot] <- paste0(
  302. ".",
  303. header_background_ignore_classes[needs_leading_dot]
  304. )
  305. header_background_ignore_classes <- purrr::map(
  306. header_background_ignore_classes,
  307. ~ list(class = .)
  308. )
  309. if (is.null(header_background_padding)) {
  310. slide_padding <- css_get_padding(padding)
  311. header_background_padding <- paste(
  312. "2rem", slide_padding$right, "1.5rem", slide_padding$left
  313. )
  314. }
  315. header_background <- list(
  316. auto = header_background_auto,
  317. background_color = header_background_color,
  318. text_color = header_background_text_color,
  319. padding = header_background_padding,
  320. content_padding_top = header_background_content_padding_top,
  321. ignore = header_background_ignore_classes
  322. )
  323. colors <- prepare_colors(colors)
  324. tf <- system.file("resources", "template.css", package = "xaringanthemer")
  325. template <- readLines(tf, warn = FALSE)
  326. template <- paste(template, collapse = "\n")
  327. x <- whisker::whisker.render(template)
  328. if (!is.null(extra_css)) {
  329. x <- c(x, style_extra_css(extra_css, outfile = NULL))
  330. }
  331. if (is.null(outfile)) {
  332. return(x)
  333. }
  334. writeLines(x, con = outfile)
  335. invisible(outfile)
  336. }