😎 Give your xaringan slides some style
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

419 lines
21KB

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