mode-css.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. ace.define("ace/mode/css_highlight_rules",[], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var lang = require("../lib/lang");
  5. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6. var supportType = exports.supportType = "align-content|align-items|align-self|all|animation|animation-delay|animation-direction|animation-duration|animation-fill-mode|animation-iteration-count|animation-name|animation-play-state|animation-timing-function|backface-visibility|background|background-attachment|background-blend-mode|background-clip|background-color|background-image|background-origin|background-position|background-repeat|background-size|border|border-bottom|border-bottom-color|border-bottom-left-radius|border-bottom-right-radius|border-bottom-style|border-bottom-width|border-collapse|border-color|border-image|border-image-outset|border-image-repeat|border-image-slice|border-image-source|border-image-width|border-left|border-left-color|border-left-style|border-left-width|border-radius|border-right|border-right-color|border-right-style|border-right-width|border-spacing|border-style|border-top|border-top-color|border-top-left-radius|border-top-right-radius|border-top-style|border-top-width|border-width|bottom|box-shadow|box-sizing|caption-side|clear|clip|color|column-count|column-fill|column-gap|column-rule|column-rule-color|column-rule-style|column-rule-width|column-span|column-width|columns|content|counter-increment|counter-reset|cursor|direction|display|empty-cells|filter|flex|flex-basis|flex-direction|flex-flow|flex-grow|flex-shrink|flex-wrap|float|font|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|hanging-punctuation|height|justify-content|left|letter-spacing|line-height|list-style|list-style-image|list-style-position|list-style-type|margin|margin-bottom|margin-left|margin-right|margin-top|max-height|max-width|max-zoom|min-height|min-width|min-zoom|nav-down|nav-index|nav-left|nav-right|nav-up|opacity|order|outline|outline-color|outline-offset|outline-style|outline-width|overflow|overflow-x|overflow-y|padding|padding-bottom|padding-left|padding-right|padding-top|page-break-after|page-break-before|page-break-inside|perspective|perspective-origin|position|quotes|resize|right|tab-size|table-layout|text-align|text-align-last|text-decoration|text-decoration-color|text-decoration-line|text-decoration-style|text-indent|text-justify|text-overflow|text-shadow|text-transform|top|transform|transform-origin|transform-style|transition|transition-delay|transition-duration|transition-property|transition-timing-function|unicode-bidi|user-select|user-zoom|vertical-align|visibility|white-space|width|word-break|word-spacing|word-wrap|z-index";
  7. var supportFunction = exports.supportFunction = "rgb|rgba|url|attr|counter|counters";
  8. var supportConstant = exports.supportConstant = "absolute|after-edge|after|all-scroll|all|alphabetic|always|antialiased|armenian|auto|avoid-column|avoid-page|avoid|balance|baseline|before-edge|before|below|bidi-override|block-line-height|block|bold|bolder|border-box|both|bottom|box|break-all|break-word|capitalize|caps-height|caption|center|central|char|circle|cjk-ideographic|clone|close-quote|col-resize|collapse|column|consider-shifts|contain|content-box|cover|crosshair|cubic-bezier|dashed|decimal-leading-zero|decimal|default|disabled|disc|disregard-shifts|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ease-in|ease-in-out|ease-out|ease|ellipsis|end|exclude-ruby|fill|fixed|georgian|glyphs|grid-height|groove|hand|hanging|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|icon|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|ideographic|inactive|include-ruby|inherit|initial|inline-block|inline-box|inline-line-height|inline-table|inline|inset|inside|inter-ideograph|inter-word|invert|italic|justify|katakana-iroha|katakana|keep-all|last|left|lighter|line-edge|line-through|line|linear|list-item|local|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|mathematical|max-height|max-size|medium|menu|message-box|middle|move|n-resize|ne-resize|newspaper|no-change|no-close-quote|no-drop|no-open-quote|no-repeat|none|normal|not-allowed|nowrap|nw-resize|oblique|open-quote|outset|outside|overline|padding-box|page|pointer|pre-line|pre-wrap|pre|preserve-3d|progress|relative|repeat-x|repeat-y|repeat|replaced|reset-size|ridge|right|round|row-resize|rtl|s-resize|scroll|se-resize|separate|slice|small-caps|small-caption|solid|space|square|start|static|status-bar|step-end|step-start|steps|stretch|strict|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|table|tb-rl|text-after-edge|text-before-edge|text-bottom|text-size|text-top|text|thick|thin|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|use-script|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|z-index|zero|zoom";
  9. var supportConstantColor = exports.supportConstantColor = "aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|rebeccapurple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen";
  10. var supportConstantFonts = exports.supportConstantFonts = "arial|century|comic|courier|cursive|fantasy|garamond|georgia|helvetica|impact|lucida|symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|serif|monospace";
  11. var numRe = exports.numRe = "\\-?(?:(?:[0-9]+(?:\\.[0-9]+)?)|(?:\\.[0-9]+))";
  12. var pseudoElements = exports.pseudoElements = "(\\:+)\\b(after|before|first-letter|first-line|moz-selection|selection)\\b";
  13. var pseudoClasses = exports.pseudoClasses = "(:)\\b(active|checked|disabled|empty|enabled|first-child|first-of-type|focus|hover|indeterminate|invalid|last-child|last-of-type|link|not|nth-child|nth-last-child|nth-last-of-type|nth-of-type|only-child|only-of-type|required|root|target|valid|visited)\\b";
  14. var CssHighlightRules = function() {
  15. var keywordMapper = this.createKeywordMapper({
  16. "support.function": supportFunction,
  17. "support.constant": supportConstant,
  18. "support.type": supportType,
  19. "support.constant.color": supportConstantColor,
  20. "support.constant.fonts": supportConstantFonts
  21. }, "text", true);
  22. this.$rules = {
  23. "start" : [{
  24. include : ["strings", "url", "comments"]
  25. }, {
  26. token: "paren.lparen",
  27. regex: "\\{",
  28. next: "ruleset"
  29. }, {
  30. token: "paren.rparen",
  31. regex: "\\}"
  32. }, {
  33. token: "string",
  34. regex: "@(?!viewport)",
  35. next: "media"
  36. }, {
  37. token: "keyword",
  38. regex: "#[a-z0-9-_]+"
  39. }, {
  40. token: "keyword",
  41. regex: "%"
  42. }, {
  43. token: "variable",
  44. regex: "\\.[a-z0-9-_]+"
  45. }, {
  46. token: "string",
  47. regex: ":[a-z0-9-_]+"
  48. }, {
  49. token : "constant.numeric",
  50. regex : numRe
  51. }, {
  52. token: "constant",
  53. regex: "[a-z0-9-_]+"
  54. }, {
  55. caseInsensitive: true
  56. }],
  57. "media": [{
  58. include : ["strings", "url", "comments"]
  59. }, {
  60. token: "paren.lparen",
  61. regex: "\\{",
  62. next: "start"
  63. }, {
  64. token: "paren.rparen",
  65. regex: "\\}",
  66. next: "start"
  67. }, {
  68. token: "string",
  69. regex: ";",
  70. next: "start"
  71. }, {
  72. token: "keyword",
  73. regex: "(?:media|supports|document|charset|import|namespace|media|supports|document"
  74. + "|page|font|keyframes|viewport|counter-style|font-feature-values"
  75. + "|swash|ornaments|annotation|stylistic|styleset|character-variant)"
  76. }],
  77. "comments" : [{
  78. token: "comment", // multi line comment
  79. regex: "\\/\\*",
  80. push: [{
  81. token : "comment",
  82. regex : "\\*\\/",
  83. next : "pop"
  84. }, {
  85. defaultToken : "comment"
  86. }]
  87. }],
  88. "ruleset" : [{
  89. regex : "-(webkit|ms|moz|o)-",
  90. token : "text"
  91. }, {
  92. token : "punctuation.operator",
  93. regex : "[:;]"
  94. }, {
  95. token : "paren.rparen",
  96. regex : "\\}",
  97. next : "start"
  98. }, {
  99. include : ["strings", "url", "comments"]
  100. }, {
  101. token : ["constant.numeric", "keyword"],
  102. regex : "(" + numRe + ")(ch|cm|deg|em|ex|fr|gd|grad|Hz|in|kHz|mm|ms|pc|pt|px|rad|rem|s|turn|vh|vmax|vmin|vm|vw|%)"
  103. }, {
  104. token : "constant.numeric",
  105. regex : numRe
  106. }, {
  107. token : "constant.numeric", // hex6 color
  108. regex : "#[a-f0-9]{6}"
  109. }, {
  110. token : "constant.numeric", // hex3 color
  111. regex : "#[a-f0-9]{3}"
  112. }, {
  113. token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"],
  114. regex : pseudoElements
  115. }, {
  116. token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"],
  117. regex : pseudoClasses
  118. }, {
  119. include: "url"
  120. }, {
  121. token : keywordMapper,
  122. regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
  123. }, {
  124. caseInsensitive: true
  125. }],
  126. url: [{
  127. token : "support.function",
  128. regex : "(?:url(:?-prefix)?|domain|regexp)\\(",
  129. push: [{
  130. token : "support.function",
  131. regex : "\\)",
  132. next : "pop"
  133. }, {
  134. defaultToken: "string"
  135. }]
  136. }],
  137. strings: [{
  138. token : "string.start",
  139. regex : "'",
  140. push : [{
  141. token : "string.end",
  142. regex : "'|$",
  143. next: "pop"
  144. }, {
  145. include : "escapes"
  146. }, {
  147. token : "constant.language.escape",
  148. regex : /\\$/,
  149. consumeLineEnd: true
  150. }, {
  151. defaultToken: "string"
  152. }]
  153. }, {
  154. token : "string.start",
  155. regex : '"',
  156. push : [{
  157. token : "string.end",
  158. regex : '"|$',
  159. next: "pop"
  160. }, {
  161. include : "escapes"
  162. }, {
  163. token : "constant.language.escape",
  164. regex : /\\$/,
  165. consumeLineEnd: true
  166. }, {
  167. defaultToken: "string"
  168. }]
  169. }],
  170. escapes: [{
  171. token : "constant.language.escape",
  172. regex : /\\([a-fA-F\d]{1,6}|[^a-fA-F\d])/
  173. }]
  174. };
  175. this.normalizeRules();
  176. };
  177. oop.inherits(CssHighlightRules, TextHighlightRules);
  178. exports.CssHighlightRules = CssHighlightRules;
  179. });
  180. ace.define("ace/mode/matching_brace_outdent",[], function(require, exports, module) {
  181. "use strict";
  182. var Range = require("../range").Range;
  183. var MatchingBraceOutdent = function() {};
  184. (function() {
  185. this.checkOutdent = function(line, input) {
  186. if (! /^\s+$/.test(line))
  187. return false;
  188. return /^\s*\}/.test(input);
  189. };
  190. this.autoOutdent = function(doc, row) {
  191. var line = doc.getLine(row);
  192. var match = line.match(/^(\s*\})/);
  193. if (!match) return 0;
  194. var column = match[1].length;
  195. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  196. if (!openBracePos || openBracePos.row == row) return 0;
  197. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  198. doc.replace(new Range(row, 0, row, column-1), indent);
  199. };
  200. this.$getIndent = function(line) {
  201. return line.match(/^\s*/)[0];
  202. };
  203. }).call(MatchingBraceOutdent.prototype);
  204. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  205. });
  206. ace.define("ace/mode/css_completions",[], function(require, exports, module) {
  207. "use strict";
  208. var propertyMap = {
  209. "background": {"#$0": 1},
  210. "background-color": {"#$0": 1, "transparent": 1, "fixed": 1},
  211. "background-image": {"url('/$0')": 1},
  212. "background-repeat": {"repeat": 1, "repeat-x": 1, "repeat-y": 1, "no-repeat": 1, "inherit": 1},
  213. "background-position": {"bottom":2, "center":2, "left":2, "right":2, "top":2, "inherit":2},
  214. "background-attachment": {"scroll": 1, "fixed": 1},
  215. "background-size": {"cover": 1, "contain": 1},
  216. "background-clip": {"border-box": 1, "padding-box": 1, "content-box": 1},
  217. "background-origin": {"border-box": 1, "padding-box": 1, "content-box": 1},
  218. "border": {"solid $0": 1, "dashed $0": 1, "dotted $0": 1, "#$0": 1},
  219. "border-color": {"#$0": 1},
  220. "border-style": {"solid":2, "dashed":2, "dotted":2, "double":2, "groove":2, "hidden":2, "inherit":2, "inset":2, "none":2, "outset":2, "ridged":2},
  221. "border-collapse": {"collapse": 1, "separate": 1},
  222. "bottom": {"px": 1, "em": 1, "%": 1},
  223. "clear": {"left": 1, "right": 1, "both": 1, "none": 1},
  224. "color": {"#$0": 1, "rgb(#$00,0,0)": 1},
  225. "cursor": {"default": 1, "pointer": 1, "move": 1, "text": 1, "wait": 1, "help": 1, "progress": 1, "n-resize": 1, "ne-resize": 1, "e-resize": 1, "se-resize": 1, "s-resize": 1, "sw-resize": 1, "w-resize": 1, "nw-resize": 1},
  226. "display": {"none": 1, "block": 1, "inline": 1, "inline-block": 1, "table-cell": 1},
  227. "empty-cells": {"show": 1, "hide": 1},
  228. "float": {"left": 1, "right": 1, "none": 1},
  229. "font-family": {"Arial":2,"Comic Sans MS":2,"Consolas":2,"Courier New":2,"Courier":2,"Georgia":2,"Monospace":2,"Sans-Serif":2, "Segoe UI":2,"Tahoma":2,"Times New Roman":2,"Trebuchet MS":2,"Verdana": 1},
  230. "font-size": {"px": 1, "em": 1, "%": 1},
  231. "font-weight": {"bold": 1, "normal": 1},
  232. "font-style": {"italic": 1, "normal": 1},
  233. "font-variant": {"normal": 1, "small-caps": 1},
  234. "height": {"px": 1, "em": 1, "%": 1},
  235. "left": {"px": 1, "em": 1, "%": 1},
  236. "letter-spacing": {"normal": 1},
  237. "line-height": {"normal": 1},
  238. "list-style-type": {"none": 1, "disc": 1, "circle": 1, "square": 1, "decimal": 1, "decimal-leading-zero": 1, "lower-roman": 1, "upper-roman": 1, "lower-greek": 1, "lower-latin": 1, "upper-latin": 1, "georgian": 1, "lower-alpha": 1, "upper-alpha": 1},
  239. "margin": {"px": 1, "em": 1, "%": 1},
  240. "margin-right": {"px": 1, "em": 1, "%": 1},
  241. "margin-left": {"px": 1, "em": 1, "%": 1},
  242. "margin-top": {"px": 1, "em": 1, "%": 1},
  243. "margin-bottom": {"px": 1, "em": 1, "%": 1},
  244. "max-height": {"px": 1, "em": 1, "%": 1},
  245. "max-width": {"px": 1, "em": 1, "%": 1},
  246. "min-height": {"px": 1, "em": 1, "%": 1},
  247. "min-width": {"px": 1, "em": 1, "%": 1},
  248. "overflow": {"hidden": 1, "visible": 1, "auto": 1, "scroll": 1},
  249. "overflow-x": {"hidden": 1, "visible": 1, "auto": 1, "scroll": 1},
  250. "overflow-y": {"hidden": 1, "visible": 1, "auto": 1, "scroll": 1},
  251. "padding": {"px": 1, "em": 1, "%": 1},
  252. "padding-top": {"px": 1, "em": 1, "%": 1},
  253. "padding-right": {"px": 1, "em": 1, "%": 1},
  254. "padding-bottom": {"px": 1, "em": 1, "%": 1},
  255. "padding-left": {"px": 1, "em": 1, "%": 1},
  256. "page-break-after": {"auto": 1, "always": 1, "avoid": 1, "left": 1, "right": 1},
  257. "page-break-before": {"auto": 1, "always": 1, "avoid": 1, "left": 1, "right": 1},
  258. "position": {"absolute": 1, "relative": 1, "fixed": 1, "static": 1},
  259. "right": {"px": 1, "em": 1, "%": 1},
  260. "table-layout": {"fixed": 1, "auto": 1},
  261. "text-decoration": {"none": 1, "underline": 1, "line-through": 1, "blink": 1},
  262. "text-align": {"left": 1, "right": 1, "center": 1, "justify": 1},
  263. "text-transform": {"capitalize": 1, "uppercase": 1, "lowercase": 1, "none": 1},
  264. "top": {"px": 1, "em": 1, "%": 1},
  265. "vertical-align": {"top": 1, "bottom": 1},
  266. "visibility": {"hidden": 1, "visible": 1},
  267. "white-space": {"nowrap": 1, "normal": 1, "pre": 1, "pre-line": 1, "pre-wrap": 1},
  268. "width": {"px": 1, "em": 1, "%": 1},
  269. "word-spacing": {"normal": 1},
  270. "filter": {"alpha(opacity=$0100)": 1},
  271. "text-shadow": {"$02px 2px 2px #777": 1},
  272. "text-overflow": {"ellipsis-word": 1, "clip": 1, "ellipsis": 1},
  273. "-moz-border-radius": 1,
  274. "-moz-border-radius-topright": 1,
  275. "-moz-border-radius-bottomright": 1,
  276. "-moz-border-radius-topleft": 1,
  277. "-moz-border-radius-bottomleft": 1,
  278. "-webkit-border-radius": 1,
  279. "-webkit-border-top-right-radius": 1,
  280. "-webkit-border-top-left-radius": 1,
  281. "-webkit-border-bottom-right-radius": 1,
  282. "-webkit-border-bottom-left-radius": 1,
  283. "-moz-box-shadow": 1,
  284. "-webkit-box-shadow": 1,
  285. "transform": {"rotate($00deg)": 1, "skew($00deg)": 1},
  286. "-moz-transform": {"rotate($00deg)": 1, "skew($00deg)": 1},
  287. "-webkit-transform": {"rotate($00deg)": 1, "skew($00deg)": 1 }
  288. };
  289. var CssCompletions = function() {
  290. };
  291. (function() {
  292. this.completionsDefined = false;
  293. this.defineCompletions = function() {
  294. if (document) {
  295. var style = document.createElement('c').style;
  296. for (var i in style) {
  297. if (typeof style[i] !== 'string')
  298. continue;
  299. var name = i.replace(/[A-Z]/g, function(x) {
  300. return '-' + x.toLowerCase();
  301. });
  302. if (!propertyMap.hasOwnProperty(name))
  303. propertyMap[name] = 1;
  304. }
  305. }
  306. this.completionsDefined = true;
  307. };
  308. this.getCompletions = function(state, session, pos, prefix) {
  309. if (!this.completionsDefined) {
  310. this.defineCompletions();
  311. }
  312. var token = session.getTokenAt(pos.row, pos.column);
  313. if (!token)
  314. return [];
  315. if (state==='ruleset'){
  316. var line = session.getLine(pos.row).substr(0, pos.column);
  317. if (/:[^;]+$/.test(line)) {
  318. /([\w\-]+):[^:]*$/.test(line);
  319. return this.getPropertyValueCompletions(state, session, pos, prefix);
  320. } else {
  321. return this.getPropertyCompletions(state, session, pos, prefix);
  322. }
  323. }
  324. return [];
  325. };
  326. this.getPropertyCompletions = function(state, session, pos, prefix) {
  327. var properties = Object.keys(propertyMap);
  328. return properties.map(function(property){
  329. return {
  330. caption: property,
  331. snippet: property + ': $0;',
  332. meta: "property",
  333. score: Number.MAX_VALUE
  334. };
  335. });
  336. };
  337. this.getPropertyValueCompletions = function(state, session, pos, prefix) {
  338. var line = session.getLine(pos.row).substr(0, pos.column);
  339. var property = (/([\w\-]+):[^:]*$/.exec(line) || {})[1];
  340. if (!property)
  341. return [];
  342. var values = [];
  343. if (property in propertyMap && typeof propertyMap[property] === "object") {
  344. values = Object.keys(propertyMap[property]);
  345. }
  346. return values.map(function(value){
  347. return {
  348. caption: value,
  349. snippet: value,
  350. meta: "property value",
  351. score: Number.MAX_VALUE
  352. };
  353. });
  354. };
  355. }).call(CssCompletions.prototype);
  356. exports.CssCompletions = CssCompletions;
  357. });
  358. ace.define("ace/mode/behaviour/css",[], function(require, exports, module) {
  359. "use strict";
  360. var oop = require("../../lib/oop");
  361. var Behaviour = require("../behaviour").Behaviour;
  362. var CstyleBehaviour = require("./cstyle").CstyleBehaviour;
  363. var TokenIterator = require("../../token_iterator").TokenIterator;
  364. var CssBehaviour = function () {
  365. this.inherit(CstyleBehaviour);
  366. this.add("colon", "insertion", function (state, action, editor, session, text) {
  367. if (text === ':' && editor.selection.isEmpty()) {
  368. var cursor = editor.getCursorPosition();
  369. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  370. var token = iterator.getCurrentToken();
  371. if (token && token.value.match(/\s+/)) {
  372. token = iterator.stepBackward();
  373. }
  374. if (token && token.type === 'support.type') {
  375. var line = session.doc.getLine(cursor.row);
  376. var rightChar = line.substring(cursor.column, cursor.column + 1);
  377. if (rightChar === ':') {
  378. return {
  379. text: '',
  380. selection: [1, 1]
  381. };
  382. }
  383. if (/^(\s+[^;]|\s*$)/.test(line.substring(cursor.column))) {
  384. return {
  385. text: ':;',
  386. selection: [1, 1]
  387. };
  388. }
  389. }
  390. }
  391. });
  392. this.add("colon", "deletion", function (state, action, editor, session, range) {
  393. var selected = session.doc.getTextRange(range);
  394. if (!range.isMultiLine() && selected === ':') {
  395. var cursor = editor.getCursorPosition();
  396. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  397. var token = iterator.getCurrentToken();
  398. if (token && token.value.match(/\s+/)) {
  399. token = iterator.stepBackward();
  400. }
  401. if (token && token.type === 'support.type') {
  402. var line = session.doc.getLine(range.start.row);
  403. var rightChar = line.substring(range.end.column, range.end.column + 1);
  404. if (rightChar === ';') {
  405. range.end.column ++;
  406. return range;
  407. }
  408. }
  409. }
  410. });
  411. this.add("semicolon", "insertion", function (state, action, editor, session, text) {
  412. if (text === ';' && editor.selection.isEmpty()) {
  413. var cursor = editor.getCursorPosition();
  414. var line = session.doc.getLine(cursor.row);
  415. var rightChar = line.substring(cursor.column, cursor.column + 1);
  416. if (rightChar === ';') {
  417. return {
  418. text: '',
  419. selection: [1, 1]
  420. };
  421. }
  422. }
  423. });
  424. this.add("!important", "insertion", function (state, action, editor, session, text) {
  425. if (text === '!' && editor.selection.isEmpty()) {
  426. var cursor = editor.getCursorPosition();
  427. var line = session.doc.getLine(cursor.row);
  428. if (/^\s*(;|}|$)/.test(line.substring(cursor.column))) {
  429. return {
  430. text: '!important',
  431. selection: [10, 10]
  432. };
  433. }
  434. }
  435. });
  436. };
  437. oop.inherits(CssBehaviour, CstyleBehaviour);
  438. exports.CssBehaviour = CssBehaviour;
  439. });
  440. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  441. "use strict";
  442. var oop = require("../../lib/oop");
  443. var Range = require("../../range").Range;
  444. var BaseFoldMode = require("./fold_mode").FoldMode;
  445. var FoldMode = exports.FoldMode = function(commentRegex) {
  446. if (commentRegex) {
  447. this.foldingStartMarker = new RegExp(
  448. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  449. );
  450. this.foldingStopMarker = new RegExp(
  451. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  452. );
  453. }
  454. };
  455. oop.inherits(FoldMode, BaseFoldMode);
  456. (function() {
  457. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  458. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  459. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  460. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  461. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  462. this._getFoldWidgetBase = this.getFoldWidget;
  463. this.getFoldWidget = function(session, foldStyle, row) {
  464. var line = session.getLine(row);
  465. if (this.singleLineBlockCommentRe.test(line)) {
  466. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  467. return "";
  468. }
  469. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  470. if (!fw && this.startRegionRe.test(line))
  471. return "start"; // lineCommentRegionStart
  472. return fw;
  473. };
  474. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  475. var line = session.getLine(row);
  476. if (this.startRegionRe.test(line))
  477. return this.getCommentRegionBlock(session, line, row);
  478. var match = line.match(this.foldingStartMarker);
  479. if (match) {
  480. var i = match.index;
  481. if (match[1])
  482. return this.openingBracketBlock(session, match[1], row, i);
  483. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  484. if (range && !range.isMultiLine()) {
  485. if (forceMultiline) {
  486. range = this.getSectionRange(session, row);
  487. } else if (foldStyle != "all")
  488. range = null;
  489. }
  490. return range;
  491. }
  492. if (foldStyle === "markbegin")
  493. return;
  494. var match = line.match(this.foldingStopMarker);
  495. if (match) {
  496. var i = match.index + match[0].length;
  497. if (match[1])
  498. return this.closingBracketBlock(session, match[1], row, i);
  499. return session.getCommentFoldRange(row, i, -1);
  500. }
  501. };
  502. this.getSectionRange = function(session, row) {
  503. var line = session.getLine(row);
  504. var startIndent = line.search(/\S/);
  505. var startRow = row;
  506. var startColumn = line.length;
  507. row = row + 1;
  508. var endRow = row;
  509. var maxRow = session.getLength();
  510. while (++row < maxRow) {
  511. line = session.getLine(row);
  512. var indent = line.search(/\S/);
  513. if (indent === -1)
  514. continue;
  515. if (startIndent > indent)
  516. break;
  517. var subRange = this.getFoldWidgetRange(session, "all", row);
  518. if (subRange) {
  519. if (subRange.start.row <= startRow) {
  520. break;
  521. } else if (subRange.isMultiLine()) {
  522. row = subRange.end.row;
  523. } else if (startIndent == indent) {
  524. break;
  525. }
  526. }
  527. endRow = row;
  528. }
  529. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  530. };
  531. this.getCommentRegionBlock = function(session, line, row) {
  532. var startColumn = line.search(/\s*$/);
  533. var maxRow = session.getLength();
  534. var startRow = row;
  535. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  536. var depth = 1;
  537. while (++row < maxRow) {
  538. line = session.getLine(row);
  539. var m = re.exec(line);
  540. if (!m) continue;
  541. if (m[1]) depth--;
  542. else depth++;
  543. if (!depth) break;
  544. }
  545. var endRow = row;
  546. if (endRow > startRow) {
  547. return new Range(startRow, startColumn, endRow, line.length);
  548. }
  549. };
  550. }).call(FoldMode.prototype);
  551. });
  552. ace.define("ace/mode/css",[], function(require, exports, module) {
  553. "use strict";
  554. var oop = require("../lib/oop");
  555. var TextMode = require("./text").Mode;
  556. var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules;
  557. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  558. var WorkerClient = require("../worker/worker_client").WorkerClient;
  559. var CssCompletions = require("./css_completions").CssCompletions;
  560. var CssBehaviour = require("./behaviour/css").CssBehaviour;
  561. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  562. var Mode = function() {
  563. this.HighlightRules = CssHighlightRules;
  564. this.$outdent = new MatchingBraceOutdent();
  565. this.$behaviour = new CssBehaviour();
  566. this.$completer = new CssCompletions();
  567. this.foldingRules = new CStyleFoldMode();
  568. };
  569. oop.inherits(Mode, TextMode);
  570. (function() {
  571. this.foldingRules = "cStyle";
  572. this.blockComment = {start: "/*", end: "*/"};
  573. this.getNextLineIndent = function(state, line, tab) {
  574. var indent = this.$getIndent(line);
  575. var tokens = this.getTokenizer().getLineTokens(line, state).tokens;
  576. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  577. return indent;
  578. }
  579. var match = line.match(/^.*\{\s*$/);
  580. if (match) {
  581. indent += tab;
  582. }
  583. return indent;
  584. };
  585. this.checkOutdent = function(state, line, input) {
  586. return this.$outdent.checkOutdent(line, input);
  587. };
  588. this.autoOutdent = function(state, doc, row) {
  589. this.$outdent.autoOutdent(doc, row);
  590. };
  591. this.getCompletions = function(state, session, pos, prefix) {
  592. return this.$completer.getCompletions(state, session, pos, prefix);
  593. };
  594. this.createWorker = function(session) {
  595. var worker = new WorkerClient(["ace"], "ace/mode/css_worker", "Worker");
  596. worker.attachToDocument(session.getDocument());
  597. worker.on("annotate", function(e) {
  598. session.setAnnotations(e.data);
  599. });
  600. worker.on("terminate", function() {
  601. session.clearAnnotations();
  602. });
  603. return worker;
  604. };
  605. this.$id = "ace/mode/css";
  606. }).call(Mode.prototype);
  607. exports.Mode = Mode;
  608. });
  609. (function() {
  610. ace.require(["ace/mode/css"], function(m) {
  611. if (typeof module == "object" && typeof exports == "object" && module) {
  612. module.exports = m;
  613. }
  614. });
  615. })();