mode-css.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. ace.define("ace/mode/css_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_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|min-height|min-width|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|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";
  9. var supportConstantColor = exports.supportConstantColor = "aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow";
  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. token : "comment", // multi line comment
  25. regex : "\\/\\*",
  26. push : "comment"
  27. }, {
  28. token: "paren.lparen",
  29. regex: "\\{",
  30. push: "ruleset"
  31. }, {
  32. token: "string",
  33. regex: "@.*?{",
  34. push: "media"
  35. }, {
  36. token: "keyword",
  37. regex: "#[a-z0-9-_]+"
  38. }, {
  39. token: "variable",
  40. regex: "\\.[a-z0-9-_]+"
  41. }, {
  42. token: "string",
  43. regex: ":[a-z0-9-_]+"
  44. }, {
  45. token: "constant",
  46. regex: "[a-z0-9-_]+"
  47. }, {
  48. caseInsensitive: true
  49. }],
  50. "media" : [{
  51. token : "comment", // multi line comment
  52. regex : "\\/\\*",
  53. push : "comment"
  54. }, {
  55. token: "paren.lparen",
  56. regex: "\\{",
  57. push: "ruleset"
  58. }, {
  59. token: "string",
  60. regex: "\\}",
  61. next: "pop"
  62. }, {
  63. token: "keyword",
  64. regex: "#[a-z0-9-_]+"
  65. }, {
  66. token: "variable",
  67. regex: "\\.[a-z0-9-_]+"
  68. }, {
  69. token: "string",
  70. regex: ":[a-z0-9-_]+"
  71. }, {
  72. token: "constant",
  73. regex: "[a-z0-9-_]+"
  74. }, {
  75. caseInsensitive: true
  76. }],
  77. "comment" : [{
  78. token : "comment",
  79. regex : "\\*\\/",
  80. next : "pop"
  81. }, {
  82. defaultToken : "comment"
  83. }],
  84. "ruleset" : [
  85. {
  86. token : "paren.rparen",
  87. regex : "\\}",
  88. next: "pop"
  89. }, {
  90. token : "comment", // multi line comment
  91. regex : "\\/\\*",
  92. push : "comment"
  93. }, {
  94. token : "string", // single line
  95. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  96. }, {
  97. token : "string", // single line
  98. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  99. }, {
  100. token : ["constant.numeric", "keyword"],
  101. regex : "(" + numRe + ")(ch|cm|deg|em|ex|fr|gd|grad|Hz|in|kHz|mm|ms|pc|pt|px|rad|rem|s|turn|vh|vm|vw|%)"
  102. }, {
  103. token : "constant.numeric",
  104. regex : numRe
  105. }, {
  106. token : "constant.numeric", // hex6 color
  107. regex : "#[a-f0-9]{6}"
  108. }, {
  109. token : "constant.numeric", // hex3 color
  110. regex : "#[a-f0-9]{3}"
  111. }, {
  112. token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"],
  113. regex : pseudoElements
  114. }, {
  115. token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"],
  116. regex : pseudoClasses
  117. }, {
  118. token : ["support.function", "string", "support.function"],
  119. regex : "(url\\()(.*)(\\))"
  120. }, {
  121. token : keywordMapper,
  122. regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
  123. }, {
  124. caseInsensitive: true
  125. }]
  126. };
  127. this.normalizeRules();
  128. };
  129. oop.inherits(CssHighlightRules, TextHighlightRules);
  130. exports.CssHighlightRules = CssHighlightRules;
  131. });
  132. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  133. "use strict";
  134. var Range = require("../range").Range;
  135. var MatchingBraceOutdent = function() {};
  136. (function() {
  137. this.checkOutdent = function(line, input) {
  138. if (! /^\s+$/.test(line))
  139. return false;
  140. return /^\s*\}/.test(input);
  141. };
  142. this.autoOutdent = function(doc, row) {
  143. var line = doc.getLine(row);
  144. var match = line.match(/^(\s*\})/);
  145. if (!match) return 0;
  146. var column = match[1].length;
  147. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  148. if (!openBracePos || openBracePos.row == row) return 0;
  149. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  150. doc.replace(new Range(row, 0, row, column-1), indent);
  151. };
  152. this.$getIndent = function(line) {
  153. return line.match(/^\s*/)[0];
  154. };
  155. }).call(MatchingBraceOutdent.prototype);
  156. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  157. });
  158. ace.define("ace/mode/css_completions",["require","exports","module"], function(require, exports, module) {
  159. "use strict";
  160. var propertyMap = {
  161. "background": {"#$0": 1},
  162. "background-color": {"#$0": 1, "transparent": 1, "fixed": 1},
  163. "background-image": {"url('/$0')": 1},
  164. "background-repeat": {"repeat": 1, "repeat-x": 1, "repeat-y": 1, "no-repeat": 1, "inherit": 1},
  165. "background-position": {"bottom":2, "center":2, "left":2, "right":2, "top":2, "inherit":2},
  166. "background-attachment": {"scroll": 1, "fixed": 1},
  167. "background-size": {"cover": 1, "contain": 1},
  168. "background-clip": {"border-box": 1, "padding-box": 1, "content-box": 1},
  169. "background-origin": {"border-box": 1, "padding-box": 1, "content-box": 1},
  170. "border": {"solid $0": 1, "dashed $0": 1, "dotted $0": 1, "#$0": 1},
  171. "border-color": {"#$0": 1},
  172. "border-style": {"solid":2, "dashed":2, "dotted":2, "double":2, "groove":2, "hidden":2, "inherit":2, "inset":2, "none":2, "outset":2, "ridged":2},
  173. "border-collapse": {"collapse": 1, "separate": 1},
  174. "bottom": {"px": 1, "em": 1, "%": 1},
  175. "clear": {"left": 1, "right": 1, "both": 1, "none": 1},
  176. "color": {"#$0": 1, "rgb(#$00,0,0)": 1},
  177. "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},
  178. "display": {"none": 1, "block": 1, "inline": 1, "inline-block": 1, "table-cell": 1},
  179. "empty-cells": {"show": 1, "hide": 1},
  180. "float": {"left": 1, "right": 1, "none": 1},
  181. "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},
  182. "font-size": {"px": 1, "em": 1, "%": 1},
  183. "font-weight": {"bold": 1, "normal": 1},
  184. "font-style": {"italic": 1, "normal": 1},
  185. "font-variant": {"normal": 1, "small-caps": 1},
  186. "height": {"px": 1, "em": 1, "%": 1},
  187. "left": {"px": 1, "em": 1, "%": 1},
  188. "letter-spacing": {"normal": 1},
  189. "line-height": {"normal": 1},
  190. "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},
  191. "margin": {"px": 1, "em": 1, "%": 1},
  192. "margin-right": {"px": 1, "em": 1, "%": 1},
  193. "margin-left": {"px": 1, "em": 1, "%": 1},
  194. "margin-top": {"px": 1, "em": 1, "%": 1},
  195. "margin-bottom": {"px": 1, "em": 1, "%": 1},
  196. "max-height": {"px": 1, "em": 1, "%": 1},
  197. "max-width": {"px": 1, "em": 1, "%": 1},
  198. "min-height": {"px": 1, "em": 1, "%": 1},
  199. "min-width": {"px": 1, "em": 1, "%": 1},
  200. "overflow": {"hidden": 1, "visible": 1, "auto": 1, "scroll": 1},
  201. "overflow-x": {"hidden": 1, "visible": 1, "auto": 1, "scroll": 1},
  202. "overflow-y": {"hidden": 1, "visible": 1, "auto": 1, "scroll": 1},
  203. "padding": {"px": 1, "em": 1, "%": 1},
  204. "padding-top": {"px": 1, "em": 1, "%": 1},
  205. "padding-right": {"px": 1, "em": 1, "%": 1},
  206. "padding-bottom": {"px": 1, "em": 1, "%": 1},
  207. "padding-left": {"px": 1, "em": 1, "%": 1},
  208. "page-break-after": {"auto": 1, "always": 1, "avoid": 1, "left": 1, "right": 1},
  209. "page-break-before": {"auto": 1, "always": 1, "avoid": 1, "left": 1, "right": 1},
  210. "position": {"absolute": 1, "relative": 1, "fixed": 1, "static": 1},
  211. "right": {"px": 1, "em": 1, "%": 1},
  212. "table-layout": {"fixed": 1, "auto": 1},
  213. "text-decoration": {"none": 1, "underline": 1, "line-through": 1, "blink": 1},
  214. "text-align": {"left": 1, "right": 1, "center": 1, "justify": 1},
  215. "text-transform": {"capitalize": 1, "uppercase": 1, "lowercase": 1, "none": 1},
  216. "top": {"px": 1, "em": 1, "%": 1},
  217. "vertical-align": {"top": 1, "bottom": 1},
  218. "visibility": {"hidden": 1, "visible": 1},
  219. "white-space": {"nowrap": 1, "normal": 1, "pre": 1, "pre-line": 1, "pre-wrap": 1},
  220. "width": {"px": 1, "em": 1, "%": 1},
  221. "word-spacing": {"normal": 1},
  222. "filter": {"alpha(opacity=$0100)": 1},
  223. "text-shadow": {"$02px 2px 2px #777": 1},
  224. "text-overflow": {"ellipsis-word": 1, "clip": 1, "ellipsis": 1},
  225. "-moz-border-radius": 1,
  226. "-moz-border-radius-topright": 1,
  227. "-moz-border-radius-bottomright": 1,
  228. "-moz-border-radius-topleft": 1,
  229. "-moz-border-radius-bottomleft": 1,
  230. "-webkit-border-radius": 1,
  231. "-webkit-border-top-right-radius": 1,
  232. "-webkit-border-top-left-radius": 1,
  233. "-webkit-border-bottom-right-radius": 1,
  234. "-webkit-border-bottom-left-radius": 1,
  235. "-moz-box-shadow": 1,
  236. "-webkit-box-shadow": 1,
  237. "transform": {"rotate($00deg)": 1, "skew($00deg)": 1},
  238. "-moz-transform": {"rotate($00deg)": 1, "skew($00deg)": 1},
  239. "-webkit-transform": {"rotate($00deg)": 1, "skew($00deg)": 1 }
  240. };
  241. var CssCompletions = function() {
  242. };
  243. (function() {
  244. this.completionsDefined = false;
  245. this.defineCompletions = function() {
  246. if (document) {
  247. var style = document.createElement('c').style;
  248. for (var i in style) {
  249. if (typeof style[i] !== 'string')
  250. continue;
  251. var name = i.replace(/[A-Z]/g, function(x) {
  252. return '-' + x.toLowerCase();
  253. });
  254. if (!propertyMap.hasOwnProperty(name))
  255. propertyMap[name] = 1;
  256. }
  257. }
  258. this.completionsDefined = true;
  259. }
  260. this.getCompletions = function(state, session, pos, prefix) {
  261. if (!this.completionsDefined) {
  262. this.defineCompletions();
  263. }
  264. var token = session.getTokenAt(pos.row, pos.column);
  265. if (!token)
  266. return [];
  267. if (state==='ruleset'){
  268. var line = session.getLine(pos.row).substr(0, pos.column);
  269. if (/:[^;]+$/.test(line)) {
  270. /([\w\-]+):[^:]*$/.test(line);
  271. return this.getPropertyValueCompletions(state, session, pos, prefix);
  272. } else {
  273. return this.getPropertyCompletions(state, session, pos, prefix);
  274. }
  275. }
  276. return [];
  277. };
  278. this.getPropertyCompletions = function(state, session, pos, prefix) {
  279. var properties = Object.keys(propertyMap);
  280. return properties.map(function(property){
  281. return {
  282. caption: property,
  283. snippet: property + ': $0',
  284. meta: "property",
  285. score: Number.MAX_VALUE
  286. };
  287. });
  288. };
  289. this.getPropertyValueCompletions = function(state, session, pos, prefix) {
  290. var line = session.getLine(pos.row).substr(0, pos.column);
  291. var property = (/([\w\-]+):[^:]*$/.exec(line) || {})[1];
  292. if (!property)
  293. return [];
  294. var values = [];
  295. if (property in propertyMap && typeof propertyMap[property] === "object") {
  296. values = Object.keys(propertyMap[property]);
  297. }
  298. return values.map(function(value){
  299. return {
  300. caption: value,
  301. snippet: value,
  302. meta: "property value",
  303. score: Number.MAX_VALUE
  304. };
  305. });
  306. };
  307. }).call(CssCompletions.prototype);
  308. exports.CssCompletions = CssCompletions;
  309. });
  310. ace.define("ace/mode/behaviour/css",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/mode/behaviour/cstyle","ace/token_iterator"], function(require, exports, module) {
  311. "use strict";
  312. var oop = require("../../lib/oop");
  313. var Behaviour = require("../behaviour").Behaviour;
  314. var CstyleBehaviour = require("./cstyle").CstyleBehaviour;
  315. var TokenIterator = require("../../token_iterator").TokenIterator;
  316. var CssBehaviour = function () {
  317. this.inherit(CstyleBehaviour);
  318. this.add("colon", "insertion", function (state, action, editor, session, text) {
  319. if (text === ':') {
  320. var cursor = editor.getCursorPosition();
  321. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  322. var token = iterator.getCurrentToken();
  323. if (token && token.value.match(/\s+/)) {
  324. token = iterator.stepBackward();
  325. }
  326. if (token && token.type === 'support.type') {
  327. var line = session.doc.getLine(cursor.row);
  328. var rightChar = line.substring(cursor.column, cursor.column + 1);
  329. if (rightChar === ':') {
  330. return {
  331. text: '',
  332. selection: [1, 1]
  333. }
  334. }
  335. if (!line.substring(cursor.column).match(/^\s*;/)) {
  336. return {
  337. text: ':;',
  338. selection: [1, 1]
  339. }
  340. }
  341. }
  342. }
  343. });
  344. this.add("colon", "deletion", function (state, action, editor, session, range) {
  345. var selected = session.doc.getTextRange(range);
  346. if (!range.isMultiLine() && selected === ':') {
  347. var cursor = editor.getCursorPosition();
  348. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  349. var token = iterator.getCurrentToken();
  350. if (token && token.value.match(/\s+/)) {
  351. token = iterator.stepBackward();
  352. }
  353. if (token && token.type === 'support.type') {
  354. var line = session.doc.getLine(range.start.row);
  355. var rightChar = line.substring(range.end.column, range.end.column + 1);
  356. if (rightChar === ';') {
  357. range.end.column ++;
  358. return range;
  359. }
  360. }
  361. }
  362. });
  363. this.add("semicolon", "insertion", function (state, action, editor, session, text) {
  364. if (text === ';') {
  365. var cursor = editor.getCursorPosition();
  366. var line = session.doc.getLine(cursor.row);
  367. var rightChar = line.substring(cursor.column, cursor.column + 1);
  368. if (rightChar === ';') {
  369. return {
  370. text: '',
  371. selection: [1, 1]
  372. }
  373. }
  374. }
  375. });
  376. }
  377. oop.inherits(CssBehaviour, CstyleBehaviour);
  378. exports.CssBehaviour = CssBehaviour;
  379. });
  380. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  381. "use strict";
  382. var oop = require("../../lib/oop");
  383. var Range = require("../../range").Range;
  384. var BaseFoldMode = require("./fold_mode").FoldMode;
  385. var FoldMode = exports.FoldMode = function(commentRegex) {
  386. if (commentRegex) {
  387. this.foldingStartMarker = new RegExp(
  388. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  389. );
  390. this.foldingStopMarker = new RegExp(
  391. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  392. );
  393. }
  394. };
  395. oop.inherits(FoldMode, BaseFoldMode);
  396. (function() {
  397. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  398. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  399. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  400. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  401. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  402. this._getFoldWidgetBase = this.getFoldWidget;
  403. this.getFoldWidget = function(session, foldStyle, row) {
  404. var line = session.getLine(row);
  405. if (this.singleLineBlockCommentRe.test(line)) {
  406. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  407. return "";
  408. }
  409. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  410. if (!fw && this.startRegionRe.test(line))
  411. return "start"; // lineCommentRegionStart
  412. return fw;
  413. };
  414. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  415. var line = session.getLine(row);
  416. if (this.startRegionRe.test(line))
  417. return this.getCommentRegionBlock(session, line, row);
  418. var match = line.match(this.foldingStartMarker);
  419. if (match) {
  420. var i = match.index;
  421. if (match[1])
  422. return this.openingBracketBlock(session, match[1], row, i);
  423. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  424. if (range && !range.isMultiLine()) {
  425. if (forceMultiline) {
  426. range = this.getSectionRange(session, row);
  427. } else if (foldStyle != "all")
  428. range = null;
  429. }
  430. return range;
  431. }
  432. if (foldStyle === "markbegin")
  433. return;
  434. var match = line.match(this.foldingStopMarker);
  435. if (match) {
  436. var i = match.index + match[0].length;
  437. if (match[1])
  438. return this.closingBracketBlock(session, match[1], row, i);
  439. return session.getCommentFoldRange(row, i, -1);
  440. }
  441. };
  442. this.getSectionRange = function(session, row) {
  443. var line = session.getLine(row);
  444. var startIndent = line.search(/\S/);
  445. var startRow = row;
  446. var startColumn = line.length;
  447. row = row + 1;
  448. var endRow = row;
  449. var maxRow = session.getLength();
  450. while (++row < maxRow) {
  451. line = session.getLine(row);
  452. var indent = line.search(/\S/);
  453. if (indent === -1)
  454. continue;
  455. if (startIndent > indent)
  456. break;
  457. var subRange = this.getFoldWidgetRange(session, "all", row);
  458. if (subRange) {
  459. if (subRange.start.row <= startRow) {
  460. break;
  461. } else if (subRange.isMultiLine()) {
  462. row = subRange.end.row;
  463. } else if (startIndent == indent) {
  464. break;
  465. }
  466. }
  467. endRow = row;
  468. }
  469. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  470. };
  471. this.getCommentRegionBlock = function(session, line, row) {
  472. var startColumn = line.search(/\s*$/);
  473. var maxRow = session.getLength();
  474. var startRow = row;
  475. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  476. var depth = 1;
  477. while (++row < maxRow) {
  478. line = session.getLine(row);
  479. var m = re.exec(line);
  480. if (!m) continue;
  481. if (m[1]) depth--;
  482. else depth++;
  483. if (!depth) break;
  484. }
  485. var endRow = row;
  486. if (endRow > startRow) {
  487. return new Range(startRow, startColumn, endRow, line.length);
  488. }
  489. };
  490. }).call(FoldMode.prototype);
  491. });
  492. ace.define("ace/mode/css",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/css_highlight_rules","ace/mode/matching_brace_outdent","ace/worker/worker_client","ace/mode/css_completions","ace/mode/behaviour/css","ace/mode/folding/cstyle"], function(require, exports, module) {
  493. "use strict";
  494. var oop = require("../lib/oop");
  495. var TextMode = require("./text").Mode;
  496. var CssHighlightRules = require("./css_highlight_rules").CssHighlightRules;
  497. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  498. var WorkerClient = require("../worker/worker_client").WorkerClient;
  499. var CssCompletions = require("./css_completions").CssCompletions;
  500. var CssBehaviour = require("./behaviour/css").CssBehaviour;
  501. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  502. var Mode = function() {
  503. this.HighlightRules = CssHighlightRules;
  504. this.$outdent = new MatchingBraceOutdent();
  505. this.$behaviour = new CssBehaviour();
  506. this.$completer = new CssCompletions();
  507. this.foldingRules = new CStyleFoldMode();
  508. };
  509. oop.inherits(Mode, TextMode);
  510. (function() {
  511. this.foldingRules = "cStyle";
  512. this.blockComment = {start: "/*", end: "*/"};
  513. this.getNextLineIndent = function(state, line, tab) {
  514. var indent = this.$getIndent(line);
  515. var tokens = this.getTokenizer().getLineTokens(line, state).tokens;
  516. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  517. return indent;
  518. }
  519. var match = line.match(/^.*\{\s*$/);
  520. if (match) {
  521. indent += tab;
  522. }
  523. return indent;
  524. };
  525. this.checkOutdent = function(state, line, input) {
  526. return this.$outdent.checkOutdent(line, input);
  527. };
  528. this.autoOutdent = function(state, doc, row) {
  529. this.$outdent.autoOutdent(doc, row);
  530. };
  531. this.getCompletions = function(state, session, pos, prefix) {
  532. return this.$completer.getCompletions(state, session, pos, prefix);
  533. };
  534. this.createWorker = function(session) {
  535. var worker = new WorkerClient(["ace"], "ace/mode/css_worker", "Worker");
  536. worker.attachToDocument(session.getDocument());
  537. worker.on("annotate", function(e) {
  538. session.setAnnotations(e.data);
  539. });
  540. worker.on("terminate", function() {
  541. session.clearAnnotations();
  542. });
  543. return worker;
  544. };
  545. this.$id = "ace/mode/css";
  546. }).call(Mode.prototype);
  547. exports.Mode = Mode;
  548. });