😎 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.

510 line
25KB

  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. #' The value of this variable is also stored as a CSS variable that can be
  4. #' referenced with `var(--text_color)` in any argument of a style function or
  5. #' in custom CSS.
  6. #' @param header_color Header Color. Defaults to #000. Modifies the
  7. #' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
  8. #' variable that can be referenced with `var(--header-color)` in any argument
  9. #' of a style function or in custom CSS.
  10. #' @param background_color Slide Background Color. Defaults to #FFF. Modifies
  11. #' the `.remark-slide-content` class. The value of this variable is also
  12. #' stored as a CSS variable that can be referenced with
  13. #' `var(--background-color)` in any argument of a style function or in custom
  14. #' CSS.
  15. #' @param link_color Link Color. Defaults to rgb(249, 38, 114). Modifies the
  16. #' `a, a > code` elements. The value of this variable is also stored as a CSS
  17. #' variable that can be referenced with `var(--link-color)` in any argument
  18. #' of a style function or in custom CSS.
  19. #' @param text_bold_color Bold Text Color. Defaults to `NULL`. Modifies the
  20. #' `strong` element. The value of this variable is also stored as a CSS
  21. #' variable that can be referenced with `var(--text-bold-color)` in any
  22. #' argument of a style function or in custom CSS.
  23. #' @param text_slide_number_color Slide Number Color. Defaults to
  24. #' `inverse_background_color`. Modifies the `.remark-slide-number` class.
  25. #' @param padding Slide Padding in `top right [bottom left]` format. Defaults
  26. #' to 16px 64px 16px 64px. Modifies the `.remark-slide-content` class.
  27. #' Accepts CSS
  28. #' [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
  29. #' property values.
  30. #' @param background_image Background image applied to each *and every* slide.
  31. #' Set `title_slide_background_image = "none"` to remove the background image
  32. #' from the title slide. Defaults to `NULL`. Modifies the
  33. #' `.remark-slide-content` class.
  34. #' @param background_size Background image size, requires `background_image` to
  35. #' be set. If `background_image` is set, `background_size` will default to
  36. #' `cover` so the background fills the screen. If both `background_image` and
  37. #' `background_position` are set, will default to 100 percent. Defaults to
  38. #' `NULL`. Modifies the `.remark-slide-content` class. Accepts CSS
  39. #' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
  40. #' property values.
  41. #' @param background_position Background image position, requires
  42. #' `background_image` to be set, and it is recommended to adjust
  43. #' `background_size`. Defaults to `NULL`. Modifies the
  44. #' `.remark-slide-content` class. Accepts CSS
  45. #' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
  46. #' property values.
  47. #' @param code_highlight_color Code Line Highlight. Defaults to
  48. #' rgba(255,255,0,0.5). Modifies the `.remark-code-line-highlighted` class.
  49. #' The value of this variable is also stored as a CSS variable that can be
  50. #' referenced with `var(--code-highlight-color)` in any argument of a style
  51. #' function or in custom CSS.
  52. #' @param code_inline_color Inline Code Color. Defaults to #000. Modifies the
  53. #' `.remark-inline-code` class.
  54. #' @param code_inline_background_color Inline Code Background Color. Defaults
  55. #' to `NULL`. Modifies the `.remark-inline-code` class.
  56. #' @param code_inline_font_size Inline Code Text Font Size. Defaults to 1em.
  57. #' Modifies the `.remark-inline-code` class. Accepts CSS
  58. #' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
  59. #' property values. The value of this variable is also stored as a CSS
  60. #' variable that can be referenced with `var(--code-inline-font-size)` in any
  61. #' argument of a style function or in custom CSS.
  62. #' @param inverse_background_color Inverse Background Color. Defaults to
  63. #' #272822. Modifies the `.inverse` class. The value of this variable is also
  64. #' stored as a CSS variable that can be referenced with
  65. #' `var(--inverse-background-color)` in any argument of a style function or
  66. #' in custom CSS.
  67. #' @param inverse_text_color Inverse Text Color. Defaults to #d6d6d6. Modifies
  68. #' the `.inverse` class. The value of this variable is also stored as a CSS
  69. #' variable that can be referenced with `var(--inverse-text-color)` in any
  70. #' argument of a style function or in custom CSS.
  71. #' @param inverse_text_shadow Enables Shadow on text of inverse slides.
  72. #' Defaults to `FALSE`. Modifies the `.inverse` class.
  73. #' @param inverse_header_color Inverse Header Color. Defaults to #f3f3f3.
  74. #' Modifies the `.inverse h1, .inverse h2, .inverse h3` classes. The value of
  75. #' this variable is also stored as a CSS variable that can be referenced with
  76. #' `var(--inverse-header-color)` in any argument of a style function or in
  77. #' custom CSS.
  78. #' @param inverse_link_color Inverse Link Color. Defaults to `link_color`.
  79. #' Modifies the `.inverse a, .inverse a > code` classes. The value of this
  80. #' variable is also stored as a CSS variable that can be referenced with
  81. #' `var(--inverse-link-color)` in any argument of a style function or in
  82. #' custom CSS.
  83. #' @param title_slide_text_color Title Slide Text Color. Defaults to
  84. #' `inverse_text_color`. Modifies the `.title-slide` class. The value of this
  85. #' variable is also stored as a CSS variable that can be referenced with
  86. #' `var(--title-slide-text-color)` in any argument of a style function or in
  87. #' custom CSS.
  88. #' @param title_slide_background_color Title Slide Background Color. Defaults
  89. #' to `inverse_background_color`. Modifies the `.title-slide` class. The
  90. #' value of this variable is also stored as a CSS variable that can be
  91. #' referenced with `var(--title-slide-background-color)` in any argument of a
  92. #' style function or in custom CSS.
  93. #' @param title_slide_background_image Title Slide Background Image URL.
  94. #' Defaults to `NULL`. Modifies the `.title-slide` class.
  95. #' @param title_slide_background_size Title Slide Background Image Size,
  96. #' defaults to "cover" if background image is set. Defaults to `NULL`.
  97. #' Modifies the `.title-slide` class. Accepts CSS
  98. #' [background-size](https://developer.mozilla.org/en-US/docs/Web/CSS/background-size)
  99. #' property values.
  100. #' @param title_slide_background_position Title Slide Background Image
  101. #' Position. Defaults to `NULL`. Modifies the `.title-slide` class. Accepts
  102. #' CSS
  103. #' [background-position](https://developer.mozilla.org/en-US/docs/Web/CSS/background-position)
  104. #' property values.
  105. #' @param footnote_color Footnote text color (if `NA`, then it will be the same
  106. #' color as `text_color`). Defaults to `NULL`. Modifies the `.footnote`
  107. #' class.
  108. #' @param footnote_font_size Footnote font size. Defaults to 0.9em. Modifies
  109. #' the `.footnote` class. Accepts CSS
  110. #' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
  111. #' property values.
  112. #' @param footnote_position_bottom Footnote location from bottom of screen.
  113. #' Defaults to 60px. Modifies the `.footnote` class. Accepts CSS
  114. #' [position](https://developer.mozilla.org/en-US/docs/Web/CSS/position_value)
  115. #' property values.
  116. #' @param left_column_subtle_color Left Column Text (not last). Defaults to
  117. #' #777. Modifies the `.left-column h2, .left-column h3` classes.
  118. #' @param left_column_selected_color Left Column Current Selection. Defaults to
  119. #' #000. Modifies the
  120. #' `.left-column h2:last-of-type, .left-column h3:last-child` classes.
  121. #' @param blockquote_left_border_color Blockquote Left Border Color. Defaults
  122. #' to lightgray. Modifies the `blockquote` element.
  123. #' @param table_border_color Table top/bottom border. Defaults to #666.
  124. #' Modifies the `table: border-top, border-bottom` elements.
  125. #' @param table_row_border_color Table row inner bottom border. Defaults to
  126. #' #ddd. Modifies the `table thead th: border-bottom` elements.
  127. #' @param table_row_even_background_color Table Even Row Background Color.
  128. #' Defaults to #eee. Modifies the `thead, tfoot, tr:nth-child(even)`
  129. #' elements.
  130. #' @param base_font_size Base Font Size for All Slide Elements (must be `px`).
  131. #' Defaults to 20px. Modifies the `html` element. The value of this variable
  132. #' is also stored as a CSS variable that can be referenced with
  133. #' `var(--base-font-size)` in any argument of a style function or in custom
  134. #' CSS.
  135. #' @param text_font_size Slide Body Text Font Size. Defaults to 1rem. Modifies
  136. #' the `.remark-slide-content` class. Accepts CSS
  137. #' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
  138. #' property values. The value of this variable is also stored as a CSS
  139. #' variable that can be referenced with `var(--text-font-size)` in any
  140. #' argument of a style function or in custom CSS.
  141. #' @param header_h1_font_size h1 Header Text Font Size. Defaults to 2.75rem.
  142. #' Modifies the `.remark-slide-content h1` class. Accepts CSS
  143. #' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
  144. #' property values. The value of this variable is also stored as a CSS
  145. #' variable that can be referenced with `var(--header-h1-font-size)` in any
  146. #' argument of a style function or in custom CSS.
  147. #' @param header_h2_font_size h2 Header Text Font Size. Defaults to 2.25rem.
  148. #' Modifies the `.remark-slide-content h2` class. Accepts CSS
  149. #' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
  150. #' property values. The value of this variable is also stored as a CSS
  151. #' variable that can be referenced with `var(--header-h2-font-size)` in any
  152. #' argument of a style function or in custom CSS.
  153. #' @param header_h3_font_size h3 Header Text Font Size. Defaults to 1.75rem.
  154. #' Modifies the `.remark-slide-content h3` class. Accepts CSS
  155. #' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
  156. #' property values. The value of this variable is also stored as a CSS
  157. #' variable that can be referenced with `var(--header-h3-font-size)` in any
  158. #' argument of a style function or in custom CSS.
  159. #' @param header_background_auto Add background under slide title automatically
  160. #' for h1 header elements. If not enabled, use `class: header_background` to
  161. #' enable. Defaults to `FALSE`.
  162. #' @param header_background_color Background Color for h1 Header with
  163. #' Background. Defaults to `header_color`. Modifies the
  164. #' `.remark-slide-content h1` class. The value of this variable is also
  165. #' stored as a CSS variable that can be referenced with
  166. #' `var(--header-background-color)` in any argument of a style function or in
  167. #' custom CSS.
  168. #' @param header_background_text_color Text Color for h1 Header with
  169. #' Background. Defaults to `background_color`. Modifies the
  170. #' `.remark-slide-content h1` class. The value of this variable is also
  171. #' stored as a CSS variable that can be referenced with
  172. #' `var(--header-background-text-color)` in any argument of a style function
  173. #' or in custom CSS.
  174. #' @param header_background_padding Padding for h1 Header with Background.
  175. #' Defaults to `NULL`. Modifies the `.remark-slide-content h1` class. Accepts
  176. #' CSS [padding](https://developer.mozilla.org/en-US/docs/Web/CSS/padding)
  177. #' property values.
  178. #' @param header_background_content_padding_top Top Padding for Content in
  179. #' Slide with Header with Background. Defaults to 7rem. Modifies the
  180. #' `.remark-slide-content` class.
  181. #' @param header_background_ignore_classes Slide Classes Where Header with
  182. #' Background will not be Applied. Defaults to
  183. #' `c('normal', 'inverse', 'title', 'middle', 'bottom')`. Modifies the
  184. #' `.remark-slide-content` class.
  185. #' @param text_slide_number_font_size Slide Number Text Font Size. Defaults to
  186. #' 0.9rem. Modifies the `.remark-slide-number` class. Accepts CSS
  187. #' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
  188. #' property values.
  189. #' @param text_font_google Use `google_font()` to specify body font. Defaults
  190. #' to `NULL`. Modifies the `body` element.
  191. #' @param text_font_family Body Text Font Family (xaringan default is
  192. #' `'Droid Serif'`). Defaults to
  193. #' `xaringanthemer_font_default("text_font_family")`. Modifies the `body`
  194. #' element. The value of this variable is also stored as a CSS variable that
  195. #' can be referenced with `var(--text-font-family)` in any argument of a
  196. #' style function or in custom CSS.
  197. #' @param text_font_weight Body Text Font Weight. Defaults to
  198. #' `xaringanthemer_font_default("text_font_weight")`. Modifies the `body`
  199. #' element. Accepts CSS
  200. #' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
  201. #' property values.
  202. #' @param text_bold_font_weight Body Bold Text Font Weight. Defaults to bold.
  203. #' Modifies the `strong` element.
  204. #' @param text_font_url Body Text Font URL(s). Defaults to
  205. #' `xaringanthemer_font_default("text_font_url")`. Modifies the
  206. #' `@import url()` elements.
  207. #' @param text_font_family_fallback Body Text Font Fallbacks. Defaults to
  208. #' `xaringanthemer_font_default("text_font_family_fallback")`. Modifies the
  209. #' `body` element. The value of this variable is also stored as a CSS
  210. #' variable that can be referenced with `var(--text-font-family-fallback)` in
  211. #' any argument of a style function or in custom CSS.
  212. #' @param text_font_base Body Text Base Font (Total Failure Fallback). Defaults
  213. #' to sans-serif. Modifies the `body` element. The value of this variable is
  214. #' also stored as a CSS variable that can be referenced with
  215. #' `var(--text-font-base)` in any argument of a style function or in custom
  216. #' CSS.
  217. #' @param header_font_google Use `google_font()` to specify header font.
  218. #' Defaults to `NULL`. Modifies the `body` element.
  219. #' @param header_font_family Header Font Family (xaringan default is
  220. #' `'Yanone Kaffeesatz'`). Defaults to
  221. #' `xaringanthemer_font_default("header_font_family")`. Modifies the
  222. #' `h1, h2, h3` elements. The value of this variable is also stored as a CSS
  223. #' variable that can be referenced with `var(--header-font-family)` in any
  224. #' argument of a style function or in custom CSS.
  225. #' @param header_font_weight Header Font Weight. Defaults to
  226. #' `xaringanthemer_font_default("header_font_weight")`. Modifies the
  227. #' `h1, h2, h3` elements. Accepts CSS
  228. #' [font-weight](https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight)
  229. #' property values.
  230. #' @param header_font_family_fallback Header Font Family Fallback. Defaults to
  231. #' Georgia, serif. Modifies the `h1, h2, h3` elements. The value of this
  232. #' variable is also stored as a CSS variable that can be referenced with
  233. #' `var(--header-font-family-fallback)` in any argument of a style function
  234. #' or in custom CSS.
  235. #' @param header_font_url Header Font URL. Defaults to
  236. #' `xaringanthemer_font_default("header_font_url")`. Modifies the
  237. #' `@import url` elements.
  238. #' @param code_font_google Use `google_font()` to specify code font. Defaults
  239. #' to `NULL`. Modifies the `body` element.
  240. #' @param code_font_family Code Font Family. Defaults to
  241. #' `xaringanthemer_font_default("code_font_family")`. Modifies the
  242. #' `.remark-code, .remark-inline-code` classes. The value of this variable is
  243. #' also stored as a CSS variable that can be referenced with
  244. #' `var(--code-font-family)` in any argument of a style function or in custom
  245. #' CSS.
  246. #' @param code_font_size Code Text Font Size. Defaults to 0.9rem. Modifies the
  247. #' `.remark-inline` class. Accepts CSS
  248. #' [font-size](https://developer.mozilla.org/en-US/docs/Web/CSS/font-size)
  249. #' property values. The value of this variable is also stored as a CSS
  250. #' variable that can be referenced with `var(--code-font-size)` in any
  251. #' argument of a style function or in custom CSS.
  252. #' @param code_font_url Code Font URL. Defaults to
  253. #' `xaringanthemer_font_default("code_font_url")`. Modifies the `@import url`
  254. #' elements.
  255. #' @param code_font_family_fallback Code Font Fallback. Defaults to
  256. #' `xaringanthemer_font_default("code_font_family_fallback")`. Modifies the
  257. #' `.remark-code, .remark-inline-code` classes.
  258. #' @param link_decoration Text decoration of links. Defaults to none. Modifies
  259. #' the `a, a > code` elements. Accepts CSS
  260. #' [text-decoration](https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration)
  261. #' property values.
  262. #' @template theme_params
  263. #' @template style-usage
  264. #' @template style_xaringan
  265. #' @export
  266. style_xaringan <- function(
  267. text_color = "#000",
  268. header_color = "#000",
  269. background_color = "#FFF",
  270. link_color = "rgb(249, 38, 114)",
  271. text_bold_color = NULL,
  272. text_slide_number_color = inverse_background_color,
  273. padding = "16px 64px 16px 64px",
  274. background_image = NULL,
  275. background_size = NULL,
  276. background_position = NULL,
  277. code_highlight_color = "rgba(255,255,0,0.5)",
  278. code_inline_color = "#000",
  279. code_inline_background_color = NULL,
  280. code_inline_font_size = "1em",
  281. inverse_background_color = "#272822",
  282. inverse_text_color = "#d6d6d6",
  283. inverse_text_shadow = FALSE,
  284. inverse_header_color = "#f3f3f3",
  285. inverse_link_color = link_color,
  286. title_slide_text_color = inverse_text_color,
  287. title_slide_background_color = inverse_background_color,
  288. title_slide_background_image = NULL,
  289. title_slide_background_size = NULL,
  290. title_slide_background_position = NULL,
  291. footnote_color = NULL,
  292. footnote_font_size = "0.9em",
  293. footnote_position_bottom = "60px",
  294. left_column_subtle_color = "#777",
  295. left_column_selected_color = "#000",
  296. blockquote_left_border_color = "lightgray",
  297. table_border_color = "#666",
  298. table_row_border_color = "#ddd",
  299. table_row_even_background_color = "#eee",
  300. base_font_size = "20px",
  301. text_font_size = "1rem",
  302. header_h1_font_size = "2.75rem",
  303. header_h2_font_size = "2.25rem",
  304. header_h3_font_size = "1.75rem",
  305. header_background_auto = FALSE,
  306. header_background_color = header_color,
  307. header_background_text_color = background_color,
  308. header_background_padding = NULL,
  309. header_background_content_padding_top = "7rem",
  310. header_background_ignore_classes = c('normal', 'inverse', 'title', 'middle', 'bottom'),
  311. text_slide_number_font_size = "0.9rem",
  312. text_font_google = NULL,
  313. text_font_family = xaringanthemer_font_default("text_font_family"),
  314. text_font_weight = xaringanthemer_font_default("text_font_weight"),
  315. text_bold_font_weight = "bold",
  316. text_font_url = xaringanthemer_font_default("text_font_url"),
  317. text_font_family_fallback = xaringanthemer_font_default("text_font_family_fallback"),
  318. text_font_base = "sans-serif",
  319. header_font_google = NULL,
  320. header_font_family = xaringanthemer_font_default("header_font_family"),
  321. header_font_weight = xaringanthemer_font_default("header_font_weight"),
  322. header_font_family_fallback = "Georgia, serif",
  323. header_font_url = xaringanthemer_font_default("header_font_url"),
  324. code_font_google = NULL,
  325. code_font_family = xaringanthemer_font_default("code_font_family"),
  326. code_font_size = "0.9rem",
  327. code_font_url = xaringanthemer_font_default("code_font_url"),
  328. code_font_family_fallback = xaringanthemer_font_default("code_font_family_fallback"),
  329. link_decoration = "none",
  330. colors = NULL,
  331. extra_css = NULL,
  332. extra_fonts = NULL,
  333. outfile = "xaringan-themer.css"
  334. ) {
  335. # DO NOT EDIT - Generated from inst/scripts/generate_theme_functions.R
  336. force(text_font_family)
  337. force(text_font_weight)
  338. force(text_font_url)
  339. force(text_font_family_fallback)
  340. force(header_font_family)
  341. force(header_font_weight)
  342. force(header_font_url)
  343. force(code_font_family)
  344. force(code_font_url)
  345. force(code_font_family_fallback)
  346. # the defaults are google fonts
  347. is_default <- function(type, suffix) {
  348. # check if font arg value is from xaringanthemer_font_default
  349. var <- paste0(type, "_", suffix)
  350. inherits(
  351. get(var, envir = parent.frame(2), inherits = FALSE),
  352. "xaringanthemer_default"
  353. )
  354. }
  355. for (var in c("text", "header", "code")) {
  356. suffixes <- c("font_family", "font_weight", "font_url")
  357. if (var == "code") suffixes <- setdiff(suffixes, "font_weight")
  358. var_is_google <- all(vapply(suffixes, is_default, logical(1), type = var))
  359. var_is_google <- as.integer(var_is_google)
  360. r_set_font_is_google <- glue::glue("{var}_font_is_google <- {var_is_google}")
  361. eval(parse(text = r_set_font_is_google))
  362. }
  363. # Make sure font names are wrapped in quotes if they have spaces
  364. f_args <- names(formals(sys.function()))
  365. for (var in f_args[grepl("font_family$", f_args)]) {
  366. var_value <- get(var, inherits = FALSE)
  367. if (!is.null(var_value)) {
  368. eval(parse(text = paste0(var, "<-quote_elements_w_spaces(", var, ")")))
  369. }
  370. }
  371. # Warn if base_font_size isn't absolute
  372. css_abs_units <- c("cm", "mm", "Q", "in", "pc", "pt", "px")
  373. if (!grepl(paste(tolower(css_abs_units), collapse = "|"), tolower(base_font_size))) {
  374. warning(
  375. glue::glue(
  376. "Base font size '{base_font_size}' is not in absolute units. ",
  377. "For best results, specify the `base_font_size` using absolute CSS units: ",
  378. "{paste(css_abs_units, collapse = ', ')}"
  379. ),
  380. call. = FALSE,
  381. immediate. = TRUE
  382. )
  383. }
  384. # If certain colors aren't in hexadecimal it may cause problems with theme_xaringan()
  385. # TODO: at some point I'd rather be able to process CSS colors or variables
  386. colors_used_by_theme_xaringan <- list(
  387. background_color = background_color,
  388. text_color = text_color,
  389. header_color = header_color,
  390. text_bold_color = text_bold_color,
  391. inverse_background_color = inverse_background_color,
  392. inverse_text_color = inverse_text_color,
  393. inverse_header_color = inverse_header_color
  394. )
  395. colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null)
  396. colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL)
  397. if (any(!colors_are_hex)) {
  398. colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex]
  399. colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ")
  400. warning(
  401. glue::glue("Colors that will be used by `theme_xaringan()` need to be in ",
  402. "hexadecimal format: {colors_better_as_hex}"),
  403. immediate. = TRUE,
  404. call. = FALSE
  405. )
  406. }
  407. # Use font_..._google args to overwrite font args
  408. for (var in f_args[grepl("font_google$", f_args)]) {
  409. gf <- eval(parse(text = var))
  410. if (is.null(gf)) next
  411. if (!inherits(gf, "google_font")) {
  412. stop("`", var, "` must be set using `google_font()`.")
  413. }
  414. group <- strsplit(var, "_")[[1]][1]
  415. if (group == "text") {
  416. text_font_family <- quote_elements_w_spaces(gf$family)
  417. text_font_weight <- gf$weights %||% "normal"
  418. if (grepl(",", text_font_weight)) {
  419. # Use first font weight if multiple are imported
  420. text_font_weight <- substr(text_font_weight, 1, regexpr(",", text_font_weight)[1] - 1)
  421. }
  422. text_font_url <- gf$url
  423. } else {
  424. eval(parse(text = paste0(group, "_font_family <- quote_elements_w_spaces(gf$family)")))
  425. eval(parse(text = paste0(group, "_font_url <- gf$url")))
  426. }
  427. eval(parse(text = paste0(group, "_font_is_google <- 1")))
  428. }
  429. extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts)
  430. extra_font_imports <- paste(extra_font_imports, collapse = "\n")
  431. # convert NA arguments to NULL
  432. for (var in f_args) {
  433. val <- eval(parse(text = var))
  434. if (is.null(val)) next
  435. val <- val[!is.na(val)]
  436. is_na <- length(val) == 0
  437. if (is_na) assign(var, NULL, envir = sys.frame(sys.nframe()))
  438. }
  439. # prepare variables for template
  440. body_font_family <- paste(c(text_font_family, text_font_family_fallback, text_font_base), collapse = ", ")
  441. background_size_fallback <- if (is.null(background_position)) "cover" else "100%"
  442. background_size <- background_image %??% (background_size %||% background_size_fallback)
  443. title_slide_background_size <- title_slide_background_size %||% (
  444. title_slide_background_image %??% "cover"
  445. )
  446. table_row_even_background_color <- table_row_even_background_color %||% background_color
  447. # stash theme settings in package env
  448. lapply(f_args, function(n) assign(n, get(n), envir = xaringanthemer_env))
  449. for (font_is_google in paste0(c("text", "code", "header"), "_font_is_google")) {
  450. assign(
  451. font_is_google,
  452. get(font_is_google, inherits = FALSE) == 1,
  453. envir = xaringanthemer_env
  454. )
  455. }
  456. xaringanthemer_version <- utils::packageVersion("xaringanthemer")
  457. # prepare header background object
  458. needs_leading_dot <- !grepl("^\\.", header_background_ignore_classes)
  459. header_background_ignore_classes[needs_leading_dot] <- paste0(
  460. ".",
  461. header_background_ignore_classes[needs_leading_dot]
  462. )
  463. header_background_ignore_classes <- purrr::map(
  464. header_background_ignore_classes,
  465. ~ list(class = .)
  466. )
  467. if (is.null(header_background_padding)) {
  468. slide_padding <- css_get_padding(padding)
  469. header_background_padding <- paste(
  470. "2rem", slide_padding$right, "1.5rem", slide_padding$left
  471. )
  472. }
  473. header_background <- list(
  474. auto = header_background_auto,
  475. background_color = header_background_color,
  476. text_color = header_background_text_color,
  477. padding = header_background_padding,
  478. content_padding_top = header_background_content_padding_top,
  479. ignore = header_background_ignore_classes
  480. )
  481. colors <- prepare_colors(colors)
  482. tf <- system.file("resources", "template.css", package = "xaringanthemer")
  483. template <- readLines(tf, warn = FALSE)
  484. template <- paste(template, collapse = "\n")
  485. x <- whisker::whisker.render(template)
  486. if (!is.null(extra_css)) {
  487. x <- c(x, style_extra_css(extra_css, outfile = NULL))
  488. }
  489. if (is.null(outfile)) {
  490. return(x)
  491. }
  492. writeLines(x, con = outfile)
  493. invisible(outfile)
  494. }