PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/assets/js/ace/worker-css.js

https://gitlab.com/nakome/admin-panel-morfy
JavaScript | 8682 lines | 8159 code | 515 blank | 8 comment | 599 complexity | a2bc13beff0a1ae8bdc1100b44522414 MD5 | raw file
  1. "no use strict";
  2. ;(function(window) {
  3. if (typeof window.window != "undefined" && window.document) {
  4. return;
  5. }
  6. window.console = function() {
  7. var msgs = Array.prototype.slice.call(arguments, 0);
  8. postMessage({type: "log", data: msgs});
  9. };
  10. window.console.error =
  11. window.console.warn =
  12. window.console.log =
  13. window.console.trace = window.console;
  14. window.window = window;
  15. window.ace = window;
  16. window.onerror = function(message, file, line, col, err) {
  17. postMessage({type: "error", data: {
  18. message: message,
  19. file: file,
  20. line: line,
  21. col: col,
  22. stack: err.stack
  23. }});
  24. };
  25. window.normalizeModule = function(parentId, moduleName) {
  26. // normalize plugin requires
  27. if (moduleName.indexOf("!") !== -1) {
  28. var chunks = moduleName.split("!");
  29. return window.normalizeModule(parentId, chunks[0]) + "!" + window.normalizeModule(parentId, chunks[1]);
  30. }
  31. // normalize relative requires
  32. if (moduleName.charAt(0) == ".") {
  33. var base = parentId.split("/").slice(0, -1).join("/");
  34. moduleName = (base ? base + "/" : "") + moduleName;
  35. while(moduleName.indexOf(".") !== -1 && previous != moduleName) {
  36. var previous = moduleName;
  37. moduleName = moduleName.replace(/^\.\//, "").replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
  38. }
  39. }
  40. return moduleName;
  41. };
  42. window.require = function(parentId, id) {
  43. if (!id) {
  44. id = parentId;
  45. parentId = null;
  46. }
  47. if (!id.charAt)
  48. throw new Error("worker.js require() accepts only (parentId, id) as arguments");
  49. id = window.normalizeModule(parentId, id);
  50. var module = window.require.modules[id];
  51. if (module) {
  52. if (!module.initialized) {
  53. module.initialized = true;
  54. module.exports = module.factory().exports;
  55. }
  56. return module.exports;
  57. }
  58. var chunks = id.split("/");
  59. if (!window.require.tlns)
  60. return console.log("unable to load " + id);
  61. chunks[0] = window.require.tlns[chunks[0]] || chunks[0];
  62. var path = chunks.join("/") + ".js";
  63. window.require.id = id;
  64. importScripts(path);
  65. return window.require(parentId, id);
  66. };
  67. window.require.modules = {};
  68. window.require.tlns = {};
  69. window.define = function(id, deps, factory) {
  70. if (arguments.length == 2) {
  71. factory = deps;
  72. if (typeof id != "string") {
  73. deps = id;
  74. id = window.require.id;
  75. }
  76. } else if (arguments.length == 1) {
  77. factory = id;
  78. deps = [];
  79. id = window.require.id;
  80. }
  81. if (typeof factory != "function") {
  82. window.require.modules[id] = {
  83. exports: factory,
  84. initialized: true
  85. };
  86. return;
  87. }
  88. if (!deps.length)
  89. // If there is no dependencies, we inject 'require', 'exports' and
  90. // 'module' as dependencies, to provide CommonJS compatibility.
  91. deps = ['require', 'exports', 'module'];
  92. var req = function(childId) {
  93. return window.require(id, childId);
  94. };
  95. window.require.modules[id] = {
  96. exports: {},
  97. factory: function() {
  98. var module = this;
  99. var returnExports = factory.apply(this, deps.map(function(dep) {
  100. switch(dep) {
  101. // Because 'require', 'exports' and 'module' aren't actual
  102. // dependencies, we must handle them seperately.
  103. case 'require': return req;
  104. case 'exports': return module.exports;
  105. case 'module': return module;
  106. // But for all other dependencies, we can just go ahead and
  107. // require them.
  108. default: return req(dep);
  109. }
  110. }));
  111. if (returnExports)
  112. module.exports = returnExports;
  113. return module;
  114. }
  115. };
  116. };
  117. window.define.amd = {};
  118. window.initBaseUrls = function initBaseUrls(topLevelNamespaces) {
  119. require.tlns = topLevelNamespaces;
  120. };
  121. window.initSender = function initSender() {
  122. var EventEmitter = window.require("ace/lib/event_emitter").EventEmitter;
  123. var oop = window.require("ace/lib/oop");
  124. var Sender = function() {};
  125. (function() {
  126. oop.implement(this, EventEmitter);
  127. this.callback = function(data, callbackId) {
  128. postMessage({
  129. type: "call",
  130. id: callbackId,
  131. data: data
  132. });
  133. };
  134. this.emit = function(name, data) {
  135. postMessage({
  136. type: "event",
  137. name: name,
  138. data: data
  139. });
  140. };
  141. }).call(Sender.prototype);
  142. return new Sender();
  143. };
  144. var main = window.main = null;
  145. var sender = window.sender = null;
  146. window.onmessage = function(e) {
  147. var msg = e.data;
  148. if (msg.command) {
  149. if (main[msg.command])
  150. main[msg.command].apply(main, msg.args);
  151. else
  152. throw new Error("Unknown command:" + msg.command);
  153. }
  154. else if (msg.init) {
  155. initBaseUrls(msg.tlns);
  156. require("ace/lib/es5-shim");
  157. sender = window.sender = initSender();
  158. var clazz = require(msg.module)[msg.classname];
  159. main = window.main = new clazz(sender);
  160. }
  161. else if (msg.event && sender) {
  162. sender._signal(msg.event, msg.data);
  163. }
  164. };
  165. })(this);
  166. ace.define("ace/lib/oop",["require","exports","module"], function(require, exports, module) {
  167. "use strict";
  168. exports.inherits = function(ctor, superCtor) {
  169. ctor.super_ = superCtor;
  170. ctor.prototype = Object.create(superCtor.prototype, {
  171. constructor: {
  172. value: ctor,
  173. enumerable: false,
  174. writable: true,
  175. configurable: true
  176. }
  177. });
  178. };
  179. exports.mixin = function(obj, mixin) {
  180. for (var key in mixin) {
  181. obj[key] = mixin[key];
  182. }
  183. return obj;
  184. };
  185. exports.implement = function(proto, mixin) {
  186. exports.mixin(proto, mixin);
  187. };
  188. });
  189. ace.define("ace/lib/lang",["require","exports","module"], function(require, exports, module) {
  190. "use strict";
  191. exports.last = function(a) {
  192. return a[a.length - 1];
  193. };
  194. exports.stringReverse = function(string) {
  195. return string.split("").reverse().join("");
  196. };
  197. exports.stringRepeat = function (string, count) {
  198. var result = '';
  199. while (count > 0) {
  200. if (count & 1)
  201. result += string;
  202. if (count >>= 1)
  203. string += string;
  204. }
  205. return result;
  206. };
  207. var trimBeginRegexp = /^\s\s*/;
  208. var trimEndRegexp = /\s\s*$/;
  209. exports.stringTrimLeft = function (string) {
  210. return string.replace(trimBeginRegexp, '');
  211. };
  212. exports.stringTrimRight = function (string) {
  213. return string.replace(trimEndRegexp, '');
  214. };
  215. exports.copyObject = function(obj) {
  216. var copy = {};
  217. for (var key in obj) {
  218. copy[key] = obj[key];
  219. }
  220. return copy;
  221. };
  222. exports.copyArray = function(array){
  223. var copy = [];
  224. for (var i=0, l=array.length; i<l; i++) {
  225. if (array[i] && typeof array[i] == "object")
  226. copy[i] = this.copyObject( array[i] );
  227. else
  228. copy[i] = array[i];
  229. }
  230. return copy;
  231. };
  232. exports.deepCopy = function (obj) {
  233. if (typeof obj !== "object" || !obj)
  234. return obj;
  235. var cons = obj.constructor;
  236. if (cons === RegExp)
  237. return obj;
  238. var copy = cons();
  239. for (var key in obj) {
  240. if (typeof obj[key] === "object") {
  241. copy[key] = exports.deepCopy(obj[key]);
  242. } else {
  243. copy[key] = obj[key];
  244. }
  245. }
  246. return copy;
  247. };
  248. exports.arrayToMap = function(arr) {
  249. var map = {};
  250. for (var i=0; i<arr.length; i++) {
  251. map[arr[i]] = 1;
  252. }
  253. return map;
  254. };
  255. exports.createMap = function(props) {
  256. var map = Object.create(null);
  257. for (var i in props) {
  258. map[i] = props[i];
  259. }
  260. return map;
  261. };
  262. exports.arrayRemove = function(array, value) {
  263. for (var i = 0; i <= array.length; i++) {
  264. if (value === array[i]) {
  265. array.splice(i, 1);
  266. }
  267. }
  268. };
  269. exports.escapeRegExp = function(str) {
  270. return str.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1');
  271. };
  272. exports.escapeHTML = function(str) {
  273. return str.replace(/&/g, "&#38;").replace(/"/g, "&#34;").replace(/'/g, "&#39;").replace(/</g, "&#60;");
  274. };
  275. exports.getMatchOffsets = function(string, regExp) {
  276. var matches = [];
  277. string.replace(regExp, function(str) {
  278. matches.push({
  279. offset: arguments[arguments.length-2],
  280. length: str.length
  281. });
  282. });
  283. return matches;
  284. };
  285. exports.deferredCall = function(fcn) {
  286. var timer = null;
  287. var callback = function() {
  288. timer = null;
  289. fcn();
  290. };
  291. var deferred = function(timeout) {
  292. deferred.cancel();
  293. timer = setTimeout(callback, timeout || 0);
  294. return deferred;
  295. };
  296. deferred.schedule = deferred;
  297. deferred.call = function() {
  298. this.cancel();
  299. fcn();
  300. return deferred;
  301. };
  302. deferred.cancel = function() {
  303. clearTimeout(timer);
  304. timer = null;
  305. return deferred;
  306. };
  307. deferred.isPending = function() {
  308. return timer;
  309. };
  310. return deferred;
  311. };
  312. exports.delayedCall = function(fcn, defaultTimeout) {
  313. var timer = null;
  314. var callback = function() {
  315. timer = null;
  316. fcn();
  317. };
  318. var _self = function(timeout) {
  319. if (timer == null)
  320. timer = setTimeout(callback, timeout || defaultTimeout);
  321. };
  322. _self.delay = function(timeout) {
  323. timer && clearTimeout(timer);
  324. timer = setTimeout(callback, timeout || defaultTimeout);
  325. };
  326. _self.schedule = _self;
  327. _self.call = function() {
  328. this.cancel();
  329. fcn();
  330. };
  331. _self.cancel = function() {
  332. timer && clearTimeout(timer);
  333. timer = null;
  334. };
  335. _self.isPending = function() {
  336. return timer;
  337. };
  338. return _self;
  339. };
  340. });
  341. ace.define("ace/lib/event_emitter",["require","exports","module"], function(require, exports, module) {
  342. "use strict";
  343. var EventEmitter = {};
  344. var stopPropagation = function() { this.propagationStopped = true; };
  345. var preventDefault = function() { this.defaultPrevented = true; };
  346. EventEmitter._emit =
  347. EventEmitter._dispatchEvent = function(eventName, e) {
  348. this._eventRegistry || (this._eventRegistry = {});
  349. this._defaultHandlers || (this._defaultHandlers = {});
  350. var listeners = this._eventRegistry[eventName] || [];
  351. var defaultHandler = this._defaultHandlers[eventName];
  352. if (!listeners.length && !defaultHandler)
  353. return;
  354. if (typeof e != "object" || !e)
  355. e = {};
  356. if (!e.type)
  357. e.type = eventName;
  358. if (!e.stopPropagation)
  359. e.stopPropagation = stopPropagation;
  360. if (!e.preventDefault)
  361. e.preventDefault = preventDefault;
  362. listeners = listeners.slice();
  363. for (var i=0; i<listeners.length; i++) {
  364. listeners[i](e, this);
  365. if (e.propagationStopped)
  366. break;
  367. }
  368. if (defaultHandler && !e.defaultPrevented)
  369. return defaultHandler(e, this);
  370. };
  371. EventEmitter._signal = function(eventName, e) {
  372. var listeners = (this._eventRegistry || {})[eventName];
  373. if (!listeners)
  374. return;
  375. listeners = listeners.slice();
  376. for (var i=0; i<listeners.length; i++)
  377. listeners[i](e, this);
  378. };
  379. EventEmitter.once = function(eventName, callback) {
  380. var _self = this;
  381. callback && this.addEventListener(eventName, function newCallback() {
  382. _self.removeEventListener(eventName, newCallback);
  383. callback.apply(null, arguments);
  384. });
  385. };
  386. EventEmitter.setDefaultHandler = function(eventName, callback) {
  387. var handlers = this._defaultHandlers
  388. if (!handlers)
  389. handlers = this._defaultHandlers = {_disabled_: {}};
  390. if (handlers[eventName]) {
  391. var old = handlers[eventName];
  392. var disabled = handlers._disabled_[eventName];
  393. if (!disabled)
  394. handlers._disabled_[eventName] = disabled = [];
  395. disabled.push(old);
  396. var i = disabled.indexOf(callback);
  397. if (i != -1)
  398. disabled.splice(i, 1);
  399. }
  400. handlers[eventName] = callback;
  401. };
  402. EventEmitter.removeDefaultHandler = function(eventName, callback) {
  403. var handlers = this._defaultHandlers
  404. if (!handlers)
  405. return;
  406. var disabled = handlers._disabled_[eventName];
  407. if (handlers[eventName] == callback) {
  408. var old = handlers[eventName];
  409. if (disabled)
  410. this.setDefaultHandler(eventName, disabled.pop());
  411. } else if (disabled) {
  412. var i = disabled.indexOf(callback);
  413. if (i != -1)
  414. disabled.splice(i, 1);
  415. }
  416. };
  417. EventEmitter.on =
  418. EventEmitter.addEventListener = function(eventName, callback, capturing) {
  419. this._eventRegistry = this._eventRegistry || {};
  420. var listeners = this._eventRegistry[eventName];
  421. if (!listeners)
  422. listeners = this._eventRegistry[eventName] = [];
  423. if (listeners.indexOf(callback) == -1)
  424. listeners[capturing ? "unshift" : "push"](callback);
  425. return callback;
  426. };
  427. EventEmitter.off =
  428. EventEmitter.removeListener =
  429. EventEmitter.removeEventListener = function(eventName, callback) {
  430. this._eventRegistry = this._eventRegistry || {};
  431. var listeners = this._eventRegistry[eventName];
  432. if (!listeners)
  433. return;
  434. var index = listeners.indexOf(callback);
  435. if (index !== -1)
  436. listeners.splice(index, 1);
  437. };
  438. EventEmitter.removeAllListeners = function(eventName) {
  439. if (this._eventRegistry) this._eventRegistry[eventName] = [];
  440. };
  441. exports.EventEmitter = EventEmitter;
  442. });
  443. ace.define("ace/range",["require","exports","module"], function(require, exports, module) {
  444. "use strict";
  445. var comparePoints = function(p1, p2) {
  446. return p1.row - p2.row || p1.column - p2.column;
  447. };
  448. var Range = function(startRow, startColumn, endRow, endColumn) {
  449. this.start = {
  450. row: startRow,
  451. column: startColumn
  452. };
  453. this.end = {
  454. row: endRow,
  455. column: endColumn
  456. };
  457. };
  458. (function() {
  459. this.isEqual = function(range) {
  460. return this.start.row === range.start.row &&
  461. this.end.row === range.end.row &&
  462. this.start.column === range.start.column &&
  463. this.end.column === range.end.column;
  464. };
  465. this.toString = function() {
  466. return ("Range: [" + this.start.row + "/" + this.start.column +
  467. "] -> [" + this.end.row + "/" + this.end.column + "]");
  468. };
  469. this.contains = function(row, column) {
  470. return this.compare(row, column) == 0;
  471. };
  472. this.compareRange = function(range) {
  473. var cmp,
  474. end = range.end,
  475. start = range.start;
  476. cmp = this.compare(end.row, end.column);
  477. if (cmp == 1) {
  478. cmp = this.compare(start.row, start.column);
  479. if (cmp == 1) {
  480. return 2;
  481. } else if (cmp == 0) {
  482. return 1;
  483. } else {
  484. return 0;
  485. }
  486. } else if (cmp == -1) {
  487. return -2;
  488. } else {
  489. cmp = this.compare(start.row, start.column);
  490. if (cmp == -1) {
  491. return -1;
  492. } else if (cmp == 1) {
  493. return 42;
  494. } else {
  495. return 0;
  496. }
  497. }
  498. };
  499. this.comparePoint = function(p) {
  500. return this.compare(p.row, p.column);
  501. };
  502. this.containsRange = function(range) {
  503. return this.comparePoint(range.start) == 0 && this.comparePoint(range.end) == 0;
  504. };
  505. this.intersects = function(range) {
  506. var cmp = this.compareRange(range);
  507. return (cmp == -1 || cmp == 0 || cmp == 1);
  508. };
  509. this.isEnd = function(row, column) {
  510. return this.end.row == row && this.end.column == column;
  511. };
  512. this.isStart = function(row, column) {
  513. return this.start.row == row && this.start.column == column;
  514. };
  515. this.setStart = function(row, column) {
  516. if (typeof row == "object") {
  517. this.start.column = row.column;
  518. this.start.row = row.row;
  519. } else {
  520. this.start.row = row;
  521. this.start.column = column;
  522. }
  523. };
  524. this.setEnd = function(row, column) {
  525. if (typeof row == "object") {
  526. this.end.column = row.column;
  527. this.end.row = row.row;
  528. } else {
  529. this.end.row = row;
  530. this.end.column = column;
  531. }
  532. };
  533. this.inside = function(row, column) {
  534. if (this.compare(row, column) == 0) {
  535. if (this.isEnd(row, column) || this.isStart(row, column)) {
  536. return false;
  537. } else {
  538. return true;
  539. }
  540. }
  541. return false;
  542. };
  543. this.insideStart = function(row, column) {
  544. if (this.compare(row, column) == 0) {
  545. if (this.isEnd(row, column)) {
  546. return false;
  547. } else {
  548. return true;
  549. }
  550. }
  551. return false;
  552. };
  553. this.insideEnd = function(row, column) {
  554. if (this.compare(row, column) == 0) {
  555. if (this.isStart(row, column)) {
  556. return false;
  557. } else {
  558. return true;
  559. }
  560. }
  561. return false;
  562. };
  563. this.compare = function(row, column) {
  564. if (!this.isMultiLine()) {
  565. if (row === this.start.row) {
  566. return column < this.start.column ? -1 : (column > this.end.column ? 1 : 0);
  567. };
  568. }
  569. if (row < this.start.row)
  570. return -1;
  571. if (row > this.end.row)
  572. return 1;
  573. if (this.start.row === row)
  574. return column >= this.start.column ? 0 : -1;
  575. if (this.end.row === row)
  576. return column <= this.end.column ? 0 : 1;
  577. return 0;
  578. };
  579. this.compareStart = function(row, column) {
  580. if (this.start.row == row && this.start.column == column) {
  581. return -1;
  582. } else {
  583. return this.compare(row, column);
  584. }
  585. };
  586. this.compareEnd = function(row, column) {
  587. if (this.end.row == row && this.end.column == column) {
  588. return 1;
  589. } else {
  590. return this.compare(row, column);
  591. }
  592. };
  593. this.compareInside = function(row, column) {
  594. if (this.end.row == row && this.end.column == column) {
  595. return 1;
  596. } else if (this.start.row == row && this.start.column == column) {
  597. return -1;
  598. } else {
  599. return this.compare(row, column);
  600. }
  601. };
  602. this.clipRows = function(firstRow, lastRow) {
  603. if (this.end.row > lastRow)
  604. var end = {row: lastRow + 1, column: 0};
  605. else if (this.end.row < firstRow)
  606. var end = {row: firstRow, column: 0};
  607. if (this.start.row > lastRow)
  608. var start = {row: lastRow + 1, column: 0};
  609. else if (this.start.row < firstRow)
  610. var start = {row: firstRow, column: 0};
  611. return Range.fromPoints(start || this.start, end || this.end);
  612. };
  613. this.extend = function(row, column) {
  614. var cmp = this.compare(row, column);
  615. if (cmp == 0)
  616. return this;
  617. else if (cmp == -1)
  618. var start = {row: row, column: column};
  619. else
  620. var end = {row: row, column: column};
  621. return Range.fromPoints(start || this.start, end || this.end);
  622. };
  623. this.isEmpty = function() {
  624. return (this.start.row === this.end.row && this.start.column === this.end.column);
  625. };
  626. this.isMultiLine = function() {
  627. return (this.start.row !== this.end.row);
  628. };
  629. this.clone = function() {
  630. return Range.fromPoints(this.start, this.end);
  631. };
  632. this.collapseRows = function() {
  633. if (this.end.column == 0)
  634. return new Range(this.start.row, 0, Math.max(this.start.row, this.end.row-1), 0)
  635. else
  636. return new Range(this.start.row, 0, this.end.row, 0)
  637. };
  638. this.toScreenRange = function(session) {
  639. var screenPosStart = session.documentToScreenPosition(this.start);
  640. var screenPosEnd = session.documentToScreenPosition(this.end);
  641. return new Range(
  642. screenPosStart.row, screenPosStart.column,
  643. screenPosEnd.row, screenPosEnd.column
  644. );
  645. };
  646. this.moveBy = function(row, column) {
  647. this.start.row += row;
  648. this.start.column += column;
  649. this.end.row += row;
  650. this.end.column += column;
  651. };
  652. }).call(Range.prototype);
  653. Range.fromPoints = function(start, end) {
  654. return new Range(start.row, start.column, end.row, end.column);
  655. };
  656. Range.comparePoints = comparePoints;
  657. Range.comparePoints = function(p1, p2) {
  658. return p1.row - p2.row || p1.column - p2.column;
  659. };
  660. exports.Range = Range;
  661. });
  662. ace.define("ace/anchor",["require","exports","module","ace/lib/oop","ace/lib/event_emitter"], function(require, exports, module) {
  663. "use strict";
  664. var oop = require("./lib/oop");
  665. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  666. var Anchor = exports.Anchor = function(doc, row, column) {
  667. this.$onChange = this.onChange.bind(this);
  668. this.attach(doc);
  669. if (typeof column == "undefined")
  670. this.setPosition(row.row, row.column);
  671. else
  672. this.setPosition(row, column);
  673. };
  674. (function() {
  675. oop.implement(this, EventEmitter);
  676. this.getPosition = function() {
  677. return this.$clipPositionToDocument(this.row, this.column);
  678. };
  679. this.getDocument = function() {
  680. return this.document;
  681. };
  682. this.$insertRight = false;
  683. this.onChange = function(e) {
  684. var delta = e.data;
  685. var range = delta.range;
  686. if (range.start.row == range.end.row && range.start.row != this.row)
  687. return;
  688. if (range.start.row > this.row)
  689. return;
  690. if (range.start.row == this.row && range.start.column > this.column)
  691. return;
  692. var row = this.row;
  693. var column = this.column;
  694. var start = range.start;
  695. var end = range.end;
  696. if (delta.action === "insertText") {
  697. if (start.row === row && start.column <= column) {
  698. if (start.column === column && this.$insertRight) {
  699. } else if (start.row === end.row) {
  700. column += end.column - start.column;
  701. } else {
  702. column -= start.column;
  703. row += end.row - start.row;
  704. }
  705. } else if (start.row !== end.row && start.row < row) {
  706. row += end.row - start.row;
  707. }
  708. } else if (delta.action === "insertLines") {
  709. if (start.row === row && column === 0 && this.$insertRight) {
  710. }
  711. else if (start.row <= row) {
  712. row += end.row - start.row;
  713. }
  714. } else if (delta.action === "removeText") {
  715. if (start.row === row && start.column < column) {
  716. if (end.column >= column)
  717. column = start.column;
  718. else
  719. column = Math.max(0, column - (end.column - start.column));
  720. } else if (start.row !== end.row && start.row < row) {
  721. if (end.row === row)
  722. column = Math.max(0, column - end.column) + start.column;
  723. row -= (end.row - start.row);
  724. } else if (end.row === row) {
  725. row -= end.row - start.row;
  726. column = Math.max(0, column - end.column) + start.column;
  727. }
  728. } else if (delta.action == "removeLines") {
  729. if (start.row <= row) {
  730. if (end.row <= row)
  731. row -= end.row - start.row;
  732. else {
  733. row = start.row;
  734. column = 0;
  735. }
  736. }
  737. }
  738. this.setPosition(row, column, true);
  739. };
  740. this.setPosition = function(row, column, noClip) {
  741. var pos;
  742. if (noClip) {
  743. pos = {
  744. row: row,
  745. column: column
  746. };
  747. } else {
  748. pos = this.$clipPositionToDocument(row, column);
  749. }
  750. if (this.row == pos.row && this.column == pos.column)
  751. return;
  752. var old = {
  753. row: this.row,
  754. column: this.column
  755. };
  756. this.row = pos.row;
  757. this.column = pos.column;
  758. this._signal("change", {
  759. old: old,
  760. value: pos
  761. });
  762. };
  763. this.detach = function() {
  764. this.document.removeEventListener("change", this.$onChange);
  765. };
  766. this.attach = function(doc) {
  767. this.document = doc || this.document;
  768. this.document.on("change", this.$onChange);
  769. };
  770. this.$clipPositionToDocument = function(row, column) {
  771. var pos = {};
  772. if (row >= this.document.getLength()) {
  773. pos.row = Math.max(0, this.document.getLength() - 1);
  774. pos.column = this.document.getLine(pos.row).length;
  775. }
  776. else if (row < 0) {
  777. pos.row = 0;
  778. pos.column = 0;
  779. }
  780. else {
  781. pos.row = row;
  782. pos.column = Math.min(this.document.getLine(pos.row).length, Math.max(0, column));
  783. }
  784. if (column < 0)
  785. pos.column = 0;
  786. return pos;
  787. };
  788. }).call(Anchor.prototype);
  789. });
  790. ace.define("ace/document",["require","exports","module","ace/lib/oop","ace/lib/event_emitter","ace/range","ace/anchor"], function(require, exports, module) {
  791. "use strict";
  792. var oop = require("./lib/oop");
  793. var EventEmitter = require("./lib/event_emitter").EventEmitter;
  794. var Range = require("./range").Range;
  795. var Anchor = require("./anchor").Anchor;
  796. var Document = function(text) {
  797. this.$lines = [];
  798. if (text.length === 0) {
  799. this.$lines = [""];
  800. } else if (Array.isArray(text)) {
  801. this._insertLines(0, text);
  802. } else {
  803. this.insert({row: 0, column:0}, text);
  804. }
  805. };
  806. (function() {
  807. oop.implement(this, EventEmitter);
  808. this.setValue = function(text) {
  809. var len = this.getLength();
  810. this.remove(new Range(0, 0, len, this.getLine(len-1).length));
  811. this.insert({row: 0, column:0}, text);
  812. };
  813. this.getValue = function() {
  814. return this.getAllLines().join(this.getNewLineCharacter());
  815. };
  816. this.createAnchor = function(row, column) {
  817. return new Anchor(this, row, column);
  818. };
  819. if ("aaa".split(/a/).length === 0)
  820. this.$split = function(text) {
  821. return text.replace(/\r\n|\r/g, "\n").split("\n");
  822. };
  823. else
  824. this.$split = function(text) {
  825. return text.split(/\r\n|\r|\n/);
  826. };
  827. this.$detectNewLine = function(text) {
  828. var match = text.match(/^.*?(\r\n|\r|\n)/m);
  829. this.$autoNewLine = match ? match[1] : "\n";
  830. this._signal("changeNewLineMode");
  831. };
  832. this.getNewLineCharacter = function() {
  833. switch (this.$newLineMode) {
  834. case "windows":
  835. return "\r\n";
  836. case "unix":
  837. return "\n";
  838. default:
  839. return this.$autoNewLine || "\n";
  840. }
  841. };
  842. this.$autoNewLine = "";
  843. this.$newLineMode = "auto";
  844. this.setNewLineMode = function(newLineMode) {
  845. if (this.$newLineMode === newLineMode)
  846. return;
  847. this.$newLineMode = newLineMode;
  848. this._signal("changeNewLineMode");
  849. };
  850. this.getNewLineMode = function() {
  851. return this.$newLineMode;
  852. };
  853. this.isNewLine = function(text) {
  854. return (text == "\r\n" || text == "\r" || text == "\n");
  855. };
  856. this.getLine = function(row) {
  857. return this.$lines[row] || "";
  858. };
  859. this.getLines = function(firstRow, lastRow) {
  860. return this.$lines.slice(firstRow, lastRow + 1);
  861. };
  862. this.getAllLines = function() {
  863. return this.getLines(0, this.getLength());
  864. };
  865. this.getLength = function() {
  866. return this.$lines.length;
  867. };
  868. this.getTextRange = function(range) {
  869. if (range.start.row == range.end.row) {
  870. return this.getLine(range.start.row)
  871. .substring(range.start.column, range.end.column);
  872. }
  873. var lines = this.getLines(range.start.row, range.end.row);
  874. lines[0] = (lines[0] || "").substring(range.start.column);
  875. var l = lines.length - 1;
  876. if (range.end.row - range.start.row == l)
  877. lines[l] = lines[l].substring(0, range.end.column);
  878. return lines.join(this.getNewLineCharacter());
  879. };
  880. this.$clipPosition = function(position) {
  881. var length = this.getLength();
  882. if (position.row >= length) {
  883. position.row = Math.max(0, length - 1);
  884. position.column = this.getLine(length-1).length;
  885. } else if (position.row < 0)
  886. position.row = 0;
  887. return position;
  888. };
  889. this.insert = function(position, text) {
  890. if (!text || text.length === 0)
  891. return position;
  892. position = this.$clipPosition(position);
  893. if (this.getLength() <= 1)
  894. this.$detectNewLine(text);
  895. var lines = this.$split(text);
  896. var firstLine = lines.splice(0, 1)[0];
  897. var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
  898. position = this.insertInLine(position, firstLine);
  899. if (lastLine !== null) {
  900. position = this.insertNewLine(position); // terminate first line
  901. position = this._insertLines(position.row, lines);
  902. position = this.insertInLine(position, lastLine || "");
  903. }
  904. return position;
  905. };
  906. this.insertLines = function(row, lines) {
  907. if (row >= this.getLength())
  908. return this.insert({row: row, column: 0}, "\n" + lines.join("\n"));
  909. return this._insertLines(Math.max(row, 0), lines);
  910. };
  911. this._insertLines = function(row, lines) {
  912. if (lines.length == 0)
  913. return {row: row, column: 0};
  914. while (lines.length > 0xF000) {
  915. var end = this._insertLines(row, lines.slice(0, 0xF000));
  916. lines = lines.slice(0xF000);
  917. row = end.row;
  918. }
  919. var args = [row, 0];
  920. args.push.apply(args, lines);
  921. this.$lines.splice.apply(this.$lines, args);
  922. var range = new Range(row, 0, row + lines.length, 0);
  923. var delta = {
  924. action: "insertLines",
  925. range: range,
  926. lines: lines
  927. };
  928. this._signal("change", { data: delta });
  929. return range.end;
  930. };
  931. this.insertNewLine = function(position) {
  932. position = this.$clipPosition(position);
  933. var line = this.$lines[position.row] || "";
  934. this.$lines[position.row] = line.substring(0, position.column);
  935. this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length));
  936. var end = {
  937. row : position.row + 1,
  938. column : 0
  939. };
  940. var delta = {
  941. action: "insertText",
  942. range: Range.fromPoints(position, end),
  943. text: this.getNewLineCharacter()
  944. };
  945. this._signal("change", { data: delta });
  946. return end;
  947. };
  948. this.insertInLine = function(position, text) {
  949. if (text.length == 0)
  950. return position;
  951. var line = this.$lines[position.row] || "";
  952. this.$lines[position.row] = line.substring(0, position.column) + text
  953. + line.substring(position.column);
  954. var end = {
  955. row : position.row,
  956. column : position.column + text.length
  957. };
  958. var delta = {
  959. action: "insertText",
  960. range: Range.fromPoints(position, end),
  961. text: text
  962. };
  963. this._signal("change", { data: delta });
  964. return end;
  965. };
  966. this.remove = function(range) {
  967. if (!(range instanceof Range))
  968. range = Range.fromPoints(range.start, range.end);
  969. range.start = this.$clipPosition(range.start);
  970. range.end = this.$clipPosition(range.end);
  971. if (range.isEmpty())
  972. return range.start;
  973. var firstRow = range.start.row;
  974. var lastRow = range.end.row;
  975. if (range.isMultiLine()) {
  976. var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
  977. var lastFullRow = lastRow - 1;
  978. if (range.end.column > 0)
  979. this.removeInLine(lastRow, 0, range.end.column);
  980. if (lastFullRow >= firstFullRow)
  981. this._removeLines(firstFullRow, lastFullRow);
  982. if (firstFullRow != firstRow) {
  983. this.removeInLine(firstRow, range.start.column, this.getLine(firstRow).length);
  984. this.removeNewLine(range.start.row);
  985. }
  986. }
  987. else {
  988. this.removeInLine(firstRow, range.start.column, range.end.column);
  989. }
  990. return range.start;
  991. };
  992. this.removeInLine = function(row, startColumn, endColumn) {
  993. if (startColumn == endColumn)
  994. return;
  995. var range = new Range(row, startColumn, row, endColumn);
  996. var line = this.getLine(row);
  997. var removed = line.substring(startColumn, endColumn);
  998. var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length);
  999. this.$lines.splice(row, 1, newLine);
  1000. var delta = {
  1001. action: "removeText",
  1002. range: range,
  1003. text: removed
  1004. };
  1005. this._signal("change", { data: delta });
  1006. return range.start;
  1007. };
  1008. this.removeLines = function(firstRow, lastRow) {
  1009. if (firstRow < 0 || lastRow >= this.getLength())
  1010. return this.remove(new Range(firstRow, 0, lastRow + 1, 0));
  1011. return this._removeLines(firstRow, lastRow);
  1012. };
  1013. this._removeLines = function(firstRow, lastRow) {
  1014. var range = new Range(firstRow, 0, lastRow + 1, 0);
  1015. var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
  1016. var delta = {
  1017. action: "removeLines",
  1018. range: range,
  1019. nl: this.getNewLineCharacter(),
  1020. lines: removed
  1021. };
  1022. this._signal("change", { data: delta });
  1023. return removed;
  1024. };
  1025. this.removeNewLine = function(row) {
  1026. var firstLine = this.getLine(row);
  1027. var secondLine = this.getLine(row+1);
  1028. var range = new Range(row, firstLine.length, row+1, 0);
  1029. var line = firstLine + secondLine;
  1030. this.$lines.splice(row, 2, line);
  1031. var delta = {
  1032. action: "removeText",
  1033. range: range,
  1034. text: this.getNewLineCharacter()
  1035. };
  1036. this._signal("change", { data: delta });
  1037. };
  1038. this.replace = function(range, text) {
  1039. if (!(range instanceof Range))
  1040. range = Range.fromPoints(range.start, range.end);
  1041. if (text.length == 0 && range.isEmpty())
  1042. return range.start;
  1043. if (text == this.getTextRange(range))
  1044. return range.end;
  1045. this.remove(range);
  1046. if (text) {
  1047. var end = this.insert(range.start, text);
  1048. }
  1049. else {
  1050. end = range.start;
  1051. }
  1052. return end;
  1053. };
  1054. this.applyDeltas = function(deltas) {
  1055. for (var i=0; i<deltas.length; i++) {
  1056. var delta = deltas[i];
  1057. var range = Range.fromPoints(delta.range.start, delta.range.end);
  1058. if (delta.action == "insertLines")
  1059. this.insertLines(range.start.row, delta.lines);
  1060. else if (delta.action == "insertText")
  1061. this.insert(range.start, delta.text);
  1062. else if (delta.action == "removeLines")
  1063. this._removeLines(range.start.row, range.end.row - 1);
  1064. else if (delta.action == "removeText")
  1065. this.remove(range);
  1066. }
  1067. };
  1068. this.revertDeltas = function(deltas) {
  1069. for (var i=deltas.length-1; i>=0; i--) {
  1070. var delta = deltas[i];
  1071. var range = Range.fromPoints(delta.range.start, delta.range.end);
  1072. if (delta.action == "insertLines")
  1073. this._removeLines(range.start.row, range.end.row - 1);
  1074. else if (delta.action == "insertText")
  1075. this.remove(range);
  1076. else if (delta.action == "removeLines")
  1077. this._insertLines(range.start.row, delta.lines);
  1078. else if (delta.action == "removeText")
  1079. this.insert(range.start, delta.text);
  1080. }
  1081. };
  1082. this.indexToPosition = function(index, startRow) {
  1083. var lines = this.$lines || this.getAllLines();
  1084. var newlineLength = this.getNewLineCharacter().length;
  1085. for (var i = startRow || 0, l = lines.length; i < l; i++) {
  1086. index -= lines[i].length + newlineLength;
  1087. if (index < 0)
  1088. return {row: i, column: index + lines[i].length + newlineLength};
  1089. }
  1090. return {row: l-1, column: lines[l-1].length};
  1091. };
  1092. this.positionToIndex = function(pos, startRow) {
  1093. var lines = this.$lines || this.getAllLines();
  1094. var newlineLength = this.getNewLineCharacter().length;
  1095. var index = 0;
  1096. var row = Math.min(pos.row, lines.length);
  1097. for (var i = startRow || 0; i < row; ++i)
  1098. index += lines[i].length + newlineLength;
  1099. return index + pos.column;
  1100. };
  1101. }).call(Document.prototype);
  1102. exports.Document = Document;
  1103. });
  1104. ace.define("ace/worker/mirror",["require","exports","module","ace/document","ace/lib/lang"], function(require, exports, module) {
  1105. "use strict";
  1106. var Document = require("../document").Document;
  1107. var lang = require("../lib/lang");
  1108. var Mirror = exports.Mirror = function(sender) {
  1109. this.sender = sender;
  1110. var doc = this.doc = new Document("");
  1111. var deferredUpdate = this.deferredUpdate = lang.delayedCall(this.onUpdate.bind(this));
  1112. var _self = this;
  1113. sender.on("change", function(e) {
  1114. doc.applyDeltas(e.data);
  1115. if (_self.$timeout)
  1116. return deferredUpdate.schedule(_self.$timeout);
  1117. _self.onUpdate();
  1118. });
  1119. };
  1120. (function() {
  1121. this.$timeout = 500;
  1122. this.setTimeout = function(timeout) {
  1123. this.$timeout = timeout;
  1124. };
  1125. this.setValue = function(value) {
  1126. this.doc.setValue(value);
  1127. this.deferredUpdate.schedule(this.$timeout);
  1128. };
  1129. this.getValue = function(callbackId) {
  1130. this.sender.callback(this.doc.getValue(), callbackId);
  1131. };
  1132. this.onUpdate = function() {
  1133. };
  1134. this.isPending = function() {
  1135. return this.deferredUpdate.isPending();
  1136. };
  1137. }).call(Mirror.prototype);
  1138. });
  1139. ace.define("ace/mode/css/csslint",["require","exports","module"], function(require, exports, module) {
  1140. var parserlib = {};
  1141. (function(){
  1142. function EventTarget(){
  1143. this._listeners = {};
  1144. }
  1145. EventTarget.prototype = {
  1146. constructor: EventTarget,
  1147. addListener: function(type, listener){
  1148. if (!this._listeners[type]){
  1149. this._listeners[type] = [];
  1150. }
  1151. this._listeners[type].push(listener);
  1152. },
  1153. fire: function(event){
  1154. if (typeof event == "string"){
  1155. event = { type: event };
  1156. }
  1157. if (typeof event.target != "undefined"){
  1158. event.target = this;
  1159. }
  1160. if (typeof event.type == "undefined"){
  1161. throw new Error("Event object missing 'type' property.");
  1162. }
  1163. if (this._listeners[event.type]){
  1164. var listeners = this._listeners[event.type].concat();
  1165. for (var i=0, len=listeners.length; i < len; i++){
  1166. listeners[i].call(this, event);
  1167. }
  1168. }
  1169. },
  1170. removeListener: function(type, listener){
  1171. if (this._listeners[type]){
  1172. var listeners = this._listeners[type];
  1173. for (var i=0, len=listeners.length; i < len; i++){
  1174. if (listeners[i] === listener){
  1175. listeners.splice(i, 1);
  1176. break;
  1177. }
  1178. }
  1179. }
  1180. }
  1181. };
  1182. function StringReader(text){
  1183. this._input = text.replace(/\n\r?/g, "\n");
  1184. this._line = 1;
  1185. this._col = 1;
  1186. this._cursor = 0;
  1187. }
  1188. StringReader.prototype = {
  1189. constructor: StringReader,
  1190. getCol: function(){
  1191. return this._col;
  1192. },
  1193. getLine: function(){
  1194. return this._line ;
  1195. },
  1196. eof: function(){
  1197. return (this._cursor == this._input.length);
  1198. },
  1199. peek: function(count){
  1200. var c = null;
  1201. count = (typeof count == "undefined" ? 1 : count);
  1202. if (this._cursor < this._input.length){
  1203. c = this._input.charAt(this._cursor + count - 1);
  1204. }
  1205. return c;
  1206. },
  1207. read: function(){
  1208. var c = null;
  1209. if (this._cursor < this._input.length){
  1210. if (this._input.charAt(this._cursor) == "\n"){
  1211. this._line++;
  1212. this._col=1;
  1213. } else {
  1214. this._col++;
  1215. }
  1216. c = this._input.charAt(this._cursor++);
  1217. }
  1218. return c;
  1219. },
  1220. mark: function(){
  1221. this._bookmark = {
  1222. cursor: this._cursor,
  1223. line: this._line,
  1224. col: this._col
  1225. };
  1226. },
  1227. reset: function(){
  1228. if (this._bookmark){
  1229. this._cursor = this._bookmark.cursor;
  1230. this._line = this._bookmark.line;
  1231. this._col = this._bookmark.col;
  1232. delete this._bookmark;
  1233. }
  1234. },
  1235. readTo: function(pattern){
  1236. var buffer = "",
  1237. c;
  1238. while (buffer.length < pattern.length || buffer.lastIndexOf(pattern) != buffer.length - pattern.length){
  1239. c = this.read();
  1240. if (c){
  1241. buffer += c;
  1242. } else {
  1243. throw new Error("Expected \"" + pattern + "\" at line " + this._line + ", col " + this._col + ".");
  1244. }
  1245. }
  1246. return buffer;
  1247. },
  1248. readWhile: function(filter){
  1249. var buffer = "",
  1250. c = this.read();
  1251. while(c !== null && filter(c)){
  1252. buffer += c;
  1253. c = this.read();
  1254. }
  1255. return buffer;
  1256. },
  1257. readMatch: function(matcher){
  1258. var source = this._input.substring(this._cursor),
  1259. value = null;
  1260. if (typeof matcher == "string"){
  1261. if (source.indexOf(matcher) === 0){
  1262. value = this.readCount(matcher.length);
  1263. }
  1264. } else if (matcher instanceof RegExp){
  1265. if (matcher.test(source)){
  1266. value = this.readCount(RegExp.lastMatch.length);
  1267. }
  1268. }
  1269. return value;
  1270. },
  1271. readCount: function(count){
  1272. var buffer = "";
  1273. while(count--){
  1274. buffer += this.read();
  1275. }
  1276. return buffer;
  1277. }
  1278. };
  1279. function SyntaxError(message, line, col){
  1280. this.col = col;
  1281. this.line = line;
  1282. this.message = message;
  1283. }
  1284. SyntaxError.prototype = new Error();
  1285. function SyntaxUnit(text, line, col, type){
  1286. this.col = col;
  1287. this.line = line;
  1288. this.text = text;
  1289. this.type = type;
  1290. }
  1291. SyntaxUnit.fromToken = function(token){
  1292. return new SyntaxUnit(token.value, token.startLine, token.startCol);
  1293. };
  1294. SyntaxUnit.prototype = {
  1295. constructor: SyntaxUnit,
  1296. valueOf: function(){
  1297. return this.text;
  1298. },
  1299. toString: function(){
  1300. return this.text;
  1301. }
  1302. };
  1303. function TokenStreamBase(input, tokenData){
  1304. this._reader = input ? new StringReader(input.toString()) : null;
  1305. this._token = null;
  1306. this._tokenData = tokenData;
  1307. this._lt = [];
  1308. this._ltIndex = 0;
  1309. this._ltIndexCache = [];
  1310. }
  1311. TokenStreamBase.createTokenData = function(tokens){
  1312. var nameMap = [],
  1313. typeMap = {},
  1314. tokenData = tokens.concat([]),
  1315. i = 0,
  1316. len = tokenData.length+1;
  1317. tokenData.UNKNOWN = -1;
  1318. tokenData.unshift({name:"EOF"});
  1319. for (; i < len; i++){
  1320. nameMap.push(tokenData[i].name);
  1321. tokenData[tokenData[i].name] = i;
  1322. if (tokenData[i].text){
  1323. typeMap[tokenData[i].text] = i;
  1324. }
  1325. }
  1326. tokenData.name = function(tt){
  1327. return nameMap[tt];
  1328. };
  1329. tokenData.type = function(c){
  1330. return typeMap[c];
  1331. };
  1332. return tokenData;
  1333. };
  1334. TokenStreamBase.prototype = {
  1335. constructor: TokenStreamBase,
  1336. match: function(tokenTypes, channel){
  1337. if (!(tokenTypes instanceof Array)){
  1338. tokenTypes = [tokenTypes];
  1339. }
  1340. var tt = this.get(channel),
  1341. i = 0,
  1342. len = tokenTypes.length;
  1343. while(i < len){
  1344. if (tt == tokenTypes[i++]){
  1345. return true;
  1346. }
  1347. }
  1348. this.unget();
  1349. return false;
  1350. },
  1351. mustMatch: function(tokenTypes, channel){
  1352. var token;
  1353. if (!(tokenTypes instanceof Array)){
  1354. tokenTypes = [tokenTypes];
  1355. }
  1356. if (!this.match.apply(this, arguments)){
  1357. token = this.LT(1);
  1358. throw new SyntaxError("Expected " + this._tokenData[tokenTypes[0]].name +
  1359. " at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
  1360. }
  1361. },
  1362. advance: function(tokenTypes, channel){
  1363. while(this.LA(0) !== 0 && !this.match(tokenTypes, channel)){
  1364. this.get();
  1365. }
  1366. return this.LA(0);
  1367. },
  1368. get: function(channel){
  1369. var tokenInfo = this._tokenData,
  1370. reader = this._reader,
  1371. value,
  1372. i =0,
  1373. len = tokenInfo.length,
  1374. found = false,
  1375. token,
  1376. info;
  1377. if (this._lt.length && this._ltIndex >= 0 && this._ltIndex < this._lt.length){
  1378. i++;
  1379. this._token = this._lt[this._ltIndex++];
  1380. info = tokenInfo[this._token.type];
  1381. while((info.channel !== undefined && channel !== info.channel) &&
  1382. this._ltIndex < this._lt.length){
  1383. this._token = this._lt[this._ltIndex++];
  1384. info = tokenInfo[this._token.type];
  1385. i++;
  1386. }
  1387. if ((info.channel === undefined || channel === info.channel) &&
  1388. this._ltIndex <= this._lt.length){
  1389. this._ltIndexCache.push(i);
  1390. return this._token.type;
  1391. }
  1392. }
  1393. token = this._getToken();
  1394. if (token.type > -1 && !tokenInfo[token.type].hide){
  1395. token.channel = tokenInfo[token.type].channel;
  1396. this._token = token;
  1397. this._lt.push(token);
  1398. this._ltIndexCache.push(this._lt.length - this._ltIndex + i);
  1399. if (this._lt.length > 5){
  1400. this._lt.shift();
  1401. }
  1402. if (this._ltIndexCache.length > 5){
  1403. this._ltIndexCache.shift();
  1404. }
  1405. this._ltIndex = this._lt.length;
  1406. }
  1407. info = tokenInfo[token.type];
  1408. if (info &&
  1409. (info.hide ||
  1410. (info.channel !== undefined && channel !== info.channel))){
  1411. return this.get(channel);
  1412. } else {
  1413. return token.type;
  1414. }
  1415. },
  1416. LA: function(index){
  1417. var total = index,
  1418. tt;
  1419. if (index > 0){
  1420. if (index > 5){
  1421. throw new Error("Too much lookahead.");
  1422. }
  1423. while(total){
  1424. tt = this.get();
  1425. total--;
  1426. }
  1427. while(total < index){
  1428. this.unget();
  1429. total++;
  1430. }
  1431. } else if (index < 0){
  1432. if(this._lt[this._ltIndex+index]){
  1433. tt = this._lt[this._ltIndex+index].type;
  1434. } else {
  1435. throw new Error("Too much lookbehind.");
  1436. }
  1437. } else {
  1438. tt = this._token.type;
  1439. }
  1440. return tt;
  1441. },
  1442. LT: function(index){
  1443. this.LA(index);
  1444. return this._lt[this._ltIndex+index-1];
  1445. },
  1446. peek: function(){
  1447. return this.LA(1);
  1448. },
  1449. token: function(){
  1450. return this._token;
  1451. },
  1452. tokenName: function(tokenType){
  1453. if (tokenType < 0 || tokenType > this._tokenData.length){
  1454. return "UNKNOWN_TOKEN";
  1455. } else {
  1456. return this._tokenData[tokenType].name;
  1457. }
  1458. },
  1459. tokenType: function(tokenName){
  1460. return this._tokenData[tokenName] || -1;
  1461. },
  1462. unget: function(){
  1463. if (this._ltIndexCache.length){
  1464. this._ltIndex -= this._ltIndexCache.pop();//--;
  1465. this._token = this._lt[this._ltIndex - 1];
  1466. } else {
  1467. throw new Error("Too much lookahead.");
  1468. }
  1469. }
  1470. };
  1471. parserlib.util = {
  1472. StringReader: StringReader,
  1473. SyntaxError : SyntaxError,
  1474. SyntaxUnit : SyntaxUnit,
  1475. EventTarget : EventTarget,
  1476. TokenStreamBase : TokenStreamBase
  1477. };
  1478. })();
  1479. (function(){
  1480. var EventTarget = parserlib.util.EventTarget,
  1481. TokenStreamBase = parserlib.util.TokenStreamBase,
  1482. StringReader = parserlib.util.StringReader,
  1483. SyntaxError = parserlib.util.SyntaxError,
  1484. SyntaxUnit = parserlib.util.SyntaxUnit;
  1485. var Colors = {
  1486. aliceblue :"#f0f8ff",
  1487. antiquewhite :"#faebd7",
  1488. aqua :"#00ffff",
  1489. aquamarine :"#7fffd4",
  1490. azure :"#f0ffff",
  1491. beige :"#f5f5dc",
  1492. bisque :"#ffe4c4",
  1493. black :"#000000",
  1494. blanchedalmond :"#ffebcd",
  1495. blue :"#0000ff",
  1496. blueviolet :"#8a2be2",
  1497. brown :"#a52a2a",
  1498. burlywood :"#deb887",
  1499. cadetblue :"#5f9ea0",
  1500. chartreuse :"#7fff00",
  1501. chocolate :"#d2691e",
  1502. coral :"#ff7f50",
  1503. cornflowerblue :"#6495ed",
  1504. cornsilk :"#fff8dc",
  1505. crimson :"#dc143c",
  1506. cyan :"#00ffff",
  1507. darkblue :"#00008b",
  1508. darkcyan :"#008b8b",
  1509. darkgoldenrod :"#b8860b",
  1510. darkgray :"#a9a9a9",
  1511. darkgrey :"#a9a9a9",
  1512. darkgreen :"#006400",
  1513. darkkhaki :"#bdb76b",
  1514. darkmagenta :"#8b008b",
  1515. darkolivegreen :"#556b2f",
  1516. darkorange :"#ff8c00",
  1517. darkorchid :"#9932cc",
  1518. darkred :"#8b0000",
  1519. darksalmon :"#e9967a",
  1520. darkseagreen :"#8fbc8f",
  1521. darkslateblue :"#483d8b",
  1522. darkslategray :"#2f4f4f",
  1523. darkslategrey :"#2f4f4f",
  1524. darkturquoise :"#00ced1",
  1525. darkviolet :"#9400d3",
  1526. deeppink :"#ff1493",
  1527. deepskyblue :"#00bfff",
  1528. dimgray :"#696969",
  1529. dimgrey :"#696969",
  1530. dodgerblue :"#1e90ff",
  1531. firebrick :"#b22222",
  1532. floralwhite :"#fffaf0",
  1533. forestgreen :"#228b22",
  1534. fuchsia :"#ff00ff",
  1535. gainsboro :"#dcdcdc",
  1536. ghostwhite :"#f8f8ff",
  1537. gold :"#ffd700",
  1538. goldenrod :"#daa520",
  1539. gray :"#808080",
  1540. grey :"#808080",
  1541. green :"#008000",
  1542. greenyellow :"#adff2f",
  1543. honeydew :"#f0fff0",
  1544. hotpink :"#ff69b4",
  1545. indianred :"#cd5c5c",
  1546. indigo :"#4b0082",
  1547. ivory :"#fffff0",
  1548. khaki :"#f0e68c",
  1549. lavender :"#e6e6fa",
  1550. lavenderblush :"#fff0f5",
  1551. lawngreen :"#7cfc00",
  1552. lemonchiffon :"#fffacd",
  1553. lightblue :"#add8e6",
  1554. lightcoral :"#f08080",
  1555. lightcyan :"#e0ffff",
  1556. lightgoldenrodyellow :"#fafad2",
  1557. lightgray :"#d3d3d3",
  1558. lightgrey :"#d3d3d3",
  1559. lightgreen :"#90ee90",
  1560. lightpink :"#ffb6c1",
  1561. lightsalmon :"#ffa07a",
  1562. lightseagreen :"#20b2aa",
  1563. lightskyblue :"#87cefa",
  1564. lightslategray :"#778899",
  1565. lightslategrey :"#778899",
  1566. lightsteelblue :"#b0c4de",
  1567. lightyellow :"#ffffe0",
  1568. lime :"#00ff00",
  1569. limegreen :"#32cd32",
  1570. linen :"#faf0e6",
  1571. magenta :"#ff00ff",
  1572. maroon :"#800000",
  1573. mediumaquamarine:"#66cdaa",
  1574. mediumblue :"#0000cd",
  1575. mediumorchid :"#ba55d3",
  1576. mediumpurple :"#9370d8",
  1577. mediumseagreen :"#3cb371",
  1578. mediumslateblue :"#7b68ee",
  1579. mediumspringgreen :"#00fa9a",
  1580. mediumturquoise :"#48d1cc",
  1581. mediumvioletred :"#c71585",
  1582. midnightblue :"#191970",
  1583. mintcream :"#f5fffa",
  1584. mistyrose :"#ffe4e1",
  1585. moccasin :"#ffe4b5",
  1586. navajowhite :"#ffdead",
  1587. navy :"#000080",
  1588. oldlace :"#fdf5e6",
  1589. olive :"#808000",
  1590. olivedrab :"#6b8e23",
  1591. orange :"#ffa500",
  1592. orangered :"#ff4500",
  1593. orchid :"#da70d6",
  1594. palegoldenrod :"#eee8aa",
  1595. palegreen :"#98fb98",
  1596. paleturquoise :"#afeeee",
  1597. palevioletred :"#d87093",
  1598. papayawhip :"#ffefd5",
  1599. peachpuff :"#ffdab9",
  1600. peru :"#cd853f",
  1601. pink :"#ffc0cb",
  1602. plum :"#dda0dd",
  1603. powderblue :"#b0e0e6",
  1604. purple :"#800080",
  1605. red :"#ff0000",
  1606. rosybrown :"#bc8f8f",
  1607. royalblue :"#4169e1",
  1608. saddlebrown :"#8b4513",
  1609. salmon :"#fa8072",
  1610. sandybrown :"#f4a460",
  1611. seagreen :"#2e8b57",
  1612. seashell :"#fff5ee",
  1613. sienna :"#a0522d",
  1614. silver :"#c0c0c0",
  1615. skyblue :"#87ceeb",
  1616. slateblue :"#6a5acd",
  1617. slategray :"#708090",
  1618. slategrey :"#708090",
  1619. snow :"#fffafa",
  1620. springgreen :"#00ff7f",
  1621. steelblue :"#4682b4",
  1622. tan :"#d2b48c",
  1623. teal :"#008080",
  1624. thistle :"#d8bfd8",
  1625. tomato :"#ff6347",
  1626. turquoise :"#40e0d0",
  1627. violet :"#ee82ee",
  1628. wheat :"#f5deb3",
  1629. white :"#ffffff",
  1630. whitesmoke :"#f5f5f5",
  1631. yellow :"#ffff00",
  1632. yellowgreen :"#9acd32",
  1633. activeBorder :"Active window border.",
  1634. activecaption :"Active window caption.",
  1635. appworkspace :"Background color of multiple document interface.",
  1636. background :"Desktop background.",
  1637. buttonface :"The face background color for 3-D elements that appear 3-D due to one layer of surrounding border.",
  1638. buttonhighlight :"The color of the border facing the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
  1639. buttonshadow :"The color of the border away from the light source for 3-D elements that appear 3-D due to one layer of surrounding border.",
  1640. buttontext :"Text on push buttons.",
  1641. captiontext :"Text in caption, size box, and scrollbar arrow box.",
  1642. graytext :"Grayed (disabled) text. This color is set to #000 if the current display driver does not support a solid gray color.",
  1643. greytext :"Greyed (disabled) text. This color is set to #000 if the current display driver does not support a solid grey color.",
  1644. highlight :"Item(s) selected in a control.",
  1645. highlighttext :"Text of item(s) selected in a control.",
  1646. inactiveborder :"Inactive window border.",
  1647. inactivecaption :"Inactive window caption.",
  1648. inactivecaptiontext :"Color of text in an inactive caption.",
  1649. infobackground :"Background color for tooltip controls.",
  1650. infotext :"Text color for tooltip controls.",
  1651. menu :"Menu background.",
  1652. menutext :"Text in menus.",
  1653. scrollbar :"Scroll bar gray area.",
  1654. threeddarkshadow :"The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  1655. threedface :"The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  1656. threedhighlight :"The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  1657. threedlightshadow :"The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  1658. threedshadow :"The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border.",
  1659. window :"Window background.",
  1660. windowframe :"Window frame.",
  1661. windowtext :"Text in windows."
  1662. };
  1663. function Combinator(text, line, col){
  1664. SyntaxUnit.call(this, text, line, col, Parser.COMBINATOR_TYPE);
  1665. this.type = "unknown";
  1666. if (/^\s+$/.test(text)){
  1667. this.type = "descendant";
  1668. } else if (text == ">"){
  1669. this.type = "child";
  1670. } else if (text == "+"){
  1671. this.type = "adjacent-sibling";
  1672. } else if (text == "~"){
  1673. this.type = "sibling";
  1674. }
  1675. }
  1676. Combinator.prototype = new SyntaxUnit();
  1677. Combinator.prototype.constructor = Combinator;
  1678. function MediaFeature(name, value){
  1679. SyntaxUnit.call(this, "(" + name + (value !== null ? ":" + value : "") + ")", name.startLine, name.startCol, Parser.MEDIA_FEATURE_TYPE);
  1680. this.name = name;
  1681. this.value = value;
  1682. }
  1683. MediaFeature.prototype = new SyntaxUnit();
  1684. MediaFeature.prototype.constructor = MediaFeature;
  1685. function MediaQuery(modifier, mediaType, features, line, col){
  1686. SyntaxUnit.call(this, (modifier ? modifier + " ": "") + (mediaType ? mediaType : "") + (mediaType && features.length > 0 ? " and " : "") + features.join(" and "), line, col, Parser.MEDIA_QUERY_TYPE);
  1687. this.modifier = modifier;
  1688. this.mediaType = mediaType;
  1689. this.features = features;
  1690. }
  1691. MediaQuery.prototype = new SyntaxUnit();
  1692. MediaQuery.prototype.constructor = MediaQuery;
  1693. function Parser(options){
  1694. EventTarget.call(this);
  1695. this.options = options || {};
  1696. this._tokenStream = null;
  1697. }
  1698. Parser.DEFAULT_TYPE = 0;
  1699. Parser.COMBINATOR_TYPE = 1;
  1700. Parser.MEDIA_FEATURE_TYPE = 2;
  1701. Parser.MEDIA_QUERY_TYPE = 3;
  1702. Parser.PROPERTY_NAME_TYPE = 4;
  1703. Parser.PROPERTY_VALUE_TYPE = 5;
  1704. Parser.PROPERTY_VALUE_PART_TYPE = 6;
  1705. Parser.SELECTOR_TYPE = 7;
  1706. Parser.SELECTOR_PART_TYPE = 8;
  1707. Parser.SELECTOR_SUB_PART_TYPE = 9;
  1708. Parser.prototype = function(){
  1709. var proto = new EventTarget(), //new prototype
  1710. prop,
  1711. additions = {
  1712. constructor: Parser,
  1713. DEFAULT_TYPE : 0,
  1714. COMBINATOR_TYPE : 1,
  1715. MEDIA_FEATURE_TYPE : 2,
  1716. MEDIA_QUERY_TYPE : 3,
  1717. PROPERTY_NAME_TYPE : 4,
  1718. PROPERTY_VALUE_TYPE : 5,
  1719. PROPERTY_VALUE_PART_TYPE : 6,
  1720. SELECTOR_TYPE : 7,
  1721. SELECTOR_PART_TYPE : 8,
  1722. SELECTOR_SUB_PART_TYPE : 9,
  1723. _stylesheet: function(){
  1724. var tokenStream = this._tokenStream,
  1725. charset = null,
  1726. count,
  1727. token,
  1728. tt;
  1729. this.fire("startstylesheet");
  1730. this._charset();
  1731. this._skipCruft();
  1732. while (tokenStream.peek() == Tokens.IMPORT_SYM){
  1733. this._import();
  1734. this._skipCruft();
  1735. }
  1736. while (tokenStream.peek() == Tokens.NAMESPACE_SYM){
  1737. this._namespace();
  1738. this._skipCruft();
  1739. }
  1740. tt = tokenStream.peek();
  1741. while(tt > Tokens.EOF){
  1742. try {
  1743. switch(tt){
  1744. case Tokens.MEDIA_SYM:
  1745. this._media();
  1746. this._skipCruft();
  1747. break;
  1748. case Tokens.PAGE_SYM:
  1749. this._page();
  1750. this._skipCruft();
  1751. break;
  1752. case Tokens.FONT_FACE_SYM:
  1753. this._font_face();
  1754. this._skipCruft();
  1755. break;
  1756. case Tokens.KEYFRAMES_SYM:
  1757. this._keyframes();
  1758. this._skipCruft();
  1759. break;
  1760. case Tokens.VIEWPORT_SYM:
  1761. this._viewport();
  1762. this._skipCruft();
  1763. break;
  1764. case Tokens.UNKNOWN_SYM: //unknown @ rule
  1765. tokenStream.get();
  1766. if (!this.options.strict){
  1767. this.fire({
  1768. type: "error",
  1769. error: null,
  1770. message: "Unknown @ rule: " + tokenStream.LT(0).value + ".",
  1771. line: tokenStream.LT(0).startLine,
  1772. col: tokenStream.LT(0).startCol
  1773. });
  1774. count=0;
  1775. while (tokenStream.advance([Tokens.LBRACE, Tokens.RBRACE]) == Tokens.LBRACE){
  1776. count++; //keep track of nesting depth
  1777. }
  1778. while(count){
  1779. tokenStream.advance([Tokens.RBRACE]);
  1780. count--;
  1781. }
  1782. } else {
  1783. throw new SyntaxError("Unknown @ rule.", tokenStream.LT(0).startLine, tokenStream.LT(0).startCol);
  1784. }
  1785. break;
  1786. case Tokens.S:
  1787. this._readWhitespace();
  1788. break;
  1789. default:
  1790. if(!this._ruleset()){
  1791. switch(tt){
  1792. case Tokens.CHARSET_SYM:
  1793. token = tokenStream.LT(1);
  1794. this._charset(false);
  1795. throw new SyntaxError("@charset not allowed here.", token.startLine, token.startCol);
  1796. case Tokens.IMPORT_SYM:
  1797. token = tokenStream.LT(1);
  1798. this._import(false);
  1799. throw new SyntaxError("@import not allowed here.", token.startLine, token.startCol);
  1800. case Tokens.NAMESPACE_SYM:
  1801. token = tokenStream.LT(1);
  1802. this._namespace(false);
  1803. throw new SyntaxError("@namespace not allowed here.", token.startLine, token.startCol);
  1804. default:
  1805. tokenStream.get(); //get the last token
  1806. this._unexpectedToken(tokenStream.token());
  1807. }
  1808. }
  1809. }
  1810. } catch(ex) {
  1811. if (ex instanceof SyntaxError && !this.options.strict){
  1812. this.fire({
  1813. type: "error",
  1814. error: ex,
  1815. message: ex.message,
  1816. line: ex.line,
  1817. col: ex.col
  1818. });
  1819. } else {
  1820. throw ex;
  1821. }
  1822. }
  1823. tt = tokenStream.peek();
  1824. }
  1825. if (tt != Tokens.EOF){
  1826. this._unexpectedToken(tokenStream.token());
  1827. }
  1828. this.fire("endstylesheet");
  1829. },
  1830. _charset: function(emit){
  1831. var tokenStream = this._tokenStream,
  1832. charset,
  1833. token,
  1834. line,
  1835. col;
  1836. if (tokenStream.match(Tokens.CHARSET_SYM)){
  1837. line = tokenStream.token().startLine;
  1838. col = tokenStream.token().startCol;
  1839. this._readWhitespace();
  1840. tokenStream.mustMatch(Tokens.STRING);
  1841. token = tokenStream.token();
  1842. charset = token.value;
  1843. this._readWhitespace();
  1844. tokenStream.mustMatch(Tokens.SEMICOLON);
  1845. if (emit !== false){
  1846. this.fire({
  1847. type: "charset",
  1848. charset:charset,
  1849. line: line,
  1850. col: col
  1851. });
  1852. }
  1853. }
  1854. },
  1855. _import: function(emit){
  1856. var tokenStream = this._tokenStream,
  1857. tt,
  1858. uri,
  1859. importToken,
  1860. mediaList = [];
  1861. tokenStream.mustMatch(Tokens.IMPORT_SYM);
  1862. importToken = tokenStream.token();
  1863. this._readWhitespace();
  1864. tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
  1865. uri = tokenStream.token().value.replace(/^(?:url\()?["']?([^"']+?)["']?\)?$/, "$1");
  1866. this._readWhitespace();
  1867. mediaList = this._media_query_list();
  1868. tokenStream.mustMatch(Tokens.SEMICOLON);
  1869. this._readWhitespace();
  1870. if (emit !== false){
  1871. this.fire({
  1872. type: "import",
  1873. uri: uri,
  1874. media: mediaList,
  1875. line: importToken.startLine,
  1876. col: importToken.startCol
  1877. });
  1878. }
  1879. },
  1880. _namespace: function(emit){
  1881. var tokenStream = this._tokenStream,
  1882. line,
  1883. col,
  1884. prefix,
  1885. uri;
  1886. tokenStream.mustMatch(Tokens.NAMESPACE_SYM);
  1887. line = tokenStream.token().startLine;
  1888. col = tokenStream.token().startCol;
  1889. this._readWhitespace();
  1890. if (tokenStream.match(Tokens.IDENT)){
  1891. prefix = tokenStream.token().value;
  1892. this._readWhitespace();
  1893. }
  1894. tokenStream.mustMatch([Tokens.STRING, Tokens.URI]);
  1895. uri = tokenStream.token().value.replace(/(?:url\()?["']([^"']+)["']\)?/, "$1");
  1896. this._readWhitespace();
  1897. tokenStream.mustMatch(Tokens.SEMICOLON);
  1898. this._readWhitespace();
  1899. if (emit !== false){
  1900. this.fire({
  1901. type: "namespace",
  1902. prefix: prefix,
  1903. uri: uri,
  1904. line: line,
  1905. col: col
  1906. });
  1907. }
  1908. },
  1909. _media: function(){
  1910. var tokenStream = this._tokenStream,
  1911. line,
  1912. col,
  1913. mediaList;// = [];
  1914. tokenStream.mustMatch(Tokens.MEDIA_SYM);
  1915. line = tokenStream.token().startLine;
  1916. col = tokenStream.token().startCol;
  1917. this._readWhitespace();
  1918. mediaList = this._media_query_list();
  1919. tokenStream.mustMatch(Tokens.LBRACE);
  1920. this._readWhitespace();
  1921. this.fire({
  1922. type: "startmedia",
  1923. media: mediaList,
  1924. line: line,
  1925. col: col
  1926. });
  1927. while(true) {
  1928. if (tokenStream.peek() == Tokens.PAGE_SYM){
  1929. this._page();
  1930. } else if (tokenStream.peek() == Tokens.FONT_FACE_SYM){
  1931. this._font_face();
  1932. } else if (tokenStream.peek() == Tokens.VIEWPORT_SYM){
  1933. this._viewport();
  1934. } else if (!this._ruleset()){
  1935. break;
  1936. }
  1937. }
  1938. tokenStream.mustMatch(Tokens.RBRACE);
  1939. this._readWhitespace();
  1940. this.fire({
  1941. type: "endmedia",
  1942. media: mediaList,
  1943. line: line,
  1944. col: col
  1945. });
  1946. },
  1947. _media_query_list: function(){
  1948. var tokenStream = this._tokenStream,
  1949. mediaList = [];
  1950. this._readWhitespace();
  1951. if (tokenStream.peek() == Tokens.IDENT || tokenStream.peek() == Tokens.LPAREN){
  1952. mediaList.push(this._media_query());
  1953. }
  1954. while(tokenStream.match(Tokens.COMMA)){
  1955. this._readWhitespace();
  1956. mediaList.push(this._media_query());
  1957. }
  1958. return mediaList;
  1959. },
  1960. _media_query: function(){
  1961. var tokenStream = this._tokenStream,
  1962. type = null,
  1963. ident = null,
  1964. token = null,
  1965. expressions = [];
  1966. if (tokenStream.match(Tokens.IDENT)){
  1967. ident = tokenStream.token().value.toLowerCase();
  1968. if (ident != "only" && ident != "not"){
  1969. tokenStream.unget();
  1970. ident = null;
  1971. } else {
  1972. token = tokenStream.token();
  1973. }
  1974. }
  1975. this._readWhitespace();
  1976. if (tokenStream.peek() == Tokens.IDENT){
  1977. type = this._media_type();
  1978. if (token === null){
  1979. token = tokenStream.token();
  1980. }
  1981. } else if (tokenStream.peek() == Tokens.LPAREN){
  1982. if (token === null){
  1983. token = tokenStream.LT(1);
  1984. }
  1985. expressions.push(this._media_expression());
  1986. }
  1987. if (type === null && expressions.length === 0){
  1988. return null;
  1989. } else {
  1990. this._readWhitespace();
  1991. while (tokenStream.match(Tokens.IDENT)){
  1992. if (tokenStream.token().value.toLowerCase() != "and"){
  1993. this._unexpectedToken(tokenStream.token());
  1994. }
  1995. this._readWhitespace();
  1996. expressions.push(this._media_expression());
  1997. }
  1998. }
  1999. return new MediaQuery(ident, type, expressions, token.startLine, token.startCol);
  2000. },
  2001. _media_type: function(){
  2002. return this._media_feature();
  2003. },
  2004. _media_expression: function(){
  2005. var tokenStream = this._tokenStream,
  2006. feature = null,
  2007. token,
  2008. expression = null;
  2009. tokenStream.mustMatch(Tokens.LPAREN);
  2010. feature = this._media_feature();
  2011. this._readWhitespace();
  2012. if (tokenStream.match(Tokens.COLON)){
  2013. this._readWhitespace();
  2014. token = tokenStream.LT(1);
  2015. expression = this._expression();
  2016. }
  2017. tokenStream.mustMatch(Tokens.RPAREN);
  2018. this._readWhitespace();
  2019. return new MediaFeature(feature, (expression ? new SyntaxUnit(expression, token.startLine, token.startCol) : null));
  2020. },
  2021. _media_feature: function(){
  2022. var tokenStream = this._tokenStream;
  2023. tokenStream.mustMatch(Tokens.IDENT);
  2024. return SyntaxUnit.fromToken(tokenStream.token());
  2025. },
  2026. _page: function(){
  2027. var tokenStream = this._tokenStream,
  2028. line,
  2029. col,
  2030. identifier = null,
  2031. pseudoPage = null;
  2032. tokenStream.mustMatch(Tokens.PAGE_SYM);
  2033. line = tokenStream.token().startLine;
  2034. col = tokenStream.token().startCol;
  2035. this._readWhitespace();
  2036. if (tokenStream.match(Tokens.IDENT)){
  2037. identifier = tokenStream.token().value;
  2038. if (identifier.toLowerCase() === "auto"){
  2039. this._unexpectedToken(tokenStream.token());
  2040. }
  2041. }
  2042. if (tokenStream.peek() == Tokens.COLON){
  2043. pseudoPage = this._pseudo_page();
  2044. }
  2045. this._readWhitespace();
  2046. this.fire({
  2047. type: "startpage",
  2048. id: identifier,
  2049. pseudo: pseudoPage,
  2050. line: line,
  2051. col: col
  2052. });
  2053. this._readDeclarations(true, true);
  2054. this.fire({
  2055. type: "endpage",
  2056. id: identifier,
  2057. pseudo: pseudoPage,
  2058. line: line,
  2059. col: col
  2060. });
  2061. },
  2062. _margin: function(){
  2063. var tokenStream = this._tokenStream,
  2064. line,
  2065. col,
  2066. marginSym = this._margin_sym();
  2067. if (marginSym){
  2068. line = tokenStream.token().startLine;
  2069. col = tokenStream.token().startCol;
  2070. this.fire({
  2071. type: "startpagemargin",
  2072. margin: marginSym,
  2073. line: line,
  2074. col: col
  2075. });
  2076. this._readDeclarations(true);
  2077. this.fire({
  2078. type: "endpagemargin",
  2079. margin: marginSym,
  2080. line: line,
  2081. col: col
  2082. });
  2083. return true;
  2084. } else {
  2085. return false;
  2086. }
  2087. },
  2088. _margin_sym: function(){
  2089. var tokenStream = this._tokenStream;
  2090. if(tokenStream.match([Tokens.TOPLEFTCORNER_SYM, Tokens.TOPLEFT_SYM,
  2091. Tokens.TOPCENTER_SYM, Tokens.TOPRIGHT_SYM, Tokens.TOPRIGHTCORNER_SYM,
  2092. Tokens.BOTTOMLEFTCORNER_SYM, Tokens.BOTTOMLEFT_SYM,
  2093. Tokens.BOTTOMCENTER_SYM, Tokens.BOTTOMRIGHT_SYM,
  2094. Tokens.BOTTOMRIGHTCORNER_SYM, Tokens.LEFTTOP_SYM,
  2095. Tokens.LEFTMIDDLE_SYM, Tokens.LEFTBOTTOM_SYM, Tokens.RIGHTTOP_SYM,
  2096. Tokens.RIGHTMIDDLE_SYM, Tokens.RIGHTBOTTOM_SYM]))
  2097. {
  2098. return SyntaxUnit.fromToken(tokenStream.token());
  2099. } else {
  2100. return null;
  2101. }
  2102. },
  2103. _pseudo_page: function(){
  2104. var tokenStream = this._tokenStream;
  2105. tokenStream.mustMatch(Tokens.COLON);
  2106. tokenStream.mustMatch(Tokens.IDENT);
  2107. return tokenStream.token().value;
  2108. },
  2109. _font_face: function(){
  2110. var tokenStream = this._tokenStream,
  2111. line,
  2112. col;
  2113. tokenStream.mustMatch(Tokens.FONT_FACE_SYM);
  2114. line = tokenStream.token().startLine;
  2115. col = tokenStream.token().startCol;
  2116. this._readWhitespace();
  2117. this.fire({
  2118. type: "startfontface",
  2119. line: line,
  2120. col: col
  2121. });
  2122. this._readDeclarations(true);
  2123. this.fire({
  2124. type: "endfontface",
  2125. line: line,
  2126. col: col
  2127. });
  2128. },
  2129. _viewport: function(){
  2130. var tokenStream = this._tokenStream,
  2131. line,
  2132. col;
  2133. tokenStream.mustMatch(Tokens.VIEWPORT_SYM);
  2134. line = tokenStream.token().startLine;
  2135. col = tokenStream.token().startCol;
  2136. this._readWhitespace();
  2137. this.fire({
  2138. type: "startviewport",
  2139. line: line,
  2140. col: col
  2141. });
  2142. this._readDeclarations(true);
  2143. this.fire({
  2144. type: "endviewport",
  2145. line: line,
  2146. col: col
  2147. });
  2148. },
  2149. _operator: function(inFunction){
  2150. var tokenStream = this._tokenStream,
  2151. token = null;
  2152. if (tokenStream.match([Tokens.SLASH, Tokens.COMMA]) ||
  2153. (inFunction && tokenStream.match([Tokens.PLUS, Tokens.STAR, Tokens.MINUS]))){
  2154. token = tokenStream.token();
  2155. this._readWhitespace();
  2156. }
  2157. return token ? PropertyValuePart.fromToken(token) : null;
  2158. },
  2159. _combinator: function(){
  2160. var tokenStream = this._tokenStream,
  2161. value = null,
  2162. token;
  2163. if(tokenStream.match([Tokens.PLUS, Tokens.GREATER, Tokens.TILDE])){
  2164. token = tokenStream.token();
  2165. value = new Combinator(token.value, token.startLine, token.startCol);
  2166. this._readWhitespace();
  2167. }
  2168. return value;
  2169. },
  2170. _unary_operator: function(){
  2171. var tokenStream = this._tokenStream;
  2172. if (tokenStream.match([Tokens.MINUS, Tokens.PLUS])){
  2173. return tokenStream.token().value;
  2174. } else {
  2175. return null;
  2176. }
  2177. },
  2178. _property: function(){
  2179. var tokenStream = this._tokenStream,
  2180. value = null,
  2181. hack = null,
  2182. tokenValue,
  2183. token,
  2184. line,
  2185. col;
  2186. if (tokenStream.peek() == Tokens.STAR && this.options.starHack){
  2187. tokenStream.get();
  2188. token = tokenStream.token();
  2189. hack = token.value;
  2190. line = token.startLine;
  2191. col = token.startCol;
  2192. }
  2193. if(tokenStream.match(Tokens.IDENT)){
  2194. token = tokenStream.token();
  2195. tokenValue = token.value;
  2196. if (tokenValue.charAt(0) == "_" && this.options.underscoreHack){
  2197. hack = "_";
  2198. tokenValue = tokenValue.substring(1);
  2199. }
  2200. value = new PropertyName(tokenValue, hack, (line||token.startLine), (col||token.startCol));
  2201. this._readWhitespace();
  2202. }
  2203. return value;
  2204. },
  2205. _ruleset: function(){
  2206. var tokenStream = this._tokenStream,
  2207. tt,
  2208. selectors;
  2209. try {
  2210. selectors = this._selectors_group();
  2211. } catch (ex){
  2212. if (ex instanceof SyntaxError && !this.options.strict){
  2213. this.fire({
  2214. type: "error",
  2215. error: ex,
  2216. message: ex.message,
  2217. line: ex.line,
  2218. col: ex.col
  2219. });
  2220. tt = tokenStream.advance([Tokens.RBRACE]);
  2221. if (tt == Tokens.RBRACE){
  2222. } else {
  2223. throw ex;
  2224. }
  2225. } else {
  2226. throw ex;
  2227. }
  2228. return true;
  2229. }
  2230. if (selectors){
  2231. this.fire({
  2232. type: "startrule",
  2233. selectors: selectors,
  2234. line: selectors[0].line,
  2235. col: selectors[0].col
  2236. });
  2237. this._readDeclarations(true);
  2238. this.fire({
  2239. type: "endrule",
  2240. selectors: selectors,
  2241. line: selectors[0].line,
  2242. col: selectors[0].col
  2243. });
  2244. }
  2245. return selectors;
  2246. },
  2247. _selectors_group: function(){
  2248. var tokenStream = this._tokenStream,
  2249. selectors = [],
  2250. selector;
  2251. selector = this._selector();
  2252. if (selector !== null){
  2253. selectors.push(selector);
  2254. while(tokenStream.match(Tokens.COMMA)){
  2255. this._readWhitespace();
  2256. selector = this._selector();
  2257. if (selector !== null){
  2258. selectors.push(selector);
  2259. } else {
  2260. this._unexpectedToken(tokenStream.LT(1));
  2261. }
  2262. }
  2263. }
  2264. return selectors.length ? selectors : null;
  2265. },
  2266. _selector: function(){
  2267. var tokenStream = this._tokenStream,
  2268. selector = [],
  2269. nextSelector = null,
  2270. combinator = null,
  2271. ws = null;
  2272. nextSelector = this._simple_selector_sequence();
  2273. if (nextSelector === null){
  2274. return null;
  2275. }
  2276. selector.push(nextSelector);
  2277. do {
  2278. combinator = this._combinator();
  2279. if (combinator !== null){
  2280. selector.push(combinator);
  2281. nextSelector = this._simple_selector_sequence();
  2282. if (nextSelector === null){
  2283. this._unexpectedToken(tokenStream.LT(1));
  2284. } else {
  2285. selector.push(nextSelector);
  2286. }
  2287. } else {
  2288. if (this._readWhitespace()){
  2289. ws = new Combinator(tokenStream.token().value, tokenStream.token().startLine, tokenStream.token().startCol);
  2290. combinator = this._combinator();
  2291. nextSelector = this._simple_selector_sequence();
  2292. if (nextSelector === null){
  2293. if (combinator !== null){
  2294. this._unexpectedToken(tokenStream.LT(1));
  2295. }
  2296. } else {
  2297. if (combinator !== null){
  2298. selector.push(combinator);
  2299. } else {
  2300. selector.push(ws);
  2301. }
  2302. selector.push(nextSelector);
  2303. }
  2304. } else {
  2305. break;
  2306. }
  2307. }
  2308. } while(true);
  2309. return new Selector(selector, selector[0].line, selector[0].col);
  2310. },
  2311. _simple_selector_sequence: function(){
  2312. var tokenStream = this._tokenStream,
  2313. elementName = null,
  2314. modifiers = [],
  2315. selectorText= "",
  2316. components = [
  2317. function(){
  2318. return tokenStream.match(Tokens.HASH) ?
  2319. new SelectorSubPart(tokenStream.token().value, "id", tokenStream.token().startLine, tokenStream.token().startCol) :
  2320. null;
  2321. },
  2322. this._class,
  2323. this._attrib,
  2324. this._pseudo,
  2325. this._negation
  2326. ],
  2327. i = 0,
  2328. len = components.length,
  2329. component = null,
  2330. found = false,
  2331. line,
  2332. col;
  2333. line = tokenStream.LT(1).startLine;
  2334. col = tokenStream.LT(1).startCol;
  2335. elementName = this._type_selector();
  2336. if (!elementName){
  2337. elementName = this._universal();
  2338. }
  2339. if (elementName !== null){
  2340. selectorText += elementName;
  2341. }
  2342. while(true){
  2343. if (tokenStream.peek() === Tokens.S){
  2344. break;
  2345. }
  2346. while(i < len && component === null){
  2347. component = components[i++].call(this);
  2348. }
  2349. if (component === null){
  2350. if (selectorText === ""){
  2351. return null;
  2352. } else {
  2353. break;
  2354. }
  2355. } else {
  2356. i = 0;
  2357. modifiers.push(component);
  2358. selectorText += component.toString();
  2359. component = null;
  2360. }
  2361. }
  2362. return selectorText !== "" ?
  2363. new SelectorPart(elementName, modifiers, selectorText, line, col) :
  2364. null;
  2365. },
  2366. _type_selector: function(){
  2367. var tokenStream = this._tokenStream,
  2368. ns = this._namespace_prefix(),
  2369. elementName = this._element_name();
  2370. if (!elementName){
  2371. if (ns){
  2372. tokenStream.unget();
  2373. if (ns.length > 1){
  2374. tokenStream.unget();
  2375. }
  2376. }
  2377. return null;
  2378. } else {
  2379. if (ns){
  2380. elementName.text = ns + elementName.text;
  2381. elementName.col -= ns.length;
  2382. }
  2383. return elementName;
  2384. }
  2385. },
  2386. _class: function(){
  2387. var tokenStream = this._tokenStream,
  2388. token;
  2389. if (tokenStream.match(Tokens.DOT)){
  2390. tokenStream.mustMatch(Tokens.IDENT);
  2391. token = tokenStream.token();
  2392. return new SelectorSubPart("." + token.value, "class", token.startLine, token.startCol - 1);
  2393. } else {
  2394. return null;
  2395. }
  2396. },
  2397. _element_name: function(){
  2398. var tokenStream = this._tokenStream,
  2399. token;
  2400. if (tokenStream.match(Tokens.IDENT)){
  2401. token = tokenStream.token();
  2402. return new SelectorSubPart(token.value, "elementName", token.startLine, token.startCol);
  2403. } else {
  2404. return null;
  2405. }
  2406. },
  2407. _namespace_prefix: function(){
  2408. var tokenStream = this._tokenStream,
  2409. value = "";
  2410. if (tokenStream.LA(1) === Tokens.PIPE || tokenStream.LA(2) === Tokens.PIPE){
  2411. if(tokenStream.match([Tokens.IDENT, Tokens.STAR])){
  2412. value += tokenStream.token().value;
  2413. }
  2414. tokenStream.mustMatch(Tokens.PIPE);
  2415. value += "|";
  2416. }
  2417. return value.length ? value : null;
  2418. },
  2419. _universal: function(){
  2420. var tokenStream = this._tokenStream,
  2421. value = "",
  2422. ns;
  2423. ns = this._namespace_prefix();
  2424. if(ns){
  2425. value += ns;
  2426. }
  2427. if(tokenStream.match(Tokens.STAR)){
  2428. value += "*";
  2429. }
  2430. return value.length ? value : null;
  2431. },
  2432. _attrib: function(){
  2433. var tokenStream = this._tokenStream,
  2434. value = null,
  2435. ns,
  2436. token;
  2437. if (tokenStream.match(Tokens.LBRACKET)){
  2438. token = tokenStream.token();
  2439. value = token.value;
  2440. value += this._readWhitespace();
  2441. ns = this._namespace_prefix();
  2442. if (ns){
  2443. value += ns;
  2444. }
  2445. tokenStream.mustMatch(Tokens.IDENT);
  2446. value += tokenStream.token().value;
  2447. value += this._readWhitespace();
  2448. if(tokenStream.match([Tokens.PREFIXMATCH, Tokens.SUFFIXMATCH, Tokens.SUBSTRINGMATCH,
  2449. Tokens.EQUALS, Tokens.INCLUDES, Tokens.DASHMATCH])){
  2450. value += tokenStream.token().value;
  2451. value += this._readWhitespace();
  2452. tokenStream.mustMatch([Tokens.IDENT, Tokens.STRING]);
  2453. value += tokenStream.token().value;
  2454. value += this._readWhitespace();
  2455. }
  2456. tokenStream.mustMatch(Tokens.RBRACKET);
  2457. return new SelectorSubPart(value + "]", "attribute", token.startLine, token.startCol);
  2458. } else {
  2459. return null;
  2460. }
  2461. },
  2462. _pseudo: function(){
  2463. var tokenStream = this._tokenStream,
  2464. pseudo = null,
  2465. colons = ":",
  2466. line,
  2467. col;
  2468. if (tokenStream.match(Tokens.COLON)){
  2469. if (tokenStream.match(Tokens.COLON)){
  2470. colons += ":";
  2471. }
  2472. if (tokenStream.match(Tokens.IDENT)){
  2473. pseudo = tokenStream.token().value;
  2474. line = tokenStream.token().startLine;
  2475. col = tokenStream.token().startCol - colons.length;
  2476. } else if (tokenStream.peek() == Tokens.FUNCTION){
  2477. line = tokenStream.LT(1).startLine;
  2478. col = tokenStream.LT(1).startCol - colons.length;
  2479. pseudo = this._functional_pseudo();
  2480. }
  2481. if (pseudo){
  2482. pseudo = new SelectorSubPart(colons + pseudo, "pseudo", line, col);
  2483. }
  2484. }
  2485. return pseudo;
  2486. },
  2487. _functional_pseudo: function(){
  2488. var tokenStream = this._tokenStream,
  2489. value = null;
  2490. if(tokenStream.match(Tokens.FUNCTION)){
  2491. value = tokenStream.token().value;
  2492. value += this._readWhitespace();
  2493. value += this._expression();
  2494. tokenStream.mustMatch(Tokens.RPAREN);
  2495. value += ")";
  2496. }
  2497. return value;
  2498. },
  2499. _expression: function(){
  2500. var tokenStream = this._tokenStream,
  2501. value = "";
  2502. while(tokenStream.match([Tokens.PLUS, Tokens.MINUS, Tokens.DIMENSION,
  2503. Tokens.NUMBER, Tokens.STRING, Tokens.IDENT, Tokens.LENGTH,
  2504. Tokens.FREQ, Tokens.ANGLE, Tokens.TIME,
  2505. Tokens.RESOLUTION, Tokens.SLASH])){
  2506. value += tokenStream.token().value;
  2507. value += this._readWhitespace();
  2508. }
  2509. return value.length ? value : null;
  2510. },
  2511. _negation: function(){
  2512. var tokenStream = this._tokenStream,
  2513. line,
  2514. col,
  2515. value = "",
  2516. arg,
  2517. subpart = null;
  2518. if (tokenStream.match(Tokens.NOT)){
  2519. value = tokenStream.token().value;
  2520. line = tokenStream.token().startLine;
  2521. col = tokenStream.token().startCol;
  2522. value += this._readWhitespace();
  2523. arg = this._negation_arg();
  2524. value += arg;
  2525. value += this._readWhitespace();
  2526. tokenStream.match(Tokens.RPAREN);
  2527. value += tokenStream.token().value;
  2528. subpart = new SelectorSubPart(value, "not", line, col);
  2529. subpart.args.push(arg);
  2530. }
  2531. return subpart;
  2532. },
  2533. _negation_arg: function(){
  2534. var tokenStream = this._tokenStream,
  2535. args = [
  2536. this._type_selector,
  2537. this._universal,
  2538. function(){
  2539. return tokenStream.match(Tokens.HASH) ?
  2540. new SelectorSubPart(tokenStream.token().value, "id", tokenStream.token().startLine, tokenStream.token().startCol) :
  2541. null;
  2542. },
  2543. this._class,
  2544. this._attrib,
  2545. this._pseudo
  2546. ],
  2547. arg = null,
  2548. i = 0,
  2549. len = args.length,
  2550. elementName,
  2551. line,
  2552. col,
  2553. part;
  2554. line = tokenStream.LT(1).startLine;
  2555. col = tokenStream.LT(1).startCol;
  2556. while(i < len && arg === null){
  2557. arg = args[i].call(this);
  2558. i++;
  2559. }
  2560. if (arg === null){
  2561. this._unexpectedToken(tokenStream.LT(1));
  2562. }
  2563. if (arg.type == "elementName"){
  2564. part = new SelectorPart(arg, [], arg.toString(), line, col);
  2565. } else {
  2566. part = new SelectorPart(null, [arg], arg.toString(), line, col);
  2567. }
  2568. return part;
  2569. },
  2570. _declaration: function(){
  2571. var tokenStream = this._tokenStream,
  2572. property = null,
  2573. expr = null,
  2574. prio = null,
  2575. error = null,
  2576. invalid = null,
  2577. propertyName= "";
  2578. property = this._property();
  2579. if (property !== null){
  2580. tokenStream.mustMatch(Tokens.COLON);
  2581. this._readWhitespace();
  2582. expr = this._expr();
  2583. if (!expr || expr.length === 0){
  2584. this._unexpectedToken(tokenStream.LT(1));
  2585. }
  2586. prio = this._prio();
  2587. propertyName = property.toString();
  2588. if (this.options.starHack && property.hack == "*" ||
  2589. this.options.underscoreHack && property.hack == "_") {
  2590. propertyName = property.text;
  2591. }
  2592. try {
  2593. this._validateProperty(propertyName, expr);
  2594. } catch (ex) {
  2595. invalid = ex;
  2596. }
  2597. this.fire({
  2598. type: "property",
  2599. property: property,
  2600. value: expr,
  2601. important: prio,
  2602. line: property.line,
  2603. col: property.col,
  2604. invalid: invalid
  2605. });
  2606. return true;
  2607. } else {
  2608. return false;
  2609. }
  2610. },
  2611. _prio: function(){
  2612. var tokenStream = this._tokenStream,
  2613. result = tokenStream.match(Tokens.IMPORTANT_SYM);
  2614. this._readWhitespace();
  2615. return result;
  2616. },
  2617. _expr: function(inFunction){
  2618. var tokenStream = this._tokenStream,
  2619. values = [],
  2620. value = null,
  2621. operator = null;
  2622. value = this._term(inFunction);
  2623. if (value !== null){
  2624. values.push(value);
  2625. do {
  2626. operator = this._operator(inFunction);
  2627. if (operator){
  2628. values.push(operator);
  2629. } /*else {
  2630. values.push(new PropertyValue(valueParts, valueParts[0].line, valueParts[0].col));
  2631. valueParts = [];
  2632. }*/
  2633. value = this._term(inFunction);
  2634. if (value === null){
  2635. break;
  2636. } else {
  2637. values.push(value);
  2638. }
  2639. } while(true);
  2640. }
  2641. return values.length > 0 ? new PropertyValue(values, values[0].line, values[0].col) : null;
  2642. },
  2643. _term: function(inFunction){
  2644. var tokenStream = this._tokenStream,
  2645. unary = null,
  2646. value = null,
  2647. endChar = null,
  2648. token,
  2649. line,
  2650. col;
  2651. unary = this._unary_operator();
  2652. if (unary !== null){
  2653. line = tokenStream.token().startLine;
  2654. col = tokenStream.token().startCol;
  2655. }
  2656. if (tokenStream.peek() == Tokens.IE_FUNCTION && this.options.ieFilters){
  2657. value = this._ie_function();
  2658. if (unary === null){
  2659. line = tokenStream.token().startLine;
  2660. col = tokenStream.token().startCol;
  2661. }
  2662. } else if (inFunction && tokenStream.match([Tokens.LPAREN, Tokens.LBRACE, Tokens.LBRACKET])){
  2663. token = tokenStream.token();
  2664. endChar = token.endChar;
  2665. value = token.value + this._expr(inFunction).text;
  2666. if (unary === null){
  2667. line = tokenStream.token().startLine;
  2668. col = tokenStream.token().startCol;
  2669. }
  2670. tokenStream.mustMatch(Tokens.type(endChar));
  2671. value += endChar;
  2672. this._readWhitespace();
  2673. } else if (tokenStream.match([Tokens.NUMBER, Tokens.PERCENTAGE, Tokens.LENGTH,
  2674. Tokens.ANGLE, Tokens.TIME,
  2675. Tokens.FREQ, Tokens.STRING, Tokens.IDENT, Tokens.URI, Tokens.UNICODE_RANGE])){
  2676. value = tokenStream.token().value;
  2677. if (unary === null){
  2678. line = tokenStream.token().startLine;
  2679. col = tokenStream.token().startCol;
  2680. }
  2681. this._readWhitespace();
  2682. } else {
  2683. token = this._hexcolor();
  2684. if (token === null){
  2685. if (unary === null){
  2686. line = tokenStream.LT(1).startLine;
  2687. col = tokenStream.LT(1).startCol;
  2688. }
  2689. if (value === null){
  2690. if (tokenStream.LA(3) == Tokens.EQUALS && this.options.ieFilters){
  2691. value = this._ie_function();
  2692. } else {
  2693. value = this._function();
  2694. }
  2695. }
  2696. } else {
  2697. value = token.value;
  2698. if (unary === null){
  2699. line = token.startLine;
  2700. col = token.startCol;
  2701. }
  2702. }
  2703. }
  2704. return value !== null ?
  2705. new PropertyValuePart(unary !== null ? unary + value : value, line, col) :
  2706. null;
  2707. },
  2708. _function: function(){
  2709. var tokenStream = this._tokenStream,
  2710. functionText = null,
  2711. expr = null,
  2712. lt;
  2713. if (tokenStream.match(Tokens.FUNCTION)){
  2714. functionText = tokenStream.token().value;
  2715. this._readWhitespace();
  2716. expr = this._expr(true);
  2717. functionText += expr;
  2718. if (this.options.ieFilters && tokenStream.peek() == Tokens.EQUALS){
  2719. do {
  2720. if (this._readWhitespace()){
  2721. functionText += tokenStream.token().value;
  2722. }
  2723. if (tokenStream.LA(0) == Tokens.COMMA){
  2724. functionText += tokenStream.token().value;
  2725. }
  2726. tokenStream.match(Tokens.IDENT);
  2727. functionText += tokenStream.token().value;
  2728. tokenStream.match(Tokens.EQUALS);
  2729. functionText += tokenStream.token().value;
  2730. lt = tokenStream.peek();
  2731. while(lt != Tokens.COMMA && lt != Tokens.S && lt != Tokens.RPAREN){
  2732. tokenStream.get();
  2733. functionText += tokenStream.token().value;
  2734. lt = tokenStream.peek();
  2735. }
  2736. } while(tokenStream.match([Tokens.COMMA, Tokens.S]));
  2737. }
  2738. tokenStream.match(Tokens.RPAREN);
  2739. functionText += ")";
  2740. this._readWhitespace();
  2741. }
  2742. return functionText;
  2743. },
  2744. _ie_function: function(){
  2745. var tokenStream = this._tokenStream,
  2746. functionText = null,
  2747. expr = null,
  2748. lt;
  2749. if (tokenStream.match([Tokens.IE_FUNCTION, Tokens.FUNCTION])){
  2750. functionText = tokenStream.token().value;
  2751. do {
  2752. if (this._readWhitespace()){
  2753. functionText += tokenStream.token().value;
  2754. }
  2755. if (tokenStream.LA(0) == Tokens.COMMA){
  2756. functionText += tokenStream.token().value;
  2757. }
  2758. tokenStream.match(Tokens.IDENT);
  2759. functionText += tokenStream.token().value;
  2760. tokenStream.match(Tokens.EQUALS);
  2761. functionText += tokenStream.token().value;
  2762. lt = tokenStream.peek();
  2763. while(lt != Tokens.COMMA && lt != Tokens.S && lt != Tokens.RPAREN){
  2764. tokenStream.get();
  2765. functionText += tokenStream.token().value;
  2766. lt = tokenStream.peek();
  2767. }
  2768. } while(tokenStream.match([Tokens.COMMA, Tokens.S]));
  2769. tokenStream.match(Tokens.RPAREN);
  2770. functionText += ")";
  2771. this._readWhitespace();
  2772. }
  2773. return functionText;
  2774. },
  2775. _hexcolor: function(){
  2776. var tokenStream = this._tokenStream,
  2777. token = null,
  2778. color;
  2779. if(tokenStream.match(Tokens.HASH)){
  2780. token = tokenStream.token();
  2781. color = token.value;
  2782. if (!/#[a-f0-9]{3,6}/i.test(color)){
  2783. throw new SyntaxError("Expected a hex color but found '" + color + "' at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
  2784. }
  2785. this._readWhitespace();
  2786. }
  2787. return token;
  2788. },
  2789. _keyframes: function(){
  2790. var tokenStream = this._tokenStream,
  2791. token,
  2792. tt,
  2793. name,
  2794. prefix = "";
  2795. tokenStream.mustMatch(Tokens.KEYFRAMES_SYM);
  2796. token = tokenStream.token();
  2797. if (/^@\-([^\-]+)\-/.test(token.value)) {
  2798. prefix = RegExp.$1;
  2799. }
  2800. this._readWhitespace();
  2801. name = this._keyframe_name();
  2802. this._readWhitespace();
  2803. tokenStream.mustMatch(Tokens.LBRACE);
  2804. this.fire({
  2805. type: "startkeyframes",
  2806. name: name,
  2807. prefix: prefix,
  2808. line: token.startLine,
  2809. col: token.startCol
  2810. });
  2811. this._readWhitespace();
  2812. tt = tokenStream.peek();
  2813. while(tt == Tokens.IDENT || tt == Tokens.PERCENTAGE) {
  2814. this._keyframe_rule();
  2815. this._readWhitespace();
  2816. tt = tokenStream.peek();
  2817. }
  2818. this.fire({
  2819. type: "endkeyframes",
  2820. name: name,
  2821. prefix: prefix,
  2822. line: token.startLine,
  2823. col: token.startCol
  2824. });
  2825. this._readWhitespace();
  2826. tokenStream.mustMatch(Tokens.RBRACE);
  2827. },
  2828. _keyframe_name: function(){
  2829. var tokenStream = this._tokenStream,
  2830. token;
  2831. tokenStream.mustMatch([Tokens.IDENT, Tokens.STRING]);
  2832. return SyntaxUnit.fromToken(tokenStream.token());
  2833. },
  2834. _keyframe_rule: function(){
  2835. var tokenStream = this._tokenStream,
  2836. token,
  2837. keyList = this._key_list();
  2838. this.fire({
  2839. type: "startkeyframerule",
  2840. keys: keyList,
  2841. line: keyList[0].line,
  2842. col: keyList[0].col
  2843. });
  2844. this._readDeclarations(true);
  2845. this.fire({
  2846. type: "endkeyframerule",
  2847. keys: keyList,
  2848. line: keyList[0].line,
  2849. col: keyList[0].col
  2850. });
  2851. },
  2852. _key_list: function(){
  2853. var tokenStream = this._tokenStream,
  2854. token,
  2855. key,
  2856. keyList = [];
  2857. keyList.push(this._key());
  2858. this._readWhitespace();
  2859. while(tokenStream.match(Tokens.COMMA)){
  2860. this._readWhitespace();
  2861. keyList.push(this._key());
  2862. this._readWhitespace();
  2863. }
  2864. return keyList;
  2865. },
  2866. _key: function(){
  2867. var tokenStream = this._tokenStream,
  2868. token;
  2869. if (tokenStream.match(Tokens.PERCENTAGE)){
  2870. return SyntaxUnit.fromToken(tokenStream.token());
  2871. } else if (tokenStream.match(Tokens.IDENT)){
  2872. token = tokenStream.token();
  2873. if (/from|to/i.test(token.value)){
  2874. return SyntaxUnit.fromToken(token);
  2875. }
  2876. tokenStream.unget();
  2877. }
  2878. this._unexpectedToken(tokenStream.LT(1));
  2879. },
  2880. _skipCruft: function(){
  2881. while(this._tokenStream.match([Tokens.S, Tokens.CDO, Tokens.CDC])){
  2882. }
  2883. },
  2884. _readDeclarations: function(checkStart, readMargins){
  2885. var tokenStream = this._tokenStream,
  2886. tt;
  2887. this._readWhitespace();
  2888. if (checkStart){
  2889. tokenStream.mustMatch(Tokens.LBRACE);
  2890. }
  2891. this._readWhitespace();
  2892. try {
  2893. while(true){
  2894. if (tokenStream.match(Tokens.SEMICOLON) || (readMargins && this._margin())){
  2895. } else if (this._declaration()){
  2896. if (!tokenStream.match(Tokens.SEMICOLON)){
  2897. break;
  2898. }
  2899. } else {
  2900. break;
  2901. }
  2902. this._readWhitespace();
  2903. }
  2904. tokenStream.mustMatch(Tokens.RBRACE);
  2905. this._readWhitespace();
  2906. } catch (ex) {
  2907. if (ex instanceof SyntaxError && !this.options.strict){
  2908. this.fire({
  2909. type: "error",
  2910. error: ex,
  2911. message: ex.message,
  2912. line: ex.line,
  2913. col: ex.col
  2914. });
  2915. tt = tokenStream.advance([Tokens.SEMICOLON, Tokens.RBRACE]);
  2916. if (tt == Tokens.SEMICOLON){
  2917. this._readDeclarations(false, readMargins);
  2918. } else if (tt != Tokens.RBRACE){
  2919. throw ex;
  2920. }
  2921. } else {
  2922. throw ex;
  2923. }
  2924. }
  2925. },
  2926. _readWhitespace: function(){
  2927. var tokenStream = this._tokenStream,
  2928. ws = "";
  2929. while(tokenStream.match(Tokens.S)){
  2930. ws += tokenStream.token().value;
  2931. }
  2932. return ws;
  2933. },
  2934. _unexpectedToken: function(token){
  2935. throw new SyntaxError("Unexpected token '" + token.value + "' at line " + token.startLine + ", col " + token.startCol + ".", token.startLine, token.startCol);
  2936. },
  2937. _verifyEnd: function(){
  2938. if (this._tokenStream.LA(1) != Tokens.EOF){
  2939. this._unexpectedToken(this._tokenStream.LT(1));
  2940. }
  2941. },
  2942. _validateProperty: function(property, value){
  2943. Validation.validate(property, value);
  2944. },
  2945. parse: function(input){
  2946. this._tokenStream = new TokenStream(input, Tokens);
  2947. this._stylesheet();
  2948. },
  2949. parseStyleSheet: function(input){
  2950. return this.parse(input);
  2951. },
  2952. parseMediaQuery: function(input){
  2953. this._tokenStream = new TokenStream(input, Tokens);
  2954. var result = this._media_query();
  2955. this._verifyEnd();
  2956. return result;
  2957. },
  2958. parsePropertyValue: function(input){
  2959. this._tokenStream = new TokenStream(input, Tokens);
  2960. this._readWhitespace();
  2961. var result = this._expr();
  2962. this._readWhitespace();
  2963. this._verifyEnd();
  2964. return result;
  2965. },
  2966. parseRule: function(input){
  2967. this._tokenStream = new TokenStream(input, Tokens);
  2968. this._readWhitespace();
  2969. var result = this._ruleset();
  2970. this._readWhitespace();
  2971. this._verifyEnd();
  2972. return result;
  2973. },
  2974. parseSelector: function(input){
  2975. this._tokenStream = new TokenStream(input, Tokens);
  2976. this._readWhitespace();
  2977. var result = this._selector();
  2978. this._readWhitespace();
  2979. this._verifyEnd();
  2980. return result;
  2981. },
  2982. parseStyleAttribute: function(input){
  2983. input += "}"; // for error recovery in _readDeclarations()
  2984. this._tokenStream = new TokenStream(input, Tokens);
  2985. this._readDeclarations();
  2986. }
  2987. };
  2988. for (prop in additions){
  2989. if (additions.hasOwnProperty(prop)){
  2990. proto[prop] = additions[prop];
  2991. }
  2992. }
  2993. return proto;
  2994. }();
  2995. var Properties = {
  2996. "align-items" : "flex-start | flex-end | center | baseline | stretch",
  2997. "align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",
  2998. "align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
  2999. "-webkit-align-items" : "flex-start | flex-end | center | baseline | stretch",
  3000. "-webkit-align-content" : "flex-start | flex-end | center | space-between | space-around | stretch",
  3001. "-webkit-align-self" : "auto | flex-start | flex-end | center | baseline | stretch",
  3002. "alignment-adjust" : "auto | baseline | before-edge | text-before-edge | middle | central | after-edge | text-after-edge | ideographic | alphabetic | hanging | mathematical | <percentage> | <length>",
  3003. "alignment-baseline" : "baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
  3004. "animation" : 1,
  3005. "animation-delay" : { multi: "<time>", comma: true },
  3006. "animation-direction" : { multi: "normal | alternate", comma: true },
  3007. "animation-duration" : { multi: "<time>", comma: true },
  3008. "animation-fill-mode" : { multi: "none | forwards | backwards | both", comma: true },
  3009. "animation-iteration-count" : { multi: "<number> | infinite", comma: true },
  3010. "animation-name" : { multi: "none | <ident>", comma: true },
  3011. "animation-play-state" : { multi: "running | paused", comma: true },
  3012. "animation-timing-function" : 1,
  3013. "-moz-animation-delay" : { multi: "<time>", comma: true },
  3014. "-moz-animation-direction" : { multi: "normal | alternate", comma: true },
  3015. "-moz-animation-duration" : { multi: "<time>", comma: true },
  3016. "-moz-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
  3017. "-moz-animation-name" : { multi: "none | <ident>", comma: true },
  3018. "-moz-animation-play-state" : { multi: "running | paused", comma: true },
  3019. "-ms-animation-delay" : { multi: "<time>", comma: true },
  3020. "-ms-animation-direction" : { multi: "normal | alternate", comma: true },
  3021. "-ms-animation-duration" : { multi: "<time>", comma: true },
  3022. "-ms-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
  3023. "-ms-animation-name" : { multi: "none | <ident>", comma: true },
  3024. "-ms-animation-play-state" : { multi: "running | paused", comma: true },
  3025. "-webkit-animation-delay" : { multi: "<time>", comma: true },
  3026. "-webkit-animation-direction" : { multi: "normal | alternate", comma: true },
  3027. "-webkit-animation-duration" : { multi: "<time>", comma: true },
  3028. "-webkit-animation-fill-mode" : { multi: "none | forwards | backwards | both", comma: true },
  3029. "-webkit-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
  3030. "-webkit-animation-name" : { multi: "none | <ident>", comma: true },
  3031. "-webkit-animation-play-state" : { multi: "running | paused", comma: true },
  3032. "-o-animation-delay" : { multi: "<time>", comma: true },
  3033. "-o-animation-direction" : { multi: "normal | alternate", comma: true },
  3034. "-o-animation-duration" : { multi: "<time>", comma: true },
  3035. "-o-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
  3036. "-o-animation-name" : { multi: "none | <ident>", comma: true },
  3037. "-o-animation-play-state" : { multi: "running | paused", comma: true },
  3038. "appearance" : "icon | window | desktop | workspace | document | tooltip | dialog | button | push-button | hyperlink | radio-button | checkbox | menu-item | tab | menu | menubar | pull-down-menu | pop-up-menu | list-menu | radio-group | checkbox-group | outline-tree | range | field | combo-box | signature | password | normal | none | inherit",
  3039. "azimuth" : function (expression) {
  3040. var simple = "<angle> | leftwards | rightwards | inherit",
  3041. direction = "left-side | far-left | left | center-left | center | center-right | right | far-right | right-side",
  3042. behind = false,
  3043. valid = false,
  3044. part;
  3045. if (!ValidationTypes.isAny(expression, simple)) {
  3046. if (ValidationTypes.isAny(expression, "behind")) {
  3047. behind = true;
  3048. valid = true;
  3049. }
  3050. if (ValidationTypes.isAny(expression, direction)) {
  3051. valid = true;
  3052. if (!behind) {
  3053. ValidationTypes.isAny(expression, "behind");
  3054. }
  3055. }
  3056. }
  3057. if (expression.hasNext()) {
  3058. part = expression.next();
  3059. if (valid) {
  3060. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  3061. } else {
  3062. throw new ValidationError("Expected (<'azimuth'>) but found '" + part + "'.", part.line, part.col);
  3063. }
  3064. }
  3065. },
  3066. "backface-visibility" : "visible | hidden",
  3067. "background" : 1,
  3068. "background-attachment" : { multi: "<attachment>", comma: true },
  3069. "background-clip" : { multi: "<box>", comma: true },
  3070. "background-color" : "<color> | inherit",
  3071. "background-image" : { multi: "<bg-image>", comma: true },
  3072. "background-origin" : { multi: "<box>", comma: true },
  3073. "background-position" : { multi: "<bg-position>", comma: true },
  3074. "background-repeat" : { multi: "<repeat-style>" },
  3075. "background-size" : { multi: "<bg-size>", comma: true },
  3076. "baseline-shift" : "baseline | sub | super | <percentage> | <length>",
  3077. "behavior" : 1,
  3078. "binding" : 1,
  3079. "bleed" : "<length>",
  3080. "bookmark-label" : "<content> | <attr> | <string>",
  3081. "bookmark-level" : "none | <integer>",
  3082. "bookmark-state" : "open | closed",
  3083. "bookmark-target" : "none | <uri> | <attr>",
  3084. "border" : "<border-width> || <border-style> || <color>",
  3085. "border-bottom" : "<border-width> || <border-style> || <color>",
  3086. "border-bottom-color" : "<color> | inherit",
  3087. "border-bottom-left-radius" : "<x-one-radius>",
  3088. "border-bottom-right-radius" : "<x-one-radius>",
  3089. "border-bottom-style" : "<border-style>",
  3090. "border-bottom-width" : "<border-width>",
  3091. "border-collapse" : "collapse | separate | inherit",
  3092. "border-color" : { multi: "<color> | inherit", max: 4 },
  3093. "border-image" : 1,
  3094. "border-image-outset" : { multi: "<length> | <number>", max: 4 },
  3095. "border-image-repeat" : { multi: "stretch | repeat | round", max: 2 },
  3096. "border-image-slice" : function(expression) {
  3097. var valid = false,
  3098. numeric = "<number> | <percentage>",
  3099. fill = false,
  3100. count = 0,
  3101. max = 4,
  3102. part;
  3103. if (ValidationTypes.isAny(expression, "fill")) {
  3104. fill = true;
  3105. valid = true;
  3106. }
  3107. while (expression.hasNext() && count < max) {
  3108. valid = ValidationTypes.isAny(expression, numeric);
  3109. if (!valid) {
  3110. break;
  3111. }
  3112. count++;
  3113. }
  3114. if (!fill) {
  3115. ValidationTypes.isAny(expression, "fill");
  3116. } else {
  3117. valid = true;
  3118. }
  3119. if (expression.hasNext()) {
  3120. part = expression.next();
  3121. if (valid) {
  3122. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  3123. } else {
  3124. throw new ValidationError("Expected ([<number> | <percentage>]{1,4} && fill?) but found '" + part + "'.", part.line, part.col);
  3125. }
  3126. }
  3127. },
  3128. "border-image-source" : "<image> | none",
  3129. "border-image-width" : { multi: "<length> | <percentage> | <number> | auto", max: 4 },
  3130. "border-left" : "<border-width> || <border-style> || <color>",
  3131. "border-left-color" : "<color> | inherit",
  3132. "border-left-style" : "<border-style>",
  3133. "border-left-width" : "<border-width>",
  3134. "border-radius" : function(expression) {
  3135. var valid = false,
  3136. simple = "<length> | <percentage> | inherit",
  3137. slash = false,
  3138. fill = false,
  3139. count = 0,
  3140. max = 8,
  3141. part;
  3142. while (expression.hasNext() && count < max) {
  3143. valid = ValidationTypes.isAny(expression, simple);
  3144. if (!valid) {
  3145. if (expression.peek() == "/" && count > 0 && !slash) {
  3146. slash = true;
  3147. max = count + 5;
  3148. expression.next();
  3149. } else {
  3150. break;
  3151. }
  3152. }
  3153. count++;
  3154. }
  3155. if (expression.hasNext()) {
  3156. part = expression.next();
  3157. if (valid) {
  3158. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  3159. } else {
  3160. throw new ValidationError("Expected (<'border-radius'>) but found '" + part + "'.", part.line, part.col);
  3161. }
  3162. }
  3163. },
  3164. "border-right" : "<border-width> || <border-style> || <color>",
  3165. "border-right-color" : "<color> | inherit",
  3166. "border-right-style" : "<border-style>",
  3167. "border-right-width" : "<border-width>",
  3168. "border-spacing" : { multi: "<length> | inherit", max: 2 },
  3169. "border-style" : { multi: "<border-style>", max: 4 },
  3170. "border-top" : "<border-width> || <border-style> || <color>",
  3171. "border-top-color" : "<color> | inherit",
  3172. "border-top-left-radius" : "<x-one-radius>",
  3173. "border-top-right-radius" : "<x-one-radius>",
  3174. "border-top-style" : "<border-style>",
  3175. "border-top-width" : "<border-width>",
  3176. "border-width" : { multi: "<border-width>", max: 4 },
  3177. "bottom" : "<margin-width> | inherit",
  3178. "-moz-box-align" : "start | end | center | baseline | stretch",
  3179. "-moz-box-decoration-break" : "slice |clone",
  3180. "-moz-box-direction" : "normal | reverse | inherit",
  3181. "-moz-box-flex" : "<number>",
  3182. "-moz-box-flex-group" : "<integer>",
  3183. "-moz-box-lines" : "single | multiple",
  3184. "-moz-box-ordinal-group" : "<integer>",
  3185. "-moz-box-orient" : "horizontal | vertical | inline-axis | block-axis | inherit",
  3186. "-moz-box-pack" : "start | end | center | justify",
  3187. "-webkit-box-align" : "start | end | center | baseline | stretch",
  3188. "-webkit-box-decoration-break" : "slice |clone",
  3189. "-webkit-box-direction" : "normal | reverse | inherit",
  3190. "-webkit-box-flex" : "<number>",
  3191. "-webkit-box-flex-group" : "<integer>",
  3192. "-webkit-box-lines" : "single | multiple",
  3193. "-webkit-box-ordinal-group" : "<integer>",
  3194. "-webkit-box-orient" : "horizontal | vertical | inline-axis | block-axis | inherit",
  3195. "-webkit-box-pack" : "start | end | center | justify",
  3196. "box-shadow" : function (expression) {
  3197. var result = false,
  3198. part;
  3199. if (!ValidationTypes.isAny(expression, "none")) {
  3200. Validation.multiProperty("<shadow>", expression, true, Infinity);
  3201. } else {
  3202. if (expression.hasNext()) {
  3203. part = expression.next();
  3204. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  3205. }
  3206. }
  3207. },
  3208. "box-sizing" : "content-box | border-box | inherit",
  3209. "break-after" : "auto | always | avoid | left | right | page | column | avoid-page | avoid-column",
  3210. "break-before" : "auto | always | avoid | left | right | page | column | avoid-page | avoid-column",
  3211. "break-inside" : "auto | avoid | avoid-page | avoid-column",
  3212. "caption-side" : "top | bottom | inherit",
  3213. "clear" : "none | right | left | both | inherit",
  3214. "clip" : 1,
  3215. "color" : "<color> | inherit",
  3216. "color-profile" : 1,
  3217. "column-count" : "<integer> | auto", //http://www.w3.org/TR/css3-multicol/
  3218. "column-fill" : "auto | balance",
  3219. "column-gap" : "<length> | normal",
  3220. "column-rule" : "<border-width> || <border-style> || <color>",
  3221. "column-rule-color" : "<color>",
  3222. "column-rule-style" : "<border-style>",
  3223. "column-rule-width" : "<border-width>",
  3224. "column-span" : "none | all",
  3225. "column-width" : "<length> | auto",
  3226. "columns" : 1,
  3227. "content" : 1,
  3228. "counter-increment" : 1,
  3229. "counter-reset" : 1,
  3230. "crop" : "<shape> | auto",
  3231. "cue" : "cue-after | cue-before | inherit",
  3232. "cue-after" : 1,
  3233. "cue-before" : 1,
  3234. "cursor" : 1,
  3235. "direction" : "ltr | rtl | inherit",
  3236. "display" : "inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | grid | inline-grid | none | inherit | -moz-box | -moz-inline-block | -moz-inline-box | -moz-inline-grid | -moz-inline-stack | -moz-inline-table | -moz-grid | -moz-grid-group | -moz-grid-line | -moz-groupbox | -moz-deck | -moz-popup | -moz-stack | -moz-marker | -webkit-box | -webkit-inline-box | -ms-flexbox | -ms-inline-flexbox | flex | -webkit-flex | inline-flex | -webkit-inline-flex",
  3237. "dominant-baseline" : 1,
  3238. "drop-initial-after-adjust" : "central | middle | after-edge | text-after-edge | ideographic | alphabetic | mathematical | <percentage> | <length>",
  3239. "drop-initial-after-align" : "baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
  3240. "drop-initial-before-adjust" : "before-edge | text-before-edge | central | middle | hanging | mathematical | <percentage> | <length>",
  3241. "drop-initial-before-align" : "caps-height | baseline | use-script | before-edge | text-before-edge | after-edge | text-after-edge | central | middle | ideographic | alphabetic | hanging | mathematical",
  3242. "drop-initial-size" : "auto | line | <length> | <percentage>",
  3243. "drop-initial-value" : "initial | <integer>",
  3244. "elevation" : "<angle> | below | level | above | higher | lower | inherit",
  3245. "empty-cells" : "show | hide | inherit",
  3246. "filter" : 1,
  3247. "fit" : "fill | hidden | meet | slice",
  3248. "fit-position" : 1,
  3249. "flex" : "<flex>",
  3250. "flex-basis" : "<width>",
  3251. "flex-direction" : "row | row-reverse | column | column-reverse",
  3252. "flex-flow" : "<flex-direction> || <flex-wrap>",
  3253. "flex-grow" : "<number>",
  3254. "flex-shrink" : "<number>",
  3255. "flex-wrap" : "nowrap | wrap | wrap-reverse",
  3256. "-webkit-flex" : "<flex>",
  3257. "-webkit-flex-basis" : "<width>",
  3258. "-webkit-flex-direction" : "row | row-reverse | column | column-reverse",
  3259. "-webkit-flex-flow" : "<flex-direction> || <flex-wrap>",
  3260. "-webkit-flex-grow" : "<number>",
  3261. "-webkit-flex-shrink" : "<number>",
  3262. "-webkit-flex-wrap" : "nowrap | wrap | wrap-reverse",
  3263. "-ms-flex" : "<flex>",
  3264. "-ms-flex-align" : "start | end | center | stretch | baseline",
  3265. "-ms-flex-direction" : "row | row-reverse | column | column-reverse | inherit",
  3266. "-ms-flex-order" : "<number>",
  3267. "-ms-flex-pack" : "start | end | center | justify",
  3268. "-ms-flex-wrap" : "nowrap | wrap | wrap-reverse",
  3269. "float" : "left | right | none | inherit",
  3270. "float-offset" : 1,
  3271. "font" : 1,
  3272. "font-family" : 1,
  3273. "font-size" : "<absolute-size> | <relative-size> | <length> | <percentage> | inherit",
  3274. "font-size-adjust" : "<number> | none | inherit",
  3275. "font-stretch" : "normal | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded | inherit",
  3276. "font-style" : "normal | italic | oblique | inherit",
  3277. "font-variant" : "normal | small-caps | inherit",
  3278. "font-weight" : "normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit",
  3279. "grid-cell-stacking" : "columns | rows | layer",
  3280. "grid-column" : 1,
  3281. "grid-columns" : 1,
  3282. "grid-column-align" : "start | end | center | stretch",
  3283. "grid-column-sizing" : 1,
  3284. "grid-column-span" : "<integer>",
  3285. "grid-flow" : "none | rows | columns",
  3286. "grid-layer" : "<integer>",
  3287. "grid-row" : 1,
  3288. "grid-rows" : 1,
  3289. "grid-row-align" : "start | end | center | stretch",
  3290. "grid-row-span" : "<integer>",
  3291. "grid-row-sizing" : 1,
  3292. "hanging-punctuation" : 1,
  3293. "height" : "<margin-width> | <content-sizing> | inherit",
  3294. "hyphenate-after" : "<integer> | auto",
  3295. "hyphenate-before" : "<integer> | auto",
  3296. "hyphenate-character" : "<string> | auto",
  3297. "hyphenate-lines" : "no-limit | <integer>",
  3298. "hyphenate-resource" : 1,
  3299. "hyphens" : "none | manual | auto",
  3300. "icon" : 1,
  3301. "image-orientation" : "angle | auto",
  3302. "image-rendering" : 1,
  3303. "image-resolution" : 1,
  3304. "inline-box-align" : "initial | last | <integer>",
  3305. "justify-content" : "flex-start | flex-end | center | space-between | space-around",
  3306. "-webkit-justify-content" : "flex-start | flex-end | center | space-between | space-around",
  3307. "left" : "<margin-width> | inherit",
  3308. "letter-spacing" : "<length> | normal | inherit",
  3309. "line-height" : "<number> | <length> | <percentage> | normal | inherit",
  3310. "line-break" : "auto | loose | normal | strict",
  3311. "line-stacking" : 1,
  3312. "line-stacking-ruby" : "exclude-ruby | include-ruby",
  3313. "line-stacking-shift" : "consider-shifts | disregard-shifts",
  3314. "line-stacking-strategy" : "inline-line-height | block-line-height | max-height | grid-height",
  3315. "list-style" : 1,
  3316. "list-style-image" : "<uri> | none | inherit",
  3317. "list-style-position" : "inside | outside | inherit",
  3318. "list-style-type" : "disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower-latin | upper-latin | armenian | georgian | lower-alpha | upper-alpha | none | inherit",
  3319. "margin" : { multi: "<margin-width> | inherit", max: 4 },
  3320. "margin-bottom" : "<margin-width> | inherit",
  3321. "margin-left" : "<margin-width> | inherit",
  3322. "margin-right" : "<margin-width> | inherit",
  3323. "margin-top" : "<margin-width> | inherit",
  3324. "mark" : 1,
  3325. "mark-after" : 1,
  3326. "mark-before" : 1,
  3327. "marks" : 1,
  3328. "marquee-direction" : 1,
  3329. "marquee-play-count" : 1,
  3330. "marquee-speed" : 1,
  3331. "marquee-style" : 1,
  3332. "max-height" : "<length> | <percentage> | <content-sizing> | none | inherit",
  3333. "max-width" : "<length> | <percentage> | <content-sizing> | none | inherit",
  3334. "min-height" : "<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats | inherit",
  3335. "min-width" : "<length> | <percentage> | <content-sizing> | contain-floats | -moz-contain-floats | -webkit-contain-floats | inherit",
  3336. "move-to" : 1,
  3337. "nav-down" : 1,
  3338. "nav-index" : 1,
  3339. "nav-left" : 1,
  3340. "nav-right" : 1,
  3341. "nav-up" : 1,
  3342. "opacity" : "<number> | inherit",
  3343. "order" : "<integer>",
  3344. "-webkit-order" : "<integer>",
  3345. "orphans" : "<integer> | inherit",
  3346. "outline" : 1,
  3347. "outline-color" : "<color> | invert | inherit",
  3348. "outline-offset" : 1,
  3349. "outline-style" : "<border-style> | inherit",
  3350. "outline-width" : "<border-width> | inherit",
  3351. "overflow" : "visible | hidden | scroll | auto | inherit",
  3352. "overflow-style" : 1,
  3353. "overflow-wrap" : "normal | break-word",
  3354. "overflow-x" : 1,
  3355. "overflow-y" : 1,
  3356. "padding" : { multi: "<padding-width> | inherit", max: 4 },
  3357. "padding-bottom" : "<padding-width> | inherit",
  3358. "padding-left" : "<padding-width> | inherit",
  3359. "padding-right" : "<padding-width> | inherit",
  3360. "padding-top" : "<padding-width> | inherit",
  3361. "page" : 1,
  3362. "page-break-after" : "auto | always | avoid | left | right | inherit",
  3363. "page-break-before" : "auto | always | avoid | left | right | inherit",
  3364. "page-break-inside" : "auto | avoid | inherit",
  3365. "page-policy" : 1,
  3366. "pause" : 1,
  3367. "pause-after" : 1,
  3368. "pause-before" : 1,
  3369. "perspective" : 1,
  3370. "perspective-origin" : 1,
  3371. "phonemes" : 1,
  3372. "pitch" : 1,
  3373. "pitch-range" : 1,
  3374. "play-during" : 1,
  3375. "pointer-events" : "auto | none | visiblePainted | visibleFill | visibleStroke | visible | painted | fill | stroke | all | inherit",
  3376. "position" : "static | relative | absolute | fixed | inherit",
  3377. "presentation-level" : 1,
  3378. "punctuation-trim" : 1,
  3379. "quotes" : 1,
  3380. "rendering-intent" : 1,
  3381. "resize" : 1,
  3382. "rest" : 1,
  3383. "rest-after" : 1,
  3384. "rest-before" : 1,
  3385. "richness" : 1,
  3386. "right" : "<margin-width> | inherit",
  3387. "rotation" : 1,
  3388. "rotation-point" : 1,
  3389. "ruby-align" : 1,
  3390. "ruby-overhang" : 1,
  3391. "ruby-position" : 1,
  3392. "ruby-span" : 1,
  3393. "size" : 1,
  3394. "speak" : "normal | none | spell-out | inherit",
  3395. "speak-header" : "once | always | inherit",
  3396. "speak-numeral" : "digits | continuous | inherit",
  3397. "speak-punctuation" : "code | none | inherit",
  3398. "speech-rate" : 1,
  3399. "src" : 1,
  3400. "stress" : 1,
  3401. "string-set" : 1,
  3402. "table-layout" : "auto | fixed | inherit",
  3403. "tab-size" : "<integer> | <length>",
  3404. "target" : 1,
  3405. "target-name" : 1,
  3406. "target-new" : 1,
  3407. "target-position" : 1,
  3408. "text-align" : "left | right | center | justify | inherit" ,
  3409. "text-align-last" : 1,
  3410. "text-decoration" : 1,
  3411. "text-emphasis" : 1,
  3412. "text-height" : 1,
  3413. "text-indent" : "<length> | <percentage> | inherit",
  3414. "text-justify" : "auto | none | inter-word | inter-ideograph | inter-cluster | distribute | kashida",
  3415. "text-outline" : 1,
  3416. "text-overflow" : 1,
  3417. "text-rendering" : "auto | optimizeSpeed | optimizeLegibility | geometricPrecision | inherit",
  3418. "text-shadow" : 1,
  3419. "text-transform" : "capitalize | uppercase | lowercase | none | inherit",
  3420. "text-wrap" : "normal | none | avoid",
  3421. "top" : "<margin-width> | inherit",
  3422. "-ms-touch-action" : "auto | none | pan-x | pan-y",
  3423. "touch-action" : "auto | none | pan-x | pan-y",
  3424. "transform" : 1,
  3425. "transform-origin" : 1,
  3426. "transform-style" : 1,
  3427. "transition" : 1,
  3428. "transition-delay" : 1,
  3429. "transition-duration" : 1,
  3430. "transition-property" : 1,
  3431. "transition-timing-function" : 1,
  3432. "unicode-bidi" : "normal | embed | isolate | bidi-override | isolate-override | plaintext | inherit",
  3433. "user-modify" : "read-only | read-write | write-only | inherit",
  3434. "user-select" : "none | text | toggle | element | elements | all | inherit",
  3435. "vertical-align" : "auto | use-script | baseline | sub | super | top | text-top | central | middle | bottom | text-bottom | <percentage> | <length>",
  3436. "visibility" : "visible | hidden | collapse | inherit",
  3437. "voice-balance" : 1,
  3438. "voice-duration" : 1,
  3439. "voice-family" : 1,
  3440. "voice-pitch" : 1,
  3441. "voice-pitch-range" : 1,
  3442. "voice-rate" : 1,
  3443. "voice-stress" : 1,
  3444. "voice-volume" : 1,
  3445. "volume" : 1,
  3446. "white-space" : "normal | pre | nowrap | pre-wrap | pre-line | inherit | -pre-wrap | -o-pre-wrap | -moz-pre-wrap | -hp-pre-wrap", //http://perishablepress.com/wrapping-content/
  3447. "white-space-collapse" : 1,
  3448. "widows" : "<integer> | inherit",
  3449. "width" : "<length> | <percentage> | <content-sizing> | auto | inherit",
  3450. "word-break" : "normal | keep-all | break-all",
  3451. "word-spacing" : "<length> | normal | inherit",
  3452. "word-wrap" : "normal | break-word",
  3453. "writing-mode" : "horizontal-tb | vertical-rl | vertical-lr | lr-tb | rl-tb | tb-rl | bt-rl | tb-lr | bt-lr | lr-bt | rl-bt | lr | rl | tb | inherit",
  3454. "z-index" : "<integer> | auto | inherit",
  3455. "zoom" : "<number> | <percentage> | normal"
  3456. };
  3457. function PropertyName(text, hack, line, col){
  3458. SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_NAME_TYPE);
  3459. this.hack = hack;
  3460. }
  3461. PropertyName.prototype = new SyntaxUnit();
  3462. PropertyName.prototype.constructor = PropertyName;
  3463. PropertyName.prototype.toString = function(){
  3464. return (this.hack ? this.hack : "") + this.text;
  3465. };
  3466. function PropertyValue(parts, line, col){
  3467. SyntaxUnit.call(this, parts.join(" "), line, col, Parser.PROPERTY_VALUE_TYPE);
  3468. this.parts = parts;
  3469. }
  3470. PropertyValue.prototype = new SyntaxUnit();
  3471. PropertyValue.prototype.constructor = PropertyValue;
  3472. function PropertyValueIterator(value){
  3473. this._i = 0;
  3474. this._parts = value.parts;
  3475. this._marks = [];
  3476. this.value = value;
  3477. }
  3478. PropertyValueIterator.prototype.count = function(){
  3479. return this._parts.length;
  3480. };
  3481. PropertyValueIterator.prototype.isFirst = function(){
  3482. return this._i === 0;
  3483. };
  3484. PropertyValueIterator.prototype.hasNext = function(){
  3485. return (this._i < this._parts.length);
  3486. };
  3487. PropertyValueIterator.prototype.mark = function(){
  3488. this._marks.push(this._i);
  3489. };
  3490. PropertyValueIterator.prototype.peek = function(count){
  3491. return this.hasNext() ? this._parts[this._i + (count || 0)] : null;
  3492. };
  3493. PropertyValueIterator.prototype.next = function(){
  3494. return this.hasNext() ? this._parts[this._i++] : null;
  3495. };
  3496. PropertyValueIterator.prototype.previous = function(){
  3497. return this._i > 0 ? this._parts[--this._i] : null;
  3498. };
  3499. PropertyValueIterator.prototype.restore = function(){
  3500. if (this._marks.length){
  3501. this._i = this._marks.pop();
  3502. }
  3503. };
  3504. function PropertyValuePart(text, line, col){
  3505. SyntaxUnit.call(this, text, line, col, Parser.PROPERTY_VALUE_PART_TYPE);
  3506. this.type = "unknown";
  3507. var temp;
  3508. if (/^([+\-]?[\d\.]+)([a-z]+)$/i.test(text)){ //dimension
  3509. this.type = "dimension";
  3510. this.value = +RegExp.$1;
  3511. this.units = RegExp.$2;
  3512. switch(this.units.toLowerCase()){
  3513. case "em":
  3514. case "rem":
  3515. case "ex":
  3516. case "px":
  3517. case "cm":
  3518. case "mm":
  3519. case "in":
  3520. case "pt":
  3521. case "pc":
  3522. case "ch":
  3523. case "vh":
  3524. case "vw":
  3525. case "vmax":
  3526. case "vmin":
  3527. this.type = "length";
  3528. break;
  3529. case "deg":
  3530. case "rad":
  3531. case "grad":
  3532. this.type = "angle";
  3533. break;
  3534. case "ms":
  3535. case "s":
  3536. this.type = "time";
  3537. break;
  3538. case "hz":
  3539. case "khz":
  3540. this.type = "frequency";
  3541. break;
  3542. case "dpi":
  3543. case "dpcm":
  3544. this.type = "resolution";
  3545. break;
  3546. }
  3547. } else if (/^([+\-]?[\d\.]+)%$/i.test(text)){ //percentage
  3548. this.type = "percentage";
  3549. this.value = +RegExp.$1;
  3550. } else if (/^([+\-]?\d+)$/i.test(text)){ //integer
  3551. this.type = "integer";
  3552. this.value = +RegExp.$1;
  3553. } else if (/^([+\-]?[\d\.]+)$/i.test(text)){ //number
  3554. this.type = "number";
  3555. this.value = +RegExp.$1;
  3556. } else if (/^#([a-f0-9]{3,6})/i.test(text)){ //hexcolor
  3557. this.type = "color";
  3558. temp = RegExp.$1;
  3559. if (temp.length == 3){
  3560. this.red = parseInt(temp.charAt(0)+temp.charAt(0),16);
  3561. this.green = parseInt(temp.charAt(1)+temp.charAt(1),16);
  3562. this.blue = parseInt(temp.charAt(2)+temp.charAt(2),16);
  3563. } else {
  3564. this.red = parseInt(temp.substring(0,2),16);
  3565. this.green = parseInt(temp.substring(2,4),16);
  3566. this.blue = parseInt(temp.substring(4,6),16);
  3567. }
  3568. } else if (/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i.test(text)){ //rgb() color with absolute numbers
  3569. this.type = "color";
  3570. this.red = +RegExp.$1;
  3571. this.green = +RegExp.$2;
  3572. this.blue = +RegExp.$3;
  3573. } else if (/^rgb\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)){ //rgb() color with percentages
  3574. this.type = "color";
  3575. this.red = +RegExp.$1 * 255 / 100;
  3576. this.green = +RegExp.$2 * 255 / 100;
  3577. this.blue = +RegExp.$3 * 255 / 100;
  3578. } else if (/^rgba\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([\d\.]+)\s*\)/i.test(text)){ //rgba() color with absolute numbers
  3579. this.type = "color";
  3580. this.red = +RegExp.$1;
  3581. this.green = +RegExp.$2;
  3582. this.blue = +RegExp.$3;
  3583. this.alpha = +RegExp.$4;
  3584. } else if (/^rgba\(\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)){ //rgba() color with percentages
  3585. this.type = "color";
  3586. this.red = +RegExp.$1 * 255 / 100;
  3587. this.green = +RegExp.$2 * 255 / 100;
  3588. this.blue = +RegExp.$3 * 255 / 100;
  3589. this.alpha = +RegExp.$4;
  3590. } else if (/^hsl\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*\)/i.test(text)){ //hsl()
  3591. this.type = "color";
  3592. this.hue = +RegExp.$1;
  3593. this.saturation = +RegExp.$2 / 100;
  3594. this.lightness = +RegExp.$3 / 100;
  3595. } else if (/^hsla\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*,\s*([\d\.]+)\s*\)/i.test(text)){ //hsla() color with percentages
  3596. this.type = "color";
  3597. this.hue = +RegExp.$1;
  3598. this.saturation = +RegExp.$2 / 100;
  3599. this.lightness = +RegExp.$3 / 100;
  3600. this.alpha = +RegExp.$4;
  3601. } else if (/^url\(["']?([^\)"']+)["']?\)/i.test(text)){ //URI
  3602. this.type = "uri";
  3603. this.uri = RegExp.$1;
  3604. } else if (/^([^\(]+)\(/i.test(text)){
  3605. this.type = "function";
  3606. this.name = RegExp.$1;
  3607. this.value = text;
  3608. } else if (/^["'][^"']*["']/.test(text)){ //string
  3609. this.type = "string";
  3610. this.value = eval(text);
  3611. } else if (Colors[text.toLowerCase()]){ //named color
  3612. this.type = "color";
  3613. temp = Colors[text.toLowerCase()].substring(1);
  3614. this.red = parseInt(temp.substring(0,2),16);
  3615. this.green = parseInt(temp.substring(2,4),16);
  3616. this.blue = parseInt(temp.substring(4,6),16);
  3617. } else if (/^[\,\/]$/.test(text)){
  3618. this.type = "operator";
  3619. this.value = text;
  3620. } else if (/^[a-z\-_\u0080-\uFFFF][a-z0-9\-_\u0080-\uFFFF]*$/i.test(text)){
  3621. this.type = "identifier";
  3622. this.value = text;
  3623. }
  3624. }
  3625. PropertyValuePart.prototype = new SyntaxUnit();
  3626. PropertyValuePart.prototype.constructor = PropertyValuePart;
  3627. PropertyValuePart.fromToken = function(token){
  3628. return new PropertyValuePart(token.value, token.startLine, token.startCol);
  3629. };
  3630. var Pseudos = {
  3631. ":first-letter": 1,
  3632. ":first-line": 1,
  3633. ":before": 1,
  3634. ":after": 1
  3635. };
  3636. Pseudos.ELEMENT = 1;
  3637. Pseudos.CLASS = 2;
  3638. Pseudos.isElement = function(pseudo){
  3639. return pseudo.indexOf("::") === 0 || Pseudos[pseudo.toLowerCase()] == Pseudos.ELEMENT;
  3640. };
  3641. function Selector(parts, line, col){
  3642. SyntaxUnit.call(this, parts.join(" "), line, col, Parser.SELECTOR_TYPE);
  3643. this.parts = parts;
  3644. this.specificity = Specificity.calculate(this);
  3645. }
  3646. Selector.prototype = new SyntaxUnit();
  3647. Selector.prototype.constructor = Selector;
  3648. function SelectorPart(elementName, modifiers, text, line, col){
  3649. SyntaxUnit.call(this, text, line, col, Parser.SELECTOR_PART_TYPE);
  3650. this.elementName = elementName;
  3651. this.modifiers = modifiers;
  3652. }
  3653. SelectorPart.prototype = new SyntaxUnit();
  3654. SelectorPart.prototype.constructor = SelectorPart;
  3655. function SelectorSubPart(text, type, line, col){
  3656. SyntaxUnit.call(this, text, line, col, Parser.SELECTOR_SUB_PART_TYPE);
  3657. this.type = type;
  3658. this.args = [];
  3659. }
  3660. SelectorSubPart.prototype = new SyntaxUnit();
  3661. SelectorSubPart.prototype.constructor = SelectorSubPart;
  3662. function Specificity(a, b, c, d){
  3663. this.a = a;
  3664. this.b = b;
  3665. this.c = c;
  3666. this.d = d;
  3667. }
  3668. Specificity.prototype = {
  3669. constructor: Specificity,
  3670. compare: function(other){
  3671. var comps = ["a", "b", "c", "d"],
  3672. i, len;
  3673. for (i=0, len=comps.length; i < len; i++){
  3674. if (this[comps[i]] < other[comps[i]]){
  3675. return -1;
  3676. } else if (this[comps[i]] > other[comps[i]]){
  3677. return 1;
  3678. }
  3679. }
  3680. return 0;
  3681. },
  3682. valueOf: function(){
  3683. return (this.a * 1000) + (this.b * 100) + (this.c * 10) + this.d;
  3684. },
  3685. toString: function(){
  3686. return this.a + "," + this.b + "," + this.c + "," + this.d;
  3687. }
  3688. };
  3689. Specificity.calculate = function(selector){
  3690. var i, len,
  3691. part,
  3692. b=0, c=0, d=0;
  3693. function updateValues(part){
  3694. var i, j, len, num,
  3695. elementName = part.elementName ? part.elementName.text : "",
  3696. modifier;
  3697. if (elementName && elementName.charAt(elementName.length-1) != "*") {
  3698. d++;
  3699. }
  3700. for (i=0, len=part.modifiers.length; i < len; i++){
  3701. modifier = part.modifiers[i];
  3702. switch(modifier.type){
  3703. case "class":
  3704. case "attribute":
  3705. c++;
  3706. break;
  3707. case "id":
  3708. b++;
  3709. break;
  3710. case "pseudo":
  3711. if (Pseudos.isElement(modifier.text)){
  3712. d++;
  3713. } else {
  3714. c++;
  3715. }
  3716. break;
  3717. case "not":
  3718. for (j=0, num=modifier.args.length; j < num; j++){
  3719. updateValues(modifier.args[j]);
  3720. }
  3721. }
  3722. }
  3723. }
  3724. for (i=0, len=selector.parts.length; i < len; i++){
  3725. part = selector.parts[i];
  3726. if (part instanceof SelectorPart){
  3727. updateValues(part);
  3728. }
  3729. }
  3730. return new Specificity(0, b, c, d);
  3731. };
  3732. var h = /^[0-9a-fA-F]$/,
  3733. nonascii = /^[\u0080-\uFFFF]$/,
  3734. nl = /\n|\r\n|\r|\f/;
  3735. function isHexDigit(c){
  3736. return c !== null && h.test(c);
  3737. }
  3738. function isDigit(c){
  3739. return c !== null && /\d/.test(c);
  3740. }
  3741. function isWhitespace(c){
  3742. return c !== null && /\s/.test(c);
  3743. }
  3744. function isNewLine(c){
  3745. return c !== null && nl.test(c);
  3746. }
  3747. function isNameStart(c){
  3748. return c !== null && (/[a-z_\u0080-\uFFFF\\]/i.test(c));
  3749. }
  3750. function isNameChar(c){
  3751. return c !== null && (isNameStart(c) || /[0-9\-\\]/.test(c));
  3752. }
  3753. function isIdentStart(c){
  3754. return c !== null && (isNameStart(c) || /\-\\/.test(c));
  3755. }
  3756. function mix(receiver, supplier){
  3757. for (var prop in supplier){
  3758. if (supplier.hasOwnProperty(prop)){
  3759. receiver[prop] = supplier[prop];
  3760. }
  3761. }
  3762. return receiver;
  3763. }
  3764. function TokenStream(input){
  3765. TokenStreamBase.call(this, input, Tokens);
  3766. }
  3767. TokenStream.prototype = mix(new TokenStreamBase(), {
  3768. _getToken: function(channel){
  3769. var c,
  3770. reader = this._reader,
  3771. token = null,
  3772. startLine = reader.getLine(),
  3773. startCol = reader.getCol();
  3774. c = reader.read();
  3775. while(c){
  3776. switch(c){
  3777. case "/":
  3778. if(reader.peek() == "*"){
  3779. token = this.commentToken(c, startLine, startCol);
  3780. } else {
  3781. token = this.charToken(c, startLine, startCol);
  3782. }
  3783. break;
  3784. case "|":
  3785. case "~":
  3786. case "^":
  3787. case "$":
  3788. case "*":
  3789. if(reader.peek() == "="){
  3790. token = this.comparisonToken(c, startLine, startCol);
  3791. } else {
  3792. token = this.charToken(c, startLine, startCol);
  3793. }
  3794. break;
  3795. case "\"":
  3796. case "'":
  3797. token = this.stringToken(c, startLine, startCol);
  3798. break;
  3799. case "#":
  3800. if (isNameChar(reader.peek())){
  3801. token = this.hashToken(c, startLine, startCol);
  3802. } else {
  3803. token = this.charToken(c, startLine, startCol);
  3804. }
  3805. break;
  3806. case ".":
  3807. if (isDigit(reader.peek())){
  3808. token = this.numberToken(c, startLine, startCol);
  3809. } else {
  3810. token = this.charToken(c, startLine, startCol);
  3811. }
  3812. break;
  3813. case "-":
  3814. if (reader.peek() == "-"){ //could be closing HTML-style comment
  3815. token = this.htmlCommentEndToken(c, startLine, startCol);
  3816. } else if (isNameStart(reader.peek())){
  3817. token = this.identOrFunctionToken(c, startLine, startCol);
  3818. } else {
  3819. token = this.charToken(c, startLine, startCol);
  3820. }
  3821. break;
  3822. case "!":
  3823. token = this.importantToken(c, startLine, startCol);
  3824. break;
  3825. case "@":
  3826. token = this.atRuleToken(c, startLine, startCol);
  3827. break;
  3828. case ":":
  3829. token = this.notToken(c, startLine, startCol);
  3830. break;
  3831. case "<":
  3832. token = this.htmlCommentStartToken(c, startLine, startCol);
  3833. break;
  3834. case "U":
  3835. case "u":
  3836. if (reader.peek() == "+"){
  3837. token = this.unicodeRangeToken(c, startLine, startCol);
  3838. break;
  3839. }
  3840. default:
  3841. if (isDigit(c)){
  3842. token = this.numberToken(c, startLine, startCol);
  3843. } else
  3844. if (isWhitespace(c)){
  3845. token = this.whitespaceToken(c, startLine, startCol);
  3846. } else
  3847. if (isIdentStart(c)){
  3848. token = this.identOrFunctionToken(c, startLine, startCol);
  3849. } else
  3850. {
  3851. token = this.charToken(c, startLine, startCol);
  3852. }
  3853. }
  3854. break;
  3855. }
  3856. if (!token && c === null){
  3857. token = this.createToken(Tokens.EOF,null,startLine,startCol);
  3858. }
  3859. return token;
  3860. },
  3861. createToken: function(tt, value, startLine, startCol, options){
  3862. var reader = this._reader;
  3863. options = options || {};
  3864. return {
  3865. value: value,
  3866. type: tt,
  3867. channel: options.channel,
  3868. endChar: options.endChar,
  3869. hide: options.hide || false,
  3870. startLine: startLine,
  3871. startCol: startCol,
  3872. endLine: reader.getLine(),
  3873. endCol: reader.getCol()
  3874. };
  3875. },
  3876. atRuleToken: function(first, startLine, startCol){
  3877. var rule = first,
  3878. reader = this._reader,
  3879. tt = Tokens.CHAR,
  3880. valid = false,
  3881. ident,
  3882. c;
  3883. reader.mark();
  3884. ident = this.readName();
  3885. rule = first + ident;
  3886. tt = Tokens.type(rule.toLowerCase());
  3887. if (tt == Tokens.CHAR || tt == Tokens.UNKNOWN){
  3888. if (rule.length > 1){
  3889. tt = Tokens.UNKNOWN_SYM;
  3890. } else {
  3891. tt = Tokens.CHAR;
  3892. rule = first;
  3893. reader.reset();
  3894. }
  3895. }
  3896. return this.createToken(tt, rule, startLine, startCol);
  3897. },
  3898. charToken: function(c, startLine, startCol){
  3899. var tt = Tokens.type(c);
  3900. var opts = {};
  3901. if (tt == -1){
  3902. tt = Tokens.CHAR;
  3903. } else {
  3904. opts.endChar = Tokens[tt].endChar;
  3905. }
  3906. return this.createToken(tt, c, startLine, startCol, opts);
  3907. },
  3908. commentToken: function(first, startLine, startCol){
  3909. var reader = this._reader,
  3910. comment = this.readComment(first);
  3911. return this.createToken(Tokens.COMMENT, comment, startLine, startCol);
  3912. },
  3913. comparisonToken: function(c, startLine, startCol){
  3914. var reader = this._reader,
  3915. comparison = c + reader.read(),
  3916. tt = Tokens.type(comparison) || Tokens.CHAR;
  3917. return this.createToken(tt, comparison, startLine, startCol);
  3918. },
  3919. hashToken: function(first, startLine, startCol){
  3920. var reader = this._reader,
  3921. name = this.readName(first);
  3922. return this.createToken(Tokens.HASH, name, startLine, startCol);
  3923. },
  3924. htmlCommentStartToken: function(first, startLine, startCol){
  3925. var reader = this._reader,
  3926. text = first;
  3927. reader.mark();
  3928. text += reader.readCount(3);
  3929. if (text == "<!--"){
  3930. return this.createToken(Tokens.CDO, text, startLine, startCol);
  3931. } else {
  3932. reader.reset();
  3933. return this.charToken(first, startLine, startCol);
  3934. }
  3935. },
  3936. htmlCommentEndToken: function(first, startLine, startCol){
  3937. var reader = this._reader,
  3938. text = first;
  3939. reader.mark();
  3940. text += reader.readCount(2);
  3941. if (text == "-->"){
  3942. return this.createToken(Tokens.CDC, text, startLine, startCol);
  3943. } else {
  3944. reader.reset();
  3945. return this.charToken(first, startLine, startCol);
  3946. }
  3947. },
  3948. identOrFunctionToken: function(first, startLine, startCol){
  3949. var reader = this._reader,
  3950. ident = this.readName(first),
  3951. tt = Tokens.IDENT;
  3952. if (reader.peek() == "("){
  3953. ident += reader.read();
  3954. if (ident.toLowerCase() == "url("){
  3955. tt = Tokens.URI;
  3956. ident = this.readURI(ident);
  3957. if (ident.toLowerCase() == "url("){
  3958. tt = Tokens.FUNCTION;
  3959. }
  3960. } else {
  3961. tt = Tokens.FUNCTION;
  3962. }
  3963. } else if (reader.peek() == ":"){ //might be an IE function
  3964. if (ident.toLowerCase() == "progid"){
  3965. ident += reader.readTo("(");
  3966. tt = Tokens.IE_FUNCTION;
  3967. }
  3968. }
  3969. return this.createToken(tt, ident, startLine, startCol);
  3970. },
  3971. importantToken: function(first, startLine, startCol){
  3972. var reader = this._reader,
  3973. important = first,
  3974. tt = Tokens.CHAR,
  3975. temp,
  3976. c;
  3977. reader.mark();
  3978. c = reader.read();
  3979. while(c){
  3980. if (c == "/"){
  3981. if (reader.peek() != "*"){
  3982. break;
  3983. } else {
  3984. temp = this.readComment(c);
  3985. if (temp === ""){ //broken!
  3986. break;
  3987. }
  3988. }
  3989. } else if (isWhitespace(c)){
  3990. important += c + this.readWhitespace();
  3991. } else if (/i/i.test(c)){
  3992. temp = reader.readCount(8);
  3993. if (/mportant/i.test(temp)){
  3994. important += c + temp;
  3995. tt = Tokens.IMPORTANT_SYM;
  3996. }
  3997. break; //we're done
  3998. } else {
  3999. break;
  4000. }
  4001. c = reader.read();
  4002. }
  4003. if (tt == Tokens.CHAR){
  4004. reader.reset();
  4005. return this.charToken(first, startLine, startCol);
  4006. } else {
  4007. return this.createToken(tt, important, startLine, startCol);
  4008. }
  4009. },
  4010. notToken: function(first, startLine, startCol){
  4011. var reader = this._reader,
  4012. text = first;
  4013. reader.mark();
  4014. text += reader.readCount(4);
  4015. if (text.toLowerCase() == ":not("){
  4016. return this.createToken(Tokens.NOT, text, startLine, startCol);
  4017. } else {
  4018. reader.reset();
  4019. return this.charToken(first, startLine, startCol);
  4020. }
  4021. },
  4022. numberToken: function(first, startLine, startCol){
  4023. var reader = this._reader,
  4024. value = this.readNumber(first),
  4025. ident,
  4026. tt = Tokens.NUMBER,
  4027. c = reader.peek();
  4028. if (isIdentStart(c)){
  4029. ident = this.readName(reader.read());
  4030. value += ident;
  4031. if (/^em$|^ex$|^px$|^gd$|^rem$|^vw$|^vh$|^vmax$|^vmin$|^ch$|^cm$|^mm$|^in$|^pt$|^pc$/i.test(ident)){
  4032. tt = Tokens.LENGTH;
  4033. } else if (/^deg|^rad$|^grad$/i.test(ident)){
  4034. tt = Tokens.ANGLE;
  4035. } else if (/^ms$|^s$/i.test(ident)){
  4036. tt = Tokens.TIME;
  4037. } else if (/^hz$|^khz$/i.test(ident)){
  4038. tt = Tokens.FREQ;
  4039. } else if (/^dpi$|^dpcm$/i.test(ident)){
  4040. tt = Tokens.RESOLUTION;
  4041. } else {
  4042. tt = Tokens.DIMENSION;
  4043. }
  4044. } else if (c == "%"){
  4045. value += reader.read();
  4046. tt = Tokens.PERCENTAGE;
  4047. }
  4048. return this.createToken(tt, value, startLine, startCol);
  4049. },
  4050. stringToken: function(first, startLine, startCol){
  4051. var delim = first,
  4052. string = first,
  4053. reader = this._reader,
  4054. prev = first,
  4055. tt = Tokens.STRING,
  4056. c = reader.read();
  4057. while(c){
  4058. string += c;
  4059. if (c == delim && prev != "\\"){
  4060. break;
  4061. }
  4062. if (isNewLine(reader.peek()) && c != "\\"){
  4063. tt = Tokens.INVALID;
  4064. break;
  4065. }
  4066. prev = c;
  4067. c = reader.read();
  4068. }
  4069. if (c === null){
  4070. tt = Tokens.INVALID;
  4071. }
  4072. return this.createToken(tt, string, startLine, startCol);
  4073. },
  4074. unicodeRangeToken: function(first, startLine, startCol){
  4075. var reader = this._reader,
  4076. value = first,
  4077. temp,
  4078. tt = Tokens.CHAR;
  4079. if (reader.peek() == "+"){
  4080. reader.mark();
  4081. value += reader.read();
  4082. value += this.readUnicodeRangePart(true);
  4083. if (value.length == 2){
  4084. reader.reset();
  4085. } else {
  4086. tt = Tokens.UNICODE_RANGE;
  4087. if (value.indexOf("?") == -1){
  4088. if (reader.peek() == "-"){
  4089. reader.mark();
  4090. temp = reader.read();
  4091. temp += this.readUnicodeRangePart(false);
  4092. if (temp.length == 1){
  4093. reader.reset();
  4094. } else {
  4095. value += temp;
  4096. }
  4097. }
  4098. }
  4099. }
  4100. }
  4101. return this.createToken(tt, value, startLine, startCol);
  4102. },
  4103. whitespaceToken: function(first, startLine, startCol){
  4104. var reader = this._reader,
  4105. value = first + this.readWhitespace();
  4106. return this.createToken(Tokens.S, value, startLine, startCol);
  4107. },
  4108. readUnicodeRangePart: function(allowQuestionMark){
  4109. var reader = this._reader,
  4110. part = "",
  4111. c = reader.peek();
  4112. while(isHexDigit(c) && part.length < 6){
  4113. reader.read();
  4114. part += c;
  4115. c = reader.peek();
  4116. }
  4117. if (allowQuestionMark){
  4118. while(c == "?" && part.length < 6){
  4119. reader.read();
  4120. part += c;
  4121. c = reader.peek();
  4122. }
  4123. }
  4124. return part;
  4125. },
  4126. readWhitespace: function(){
  4127. var reader = this._reader,
  4128. whitespace = "",
  4129. c = reader.peek();
  4130. while(isWhitespace(c)){
  4131. reader.read();
  4132. whitespace += c;
  4133. c = reader.peek();
  4134. }
  4135. return whitespace;
  4136. },
  4137. readNumber: function(first){
  4138. var reader = this._reader,
  4139. number = first,
  4140. hasDot = (first == "."),
  4141. c = reader.peek();
  4142. while(c){
  4143. if (isDigit(c)){
  4144. number += reader.read();
  4145. } else if (c == "."){
  4146. if (hasDot){
  4147. break;
  4148. } else {
  4149. hasDot = true;
  4150. number += reader.read();
  4151. }
  4152. } else {
  4153. break;
  4154. }
  4155. c = reader.peek();
  4156. }
  4157. return number;
  4158. },
  4159. readString: function(){
  4160. var reader = this._reader,
  4161. delim = reader.read(),
  4162. string = delim,
  4163. prev = delim,
  4164. c = reader.peek();
  4165. while(c){
  4166. c = reader.read();
  4167. string += c;
  4168. if (c == delim && prev != "\\"){
  4169. break;
  4170. }
  4171. if (isNewLine(reader.peek()) && c != "\\"){
  4172. string = "";
  4173. break;
  4174. }
  4175. prev = c;
  4176. c = reader.peek();
  4177. }
  4178. if (c === null){
  4179. string = "";
  4180. }
  4181. return string;
  4182. },
  4183. readURI: function(first){
  4184. var reader = this._reader,
  4185. uri = first,
  4186. inner = "",
  4187. c = reader.peek();
  4188. reader.mark();
  4189. while(c && isWhitespace(c)){
  4190. reader.read();
  4191. c = reader.peek();
  4192. }
  4193. if (c == "'" || c == "\""){
  4194. inner = this.readString();
  4195. } else {
  4196. inner = this.readURL();
  4197. }
  4198. c = reader.peek();
  4199. while(c && isWhitespace(c)){
  4200. reader.read();
  4201. c = reader.peek();
  4202. }
  4203. if (inner === "" || c != ")"){
  4204. uri = first;
  4205. reader.reset();
  4206. } else {
  4207. uri += inner + reader.read();
  4208. }
  4209. return uri;
  4210. },
  4211. readURL: function(){
  4212. var reader = this._reader,
  4213. url = "",
  4214. c = reader.peek();
  4215. while (/^[!#$%&\\*-~]$/.test(c)){
  4216. url += reader.read();
  4217. c = reader.peek();
  4218. }
  4219. return url;
  4220. },
  4221. readName: function(first){
  4222. var reader = this._reader,
  4223. ident = first || "",
  4224. c = reader.peek();
  4225. while(true){
  4226. if (c == "\\"){
  4227. ident += this.readEscape(reader.read());
  4228. c = reader.peek();
  4229. } else if(c && isNameChar(c)){
  4230. ident += reader.read();
  4231. c = reader.peek();
  4232. } else {
  4233. break;
  4234. }
  4235. }
  4236. return ident;
  4237. },
  4238. readEscape: function(first){
  4239. var reader = this._reader,
  4240. cssEscape = first || "",
  4241. i = 0,
  4242. c = reader.peek();
  4243. if (isHexDigit(c)){
  4244. do {
  4245. cssEscape += reader.read();
  4246. c = reader.peek();
  4247. } while(c && isHexDigit(c) && ++i < 6);
  4248. }
  4249. if (cssEscape.length == 3 && /\s/.test(c) ||
  4250. cssEscape.length == 7 || cssEscape.length == 1){
  4251. reader.read();
  4252. } else {
  4253. c = "";
  4254. }
  4255. return cssEscape + c;
  4256. },
  4257. readComment: function(first){
  4258. var reader = this._reader,
  4259. comment = first || "",
  4260. c = reader.read();
  4261. if (c == "*"){
  4262. while(c){
  4263. comment += c;
  4264. if (comment.length > 2 && c == "*" && reader.peek() == "/"){
  4265. comment += reader.read();
  4266. break;
  4267. }
  4268. c = reader.read();
  4269. }
  4270. return comment;
  4271. } else {
  4272. return "";
  4273. }
  4274. }
  4275. });
  4276. var Tokens = [
  4277. { name: "CDO"},
  4278. { name: "CDC"},
  4279. { name: "S", whitespace: true/*, channel: "ws"*/},
  4280. { name: "COMMENT", comment: true, hide: true, channel: "comment" },
  4281. { name: "INCLUDES", text: "~="},
  4282. { name: "DASHMATCH", text: "|="},
  4283. { name: "PREFIXMATCH", text: "^="},
  4284. { name: "SUFFIXMATCH", text: "$="},
  4285. { name: "SUBSTRINGMATCH", text: "*="},
  4286. { name: "STRING"},
  4287. { name: "IDENT"},
  4288. { name: "HASH"},
  4289. { name: "IMPORT_SYM", text: "@import"},
  4290. { name: "PAGE_SYM", text: "@page"},
  4291. { name: "MEDIA_SYM", text: "@media"},
  4292. { name: "FONT_FACE_SYM", text: "@font-face"},
  4293. { name: "CHARSET_SYM", text: "@charset"},
  4294. { name: "NAMESPACE_SYM", text: "@namespace"},
  4295. { name: "VIEWPORT_SYM", text: ["@viewport", "@-ms-viewport"]},
  4296. { name: "UNKNOWN_SYM" },
  4297. { name: "KEYFRAMES_SYM", text: [ "@keyframes", "@-webkit-keyframes", "@-moz-keyframes", "@-o-keyframes" ] },
  4298. { name: "IMPORTANT_SYM"},
  4299. { name: "LENGTH"},
  4300. { name: "ANGLE"},
  4301. { name: "TIME"},
  4302. { name: "FREQ"},
  4303. { name: "DIMENSION"},
  4304. { name: "PERCENTAGE"},
  4305. { name: "NUMBER"},
  4306. { name: "URI"},
  4307. { name: "FUNCTION"},
  4308. { name: "UNICODE_RANGE"},
  4309. { name: "INVALID"},
  4310. { name: "PLUS", text: "+" },
  4311. { name: "GREATER", text: ">"},
  4312. { name: "COMMA", text: ","},
  4313. { name: "TILDE", text: "~"},
  4314. { name: "NOT"},
  4315. { name: "TOPLEFTCORNER_SYM", text: "@top-left-corner"},
  4316. { name: "TOPLEFT_SYM", text: "@top-left"},
  4317. { name: "TOPCENTER_SYM", text: "@top-center"},
  4318. { name: "TOPRIGHT_SYM", text: "@top-right"},
  4319. { name: "TOPRIGHTCORNER_SYM", text: "@top-right-corner"},
  4320. { name: "BOTTOMLEFTCORNER_SYM", text: "@bottom-left-corner"},
  4321. { name: "BOTTOMLEFT_SYM", text: "@bottom-left"},
  4322. { name: "BOTTOMCENTER_SYM", text: "@bottom-center"},
  4323. { name: "BOTTOMRIGHT_SYM", text: "@bottom-right"},
  4324. { name: "BOTTOMRIGHTCORNER_SYM", text: "@bottom-right-corner"},
  4325. { name: "LEFTTOP_SYM", text: "@left-top"},
  4326. { name: "LEFTMIDDLE_SYM", text: "@left-middle"},
  4327. { name: "LEFTBOTTOM_SYM", text: "@left-bottom"},
  4328. { name: "RIGHTTOP_SYM", text: "@right-top"},
  4329. { name: "RIGHTMIDDLE_SYM", text: "@right-middle"},
  4330. { name: "RIGHTBOTTOM_SYM", text: "@right-bottom"},
  4331. { name: "RESOLUTION", state: "media"},
  4332. { name: "IE_FUNCTION" },
  4333. { name: "CHAR" },
  4334. {
  4335. name: "PIPE",
  4336. text: "|"
  4337. },
  4338. {
  4339. name: "SLASH",
  4340. text: "/"
  4341. },
  4342. {
  4343. name: "MINUS",
  4344. text: "-"
  4345. },
  4346. {
  4347. name: "STAR",
  4348. text: "*"
  4349. },
  4350. {
  4351. name: "LBRACE",
  4352. endChar: "}",
  4353. text: "{"
  4354. },
  4355. {
  4356. name: "RBRACE",
  4357. text: "}"
  4358. },
  4359. {
  4360. name: "LBRACKET",
  4361. endChar: "]",
  4362. text: "["
  4363. },
  4364. {
  4365. name: "RBRACKET",
  4366. text: "]"
  4367. },
  4368. {
  4369. name: "EQUALS",
  4370. text: "="
  4371. },
  4372. {
  4373. name: "COLON",
  4374. text: ":"
  4375. },
  4376. {
  4377. name: "SEMICOLON",
  4378. text: ";"
  4379. },
  4380. {
  4381. name: "LPAREN",
  4382. endChar: ")",
  4383. text: "("
  4384. },
  4385. {
  4386. name: "RPAREN",
  4387. text: ")"
  4388. },
  4389. {
  4390. name: "DOT",
  4391. text: "."
  4392. }
  4393. ];
  4394. (function(){
  4395. var nameMap = [],
  4396. typeMap = {};
  4397. Tokens.UNKNOWN = -1;
  4398. Tokens.unshift({name:"EOF"});
  4399. for (var i=0, len = Tokens.length; i < len; i++){
  4400. nameMap.push(Tokens[i].name);
  4401. Tokens[Tokens[i].name] = i;
  4402. if (Tokens[i].text){
  4403. if (Tokens[i].text instanceof Array){
  4404. for (var j=0; j < Tokens[i].text.length; j++){
  4405. typeMap[Tokens[i].text[j]] = i;
  4406. }
  4407. } else {
  4408. typeMap[Tokens[i].text] = i;
  4409. }
  4410. }
  4411. }
  4412. Tokens.name = function(tt){
  4413. return nameMap[tt];
  4414. };
  4415. Tokens.type = function(c){
  4416. return typeMap[c] || -1;
  4417. };
  4418. })();
  4419. var Validation = {
  4420. validate: function(property, value){
  4421. var name = property.toString().toLowerCase(),
  4422. parts = value.parts,
  4423. expression = new PropertyValueIterator(value),
  4424. spec = Properties[name],
  4425. part,
  4426. valid,
  4427. j, count,
  4428. msg,
  4429. types,
  4430. last,
  4431. literals,
  4432. max, multi, group;
  4433. if (!spec) {
  4434. if (name.indexOf("-") !== 0){ //vendor prefixed are ok
  4435. throw new ValidationError("Unknown property '" + property + "'.", property.line, property.col);
  4436. }
  4437. } else if (typeof spec != "number"){
  4438. if (typeof spec == "string"){
  4439. if (spec.indexOf("||") > -1) {
  4440. this.groupProperty(spec, expression);
  4441. } else {
  4442. this.singleProperty(spec, expression, 1);
  4443. }
  4444. } else if (spec.multi) {
  4445. this.multiProperty(spec.multi, expression, spec.comma, spec.max || Infinity);
  4446. } else if (typeof spec == "function") {
  4447. spec(expression);
  4448. }
  4449. }
  4450. },
  4451. singleProperty: function(types, expression, max, partial) {
  4452. var result = false,
  4453. value = expression.value,
  4454. count = 0,
  4455. part;
  4456. while (expression.hasNext() && count < max) {
  4457. result = ValidationTypes.isAny(expression, types);
  4458. if (!result) {
  4459. break;
  4460. }
  4461. count++;
  4462. }
  4463. if (!result) {
  4464. if (expression.hasNext() && !expression.isFirst()) {
  4465. part = expression.peek();
  4466. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4467. } else {
  4468. throw new ValidationError("Expected (" + types + ") but found '" + value + "'.", value.line, value.col);
  4469. }
  4470. } else if (expression.hasNext()) {
  4471. part = expression.next();
  4472. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4473. }
  4474. },
  4475. multiProperty: function (types, expression, comma, max) {
  4476. var result = false,
  4477. value = expression.value,
  4478. count = 0,
  4479. sep = false,
  4480. part;
  4481. while(expression.hasNext() && !result && count < max) {
  4482. if (ValidationTypes.isAny(expression, types)) {
  4483. count++;
  4484. if (!expression.hasNext()) {
  4485. result = true;
  4486. } else if (comma) {
  4487. if (expression.peek() == ",") {
  4488. part = expression.next();
  4489. } else {
  4490. break;
  4491. }
  4492. }
  4493. } else {
  4494. break;
  4495. }
  4496. }
  4497. if (!result) {
  4498. if (expression.hasNext() && !expression.isFirst()) {
  4499. part = expression.peek();
  4500. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4501. } else {
  4502. part = expression.previous();
  4503. if (comma && part == ",") {
  4504. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4505. } else {
  4506. throw new ValidationError("Expected (" + types + ") but found '" + value + "'.", value.line, value.col);
  4507. }
  4508. }
  4509. } else if (expression.hasNext()) {
  4510. part = expression.next();
  4511. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4512. }
  4513. },
  4514. groupProperty: function (types, expression, comma) {
  4515. var result = false,
  4516. value = expression.value,
  4517. typeCount = types.split("||").length,
  4518. groups = { count: 0 },
  4519. partial = false,
  4520. name,
  4521. part;
  4522. while(expression.hasNext() && !result) {
  4523. name = ValidationTypes.isAnyOfGroup(expression, types);
  4524. if (name) {
  4525. if (groups[name]) {
  4526. break;
  4527. } else {
  4528. groups[name] = 1;
  4529. groups.count++;
  4530. partial = true;
  4531. if (groups.count == typeCount || !expression.hasNext()) {
  4532. result = true;
  4533. }
  4534. }
  4535. } else {
  4536. break;
  4537. }
  4538. }
  4539. if (!result) {
  4540. if (partial && expression.hasNext()) {
  4541. part = expression.peek();
  4542. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4543. } else {
  4544. throw new ValidationError("Expected (" + types + ") but found '" + value + "'.", value.line, value.col);
  4545. }
  4546. } else if (expression.hasNext()) {
  4547. part = expression.next();
  4548. throw new ValidationError("Expected end of value but found '" + part + "'.", part.line, part.col);
  4549. }
  4550. }
  4551. };
  4552. function ValidationError(message, line, col){
  4553. this.col = col;
  4554. this.line = line;
  4555. this.message = message;
  4556. }
  4557. ValidationError.prototype = new Error();
  4558. var ValidationTypes = {
  4559. isLiteral: function (part, literals) {
  4560. var text = part.text.toString().toLowerCase(),
  4561. args = literals.split(" | "),
  4562. i, len, found = false;
  4563. for (i=0,len=args.length; i < len && !found; i++){
  4564. if (text == args[i].toLowerCase()){
  4565. found = true;
  4566. }
  4567. }
  4568. return found;
  4569. },
  4570. isSimple: function(type) {
  4571. return !!this.simple[type];
  4572. },
  4573. isComplex: function(type) {
  4574. return !!this.complex[type];
  4575. },
  4576. isAny: function (expression, types) {
  4577. var args = types.split(" | "),
  4578. i, len, found = false;
  4579. for (i=0,len=args.length; i < len && !found && expression.hasNext(); i++){
  4580. found = this.isType(expression, args[i]);
  4581. }
  4582. return found;
  4583. },
  4584. isAnyOfGroup: function(expression, types) {
  4585. var args = types.split(" || "),
  4586. i, len, found = false;
  4587. for (i=0,len=args.length; i < len && !found; i++){
  4588. found = this.isType(expression, args[i]);
  4589. }
  4590. return found ? args[i-1] : false;
  4591. },
  4592. isType: function (expression, type) {
  4593. var part = expression.peek(),
  4594. result = false;
  4595. if (type.charAt(0) != "<") {
  4596. result = this.isLiteral(part, type);
  4597. if (result) {
  4598. expression.next();
  4599. }
  4600. } else if (this.simple[type]) {
  4601. result = this.simple[type](part);
  4602. if (result) {
  4603. expression.next();
  4604. }
  4605. } else {
  4606. result = this.complex[type](expression);
  4607. }
  4608. return result;
  4609. },
  4610. simple: {
  4611. "<absolute-size>": function(part){
  4612. return ValidationTypes.isLiteral(part, "xx-small | x-small | small | medium | large | x-large | xx-large");
  4613. },
  4614. "<attachment>": function(part){
  4615. return ValidationTypes.isLiteral(part, "scroll | fixed | local");
  4616. },
  4617. "<attr>": function(part){
  4618. return part.type == "function" && part.name == "attr";
  4619. },
  4620. "<bg-image>": function(part){
  4621. return this["<image>"](part) || this["<gradient>"](part) || part == "none";
  4622. },
  4623. "<gradient>": function(part) {
  4624. return part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?(?:repeating\-)?(?:radial\-|linear\-)?gradient/i.test(part);
  4625. },
  4626. "<box>": function(part){
  4627. return ValidationTypes.isLiteral(part, "padding-box | border-box | content-box");
  4628. },
  4629. "<content>": function(part){
  4630. return part.type == "function" && part.name == "content";
  4631. },
  4632. "<relative-size>": function(part){
  4633. return ValidationTypes.isLiteral(part, "smaller | larger");
  4634. },
  4635. "<ident>": function(part){
  4636. return part.type == "identifier";
  4637. },
  4638. "<length>": function(part){
  4639. if (part.type == "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(part)){
  4640. return true;
  4641. }else{
  4642. return part.type == "length" || part.type == "number" || part.type == "integer" || part == "0";
  4643. }
  4644. },
  4645. "<color>": function(part){
  4646. return part.type == "color" || part == "transparent";
  4647. },
  4648. "<number>": function(part){
  4649. return part.type == "number" || this["<integer>"](part);
  4650. },
  4651. "<integer>": function(part){
  4652. return part.type == "integer";
  4653. },
  4654. "<line>": function(part){
  4655. return part.type == "integer";
  4656. },
  4657. "<angle>": function(part){
  4658. return part.type == "angle";
  4659. },
  4660. "<uri>": function(part){
  4661. return part.type == "uri";
  4662. },
  4663. "<image>": function(part){
  4664. return this["<uri>"](part);
  4665. },
  4666. "<percentage>": function(part){
  4667. return part.type == "percentage" || part == "0";
  4668. },
  4669. "<border-width>": function(part){
  4670. return this["<length>"](part) || ValidationTypes.isLiteral(part, "thin | medium | thick");
  4671. },
  4672. "<border-style>": function(part){
  4673. return ValidationTypes.isLiteral(part, "none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset");
  4674. },
  4675. "<content-sizing>": function(part){ // http://www.w3.org/TR/css3-sizing/#width-height-keywords
  4676. return ValidationTypes.isLiteral(part, "fill-available | -moz-available | -webkit-fill-available | max-content | -moz-max-content | -webkit-max-content | min-content | -moz-min-content | -webkit-min-content | fit-content | -moz-fit-content | -webkit-fit-content");
  4677. },
  4678. "<margin-width>": function(part){
  4679. return this["<length>"](part) || this["<percentage>"](part) || ValidationTypes.isLiteral(part, "auto");
  4680. },
  4681. "<padding-width>": function(part){
  4682. return this["<length>"](part) || this["<percentage>"](part);
  4683. },
  4684. "<shape>": function(part){
  4685. return part.type == "function" && (part.name == "rect" || part.name == "inset-rect");
  4686. },
  4687. "<time>": function(part) {
  4688. return part.type == "time";
  4689. },
  4690. "<flex-grow>": function(part){
  4691. return this["<number>"](part);
  4692. },
  4693. "<flex-shrink>": function(part){
  4694. return this["<number>"](part);
  4695. },
  4696. "<width>": function(part){
  4697. return this["<margin-width>"](part);
  4698. },
  4699. "<flex-basis>": function(part){
  4700. return this["<width>"](part);
  4701. },
  4702. "<flex-direction>": function(part){
  4703. return ValidationTypes.isLiteral(part, "row | row-reverse | column | column-reverse");
  4704. },
  4705. "<flex-wrap>": function(part){
  4706. return ValidationTypes.isLiteral(part, "nowrap | wrap | wrap-reverse");
  4707. }
  4708. },
  4709. complex: {
  4710. "<bg-position>": function(expression){
  4711. var types = this,
  4712. result = false,
  4713. numeric = "<percentage> | <length>",
  4714. xDir = "left | right",
  4715. yDir = "top | bottom",
  4716. count = 0,
  4717. hasNext = function() {
  4718. return expression.hasNext() && expression.peek() != ",";
  4719. };
  4720. while (expression.peek(count) && expression.peek(count) != ",") {
  4721. count++;
  4722. }
  4723. if (count < 3) {
  4724. if (ValidationTypes.isAny(expression, xDir + " | center | " + numeric)) {
  4725. result = true;
  4726. ValidationTypes.isAny(expression, yDir + " | center | " + numeric);
  4727. } else if (ValidationTypes.isAny(expression, yDir)) {
  4728. result = true;
  4729. ValidationTypes.isAny(expression, xDir + " | center");
  4730. }
  4731. } else {
  4732. if (ValidationTypes.isAny(expression, xDir)) {
  4733. if (ValidationTypes.isAny(expression, yDir)) {
  4734. result = true;
  4735. ValidationTypes.isAny(expression, numeric);
  4736. } else if (ValidationTypes.isAny(expression, numeric)) {
  4737. if (ValidationTypes.isAny(expression, yDir)) {
  4738. result = true;
  4739. ValidationTypes.isAny(expression, numeric);
  4740. } else if (ValidationTypes.isAny(expression, "center")) {
  4741. result = true;
  4742. }
  4743. }
  4744. } else if (ValidationTypes.isAny(expression, yDir)) {
  4745. if (ValidationTypes.isAny(expression, xDir)) {
  4746. result = true;
  4747. ValidationTypes.isAny(expression, numeric);
  4748. } else if (ValidationTypes.isAny(expression, numeric)) {
  4749. if (ValidationTypes.isAny(expression, xDir)) {
  4750. result = true;
  4751. ValidationTypes.isAny(expression, numeric);
  4752. } else if (ValidationTypes.isAny(expression, "center")) {
  4753. result = true;
  4754. }
  4755. }
  4756. } else if (ValidationTypes.isAny(expression, "center")) {
  4757. if (ValidationTypes.isAny(expression, xDir + " | " + yDir)) {
  4758. result = true;
  4759. ValidationTypes.isAny(expression, numeric);
  4760. }
  4761. }
  4762. }
  4763. return result;
  4764. },
  4765. "<bg-size>": function(expression){
  4766. var types = this,
  4767. result = false,
  4768. numeric = "<percentage> | <length> | auto",
  4769. part,
  4770. i, len;
  4771. if (ValidationTypes.isAny(expression, "cover | contain")) {
  4772. result = true;
  4773. } else if (ValidationTypes.isAny(expression, numeric)) {
  4774. result = true;
  4775. ValidationTypes.isAny(expression, numeric);
  4776. }
  4777. return result;
  4778. },
  4779. "<repeat-style>": function(expression){
  4780. var result = false,
  4781. values = "repeat | space | round | no-repeat",
  4782. part;
  4783. if (expression.hasNext()){
  4784. part = expression.next();
  4785. if (ValidationTypes.isLiteral(part, "repeat-x | repeat-y")) {
  4786. result = true;
  4787. } else if (ValidationTypes.isLiteral(part, values)) {
  4788. result = true;
  4789. if (expression.hasNext() && ValidationTypes.isLiteral(expression.peek(), values)) {
  4790. expression.next();
  4791. }
  4792. }
  4793. }
  4794. return result;
  4795. },
  4796. "<shadow>": function(expression) {
  4797. var result = false,
  4798. count = 0,
  4799. inset = false,
  4800. color = false,
  4801. part;
  4802. if (expression.hasNext()) {
  4803. if (ValidationTypes.isAny(expression, "inset")){
  4804. inset = true;
  4805. }
  4806. if (ValidationTypes.isAny(expression, "<color>")) {
  4807. color = true;
  4808. }
  4809. while (ValidationTypes.isAny(expression, "<length>") && count < 4) {
  4810. count++;
  4811. }
  4812. if (expression.hasNext()) {
  4813. if (!color) {
  4814. ValidationTypes.isAny(expression, "<color>");
  4815. }
  4816. if (!inset) {
  4817. ValidationTypes.isAny(expression, "inset");
  4818. }
  4819. }
  4820. result = (count >= 2 && count <= 4);
  4821. }
  4822. return result;
  4823. },
  4824. "<x-one-radius>": function(expression) {
  4825. var result = false,
  4826. simple = "<length> | <percentage> | inherit";
  4827. if (ValidationTypes.isAny(expression, simple)){
  4828. result = true;
  4829. ValidationTypes.isAny(expression, simple);
  4830. }
  4831. return result;
  4832. },
  4833. "<flex>": function(expression) {
  4834. var part,
  4835. result = false;
  4836. if (ValidationTypes.isAny(expression, "none | inherit")) {
  4837. result = true;
  4838. } else {
  4839. if (ValidationTypes.isType(expression, "<flex-grow>")) {
  4840. if (expression.peek()) {
  4841. if (ValidationTypes.isType(expression, "<flex-shrink>")) {
  4842. if (expression.peek()) {
  4843. result = ValidationTypes.isType(expression, "<flex-basis>");
  4844. } else {
  4845. result = true;
  4846. }
  4847. } else if (ValidationTypes.isType(expression, "<flex-basis>")) {
  4848. result = expression.peek() === null;
  4849. }
  4850. } else {
  4851. result = true;
  4852. }
  4853. } else if (ValidationTypes.isType(expression, "<flex-basis>")) {
  4854. result = true;
  4855. }
  4856. }
  4857. if (!result) {
  4858. part = expression.peek();
  4859. throw new ValidationError("Expected (none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]) but found '" + expression.value.text + "'.", part.line, part.col);
  4860. }
  4861. return result;
  4862. }
  4863. }
  4864. };
  4865. parserlib.css = {
  4866. Colors :Colors,
  4867. Combinator :Combinator,
  4868. Parser :Parser,
  4869. PropertyName :PropertyName,
  4870. PropertyValue :PropertyValue,
  4871. PropertyValuePart :PropertyValuePart,
  4872. MediaFeature :MediaFeature,
  4873. MediaQuery :MediaQuery,
  4874. Selector :Selector,
  4875. SelectorPart :SelectorPart,
  4876. SelectorSubPart :SelectorSubPart,
  4877. Specificity :Specificity,
  4878. TokenStream :TokenStream,
  4879. Tokens :Tokens,
  4880. ValidationError :ValidationError
  4881. };
  4882. })();
  4883. (function(){
  4884. for(var prop in parserlib){
  4885. exports[prop] = parserlib[prop];
  4886. }
  4887. })();
  4888. function objectToString(o) {
  4889. return Object.prototype.toString.call(o);
  4890. }
  4891. var util = {
  4892. isArray: function (ar) {
  4893. return Array.isArray(ar) || (typeof ar === 'object' && objectToString(ar) === '[object Array]');
  4894. },
  4895. isDate: function (d) {
  4896. return typeof d === 'object' && objectToString(d) === '[object Date]';
  4897. },
  4898. isRegExp: function (re) {
  4899. return typeof re === 'object' && objectToString(re) === '[object RegExp]';
  4900. },
  4901. getRegExpFlags: function (re) {
  4902. var flags = '';
  4903. re.global && (flags += 'g');
  4904. re.ignoreCase && (flags += 'i');
  4905. re.multiline && (flags += 'm');
  4906. return flags;
  4907. }
  4908. };
  4909. if (typeof module === 'object')
  4910. module.exports = clone;
  4911. function clone(parent, circular, depth, prototype) {
  4912. var allParents = [];
  4913. var allChildren = [];
  4914. var useBuffer = typeof Buffer != 'undefined';
  4915. if (typeof circular == 'undefined')
  4916. circular = true;
  4917. if (typeof depth == 'undefined')
  4918. depth = Infinity;
  4919. function _clone(parent, depth) {
  4920. if (parent === null)
  4921. return null;
  4922. if (depth == 0)
  4923. return parent;
  4924. var child;
  4925. if (typeof parent != 'object') {
  4926. return parent;
  4927. }
  4928. if (util.isArray(parent)) {
  4929. child = [];
  4930. } else if (util.isRegExp(parent)) {
  4931. child = new RegExp(parent.source, util.getRegExpFlags(parent));
  4932. if (parent.lastIndex) child.lastIndex = parent.lastIndex;
  4933. } else if (util.isDate(parent)) {
  4934. child = new Date(parent.getTime());
  4935. } else if (useBuffer && Buffer.isBuffer(parent)) {
  4936. child = new Buffer(parent.length);
  4937. parent.copy(child);
  4938. return child;
  4939. } else {
  4940. if (typeof prototype == 'undefined') child = Object.create(Object.getPrototypeOf(parent));
  4941. else child = Object.create(prototype);
  4942. }
  4943. if (circular) {
  4944. var index = allParents.indexOf(parent);
  4945. if (index != -1) {
  4946. return allChildren[index];
  4947. }
  4948. allParents.push(parent);
  4949. allChildren.push(child);
  4950. }
  4951. for (var i in parent) {
  4952. child[i] = _clone(parent[i], depth - 1);
  4953. }
  4954. return child;
  4955. }
  4956. return _clone(parent, depth);
  4957. }
  4958. clone.clonePrototype = function(parent) {
  4959. if (parent === null)
  4960. return null;
  4961. var c = function () {};
  4962. c.prototype = parent;
  4963. return new c();
  4964. };
  4965. var CSSLint = (function(){
  4966. var rules = [],
  4967. formatters = [],
  4968. embeddedRuleset = /\/\*csslint([^\*]*)\*\//,
  4969. api = new parserlib.util.EventTarget();
  4970. api.version = "@VERSION@";
  4971. api.addRule = function(rule){
  4972. rules.push(rule);
  4973. rules[rule.id] = rule;
  4974. };
  4975. api.clearRules = function(){
  4976. rules = [];
  4977. };
  4978. api.getRules = function(){
  4979. return [].concat(rules).sort(function(a,b){
  4980. return a.id > b.id ? 1 : 0;
  4981. });
  4982. };
  4983. api.getRuleset = function() {
  4984. var ruleset = {},
  4985. i = 0,
  4986. len = rules.length;
  4987. while (i < len){
  4988. ruleset[rules[i++].id] = 1; //by default, everything is a warning
  4989. }
  4990. return ruleset;
  4991. };
  4992. function applyEmbeddedRuleset(text, ruleset){
  4993. var valueMap,
  4994. embedded = text && text.match(embeddedRuleset),
  4995. rules = embedded && embedded[1];
  4996. if (rules) {
  4997. valueMap = {
  4998. "true": 2, // true is error
  4999. "": 1, // blank is warning
  5000. "false": 0, // false is ignore
  5001. "2": 2, // explicit error
  5002. "1": 1, // explicit warning
  5003. "0": 0 // explicit ignore
  5004. };
  5005. rules.toLowerCase().split(",").forEach(function(rule){
  5006. var pair = rule.split(":"),
  5007. property = pair[0] || "",
  5008. value = pair[1] || "";
  5009. ruleset[property.trim()] = valueMap[value.trim()];
  5010. });
  5011. }
  5012. return ruleset;
  5013. }
  5014. api.addFormatter = function(formatter) {
  5015. formatters[formatter.id] = formatter;
  5016. };
  5017. api.getFormatter = function(formatId){
  5018. return formatters[formatId];
  5019. };
  5020. api.format = function(results, filename, formatId, options) {
  5021. var formatter = this.getFormatter(formatId),
  5022. result = null;
  5023. if (formatter){
  5024. result = formatter.startFormat();
  5025. result += formatter.formatResults(results, filename, options || {});
  5026. result += formatter.endFormat();
  5027. }
  5028. return result;
  5029. };
  5030. api.hasFormat = function(formatId){
  5031. return formatters.hasOwnProperty(formatId);
  5032. };
  5033. api.verify = function(text, ruleset){
  5034. var i = 0,
  5035. reporter,
  5036. lines,
  5037. report,
  5038. parser = new parserlib.css.Parser({ starHack: true, ieFilters: true,
  5039. underscoreHack: true, strict: false });
  5040. lines = text.replace(/\n\r?/g, "$split$").split("$split$");
  5041. if (!ruleset){
  5042. ruleset = this.getRuleset();
  5043. }
  5044. if (embeddedRuleset.test(text)){
  5045. ruleset = clone(ruleset);
  5046. ruleset = applyEmbeddedRuleset(text, ruleset);
  5047. }
  5048. reporter = new Reporter(lines, ruleset);
  5049. ruleset.errors = 2; //always report parsing errors as errors
  5050. for (i in ruleset){
  5051. if(ruleset.hasOwnProperty(i) && ruleset[i]){
  5052. if (rules[i]){
  5053. rules[i].init(parser, reporter);
  5054. }
  5055. }
  5056. }
  5057. try {
  5058. parser.parse(text);
  5059. } catch (ex) {
  5060. reporter.error("Fatal error, cannot continue: " + ex.message, ex.line, ex.col, {});
  5061. }
  5062. report = {
  5063. messages : reporter.messages,
  5064. stats : reporter.stats,
  5065. ruleset : reporter.ruleset
  5066. };
  5067. report.messages.sort(function (a, b){
  5068. if (a.rollup && !b.rollup){
  5069. return 1;
  5070. } else if (!a.rollup && b.rollup){
  5071. return -1;
  5072. } else {
  5073. return a.line - b.line;
  5074. }
  5075. });
  5076. return report;
  5077. };
  5078. return api;
  5079. })();
  5080. function Reporter(lines, ruleset){
  5081. this.messages = [];
  5082. this.stats = [];
  5083. this.lines = lines;
  5084. this.ruleset = ruleset;
  5085. }
  5086. Reporter.prototype = {
  5087. constructor: Reporter,
  5088. error: function(message, line, col, rule){
  5089. this.messages.push({
  5090. type : "error",
  5091. line : line,
  5092. col : col,
  5093. message : message,
  5094. evidence: this.lines[line-1],
  5095. rule : rule || {}
  5096. });
  5097. },
  5098. warn: function(message, line, col, rule){
  5099. this.report(message, line, col, rule);
  5100. },
  5101. report: function(message, line, col, rule){
  5102. this.messages.push({
  5103. type : this.ruleset[rule.id] === 2 ? "error" : "warning",
  5104. line : line,
  5105. col : col,
  5106. message : message,
  5107. evidence: this.lines[line-1],
  5108. rule : rule
  5109. });
  5110. },
  5111. info: function(message, line, col, rule){
  5112. this.messages.push({
  5113. type : "info",
  5114. line : line,
  5115. col : col,
  5116. message : message,
  5117. evidence: this.lines[line-1],
  5118. rule : rule
  5119. });
  5120. },
  5121. rollupError: function(message, rule){
  5122. this.messages.push({
  5123. type : "error",
  5124. rollup : true,
  5125. message : message,
  5126. rule : rule
  5127. });
  5128. },
  5129. rollupWarn: function(message, rule){
  5130. this.messages.push({
  5131. type : "warning",
  5132. rollup : true,
  5133. message : message,
  5134. rule : rule
  5135. });
  5136. },
  5137. stat: function(name, value){
  5138. this.stats[name] = value;
  5139. }
  5140. };
  5141. CSSLint._Reporter = Reporter;
  5142. CSSLint.Util = {
  5143. mix: function(receiver, supplier){
  5144. var prop;
  5145. for (prop in supplier){
  5146. if (supplier.hasOwnProperty(prop)){
  5147. receiver[prop] = supplier[prop];
  5148. }
  5149. }
  5150. return prop;
  5151. },
  5152. indexOf: function(values, value){
  5153. if (values.indexOf){
  5154. return values.indexOf(value);
  5155. } else {
  5156. for (var i=0, len=values.length; i < len; i++){
  5157. if (values[i] === value){
  5158. return i;
  5159. }
  5160. }
  5161. return -1;
  5162. }
  5163. },
  5164. forEach: function(values, func) {
  5165. if (values.forEach){
  5166. return values.forEach(func);
  5167. } else {
  5168. for (var i=0, len=values.length; i < len; i++){
  5169. func(values[i], i, values);
  5170. }
  5171. }
  5172. }
  5173. };
  5174. CSSLint.addRule({
  5175. id: "adjoining-classes",
  5176. name: "Disallow adjoining classes",
  5177. desc: "Don't use adjoining classes.",
  5178. browsers: "IE6",
  5179. init: function(parser, reporter){
  5180. var rule = this;
  5181. parser.addListener("startrule", function(event){
  5182. var selectors = event.selectors,
  5183. selector,
  5184. part,
  5185. modifier,
  5186. classCount,
  5187. i, j, k;
  5188. for (i=0; i < selectors.length; i++){
  5189. selector = selectors[i];
  5190. for (j=0; j < selector.parts.length; j++){
  5191. part = selector.parts[j];
  5192. if (part.type === parser.SELECTOR_PART_TYPE){
  5193. classCount = 0;
  5194. for (k=0; k < part.modifiers.length; k++){
  5195. modifier = part.modifiers[k];
  5196. if (modifier.type === "class"){
  5197. classCount++;
  5198. }
  5199. if (classCount > 1){
  5200. reporter.report("Don't use adjoining classes.", part.line, part.col, rule);
  5201. }
  5202. }
  5203. }
  5204. }
  5205. }
  5206. });
  5207. }
  5208. });
  5209. CSSLint.addRule({
  5210. id: "box-model",
  5211. name: "Beware of broken box size",
  5212. desc: "Don't use width or height when using padding or border.",
  5213. browsers: "All",
  5214. init: function(parser, reporter){
  5215. var rule = this,
  5216. widthProperties = {
  5217. border: 1,
  5218. "border-left": 1,
  5219. "border-right": 1,
  5220. padding: 1,
  5221. "padding-left": 1,
  5222. "padding-right": 1
  5223. },
  5224. heightProperties = {
  5225. border: 1,
  5226. "border-bottom": 1,
  5227. "border-top": 1,
  5228. padding: 1,
  5229. "padding-bottom": 1,
  5230. "padding-top": 1
  5231. },
  5232. properties,
  5233. boxSizing = false;
  5234. function startRule(){
  5235. properties = {};
  5236. boxSizing = false;
  5237. }
  5238. function endRule(){
  5239. var prop, value;
  5240. if (!boxSizing) {
  5241. if (properties.height){
  5242. for (prop in heightProperties){
  5243. if (heightProperties.hasOwnProperty(prop) && properties[prop]){
  5244. value = properties[prop].value;
  5245. if (!(prop === "padding" && value.parts.length === 2 && value.parts[0].value === 0)){
  5246. reporter.report("Using height with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
  5247. }
  5248. }
  5249. }
  5250. }
  5251. if (properties.width){
  5252. for (prop in widthProperties){
  5253. if (widthProperties.hasOwnProperty(prop) && properties[prop]){
  5254. value = properties[prop].value;
  5255. if (!(prop === "padding" && value.parts.length === 2 && value.parts[1].value === 0)){
  5256. reporter.report("Using width with " + prop + " can sometimes make elements larger than you expect.", properties[prop].line, properties[prop].col, rule);
  5257. }
  5258. }
  5259. }
  5260. }
  5261. }
  5262. }
  5263. parser.addListener("startrule", startRule);
  5264. parser.addListener("startfontface", startRule);
  5265. parser.addListener("startpage", startRule);
  5266. parser.addListener("startpagemargin", startRule);
  5267. parser.addListener("startkeyframerule", startRule);
  5268. parser.addListener("property", function(event){
  5269. var name = event.property.text.toLowerCase();
  5270. if (heightProperties[name] || widthProperties[name]){
  5271. if (!/^0\S*$/.test(event.value) && !(name === "border" && event.value.toString() === "none")){
  5272. properties[name] = { line: event.property.line, col: event.property.col, value: event.value };
  5273. }
  5274. } else {
  5275. if (/^(width|height)/i.test(name) && /^(length|percentage)/.test(event.value.parts[0].type)){
  5276. properties[name] = 1;
  5277. } else if (name === "box-sizing") {
  5278. boxSizing = true;
  5279. }
  5280. }
  5281. });
  5282. parser.addListener("endrule", endRule);
  5283. parser.addListener("endfontface", endRule);
  5284. parser.addListener("endpage", endRule);
  5285. parser.addListener("endpagemargin", endRule);
  5286. parser.addListener("endkeyframerule", endRule);
  5287. }
  5288. });
  5289. CSSLint.addRule({
  5290. id: "box-sizing",
  5291. name: "Disallow use of box-sizing",
  5292. desc: "The box-sizing properties isn't supported in IE6 and IE7.",
  5293. browsers: "IE6, IE7",
  5294. tags: ["Compatibility"],
  5295. init: function(parser, reporter){
  5296. var rule = this;
  5297. parser.addListener("property", function(event){
  5298. var name = event.property.text.toLowerCase();
  5299. if (name === "box-sizing"){
  5300. reporter.report("The box-sizing property isn't supported in IE6 and IE7.", event.line, event.col, rule);
  5301. }
  5302. });
  5303. }
  5304. });
  5305. CSSLint.addRule({
  5306. id: "bulletproof-font-face",
  5307. name: "Use the bulletproof @font-face syntax",
  5308. desc: "Use the bulletproof @font-face syntax to avoid 404's in old IE (http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax).",
  5309. browsers: "All",
  5310. init: function(parser, reporter){
  5311. var rule = this,
  5312. fontFaceRule = false,
  5313. firstSrc = true,
  5314. ruleFailed = false,
  5315. line, col;
  5316. parser.addListener("startfontface", function(){
  5317. fontFaceRule = true;
  5318. });
  5319. parser.addListener("property", function(event){
  5320. if (!fontFaceRule) {
  5321. return;
  5322. }
  5323. var propertyName = event.property.toString().toLowerCase(),
  5324. value = event.value.toString();
  5325. line = event.line;
  5326. col = event.col;
  5327. if (propertyName === "src") {
  5328. var regex = /^\s?url\(['"].+\.eot\?.*['"]\)\s*format\(['"]embedded-opentype['"]\).*$/i;
  5329. if (!value.match(regex) && firstSrc) {
  5330. ruleFailed = true;
  5331. firstSrc = false;
  5332. } else if (value.match(regex) && !firstSrc) {
  5333. ruleFailed = false;
  5334. }
  5335. }
  5336. });
  5337. parser.addListener("endfontface", function(){
  5338. fontFaceRule = false;
  5339. if (ruleFailed) {
  5340. reporter.report("@font-face declaration doesn't follow the fontspring bulletproof syntax.", line, col, rule);
  5341. }
  5342. });
  5343. }
  5344. });
  5345. CSSLint.addRule({
  5346. id: "compatible-vendor-prefixes",
  5347. name: "Require compatible vendor prefixes",
  5348. desc: "Include all compatible vendor prefixes to reach a wider range of users.",
  5349. browsers: "All",
  5350. init: function (parser, reporter) {
  5351. var rule = this,
  5352. compatiblePrefixes,
  5353. properties,
  5354. prop,
  5355. variations,
  5356. prefixed,
  5357. i,
  5358. len,
  5359. inKeyFrame = false,
  5360. arrayPush = Array.prototype.push,
  5361. applyTo = [];
  5362. compatiblePrefixes = {
  5363. "animation" : "webkit moz",
  5364. "animation-delay" : "webkit moz",
  5365. "animation-direction" : "webkit moz",
  5366. "animation-duration" : "webkit moz",
  5367. "animation-fill-mode" : "webkit moz",
  5368. "animation-iteration-count" : "webkit moz",
  5369. "animation-name" : "webkit moz",
  5370. "animation-play-state" : "webkit moz",
  5371. "animation-timing-function" : "webkit moz",
  5372. "appearance" : "webkit moz",
  5373. "border-end" : "webkit moz",
  5374. "border-end-color" : "webkit moz",
  5375. "border-end-style" : "webkit moz",
  5376. "border-end-width" : "webkit moz",
  5377. "border-image" : "webkit moz o",
  5378. "border-radius" : "webkit",
  5379. "border-start" : "webkit moz",
  5380. "border-start-color" : "webkit moz",
  5381. "border-start-style" : "webkit moz",
  5382. "border-start-width" : "webkit moz",
  5383. "box-align" : "webkit moz ms",
  5384. "box-direction" : "webkit moz ms",
  5385. "box-flex" : "webkit moz ms",
  5386. "box-lines" : "webkit ms",
  5387. "box-ordinal-group" : "webkit moz ms",
  5388. "box-orient" : "webkit moz ms",
  5389. "box-pack" : "webkit moz ms",
  5390. "box-sizing" : "webkit moz",
  5391. "box-shadow" : "webkit moz",
  5392. "column-count" : "webkit moz ms",
  5393. "column-gap" : "webkit moz ms",
  5394. "column-rule" : "webkit moz ms",
  5395. "column-rule-color" : "webkit moz ms",
  5396. "column-rule-style" : "webkit moz ms",
  5397. "column-rule-width" : "webkit moz ms",
  5398. "column-width" : "webkit moz ms",
  5399. "hyphens" : "epub moz",
  5400. "line-break" : "webkit ms",
  5401. "margin-end" : "webkit moz",
  5402. "margin-start" : "webkit moz",
  5403. "marquee-speed" : "webkit wap",
  5404. "marquee-style" : "webkit wap",
  5405. "padding-end" : "webkit moz",
  5406. "padding-start" : "webkit moz",
  5407. "tab-size" : "moz o",
  5408. "text-size-adjust" : "webkit ms",
  5409. "transform" : "webkit moz ms o",
  5410. "transform-origin" : "webkit moz ms o",
  5411. "transition" : "webkit moz o",
  5412. "transition-delay" : "webkit moz o",
  5413. "transition-duration" : "webkit moz o",
  5414. "transition-property" : "webkit moz o",
  5415. "transition-timing-function" : "webkit moz o",
  5416. "user-modify" : "webkit moz",
  5417. "user-select" : "webkit moz ms",
  5418. "word-break" : "epub ms",
  5419. "writing-mode" : "epub ms"
  5420. };
  5421. for (prop in compatiblePrefixes) {
  5422. if (compatiblePrefixes.hasOwnProperty(prop)) {
  5423. variations = [];
  5424. prefixed = compatiblePrefixes[prop].split(" ");
  5425. for (i = 0, len = prefixed.length; i < len; i++) {
  5426. variations.push("-" + prefixed[i] + "-" + prop);
  5427. }
  5428. compatiblePrefixes[prop] = variations;
  5429. arrayPush.apply(applyTo, variations);
  5430. }
  5431. }
  5432. parser.addListener("startrule", function () {
  5433. properties = [];
  5434. });
  5435. parser.addListener("startkeyframes", function (event) {
  5436. inKeyFrame = event.prefix || true;
  5437. });
  5438. parser.addListener("endkeyframes", function () {
  5439. inKeyFrame = false;
  5440. });
  5441. parser.addListener("property", function (event) {
  5442. var name = event.property;
  5443. if (CSSLint.Util.indexOf(applyTo, name.text) > -1) {
  5444. if (!inKeyFrame || typeof inKeyFrame !== "string" ||
  5445. name.text.indexOf("-" + inKeyFrame + "-") !== 0) {
  5446. properties.push(name);
  5447. }
  5448. }
  5449. });
  5450. parser.addListener("endrule", function () {
  5451. if (!properties.length) {
  5452. return;
  5453. }
  5454. var propertyGroups = {},
  5455. i,
  5456. len,
  5457. name,
  5458. prop,
  5459. variations,
  5460. value,
  5461. full,
  5462. actual,
  5463. item,
  5464. propertiesSpecified;
  5465. for (i = 0, len = properties.length; i < len; i++) {
  5466. name = properties[i];
  5467. for (prop in compatiblePrefixes) {
  5468. if (compatiblePrefixes.hasOwnProperty(prop)) {
  5469. variations = compatiblePrefixes[prop];
  5470. if (CSSLint.Util.indexOf(variations, name.text) > -1) {
  5471. if (!propertyGroups[prop]) {
  5472. propertyGroups[prop] = {
  5473. full : variations.slice(0),
  5474. actual : [],
  5475. actualNodes: []
  5476. };
  5477. }
  5478. if (CSSLint.Util.indexOf(propertyGroups[prop].actual, name.text) === -1) {
  5479. propertyGroups[prop].actual.push(name.text);
  5480. propertyGroups[prop].actualNodes.push(name);
  5481. }
  5482. }
  5483. }
  5484. }
  5485. }
  5486. for (prop in propertyGroups) {
  5487. if (propertyGroups.hasOwnProperty(prop)) {
  5488. value = propertyGroups[prop];
  5489. full = value.full;
  5490. actual = value.actual;
  5491. if (full.length > actual.length) {
  5492. for (i = 0, len = full.length; i < len; i++) {
  5493. item = full[i];
  5494. if (CSSLint.Util.indexOf(actual, item) === -1) {
  5495. propertiesSpecified = (actual.length === 1) ? actual[0] : (actual.length === 2) ? actual.join(" and ") : actual.join(", ");
  5496. reporter.report("The property " + item + " is compatible with " + propertiesSpecified + " and should be included as well.", value.actualNodes[0].line, value.actualNodes[0].col, rule);
  5497. }
  5498. }
  5499. }
  5500. }
  5501. }
  5502. });
  5503. }
  5504. });
  5505. CSSLint.addRule({
  5506. id: "display-property-grouping",
  5507. name: "Require properties appropriate for display",
  5508. desc: "Certain properties shouldn't be used with certain display property values.",
  5509. browsers: "All",
  5510. init: function(parser, reporter){
  5511. var rule = this;
  5512. var propertiesToCheck = {
  5513. display: 1,
  5514. "float": "none",
  5515. height: 1,
  5516. width: 1,
  5517. margin: 1,
  5518. "margin-left": 1,
  5519. "margin-right": 1,
  5520. "margin-bottom": 1,
  5521. "margin-top": 1,
  5522. padding: 1,
  5523. "padding-left": 1,
  5524. "padding-right": 1,
  5525. "padding-bottom": 1,
  5526. "padding-top": 1,
  5527. "vertical-align": 1
  5528. },
  5529. properties;
  5530. function reportProperty(name, display, msg){
  5531. if (properties[name]){
  5532. if (typeof propertiesToCheck[name] !== "string" || properties[name].value.toLowerCase() !== propertiesToCheck[name]){
  5533. reporter.report(msg || name + " can't be used with display: " + display + ".", properties[name].line, properties[name].col, rule);
  5534. }
  5535. }
  5536. }
  5537. function startRule(){
  5538. properties = {};
  5539. }
  5540. function endRule(){
  5541. var display = properties.display ? properties.display.value : null;
  5542. if (display){
  5543. switch(display){
  5544. case "inline":
  5545. reportProperty("height", display);
  5546. reportProperty("width", display);
  5547. reportProperty("margin", display);
  5548. reportProperty("margin-top", display);
  5549. reportProperty("margin-bottom", display);
  5550. reportProperty("float", display, "display:inline has no effect on floated elements (but may be used to fix the IE6 double-margin bug).");
  5551. break;
  5552. case "block":
  5553. reportProperty("vertical-align", display);
  5554. break;
  5555. case "inline-block":
  5556. reportProperty("float", display);
  5557. break;
  5558. default:
  5559. if (display.indexOf("table-") === 0){
  5560. reportProperty("margin", display);
  5561. reportProperty("margin-left", display);
  5562. reportProperty("margin-right", display);
  5563. reportProperty("margin-top", display);
  5564. reportProperty("margin-bottom", display);
  5565. reportProperty("float", display);
  5566. }
  5567. }
  5568. }
  5569. }
  5570. parser.addListener("startrule", startRule);
  5571. parser.addListener("startfontface", startRule);
  5572. parser.addListener("startkeyframerule", startRule);
  5573. parser.addListener("startpagemargin", startRule);
  5574. parser.addListener("startpage", startRule);
  5575. parser.addListener("property", function(event){
  5576. var name = event.property.text.toLowerCase();
  5577. if (propertiesToCheck[name]){
  5578. properties[name] = { value: event.value.text, line: event.property.line, col: event.property.col };
  5579. }
  5580. });
  5581. parser.addListener("endrule", endRule);
  5582. parser.addListener("endfontface", endRule);
  5583. parser.addListener("endkeyframerule", endRule);
  5584. parser.addListener("endpagemargin", endRule);
  5585. parser.addListener("endpage", endRule);
  5586. }
  5587. });
  5588. CSSLint.addRule({
  5589. id: "duplicate-background-images",
  5590. name: "Disallow duplicate background images",
  5591. desc: "Every background-image should be unique. Use a common class for e.g. sprites.",
  5592. browsers: "All",
  5593. init: function(parser, reporter){
  5594. var rule = this,
  5595. stack = {};
  5596. parser.addListener("property", function(event){
  5597. var name = event.property.text,
  5598. value = event.value,
  5599. i, len;
  5600. if (name.match(/background/i)) {
  5601. for (i=0, len=value.parts.length; i < len; i++) {
  5602. if (value.parts[i].type === "uri") {
  5603. if (typeof stack[value.parts[i].uri] === "undefined") {
  5604. stack[value.parts[i].uri] = event;
  5605. }
  5606. else {
  5607. reporter.report("Background image '" + value.parts[i].uri + "' was used multiple times, first declared at line " + stack[value.parts[i].uri].line + ", col " + stack[value.parts[i].uri].col + ".", event.line, event.col, rule);
  5608. }
  5609. }
  5610. }
  5611. }
  5612. });
  5613. }
  5614. });
  5615. CSSLint.addRule({
  5616. id: "duplicate-properties",
  5617. name: "Disallow duplicate properties",
  5618. desc: "Duplicate properties must appear one after the other.",
  5619. browsers: "All",
  5620. init: function(parser, reporter){
  5621. var rule = this,
  5622. properties,
  5623. lastProperty;
  5624. function startRule(){
  5625. properties = {};
  5626. }
  5627. parser.addListener("startrule", startRule);
  5628. parser.addListener("startfontface", startRule);
  5629. parser.addListener("startpage", startRule);
  5630. parser.addListener("startpagemargin", startRule);
  5631. parser.addListener("startkeyframerule", startRule);
  5632. parser.addListener("property", function(event){
  5633. var property = event.property,
  5634. name = property.text.toLowerCase();
  5635. if (properties[name] && (lastProperty !== name || properties[name] === event.value.text)){
  5636. reporter.report("Duplicate property '" + event.property + "' found.", event.line, event.col, rule);
  5637. }
  5638. properties[name] = event.value.text;
  5639. lastProperty = name;
  5640. });
  5641. }
  5642. });
  5643. CSSLint.addRule({
  5644. id: "empty-rules",
  5645. name: "Disallow empty rules",
  5646. desc: "Rules without any properties specified should be removed.",
  5647. browsers: "All",
  5648. init: function(parser, reporter){
  5649. var rule = this,
  5650. count = 0;
  5651. parser.addListener("startrule", function(){
  5652. count=0;
  5653. });
  5654. parser.addListener("property", function(){
  5655. count++;
  5656. });
  5657. parser.addListener("endrule", function(event){
  5658. var selectors = event.selectors;
  5659. if (count === 0){
  5660. reporter.report("Rule is empty.", selectors[0].line, selectors[0].col, rule);
  5661. }
  5662. });
  5663. }
  5664. });
  5665. CSSLint.addRule({
  5666. id: "errors",
  5667. name: "Parsing Errors",
  5668. desc: "This rule looks for recoverable syntax errors.",
  5669. browsers: "All",
  5670. init: function(parser, reporter){
  5671. var rule = this;
  5672. parser.addListener("error", function(event){
  5673. reporter.error(event.message, event.line, event.col, rule);
  5674. });
  5675. }
  5676. });
  5677. CSSLint.addRule({
  5678. id: "fallback-colors",
  5679. name: "Require fallback colors",
  5680. desc: "For older browsers that don't support RGBA, HSL, or HSLA, provide a fallback color.",
  5681. browsers: "IE6,IE7,IE8",
  5682. init: function(parser, reporter){
  5683. var rule = this,
  5684. lastProperty,
  5685. propertiesToCheck = {
  5686. color: 1,
  5687. background: 1,
  5688. "border-color": 1,
  5689. "border-top-color": 1,
  5690. "border-right-color": 1,
  5691. "border-bottom-color": 1,
  5692. "border-left-color": 1,
  5693. border: 1,
  5694. "border-top": 1,
  5695. "border-right": 1,
  5696. "border-bottom": 1,
  5697. "border-left": 1,
  5698. "background-color": 1
  5699. },
  5700. properties;
  5701. function startRule(){
  5702. properties = {};
  5703. lastProperty = null;
  5704. }
  5705. parser.addListener("startrule", startRule);
  5706. parser.addListener("startfontface", startRule);
  5707. parser.addListener("startpage", startRule);
  5708. parser.addListener("startpagemargin", startRule);
  5709. parser.addListener("startkeyframerule", startRule);
  5710. parser.addListener("property", function(event){
  5711. var property = event.property,
  5712. name = property.text.toLowerCase(),
  5713. parts = event.value.parts,
  5714. i = 0,
  5715. colorType = "",
  5716. len = parts.length;
  5717. if(propertiesToCheck[name]){
  5718. while(i < len){
  5719. if (parts[i].type === "color"){
  5720. if ("alpha" in parts[i] || "hue" in parts[i]){
  5721. if (/([^\)]+)\(/.test(parts[i])){
  5722. colorType = RegExp.$1.toUpperCase();
  5723. }
  5724. if (!lastProperty || (lastProperty.property.text.toLowerCase() !== name || lastProperty.colorType !== "compat")){
  5725. reporter.report("Fallback " + name + " (hex or RGB) should precede " + colorType + " " + name + ".", event.line, event.col, rule);
  5726. }
  5727. } else {
  5728. event.colorType = "compat";
  5729. }
  5730. }
  5731. i++;
  5732. }
  5733. }
  5734. lastProperty = event;
  5735. });
  5736. }
  5737. });
  5738. CSSLint.addRule({
  5739. id: "floats",
  5740. name: "Disallow too many floats",
  5741. desc: "This rule tests if the float property is used too many times",
  5742. browsers: "All",
  5743. init: function(parser, reporter){
  5744. var rule = this;
  5745. var count = 0;
  5746. parser.addListener("property", function(event){
  5747. if (event.property.text.toLowerCase() === "float" &&
  5748. event.value.text.toLowerCase() !== "none"){
  5749. count++;
  5750. }
  5751. });
  5752. parser.addListener("endstylesheet", function(){
  5753. reporter.stat("floats", count);
  5754. if (count >= 10){
  5755. reporter.rollupWarn("Too many floats (" + count + "), you're probably using them for layout. Consider using a grid system instead.", rule);
  5756. }
  5757. });
  5758. }
  5759. });
  5760. CSSLint.addRule({
  5761. id: "font-faces",
  5762. name: "Don't use too many web fonts",
  5763. desc: "Too many different web fonts in the same stylesheet.",
  5764. browsers: "All",
  5765. init: function(parser, reporter){
  5766. var rule = this,
  5767. count = 0;
  5768. parser.addListener("startfontface", function(){
  5769. count++;
  5770. });
  5771. parser.addListener("endstylesheet", function(){
  5772. if (count > 5){
  5773. reporter.rollupWarn("Too many @font-face declarations (" + count + ").", rule);
  5774. }
  5775. });
  5776. }
  5777. });
  5778. CSSLint.addRule({
  5779. id: "font-sizes",
  5780. name: "Disallow too many font sizes",
  5781. desc: "Checks the number of font-size declarations.",
  5782. browsers: "All",
  5783. init: function(parser, reporter){
  5784. var rule = this,
  5785. count = 0;
  5786. parser.addListener("property", function(event){
  5787. if (event.property.toString() === "font-size"){
  5788. count++;
  5789. }
  5790. });
  5791. parser.addListener("endstylesheet", function(){
  5792. reporter.stat("font-sizes", count);
  5793. if (count >= 10){
  5794. reporter.rollupWarn("Too many font-size declarations (" + count + "), abstraction needed.", rule);
  5795. }
  5796. });
  5797. }
  5798. });
  5799. CSSLint.addRule({
  5800. id: "gradients",
  5801. name: "Require all gradient definitions",
  5802. desc: "When using a vendor-prefixed gradient, make sure to use them all.",
  5803. browsers: "All",
  5804. init: function(parser, reporter){
  5805. var rule = this,
  5806. gradients;
  5807. parser.addListener("startrule", function(){
  5808. gradients = {
  5809. moz: 0,
  5810. webkit: 0,
  5811. oldWebkit: 0,
  5812. o: 0
  5813. };
  5814. });
  5815. parser.addListener("property", function(event){
  5816. if (/\-(moz|o|webkit)(?:\-(?:linear|radial))\-gradient/i.test(event.value)){
  5817. gradients[RegExp.$1] = 1;
  5818. } else if (/\-webkit\-gradient/i.test(event.value)){
  5819. gradients.oldWebkit = 1;
  5820. }
  5821. });
  5822. parser.addListener("endrule", function(event){
  5823. var missing = [];
  5824. if (!gradients.moz){
  5825. missing.push("Firefox 3.6+");
  5826. }
  5827. if (!gradients.webkit){
  5828. missing.push("Webkit (Safari 5+, Chrome)");
  5829. }
  5830. if (!gradients.oldWebkit){
  5831. missing.push("Old Webkit (Safari 4+, Chrome)");
  5832. }
  5833. if (!gradients.o){
  5834. missing.push("Opera 11.1+");
  5835. }
  5836. if (missing.length && missing.length < 4){
  5837. reporter.report("Missing vendor-prefixed CSS gradients for " + missing.join(", ") + ".", event.selectors[0].line, event.selectors[0].col, rule);
  5838. }
  5839. });
  5840. }
  5841. });
  5842. CSSLint.addRule({
  5843. id: "ids",
  5844. name: "Disallow IDs in selectors",
  5845. desc: "Selectors should not contain IDs.",
  5846. browsers: "All",
  5847. init: function(parser, reporter){
  5848. var rule = this;
  5849. parser.addListener("startrule", function(event){
  5850. var selectors = event.selectors,
  5851. selector,
  5852. part,
  5853. modifier,
  5854. idCount,
  5855. i, j, k;
  5856. for (i=0; i < selectors.length; i++){
  5857. selector = selectors[i];
  5858. idCount = 0;
  5859. for (j=0; j < selector.parts.length; j++){
  5860. part = selector.parts[j];
  5861. if (part.type === parser.SELECTOR_PART_TYPE){
  5862. for (k=0; k < part.modifiers.length; k++){
  5863. modifier = part.modifiers[k];
  5864. if (modifier.type === "id"){
  5865. idCount++;
  5866. }
  5867. }
  5868. }
  5869. }
  5870. if (idCount === 1){
  5871. reporter.report("Don't use IDs in selectors.", selector.line, selector.col, rule);
  5872. } else if (idCount > 1){
  5873. reporter.report(idCount + " IDs in the selector, really?", selector.line, selector.col, rule);
  5874. }
  5875. }
  5876. });
  5877. }
  5878. });
  5879. CSSLint.addRule({
  5880. id: "import",
  5881. name: "Disallow @import",
  5882. desc: "Don't use @import, use <link> instead.",
  5883. browsers: "All",
  5884. init: function(parser, reporter){
  5885. var rule = this;
  5886. parser.addListener("import", function(event){
  5887. reporter.report("@import prevents parallel downloads, use <link> instead.", event.line, event.col, rule);
  5888. });
  5889. }
  5890. });
  5891. CSSLint.addRule({
  5892. id: "important",
  5893. name: "Disallow !important",
  5894. desc: "Be careful when using !important declaration",
  5895. browsers: "All",
  5896. init: function(parser, reporter){
  5897. var rule = this,
  5898. count = 0;
  5899. parser.addListener("property", function(event){
  5900. if (event.important === true){
  5901. count++;
  5902. reporter.report("Use of !important", event.line, event.col, rule);
  5903. }
  5904. });
  5905. parser.addListener("endstylesheet", function(){
  5906. reporter.stat("important", count);
  5907. if (count >= 10){
  5908. reporter.rollupWarn("Too many !important declarations (" + count + "), try to use less than 10 to avoid specificity issues.", rule);
  5909. }
  5910. });
  5911. }
  5912. });
  5913. CSSLint.addRule({
  5914. id: "known-properties",
  5915. name: "Require use of known properties",
  5916. desc: "Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.",
  5917. browsers: "All",
  5918. init: function(parser, reporter){
  5919. var rule = this;
  5920. parser.addListener("property", function(event){
  5921. if (event.invalid) {
  5922. reporter.report(event.invalid.message, event.line, event.col, rule);
  5923. }
  5924. });
  5925. }
  5926. });
  5927. CSSLint.addRule({
  5928. id: "order-alphabetical",
  5929. name: "Alphabetical order",
  5930. desc: "Assure properties are in alphabetical order",
  5931. browsers: "All",
  5932. init: function(parser, reporter){
  5933. var rule = this,
  5934. properties;
  5935. var startRule = function () {
  5936. properties = [];
  5937. };
  5938. parser.addListener("startrule", startRule);
  5939. parser.addListener("startfontface", startRule);
  5940. parser.addListener("startpage", startRule);
  5941. parser.addListener("startpagemargin", startRule);
  5942. parser.addListener("startkeyframerule", startRule);
  5943. parser.addListener("property", function(event){
  5944. var name = event.property.text,
  5945. lowerCasePrefixLessName = name.toLowerCase().replace(/^-.*?-/, "");
  5946. properties.push(lowerCasePrefixLessName);
  5947. });
  5948. parser.addListener("endrule", function(event){
  5949. var currentProperties = properties.join(","),
  5950. expectedProperties = properties.sort().join(",");
  5951. if (currentProperties !== expectedProperties){
  5952. reporter.report("Rule doesn't have all its properties in alphabetical ordered.", event.line, event.col, rule);
  5953. }
  5954. });
  5955. }
  5956. });
  5957. CSSLint.addRule({
  5958. id: "outline-none",
  5959. name: "Disallow outline: none",
  5960. desc: "Use of outline: none or outline: 0 should be limited to :focus rules.",
  5961. browsers: "All",
  5962. tags: ["Accessibility"],
  5963. init: function(parser, reporter){
  5964. var rule = this,
  5965. lastRule;
  5966. function startRule(event){
  5967. if (event.selectors){
  5968. lastRule = {
  5969. line: event.line,
  5970. col: event.col,
  5971. selectors: event.selectors,
  5972. propCount: 0,
  5973. outline: false
  5974. };
  5975. } else {
  5976. lastRule = null;
  5977. }
  5978. }
  5979. function endRule(){
  5980. if (lastRule){
  5981. if (lastRule.outline){
  5982. if (lastRule.selectors.toString().toLowerCase().indexOf(":focus") === -1){
  5983. reporter.report("Outlines should only be modified using :focus.", lastRule.line, lastRule.col, rule);
  5984. } else if (lastRule.propCount === 1) {
  5985. reporter.report("Outlines shouldn't be hidden unless other visual changes are made.", lastRule.line, lastRule.col, rule);
  5986. }
  5987. }
  5988. }
  5989. }
  5990. parser.addListener("startrule", startRule);
  5991. parser.addListener("startfontface", startRule);
  5992. parser.addListener("startpage", startRule);
  5993. parser.addListener("startpagemargin", startRule);
  5994. parser.addListener("startkeyframerule", startRule);
  5995. parser.addListener("property", function(event){
  5996. var name = event.property.text.toLowerCase(),
  5997. value = event.value;
  5998. if (lastRule){
  5999. lastRule.propCount++;
  6000. if (name === "outline" && (value.toString() === "none" || value.toString() === "0")){
  6001. lastRule.outline = true;
  6002. }
  6003. }
  6004. });
  6005. parser.addListener("endrule", endRule);
  6006. parser.addListener("endfontface", endRule);
  6007. parser.addListener("endpage", endRule);
  6008. parser.addListener("endpagemargin", endRule);
  6009. parser.addListener("endkeyframerule", endRule);
  6010. }
  6011. });
  6012. CSSLint.addRule({
  6013. id: "overqualified-elements",
  6014. name: "Disallow overqualified elements",
  6015. desc: "Don't use classes or IDs with elements (a.foo or a#foo).",
  6016. browsers: "All",
  6017. init: function(parser, reporter){
  6018. var rule = this,
  6019. classes = {};
  6020. parser.addListener("startrule", function(event){
  6021. var selectors = event.selectors,
  6022. selector,
  6023. part,
  6024. modifier,
  6025. i, j, k;
  6026. for (i=0; i < selectors.length; i++){
  6027. selector = selectors[i];
  6028. for (j=0; j < selector.parts.length; j++){
  6029. part = selector.parts[j];
  6030. if (part.type === parser.SELECTOR_PART_TYPE){
  6031. for (k=0; k < part.modifiers.length; k++){
  6032. modifier = part.modifiers[k];
  6033. if (part.elementName && modifier.type === "id"){
  6034. reporter.report("Element (" + part + ") is overqualified, just use " + modifier + " without element name.", part.line, part.col, rule);
  6035. } else if (modifier.type === "class"){
  6036. if (!classes[modifier]){
  6037. classes[modifier] = [];
  6038. }
  6039. classes[modifier].push({ modifier: modifier, part: part });
  6040. }
  6041. }
  6042. }
  6043. }
  6044. }
  6045. });
  6046. parser.addListener("endstylesheet", function(){
  6047. var prop;
  6048. for (prop in classes){
  6049. if (classes.hasOwnProperty(prop)){
  6050. if (classes[prop].length === 1 && classes[prop][0].part.elementName){
  6051. reporter.report("Element (" + classes[prop][0].part + ") is overqualified, just use " + classes[prop][0].modifier + " without element name.", classes[prop][0].part.line, classes[prop][0].part.col, rule);
  6052. }
  6053. }
  6054. }
  6055. });
  6056. }
  6057. });
  6058. CSSLint.addRule({
  6059. id: "qualified-headings",
  6060. name: "Disallow qualified headings",
  6061. desc: "Headings should not be qualified (namespaced).",
  6062. browsers: "All",
  6063. init: function(parser, reporter){
  6064. var rule = this;
  6065. parser.addListener("startrule", function(event){
  6066. var selectors = event.selectors,
  6067. selector,
  6068. part,
  6069. i, j;
  6070. for (i=0; i < selectors.length; i++){
  6071. selector = selectors[i];
  6072. for (j=0; j < selector.parts.length; j++){
  6073. part = selector.parts[j];
  6074. if (part.type === parser.SELECTOR_PART_TYPE){
  6075. if (part.elementName && /h[1-6]/.test(part.elementName.toString()) && j > 0){
  6076. reporter.report("Heading (" + part.elementName + ") should not be qualified.", part.line, part.col, rule);
  6077. }
  6078. }
  6079. }
  6080. }
  6081. });
  6082. }
  6083. });
  6084. CSSLint.addRule({
  6085. id: "regex-selectors",
  6086. name: "Disallow selectors that look like regexs",
  6087. desc: "Selectors that look like regular expressions are slow and should be avoided.",
  6088. browsers: "All",
  6089. init: function(parser, reporter){
  6090. var rule = this;
  6091. parser.addListener("startrule", function(event){
  6092. var selectors = event.selectors,
  6093. selector,
  6094. part,
  6095. modifier,
  6096. i, j, k;
  6097. for (i=0; i < selectors.length; i++){
  6098. selector = selectors[i];
  6099. for (j=0; j < selector.parts.length; j++){
  6100. part = selector.parts[j];
  6101. if (part.type === parser.SELECTOR_PART_TYPE){
  6102. for (k=0; k < part.modifiers.length; k++){
  6103. modifier = part.modifiers[k];
  6104. if (modifier.type === "attribute"){
  6105. if (/([\~\|\^\$\*]=)/.test(modifier)){
  6106. reporter.report("Attribute selectors with " + RegExp.$1 + " are slow!", modifier.line, modifier.col, rule);
  6107. }
  6108. }
  6109. }
  6110. }
  6111. }
  6112. }
  6113. });
  6114. }
  6115. });
  6116. CSSLint.addRule({
  6117. id: "rules-count",
  6118. name: "Rules Count",
  6119. desc: "Track how many rules there are.",
  6120. browsers: "All",
  6121. init: function(parser, reporter){
  6122. var count = 0;
  6123. parser.addListener("startrule", function(){
  6124. count++;
  6125. });
  6126. parser.addListener("endstylesheet", function(){
  6127. reporter.stat("rule-count", count);
  6128. });
  6129. }
  6130. });
  6131. CSSLint.addRule({
  6132. id: "selector-max-approaching",
  6133. name: "Warn when approaching the 4095 selector limit for IE",
  6134. desc: "Will warn when selector count is >= 3800 selectors.",
  6135. browsers: "IE",
  6136. init: function(parser, reporter) {
  6137. var rule = this, count = 0;
  6138. parser.addListener("startrule", function(event) {
  6139. count += event.selectors.length;
  6140. });
  6141. parser.addListener("endstylesheet", function() {
  6142. if (count >= 3800) {
  6143. reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,rule);
  6144. }
  6145. });
  6146. }
  6147. });
  6148. CSSLint.addRule({
  6149. id: "selector-max",
  6150. name: "Error when past the 4095 selector limit for IE",
  6151. desc: "Will error when selector count is > 4095.",
  6152. browsers: "IE",
  6153. init: function(parser, reporter){
  6154. var rule = this, count = 0;
  6155. parser.addListener("startrule", function(event) {
  6156. count += event.selectors.length;
  6157. });
  6158. parser.addListener("endstylesheet", function() {
  6159. if (count > 4095) {
  6160. reporter.report("You have " + count + " selectors. Internet Explorer supports a maximum of 4095 selectors per stylesheet. Consider refactoring.",0,0,rule);
  6161. }
  6162. });
  6163. }
  6164. });
  6165. CSSLint.addRule({
  6166. id: "selector-newline",
  6167. name: "Disallow new-line characters in selectors",
  6168. desc: "New-line characters in selectors are usually a forgotten comma and not a descendant combinator.",
  6169. browsers: "All",
  6170. init: function(parser, reporter) {
  6171. var rule = this;
  6172. function startRule(event) {
  6173. var i, len, selector, p, n, pLen, part, part2, type, currentLine, nextLine,
  6174. selectors = event.selectors;
  6175. for (i = 0, len = selectors.length; i < len; i++) {
  6176. selector = selectors[i];
  6177. for (p = 0, pLen = selector.parts.length; p < pLen; p++) {
  6178. for (n = p + 1; n < pLen; n++) {
  6179. part = selector.parts[p];
  6180. part2 = selector.parts[n];
  6181. type = part.type;
  6182. currentLine = part.line;
  6183. nextLine = part2.line;
  6184. if (type === "descendant" && nextLine > currentLine) {
  6185. reporter.report("newline character found in selector (forgot a comma?)", currentLine, selectors[i].parts[0].col, rule);
  6186. }
  6187. }
  6188. }
  6189. }
  6190. }
  6191. parser.addListener("startrule", startRule);
  6192. }
  6193. });
  6194. CSSLint.addRule({
  6195. id: "shorthand",
  6196. name: "Require shorthand properties",
  6197. desc: "Use shorthand properties where possible.",
  6198. browsers: "All",
  6199. init: function(parser, reporter){
  6200. var rule = this,
  6201. prop, i, len,
  6202. propertiesToCheck = {},
  6203. properties,
  6204. mapping = {
  6205. "margin": [
  6206. "margin-top",
  6207. "margin-bottom",
  6208. "margin-left",
  6209. "margin-right"
  6210. ],
  6211. "padding": [
  6212. "padding-top",
  6213. "padding-bottom",
  6214. "padding-left",
  6215. "padding-right"
  6216. ]
  6217. };
  6218. for (prop in mapping){
  6219. if (mapping.hasOwnProperty(prop)){
  6220. for (i=0, len=mapping[prop].length; i < len; i++){
  6221. propertiesToCheck[mapping[prop][i]] = prop;
  6222. }
  6223. }
  6224. }
  6225. function startRule(){
  6226. properties = {};
  6227. }
  6228. function endRule(event){
  6229. var prop, i, len, total;
  6230. for (prop in mapping){
  6231. if (mapping.hasOwnProperty(prop)){
  6232. total=0;
  6233. for (i=0, len=mapping[prop].length; i < len; i++){
  6234. total += properties[mapping[prop][i]] ? 1 : 0;
  6235. }
  6236. if (total === mapping[prop].length){
  6237. reporter.report("The properties " + mapping[prop].join(", ") + " can be replaced by " + prop + ".", event.line, event.col, rule);
  6238. }
  6239. }
  6240. }
  6241. }
  6242. parser.addListener("startrule", startRule);
  6243. parser.addListener("startfontface", startRule);
  6244. parser.addListener("property", function(event){
  6245. var name = event.property.toString().toLowerCase();
  6246. if (propertiesToCheck[name]){
  6247. properties[name] = 1;
  6248. }
  6249. });
  6250. parser.addListener("endrule", endRule);
  6251. parser.addListener("endfontface", endRule);
  6252. }
  6253. });
  6254. CSSLint.addRule({
  6255. id: "star-property-hack",
  6256. name: "Disallow properties with a star prefix",
  6257. desc: "Checks for the star property hack (targets IE6/7)",
  6258. browsers: "All",
  6259. init: function(parser, reporter){
  6260. var rule = this;
  6261. parser.addListener("property", function(event){
  6262. var property = event.property;
  6263. if (property.hack === "*") {
  6264. reporter.report("Property with star prefix found.", event.property.line, event.property.col, rule);
  6265. }
  6266. });
  6267. }
  6268. });
  6269. CSSLint.addRule({
  6270. id: "text-indent",
  6271. name: "Disallow negative text-indent",
  6272. desc: "Checks for text indent less than -99px",
  6273. browsers: "All",
  6274. init: function(parser, reporter){
  6275. var rule = this,
  6276. textIndent,
  6277. direction;
  6278. function startRule(){
  6279. textIndent = false;
  6280. direction = "inherit";
  6281. }
  6282. function endRule(){
  6283. if (textIndent && direction !== "ltr"){
  6284. reporter.report("Negative text-indent doesn't work well with RTL. If you use text-indent for image replacement explicitly set direction for that item to ltr.", textIndent.line, textIndent.col, rule);
  6285. }
  6286. }
  6287. parser.addListener("startrule", startRule);
  6288. parser.addListener("startfontface", startRule);
  6289. parser.addListener("property", function(event){
  6290. var name = event.property.toString().toLowerCase(),
  6291. value = event.value;
  6292. if (name === "text-indent" && value.parts[0].value < -99){
  6293. textIndent = event.property;
  6294. } else if (name === "direction" && value.toString() === "ltr"){
  6295. direction = "ltr";
  6296. }
  6297. });
  6298. parser.addListener("endrule", endRule);
  6299. parser.addListener("endfontface", endRule);
  6300. }
  6301. });
  6302. CSSLint.addRule({
  6303. id: "underscore-property-hack",
  6304. name: "Disallow properties with an underscore prefix",
  6305. desc: "Checks for the underscore property hack (targets IE6)",
  6306. browsers: "All",
  6307. init: function(parser, reporter){
  6308. var rule = this;
  6309. parser.addListener("property", function(event){
  6310. var property = event.property;
  6311. if (property.hack === "_") {
  6312. reporter.report("Property with underscore prefix found.", event.property.line, event.property.col, rule);
  6313. }
  6314. });
  6315. }
  6316. });
  6317. CSSLint.addRule({
  6318. id: "unique-headings",
  6319. name: "Headings should only be defined once",
  6320. desc: "Headings should be defined only once.",
  6321. browsers: "All",
  6322. init: function(parser, reporter){
  6323. var rule = this;
  6324. var headings = {
  6325. h1: 0,
  6326. h2: 0,
  6327. h3: 0,
  6328. h4: 0,
  6329. h5: 0,
  6330. h6: 0
  6331. };
  6332. parser.addListener("startrule", function(event){
  6333. var selectors = event.selectors,
  6334. selector,
  6335. part,
  6336. pseudo,
  6337. i, j;
  6338. for (i=0; i < selectors.length; i++){
  6339. selector = selectors[i];
  6340. part = selector.parts[selector.parts.length-1];
  6341. if (part.elementName && /(h[1-6])/i.test(part.elementName.toString())){
  6342. for (j=0; j < part.modifiers.length; j++){
  6343. if (part.modifiers[j].type === "pseudo"){
  6344. pseudo = true;
  6345. break;
  6346. }
  6347. }
  6348. if (!pseudo){
  6349. headings[RegExp.$1]++;
  6350. if (headings[RegExp.$1] > 1) {
  6351. reporter.report("Heading (" + part.elementName + ") has already been defined.", part.line, part.col, rule);
  6352. }
  6353. }
  6354. }
  6355. }
  6356. });
  6357. parser.addListener("endstylesheet", function(){
  6358. var prop,
  6359. messages = [];
  6360. for (prop in headings){
  6361. if (headings.hasOwnProperty(prop)){
  6362. if (headings[prop] > 1){
  6363. messages.push(headings[prop] + " " + prop + "s");
  6364. }
  6365. }
  6366. }
  6367. if (messages.length){
  6368. reporter.rollupWarn("You have " + messages.join(", ") + " defined in this stylesheet.", rule);
  6369. }
  6370. });
  6371. }
  6372. });
  6373. CSSLint.addRule({
  6374. id: "universal-selector",
  6375. name: "Disallow universal selector",
  6376. desc: "The universal selector (*) is known to be slow.",
  6377. browsers: "All",
  6378. init: function(parser, reporter){
  6379. var rule = this;
  6380. parser.addListener("startrule", function(event){
  6381. var selectors = event.selectors,
  6382. selector,
  6383. part,
  6384. i;
  6385. for (i=0; i < selectors.length; i++){
  6386. selector = selectors[i];
  6387. part = selector.parts[selector.parts.length-1];
  6388. if (part.elementName === "*"){
  6389. reporter.report(rule.desc, part.line, part.col, rule);
  6390. }
  6391. }
  6392. });
  6393. }
  6394. });
  6395. CSSLint.addRule({
  6396. id: "unqualified-attributes",
  6397. name: "Disallow unqualified attribute selectors",
  6398. desc: "Unqualified attribute selectors are known to be slow.",
  6399. browsers: "All",
  6400. init: function(parser, reporter){
  6401. var rule = this;
  6402. parser.addListener("startrule", function(event){
  6403. var selectors = event.selectors,
  6404. selector,
  6405. part,
  6406. modifier,
  6407. i, k;
  6408. for (i=0; i < selectors.length; i++){
  6409. selector = selectors[i];
  6410. part = selector.parts[selector.parts.length-1];
  6411. if (part.type === parser.SELECTOR_PART_TYPE){
  6412. for (k=0; k < part.modifiers.length; k++){
  6413. modifier = part.modifiers[k];
  6414. if (modifier.type === "attribute" && (!part.elementName || part.elementName === "*")){
  6415. reporter.report(rule.desc, part.line, part.col, rule);
  6416. }
  6417. }
  6418. }
  6419. }
  6420. });
  6421. }
  6422. });
  6423. CSSLint.addRule({
  6424. id: "vendor-prefix",
  6425. name: "Require standard property with vendor prefix",
  6426. desc: "When using a vendor-prefixed property, make sure to include the standard one.",
  6427. browsers: "All",
  6428. init: function(parser, reporter){
  6429. var rule = this,
  6430. properties,
  6431. num,
  6432. propertiesToCheck = {
  6433. "-webkit-border-radius": "border-radius",
  6434. "-webkit-border-top-left-radius": "border-top-left-radius",
  6435. "-webkit-border-top-right-radius": "border-top-right-radius",
  6436. "-webkit-border-bottom-left-radius": "border-bottom-left-radius",
  6437. "-webkit-border-bottom-right-radius": "border-bottom-right-radius",
  6438. "-o-border-radius": "border-radius",
  6439. "-o-border-top-left-radius": "border-top-left-radius",
  6440. "-o-border-top-right-radius": "border-top-right-radius",
  6441. "-o-border-bottom-left-radius": "border-bottom-left-radius",
  6442. "-o-border-bottom-right-radius": "border-bottom-right-radius",
  6443. "-moz-border-radius": "border-radius",
  6444. "-moz-border-radius-topleft": "border-top-left-radius",
  6445. "-moz-border-radius-topright": "border-top-right-radius",
  6446. "-moz-border-radius-bottomleft": "border-bottom-left-radius",
  6447. "-moz-border-radius-bottomright": "border-bottom-right-radius",
  6448. "-moz-column-count": "column-count",
  6449. "-webkit-column-count": "column-count",
  6450. "-moz-column-gap": "column-gap",
  6451. "-webkit-column-gap": "column-gap",
  6452. "-moz-column-rule": "column-rule",
  6453. "-webkit-column-rule": "column-rule",
  6454. "-moz-column-rule-style": "column-rule-style",
  6455. "-webkit-column-rule-style": "column-rule-style",
  6456. "-moz-column-rule-color": "column-rule-color",
  6457. "-webkit-column-rule-color": "column-rule-color",
  6458. "-moz-column-rule-width": "column-rule-width",
  6459. "-webkit-column-rule-width": "column-rule-width",
  6460. "-moz-column-width": "column-width",
  6461. "-webkit-column-width": "column-width",
  6462. "-webkit-column-span": "column-span",
  6463. "-webkit-columns": "columns",
  6464. "-moz-box-shadow": "box-shadow",
  6465. "-webkit-box-shadow": "box-shadow",
  6466. "-moz-transform" : "transform",
  6467. "-webkit-transform" : "transform",
  6468. "-o-transform" : "transform",
  6469. "-ms-transform" : "transform",
  6470. "-moz-transform-origin" : "transform-origin",
  6471. "-webkit-transform-origin" : "transform-origin",
  6472. "-o-transform-origin" : "transform-origin",
  6473. "-ms-transform-origin" : "transform-origin",
  6474. "-moz-box-sizing" : "box-sizing",
  6475. "-webkit-box-sizing" : "box-sizing"
  6476. };
  6477. function startRule(){
  6478. properties = {};
  6479. num = 1;
  6480. }
  6481. function endRule(){
  6482. var prop,
  6483. i,
  6484. len,
  6485. needed,
  6486. actual,
  6487. needsStandard = [];
  6488. for (prop in properties){
  6489. if (propertiesToCheck[prop]){
  6490. needsStandard.push({ actual: prop, needed: propertiesToCheck[prop]});
  6491. }
  6492. }
  6493. for (i=0, len=needsStandard.length; i < len; i++){
  6494. needed = needsStandard[i].needed;
  6495. actual = needsStandard[i].actual;
  6496. if (!properties[needed]){
  6497. reporter.report("Missing standard property '" + needed + "' to go along with '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
  6498. } else {
  6499. if (properties[needed][0].pos < properties[actual][0].pos){
  6500. reporter.report("Standard property '" + needed + "' should come after vendor-prefixed property '" + actual + "'.", properties[actual][0].name.line, properties[actual][0].name.col, rule);
  6501. }
  6502. }
  6503. }
  6504. }
  6505. parser.addListener("startrule", startRule);
  6506. parser.addListener("startfontface", startRule);
  6507. parser.addListener("startpage", startRule);
  6508. parser.addListener("startpagemargin", startRule);
  6509. parser.addListener("startkeyframerule", startRule);
  6510. parser.addListener("property", function(event){
  6511. var name = event.property.text.toLowerCase();
  6512. if (!properties[name]){
  6513. properties[name] = [];
  6514. }
  6515. properties[name].push({ name: event.property, value : event.value, pos:num++ });
  6516. });
  6517. parser.addListener("endrule", endRule);
  6518. parser.addListener("endfontface", endRule);
  6519. parser.addListener("endpage", endRule);
  6520. parser.addListener("endpagemargin", endRule);
  6521. parser.addListener("endkeyframerule", endRule);
  6522. }
  6523. });
  6524. CSSLint.addRule({
  6525. id: "zero-units",
  6526. name: "Disallow units for 0 values",
  6527. desc: "You don't need to specify units when a value is 0.",
  6528. browsers: "All",
  6529. init: function(parser, reporter){
  6530. var rule = this;
  6531. parser.addListener("property", function(event){
  6532. var parts = event.value.parts,
  6533. i = 0,
  6534. len = parts.length;
  6535. while(i < len){
  6536. if ((parts[i].units || parts[i].type === "percentage") && parts[i].value === 0 && parts[i].type !== "time"){
  6537. reporter.report("Values of 0 shouldn't have units specified.", parts[i].line, parts[i].col, rule);
  6538. }
  6539. i++;
  6540. }
  6541. });
  6542. }
  6543. });
  6544. (function() {
  6545. var xmlEscape = function(str) {
  6546. if (!str || str.constructor !== String) {
  6547. return "";
  6548. }
  6549. return str.replace(/[\"&><]/g, function(match) {
  6550. switch (match) {
  6551. case "\"":
  6552. return "&quot;";
  6553. case "&":
  6554. return "&amp;";
  6555. case "<":
  6556. return "&lt;";
  6557. case ">":
  6558. return "&gt;";
  6559. }
  6560. });
  6561. };
  6562. CSSLint.addFormatter({
  6563. id: "checkstyle-xml",
  6564. name: "Checkstyle XML format",
  6565. startFormat: function(){
  6566. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
  6567. },
  6568. endFormat: function(){
  6569. return "</checkstyle>";
  6570. },
  6571. readError: function(filename, message) {
  6572. return "<file name=\"" + xmlEscape(filename) + "\"><error line=\"0\" column=\"0\" severty=\"error\" message=\"" + xmlEscape(message) + "\"></error></file>";
  6573. },
  6574. formatResults: function(results, filename/*, options*/) {
  6575. var messages = results.messages,
  6576. output = [];
  6577. var generateSource = function(rule) {
  6578. if (!rule || !("name" in rule)) {
  6579. return "";
  6580. }
  6581. return "net.csslint." + rule.name.replace(/\s/g,"");
  6582. };
  6583. if (messages.length > 0) {
  6584. output.push("<file name=\""+filename+"\">");
  6585. CSSLint.Util.forEach(messages, function (message) {
  6586. if (!message.rollup) {
  6587. output.push("<error line=\"" + message.line + "\" column=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  6588. " message=\"" + xmlEscape(message.message) + "\" source=\"" + generateSource(message.rule) +"\"/>");
  6589. }
  6590. });
  6591. output.push("</file>");
  6592. }
  6593. return output.join("");
  6594. }
  6595. });
  6596. }());
  6597. CSSLint.addFormatter({
  6598. id: "compact",
  6599. name: "Compact, 'porcelain' format",
  6600. startFormat: function() {
  6601. return "";
  6602. },
  6603. endFormat: function() {
  6604. return "";
  6605. },
  6606. formatResults: function(results, filename, options) {
  6607. var messages = results.messages,
  6608. output = "";
  6609. options = options || {};
  6610. var capitalize = function(str) {
  6611. return str.charAt(0).toUpperCase() + str.slice(1);
  6612. };
  6613. if (messages.length === 0) {
  6614. return options.quiet ? "" : filename + ": Lint Free!";
  6615. }
  6616. CSSLint.Util.forEach(messages, function(message) {
  6617. if (message.rollup) {
  6618. output += filename + ": " + capitalize(message.type) + " - " + message.message + "\n";
  6619. } else {
  6620. output += filename + ": " + "line " + message.line +
  6621. ", col " + message.col + ", " + capitalize(message.type) + " - " + message.message + " (" + message.rule.id + ")\n";
  6622. }
  6623. });
  6624. return output;
  6625. }
  6626. });
  6627. CSSLint.addFormatter({
  6628. id: "csslint-xml",
  6629. name: "CSSLint XML format",
  6630. startFormat: function(){
  6631. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><csslint>";
  6632. },
  6633. endFormat: function(){
  6634. return "</csslint>";
  6635. },
  6636. formatResults: function(results, filename/*, options*/) {
  6637. var messages = results.messages,
  6638. output = [];
  6639. var escapeSpecialCharacters = function(str) {
  6640. if (!str || str.constructor !== String) {
  6641. return "";
  6642. }
  6643. return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  6644. };
  6645. if (messages.length > 0) {
  6646. output.push("<file name=\""+filename+"\">");
  6647. CSSLint.Util.forEach(messages, function (message) {
  6648. if (message.rollup) {
  6649. output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6650. } else {
  6651. output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  6652. " reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6653. }
  6654. });
  6655. output.push("</file>");
  6656. }
  6657. return output.join("");
  6658. }
  6659. });
  6660. CSSLint.addFormatter({
  6661. id: "junit-xml",
  6662. name: "JUNIT XML format",
  6663. startFormat: function(){
  6664. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><testsuites>";
  6665. },
  6666. endFormat: function() {
  6667. return "</testsuites>";
  6668. },
  6669. formatResults: function(results, filename/*, options*/) {
  6670. var messages = results.messages,
  6671. output = [],
  6672. tests = {
  6673. "error": 0,
  6674. "failure": 0
  6675. };
  6676. var generateSource = function(rule) {
  6677. if (!rule || !("name" in rule)) {
  6678. return "";
  6679. }
  6680. return "net.csslint." + rule.name.replace(/\s/g,"");
  6681. };
  6682. var escapeSpecialCharacters = function(str) {
  6683. if (!str || str.constructor !== String) {
  6684. return "";
  6685. }
  6686. return str.replace(/\"/g, "'").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  6687. };
  6688. if (messages.length > 0) {
  6689. messages.forEach(function (message) {
  6690. var type = message.type === "warning" ? "error" : message.type;
  6691. if (!message.rollup) {
  6692. output.push("<testcase time=\"0\" name=\"" + generateSource(message.rule) + "\">");
  6693. output.push("<" + type + " message=\"" + escapeSpecialCharacters(message.message) + "\"><![CDATA[" + message.line + ":" + message.col + ":" + escapeSpecialCharacters(message.evidence) + "]]></" + type + ">");
  6694. output.push("</testcase>");
  6695. tests[type] += 1;
  6696. }
  6697. });
  6698. output.unshift("<testsuite time=\"0\" tests=\"" + messages.length + "\" skipped=\"0\" errors=\"" + tests.error + "\" failures=\"" + tests.failure + "\" package=\"net.csslint\" name=\"" + filename + "\">");
  6699. output.push("</testsuite>");
  6700. }
  6701. return output.join("");
  6702. }
  6703. });
  6704. CSSLint.addFormatter({
  6705. id: "lint-xml",
  6706. name: "Lint XML format",
  6707. startFormat: function(){
  6708. return "<?xml version=\"1.0\" encoding=\"utf-8\"?><lint>";
  6709. },
  6710. endFormat: function(){
  6711. return "</lint>";
  6712. },
  6713. formatResults: function(results, filename/*, options*/) {
  6714. var messages = results.messages,
  6715. output = [];
  6716. var escapeSpecialCharacters = function(str) {
  6717. if (!str || str.constructor !== String) {
  6718. return "";
  6719. }
  6720. return str.replace(/\"/g, "'").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  6721. };
  6722. if (messages.length > 0) {
  6723. output.push("<file name=\""+filename+"\">");
  6724. CSSLint.Util.forEach(messages, function (message) {
  6725. if (message.rollup) {
  6726. output.push("<issue severity=\"" + message.type + "\" reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6727. } else {
  6728. output.push("<issue line=\"" + message.line + "\" char=\"" + message.col + "\" severity=\"" + message.type + "\"" +
  6729. " reason=\"" + escapeSpecialCharacters(message.message) + "\" evidence=\"" + escapeSpecialCharacters(message.evidence) + "\"/>");
  6730. }
  6731. });
  6732. output.push("</file>");
  6733. }
  6734. return output.join("");
  6735. }
  6736. });
  6737. CSSLint.addFormatter({
  6738. id: "text",
  6739. name: "Plain Text",
  6740. startFormat: function() {
  6741. return "";
  6742. },
  6743. endFormat: function() {
  6744. return "";
  6745. },
  6746. formatResults: function(results, filename, options) {
  6747. var messages = results.messages,
  6748. output = "";
  6749. options = options || {};
  6750. if (messages.length === 0) {
  6751. return options.quiet ? "" : "\n\ncsslint: No errors in " + filename + ".";
  6752. }
  6753. output = "\n\ncsslint: There ";
  6754. if (messages.length === 1) {
  6755. output += "is 1 problem";
  6756. } else {
  6757. output += "are " + messages.length + " problems";
  6758. }
  6759. output += " in " + filename + ".";
  6760. var pos = filename.lastIndexOf("/"),
  6761. shortFilename = filename;
  6762. if (pos === -1){
  6763. pos = filename.lastIndexOf("\\");
  6764. }
  6765. if (pos > -1){
  6766. shortFilename = filename.substring(pos+1);
  6767. }
  6768. CSSLint.Util.forEach(messages, function (message, i) {
  6769. output = output + "\n\n" + shortFilename;
  6770. if (message.rollup) {
  6771. output += "\n" + (i+1) + ": " + message.type;
  6772. output += "\n" + message.message;
  6773. } else {
  6774. output += "\n" + (i+1) + ": " + message.type + " at line " + message.line + ", col " + message.col;
  6775. output += "\n" + message.message;
  6776. output += "\n" + message.evidence;
  6777. }
  6778. });
  6779. return output;
  6780. }
  6781. });
  6782. module.exports.CSSLint = CSSLint;
  6783. });
  6784. ace.define("ace/mode/css_worker",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/worker/mirror","ace/mode/css/csslint"], function(require, exports, module) {
  6785. "use strict";
  6786. var oop = require("../lib/oop");
  6787. var lang = require("../lib/lang");
  6788. var Mirror = require("../worker/mirror").Mirror;
  6789. var CSSLint = require("./css/csslint").CSSLint;
  6790. var Worker = exports.Worker = function(sender) {
  6791. Mirror.call(this, sender);
  6792. this.setTimeout(400);
  6793. this.ruleset = null;
  6794. this.setDisabledRules("ids|order-alphabetical");
  6795. this.setInfoRules(
  6796. "adjoining-classes|qualified-headings|zero-units|gradients|" +
  6797. "import|outline-none|vendor-prefix"
  6798. );
  6799. };
  6800. oop.inherits(Worker, Mirror);
  6801. (function() {
  6802. this.setInfoRules = function(ruleNames) {
  6803. if (typeof ruleNames == "string")
  6804. ruleNames = ruleNames.split("|");
  6805. this.infoRules = lang.arrayToMap(ruleNames);
  6806. this.doc.getValue() && this.deferredUpdate.schedule(100);
  6807. };
  6808. this.setDisabledRules = function(ruleNames) {
  6809. if (!ruleNames) {
  6810. this.ruleset = null;
  6811. } else {
  6812. if (typeof ruleNames == "string")
  6813. ruleNames = ruleNames.split("|");
  6814. var all = {};
  6815. CSSLint.getRules().forEach(function(x){
  6816. all[x.id] = true;
  6817. });
  6818. ruleNames.forEach(function(x) {
  6819. delete all[x];
  6820. });
  6821. this.ruleset = all;
  6822. }
  6823. this.doc.getValue() && this.deferredUpdate.schedule(100);
  6824. };
  6825. this.onUpdate = function() {
  6826. var value = this.doc.getValue();
  6827. if (!value)
  6828. return this.sender.emit("csslint", []);
  6829. var infoRules = this.infoRules;
  6830. var result = CSSLint.verify(value, this.ruleset);
  6831. this.sender.emit("csslint", result.messages.map(function(msg) {
  6832. return {
  6833. row: msg.line - 1,
  6834. column: msg.col - 1,
  6835. text: msg.message,
  6836. type: infoRules[msg.rule.id] ? "info" : msg.type,
  6837. rule: msg.rule.name
  6838. }
  6839. }));
  6840. };
  6841. }).call(Worker.prototype);
  6842. });
  6843. ace.define("ace/lib/es5-shim",["require","exports","module"], function(require, exports, module) {
  6844. function Empty() {}
  6845. if (!Function.prototype.bind) {
  6846. Function.prototype.bind = function bind(that) { // .length is 1
  6847. var target = this;
  6848. if (typeof target != "function") {
  6849. throw new TypeError("Function.prototype.bind called on incompatible " + target);
  6850. }
  6851. var args = slice.call(arguments, 1); // for normal call
  6852. var bound = function () {
  6853. if (this instanceof bound) {
  6854. var result = target.apply(
  6855. this,
  6856. args.concat(slice.call(arguments))
  6857. );
  6858. if (Object(result) === result) {
  6859. return result;
  6860. }
  6861. return this;
  6862. } else {
  6863. return target.apply(
  6864. that,
  6865. args.concat(slice.call(arguments))
  6866. );
  6867. }
  6868. };
  6869. if(target.prototype) {
  6870. Empty.prototype = target.prototype;
  6871. bound.prototype = new Empty();
  6872. Empty.prototype = null;
  6873. }
  6874. return bound;
  6875. };
  6876. }
  6877. var call = Function.prototype.call;
  6878. var prototypeOfArray = Array.prototype;
  6879. var prototypeOfObject = Object.prototype;
  6880. var slice = prototypeOfArray.slice;
  6881. var _toString = call.bind(prototypeOfObject.toString);
  6882. var owns = call.bind(prototypeOfObject.hasOwnProperty);
  6883. var defineGetter;
  6884. var defineSetter;
  6885. var lookupGetter;
  6886. var lookupSetter;
  6887. var supportsAccessors;
  6888. if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
  6889. defineGetter = call.bind(prototypeOfObject.__defineGetter__);
  6890. defineSetter = call.bind(prototypeOfObject.__defineSetter__);
  6891. lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
  6892. lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
  6893. }
  6894. if ([1,2].splice(0).length != 2) {
  6895. if(function() { // test IE < 9 to splice bug - see issue #138
  6896. function makeArray(l) {
  6897. var a = new Array(l+2);
  6898. a[0] = a[1] = 0;
  6899. return a;
  6900. }
  6901. var array = [], lengthBefore;
  6902. array.splice.apply(array, makeArray(20));
  6903. array.splice.apply(array, makeArray(26));
  6904. lengthBefore = array.length; //46
  6905. array.splice(5, 0, "XXX"); // add one element
  6906. lengthBefore + 1 == array.length
  6907. if (lengthBefore + 1 == array.length) {
  6908. return true;// has right splice implementation without bugs
  6909. }
  6910. }()) {//IE 6/7
  6911. var array_splice = Array.prototype.splice;
  6912. Array.prototype.splice = function(start, deleteCount) {
  6913. if (!arguments.length) {
  6914. return [];
  6915. } else {
  6916. return array_splice.apply(this, [
  6917. start === void 0 ? 0 : start,
  6918. deleteCount === void 0 ? (this.length - start) : deleteCount
  6919. ].concat(slice.call(arguments, 2)))
  6920. }
  6921. };
  6922. } else {//IE8
  6923. Array.prototype.splice = function(pos, removeCount){
  6924. var length = this.length;
  6925. if (pos > 0) {
  6926. if (pos > length)
  6927. pos = length;
  6928. } else if (pos == void 0) {
  6929. pos = 0;
  6930. } else if (pos < 0) {
  6931. pos = Math.max(length + pos, 0);
  6932. }
  6933. if (!(pos+removeCount < length))
  6934. removeCount = length - pos;
  6935. var removed = this.slice(pos, pos+removeCount);
  6936. var insert = slice.call(arguments, 2);
  6937. var add = insert.length;
  6938. if (pos === length) {
  6939. if (add) {
  6940. this.push.apply(this, insert);
  6941. }
  6942. } else {
  6943. var remove = Math.min(removeCount, length - pos);
  6944. var tailOldPos = pos + remove;
  6945. var tailNewPos = tailOldPos + add - remove;
  6946. var tailCount = length - tailOldPos;
  6947. var lengthAfterRemove = length - remove;
  6948. if (tailNewPos < tailOldPos) { // case A
  6949. for (var i = 0; i < tailCount; ++i) {
  6950. this[tailNewPos+i] = this[tailOldPos+i];
  6951. }
  6952. } else if (tailNewPos > tailOldPos) { // case B
  6953. for (i = tailCount; i--; ) {
  6954. this[tailNewPos+i] = this[tailOldPos+i];
  6955. }
  6956. } // else, add == remove (nothing to do)
  6957. if (add && pos === lengthAfterRemove) {
  6958. this.length = lengthAfterRemove; // truncate array
  6959. this.push.apply(this, insert);
  6960. } else {
  6961. this.length = lengthAfterRemove + add; // reserves space
  6962. for (i = 0; i < add; ++i) {
  6963. this[pos+i] = insert[i];
  6964. }
  6965. }
  6966. }
  6967. return removed;
  6968. };
  6969. }
  6970. }
  6971. if (!Array.isArray) {
  6972. Array.isArray = function isArray(obj) {
  6973. return _toString(obj) == "[object Array]";
  6974. };
  6975. }
  6976. var boxedString = Object("a"),
  6977. splitString = boxedString[0] != "a" || !(0 in boxedString);
  6978. if (!Array.prototype.forEach) {
  6979. Array.prototype.forEach = function forEach(fun /*, thisp*/) {
  6980. var object = toObject(this),
  6981. self = splitString && _toString(this) == "[object String]" ?
  6982. this.split("") :
  6983. object,
  6984. thisp = arguments[1],
  6985. i = -1,
  6986. length = self.length >>> 0;
  6987. if (_toString(fun) != "[object Function]") {
  6988. throw new TypeError(); // TODO message
  6989. }
  6990. while (++i < length) {
  6991. if (i in self) {
  6992. fun.call(thisp, self[i], i, object);
  6993. }
  6994. }
  6995. };
  6996. }
  6997. if (!Array.prototype.map) {
  6998. Array.prototype.map = function map(fun /*, thisp*/) {
  6999. var object = toObject(this),
  7000. self = splitString && _toString(this) == "[object String]" ?
  7001. this.split("") :
  7002. object,
  7003. length = self.length >>> 0,
  7004. result = Array(length),
  7005. thisp = arguments[1];
  7006. if (_toString(fun) != "[object Function]") {
  7007. throw new TypeError(fun + " is not a function");
  7008. }
  7009. for (var i = 0; i < length; i++) {
  7010. if (i in self)
  7011. result[i] = fun.call(thisp, self[i], i, object);
  7012. }
  7013. return result;
  7014. };
  7015. }
  7016. if (!Array.prototype.filter) {
  7017. Array.prototype.filter = function filter(fun /*, thisp */) {
  7018. var object = toObject(this),
  7019. self = splitString && _toString(this) == "[object String]" ?
  7020. this.split("") :
  7021. object,
  7022. length = self.length >>> 0,
  7023. result = [],
  7024. value,
  7025. thisp = arguments[1];
  7026. if (_toString(fun) != "[object Function]") {
  7027. throw new TypeError(fun + " is not a function");
  7028. }
  7029. for (var i = 0; i < length; i++) {
  7030. if (i in self) {
  7031. value = self[i];
  7032. if (fun.call(thisp, value, i, object)) {
  7033. result.push(value);
  7034. }
  7035. }
  7036. }
  7037. return result;
  7038. };
  7039. }
  7040. if (!Array.prototype.every) {
  7041. Array.prototype.every = function every(fun /*, thisp */) {
  7042. var object = toObject(this),
  7043. self = splitString && _toString(this) == "[object String]" ?
  7044. this.split("") :
  7045. object,
  7046. length = self.length >>> 0,
  7047. thisp = arguments[1];
  7048. if (_toString(fun) != "[object Function]") {
  7049. throw new TypeError(fun + " is not a function");
  7050. }
  7051. for (var i = 0; i < length; i++) {
  7052. if (i in self && !fun.call(thisp, self[i], i, object)) {
  7053. return false;
  7054. }
  7055. }
  7056. return true;
  7057. };
  7058. }
  7059. if (!Array.prototype.some) {
  7060. Array.prototype.some = function some(fun /*, thisp */) {
  7061. var object = toObject(this),
  7062. self = splitString && _toString(this) == "[object String]" ?
  7063. this.split("") :
  7064. object,
  7065. length = self.length >>> 0,
  7066. thisp = arguments[1];
  7067. if (_toString(fun) != "[object Function]") {
  7068. throw new TypeError(fun + " is not a function");
  7069. }
  7070. for (var i = 0; i < length; i++) {
  7071. if (i in self && fun.call(thisp, self[i], i, object)) {
  7072. return true;
  7073. }
  7074. }
  7075. return false;
  7076. };
  7077. }
  7078. if (!Array.prototype.reduce) {
  7079. Array.prototype.reduce = function reduce(fun /*, initial*/) {
  7080. var object = toObject(this),
  7081. self = splitString && _toString(this) == "[object String]" ?
  7082. this.split("") :
  7083. object,
  7084. length = self.length >>> 0;
  7085. if (_toString(fun) != "[object Function]") {
  7086. throw new TypeError(fun + " is not a function");
  7087. }
  7088. if (!length && arguments.length == 1) {
  7089. throw new TypeError("reduce of empty array with no initial value");
  7090. }
  7091. var i = 0;
  7092. var result;
  7093. if (arguments.length >= 2) {
  7094. result = arguments[1];
  7095. } else {
  7096. do {
  7097. if (i in self) {
  7098. result = self[i++];
  7099. break;
  7100. }
  7101. if (++i >= length) {
  7102. throw new TypeError("reduce of empty array with no initial value");
  7103. }
  7104. } while (true);
  7105. }
  7106. for (; i < length; i++) {
  7107. if (i in self) {
  7108. result = fun.call(void 0, result, self[i], i, object);
  7109. }
  7110. }
  7111. return result;
  7112. };
  7113. }
  7114. if (!Array.prototype.reduceRight) {
  7115. Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
  7116. var object = toObject(this),
  7117. self = splitString && _toString(this) == "[object String]" ?
  7118. this.split("") :
  7119. object,
  7120. length = self.length >>> 0;
  7121. if (_toString(fun) != "[object Function]") {
  7122. throw new TypeError(fun + " is not a function");
  7123. }
  7124. if (!length && arguments.length == 1) {
  7125. throw new TypeError("reduceRight of empty array with no initial value");
  7126. }
  7127. var result, i = length - 1;
  7128. if (arguments.length >= 2) {
  7129. result = arguments[1];
  7130. } else {
  7131. do {
  7132. if (i in self) {
  7133. result = self[i--];
  7134. break;
  7135. }
  7136. if (--i < 0) {
  7137. throw new TypeError("reduceRight of empty array with no initial value");
  7138. }
  7139. } while (true);
  7140. }
  7141. do {
  7142. if (i in this) {
  7143. result = fun.call(void 0, result, self[i], i, object);
  7144. }
  7145. } while (i--);
  7146. return result;
  7147. };
  7148. }
  7149. if (!Array.prototype.indexOf || ([0, 1].indexOf(1, 2) != -1)) {
  7150. Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
  7151. var self = splitString && _toString(this) == "[object String]" ?
  7152. this.split("") :
  7153. toObject(this),
  7154. length = self.length >>> 0;
  7155. if (!length) {
  7156. return -1;
  7157. }
  7158. var i = 0;
  7159. if (arguments.length > 1) {
  7160. i = toInteger(arguments[1]);
  7161. }
  7162. i = i >= 0 ? i : Math.max(0, length + i);
  7163. for (; i < length; i++) {
  7164. if (i in self && self[i] === sought) {
  7165. return i;
  7166. }
  7167. }
  7168. return -1;
  7169. };
  7170. }
  7171. if (!Array.prototype.lastIndexOf || ([0, 1].lastIndexOf(0, -3) != -1)) {
  7172. Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
  7173. var self = splitString && _toString(this) == "[object String]" ?
  7174. this.split("") :
  7175. toObject(this),
  7176. length = self.length >>> 0;
  7177. if (!length) {
  7178. return -1;
  7179. }
  7180. var i = length - 1;
  7181. if (arguments.length > 1) {
  7182. i = Math.min(i, toInteger(arguments[1]));
  7183. }
  7184. i = i >= 0 ? i : length - Math.abs(i);
  7185. for (; i >= 0; i--) {
  7186. if (i in self && sought === self[i]) {
  7187. return i;
  7188. }
  7189. }
  7190. return -1;
  7191. };
  7192. }
  7193. if (!Object.getPrototypeOf) {
  7194. Object.getPrototypeOf = function getPrototypeOf(object) {
  7195. return object.__proto__ || (
  7196. object.constructor ?
  7197. object.constructor.prototype :
  7198. prototypeOfObject
  7199. );
  7200. };
  7201. }
  7202. if (!Object.getOwnPropertyDescriptor) {
  7203. var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
  7204. "non-object: ";
  7205. Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
  7206. if ((typeof object != "object" && typeof object != "function") || object === null)
  7207. throw new TypeError(ERR_NON_OBJECT + object);
  7208. if (!owns(object, property))
  7209. return;
  7210. var descriptor, getter, setter;
  7211. descriptor = { enumerable: true, configurable: true };
  7212. if (supportsAccessors) {
  7213. var prototype = object.__proto__;
  7214. object.__proto__ = prototypeOfObject;
  7215. var getter = lookupGetter(object, property);
  7216. var setter = lookupSetter(object, property);
  7217. object.__proto__ = prototype;
  7218. if (getter || setter) {
  7219. if (getter) descriptor.get = getter;
  7220. if (setter) descriptor.set = setter;
  7221. return descriptor;
  7222. }
  7223. }
  7224. descriptor.value = object[property];
  7225. return descriptor;
  7226. };
  7227. }
  7228. if (!Object.getOwnPropertyNames) {
  7229. Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
  7230. return Object.keys(object);
  7231. };
  7232. }
  7233. if (!Object.create) {
  7234. var createEmpty;
  7235. if (Object.prototype.__proto__ === null) {
  7236. createEmpty = function () {
  7237. return { "__proto__": null };
  7238. };
  7239. } else {
  7240. createEmpty = function () {
  7241. var empty = {};
  7242. for (var i in empty)
  7243. empty[i] = null;
  7244. empty.constructor =
  7245. empty.hasOwnProperty =
  7246. empty.propertyIsEnumerable =
  7247. empty.isPrototypeOf =
  7248. empty.toLocaleString =
  7249. empty.toString =
  7250. empty.valueOf =
  7251. empty.__proto__ = null;
  7252. return empty;
  7253. }
  7254. }
  7255. Object.create = function create(prototype, properties) {
  7256. var object;
  7257. if (prototype === null) {
  7258. object = createEmpty();
  7259. } else {
  7260. if (typeof prototype != "object")
  7261. throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
  7262. var Type = function () {};
  7263. Type.prototype = prototype;
  7264. object = new Type();
  7265. object.__proto__ = prototype;
  7266. }
  7267. if (properties !== void 0)
  7268. Object.defineProperties(object, properties);
  7269. return object;
  7270. };
  7271. }
  7272. function doesDefinePropertyWork(object) {
  7273. try {
  7274. Object.defineProperty(object, "sentinel", {});
  7275. return "sentinel" in object;
  7276. } catch (exception) {
  7277. }
  7278. }
  7279. if (Object.defineProperty) {
  7280. var definePropertyWorksOnObject = doesDefinePropertyWork({});
  7281. var definePropertyWorksOnDom = typeof document == "undefined" ||
  7282. doesDefinePropertyWork(document.createElement("div"));
  7283. if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
  7284. var definePropertyFallback = Object.defineProperty;
  7285. }
  7286. }
  7287. if (!Object.defineProperty || definePropertyFallback) {
  7288. var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
  7289. var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
  7290. var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
  7291. "on this javascript engine";
  7292. Object.defineProperty = function defineProperty(object, property, descriptor) {
  7293. if ((typeof object != "object" && typeof object != "function") || object === null)
  7294. throw new TypeError(ERR_NON_OBJECT_TARGET + object);
  7295. if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
  7296. throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
  7297. if (definePropertyFallback) {
  7298. try {
  7299. return definePropertyFallback.call(Object, object, property, descriptor);
  7300. } catch (exception) {
  7301. }
  7302. }
  7303. if (owns(descriptor, "value")) {
  7304. if (supportsAccessors && (lookupGetter(object, property) ||
  7305. lookupSetter(object, property)))
  7306. {
  7307. var prototype = object.__proto__;
  7308. object.__proto__ = prototypeOfObject;
  7309. delete object[property];
  7310. object[property] = descriptor.value;
  7311. object.__proto__ = prototype;
  7312. } else {
  7313. object[property] = descriptor.value;
  7314. }
  7315. } else {
  7316. if (!supportsAccessors)
  7317. throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
  7318. if (owns(descriptor, "get"))
  7319. defineGetter(object, property, descriptor.get);
  7320. if (owns(descriptor, "set"))
  7321. defineSetter(object, property, descriptor.set);
  7322. }
  7323. return object;
  7324. };
  7325. }
  7326. if (!Object.defineProperties) {
  7327. Object.defineProperties = function defineProperties(object, properties) {
  7328. for (var property in properties) {
  7329. if (owns(properties, property))
  7330. Object.defineProperty(object, property, properties[property]);
  7331. }
  7332. return object;
  7333. };
  7334. }
  7335. if (!Object.seal) {
  7336. Object.seal = function seal(object) {
  7337. return object;
  7338. };
  7339. }
  7340. if (!Object.freeze) {
  7341. Object.freeze = function freeze(object) {
  7342. return object;
  7343. };
  7344. }
  7345. try {
  7346. Object.freeze(function () {});
  7347. } catch (exception) {
  7348. Object.freeze = (function freeze(freezeObject) {
  7349. return function freeze(object) {
  7350. if (typeof object == "function") {
  7351. return object;
  7352. } else {
  7353. return freezeObject(object);
  7354. }
  7355. };
  7356. })(Object.freeze);
  7357. }
  7358. if (!Object.preventExtensions) {
  7359. Object.preventExtensions = function preventExtensions(object) {
  7360. return object;
  7361. };
  7362. }
  7363. if (!Object.isSealed) {
  7364. Object.isSealed = function isSealed(object) {
  7365. return false;
  7366. };
  7367. }
  7368. if (!Object.isFrozen) {
  7369. Object.isFrozen = function isFrozen(object) {
  7370. return false;
  7371. };
  7372. }
  7373. if (!Object.isExtensible) {
  7374. Object.isExtensible = function isExtensible(object) {
  7375. if (Object(object) === object) {
  7376. throw new TypeError(); // TODO message
  7377. }
  7378. var name = '';
  7379. while (owns(object, name)) {
  7380. name += '?';
  7381. }
  7382. object[name] = true;
  7383. var returnValue = owns(object, name);
  7384. delete object[name];
  7385. return returnValue;
  7386. };
  7387. }
  7388. if (!Object.keys) {
  7389. var hasDontEnumBug = true,
  7390. dontEnums = [
  7391. "toString",
  7392. "toLocaleString",
  7393. "valueOf",
  7394. "hasOwnProperty",
  7395. "isPrototypeOf",
  7396. "propertyIsEnumerable",
  7397. "constructor"
  7398. ],
  7399. dontEnumsLength = dontEnums.length;
  7400. for (var key in {"toString": null}) {
  7401. hasDontEnumBug = false;
  7402. }
  7403. Object.keys = function keys(object) {
  7404. if (
  7405. (typeof object != "object" && typeof object != "function") ||
  7406. object === null
  7407. ) {
  7408. throw new TypeError("Object.keys called on a non-object");
  7409. }
  7410. var keys = [];
  7411. for (var name in object) {
  7412. if (owns(object, name)) {
  7413. keys.push(name);
  7414. }
  7415. }
  7416. if (hasDontEnumBug) {
  7417. for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
  7418. var dontEnum = dontEnums[i];
  7419. if (owns(object, dontEnum)) {
  7420. keys.push(dontEnum);
  7421. }
  7422. }
  7423. }
  7424. return keys;
  7425. };
  7426. }
  7427. if (!Date.now) {
  7428. Date.now = function now() {
  7429. return new Date().getTime();
  7430. };
  7431. }
  7432. var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
  7433. "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
  7434. "\u2029\uFEFF";
  7435. if (!String.prototype.trim || ws.trim()) {
  7436. ws = "[" + ws + "]";
  7437. var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
  7438. trimEndRegexp = new RegExp(ws + ws + "*$");
  7439. String.prototype.trim = function trim() {
  7440. return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
  7441. };
  7442. }
  7443. function toInteger(n) {
  7444. n = +n;
  7445. if (n !== n) { // isNaN
  7446. n = 0;
  7447. } else if (n !== 0 && n !== (1/0) && n !== -(1/0)) {
  7448. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  7449. }
  7450. return n;
  7451. }
  7452. function isPrimitive(input) {
  7453. var type = typeof input;
  7454. return (
  7455. input === null ||
  7456. type === "undefined" ||
  7457. type === "boolean" ||
  7458. type === "number" ||
  7459. type === "string"
  7460. );
  7461. }
  7462. function toPrimitive(input) {
  7463. var val, valueOf, toString;
  7464. if (isPrimitive(input)) {
  7465. return input;
  7466. }
  7467. valueOf = input.valueOf;
  7468. if (typeof valueOf === "function") {
  7469. val = valueOf.call(input);
  7470. if (isPrimitive(val)) {
  7471. return val;
  7472. }
  7473. }
  7474. toString = input.toString;
  7475. if (typeof toString === "function") {
  7476. val = toString.call(input);
  7477. if (isPrimitive(val)) {
  7478. return val;
  7479. }
  7480. }
  7481. throw new TypeError();
  7482. }
  7483. var toObject = function (o) {
  7484. if (o == null) { // this matches both null and undefined
  7485. throw new TypeError("can't convert "+o+" to object");
  7486. }
  7487. return Object(o);
  7488. };
  7489. });