constants.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. export enum HeadingElementTypes {
  21. HeadingOne = 'heading-one',
  22. HeadingTwo = 'heading-two',
  23. HeadingThree = 'heading-three',
  24. HeadingFour = 'heading-four',
  25. HeadingFive = 'heading-five',
  26. HeadingSix = 'heading-six',
  27. HeadingNone = 'heading-none'
  28. }
  29. export enum ListElementTypes {
  30. BulletedList = 'bulleted-list',
  31. NumberedList = 'numbered-list',
  32. ListItem = 'list-item'
  33. }
  34. export enum MediaElementTypes {
  35. Image = 'image'
  36. }
  37. export enum AnimationElementTypes {
  38. Marquee = 'marquee'
  39. }
  40. export enum TableElementTypes {
  41. Table = 'table',
  42. TableRow = 'table-row',
  43. TableCell = 'table-cell'
  44. }
  45. export enum BaseElementTypes {
  46. Paragraph = 'paragraph',
  47. Code = 'code',
  48. BlockQuote = 'block-quote',
  49. Link = 'link'
  50. }
  51. export const ElementTypes = {
  52. ...BaseElementTypes,
  53. ...HeadingElementTypes,
  54. ...MediaElementTypes,
  55. ...AnimationElementTypes,
  56. ...TableElementTypes,
  57. ...ListElementTypes
  58. }
  59. export type ElementType =
  60. | BaseElementTypes
  61. | HeadingElementTypes
  62. | MediaElementTypes
  63. | AnimationElementTypes
  64. | TableElementTypes
  65. | ListElementTypes
  66. export enum TextStyles {
  67. Bold = 'bold',
  68. Italic = 'italic',
  69. Underline = 'underline',
  70. StrikeThrough = 'strike-through',
  71. Code = 'code'
  72. }
  73. export enum BlockAlignments {
  74. AlignLeft = 'left',
  75. AlignCenter = 'center',
  76. AlignRight = 'right'
  77. }
  78. export enum BlockProperties {
  79. TextAlign = 'textAlign'
  80. }
  81. export enum TextProperties {
  82. FontFamily = 'fontFamily',
  83. FontSize = 'fontSize',
  84. Color = 'color',
  85. BackgroundColor = 'backgroundColor'
  86. }
  87. export const ElementTags: {
  88. [key: string]: (
  89. el: HTMLElement
  90. ) => {
  91. type: ElementType
  92. url?: string
  93. textAlign?: string
  94. }
  95. } = {
  96. A: (el) => ({ type: ElementTypes.Link, url: el.getAttribute('href') }),
  97. BLOCKQUOTE: () => ({ type: ElementTypes.BlockQuote }),
  98. H1: () => ({ type: ElementTypes.HeadingOne }),
  99. H2: () => ({ type: ElementTypes.HeadingTwo }),
  100. H3: () => ({ type: ElementTypes.HeadingThree }),
  101. H4: () => ({ type: ElementTypes.HeadingFour }),
  102. H5: () => ({ type: ElementTypes.HeadingFive }),
  103. H6: () => ({ type: ElementTypes.HeadingSix }),
  104. IMG: (el) => ({
  105. type: ElementTypes.Image,
  106. url: el.getAttribute('src'),
  107. width: el.getAttribute('width')
  108. }),
  109. LI: () => ({ type: ElementTypes.ListItem }),
  110. OL: () => ({ type: ElementTypes.NumberedList }),
  111. UL: () => ({ type: ElementTypes.BulletedList }),
  112. P: () => {
  113. return { type: ElementTypes.Paragraph }
  114. },
  115. PRE: () => ({ type: ElementTypes.Code }),
  116. TABLE: () => ({ type: ElementTypes.Table }),
  117. TR: () => ({ type: ElementTypes.TableRow }),
  118. TD: () => ({ type: ElementTypes.TableCell })
  119. }
  120. export const TextTags: {
  121. [key: string]: () => { [key in TextStyles]?: boolean } & {
  122. fontSize?: number
  123. color?: string
  124. backgroundColor?: string
  125. }
  126. } = {
  127. CODE: () => ({ [TextStyles.Code]: true }),
  128. DEL: () => ({ [TextStyles.StrikeThrough]: true }),
  129. EM: () => ({ [TextStyles.Italic]: true }),
  130. I: () => ({ [TextStyles.Italic]: true }),
  131. S: () => ({ [TextStyles.StrikeThrough]: true }),
  132. STRONG: () => ({ [TextStyles.Bold]: true }),
  133. U: () => ({ [TextStyles.Underline]: true }),
  134. SPAN: () => ({})
  135. }