css.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/css/css.ts
  8. var conf = {
  9. wordPattern: /(#?-?\d*\.\d\w*%?)|((::|[@#.!:])?[\w-?]+%?)|::|[@#.!:]/g,
  10. comments: {
  11. blockComment: ["/*", "*/"]
  12. },
  13. brackets: [
  14. ["{", "}"],
  15. ["[", "]"],
  16. ["(", ")"]
  17. ],
  18. autoClosingPairs: [
  19. { open: "{", close: "}", notIn: ["string", "comment"] },
  20. { open: "[", close: "]", notIn: ["string", "comment"] },
  21. { open: "(", close: ")", notIn: ["string", "comment"] },
  22. { open: '"', close: '"', notIn: ["string", "comment"] },
  23. { open: "'", close: "'", notIn: ["string", "comment"] }
  24. ],
  25. surroundingPairs: [
  26. { open: "{", close: "}" },
  27. { open: "[", close: "]" },
  28. { open: "(", close: ")" },
  29. { open: '"', close: '"' },
  30. { open: "'", close: "'" }
  31. ],
  32. folding: {
  33. markers: {
  34. start: new RegExp("^\\s*\\/\\*\\s*#region\\b\\s*(.*?)\\s*\\*\\/"),
  35. end: new RegExp("^\\s*\\/\\*\\s*#endregion\\b.*\\*\\/")
  36. }
  37. }
  38. };
  39. var language = {
  40. defaultToken: "",
  41. tokenPostfix: ".css",
  42. ws: "[ \n\r\f]*",
  43. identifier: "-?-?([a-zA-Z]|(\\\\(([0-9a-fA-F]{1,6}\\s?)|[^[0-9a-fA-F])))([\\w\\-]|(\\\\(([0-9a-fA-F]{1,6}\\s?)|[^[0-9a-fA-F])))*",
  44. brackets: [
  45. { open: "{", close: "}", token: "delimiter.bracket" },
  46. { open: "[", close: "]", token: "delimiter.bracket" },
  47. { open: "(", close: ")", token: "delimiter.parenthesis" },
  48. { open: "<", close: ">", token: "delimiter.angle" }
  49. ],
  50. tokenizer: {
  51. root: [{ include: "@selector" }],
  52. selector: [
  53. { include: "@comments" },
  54. { include: "@import" },
  55. { include: "@strings" },
  56. [
  57. "[@](keyframes|-webkit-keyframes|-moz-keyframes|-o-keyframes)",
  58. { token: "keyword", next: "@keyframedeclaration" }
  59. ],
  60. ["[@](page|content|font-face|-moz-document)", { token: "keyword" }],
  61. ["[@](charset|namespace)", { token: "keyword", next: "@declarationbody" }],
  62. [
  63. "(url-prefix)(\\()",
  64. ["attribute.value", { token: "delimiter.parenthesis", next: "@urldeclaration" }]
  65. ],
  66. [
  67. "(url)(\\()",
  68. ["attribute.value", { token: "delimiter.parenthesis", next: "@urldeclaration" }]
  69. ],
  70. { include: "@selectorname" },
  71. ["[\\*]", "tag"],
  72. ["[>\\+,]", "delimiter"],
  73. ["\\[", { token: "delimiter.bracket", next: "@selectorattribute" }],
  74. ["{", { token: "delimiter.bracket", next: "@selectorbody" }]
  75. ],
  76. selectorbody: [
  77. { include: "@comments" },
  78. ["[*_]?@identifier@ws:(?=(\\s|\\d|[^{;}]*[;}]))", "attribute.name", "@rulevalue"],
  79. ["}", { token: "delimiter.bracket", next: "@pop" }]
  80. ],
  81. selectorname: [
  82. ["(\\.|#(?=[^{])|%|(@identifier)|:)+", "tag"]
  83. ],
  84. selectorattribute: [{ include: "@term" }, ["]", { token: "delimiter.bracket", next: "@pop" }]],
  85. term: [
  86. { include: "@comments" },
  87. [
  88. "(url-prefix)(\\()",
  89. ["attribute.value", { token: "delimiter.parenthesis", next: "@urldeclaration" }]
  90. ],
  91. [
  92. "(url)(\\()",
  93. ["attribute.value", { token: "delimiter.parenthesis", next: "@urldeclaration" }]
  94. ],
  95. { include: "@functioninvocation" },
  96. { include: "@numbers" },
  97. { include: "@name" },
  98. { include: "@strings" },
  99. ["([<>=\\+\\-\\*\\/\\^\\|\\~,])", "delimiter"],
  100. [",", "delimiter"]
  101. ],
  102. rulevalue: [
  103. { include: "@comments" },
  104. { include: "@strings" },
  105. { include: "@term" },
  106. ["!important", "keyword"],
  107. [";", "delimiter", "@pop"],
  108. ["(?=})", { token: "", next: "@pop" }]
  109. ],
  110. warndebug: [["[@](warn|debug)", { token: "keyword", next: "@declarationbody" }]],
  111. import: [["[@](import)", { token: "keyword", next: "@declarationbody" }]],
  112. urldeclaration: [
  113. { include: "@strings" },
  114. ["[^)\r\n]+", "string"],
  115. ["\\)", { token: "delimiter.parenthesis", next: "@pop" }]
  116. ],
  117. parenthizedterm: [
  118. { include: "@term" },
  119. ["\\)", { token: "delimiter.parenthesis", next: "@pop" }]
  120. ],
  121. declarationbody: [
  122. { include: "@term" },
  123. [";", "delimiter", "@pop"],
  124. ["(?=})", { token: "", next: "@pop" }]
  125. ],
  126. comments: [
  127. ["\\/\\*", "comment", "@comment"],
  128. ["\\/\\/+.*", "comment"]
  129. ],
  130. comment: [
  131. ["\\*\\/", "comment", "@pop"],
  132. [/[^*/]+/, "comment"],
  133. [/./, "comment"]
  134. ],
  135. name: [["@identifier", "attribute.value"]],
  136. numbers: [
  137. ["-?(\\d*\\.)?\\d+([eE][\\-+]?\\d+)?", { token: "attribute.value.number", next: "@units" }],
  138. ["#[0-9a-fA-F_]+(?!\\w)", "attribute.value.hex"]
  139. ],
  140. units: [
  141. [
  142. "(em|ex|ch|rem|vmin|vmax|vw|vh|vm|cm|mm|in|px|pt|pc|deg|grad|rad|turn|s|ms|Hz|kHz|%)?",
  143. "attribute.value.unit",
  144. "@pop"
  145. ]
  146. ],
  147. keyframedeclaration: [
  148. ["@identifier", "attribute.value"],
  149. ["{", { token: "delimiter.bracket", switchTo: "@keyframebody" }]
  150. ],
  151. keyframebody: [
  152. { include: "@term" },
  153. ["{", { token: "delimiter.bracket", next: "@selectorbody" }],
  154. ["}", { token: "delimiter.bracket", next: "@pop" }]
  155. ],
  156. functioninvocation: [
  157. ["@identifier\\(", { token: "attribute.value", next: "@functionarguments" }]
  158. ],
  159. functionarguments: [
  160. ["\\$@identifier@ws:", "attribute.name"],
  161. ["[,]", "delimiter"],
  162. { include: "@term" },
  163. ["\\)", { token: "attribute.value", next: "@pop" }]
  164. ],
  165. strings: [
  166. ['~?"', { token: "string", next: "@stringenddoublequote" }],
  167. ["~?'", { token: "string", next: "@stringendquote" }]
  168. ],
  169. stringenddoublequote: [
  170. ["\\\\.", "string"],
  171. ['"', { token: "string", next: "@pop" }],
  172. [/[^\\"]+/, "string"],
  173. [".", "string"]
  174. ],
  175. stringendquote: [
  176. ["\\\\.", "string"],
  177. ["'", { token: "string", next: "@pop" }],
  178. [/[^\\']+/, "string"],
  179. [".", "string"]
  180. ]
  181. }
  182. };
  183. export {
  184. conf,
  185. language
  186. };