configuration/DefaultTheme.js

  1. import JsonCSS from 'json-css'
  2. import merge from 'lodash.merge'
  3. import { editorLogger as logger } from './LoggerConfig'
  4. /**
  5. * @typedef {PenStyle} InkTheme
  6. */
  7. /**
  8. * @typedef {Object} MathTheme
  9. * @property {String} font-family=STIXGeneral Font-family to be used
  10. */
  11. /**
  12. * @typedef {Object} GeneratedTheme
  13. * @property {String} font-family=STIXGeneral Font-family to be used
  14. * @property {String} color=#A8A8A8FF Color to be used
  15. */
  16. /**
  17. * @typedef {Object} TextTheme
  18. * @property {String} font-family=OpenSans Font-family to be used
  19. * @property {Number} font-size=10 Font-size to be used
  20. */
  21. /**
  22. * @typedef {Object} Theme
  23. * @property {InkTheme} ink General settings
  24. * @property {MathTheme} .math Math theme
  25. * @property {GeneratedTheme} .math-solver Theme to be used for generated items
  26. * @property {TextTheme} .text Text theme
  27. */
  28. /**
  29. * Default theme
  30. * @type {Theme}
  31. */
  32. const defaultTheme = {
  33. ink: {
  34. color: '#000000',
  35. '-myscript-pen-width': 1,
  36. '-myscript-pen-fill-style': 'none',
  37. '-myscript-pen-fill-color': '#FFFFFF00'
  38. },
  39. '.math': {
  40. 'font-family': 'STIXGeneral'
  41. },
  42. '.math-solved': {
  43. 'font-family': 'STIXGeneral',
  44. color: '#A8A8A8FF'
  45. },
  46. '.text': {
  47. 'font-family': 'MyScriptInter',
  48. 'font-size': 10
  49. }
  50. }
  51. const parser = new JsonCSS()
  52. /**
  53. * Generate theme
  54. * @param {Theme} theme Custom theme to be applied
  55. * @return {Theme} Overridden theme
  56. */
  57. export function overrideDefaultTheme (theme) {
  58. const currentTheme = merge({}, defaultTheme, theme === undefined ? {} : theme)
  59. logger.debug('Override default theme', currentTheme)
  60. return currentTheme
  61. }
  62. export function toCSS (theme) {
  63. return parser.toCSS(theme)
  64. }
  65. export function toJSON (theme) {
  66. return parser.toJSON(theme)
  67. }
  68. export default defaultTheme